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, 2007, 2008 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 3, 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 COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols
== DWARF2_DEBUG
123 || write_symbols
== VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
133 /* Decide whether to emit frame unwind via assembler directives. */
136 dwarf2out_do_cfi_asm (void)
140 #ifdef MIPS_DEBUGGING_INFO
143 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
145 if (!eh_personality_libfunc
)
147 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
150 /* Make sure the personality encoding is one the assembler can support.
151 In particular, aligned addresses can't be handled. */
152 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
153 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
155 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
156 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
162 /* The size of the target's pointer type. */
164 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
167 /* Array of RTXes referenced by the debugging information, which therefore
168 must be kept around forever. */
169 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
171 /* A pointer to the base of a list of incomplete types which might be
172 completed at some later time. incomplete_types_list needs to be a
173 VEC(tree,gc) because we want to tell the garbage collector about
175 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
177 /* A pointer to the base of a table of references to declaration
178 scopes. This table is a display which tracks the nesting
179 of declaration scopes at the current scope and containing
180 scopes. This table is used to find the proper place to
181 define type declaration DIE's. */
182 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
184 /* Pointers to various DWARF2 sections. */
185 static GTY(()) section
*debug_info_section
;
186 static GTY(()) section
*debug_abbrev_section
;
187 static GTY(()) section
*debug_aranges_section
;
188 static GTY(()) section
*debug_macinfo_section
;
189 static GTY(()) section
*debug_line_section
;
190 static GTY(()) section
*debug_loc_section
;
191 static GTY(()) section
*debug_pubnames_section
;
192 static GTY(()) section
*debug_pubtypes_section
;
193 static GTY(()) section
*debug_str_section
;
194 static GTY(()) section
*debug_ranges_section
;
195 static GTY(()) section
*debug_frame_section
;
197 /* How to start an assembler comment. */
198 #ifndef ASM_COMMENT_START
199 #define ASM_COMMENT_START ";#"
202 typedef struct dw_cfi_struct
*dw_cfi_ref
;
203 typedef struct dw_fde_struct
*dw_fde_ref
;
204 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
206 /* Call frames are described using a sequence of Call Frame
207 Information instructions. The register number, offset
208 and address fields are provided as possible operands;
209 their use is selected by the opcode field. */
211 enum dw_cfi_oprnd_type
{
213 dw_cfi_oprnd_reg_num
,
219 typedef union dw_cfi_oprnd_struct
GTY(())
221 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
222 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
223 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
224 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
228 typedef struct dw_cfi_struct
GTY(())
230 dw_cfi_ref dw_cfi_next
;
231 enum dwarf_call_frame_info dw_cfi_opc
;
232 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
234 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
239 /* This is how we define the location of the CFA. We use to handle it
240 as REG + OFFSET all the time, but now it can be more complex.
241 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
242 Instead of passing around REG and OFFSET, we pass a copy
243 of this structure. */
244 typedef struct cfa_loc
GTY(())
246 HOST_WIDE_INT offset
;
247 HOST_WIDE_INT base_offset
;
249 int indirect
; /* 1 if CFA is accessed via a dereference. */
252 /* All call frame descriptions (FDE's) in the GCC generated DWARF
253 refer to a single Common Information Entry (CIE), defined at
254 the beginning of the .debug_frame section. This use of a single
255 CIE obviates the need to keep track of multiple CIE's
256 in the DWARF generation routines below. */
258 typedef struct dw_fde_struct
GTY(())
261 const char *dw_fde_begin
;
262 const char *dw_fde_current_label
;
263 const char *dw_fde_end
;
264 const char *dw_fde_hot_section_label
;
265 const char *dw_fde_hot_section_end_label
;
266 const char *dw_fde_unlikely_section_label
;
267 const char *dw_fde_unlikely_section_end_label
;
268 bool dw_fde_switched_sections
;
269 dw_cfi_ref dw_fde_cfi
;
270 unsigned funcdef_number
;
271 HOST_WIDE_INT stack_realignment
;
272 /* Dynamic realign argument pointer register. */
273 unsigned int drap_reg
;
274 /* Virtual dynamic realign argument pointer register. */
275 unsigned int vdrap_reg
;
276 unsigned all_throwers_are_sibcalls
: 1;
277 unsigned nothrow
: 1;
278 unsigned uses_eh_lsda
: 1;
279 /* Whether we did stack realign in this call frame. */
280 unsigned stack_realign
: 1;
281 /* Whether dynamic realign argument pointer register has been saved. */
282 unsigned drap_reg_saved
: 1;
286 /* Maximum size (in bytes) of an artificially generated label. */
287 #define MAX_ARTIFICIAL_LABEL_BYTES 30
289 /* The size of addresses as they appear in the Dwarf 2 data.
290 Some architectures use word addresses to refer to code locations,
291 but Dwarf 2 info always uses byte addresses. On such machines,
292 Dwarf 2 addresses need to be larger than the architecture's
294 #ifndef DWARF2_ADDR_SIZE
295 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
298 /* The size in bytes of a DWARF field indicating an offset or length
299 relative to a debug info section, specified to be 4 bytes in the
300 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
303 #ifndef DWARF_OFFSET_SIZE
304 #define DWARF_OFFSET_SIZE 4
307 /* According to the (draft) DWARF 3 specification, the initial length
308 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
309 bytes are 0xffffffff, followed by the length stored in the next 8
312 However, the SGI/MIPS ABI uses an initial length which is equal to
313 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
315 #ifndef DWARF_INITIAL_LENGTH_SIZE
316 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
319 #define DWARF_VERSION 2
321 /* Round SIZE up to the nearest BOUNDARY. */
322 #define DWARF_ROUND(SIZE,BOUNDARY) \
323 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
325 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
326 #ifndef DWARF_CIE_DATA_ALIGNMENT
327 #ifdef STACK_GROWS_DOWNWARD
328 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
330 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
334 /* CIE identifier. */
335 #if HOST_BITS_PER_WIDE_INT >= 64
336 #define DWARF_CIE_ID \
337 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
339 #define DWARF_CIE_ID DW_CIE_ID
342 /* A pointer to the base of a table that contains frame description
343 information for each routine. */
344 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
346 /* Number of elements currently allocated for fde_table. */
347 static GTY(()) unsigned fde_table_allocated
;
349 /* Number of elements in fde_table currently in use. */
350 static GTY(()) unsigned fde_table_in_use
;
352 /* Size (in elements) of increments by which we may expand the
354 #define FDE_TABLE_INCREMENT 256
356 /* Get the current fde_table entry we should use. */
358 static inline dw_fde_ref
361 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
364 /* A list of call frame insns for the CIE. */
365 static GTY(()) dw_cfi_ref cie_cfi_head
;
367 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
368 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
369 attribute that accelerates the lookup of the FDE associated
370 with the subprogram. This variable holds the table index of the FDE
371 associated with the current function (body) definition. */
372 static unsigned current_funcdef_fde
;
375 struct indirect_string_node
GTY(())
378 unsigned int refcount
;
383 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
385 static GTY(()) int dw2_string_counter
;
386 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
388 /* True if the compilation unit places functions in more than one section. */
389 static GTY(()) bool have_multiple_function_sections
= false;
391 /* Whether the default text and cold text sections have been used at all. */
393 static GTY(()) bool text_section_used
= false;
394 static GTY(()) bool cold_text_section_used
= false;
396 /* The default cold text section. */
397 static GTY(()) section
*cold_text_section
;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
401 /* Forward declarations for functions defined in this file. */
403 static char *stripattributes (const char *);
404 static const char *dwarf_cfi_name (unsigned);
405 static dw_cfi_ref
new_cfi (void);
406 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
407 static void add_fde_cfi (const char *, dw_cfi_ref
);
408 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
409 static void lookup_cfa (dw_cfa_location
*);
410 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
411 #ifdef DWARF2_UNWIND_INFO
412 static void initial_return_save (rtx
);
414 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
);
415 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
416 static void output_cfi_directive (dw_cfi_ref
);
417 static void output_call_frame_info (int);
418 static void dwarf2out_note_section_used (void);
419 static void dwarf2out_stack_adjust (rtx
, bool);
420 static void dwarf2out_args_size_adjust (HOST_WIDE_INT
, const char *);
421 static void flush_queued_reg_saves (void);
422 static bool clobbers_queued_reg_save (const_rtx
);
423 static void dwarf2out_frame_debug_expr (rtx
, const char *);
425 /* Support for complex CFA locations. */
426 static void output_cfa_loc (dw_cfi_ref
);
427 static void output_cfa_loc_raw (dw_cfi_ref
);
428 static void get_cfa_from_loc_descr (dw_cfa_location
*,
429 struct dw_loc_descr_struct
*);
430 static struct dw_loc_descr_struct
*build_cfa_loc
431 (dw_cfa_location
*, HOST_WIDE_INT
);
432 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
433 (HOST_WIDE_INT
, HOST_WIDE_INT
);
434 static void def_cfa_1 (const char *, dw_cfa_location
*);
436 /* How to start an assembler comment. */
437 #ifndef ASM_COMMENT_START
438 #define ASM_COMMENT_START ";#"
441 /* Data and reference forms for relocatable data. */
442 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
443 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
445 #ifndef DEBUG_FRAME_SECTION
446 #define DEBUG_FRAME_SECTION ".debug_frame"
449 #ifndef FUNC_BEGIN_LABEL
450 #define FUNC_BEGIN_LABEL "LFB"
453 #ifndef FUNC_END_LABEL
454 #define FUNC_END_LABEL "LFE"
457 #ifndef FRAME_BEGIN_LABEL
458 #define FRAME_BEGIN_LABEL "Lframe"
460 #define CIE_AFTER_SIZE_LABEL "LSCIE"
461 #define CIE_END_LABEL "LECIE"
462 #define FDE_LABEL "LSFDE"
463 #define FDE_AFTER_SIZE_LABEL "LASFDE"
464 #define FDE_END_LABEL "LEFDE"
465 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
466 #define LINE_NUMBER_END_LABEL "LELT"
467 #define LN_PROLOG_AS_LABEL "LASLTP"
468 #define LN_PROLOG_END_LABEL "LELTP"
469 #define DIE_LABEL_PREFIX "DW"
471 /* The DWARF 2 CFA column which tracks the return address. Normally this
472 is the column for PC, or the first column after all of the hard
474 #ifndef DWARF_FRAME_RETURN_COLUMN
476 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
478 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
482 /* The mapping from gcc register number to DWARF 2 CFA column number. By
483 default, we just provide columns for all registers. */
484 #ifndef DWARF_FRAME_REGNUM
485 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
488 /* Hook used by __throw. */
491 expand_builtin_dwarf_sp_column (void)
493 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
494 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
497 /* Return a pointer to a copy of the section string name S with all
498 attributes stripped off, and an asterisk prepended (for assemble_name). */
501 stripattributes (const char *s
)
503 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
508 while (*s
&& *s
!= ',')
515 /* MEM is a memory reference for the register size table, each element of
516 which has mode MODE. Initialize column C as a return address column. */
519 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
521 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
522 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
523 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
526 /* Generate code to initialize the register size table. */
529 expand_builtin_init_dwarf_reg_sizes (tree address
)
532 enum machine_mode mode
= TYPE_MODE (char_type_node
);
533 rtx addr
= expand_normal (address
);
534 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
535 bool wrote_return_column
= false;
537 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
539 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
541 if (rnum
< DWARF_FRAME_REGISTERS
)
543 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
544 enum machine_mode save_mode
= reg_raw_mode
[i
];
547 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
548 save_mode
= choose_hard_reg_mode (i
, 1, true);
549 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
551 if (save_mode
== VOIDmode
)
553 wrote_return_column
= true;
555 size
= GET_MODE_SIZE (save_mode
);
559 emit_move_insn (adjust_address (mem
, mode
, offset
),
560 gen_int_mode (size
, mode
));
564 if (!wrote_return_column
)
565 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
567 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
568 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
571 targetm
.init_dwarf_reg_sizes_extra (address
);
574 /* Convert a DWARF call frame info. operation to its string name */
577 dwarf_cfi_name (unsigned int cfi_opc
)
581 case DW_CFA_advance_loc
:
582 return "DW_CFA_advance_loc";
584 return "DW_CFA_offset";
586 return "DW_CFA_restore";
590 return "DW_CFA_set_loc";
591 case DW_CFA_advance_loc1
:
592 return "DW_CFA_advance_loc1";
593 case DW_CFA_advance_loc2
:
594 return "DW_CFA_advance_loc2";
595 case DW_CFA_advance_loc4
:
596 return "DW_CFA_advance_loc4";
597 case DW_CFA_offset_extended
:
598 return "DW_CFA_offset_extended";
599 case DW_CFA_restore_extended
:
600 return "DW_CFA_restore_extended";
601 case DW_CFA_undefined
:
602 return "DW_CFA_undefined";
603 case DW_CFA_same_value
:
604 return "DW_CFA_same_value";
605 case DW_CFA_register
:
606 return "DW_CFA_register";
607 case DW_CFA_remember_state
:
608 return "DW_CFA_remember_state";
609 case DW_CFA_restore_state
:
610 return "DW_CFA_restore_state";
612 return "DW_CFA_def_cfa";
613 case DW_CFA_def_cfa_register
:
614 return "DW_CFA_def_cfa_register";
615 case DW_CFA_def_cfa_offset
:
616 return "DW_CFA_def_cfa_offset";
619 case DW_CFA_def_cfa_expression
:
620 return "DW_CFA_def_cfa_expression";
621 case DW_CFA_expression
:
622 return "DW_CFA_expression";
623 case DW_CFA_offset_extended_sf
:
624 return "DW_CFA_offset_extended_sf";
625 case DW_CFA_def_cfa_sf
:
626 return "DW_CFA_def_cfa_sf";
627 case DW_CFA_def_cfa_offset_sf
:
628 return "DW_CFA_def_cfa_offset_sf";
630 /* SGI/MIPS specific */
631 case DW_CFA_MIPS_advance_loc8
:
632 return "DW_CFA_MIPS_advance_loc8";
635 case DW_CFA_GNU_window_save
:
636 return "DW_CFA_GNU_window_save";
637 case DW_CFA_GNU_args_size
:
638 return "DW_CFA_GNU_args_size";
639 case DW_CFA_GNU_negative_offset_extended
:
640 return "DW_CFA_GNU_negative_offset_extended";
643 return "DW_CFA_<unknown>";
647 /* Return a pointer to a newly allocated Call Frame Instruction. */
649 static inline dw_cfi_ref
652 dw_cfi_ref cfi
= GGC_NEW (dw_cfi_node
);
654 cfi
->dw_cfi_next
= NULL
;
655 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
656 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
661 /* Add a Call Frame Instruction to list of instructions. */
664 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
667 dw_fde_ref fde
= current_fde ();
669 /* When DRAP is used, CFA is defined with an expression. Redefine
670 CFA may lead to a different CFA value. */
671 if (fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
672 switch (cfi
->dw_cfi_opc
)
674 case DW_CFA_def_cfa_register
:
675 case DW_CFA_def_cfa_offset
:
676 case DW_CFA_def_cfa_offset_sf
:
678 case DW_CFA_def_cfa_sf
:
685 /* Find the end of the chain. */
686 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
692 /* Generate a new label for the CFI info to refer to. */
695 dwarf2out_cfi_label (void)
697 static char label
[20];
699 if (dwarf2out_do_cfi_asm ())
701 /* In this case, we will be emitting the asm directive instead of
702 the label, so just return a placeholder to keep the rest of the
704 strcpy (label
, "<do not output>");
708 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
709 ASM_OUTPUT_LABEL (asm_out_file
, label
);
715 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
716 or to the CIE if LABEL is NULL. */
719 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
721 dw_cfi_ref
*list_head
= &cie_cfi_head
;
723 if (dwarf2out_do_cfi_asm ())
727 output_cfi_directive (cfi
);
729 /* We still have to add the cfi to the list so that
730 lookup_cfa works later on. */
731 list_head
= ¤t_fde ()->dw_fde_cfi
;
733 /* ??? If this is a CFI for the CIE, we don't emit. This
734 assumes that the standard CIE contents that the assembler
735 uses matches the standard CIE contents that the compiler
736 uses. This is probably a bad assumption. I'm not quite
737 sure how to address this for now. */
741 dw_fde_ref fde
= current_fde ();
743 gcc_assert (fde
!= NULL
);
746 label
= dwarf2out_cfi_label ();
748 if (fde
->dw_fde_current_label
== NULL
749 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
753 label
= xstrdup (label
);
755 /* Set the location counter to the new label. */
757 /* If we have a current label, advance from there, otherwise
758 set the location directly using set_loc. */
759 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
760 ? DW_CFA_advance_loc4
762 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
763 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
765 fde
->dw_fde_current_label
= label
;
768 list_head
= &fde
->dw_fde_cfi
;
771 add_cfi (list_head
, cfi
);
774 /* Subroutine of lookup_cfa. */
777 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
779 switch (cfi
->dw_cfi_opc
)
781 case DW_CFA_def_cfa_offset
:
782 case DW_CFA_def_cfa_offset_sf
:
783 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
785 case DW_CFA_def_cfa_register
:
786 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
789 case DW_CFA_def_cfa_sf
:
790 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
791 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
793 case DW_CFA_def_cfa_expression
:
794 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
801 /* Find the previous value for the CFA. */
804 lookup_cfa (dw_cfa_location
*loc
)
809 loc
->reg
= INVALID_REGNUM
;
812 loc
->base_offset
= 0;
814 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
815 lookup_cfa_1 (cfi
, loc
);
817 fde
= current_fde ();
819 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
820 lookup_cfa_1 (cfi
, loc
);
823 /* The current rule for calculating the DWARF2 canonical frame address. */
824 static dw_cfa_location cfa
;
826 /* The register used for saving registers to the stack, and its offset
828 static dw_cfa_location cfa_store
;
830 /* The running total of the size of arguments pushed onto the stack. */
831 static HOST_WIDE_INT args_size
;
833 /* The last args_size we actually output. */
834 static HOST_WIDE_INT old_args_size
;
836 /* Entry point to update the canonical frame address (CFA).
837 LABEL is passed to add_fde_cfi. The value of CFA is now to be
838 calculated from REG+OFFSET. */
841 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
848 def_cfa_1 (label
, &loc
);
851 /* Determine if two dw_cfa_location structures define the same data. */
854 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
856 return (loc1
->reg
== loc2
->reg
857 && loc1
->offset
== loc2
->offset
858 && loc1
->indirect
== loc2
->indirect
859 && (loc1
->indirect
== 0
860 || loc1
->base_offset
== loc2
->base_offset
));
863 /* This routine does the actual work. The CFA is now calculated from
864 the dw_cfa_location structure. */
867 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
870 dw_cfa_location old_cfa
, loc
;
875 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
876 cfa_store
.offset
= loc
.offset
;
878 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
879 lookup_cfa (&old_cfa
);
881 /* If nothing changed, no need to issue any call frame instructions. */
882 if (cfa_equal_p (&loc
, &old_cfa
))
887 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
889 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
890 the CFA register did not change but the offset did. The data
891 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
892 in the assembler via the .cfi_def_cfa_offset directive. */
894 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
896 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
897 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
900 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
901 else if (loc
.offset
== old_cfa
.offset
902 && old_cfa
.reg
!= INVALID_REGNUM
905 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
906 indicating the CFA register has changed to <register> but the
907 offset has not changed. */
908 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
909 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
913 else if (loc
.indirect
== 0)
915 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
916 indicating the CFA register has changed to <register> with
917 the specified offset. The data factoring for DW_CFA_def_cfa_sf
918 happens in output_cfi, or in the assembler via the .cfi_def_cfa
921 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
923 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
924 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
925 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
929 /* Construct a DW_CFA_def_cfa_expression instruction to
930 calculate the CFA using a full location expression since no
931 register-offset pair is available. */
932 struct dw_loc_descr_struct
*loc_list
;
934 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
935 loc_list
= build_cfa_loc (&loc
, 0);
936 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
939 add_fde_cfi (label
, cfi
);
942 /* Add the CFI for saving a register. REG is the CFA column number.
943 LABEL is passed to add_fde_cfi.
944 If SREG is -1, the register is saved at OFFSET from the CFA;
945 otherwise it is saved in SREG. */
948 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
950 dw_cfi_ref cfi
= new_cfi ();
951 dw_fde_ref fde
= current_fde ();
953 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
955 /* When stack is aligned, store REG using DW_CFA_expression with
958 && fde
->stack_realign
959 && sreg
== INVALID_REGNUM
)
961 cfi
->dw_cfi_opc
= DW_CFA_expression
;
962 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= reg
;
963 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
964 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
966 else if (sreg
== INVALID_REGNUM
)
969 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
970 else if (reg
& ~0x3f)
971 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
973 cfi
->dw_cfi_opc
= DW_CFA_offset
;
974 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
976 else if (sreg
== reg
)
977 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
980 cfi
->dw_cfi_opc
= DW_CFA_register
;
981 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
984 add_fde_cfi (label
, cfi
);
987 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
988 This CFI tells the unwinder that it needs to restore the window registers
989 from the previous frame's window save area.
991 ??? Perhaps we should note in the CIE where windows are saved (instead of
992 assuming 0(cfa)) and what registers are in the window. */
995 dwarf2out_window_save (const char *label
)
997 dw_cfi_ref cfi
= new_cfi ();
999 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1000 add_fde_cfi (label
, cfi
);
1003 /* Add a CFI to update the running total of the size of arguments
1004 pushed onto the stack. */
1007 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1011 if (size
== old_args_size
)
1014 old_args_size
= size
;
1017 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1018 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1019 add_fde_cfi (label
, cfi
);
1022 /* Entry point for saving a register to the stack. REG is the GCC register
1023 number. LABEL and OFFSET are passed to reg_save. */
1026 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1028 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1031 /* Entry point for saving the return address in the stack.
1032 LABEL and OFFSET are passed to reg_save. */
1035 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1037 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1040 /* Entry point for saving the return address in a register.
1041 LABEL and SREG are passed to reg_save. */
1044 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1046 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1049 #ifdef DWARF2_UNWIND_INFO
1050 /* Record the initial position of the return address. RTL is
1051 INCOMING_RETURN_ADDR_RTX. */
1054 initial_return_save (rtx rtl
)
1056 unsigned int reg
= INVALID_REGNUM
;
1057 HOST_WIDE_INT offset
= 0;
1059 switch (GET_CODE (rtl
))
1062 /* RA is in a register. */
1063 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1067 /* RA is on the stack. */
1068 rtl
= XEXP (rtl
, 0);
1069 switch (GET_CODE (rtl
))
1072 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1077 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1078 offset
= INTVAL (XEXP (rtl
, 1));
1082 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1083 offset
= -INTVAL (XEXP (rtl
, 1));
1093 /* The return address is at some offset from any value we can
1094 actually load. For instance, on the SPARC it is in %i7+8. Just
1095 ignore the offset for now; it doesn't matter for unwinding frames. */
1096 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
1097 initial_return_save (XEXP (rtl
, 0));
1104 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1105 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1109 /* Given a SET, calculate the amount of stack adjustment it
1112 static HOST_WIDE_INT
1113 stack_adjust_offset (const_rtx pattern
)
1115 const_rtx src
= SET_SRC (pattern
);
1116 const_rtx dest
= SET_DEST (pattern
);
1117 HOST_WIDE_INT offset
= 0;
1120 if (dest
== stack_pointer_rtx
)
1122 /* (set (reg sp) (plus (reg sp) (const_int))) */
1123 code
= GET_CODE (src
);
1124 if (! (code
== PLUS
|| code
== MINUS
)
1125 || XEXP (src
, 0) != stack_pointer_rtx
1126 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1129 offset
= INTVAL (XEXP (src
, 1));
1133 else if (MEM_P (dest
))
1135 /* (set (mem (pre_dec (reg sp))) (foo)) */
1136 src
= XEXP (dest
, 0);
1137 code
= GET_CODE (src
);
1143 if (XEXP (src
, 0) == stack_pointer_rtx
)
1145 rtx val
= XEXP (XEXP (src
, 1), 1);
1146 /* We handle only adjustments by constant amount. */
1147 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1148 && GET_CODE (val
) == CONST_INT
);
1149 offset
= -INTVAL (val
);
1156 if (XEXP (src
, 0) == stack_pointer_rtx
)
1158 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1165 if (XEXP (src
, 0) == stack_pointer_rtx
)
1167 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1182 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1183 indexed by INSN_UID. */
1185 static HOST_WIDE_INT
*barrier_args_size
;
1187 /* Helper function for compute_barrier_args_size. Handle one insn. */
1189 static HOST_WIDE_INT
1190 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1191 VEC (rtx
, heap
) **next
)
1193 HOST_WIDE_INT offset
= 0;
1196 if (! RTX_FRAME_RELATED_P (insn
))
1198 if (prologue_epilogue_contains (insn
)
1199 || sibcall_epilogue_contains (insn
))
1201 else if (GET_CODE (PATTERN (insn
)) == SET
)
1202 offset
= stack_adjust_offset (PATTERN (insn
));
1203 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1204 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1206 /* There may be stack adjustments inside compound insns. Search
1208 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1209 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1210 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1215 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1219 expr
= XEXP (expr
, 0);
1220 if (GET_CODE (expr
) == PARALLEL
1221 || GET_CODE (expr
) == SEQUENCE
)
1222 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1224 rtx elem
= XVECEXP (expr
, 0, i
);
1226 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1227 offset
+= stack_adjust_offset (elem
);
1232 #ifndef STACK_GROWS_DOWNWARD
1236 cur_args_size
+= offset
;
1237 if (cur_args_size
< 0)
1242 rtx dest
= JUMP_LABEL (insn
);
1246 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1248 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1249 VEC_safe_push (rtx
, heap
, *next
, dest
);
1254 return cur_args_size
;
1257 /* Walk the whole function and compute args_size on BARRIERs. */
1260 compute_barrier_args_size (void)
1262 int max_uid
= get_max_uid (), i
;
1264 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1266 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1267 for (i
= 0; i
< max_uid
; i
++)
1268 barrier_args_size
[i
] = -1;
1270 worklist
= VEC_alloc (rtx
, heap
, 20);
1271 next
= VEC_alloc (rtx
, heap
, 20);
1272 insn
= get_insns ();
1273 barrier_args_size
[INSN_UID (insn
)] = 0;
1274 VEC_quick_push (rtx
, worklist
, insn
);
1277 while (!VEC_empty (rtx
, worklist
))
1279 rtx prev
, body
, first_insn
;
1280 HOST_WIDE_INT cur_args_size
;
1282 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1283 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1284 prev
= prev_nonnote_insn (insn
);
1285 if (prev
&& BARRIER_P (prev
))
1286 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1288 for (; insn
; insn
= NEXT_INSN (insn
))
1290 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1292 if (BARRIER_P (insn
))
1297 if (insn
== first_insn
)
1299 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1301 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1306 /* The insns starting with this label have been
1307 already scanned or are in the worklist. */
1312 body
= PATTERN (insn
);
1313 if (GET_CODE (body
) == SEQUENCE
)
1315 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1317 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1318 cur_args_size
, &next
);
1320 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1321 cur_args_size
, &next
);
1325 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1329 if (VEC_empty (rtx
, next
))
1332 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1336 VEC_truncate (rtx
, next
, 0);
1339 VEC_free (rtx
, heap
, worklist
);
1340 VEC_free (rtx
, heap
, next
);
1344 /* Check INSN to see if it looks like a push or a stack adjustment, and
1345 make a note of it if it does. EH uses this information to find out how
1346 much extra space it needs to pop off the stack. */
1349 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1351 HOST_WIDE_INT offset
;
1355 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1356 with this function. Proper support would require all frame-related
1357 insns to be marked, and to be able to handle saving state around
1358 epilogues textually in the middle of the function. */
1359 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1362 /* If only calls can throw, and we have a frame pointer,
1363 save up adjustments until we see the CALL_INSN. */
1364 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1366 if (CALL_P (insn
) && !after_p
)
1368 /* Extract the size of the args from the CALL rtx itself. */
1369 insn
= PATTERN (insn
);
1370 if (GET_CODE (insn
) == PARALLEL
)
1371 insn
= XVECEXP (insn
, 0, 0);
1372 if (GET_CODE (insn
) == SET
)
1373 insn
= SET_SRC (insn
);
1374 gcc_assert (GET_CODE (insn
) == CALL
);
1375 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1380 if (CALL_P (insn
) && !after_p
)
1382 if (!flag_asynchronous_unwind_tables
)
1383 dwarf2out_args_size ("", args_size
);
1386 else if (BARRIER_P (insn
))
1388 /* Don't call compute_barrier_args_size () if the only
1389 BARRIER is at the end of function. */
1390 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1391 compute_barrier_args_size ();
1392 if (barrier_args_size
== NULL
)
1396 offset
= barrier_args_size
[INSN_UID (insn
)];
1401 offset
-= args_size
;
1402 #ifndef STACK_GROWS_DOWNWARD
1406 else if (GET_CODE (PATTERN (insn
)) == SET
)
1407 offset
= stack_adjust_offset (PATTERN (insn
));
1408 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1409 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1411 /* There may be stack adjustments inside compound insns. Search
1413 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1414 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1415 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1423 label
= dwarf2out_cfi_label ();
1424 dwarf2out_args_size_adjust (offset
, label
);
1427 /* Adjust args_size based on stack adjustment OFFSET. */
1430 dwarf2out_args_size_adjust (HOST_WIDE_INT offset
, const char *label
)
1432 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1433 cfa
.offset
+= offset
;
1435 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1436 cfa_store
.offset
+= offset
;
1438 #ifndef STACK_GROWS_DOWNWARD
1442 args_size
+= offset
;
1446 def_cfa_1 (label
, &cfa
);
1447 if (flag_asynchronous_unwind_tables
)
1448 dwarf2out_args_size (label
, args_size
);
1453 /* We delay emitting a register save until either (a) we reach the end
1454 of the prologue or (b) the register is clobbered. This clusters
1455 register saves so that there are fewer pc advances. */
1457 struct queued_reg_save
GTY(())
1459 struct queued_reg_save
*next
;
1461 HOST_WIDE_INT cfa_offset
;
1465 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1467 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1468 struct reg_saved_in_data
GTY(()) {
1473 /* A list of registers saved in other registers.
1474 The list intentionally has a small maximum capacity of 4; if your
1475 port needs more than that, you might consider implementing a
1476 more efficient data structure. */
1477 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1478 static GTY(()) size_t num_regs_saved_in_regs
;
1480 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1481 static const char *last_reg_save_label
;
1483 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1484 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1487 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1489 struct queued_reg_save
*q
;
1491 /* Duplicates waste space, but it's also necessary to remove them
1492 for correctness, since the queue gets output in reverse
1494 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1495 if (REGNO (q
->reg
) == REGNO (reg
))
1500 q
= GGC_NEW (struct queued_reg_save
);
1501 q
->next
= queued_reg_saves
;
1502 queued_reg_saves
= q
;
1506 q
->cfa_offset
= offset
;
1507 q
->saved_reg
= sreg
;
1509 last_reg_save_label
= label
;
1512 /* Output all the entries in QUEUED_REG_SAVES. */
1515 flush_queued_reg_saves (void)
1517 struct queued_reg_save
*q
;
1519 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1522 unsigned int reg
, sreg
;
1524 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1525 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1527 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1529 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1530 num_regs_saved_in_regs
++;
1532 if (i
!= num_regs_saved_in_regs
)
1534 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1535 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1538 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1540 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1542 sreg
= INVALID_REGNUM
;
1543 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1546 queued_reg_saves
= NULL
;
1547 last_reg_save_label
= NULL
;
1550 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1551 location for? Or, does it clobber a register which we've previously
1552 said that some other register is saved in, and for which we now
1553 have a new location for? */
1556 clobbers_queued_reg_save (const_rtx insn
)
1558 struct queued_reg_save
*q
;
1560 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1563 if (modified_in_p (q
->reg
, insn
))
1565 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1566 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1567 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1574 /* Entry point for saving the first register into the second. */
1577 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1580 unsigned int regno
, sregno
;
1582 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1583 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1585 if (i
== num_regs_saved_in_regs
)
1587 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1588 num_regs_saved_in_regs
++;
1590 regs_saved_in_regs
[i
].orig_reg
= reg
;
1591 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1593 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1594 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1595 reg_save (label
, regno
, sregno
, 0);
1598 /* What register, if any, is currently saved in REG? */
1601 reg_saved_in (rtx reg
)
1603 unsigned int regn
= REGNO (reg
);
1605 struct queued_reg_save
*q
;
1607 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1608 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1611 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1612 if (regs_saved_in_regs
[i
].saved_in_reg
1613 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1614 return regs_saved_in_regs
[i
].orig_reg
;
1620 /* A temporary register holding an integral value used in adjusting SP
1621 or setting up the store_reg. The "offset" field holds the integer
1622 value, not an offset. */
1623 static dw_cfa_location cfa_temp
;
1625 /* Record call frame debugging information for an expression EXPR,
1626 which either sets SP or FP (adjusting how we calculate the frame
1627 address) or saves a register to the stack or another register.
1628 LABEL indicates the address of EXPR.
1630 This function encodes a state machine mapping rtxes to actions on
1631 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1632 users need not read the source code.
1634 The High-Level Picture
1636 Changes in the register we use to calculate the CFA: Currently we
1637 assume that if you copy the CFA register into another register, we
1638 should take the other one as the new CFA register; this seems to
1639 work pretty well. If it's wrong for some target, it's simple
1640 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1642 Changes in the register we use for saving registers to the stack:
1643 This is usually SP, but not always. Again, we deduce that if you
1644 copy SP into another register (and SP is not the CFA register),
1645 then the new register is the one we will be using for register
1646 saves. This also seems to work.
1648 Register saves: There's not much guesswork about this one; if
1649 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1650 register save, and the register used to calculate the destination
1651 had better be the one we think we're using for this purpose.
1652 It's also assumed that a copy from a call-saved register to another
1653 register is saving that register if RTX_FRAME_RELATED_P is set on
1654 that instruction. If the copy is from a call-saved register to
1655 the *same* register, that means that the register is now the same
1656 value as in the caller.
1658 Except: If the register being saved is the CFA register, and the
1659 offset is nonzero, we are saving the CFA, so we assume we have to
1660 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1661 the intent is to save the value of SP from the previous frame.
1663 In addition, if a register has previously been saved to a different
1666 Invariants / Summaries of Rules
1668 cfa current rule for calculating the CFA. It usually
1669 consists of a register and an offset.
1670 cfa_store register used by prologue code to save things to the stack
1671 cfa_store.offset is the offset from the value of
1672 cfa_store.reg to the actual CFA
1673 cfa_temp register holding an integral value. cfa_temp.offset
1674 stores the value, which will be used to adjust the
1675 stack pointer. cfa_temp is also used like cfa_store,
1676 to track stores to the stack via fp or a temp reg.
1678 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1679 with cfa.reg as the first operand changes the cfa.reg and its
1680 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1683 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1684 expression yielding a constant. This sets cfa_temp.reg
1685 and cfa_temp.offset.
1687 Rule 5: Create a new register cfa_store used to save items to the
1690 Rules 10-14: Save a register to the stack. Define offset as the
1691 difference of the original location and cfa_store's
1692 location (or cfa_temp's location if cfa_temp is used).
1694 Rules 16-20: If AND operation happens on sp in prologue, we assume
1695 stack is realigned. We will use a group of DW_OP_XXX
1696 expressions to represent the location of the stored
1697 register instead of CFA+offset.
1701 "{a,b}" indicates a choice of a xor b.
1702 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1705 (set <reg1> <reg2>:cfa.reg)
1706 effects: cfa.reg = <reg1>
1707 cfa.offset unchanged
1708 cfa_temp.reg = <reg1>
1709 cfa_temp.offset = cfa.offset
1712 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1713 {<const_int>,<reg>:cfa_temp.reg}))
1714 effects: cfa.reg = sp if fp used
1715 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1716 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1717 if cfa_store.reg==sp
1720 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1721 effects: cfa.reg = fp
1722 cfa_offset += +/- <const_int>
1725 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1726 constraints: <reg1> != fp
1728 effects: cfa.reg = <reg1>
1729 cfa_temp.reg = <reg1>
1730 cfa_temp.offset = cfa.offset
1733 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1734 constraints: <reg1> != fp
1736 effects: cfa_store.reg = <reg1>
1737 cfa_store.offset = cfa.offset - cfa_temp.offset
1740 (set <reg> <const_int>)
1741 effects: cfa_temp.reg = <reg>
1742 cfa_temp.offset = <const_int>
1745 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1746 effects: cfa_temp.reg = <reg1>
1747 cfa_temp.offset |= <const_int>
1750 (set <reg> (high <exp>))
1754 (set <reg> (lo_sum <exp> <const_int>))
1755 effects: cfa_temp.reg = <reg>
1756 cfa_temp.offset = <const_int>
1759 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1760 effects: cfa_store.offset -= <const_int>
1761 cfa.offset = cfa_store.offset if cfa.reg == sp
1763 cfa.base_offset = -cfa_store.offset
1766 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1767 effects: cfa_store.offset += -/+ mode_size(mem)
1768 cfa.offset = cfa_store.offset if cfa.reg == sp
1770 cfa.base_offset = -cfa_store.offset
1773 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1776 effects: cfa.reg = <reg1>
1777 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1780 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1781 effects: cfa.reg = <reg1>
1782 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1785 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1786 effects: cfa.reg = <reg1>
1787 cfa.base_offset = -cfa_temp.offset
1788 cfa_temp.offset -= mode_size(mem)
1791 (set <reg> {unspec, unspec_volatile})
1792 effects: target-dependent
1795 (set sp (and: sp <const_int>))
1796 constraints: cfa_store.reg == sp
1797 effects: current_fde.stack_realign = 1
1798 cfa_store.offset = 0
1799 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1802 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1803 effects: cfa_store.offset += -/+ mode_size(mem)
1806 (set (mem ({pre_inc, pre_dec} sp)) fp)
1807 constraints: fde->stack_realign == 1
1808 effects: cfa_store.offset = 0
1809 cfa.reg != HARD_FRAME_POINTER_REGNUM
1812 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1813 constraints: fde->stack_realign == 1
1815 && cfa.indirect == 0
1816 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1817 effects: Use DW_CFA_def_cfa_expression to define cfa
1818 cfa.reg == fde->drap_reg
1821 (set reg fde->drap_reg)
1822 constraints: fde->vdrap_reg == INVALID_REGNUM
1823 effects: fde->vdrap_reg = reg.
1824 (set mem fde->drap_reg)
1825 constraints: fde->drap_reg_saved == 1
1829 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1831 rtx src
, dest
, span
;
1832 HOST_WIDE_INT offset
;
1835 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1836 the PARALLEL independently. The first element is always processed if
1837 it is a SET. This is for backward compatibility. Other elements
1838 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1839 flag is set in them. */
1840 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1843 int limit
= XVECLEN (expr
, 0);
1846 /* PARALLELs have strict read-modify-write semantics, so we
1847 ought to evaluate every rvalue before changing any lvalue.
1848 It's cumbersome to do that in general, but there's an
1849 easy approximation that is enough for all current users:
1850 handle register saves before register assignments. */
1851 if (GET_CODE (expr
) == PARALLEL
)
1852 for (par_index
= 0; par_index
< limit
; par_index
++)
1854 elem
= XVECEXP (expr
, 0, par_index
);
1855 if (GET_CODE (elem
) == SET
1856 && MEM_P (SET_DEST (elem
))
1857 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1858 dwarf2out_frame_debug_expr (elem
, label
);
1861 for (par_index
= 0; par_index
< limit
; par_index
++)
1863 elem
= XVECEXP (expr
, 0, par_index
);
1864 if (GET_CODE (elem
) == SET
1865 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1866 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1867 dwarf2out_frame_debug_expr (elem
, label
);
1868 else if (GET_CODE (elem
) == SET
1870 && !RTX_FRAME_RELATED_P (elem
))
1872 /* Stack adjustment combining might combine some post-prologue
1873 stack adjustment into a prologue stack adjustment. */
1874 HOST_WIDE_INT offset
= stack_adjust_offset (elem
);
1877 dwarf2out_args_size_adjust (offset
, label
);
1883 gcc_assert (GET_CODE (expr
) == SET
);
1885 src
= SET_SRC (expr
);
1886 dest
= SET_DEST (expr
);
1890 rtx rsi
= reg_saved_in (src
);
1895 fde
= current_fde ();
1897 if (GET_CODE (src
) == REG
1899 && fde
->drap_reg
== REGNO (src
)
1900 && (fde
->drap_reg_saved
1901 || GET_CODE (dest
) == REG
))
1904 /* If we are saving dynamic realign argument pointer to a
1905 register, the destination is virtual dynamic realign
1906 argument pointer. It may be used to access argument. */
1907 if (GET_CODE (dest
) == REG
)
1909 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
1910 fde
->vdrap_reg
= REGNO (dest
);
1915 switch (GET_CODE (dest
))
1918 switch (GET_CODE (src
))
1920 /* Setting FP from SP. */
1922 if (cfa
.reg
== (unsigned) REGNO (src
))
1925 /* Update the CFA rule wrt SP or FP. Make sure src is
1926 relative to the current CFA register.
1928 We used to require that dest be either SP or FP, but the
1929 ARM copies SP to a temporary register, and from there to
1930 FP. So we just rely on the backends to only set
1931 RTX_FRAME_RELATED_P on appropriate insns. */
1932 cfa
.reg
= REGNO (dest
);
1933 cfa_temp
.reg
= cfa
.reg
;
1934 cfa_temp
.offset
= cfa
.offset
;
1938 /* Saving a register in a register. */
1939 gcc_assert (!fixed_regs
[REGNO (dest
)]
1940 /* For the SPARC and its register window. */
1941 || (DWARF_FRAME_REGNUM (REGNO (src
))
1942 == DWARF_FRAME_RETURN_COLUMN
));
1944 /* After stack is aligned, we can only save SP in FP
1945 if drap register is used. In this case, we have
1946 to restore stack pointer with the CFA value and we
1947 don't generate this DWARF information. */
1949 && fde
->stack_realign
1950 && REGNO (src
) == STACK_POINTER_REGNUM
)
1951 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
1952 && fde
->drap_reg
!= INVALID_REGNUM
1953 && cfa
.reg
!= REGNO (src
));
1955 queue_reg_save (label
, src
, dest
, 0);
1962 if (dest
== stack_pointer_rtx
)
1966 switch (GET_CODE (XEXP (src
, 1)))
1969 offset
= INTVAL (XEXP (src
, 1));
1972 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1974 offset
= cfa_temp
.offset
;
1980 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1982 /* Restoring SP from FP in the epilogue. */
1983 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1984 cfa
.reg
= STACK_POINTER_REGNUM
;
1986 else if (GET_CODE (src
) == LO_SUM
)
1987 /* Assume we've set the source reg of the LO_SUM from sp. */
1990 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1992 if (GET_CODE (src
) != MINUS
)
1994 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1995 cfa
.offset
+= offset
;
1996 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1997 cfa_store
.offset
+= offset
;
1999 else if (dest
== hard_frame_pointer_rtx
)
2002 /* Either setting the FP from an offset of the SP,
2003 or adjusting the FP */
2004 gcc_assert (frame_pointer_needed
);
2006 gcc_assert (REG_P (XEXP (src
, 0))
2007 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2008 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
2009 offset
= INTVAL (XEXP (src
, 1));
2010 if (GET_CODE (src
) != MINUS
)
2012 cfa
.offset
+= offset
;
2013 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2017 gcc_assert (GET_CODE (src
) != MINUS
);
2020 if (REG_P (XEXP (src
, 0))
2021 && REGNO (XEXP (src
, 0)) == cfa
.reg
2022 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2024 /* Setting a temporary CFA register that will be copied
2025 into the FP later on. */
2026 offset
= - INTVAL (XEXP (src
, 1));
2027 cfa
.offset
+= offset
;
2028 cfa
.reg
= REGNO (dest
);
2029 /* Or used to save regs to the stack. */
2030 cfa_temp
.reg
= cfa
.reg
;
2031 cfa_temp
.offset
= cfa
.offset
;
2035 else if (REG_P (XEXP (src
, 0))
2036 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2037 && XEXP (src
, 1) == stack_pointer_rtx
)
2039 /* Setting a scratch register that we will use instead
2040 of SP for saving registers to the stack. */
2041 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2042 cfa_store
.reg
= REGNO (dest
);
2043 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2047 else if (GET_CODE (src
) == LO_SUM
2048 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2050 cfa_temp
.reg
= REGNO (dest
);
2051 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2060 cfa_temp
.reg
= REGNO (dest
);
2061 cfa_temp
.offset
= INTVAL (src
);
2066 gcc_assert (REG_P (XEXP (src
, 0))
2067 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2068 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
2070 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2071 cfa_temp
.reg
= REGNO (dest
);
2072 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2075 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2076 which will fill in all of the bits. */
2083 case UNSPEC_VOLATILE
:
2084 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2085 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2090 /* If this AND operation happens on stack pointer in prologue,
2091 we assume the stack is realigned and we extract the
2093 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2095 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2096 fde
->stack_realign
= 1;
2097 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2098 cfa_store
.offset
= 0;
2100 if (cfa
.reg
!= STACK_POINTER_REGNUM
2101 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2102 fde
->drap_reg
= cfa
.reg
;
2110 def_cfa_1 (label
, &cfa
);
2115 /* Saving a register to the stack. Make sure dest is relative to the
2117 switch (GET_CODE (XEXP (dest
, 0)))
2122 /* We can't handle variable size modifications. */
2123 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2125 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2127 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2128 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2130 cfa_store
.offset
+= offset
;
2131 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2132 cfa
.offset
= cfa_store
.offset
;
2134 offset
= -cfa_store
.offset
;
2140 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2141 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2144 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2145 == STACK_POINTER_REGNUM
)
2146 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2148 cfa_store
.offset
+= offset
;
2150 /* Rule 18: If stack is aligned, we will use FP as a
2151 reference to represent the address of the stored
2154 && fde
->stack_realign
2155 && src
== hard_frame_pointer_rtx
)
2157 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2158 cfa_store
.offset
= 0;
2161 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2162 cfa
.offset
= cfa_store
.offset
;
2164 offset
= -cfa_store
.offset
;
2168 /* With an offset. */
2175 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
2176 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2177 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2178 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2181 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2183 if (cfa_store
.reg
== (unsigned) regno
)
2184 offset
-= cfa_store
.offset
;
2187 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2188 offset
-= cfa_temp
.offset
;
2194 /* Without an offset. */
2197 int regno
= REGNO (XEXP (dest
, 0));
2199 if (cfa_store
.reg
== (unsigned) regno
)
2200 offset
= -cfa_store
.offset
;
2203 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2204 offset
= -cfa_temp
.offset
;
2211 gcc_assert (cfa_temp
.reg
2212 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2213 offset
= -cfa_temp
.offset
;
2214 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2222 /* If the source operand of this MEM operation is not a
2223 register, basically the source is return address. Here
2224 we only care how much stack grew and we don't save it. */
2228 if (REGNO (src
) != STACK_POINTER_REGNUM
2229 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2230 && (unsigned) REGNO (src
) == cfa
.reg
)
2232 /* We're storing the current CFA reg into the stack. */
2234 if (cfa
.offset
== 0)
2237 /* If stack is aligned, putting CFA reg into stack means
2238 we can no longer use reg + offset to represent CFA.
2239 Here we use DW_CFA_def_cfa_expression instead. The
2240 result of this expression equals to the original CFA
2243 && fde
->stack_realign
2244 && cfa
.indirect
== 0
2245 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2247 dw_cfa_location cfa_exp
;
2249 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2251 cfa_exp
.indirect
= 1;
2252 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2253 cfa_exp
.base_offset
= offset
;
2256 fde
->drap_reg_saved
= 1;
2258 def_cfa_1 (label
, &cfa_exp
);
2262 /* If the source register is exactly the CFA, assume
2263 we're saving SP like any other register; this happens
2265 def_cfa_1 (label
, &cfa
);
2266 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2271 /* Otherwise, we'll need to look in the stack to
2272 calculate the CFA. */
2273 rtx x
= XEXP (dest
, 0);
2277 gcc_assert (REG_P (x
));
2279 cfa
.reg
= REGNO (x
);
2280 cfa
.base_offset
= offset
;
2282 def_cfa_1 (label
, &cfa
);
2287 def_cfa_1 (label
, &cfa
);
2289 span
= targetm
.dwarf_register_span (src
);
2292 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2295 /* We have a PARALLEL describing where the contents of SRC
2296 live. Queue register saves for each piece of the
2300 HOST_WIDE_INT span_offset
= offset
;
2302 gcc_assert (GET_CODE (span
) == PARALLEL
);
2304 limit
= XVECLEN (span
, 0);
2305 for (par_index
= 0; par_index
< limit
; par_index
++)
2307 rtx elem
= XVECEXP (span
, 0, par_index
);
2309 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2310 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2321 /* Record call frame debugging information for INSN, which either
2322 sets SP or FP (adjusting how we calculate the frame address) or saves a
2323 register to the stack. If INSN is NULL_RTX, initialize our state.
2325 If AFTER_P is false, we're being called before the insn is emitted,
2326 otherwise after. Call instructions get invoked twice. */
2329 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2334 if (insn
== NULL_RTX
)
2338 /* Flush any queued register saves. */
2339 flush_queued_reg_saves ();
2341 /* Set up state for generating call frame debug info. */
2344 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2346 cfa
.reg
= STACK_POINTER_REGNUM
;
2349 cfa_temp
.offset
= 0;
2351 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2353 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2354 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2356 num_regs_saved_in_regs
= 0;
2358 if (barrier_args_size
)
2360 XDELETEVEC (barrier_args_size
);
2361 barrier_args_size
= NULL
;
2366 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2367 flush_queued_reg_saves ();
2369 if (! RTX_FRAME_RELATED_P (insn
))
2371 if (!ACCUMULATE_OUTGOING_ARGS
)
2372 dwarf2out_stack_adjust (insn
, after_p
);
2376 label
= dwarf2out_cfi_label ();
2377 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
2379 insn
= XEXP (src
, 0);
2381 insn
= PATTERN (insn
);
2383 dwarf2out_frame_debug_expr (insn
, label
);
2388 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2389 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2390 (enum dwarf_call_frame_info cfi
);
2392 static enum dw_cfi_oprnd_type
2393 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2398 case DW_CFA_GNU_window_save
:
2399 return dw_cfi_oprnd_unused
;
2401 case DW_CFA_set_loc
:
2402 case DW_CFA_advance_loc1
:
2403 case DW_CFA_advance_loc2
:
2404 case DW_CFA_advance_loc4
:
2405 case DW_CFA_MIPS_advance_loc8
:
2406 return dw_cfi_oprnd_addr
;
2409 case DW_CFA_offset_extended
:
2410 case DW_CFA_def_cfa
:
2411 case DW_CFA_offset_extended_sf
:
2412 case DW_CFA_def_cfa_sf
:
2413 case DW_CFA_restore_extended
:
2414 case DW_CFA_undefined
:
2415 case DW_CFA_same_value
:
2416 case DW_CFA_def_cfa_register
:
2417 case DW_CFA_register
:
2418 return dw_cfi_oprnd_reg_num
;
2420 case DW_CFA_def_cfa_offset
:
2421 case DW_CFA_GNU_args_size
:
2422 case DW_CFA_def_cfa_offset_sf
:
2423 return dw_cfi_oprnd_offset
;
2425 case DW_CFA_def_cfa_expression
:
2426 case DW_CFA_expression
:
2427 return dw_cfi_oprnd_loc
;
2434 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2435 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2436 (enum dwarf_call_frame_info cfi
);
2438 static enum dw_cfi_oprnd_type
2439 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2443 case DW_CFA_def_cfa
:
2444 case DW_CFA_def_cfa_sf
:
2446 case DW_CFA_offset_extended_sf
:
2447 case DW_CFA_offset_extended
:
2448 return dw_cfi_oprnd_offset
;
2450 case DW_CFA_register
:
2451 return dw_cfi_oprnd_reg_num
;
2454 return dw_cfi_oprnd_unused
;
2458 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2460 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2461 switch to the data section instead, and write out a synthetic label
2465 switch_to_eh_frame_section (void)
2469 #ifdef EH_FRAME_SECTION_NAME
2470 if (eh_frame_section
== 0)
2474 if (EH_TABLES_CAN_BE_READ_ONLY
)
2480 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2482 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2484 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2486 flags
= ((! flag_pic
2487 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2488 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2489 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2490 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2491 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2492 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2493 ? 0 : SECTION_WRITE
);
2496 flags
= SECTION_WRITE
;
2497 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2501 if (eh_frame_section
)
2502 switch_to_section (eh_frame_section
);
2505 /* We have no special eh_frame section. Put the information in
2506 the data section and emit special labels to guide collect2. */
2507 switch_to_section (data_section
);
2508 label
= get_file_function_name ("F");
2509 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2510 targetm
.asm_out
.globalize_label (asm_out_file
,
2511 IDENTIFIER_POINTER (label
));
2512 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2516 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2518 static HOST_WIDE_INT
2519 div_data_align (HOST_WIDE_INT off
)
2521 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
2522 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
2526 /* Output a Call Frame Information opcode and its operand(s). */
2529 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2534 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2535 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2536 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2537 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2538 ((unsigned HOST_WIDE_INT
)
2539 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
2540 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2542 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2543 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2544 "DW_CFA_offset, column 0x%lx", r
);
2545 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2546 dw2_asm_output_data_uleb128 (off
, NULL
);
2548 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2550 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2551 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2552 "DW_CFA_restore, column 0x%lx", r
);
2556 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2557 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2559 switch (cfi
->dw_cfi_opc
)
2561 case DW_CFA_set_loc
:
2563 dw2_asm_output_encoded_addr_rtx (
2564 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2565 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2568 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2569 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2570 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2573 case DW_CFA_advance_loc1
:
2574 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2575 fde
->dw_fde_current_label
, NULL
);
2576 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2579 case DW_CFA_advance_loc2
:
2580 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2581 fde
->dw_fde_current_label
, NULL
);
2582 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2585 case DW_CFA_advance_loc4
:
2586 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2587 fde
->dw_fde_current_label
, NULL
);
2588 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2591 case DW_CFA_MIPS_advance_loc8
:
2592 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2593 fde
->dw_fde_current_label
, NULL
);
2594 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2597 case DW_CFA_offset_extended
:
2598 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2599 dw2_asm_output_data_uleb128 (r
, NULL
);
2600 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2601 dw2_asm_output_data_uleb128 (off
, NULL
);
2604 case DW_CFA_def_cfa
:
2605 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2606 dw2_asm_output_data_uleb128 (r
, NULL
);
2607 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2610 case DW_CFA_offset_extended_sf
:
2611 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2612 dw2_asm_output_data_uleb128 (r
, NULL
);
2613 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2614 dw2_asm_output_data_sleb128 (off
, NULL
);
2617 case DW_CFA_def_cfa_sf
:
2618 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2619 dw2_asm_output_data_uleb128 (r
, NULL
);
2620 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2621 dw2_asm_output_data_sleb128 (off
, NULL
);
2624 case DW_CFA_restore_extended
:
2625 case DW_CFA_undefined
:
2626 case DW_CFA_same_value
:
2627 case DW_CFA_def_cfa_register
:
2628 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2629 dw2_asm_output_data_uleb128 (r
, NULL
);
2632 case DW_CFA_register
:
2633 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2634 dw2_asm_output_data_uleb128 (r
, NULL
);
2635 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2636 dw2_asm_output_data_uleb128 (r
, NULL
);
2639 case DW_CFA_def_cfa_offset
:
2640 case DW_CFA_GNU_args_size
:
2641 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2644 case DW_CFA_def_cfa_offset_sf
:
2645 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2646 dw2_asm_output_data_sleb128 (off
, NULL
);
2649 case DW_CFA_GNU_window_save
:
2652 case DW_CFA_def_cfa_expression
:
2653 case DW_CFA_expression
:
2654 output_cfa_loc (cfi
);
2657 case DW_CFA_GNU_negative_offset_extended
:
2658 /* Obsoleted by DW_CFA_offset_extended_sf. */
2667 /* Similar, but do it via assembler directives instead. */
2670 output_cfi_directive (dw_cfi_ref cfi
)
2672 unsigned long r
, r2
;
2674 switch (cfi
->dw_cfi_opc
)
2676 case DW_CFA_advance_loc
:
2677 case DW_CFA_advance_loc1
:
2678 case DW_CFA_advance_loc2
:
2679 case DW_CFA_advance_loc4
:
2680 case DW_CFA_MIPS_advance_loc8
:
2681 case DW_CFA_set_loc
:
2682 /* Should only be created by add_fde_cfi in a code path not
2683 followed when emitting via directives. The assembler is
2684 going to take care of this for us. */
2688 case DW_CFA_offset_extended
:
2689 case DW_CFA_offset_extended_sf
:
2690 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2691 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
2692 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2695 case DW_CFA_restore
:
2696 case DW_CFA_restore_extended
:
2697 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2698 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
2701 case DW_CFA_undefined
:
2702 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2703 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
2706 case DW_CFA_same_value
:
2707 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2708 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
2711 case DW_CFA_def_cfa
:
2712 case DW_CFA_def_cfa_sf
:
2713 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2714 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
2715 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2718 case DW_CFA_def_cfa_register
:
2719 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2720 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
2723 case DW_CFA_register
:
2724 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2725 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 0);
2726 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
2729 case DW_CFA_def_cfa_offset
:
2730 case DW_CFA_def_cfa_offset_sf
:
2731 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
2732 HOST_WIDE_INT_PRINT_DEC
"\n",
2733 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2736 case DW_CFA_GNU_args_size
:
2737 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size
);
2738 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2740 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
2741 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2742 fputc ('\n', asm_out_file
);
2745 case DW_CFA_GNU_window_save
:
2746 fprintf (asm_out_file
, "\t.cfi_window_save\n");
2749 case DW_CFA_def_cfa_expression
:
2750 case DW_CFA_expression
:
2751 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", cfi
->dw_cfi_opc
);
2752 output_cfa_loc_raw (cfi
);
2753 fputc ('\n', asm_out_file
);
2761 /* Output the call frame information used to record information
2762 that relates to calculating the frame pointer, and records the
2763 location of saved registers. */
2766 output_call_frame_info (int for_eh
)
2771 char l1
[20], l2
[20], section_start_label
[20];
2772 bool any_lsda_needed
= false;
2773 char augmentation
[6];
2774 int augmentation_size
;
2775 int fde_encoding
= DW_EH_PE_absptr
;
2776 int per_encoding
= DW_EH_PE_absptr
;
2777 int lsda_encoding
= DW_EH_PE_absptr
;
2780 /* Don't emit a CIE if there won't be any FDEs. */
2781 if (fde_table_in_use
== 0)
2784 /* Nothing to do if the assembler's doing it all. */
2785 if (dwarf2out_do_cfi_asm ())
2788 /* If we make FDEs linkonce, we may have to emit an empty label for
2789 an FDE that wouldn't otherwise be emitted. We want to avoid
2790 having an FDE kept around when the function it refers to is
2791 discarded. Example where this matters: a primary function
2792 template in C++ requires EH information, but an explicit
2793 specialization doesn't. */
2794 if (TARGET_USES_WEAK_UNWIND_INFO
2795 && ! flag_asynchronous_unwind_tables
2798 for (i
= 0; i
< fde_table_in_use
; i
++)
2799 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2800 && !fde_table
[i
].uses_eh_lsda
2801 && ! DECL_WEAK (fde_table
[i
].decl
))
2802 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2803 for_eh
, /* empty */ 1);
2805 /* If we don't have any functions we'll want to unwind out of, don't
2806 emit any EH unwind information. Note that if exceptions aren't
2807 enabled, we won't have collected nothrow information, and if we
2808 asked for asynchronous tables, we always want this info. */
2811 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2813 for (i
= 0; i
< fde_table_in_use
; i
++)
2814 if (fde_table
[i
].uses_eh_lsda
)
2815 any_eh_needed
= any_lsda_needed
= true;
2816 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2817 any_eh_needed
= true;
2818 else if (! fde_table
[i
].nothrow
2819 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2820 any_eh_needed
= true;
2822 if (! any_eh_needed
)
2826 /* We're going to be generating comments, so turn on app. */
2831 switch_to_eh_frame_section ();
2834 if (!debug_frame_section
)
2835 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
2836 SECTION_DEBUG
, NULL
);
2837 switch_to_section (debug_frame_section
);
2840 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2841 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2843 /* Output the CIE. */
2844 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2845 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2846 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2847 dw2_asm_output_data (4, 0xffffffff,
2848 "Initial length escape value indicating 64-bit DWARF extension");
2849 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2850 "Length of Common Information Entry");
2851 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2853 /* Now that the CIE pointer is PC-relative for EH,
2854 use 0 to identify the CIE. */
2855 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2856 (for_eh
? 0 : DWARF_CIE_ID
),
2857 "CIE Identifier Tag");
2859 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2861 augmentation
[0] = 0;
2862 augmentation_size
= 0;
2868 z Indicates that a uleb128 is present to size the
2869 augmentation section.
2870 L Indicates the encoding (and thus presence) of
2871 an LSDA pointer in the FDE augmentation.
2872 R Indicates a non-default pointer encoding for
2874 P Indicates the presence of an encoding + language
2875 personality routine in the CIE augmentation. */
2877 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2878 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2879 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2881 p
= augmentation
+ 1;
2882 if (eh_personality_libfunc
)
2885 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2886 assemble_external_libcall (eh_personality_libfunc
);
2888 if (any_lsda_needed
)
2891 augmentation_size
+= 1;
2893 if (fde_encoding
!= DW_EH_PE_absptr
)
2896 augmentation_size
+= 1;
2898 if (p
> augmentation
+ 1)
2900 augmentation
[0] = 'z';
2904 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2905 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2907 int offset
= ( 4 /* Length */
2909 + 1 /* CIE version */
2910 + strlen (augmentation
) + 1 /* Augmentation */
2911 + size_of_uleb128 (1) /* Code alignment */
2912 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2914 + 1 /* Augmentation size */
2915 + 1 /* Personality encoding */ );
2916 int pad
= -offset
& (PTR_SIZE
- 1);
2918 augmentation_size
+= pad
;
2920 /* Augmentations should be small, so there's scarce need to
2921 iterate for a solution. Die if we exceed one uleb128 byte. */
2922 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2926 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2927 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2928 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2929 "CIE Data Alignment Factor");
2931 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2932 if (DW_CIE_VERSION
== 1)
2933 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2935 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2937 if (augmentation
[0])
2939 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2940 if (eh_personality_libfunc
)
2942 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2943 eh_data_format_name (per_encoding
));
2944 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2945 eh_personality_libfunc
,
2949 if (any_lsda_needed
)
2950 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2951 eh_data_format_name (lsda_encoding
));
2953 if (fde_encoding
!= DW_EH_PE_absptr
)
2954 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2955 eh_data_format_name (fde_encoding
));
2958 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2959 output_cfi (cfi
, NULL
, for_eh
);
2961 /* Pad the CIE out to an address sized boundary. */
2962 ASM_OUTPUT_ALIGN (asm_out_file
,
2963 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2964 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2966 /* Loop through all of the FDE's. */
2967 for (i
= 0; i
< fde_table_in_use
; i
++)
2969 fde
= &fde_table
[i
];
2971 /* Don't emit EH unwind info for leaf functions that don't need it. */
2972 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2973 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2974 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2975 && !fde
->uses_eh_lsda
)
2978 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2979 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2980 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2981 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2982 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2983 dw2_asm_output_data (4, 0xffffffff,
2984 "Initial length escape value indicating 64-bit DWARF extension");
2985 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2987 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2990 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2992 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2993 debug_frame_section
, "FDE CIE offset");
2997 if (fde
->dw_fde_switched_sections
)
2999 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
3000 fde
->dw_fde_unlikely_section_label
);
3001 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
3002 fde
->dw_fde_hot_section_label
);
3003 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
3004 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
3005 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
3006 "FDE initial location");
3007 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3008 fde
->dw_fde_hot_section_end_label
,
3009 fde
->dw_fde_hot_section_label
,
3010 "FDE address range");
3011 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
3012 "FDE initial location");
3013 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3014 fde
->dw_fde_unlikely_section_end_label
,
3015 fde
->dw_fde_unlikely_section_label
,
3016 "FDE address range");
3020 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
3021 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3022 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
3025 "FDE initial location");
3026 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3027 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3028 "FDE address range");
3033 if (fde
->dw_fde_switched_sections
)
3035 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3036 fde
->dw_fde_hot_section_label
,
3037 "FDE initial location");
3038 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3039 fde
->dw_fde_hot_section_end_label
,
3040 fde
->dw_fde_hot_section_label
,
3041 "FDE address range");
3042 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3043 fde
->dw_fde_unlikely_section_label
,
3044 "FDE initial location");
3045 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3046 fde
->dw_fde_unlikely_section_end_label
,
3047 fde
->dw_fde_unlikely_section_label
,
3048 "FDE address range");
3052 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
3053 "FDE initial location");
3054 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3055 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3056 "FDE address range");
3060 if (augmentation
[0])
3062 if (any_lsda_needed
)
3064 int size
= size_of_encoded_value (lsda_encoding
);
3066 if (lsda_encoding
== DW_EH_PE_aligned
)
3068 int offset
= ( 4 /* Length */
3069 + 4 /* CIE offset */
3070 + 2 * size_of_encoded_value (fde_encoding
)
3071 + 1 /* Augmentation size */ );
3072 int pad
= -offset
& (PTR_SIZE
- 1);
3075 gcc_assert (size_of_uleb128 (size
) == 1);
3078 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3080 if (fde
->uses_eh_lsda
)
3082 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
3083 fde
->funcdef_number
);
3084 dw2_asm_output_encoded_addr_rtx (
3085 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
3086 false, "Language Specific Data Area");
3090 if (lsda_encoding
== DW_EH_PE_aligned
)
3091 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3093 (size_of_encoded_value (lsda_encoding
), 0,
3094 "Language Specific Data Area (none)");
3098 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3101 /* Loop through the Call Frame Instructions associated with
3103 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
3104 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3105 output_cfi (cfi
, fde
, for_eh
);
3107 /* Pad the FDE out to an address sized boundary. */
3108 ASM_OUTPUT_ALIGN (asm_out_file
,
3109 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3110 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3113 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3114 dw2_asm_output_data (4, 0, "End of Table");
3115 #ifdef MIPS_DEBUGGING_INFO
3116 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3117 get a value of 0. Putting .align 0 after the label fixes it. */
3118 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3121 /* Turn off app to make assembly quicker. */
3126 /* Output a marker (i.e. a label) for the beginning of a function, before
3130 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
3131 const char *file ATTRIBUTE_UNUSED
)
3133 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3137 current_function_func_begin_label
= NULL
;
3139 #ifdef TARGET_UNWIND_INFO
3140 /* ??? current_function_func_begin_label is also used by except.c
3141 for call-site information. We must emit this label if it might
3143 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
3144 && ! dwarf2out_do_frame ())
3147 if (! dwarf2out_do_frame ())
3151 switch_to_section (function_section (current_function_decl
));
3152 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
3153 current_function_funcdef_no
);
3154 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
3155 current_function_funcdef_no
);
3156 dup_label
= xstrdup (label
);
3157 current_function_func_begin_label
= dup_label
;
3159 #ifdef TARGET_UNWIND_INFO
3160 /* We can elide the fde allocation if we're not emitting debug info. */
3161 if (! dwarf2out_do_frame ())
3165 /* Expand the fde table if necessary. */
3166 if (fde_table_in_use
== fde_table_allocated
)
3168 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
3169 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
3170 memset (fde_table
+ fde_table_in_use
, 0,
3171 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
3174 /* Record the FDE associated with this function. */
3175 current_funcdef_fde
= fde_table_in_use
;
3177 /* Add the new FDE at the end of the fde_table. */
3178 fde
= &fde_table
[fde_table_in_use
++];
3179 fde
->decl
= current_function_decl
;
3180 fde
->dw_fde_begin
= dup_label
;
3181 fde
->dw_fde_current_label
= dup_label
;
3182 fde
->dw_fde_hot_section_label
= NULL
;
3183 fde
->dw_fde_hot_section_end_label
= NULL
;
3184 fde
->dw_fde_unlikely_section_label
= NULL
;
3185 fde
->dw_fde_unlikely_section_end_label
= NULL
;
3186 fde
->dw_fde_switched_sections
= false;
3187 fde
->dw_fde_end
= NULL
;
3188 fde
->dw_fde_cfi
= NULL
;
3189 fde
->funcdef_number
= current_function_funcdef_no
;
3190 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
3191 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
3192 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
3193 fde
->drap_reg
= INVALID_REGNUM
;
3194 fde
->vdrap_reg
= INVALID_REGNUM
;
3196 args_size
= old_args_size
= 0;
3198 /* We only want to output line number information for the genuine dwarf2
3199 prologue case, not the eh frame case. */
3200 #ifdef DWARF2_DEBUGGING_INFO
3202 dwarf2out_source_line (line
, file
);
3205 if (dwarf2out_do_cfi_asm ())
3210 fprintf (asm_out_file
, "\t.cfi_startproc\n");
3212 if (eh_personality_libfunc
)
3214 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3215 ref
= eh_personality_libfunc
;
3217 /* ??? The GAS support isn't entirely consistent. We have to
3218 handle indirect support ourselves, but PC-relative is done
3219 in the assembler. Further, the assembler can't handle any
3220 of the weirder relocation types. */
3221 if (enc
& DW_EH_PE_indirect
)
3222 ref
= dw2_force_const_mem (ref
, true);
3224 fprintf (asm_out_file
, "\t.cfi_personality 0x%x,", enc
);
3225 output_addr_const (asm_out_file
, ref
);
3226 fputc ('\n', asm_out_file
);
3229 if (crtl
->uses_eh_lsda
)
3233 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3234 ASM_GENERATE_INTERNAL_LABEL (lab
, "LLSDA",
3235 current_function_funcdef_no
);
3236 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
3237 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
3239 if (enc
& DW_EH_PE_indirect
)
3240 ref
= dw2_force_const_mem (ref
, true);
3242 fprintf (asm_out_file
, "\t.cfi_lsda 0x%x,", enc
);
3243 output_addr_const (asm_out_file
, ref
);
3244 fputc ('\n', asm_out_file
);
3249 /* Output a marker (i.e. a label) for the absolute end of the generated code
3250 for a function definition. This gets called *after* the epilogue code has
3254 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
3255 const char *file ATTRIBUTE_UNUSED
)
3258 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3260 if (dwarf2out_do_cfi_asm ())
3261 fprintf (asm_out_file
, "\t.cfi_endproc\n");
3263 /* Output a label to mark the endpoint of the code generated for this
3265 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
3266 current_function_funcdef_no
);
3267 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3268 fde
= current_fde ();
3269 gcc_assert (fde
!= NULL
);
3270 fde
->dw_fde_end
= xstrdup (label
);
3274 dwarf2out_frame_init (void)
3276 /* Allocate the initial hunk of the fde_table. */
3277 fde_table
= GGC_CNEWVEC (dw_fde_node
, FDE_TABLE_INCREMENT
);
3278 fde_table_allocated
= FDE_TABLE_INCREMENT
;
3279 fde_table_in_use
= 0;
3281 /* Generate the CFA instructions common to all FDE's. Do it now for the
3282 sake of lookup_cfa. */
3284 /* On entry, the Canonical Frame Address is at SP. */
3285 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
3287 #ifdef DWARF2_UNWIND_INFO
3288 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
3289 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
3294 dwarf2out_frame_finish (void)
3296 /* Output call frame information. */
3297 if (DWARF2_FRAME_INFO
)
3298 output_call_frame_info (0);
3300 #ifndef TARGET_UNWIND_INFO
3301 /* Output another copy for the unwinder. */
3302 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
3303 output_call_frame_info (1);
3307 /* Note that the current function section is being used for code. */
3310 dwarf2out_note_section_used (void)
3312 section
*sec
= current_function_section ();
3313 if (sec
== text_section
)
3314 text_section_used
= true;
3315 else if (sec
== cold_text_section
)
3316 cold_text_section_used
= true;
3320 dwarf2out_switch_text_section (void)
3322 dw_fde_ref fde
= current_fde ();
3324 gcc_assert (cfun
&& fde
);
3326 fde
->dw_fde_switched_sections
= true;
3327 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
3328 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
3329 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
3330 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
3331 have_multiple_function_sections
= true;
3333 /* Reset the current label on switching text sections, so that we
3334 don't attempt to advance_loc4 between labels in different sections. */
3335 fde
->dw_fde_current_label
= NULL
;
3337 /* There is no need to mark used sections when not debugging. */
3338 if (cold_text_section
!= NULL
)
3339 dwarf2out_note_section_used ();
3343 /* And now, the subset of the debugging information support code necessary
3344 for emitting location expressions. */
3346 /* Data about a single source file. */
3347 struct dwarf_file_data
GTY(())
3349 const char * filename
;
3353 /* We need some way to distinguish DW_OP_addr with a direct symbol
3354 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3355 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3358 typedef struct dw_val_struct
*dw_val_ref
;
3359 typedef struct die_struct
*dw_die_ref
;
3360 typedef const struct die_struct
*const_dw_die_ref
;
3361 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
3362 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
3364 /* Each DIE may have a series of attribute/value pairs. Values
3365 can take on several forms. The forms that are used in this
3366 implementation are listed below. */
3371 dw_val_class_offset
,
3373 dw_val_class_loc_list
,
3374 dw_val_class_range_list
,
3376 dw_val_class_unsigned_const
,
3377 dw_val_class_long_long
,
3380 dw_val_class_die_ref
,
3381 dw_val_class_fde_ref
,
3382 dw_val_class_lbl_id
,
3383 dw_val_class_lineptr
,
3385 dw_val_class_macptr
,
3389 /* Describe a double word constant value. */
3390 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3392 typedef struct dw_long_long_struct
GTY(())
3399 /* Describe a floating point constant value, or a vector constant value. */
3401 typedef struct dw_vec_struct
GTY(())
3403 unsigned char * GTY((length ("%h.length"))) array
;
3409 /* The dw_val_node describes an attribute's value, as it is
3410 represented internally. */
3412 typedef struct dw_val_struct
GTY(())
3414 enum dw_val_class val_class
;
3415 union dw_val_struct_union
3417 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
3418 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
3419 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
3420 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
3421 HOST_WIDE_INT
GTY ((default)) val_int
;
3422 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
3423 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
3424 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
3425 struct dw_val_die_union
3429 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
3430 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
3431 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
3432 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
3433 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
3434 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
3436 GTY ((desc ("%1.val_class"))) v
;
3440 /* Locations in memory are described using a sequence of stack machine
3443 typedef struct dw_loc_descr_struct
GTY(())
3445 dw_loc_descr_ref dw_loc_next
;
3446 enum dwarf_location_atom dw_loc_opc
;
3447 dw_val_node dw_loc_oprnd1
;
3448 dw_val_node dw_loc_oprnd2
;
3453 /* Location lists are ranges + location descriptions for that range,
3454 so you can track variables that are in different places over
3455 their entire life. */
3456 typedef struct dw_loc_list_struct
GTY(())
3458 dw_loc_list_ref dw_loc_next
;
3459 const char *begin
; /* Label for begin address of range */
3460 const char *end
; /* Label for end address of range */
3461 char *ll_symbol
; /* Label for beginning of location list.
3462 Only on head of list */
3463 const char *section
; /* Section this loclist is relative to */
3464 dw_loc_descr_ref expr
;
3467 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3469 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3471 /* Convert a DWARF stack opcode into its string name. */
3474 dwarf_stack_op_name (unsigned int op
)
3479 case INTERNAL_DW_OP_tls_addr
:
3480 return "DW_OP_addr";
3482 return "DW_OP_deref";
3484 return "DW_OP_const1u";
3486 return "DW_OP_const1s";
3488 return "DW_OP_const2u";
3490 return "DW_OP_const2s";
3492 return "DW_OP_const4u";
3494 return "DW_OP_const4s";
3496 return "DW_OP_const8u";
3498 return "DW_OP_const8s";
3500 return "DW_OP_constu";
3502 return "DW_OP_consts";
3506 return "DW_OP_drop";
3508 return "DW_OP_over";
3510 return "DW_OP_pick";
3512 return "DW_OP_swap";
3516 return "DW_OP_xderef";
3524 return "DW_OP_minus";
3536 return "DW_OP_plus";
3537 case DW_OP_plus_uconst
:
3538 return "DW_OP_plus_uconst";
3544 return "DW_OP_shra";
3562 return "DW_OP_skip";
3564 return "DW_OP_lit0";
3566 return "DW_OP_lit1";
3568 return "DW_OP_lit2";
3570 return "DW_OP_lit3";
3572 return "DW_OP_lit4";
3574 return "DW_OP_lit5";
3576 return "DW_OP_lit6";
3578 return "DW_OP_lit7";
3580 return "DW_OP_lit8";
3582 return "DW_OP_lit9";
3584 return "DW_OP_lit10";
3586 return "DW_OP_lit11";
3588 return "DW_OP_lit12";
3590 return "DW_OP_lit13";
3592 return "DW_OP_lit14";
3594 return "DW_OP_lit15";
3596 return "DW_OP_lit16";
3598 return "DW_OP_lit17";
3600 return "DW_OP_lit18";
3602 return "DW_OP_lit19";
3604 return "DW_OP_lit20";
3606 return "DW_OP_lit21";
3608 return "DW_OP_lit22";
3610 return "DW_OP_lit23";
3612 return "DW_OP_lit24";
3614 return "DW_OP_lit25";
3616 return "DW_OP_lit26";
3618 return "DW_OP_lit27";
3620 return "DW_OP_lit28";
3622 return "DW_OP_lit29";
3624 return "DW_OP_lit30";
3626 return "DW_OP_lit31";
3628 return "DW_OP_reg0";
3630 return "DW_OP_reg1";
3632 return "DW_OP_reg2";
3634 return "DW_OP_reg3";
3636 return "DW_OP_reg4";
3638 return "DW_OP_reg5";
3640 return "DW_OP_reg6";
3642 return "DW_OP_reg7";
3644 return "DW_OP_reg8";
3646 return "DW_OP_reg9";
3648 return "DW_OP_reg10";
3650 return "DW_OP_reg11";
3652 return "DW_OP_reg12";
3654 return "DW_OP_reg13";
3656 return "DW_OP_reg14";
3658 return "DW_OP_reg15";
3660 return "DW_OP_reg16";
3662 return "DW_OP_reg17";
3664 return "DW_OP_reg18";
3666 return "DW_OP_reg19";
3668 return "DW_OP_reg20";
3670 return "DW_OP_reg21";
3672 return "DW_OP_reg22";
3674 return "DW_OP_reg23";
3676 return "DW_OP_reg24";
3678 return "DW_OP_reg25";
3680 return "DW_OP_reg26";
3682 return "DW_OP_reg27";
3684 return "DW_OP_reg28";
3686 return "DW_OP_reg29";
3688 return "DW_OP_reg30";
3690 return "DW_OP_reg31";
3692 return "DW_OP_breg0";
3694 return "DW_OP_breg1";
3696 return "DW_OP_breg2";
3698 return "DW_OP_breg3";
3700 return "DW_OP_breg4";
3702 return "DW_OP_breg5";
3704 return "DW_OP_breg6";
3706 return "DW_OP_breg7";
3708 return "DW_OP_breg8";
3710 return "DW_OP_breg9";
3712 return "DW_OP_breg10";
3714 return "DW_OP_breg11";
3716 return "DW_OP_breg12";
3718 return "DW_OP_breg13";
3720 return "DW_OP_breg14";
3722 return "DW_OP_breg15";
3724 return "DW_OP_breg16";
3726 return "DW_OP_breg17";
3728 return "DW_OP_breg18";
3730 return "DW_OP_breg19";
3732 return "DW_OP_breg20";
3734 return "DW_OP_breg21";
3736 return "DW_OP_breg22";
3738 return "DW_OP_breg23";
3740 return "DW_OP_breg24";
3742 return "DW_OP_breg25";
3744 return "DW_OP_breg26";
3746 return "DW_OP_breg27";
3748 return "DW_OP_breg28";
3750 return "DW_OP_breg29";
3752 return "DW_OP_breg30";
3754 return "DW_OP_breg31";
3756 return "DW_OP_regx";
3758 return "DW_OP_fbreg";
3760 return "DW_OP_bregx";
3762 return "DW_OP_piece";
3763 case DW_OP_deref_size
:
3764 return "DW_OP_deref_size";
3765 case DW_OP_xderef_size
:
3766 return "DW_OP_xderef_size";
3769 case DW_OP_push_object_address
:
3770 return "DW_OP_push_object_address";
3772 return "DW_OP_call2";
3774 return "DW_OP_call4";
3775 case DW_OP_call_ref
:
3776 return "DW_OP_call_ref";
3777 case DW_OP_GNU_push_tls_address
:
3778 return "DW_OP_GNU_push_tls_address";
3779 case DW_OP_GNU_uninit
:
3780 return "DW_OP_GNU_uninit";
3782 return "OP_<unknown>";
3786 /* Return a pointer to a newly allocated location description. Location
3787 descriptions are simple expression terms that can be strung
3788 together to form more complicated location (address) descriptions. */
3790 static inline dw_loc_descr_ref
3791 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3792 unsigned HOST_WIDE_INT oprnd2
)
3794 dw_loc_descr_ref descr
= GGC_CNEW (dw_loc_descr_node
);
3796 descr
->dw_loc_opc
= op
;
3797 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3798 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3799 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3800 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3805 /* Return a pointer to a newly allocated location description for
3808 static inline dw_loc_descr_ref
3809 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
3814 return new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
3816 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
3819 return new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
3821 return new_loc_descr (DW_OP_regx
, reg
, 0);
3824 /* Add a location description term to a location description expression. */
3827 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3829 dw_loc_descr_ref
*d
;
3831 /* Find the end of the chain. */
3832 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3838 /* Return the size of a location descriptor. */
3840 static unsigned long
3841 size_of_loc_descr (dw_loc_descr_ref loc
)
3843 unsigned long size
= 1;
3845 switch (loc
->dw_loc_opc
)
3848 case INTERNAL_DW_OP_tls_addr
:
3849 size
+= DWARF2_ADDR_SIZE
;
3868 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3871 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3876 case DW_OP_plus_uconst
:
3877 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3915 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3918 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3921 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3924 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3925 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3928 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3930 case DW_OP_deref_size
:
3931 case DW_OP_xderef_size
:
3940 case DW_OP_call_ref
:
3941 size
+= DWARF2_ADDR_SIZE
;
3950 /* Return the size of a series of location descriptors. */
3952 static unsigned long
3953 size_of_locs (dw_loc_descr_ref loc
)
3958 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3959 field, to avoid writing to a PCH file. */
3960 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3962 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
3964 size
+= size_of_loc_descr (l
);
3969 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3971 l
->dw_loc_addr
= size
;
3972 size
+= size_of_loc_descr (l
);
3978 /* Output location description stack opcode's operands (if any). */
3981 output_loc_operands (dw_loc_descr_ref loc
)
3983 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3984 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3986 switch (loc
->dw_loc_opc
)
3988 #ifdef DWARF2_DEBUGGING_INFO
3990 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3994 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3998 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
4002 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4003 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
4010 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4011 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4013 dw2_asm_output_data (2, offset
, NULL
);
4026 /* We currently don't make any attempt to make sure these are
4027 aligned properly like we do for the main unwind info, so
4028 don't support emitting things larger than a byte if we're
4029 only doing unwinding. */
4034 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4037 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4040 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4043 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4045 case DW_OP_plus_uconst
:
4046 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4080 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4083 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4086 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4089 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4090 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
4093 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4095 case DW_OP_deref_size
:
4096 case DW_OP_xderef_size
:
4097 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4100 case INTERNAL_DW_OP_tls_addr
:
4101 if (targetm
.asm_out
.output_dwarf_dtprel
)
4103 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
4106 fputc ('\n', asm_out_file
);
4113 /* Other codes have no operands. */
4118 /* Output a sequence of location operations. */
4121 output_loc_sequence (dw_loc_descr_ref loc
)
4123 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4125 /* Output the opcode. */
4126 dw2_asm_output_data (1, loc
->dw_loc_opc
,
4127 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
4129 /* Output the operand(s) (if any). */
4130 output_loc_operands (loc
);
4134 /* Output location description stack opcode's operands (if any).
4135 The output is single bytes on a line, suitable for .cfi_escape. */
4138 output_loc_operands_raw (dw_loc_descr_ref loc
)
4140 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4141 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4143 switch (loc
->dw_loc_opc
)
4146 /* We cannot output addresses in .cfi_escape, only bytes. */
4152 case DW_OP_deref_size
:
4153 case DW_OP_xderef_size
:
4154 fputc (',', asm_out_file
);
4155 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
4160 fputc (',', asm_out_file
);
4161 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
4166 fputc (',', asm_out_file
);
4167 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
4172 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4173 fputc (',', asm_out_file
);
4174 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
4182 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4183 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4185 fputc (',', asm_out_file
);
4186 dw2_asm_output_data_raw (2, offset
);
4191 case DW_OP_plus_uconst
:
4194 fputc (',', asm_out_file
);
4195 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4232 fputc (',', asm_out_file
);
4233 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
4237 fputc (',', asm_out_file
);
4238 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4239 fputc (',', asm_out_file
);
4240 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
4243 case INTERNAL_DW_OP_tls_addr
:
4247 /* Other codes have no operands. */
4253 output_loc_sequence_raw (dw_loc_descr_ref loc
)
4257 /* Output the opcode. */
4258 fprintf (asm_out_file
, "0x%x", loc
->dw_loc_opc
);
4259 output_loc_operands_raw (loc
);
4261 if (!loc
->dw_loc_next
)
4263 loc
= loc
->dw_loc_next
;
4265 fputc (',', asm_out_file
);
4269 /* This routine will generate the correct assembly data for a location
4270 description based on a cfi entry with a complex address. */
4273 output_cfa_loc (dw_cfi_ref cfi
)
4275 dw_loc_descr_ref loc
;
4278 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4279 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, NULL
);
4281 /* Output the size of the block. */
4282 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4283 size
= size_of_locs (loc
);
4284 dw2_asm_output_data_uleb128 (size
, NULL
);
4286 /* Now output the operations themselves. */
4287 output_loc_sequence (loc
);
4290 /* Similar, but used for .cfi_escape. */
4293 output_cfa_loc_raw (dw_cfi_ref cfi
)
4295 dw_loc_descr_ref loc
;
4298 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4299 fprintf (asm_out_file
, "0x%x,", cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
4301 /* Output the size of the block. */
4302 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4303 size
= size_of_locs (loc
);
4304 dw2_asm_output_data_uleb128_raw (size
);
4305 fputc (',', asm_out_file
);
4307 /* Now output the operations themselves. */
4308 output_loc_sequence_raw (loc
);
4311 /* This function builds a dwarf location descriptor sequence from a
4312 dw_cfa_location, adding the given OFFSET to the result of the
4315 static struct dw_loc_descr_struct
*
4316 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
4318 struct dw_loc_descr_struct
*head
, *tmp
;
4320 offset
+= cfa
->offset
;
4324 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
4325 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
4326 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
4327 add_loc_descr (&head
, tmp
);
4330 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4331 add_loc_descr (&head
, tmp
);
4335 head
= new_reg_loc_descr (cfa
->reg
, offset
);
4340 /* This function builds a dwarf location descriptor sequence for
4341 the address at OFFSET from the CFA when stack is aligned to
4344 static struct dw_loc_descr_struct
*
4345 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
4347 struct dw_loc_descr_struct
*head
;
4348 unsigned int dwarf_fp
4349 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
4351 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4352 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
4354 head
= new_reg_loc_descr (dwarf_fp
, 0);
4355 add_loc_descr (&head
, int_loc_descriptor (alignment
));
4356 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
4358 add_loc_descr (&head
, int_loc_descriptor (offset
));
4359 add_loc_descr (&head
, new_loc_descr (DW_OP_plus
, 0, 0));
4362 head
= new_reg_loc_descr (dwarf_fp
, offset
);
4366 /* This function fills in aa dw_cfa_location structure from a dwarf location
4367 descriptor sequence. */
4370 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
4372 struct dw_loc_descr_struct
*ptr
;
4374 cfa
->base_offset
= 0;
4378 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
4380 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
4416 cfa
->reg
= op
- DW_OP_reg0
;
4419 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4453 cfa
->reg
= op
- DW_OP_breg0
;
4454 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4457 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4458 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
4463 case DW_OP_plus_uconst
:
4464 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
4467 internal_error ("DW_LOC_OP %s not implemented",
4468 dwarf_stack_op_name (ptr
->dw_loc_opc
));
4472 #endif /* .debug_frame support */
4474 /* And now, the support for symbolic debugging information. */
4475 #ifdef DWARF2_DEBUGGING_INFO
4477 /* .debug_str support. */
4478 static int output_indirect_string (void **, void *);
4480 static void dwarf2out_init (const char *);
4481 static void dwarf2out_finish (const char *);
4482 static void dwarf2out_define (unsigned int, const char *);
4483 static void dwarf2out_undef (unsigned int, const char *);
4484 static void dwarf2out_start_source_file (unsigned, const char *);
4485 static void dwarf2out_end_source_file (unsigned);
4486 static void dwarf2out_begin_block (unsigned, unsigned);
4487 static void dwarf2out_end_block (unsigned, unsigned);
4488 static bool dwarf2out_ignore_block (const_tree
);
4489 static void dwarf2out_global_decl (tree
);
4490 static void dwarf2out_type_decl (tree
, int);
4491 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
4492 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
4494 static void dwarf2out_abstract_function (tree
);
4495 static void dwarf2out_var_location (rtx
);
4496 static void dwarf2out_begin_function (tree
);
4498 /* The debug hooks structure. */
4500 const struct gcc_debug_hooks dwarf2_debug_hooks
=
4506 dwarf2out_start_source_file
,
4507 dwarf2out_end_source_file
,
4508 dwarf2out_begin_block
,
4509 dwarf2out_end_block
,
4510 dwarf2out_ignore_block
,
4511 dwarf2out_source_line
,
4512 dwarf2out_begin_prologue
,
4513 debug_nothing_int_charstar
, /* end_prologue */
4514 dwarf2out_end_epilogue
,
4515 dwarf2out_begin_function
,
4516 debug_nothing_int
, /* end_function */
4517 dwarf2out_decl
, /* function_decl */
4518 dwarf2out_global_decl
,
4519 dwarf2out_type_decl
, /* type_decl */
4520 dwarf2out_imported_module_or_decl
,
4521 debug_nothing_tree
, /* deferred_inline_function */
4522 /* The DWARF 2 backend tries to reduce debugging bloat by not
4523 emitting the abstract description of inline functions until
4524 something tries to reference them. */
4525 dwarf2out_abstract_function
, /* outlining_inline_function */
4526 debug_nothing_rtx
, /* label */
4527 debug_nothing_int
, /* handle_pch */
4528 dwarf2out_var_location
,
4529 dwarf2out_switch_text_section
,
4530 1 /* start_end_main_source_file */
4534 /* NOTE: In the comments in this file, many references are made to
4535 "Debugging Information Entries". This term is abbreviated as `DIE'
4536 throughout the remainder of this file. */
4538 /* An internal representation of the DWARF output is built, and then
4539 walked to generate the DWARF debugging info. The walk of the internal
4540 representation is done after the entire program has been compiled.
4541 The types below are used to describe the internal representation. */
4543 /* Various DIE's use offsets relative to the beginning of the
4544 .debug_info section to refer to each other. */
4546 typedef long int dw_offset
;
4548 /* Define typedefs here to avoid circular dependencies. */
4550 typedef struct dw_attr_struct
*dw_attr_ref
;
4551 typedef struct dw_line_info_struct
*dw_line_info_ref
;
4552 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
4553 typedef struct pubname_struct
*pubname_ref
;
4554 typedef struct dw_ranges_struct
*dw_ranges_ref
;
4555 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
4557 /* Each entry in the line_info_table maintains the file and
4558 line number associated with the label generated for that
4559 entry. The label gives the PC value associated with
4560 the line number entry. */
4562 typedef struct dw_line_info_struct
GTY(())
4564 unsigned long dw_file_num
;
4565 unsigned long dw_line_num
;
4569 /* Line information for functions in separate sections; each one gets its
4571 typedef struct dw_separate_line_info_struct
GTY(())
4573 unsigned long dw_file_num
;
4574 unsigned long dw_line_num
;
4575 unsigned long function
;
4577 dw_separate_line_info_entry
;
4579 /* Each DIE attribute has a field specifying the attribute kind,
4580 a link to the next attribute in the chain, and an attribute value.
4581 Attributes are typically linked below the DIE they modify. */
4583 typedef struct dw_attr_struct
GTY(())
4585 enum dwarf_attribute dw_attr
;
4586 dw_val_node dw_attr_val
;
4590 DEF_VEC_O(dw_attr_node
);
4591 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
4593 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4594 The children of each node form a circular list linked by
4595 die_sib. die_child points to the node *before* the "first" child node. */
4597 typedef struct die_struct
GTY((chain_circular ("%h.die_sib")))
4599 enum dwarf_tag die_tag
;
4601 VEC(dw_attr_node
,gc
) * die_attr
;
4602 dw_die_ref die_parent
;
4603 dw_die_ref die_child
;
4605 dw_die_ref die_definition
; /* ref from a specification to its definition */
4606 dw_offset die_offset
;
4607 unsigned long die_abbrev
;
4609 /* Die is used and must not be pruned as unused. */
4610 int die_perennial_p
;
4611 unsigned int decl_id
;
4615 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4616 #define FOR_EACH_CHILD(die, c, expr) do { \
4617 c = die->die_child; \
4621 } while (c != die->die_child); \
4624 /* The pubname structure */
4626 typedef struct pubname_struct
GTY(())
4633 DEF_VEC_O(pubname_entry
);
4634 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
4636 struct dw_ranges_struct
GTY(())
4638 /* If this is positive, it's a block number, otherwise it's a
4639 bitwise-negated index into dw_ranges_by_label. */
4643 struct dw_ranges_by_label_struct
GTY(())
4649 /* The limbo die list structure. */
4650 typedef struct limbo_die_struct
GTY(())
4654 struct limbo_die_struct
*next
;
4658 /* How to start an assembler comment. */
4659 #ifndef ASM_COMMENT_START
4660 #define ASM_COMMENT_START ";#"
4663 /* Define a macro which returns nonzero for a TYPE_DECL which was
4664 implicitly generated for a tagged type.
4666 Note that unlike the gcc front end (which generates a NULL named
4667 TYPE_DECL node for each complete tagged type, each array type, and
4668 each function type node created) the g++ front end generates a
4669 _named_ TYPE_DECL node for each tagged type node created.
4670 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4671 generate a DW_TAG_typedef DIE for them. */
4673 #define TYPE_DECL_IS_STUB(decl) \
4674 (DECL_NAME (decl) == NULL_TREE \
4675 || (DECL_ARTIFICIAL (decl) \
4676 && is_tagged_type (TREE_TYPE (decl)) \
4677 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4678 /* This is necessary for stub decls that \
4679 appear in nested inline functions. */ \
4680 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4681 && (decl_ultimate_origin (decl) \
4682 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4684 /* Information concerning the compilation unit's programming
4685 language, and compiler version. */
4687 /* Fixed size portion of the DWARF compilation unit header. */
4688 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4689 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4691 /* Fixed size portion of public names info. */
4692 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4694 /* Fixed size portion of the address range info. */
4695 #define DWARF_ARANGES_HEADER_SIZE \
4696 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4697 DWARF2_ADDR_SIZE * 2) \
4698 - DWARF_INITIAL_LENGTH_SIZE)
4700 /* Size of padding portion in the address range info. It must be
4701 aligned to twice the pointer size. */
4702 #define DWARF_ARANGES_PAD_SIZE \
4703 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4704 DWARF2_ADDR_SIZE * 2) \
4705 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4707 /* Use assembler line directives if available. */
4708 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4709 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4710 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4712 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4716 /* Minimum line offset in a special line info. opcode.
4717 This value was chosen to give a reasonable range of values. */
4718 #define DWARF_LINE_BASE -10
4720 /* First special line opcode - leave room for the standard opcodes. */
4721 #define DWARF_LINE_OPCODE_BASE 10
4723 /* Range of line offsets in a special line info. opcode. */
4724 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4726 /* Flag that indicates the initial value of the is_stmt_start flag.
4727 In the present implementation, we do not mark any lines as
4728 the beginning of a source statement, because that information
4729 is not made available by the GCC front-end. */
4730 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4732 #ifdef DWARF2_DEBUGGING_INFO
4733 /* This location is used by calc_die_sizes() to keep track
4734 the offset of each DIE within the .debug_info section. */
4735 static unsigned long next_die_offset
;
4738 /* Record the root of the DIE's built for the current compilation unit. */
4739 static GTY(()) dw_die_ref comp_unit_die
;
4741 /* A list of DIEs with a NULL parent waiting to be relocated. */
4742 static GTY(()) limbo_die_node
*limbo_die_list
;
4744 /* Filenames referenced by this compilation unit. */
4745 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
4747 /* A hash table of references to DIE's that describe declarations.
4748 The key is a DECL_UID() which is a unique number identifying each decl. */
4749 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
4751 /* Node of the variable location list. */
4752 struct var_loc_node
GTY ((chain_next ("%h.next")))
4754 rtx
GTY (()) var_loc_note
;
4755 const char * GTY (()) label
;
4756 const char * GTY (()) section_label
;
4757 struct var_loc_node
* GTY (()) next
;
4760 /* Variable location list. */
4761 struct var_loc_list_def
GTY (())
4763 struct var_loc_node
* GTY (()) first
;
4765 /* Do not mark the last element of the chained list because
4766 it is marked through the chain. */
4767 struct var_loc_node
* GTY ((skip ("%h"))) last
;
4769 /* DECL_UID of the variable decl. */
4770 unsigned int decl_id
;
4772 typedef struct var_loc_list_def var_loc_list
;
4775 /* Table of decl location linked lists. */
4776 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
4778 /* A pointer to the base of a list of references to DIE's that
4779 are uniquely identified by their tag, presence/absence of
4780 children DIE's, and list of attribute/value pairs. */
4781 static GTY((length ("abbrev_die_table_allocated")))
4782 dw_die_ref
*abbrev_die_table
;
4784 /* Number of elements currently allocated for abbrev_die_table. */
4785 static GTY(()) unsigned abbrev_die_table_allocated
;
4787 /* Number of elements in type_die_table currently in use. */
4788 static GTY(()) unsigned abbrev_die_table_in_use
;
4790 /* Size (in elements) of increments by which we may expand the
4791 abbrev_die_table. */
4792 #define ABBREV_DIE_TABLE_INCREMENT 256
4794 /* A pointer to the base of a table that contains line information
4795 for each source code line in .text in the compilation unit. */
4796 static GTY((length ("line_info_table_allocated")))
4797 dw_line_info_ref line_info_table
;
4799 /* Number of elements currently allocated for line_info_table. */
4800 static GTY(()) unsigned line_info_table_allocated
;
4802 /* Number of elements in line_info_table currently in use. */
4803 static GTY(()) unsigned line_info_table_in_use
;
4805 /* A pointer to the base of a table that contains line information
4806 for each source code line outside of .text in the compilation unit. */
4807 static GTY ((length ("separate_line_info_table_allocated")))
4808 dw_separate_line_info_ref separate_line_info_table
;
4810 /* Number of elements currently allocated for separate_line_info_table. */
4811 static GTY(()) unsigned separate_line_info_table_allocated
;
4813 /* Number of elements in separate_line_info_table currently in use. */
4814 static GTY(()) unsigned separate_line_info_table_in_use
;
4816 /* Size (in elements) of increments by which we may expand the
4818 #define LINE_INFO_TABLE_INCREMENT 1024
4820 /* A pointer to the base of a table that contains a list of publicly
4821 accessible names. */
4822 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
4824 /* A pointer to the base of a table that contains a list of publicly
4825 accessible types. */
4826 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
4828 /* Array of dies for which we should generate .debug_arange info. */
4829 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
4831 /* Number of elements currently allocated for arange_table. */
4832 static GTY(()) unsigned arange_table_allocated
;
4834 /* Number of elements in arange_table currently in use. */
4835 static GTY(()) unsigned arange_table_in_use
;
4837 /* Size (in elements) of increments by which we may expand the
4839 #define ARANGE_TABLE_INCREMENT 64
4841 /* Array of dies for which we should generate .debug_ranges info. */
4842 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
4844 /* Number of elements currently allocated for ranges_table. */
4845 static GTY(()) unsigned ranges_table_allocated
;
4847 /* Number of elements in ranges_table currently in use. */
4848 static GTY(()) unsigned ranges_table_in_use
;
4850 /* Array of pairs of labels referenced in ranges_table. */
4851 static GTY ((length ("ranges_by_label_allocated")))
4852 dw_ranges_by_label_ref ranges_by_label
;
4854 /* Number of elements currently allocated for ranges_by_label. */
4855 static GTY(()) unsigned ranges_by_label_allocated
;
4857 /* Number of elements in ranges_by_label currently in use. */
4858 static GTY(()) unsigned ranges_by_label_in_use
;
4860 /* Size (in elements) of increments by which we may expand the
4862 #define RANGES_TABLE_INCREMENT 64
4864 /* Whether we have location lists that need outputting */
4865 static GTY(()) bool have_location_lists
;
4867 /* Unique label counter. */
4868 static GTY(()) unsigned int loclabel_num
;
4870 #ifdef DWARF2_DEBUGGING_INFO
4871 /* Record whether the function being analyzed contains inlined functions. */
4872 static int current_function_has_inlines
;
4874 #if 0 && defined (MIPS_DEBUGGING_INFO)
4875 static int comp_unit_has_inlines
;
4878 /* The last file entry emitted by maybe_emit_file(). */
4879 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
4881 /* Number of internal labels generated by gen_internal_sym(). */
4882 static GTY(()) int label_num
;
4884 /* Cached result of previous call to lookup_filename. */
4885 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
4887 #ifdef DWARF2_DEBUGGING_INFO
4889 /* Offset from the "steady-state frame pointer" to the frame base,
4890 within the current function. */
4891 static HOST_WIDE_INT frame_pointer_fb_offset
;
4893 /* Forward declarations for functions defined in this file. */
4895 static int is_pseudo_reg (const_rtx
);
4896 static tree
type_main_variant (tree
);
4897 static int is_tagged_type (const_tree
);
4898 static const char *dwarf_tag_name (unsigned);
4899 static const char *dwarf_attr_name (unsigned);
4900 static const char *dwarf_form_name (unsigned);
4901 static tree
decl_ultimate_origin (const_tree
);
4902 static tree
block_ultimate_origin (const_tree
);
4903 static tree
decl_class_context (tree
);
4904 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
4905 static inline enum dw_val_class
AT_class (dw_attr_ref
);
4906 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
4907 static inline unsigned AT_flag (dw_attr_ref
);
4908 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
4909 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
4910 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
4911 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
4912 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
4914 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
4915 unsigned int, unsigned char *);
4916 static hashval_t
debug_str_do_hash (const void *);
4917 static int debug_str_eq (const void *, const void *);
4918 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
4919 static inline const char *AT_string (dw_attr_ref
);
4920 static int AT_string_form (dw_attr_ref
);
4921 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
4922 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
4923 static inline dw_die_ref
AT_ref (dw_attr_ref
);
4924 static inline int AT_ref_external (dw_attr_ref
);
4925 static inline void set_AT_ref_external (dw_attr_ref
, int);
4926 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
4927 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
4928 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
4929 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
4931 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
4932 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
4933 static inline rtx
AT_addr (dw_attr_ref
);
4934 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
4935 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4936 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4937 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
4938 unsigned HOST_WIDE_INT
);
4939 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
4941 static inline const char *AT_lbl (dw_attr_ref
);
4942 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
4943 static const char *get_AT_low_pc (dw_die_ref
);
4944 static const char *get_AT_hi_pc (dw_die_ref
);
4945 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4946 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4947 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4948 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4949 static bool is_c_family (void);
4950 static bool is_cxx (void);
4951 static bool is_java (void);
4952 static bool is_fortran (void);
4953 static bool is_ada (void);
4954 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4955 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4956 static void add_child_die (dw_die_ref
, dw_die_ref
);
4957 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4958 static dw_die_ref
lookup_type_die (tree
);
4959 static void equate_type_number_to_die (tree
, dw_die_ref
);
4960 static hashval_t
decl_die_table_hash (const void *);
4961 static int decl_die_table_eq (const void *, const void *);
4962 static dw_die_ref
lookup_decl_die (tree
);
4963 static hashval_t
decl_loc_table_hash (const void *);
4964 static int decl_loc_table_eq (const void *, const void *);
4965 static var_loc_list
*lookup_decl_loc (const_tree
);
4966 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4967 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4968 static void print_spaces (FILE *);
4969 static void print_die (dw_die_ref
, FILE *);
4970 static void print_dwarf_line_table (FILE *);
4971 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4972 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4973 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4974 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4975 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4976 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4977 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
4978 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4979 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4980 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4981 static void compute_section_prefix (dw_die_ref
);
4982 static int is_type_die (dw_die_ref
);
4983 static int is_comdat_die (dw_die_ref
);
4984 static int is_symbol_die (dw_die_ref
);
4985 static void assign_symbol_names (dw_die_ref
);
4986 static void break_out_includes (dw_die_ref
);
4987 static hashval_t
htab_cu_hash (const void *);
4988 static int htab_cu_eq (const void *, const void *);
4989 static void htab_cu_del (void *);
4990 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4991 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4992 static void add_sibling_attributes (dw_die_ref
);
4993 static void build_abbrev_table (dw_die_ref
);
4994 static void output_location_lists (dw_die_ref
);
4995 static int constant_size (unsigned HOST_WIDE_INT
);
4996 static unsigned long size_of_die (dw_die_ref
);
4997 static void calc_die_sizes (dw_die_ref
);
4998 static void mark_dies (dw_die_ref
);
4999 static void unmark_dies (dw_die_ref
);
5000 static void unmark_all_dies (dw_die_ref
);
5001 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
5002 static unsigned long size_of_aranges (void);
5003 static enum dwarf_form
value_format (dw_attr_ref
);
5004 static void output_value_format (dw_attr_ref
);
5005 static void output_abbrev_section (void);
5006 static void output_die_symbol (dw_die_ref
);
5007 static void output_die (dw_die_ref
);
5008 static void output_compilation_unit_header (void);
5009 static void output_comp_unit (dw_die_ref
, int);
5010 static const char *dwarf2_name (tree
, int);
5011 static void add_pubname (tree
, dw_die_ref
);
5012 static void add_pubname_string (const char *, dw_die_ref
);
5013 static void add_pubtype (tree
, dw_die_ref
);
5014 static void output_pubnames (VEC (pubname_entry
,gc
) *);
5015 static void add_arange (tree
, dw_die_ref
);
5016 static void output_aranges (void);
5017 static unsigned int add_ranges_num (int);
5018 static unsigned int add_ranges (const_tree
);
5019 static unsigned int add_ranges_by_labels (const char *, const char *);
5020 static void output_ranges (void);
5021 static void output_line_info (void);
5022 static void output_file_names (void);
5023 static dw_die_ref
base_type_die (tree
);
5024 static int is_base_type (tree
);
5025 static bool is_subrange_type (const_tree
);
5026 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
5027 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
5028 static int type_is_enum (const_tree
);
5029 static unsigned int dbx_reg_number (const_rtx
);
5030 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
5031 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
5032 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
5033 enum var_init_status
);
5034 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
5035 enum var_init_status
);
5036 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
5037 enum var_init_status
);
5038 static int is_based_loc (const_rtx
);
5039 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
5040 enum var_init_status
);
5041 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
5042 enum var_init_status
);
5043 static dw_loc_descr_ref
loc_descriptor (rtx
, enum var_init_status
);
5044 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
5045 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
5046 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
5047 static tree
field_type (const_tree
);
5048 static unsigned int simple_type_align_in_bits (const_tree
);
5049 static unsigned int simple_decl_align_in_bits (const_tree
);
5050 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
5051 static HOST_WIDE_INT
field_byte_offset (const_tree
);
5052 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
5054 static void add_data_member_location_attribute (dw_die_ref
, tree
);
5055 static void add_const_value_attribute (dw_die_ref
, rtx
);
5056 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
5057 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
5058 static void insert_float (const_rtx
, unsigned char *);
5059 static rtx
rtl_for_decl_location (tree
);
5060 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
5061 enum dwarf_attribute
);
5062 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
5063 static void add_name_attribute (dw_die_ref
, const char *);
5064 static void add_comp_dir_attribute (dw_die_ref
);
5065 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
5066 static void add_subscript_info (dw_die_ref
, tree
, bool);
5067 static void add_byte_size_attribute (dw_die_ref
, tree
);
5068 static void add_bit_offset_attribute (dw_die_ref
, tree
);
5069 static void add_bit_size_attribute (dw_die_ref
, tree
);
5070 static void add_prototyped_attribute (dw_die_ref
, tree
);
5071 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
5072 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
5073 static void add_src_coords_attributes (dw_die_ref
, tree
);
5074 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
5075 static void push_decl_scope (tree
);
5076 static void pop_decl_scope (void);
5077 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
5078 static inline int local_scope_p (dw_die_ref
);
5079 static inline int class_or_namespace_scope_p (dw_die_ref
);
5080 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
5081 static void add_calling_convention_attribute (dw_die_ref
, tree
);
5082 static const char *type_tag (const_tree
);
5083 static tree
member_declared_type (const_tree
);
5085 static const char *decl_start_label (tree
);
5087 static void gen_array_type_die (tree
, dw_die_ref
);
5088 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
5090 static void gen_entry_point_die (tree
, dw_die_ref
);
5092 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
5093 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
5094 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
5095 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
5096 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
5097 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
5098 static void gen_formal_types_die (tree
, dw_die_ref
);
5099 static void gen_subprogram_die (tree
, dw_die_ref
);
5100 static void gen_variable_die (tree
, dw_die_ref
);
5101 static void gen_const_die (tree
, dw_die_ref
);
5102 static void gen_label_die (tree
, dw_die_ref
);
5103 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
5104 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
5105 static void gen_field_die (tree
, dw_die_ref
);
5106 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
5107 static dw_die_ref
gen_compile_unit_die (const char *);
5108 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
5109 static void gen_member_die (tree
, dw_die_ref
);
5110 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
5111 enum debug_info_usage
);
5112 static void gen_subroutine_type_die (tree
, dw_die_ref
);
5113 static void gen_typedef_die (tree
, dw_die_ref
);
5114 static void gen_type_die (tree
, dw_die_ref
);
5115 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
5116 static void gen_block_die (tree
, dw_die_ref
, int);
5117 static void decls_for_scope (tree
, dw_die_ref
, int);
5118 static int is_redundant_typedef (const_tree
);
5119 static void gen_namespace_die (tree
);
5120 static void gen_decl_die (tree
, dw_die_ref
);
5121 static dw_die_ref
force_decl_die (tree
);
5122 static dw_die_ref
force_type_die (tree
);
5123 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
5124 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
5125 static struct dwarf_file_data
* lookup_filename (const char *);
5126 static void retry_incomplete_types (void);
5127 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
5128 static void splice_child_die (dw_die_ref
, dw_die_ref
);
5129 static int file_info_cmp (const void *, const void *);
5130 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
5131 const char *, const char *, unsigned);
5132 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
5133 const char *, const char *,
5135 static void output_loc_list (dw_loc_list_ref
);
5136 static char *gen_internal_sym (const char *);
5138 static void prune_unmark_dies (dw_die_ref
);
5139 static void prune_unused_types_mark (dw_die_ref
, int);
5140 static void prune_unused_types_walk (dw_die_ref
);
5141 static void prune_unused_types_walk_attribs (dw_die_ref
);
5142 static void prune_unused_types_prune (dw_die_ref
);
5143 static void prune_unused_types (void);
5144 static int maybe_emit_file (struct dwarf_file_data
*fd
);
5146 /* Section names used to hold DWARF debugging information. */
5147 #ifndef DEBUG_INFO_SECTION
5148 #define DEBUG_INFO_SECTION ".debug_info"
5150 #ifndef DEBUG_ABBREV_SECTION
5151 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5153 #ifndef DEBUG_ARANGES_SECTION
5154 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5156 #ifndef DEBUG_MACINFO_SECTION
5157 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5159 #ifndef DEBUG_LINE_SECTION
5160 #define DEBUG_LINE_SECTION ".debug_line"
5162 #ifndef DEBUG_LOC_SECTION
5163 #define DEBUG_LOC_SECTION ".debug_loc"
5165 #ifndef DEBUG_PUBNAMES_SECTION
5166 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5168 #ifndef DEBUG_STR_SECTION
5169 #define DEBUG_STR_SECTION ".debug_str"
5171 #ifndef DEBUG_RANGES_SECTION
5172 #define DEBUG_RANGES_SECTION ".debug_ranges"
5175 /* Standard ELF section names for compiled code and data. */
5176 #ifndef TEXT_SECTION_NAME
5177 #define TEXT_SECTION_NAME ".text"
5180 /* Section flags for .debug_str section. */
5181 #define DEBUG_STR_SECTION_FLAGS \
5182 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5183 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5186 /* Labels we insert at beginning sections we can reference instead of
5187 the section names themselves. */
5189 #ifndef TEXT_SECTION_LABEL
5190 #define TEXT_SECTION_LABEL "Ltext"
5192 #ifndef COLD_TEXT_SECTION_LABEL
5193 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5195 #ifndef DEBUG_LINE_SECTION_LABEL
5196 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5198 #ifndef DEBUG_INFO_SECTION_LABEL
5199 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5201 #ifndef DEBUG_ABBREV_SECTION_LABEL
5202 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5204 #ifndef DEBUG_LOC_SECTION_LABEL
5205 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5207 #ifndef DEBUG_RANGES_SECTION_LABEL
5208 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5210 #ifndef DEBUG_MACINFO_SECTION_LABEL
5211 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5214 /* Definitions of defaults for formats and names of various special
5215 (artificial) labels which may be generated within this file (when the -g
5216 options is used and DWARF2_DEBUGGING_INFO is in effect.
5217 If necessary, these may be overridden from within the tm.h file, but
5218 typically, overriding these defaults is unnecessary. */
5220 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5221 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5222 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5223 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5224 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5225 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5226 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5227 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5228 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5229 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
5231 #ifndef TEXT_END_LABEL
5232 #define TEXT_END_LABEL "Letext"
5234 #ifndef COLD_END_LABEL
5235 #define COLD_END_LABEL "Letext_cold"
5237 #ifndef BLOCK_BEGIN_LABEL
5238 #define BLOCK_BEGIN_LABEL "LBB"
5240 #ifndef BLOCK_END_LABEL
5241 #define BLOCK_END_LABEL "LBE"
5243 #ifndef LINE_CODE_LABEL
5244 #define LINE_CODE_LABEL "LM"
5246 #ifndef SEPARATE_LINE_CODE_LABEL
5247 #define SEPARATE_LINE_CODE_LABEL "LSM"
5251 /* We allow a language front-end to designate a function that is to be
5252 called to "demangle" any name before it is put into a DIE. */
5254 static const char *(*demangle_name_func
) (const char *);
5257 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
5259 demangle_name_func
= func
;
5262 /* Test if rtl node points to a pseudo register. */
5265 is_pseudo_reg (const_rtx rtl
)
5267 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
5268 || (GET_CODE (rtl
) == SUBREG
5269 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
5272 /* Return a reference to a type, with its const and volatile qualifiers
5276 type_main_variant (tree type
)
5278 type
= TYPE_MAIN_VARIANT (type
);
5280 /* ??? There really should be only one main variant among any group of
5281 variants of a given type (and all of the MAIN_VARIANT values for all
5282 members of the group should point to that one type) but sometimes the C
5283 front-end messes this up for array types, so we work around that bug
5285 if (TREE_CODE (type
) == ARRAY_TYPE
)
5286 while (type
!= TYPE_MAIN_VARIANT (type
))
5287 type
= TYPE_MAIN_VARIANT (type
);
5292 /* Return nonzero if the given type node represents a tagged type. */
5295 is_tagged_type (const_tree type
)
5297 enum tree_code code
= TREE_CODE (type
);
5299 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
5300 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
5303 /* Convert a DIE tag into its string name. */
5306 dwarf_tag_name (unsigned int tag
)
5310 case DW_TAG_padding
:
5311 return "DW_TAG_padding";
5312 case DW_TAG_array_type
:
5313 return "DW_TAG_array_type";
5314 case DW_TAG_class_type
:
5315 return "DW_TAG_class_type";
5316 case DW_TAG_entry_point
:
5317 return "DW_TAG_entry_point";
5318 case DW_TAG_enumeration_type
:
5319 return "DW_TAG_enumeration_type";
5320 case DW_TAG_formal_parameter
:
5321 return "DW_TAG_formal_parameter";
5322 case DW_TAG_imported_declaration
:
5323 return "DW_TAG_imported_declaration";
5325 return "DW_TAG_label";
5326 case DW_TAG_lexical_block
:
5327 return "DW_TAG_lexical_block";
5329 return "DW_TAG_member";
5330 case DW_TAG_pointer_type
:
5331 return "DW_TAG_pointer_type";
5332 case DW_TAG_reference_type
:
5333 return "DW_TAG_reference_type";
5334 case DW_TAG_compile_unit
:
5335 return "DW_TAG_compile_unit";
5336 case DW_TAG_string_type
:
5337 return "DW_TAG_string_type";
5338 case DW_TAG_structure_type
:
5339 return "DW_TAG_structure_type";
5340 case DW_TAG_subroutine_type
:
5341 return "DW_TAG_subroutine_type";
5342 case DW_TAG_typedef
:
5343 return "DW_TAG_typedef";
5344 case DW_TAG_union_type
:
5345 return "DW_TAG_union_type";
5346 case DW_TAG_unspecified_parameters
:
5347 return "DW_TAG_unspecified_parameters";
5348 case DW_TAG_variant
:
5349 return "DW_TAG_variant";
5350 case DW_TAG_common_block
:
5351 return "DW_TAG_common_block";
5352 case DW_TAG_common_inclusion
:
5353 return "DW_TAG_common_inclusion";
5354 case DW_TAG_inheritance
:
5355 return "DW_TAG_inheritance";
5356 case DW_TAG_inlined_subroutine
:
5357 return "DW_TAG_inlined_subroutine";
5359 return "DW_TAG_module";
5360 case DW_TAG_ptr_to_member_type
:
5361 return "DW_TAG_ptr_to_member_type";
5362 case DW_TAG_set_type
:
5363 return "DW_TAG_set_type";
5364 case DW_TAG_subrange_type
:
5365 return "DW_TAG_subrange_type";
5366 case DW_TAG_with_stmt
:
5367 return "DW_TAG_with_stmt";
5368 case DW_TAG_access_declaration
:
5369 return "DW_TAG_access_declaration";
5370 case DW_TAG_base_type
:
5371 return "DW_TAG_base_type";
5372 case DW_TAG_catch_block
:
5373 return "DW_TAG_catch_block";
5374 case DW_TAG_const_type
:
5375 return "DW_TAG_const_type";
5376 case DW_TAG_constant
:
5377 return "DW_TAG_constant";
5378 case DW_TAG_enumerator
:
5379 return "DW_TAG_enumerator";
5380 case DW_TAG_file_type
:
5381 return "DW_TAG_file_type";
5383 return "DW_TAG_friend";
5384 case DW_TAG_namelist
:
5385 return "DW_TAG_namelist";
5386 case DW_TAG_namelist_item
:
5387 return "DW_TAG_namelist_item";
5388 case DW_TAG_packed_type
:
5389 return "DW_TAG_packed_type";
5390 case DW_TAG_subprogram
:
5391 return "DW_TAG_subprogram";
5392 case DW_TAG_template_type_param
:
5393 return "DW_TAG_template_type_param";
5394 case DW_TAG_template_value_param
:
5395 return "DW_TAG_template_value_param";
5396 case DW_TAG_thrown_type
:
5397 return "DW_TAG_thrown_type";
5398 case DW_TAG_try_block
:
5399 return "DW_TAG_try_block";
5400 case DW_TAG_variant_part
:
5401 return "DW_TAG_variant_part";
5402 case DW_TAG_variable
:
5403 return "DW_TAG_variable";
5404 case DW_TAG_volatile_type
:
5405 return "DW_TAG_volatile_type";
5406 case DW_TAG_dwarf_procedure
:
5407 return "DW_TAG_dwarf_procedure";
5408 case DW_TAG_restrict_type
:
5409 return "DW_TAG_restrict_type";
5410 case DW_TAG_interface_type
:
5411 return "DW_TAG_interface_type";
5412 case DW_TAG_namespace
:
5413 return "DW_TAG_namespace";
5414 case DW_TAG_imported_module
:
5415 return "DW_TAG_imported_module";
5416 case DW_TAG_unspecified_type
:
5417 return "DW_TAG_unspecified_type";
5418 case DW_TAG_partial_unit
:
5419 return "DW_TAG_partial_unit";
5420 case DW_TAG_imported_unit
:
5421 return "DW_TAG_imported_unit";
5422 case DW_TAG_condition
:
5423 return "DW_TAG_condition";
5424 case DW_TAG_shared_type
:
5425 return "DW_TAG_shared_type";
5426 case DW_TAG_MIPS_loop
:
5427 return "DW_TAG_MIPS_loop";
5428 case DW_TAG_format_label
:
5429 return "DW_TAG_format_label";
5430 case DW_TAG_function_template
:
5431 return "DW_TAG_function_template";
5432 case DW_TAG_class_template
:
5433 return "DW_TAG_class_template";
5434 case DW_TAG_GNU_BINCL
:
5435 return "DW_TAG_GNU_BINCL";
5436 case DW_TAG_GNU_EINCL
:
5437 return "DW_TAG_GNU_EINCL";
5439 return "DW_TAG_<unknown>";
5443 /* Convert a DWARF attribute code into its string name. */
5446 dwarf_attr_name (unsigned int attr
)
5451 return "DW_AT_sibling";
5452 case DW_AT_location
:
5453 return "DW_AT_location";
5455 return "DW_AT_name";
5456 case DW_AT_ordering
:
5457 return "DW_AT_ordering";
5458 case DW_AT_subscr_data
:
5459 return "DW_AT_subscr_data";
5460 case DW_AT_byte_size
:
5461 return "DW_AT_byte_size";
5462 case DW_AT_bit_offset
:
5463 return "DW_AT_bit_offset";
5464 case DW_AT_bit_size
:
5465 return "DW_AT_bit_size";
5466 case DW_AT_element_list
:
5467 return "DW_AT_element_list";
5468 case DW_AT_stmt_list
:
5469 return "DW_AT_stmt_list";
5471 return "DW_AT_low_pc";
5473 return "DW_AT_high_pc";
5474 case DW_AT_language
:
5475 return "DW_AT_language";
5477 return "DW_AT_member";
5479 return "DW_AT_discr";
5480 case DW_AT_discr_value
:
5481 return "DW_AT_discr_value";
5482 case DW_AT_visibility
:
5483 return "DW_AT_visibility";
5485 return "DW_AT_import";
5486 case DW_AT_string_length
:
5487 return "DW_AT_string_length";
5488 case DW_AT_common_reference
:
5489 return "DW_AT_common_reference";
5490 case DW_AT_comp_dir
:
5491 return "DW_AT_comp_dir";
5492 case DW_AT_const_value
:
5493 return "DW_AT_const_value";
5494 case DW_AT_containing_type
:
5495 return "DW_AT_containing_type";
5496 case DW_AT_default_value
:
5497 return "DW_AT_default_value";
5499 return "DW_AT_inline";
5500 case DW_AT_is_optional
:
5501 return "DW_AT_is_optional";
5502 case DW_AT_lower_bound
:
5503 return "DW_AT_lower_bound";
5504 case DW_AT_producer
:
5505 return "DW_AT_producer";
5506 case DW_AT_prototyped
:
5507 return "DW_AT_prototyped";
5508 case DW_AT_return_addr
:
5509 return "DW_AT_return_addr";
5510 case DW_AT_start_scope
:
5511 return "DW_AT_start_scope";
5512 case DW_AT_bit_stride
:
5513 return "DW_AT_bit_stride";
5514 case DW_AT_upper_bound
:
5515 return "DW_AT_upper_bound";
5516 case DW_AT_abstract_origin
:
5517 return "DW_AT_abstract_origin";
5518 case DW_AT_accessibility
:
5519 return "DW_AT_accessibility";
5520 case DW_AT_address_class
:
5521 return "DW_AT_address_class";
5522 case DW_AT_artificial
:
5523 return "DW_AT_artificial";
5524 case DW_AT_base_types
:
5525 return "DW_AT_base_types";
5526 case DW_AT_calling_convention
:
5527 return "DW_AT_calling_convention";
5529 return "DW_AT_count";
5530 case DW_AT_data_member_location
:
5531 return "DW_AT_data_member_location";
5532 case DW_AT_decl_column
:
5533 return "DW_AT_decl_column";
5534 case DW_AT_decl_file
:
5535 return "DW_AT_decl_file";
5536 case DW_AT_decl_line
:
5537 return "DW_AT_decl_line";
5538 case DW_AT_declaration
:
5539 return "DW_AT_declaration";
5540 case DW_AT_discr_list
:
5541 return "DW_AT_discr_list";
5542 case DW_AT_encoding
:
5543 return "DW_AT_encoding";
5544 case DW_AT_external
:
5545 return "DW_AT_external";
5546 case DW_AT_frame_base
:
5547 return "DW_AT_frame_base";
5549 return "DW_AT_friend";
5550 case DW_AT_identifier_case
:
5551 return "DW_AT_identifier_case";
5552 case DW_AT_macro_info
:
5553 return "DW_AT_macro_info";
5554 case DW_AT_namelist_items
:
5555 return "DW_AT_namelist_items";
5556 case DW_AT_priority
:
5557 return "DW_AT_priority";
5559 return "DW_AT_segment";
5560 case DW_AT_specification
:
5561 return "DW_AT_specification";
5562 case DW_AT_static_link
:
5563 return "DW_AT_static_link";
5565 return "DW_AT_type";
5566 case DW_AT_use_location
:
5567 return "DW_AT_use_location";
5568 case DW_AT_variable_parameter
:
5569 return "DW_AT_variable_parameter";
5570 case DW_AT_virtuality
:
5571 return "DW_AT_virtuality";
5572 case DW_AT_vtable_elem_location
:
5573 return "DW_AT_vtable_elem_location";
5575 case DW_AT_allocated
:
5576 return "DW_AT_allocated";
5577 case DW_AT_associated
:
5578 return "DW_AT_associated";
5579 case DW_AT_data_location
:
5580 return "DW_AT_data_location";
5581 case DW_AT_byte_stride
:
5582 return "DW_AT_byte_stride";
5583 case DW_AT_entry_pc
:
5584 return "DW_AT_entry_pc";
5585 case DW_AT_use_UTF8
:
5586 return "DW_AT_use_UTF8";
5587 case DW_AT_extension
:
5588 return "DW_AT_extension";
5590 return "DW_AT_ranges";
5591 case DW_AT_trampoline
:
5592 return "DW_AT_trampoline";
5593 case DW_AT_call_column
:
5594 return "DW_AT_call_column";
5595 case DW_AT_call_file
:
5596 return "DW_AT_call_file";
5597 case DW_AT_call_line
:
5598 return "DW_AT_call_line";
5600 case DW_AT_MIPS_fde
:
5601 return "DW_AT_MIPS_fde";
5602 case DW_AT_MIPS_loop_begin
:
5603 return "DW_AT_MIPS_loop_begin";
5604 case DW_AT_MIPS_tail_loop_begin
:
5605 return "DW_AT_MIPS_tail_loop_begin";
5606 case DW_AT_MIPS_epilog_begin
:
5607 return "DW_AT_MIPS_epilog_begin";
5608 case DW_AT_MIPS_loop_unroll_factor
:
5609 return "DW_AT_MIPS_loop_unroll_factor";
5610 case DW_AT_MIPS_software_pipeline_depth
:
5611 return "DW_AT_MIPS_software_pipeline_depth";
5612 case DW_AT_MIPS_linkage_name
:
5613 return "DW_AT_MIPS_linkage_name";
5614 case DW_AT_MIPS_stride
:
5615 return "DW_AT_MIPS_stride";
5616 case DW_AT_MIPS_abstract_name
:
5617 return "DW_AT_MIPS_abstract_name";
5618 case DW_AT_MIPS_clone_origin
:
5619 return "DW_AT_MIPS_clone_origin";
5620 case DW_AT_MIPS_has_inlines
:
5621 return "DW_AT_MIPS_has_inlines";
5623 case DW_AT_sf_names
:
5624 return "DW_AT_sf_names";
5625 case DW_AT_src_info
:
5626 return "DW_AT_src_info";
5627 case DW_AT_mac_info
:
5628 return "DW_AT_mac_info";
5629 case DW_AT_src_coords
:
5630 return "DW_AT_src_coords";
5631 case DW_AT_body_begin
:
5632 return "DW_AT_body_begin";
5633 case DW_AT_body_end
:
5634 return "DW_AT_body_end";
5635 case DW_AT_GNU_vector
:
5636 return "DW_AT_GNU_vector";
5638 case DW_AT_VMS_rtnbeg_pd_address
:
5639 return "DW_AT_VMS_rtnbeg_pd_address";
5642 return "DW_AT_<unknown>";
5646 /* Convert a DWARF value form code into its string name. */
5649 dwarf_form_name (unsigned int form
)
5654 return "DW_FORM_addr";
5655 case DW_FORM_block2
:
5656 return "DW_FORM_block2";
5657 case DW_FORM_block4
:
5658 return "DW_FORM_block4";
5660 return "DW_FORM_data2";
5662 return "DW_FORM_data4";
5664 return "DW_FORM_data8";
5665 case DW_FORM_string
:
5666 return "DW_FORM_string";
5668 return "DW_FORM_block";
5669 case DW_FORM_block1
:
5670 return "DW_FORM_block1";
5672 return "DW_FORM_data1";
5674 return "DW_FORM_flag";
5676 return "DW_FORM_sdata";
5678 return "DW_FORM_strp";
5680 return "DW_FORM_udata";
5681 case DW_FORM_ref_addr
:
5682 return "DW_FORM_ref_addr";
5684 return "DW_FORM_ref1";
5686 return "DW_FORM_ref2";
5688 return "DW_FORM_ref4";
5690 return "DW_FORM_ref8";
5691 case DW_FORM_ref_udata
:
5692 return "DW_FORM_ref_udata";
5693 case DW_FORM_indirect
:
5694 return "DW_FORM_indirect";
5696 return "DW_FORM_<unknown>";
5700 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5701 instance of an inlined instance of a decl which is local to an inline
5702 function, so we have to trace all of the way back through the origin chain
5703 to find out what sort of node actually served as the original seed for the
5707 decl_ultimate_origin (const_tree decl
)
5709 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
5712 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5713 nodes in the function to point to themselves; ignore that if
5714 we're trying to output the abstract instance of this function. */
5715 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
5718 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5719 most distant ancestor, this should never happen. */
5720 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
5722 return DECL_ABSTRACT_ORIGIN (decl
);
5725 /* Determine the "ultimate origin" of a block. The block may be an inlined
5726 instance of an inlined instance of a block which is local to an inline
5727 function, so we have to trace all of the way back through the origin chain
5728 to find out what sort of node actually served as the original seed for the
5732 block_ultimate_origin (const_tree block
)
5734 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
5736 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5737 nodes in the function to point to themselves; ignore that if
5738 we're trying to output the abstract instance of this function. */
5739 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
5742 if (immediate_origin
== NULL_TREE
)
5747 tree lookahead
= immediate_origin
;
5751 ret_val
= lookahead
;
5752 lookahead
= (TREE_CODE (ret_val
) == BLOCK
5753 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
5755 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
5757 /* The block's abstract origin chain may not be the *ultimate* origin of
5758 the block. It could lead to a DECL that has an abstract origin set.
5759 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5760 will give us if it has one). Note that DECL's abstract origins are
5761 supposed to be the most distant ancestor (or so decl_ultimate_origin
5762 claims), so we don't need to loop following the DECL origins. */
5763 if (DECL_P (ret_val
))
5764 return DECL_ORIGIN (ret_val
);
5770 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5771 of a virtual function may refer to a base class, so we check the 'this'
5775 decl_class_context (tree decl
)
5777 tree context
= NULL_TREE
;
5779 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
5780 context
= DECL_CONTEXT (decl
);
5782 context
= TYPE_MAIN_VARIANT
5783 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
5785 if (context
&& !TYPE_P (context
))
5786 context
= NULL_TREE
;
5791 /* Add an attribute/value pair to a DIE. */
5794 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
5796 /* Maybe this should be an assert? */
5800 if (die
->die_attr
== NULL
)
5801 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
5802 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
5805 static inline enum dw_val_class
5806 AT_class (dw_attr_ref a
)
5808 return a
->dw_attr_val
.val_class
;
5811 /* Add a flag value attribute to a DIE. */
5814 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
5818 attr
.dw_attr
= attr_kind
;
5819 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
5820 attr
.dw_attr_val
.v
.val_flag
= flag
;
5821 add_dwarf_attr (die
, &attr
);
5824 static inline unsigned
5825 AT_flag (dw_attr_ref a
)
5827 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
5828 return a
->dw_attr_val
.v
.val_flag
;
5831 /* Add a signed integer attribute value to a DIE. */
5834 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
5838 attr
.dw_attr
= attr_kind
;
5839 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
5840 attr
.dw_attr_val
.v
.val_int
= int_val
;
5841 add_dwarf_attr (die
, &attr
);
5844 static inline HOST_WIDE_INT
5845 AT_int (dw_attr_ref a
)
5847 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
5848 return a
->dw_attr_val
.v
.val_int
;
5851 /* Add an unsigned integer attribute value to a DIE. */
5854 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5855 unsigned HOST_WIDE_INT unsigned_val
)
5859 attr
.dw_attr
= attr_kind
;
5860 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
5861 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
5862 add_dwarf_attr (die
, &attr
);
5865 static inline unsigned HOST_WIDE_INT
5866 AT_unsigned (dw_attr_ref a
)
5868 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
5869 return a
->dw_attr_val
.v
.val_unsigned
;
5872 /* Add an unsigned double integer attribute value to a DIE. */
5875 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5876 long unsigned int val_hi
, long unsigned int val_low
)
5880 attr
.dw_attr
= attr_kind
;
5881 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
5882 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
5883 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
5884 add_dwarf_attr (die
, &attr
);
5887 /* Add a floating point attribute value to a DIE and return it. */
5890 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5891 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
5895 attr
.dw_attr
= attr_kind
;
5896 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
5897 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
5898 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
5899 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
5900 add_dwarf_attr (die
, &attr
);
5903 /* Hash and equality functions for debug_str_hash. */
5906 debug_str_do_hash (const void *x
)
5908 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
5912 debug_str_eq (const void *x1
, const void *x2
)
5914 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
5915 (const char *)x2
) == 0;
5918 /* Add a string attribute value to a DIE. */
5921 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
5924 struct indirect_string_node
*node
;
5927 if (! debug_str_hash
)
5928 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
5929 debug_str_eq
, NULL
);
5931 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
5932 htab_hash_string (str
), INSERT
);
5935 node
= (struct indirect_string_node
*)
5936 ggc_alloc_cleared (sizeof (struct indirect_string_node
));
5937 node
->str
= ggc_strdup (str
);
5941 node
= (struct indirect_string_node
*) *slot
;
5945 attr
.dw_attr
= attr_kind
;
5946 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
5947 attr
.dw_attr_val
.v
.val_str
= node
;
5948 add_dwarf_attr (die
, &attr
);
5951 static inline const char *
5952 AT_string (dw_attr_ref a
)
5954 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5955 return a
->dw_attr_val
.v
.val_str
->str
;
5958 /* Find out whether a string should be output inline in DIE
5959 or out-of-line in .debug_str section. */
5962 AT_string_form (dw_attr_ref a
)
5964 struct indirect_string_node
*node
;
5968 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5970 node
= a
->dw_attr_val
.v
.val_str
;
5974 len
= strlen (node
->str
) + 1;
5976 /* If the string is shorter or equal to the size of the reference, it is
5977 always better to put it inline. */
5978 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5979 return node
->form
= DW_FORM_string
;
5981 /* If we cannot expect the linker to merge strings in .debug_str
5982 section, only put it into .debug_str if it is worth even in this
5984 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5985 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5986 return node
->form
= DW_FORM_string
;
5988 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5989 ++dw2_string_counter
;
5990 node
->label
= xstrdup (label
);
5992 return node
->form
= DW_FORM_strp
;
5995 /* Add a DIE reference attribute value to a DIE. */
5998 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
6002 attr
.dw_attr
= attr_kind
;
6003 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
6004 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
6005 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
6006 add_dwarf_attr (die
, &attr
);
6009 /* Add an AT_specification attribute to a DIE, and also make the back
6010 pointer from the specification to the definition. */
6013 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
6015 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
6016 gcc_assert (!targ_die
->die_definition
);
6017 targ_die
->die_definition
= die
;
6020 static inline dw_die_ref
6021 AT_ref (dw_attr_ref a
)
6023 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6024 return a
->dw_attr_val
.v
.val_die_ref
.die
;
6028 AT_ref_external (dw_attr_ref a
)
6030 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
6031 return a
->dw_attr_val
.v
.val_die_ref
.external
;
6037 set_AT_ref_external (dw_attr_ref a
, int i
)
6039 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6040 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
6043 /* Add an FDE reference attribute value to a DIE. */
6046 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
6050 attr
.dw_attr
= attr_kind
;
6051 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
6052 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
6053 add_dwarf_attr (die
, &attr
);
6056 /* Add a location description attribute value to a DIE. */
6059 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
6063 attr
.dw_attr
= attr_kind
;
6064 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
6065 attr
.dw_attr_val
.v
.val_loc
= loc
;
6066 add_dwarf_attr (die
, &attr
);
6069 static inline dw_loc_descr_ref
6070 AT_loc (dw_attr_ref a
)
6072 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
6073 return a
->dw_attr_val
.v
.val_loc
;
6077 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
6081 attr
.dw_attr
= attr_kind
;
6082 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
6083 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
6084 add_dwarf_attr (die
, &attr
);
6085 have_location_lists
= true;
6088 static inline dw_loc_list_ref
6089 AT_loc_list (dw_attr_ref a
)
6091 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
6092 return a
->dw_attr_val
.v
.val_loc_list
;
6095 /* Add an address constant attribute value to a DIE. */
6098 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
6102 attr
.dw_attr
= attr_kind
;
6103 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
6104 attr
.dw_attr_val
.v
.val_addr
= addr
;
6105 add_dwarf_attr (die
, &attr
);
6108 /* Get the RTX from to an address DIE attribute. */
6111 AT_addr (dw_attr_ref a
)
6113 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
6114 return a
->dw_attr_val
.v
.val_addr
;
6117 /* Add a file attribute value to a DIE. */
6120 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6121 struct dwarf_file_data
*fd
)
6125 attr
.dw_attr
= attr_kind
;
6126 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
6127 attr
.dw_attr_val
.v
.val_file
= fd
;
6128 add_dwarf_attr (die
, &attr
);
6131 /* Get the dwarf_file_data from a file DIE attribute. */
6133 static inline struct dwarf_file_data
*
6134 AT_file (dw_attr_ref a
)
6136 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
6137 return a
->dw_attr_val
.v
.val_file
;
6140 /* Add a label identifier attribute value to a DIE. */
6143 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
6147 attr
.dw_attr
= attr_kind
;
6148 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
6149 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
6150 add_dwarf_attr (die
, &attr
);
6153 /* Add a section offset attribute value to a DIE, an offset into the
6154 debug_line section. */
6157 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6162 attr
.dw_attr
= attr_kind
;
6163 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
6164 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6165 add_dwarf_attr (die
, &attr
);
6168 /* Add a section offset attribute value to a DIE, an offset into the
6169 debug_macinfo section. */
6172 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6177 attr
.dw_attr
= attr_kind
;
6178 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
6179 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6180 add_dwarf_attr (die
, &attr
);
6183 /* Add an offset attribute value to a DIE. */
6186 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6187 unsigned HOST_WIDE_INT offset
)
6191 attr
.dw_attr
= attr_kind
;
6192 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
6193 attr
.dw_attr_val
.v
.val_offset
= offset
;
6194 add_dwarf_attr (die
, &attr
);
6197 /* Add an range_list attribute value to a DIE. */
6200 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6201 long unsigned int offset
)
6205 attr
.dw_attr
= attr_kind
;
6206 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
6207 attr
.dw_attr_val
.v
.val_offset
= offset
;
6208 add_dwarf_attr (die
, &attr
);
6211 static inline const char *
6212 AT_lbl (dw_attr_ref a
)
6214 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
6215 || AT_class (a
) == dw_val_class_lineptr
6216 || AT_class (a
) == dw_val_class_macptr
));
6217 return a
->dw_attr_val
.v
.val_lbl_id
;
6220 /* Get the attribute of type attr_kind. */
6223 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6227 dw_die_ref spec
= NULL
;
6232 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6233 if (a
->dw_attr
== attr_kind
)
6235 else if (a
->dw_attr
== DW_AT_specification
6236 || a
->dw_attr
== DW_AT_abstract_origin
)
6240 return get_AT (spec
, attr_kind
);
6245 /* Return the "low pc" attribute value, typically associated with a subprogram
6246 DIE. Return null if the "low pc" attribute is either not present, or if it
6247 cannot be represented as an assembler label identifier. */
6249 static inline const char *
6250 get_AT_low_pc (dw_die_ref die
)
6252 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
6254 return a
? AT_lbl (a
) : NULL
;
6257 /* Return the "high pc" attribute value, typically associated with a subprogram
6258 DIE. Return null if the "high pc" attribute is either not present, or if it
6259 cannot be represented as an assembler label identifier. */
6261 static inline const char *
6262 get_AT_hi_pc (dw_die_ref die
)
6264 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
6266 return a
? AT_lbl (a
) : NULL
;
6269 /* Return the value of the string attribute designated by ATTR_KIND, or
6270 NULL if it is not present. */
6272 static inline const char *
6273 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6275 dw_attr_ref a
= get_AT (die
, attr_kind
);
6277 return a
? AT_string (a
) : NULL
;
6280 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6281 if it is not present. */
6284 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6286 dw_attr_ref a
= get_AT (die
, attr_kind
);
6288 return a
? AT_flag (a
) : 0;
6291 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6292 if it is not present. */
6294 static inline unsigned
6295 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6297 dw_attr_ref a
= get_AT (die
, attr_kind
);
6299 return a
? AT_unsigned (a
) : 0;
6302 static inline dw_die_ref
6303 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6305 dw_attr_ref a
= get_AT (die
, attr_kind
);
6307 return a
? AT_ref (a
) : NULL
;
6310 static inline struct dwarf_file_data
*
6311 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6313 dw_attr_ref a
= get_AT (die
, attr_kind
);
6315 return a
? AT_file (a
) : NULL
;
6318 /* Return TRUE if the language is C or C++. */
6323 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6325 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
6326 || lang
== DW_LANG_C99
6327 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
6330 /* Return TRUE if the language is C++. */
6335 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6337 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
6340 /* Return TRUE if the language is Fortran. */
6345 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6347 return (lang
== DW_LANG_Fortran77
6348 || lang
== DW_LANG_Fortran90
6349 || lang
== DW_LANG_Fortran95
);
6352 /* Return TRUE if the language is Java. */
6357 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6359 return lang
== DW_LANG_Java
;
6362 /* Return TRUE if the language is Ada. */
6367 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6369 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
6372 /* Remove the specified attribute if present. */
6375 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6383 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6384 if (a
->dw_attr
== attr_kind
)
6386 if (AT_class (a
) == dw_val_class_str
)
6387 if (a
->dw_attr_val
.v
.val_str
->refcount
)
6388 a
->dw_attr_val
.v
.val_str
->refcount
--;
6390 /* VEC_ordered_remove should help reduce the number of abbrevs
6392 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
6397 /* Remove CHILD from its parent. PREV must have the property that
6398 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6401 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
6403 gcc_assert (child
->die_parent
== prev
->die_parent
);
6404 gcc_assert (prev
->die_sib
== child
);
6407 gcc_assert (child
->die_parent
->die_child
== child
);
6411 prev
->die_sib
= child
->die_sib
;
6412 if (child
->die_parent
->die_child
== child
)
6413 child
->die_parent
->die_child
= prev
;
6416 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6420 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
6426 dw_die_ref prev
= c
;
6428 while (c
->die_tag
== tag
)
6430 remove_child_with_prev (c
, prev
);
6431 /* Might have removed every child. */
6432 if (c
== c
->die_sib
)
6436 } while (c
!= die
->die_child
);
6439 /* Add a CHILD_DIE as the last child of DIE. */
6442 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
6444 /* FIXME this should probably be an assert. */
6445 if (! die
|| ! child_die
)
6447 gcc_assert (die
!= child_die
);
6449 child_die
->die_parent
= die
;
6452 child_die
->die_sib
= die
->die_child
->die_sib
;
6453 die
->die_child
->die_sib
= child_die
;
6456 child_die
->die_sib
= child_die
;
6457 die
->die_child
= child_die
;
6460 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6461 is the specification, to the end of PARENT's list of children.
6462 This is done by removing and re-adding it. */
6465 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
6469 /* We want the declaration DIE from inside the class, not the
6470 specification DIE at toplevel. */
6471 if (child
->die_parent
!= parent
)
6473 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
6479 gcc_assert (child
->die_parent
== parent
6480 || (child
->die_parent
6481 == get_AT_ref (parent
, DW_AT_specification
)));
6483 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
6484 if (p
->die_sib
== child
)
6486 remove_child_with_prev (child
, p
);
6490 add_child_die (parent
, child
);
6493 /* Return a pointer to a newly created DIE node. */
6495 static inline dw_die_ref
6496 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
6498 dw_die_ref die
= GGC_CNEW (die_node
);
6500 die
->die_tag
= tag_value
;
6502 if (parent_die
!= NULL
)
6503 add_child_die (parent_die
, die
);
6506 limbo_die_node
*limbo_node
;
6508 limbo_node
= GGC_CNEW (limbo_die_node
);
6509 limbo_node
->die
= die
;
6510 limbo_node
->created_for
= t
;
6511 limbo_node
->next
= limbo_die_list
;
6512 limbo_die_list
= limbo_node
;
6518 /* Return the DIE associated with the given type specifier. */
6520 static inline dw_die_ref
6521 lookup_type_die (tree type
)
6523 return TYPE_SYMTAB_DIE (type
);
6526 /* Equate a DIE to a given type specifier. */
6529 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
6531 TYPE_SYMTAB_DIE (type
) = type_die
;
6534 /* Returns a hash value for X (which really is a die_struct). */
6537 decl_die_table_hash (const void *x
)
6539 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
6542 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6545 decl_die_table_eq (const void *x
, const void *y
)
6547 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6550 /* Return the DIE associated with a given declaration. */
6552 static inline dw_die_ref
6553 lookup_decl_die (tree decl
)
6555 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
6558 /* Returns a hash value for X (which really is a var_loc_list). */
6561 decl_loc_table_hash (const void *x
)
6563 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
6566 /* Return nonzero if decl_id of var_loc_list X is the same as
6570 decl_loc_table_eq (const void *x
, const void *y
)
6572 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6575 /* Return the var_loc list associated with a given declaration. */
6577 static inline var_loc_list
*
6578 lookup_decl_loc (const_tree decl
)
6580 return (var_loc_list
*)
6581 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
6584 /* Equate a DIE to a particular declaration. */
6587 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6589 unsigned int decl_id
= DECL_UID (decl
);
6592 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
6594 decl_die
->decl_id
= decl_id
;
6597 /* Add a variable location node to the linked list for DECL. */
6600 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
6602 unsigned int decl_id
= DECL_UID (decl
);
6606 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
6609 temp
= GGC_CNEW (var_loc_list
);
6610 temp
->decl_id
= decl_id
;
6614 temp
= (var_loc_list
*) *slot
;
6618 /* If the current location is the same as the end of the list,
6619 and either both or neither of the locations is uninitialized,
6620 we have nothing to do. */
6621 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
6622 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
6623 || ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6624 != NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
))
6625 && ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6626 == VAR_INIT_STATUS_UNINITIALIZED
)
6627 || (NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
)
6628 == VAR_INIT_STATUS_UNINITIALIZED
))))
6630 /* Add LOC to the end of list and update LAST. */
6631 temp
->last
->next
= loc
;
6635 /* Do not add empty location to the beginning of the list. */
6636 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
6643 /* Keep track of the number of spaces used to indent the
6644 output of the debugging routines that print the structure of
6645 the DIE internal representation. */
6646 static int print_indent
;
6648 /* Indent the line the number of spaces given by print_indent. */
6651 print_spaces (FILE *outfile
)
6653 fprintf (outfile
, "%*s", print_indent
, "");
6656 /* Print the information associated with a given DIE, and its children.
6657 This routine is a debugging aid only. */
6660 print_die (dw_die_ref die
, FILE *outfile
)
6666 print_spaces (outfile
);
6667 fprintf (outfile
, "DIE %4ld: %s\n",
6668 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6669 print_spaces (outfile
);
6670 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6671 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
6673 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6675 print_spaces (outfile
);
6676 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6678 switch (AT_class (a
))
6680 case dw_val_class_addr
:
6681 fprintf (outfile
, "address");
6683 case dw_val_class_offset
:
6684 fprintf (outfile
, "offset");
6686 case dw_val_class_loc
:
6687 fprintf (outfile
, "location descriptor");
6689 case dw_val_class_loc_list
:
6690 fprintf (outfile
, "location list -> label:%s",
6691 AT_loc_list (a
)->ll_symbol
);
6693 case dw_val_class_range_list
:
6694 fprintf (outfile
, "range list");
6696 case dw_val_class_const
:
6697 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
6699 case dw_val_class_unsigned_const
:
6700 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
6702 case dw_val_class_long_long
:
6703 fprintf (outfile
, "constant (%lu,%lu)",
6704 a
->dw_attr_val
.v
.val_long_long
.hi
,
6705 a
->dw_attr_val
.v
.val_long_long
.low
);
6707 case dw_val_class_vec
:
6708 fprintf (outfile
, "floating-point or vector constant");
6710 case dw_val_class_flag
:
6711 fprintf (outfile
, "%u", AT_flag (a
));
6713 case dw_val_class_die_ref
:
6714 if (AT_ref (a
) != NULL
)
6716 if (AT_ref (a
)->die_symbol
)
6717 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
6719 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
6722 fprintf (outfile
, "die -> <null>");
6724 case dw_val_class_lbl_id
:
6725 case dw_val_class_lineptr
:
6726 case dw_val_class_macptr
:
6727 fprintf (outfile
, "label: %s", AT_lbl (a
));
6729 case dw_val_class_str
:
6730 if (AT_string (a
) != NULL
)
6731 fprintf (outfile
, "\"%s\"", AT_string (a
));
6733 fprintf (outfile
, "<null>");
6735 case dw_val_class_file
:
6736 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
6737 AT_file (a
)->emitted_number
);
6743 fprintf (outfile
, "\n");
6746 if (die
->die_child
!= NULL
)
6749 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6752 if (print_indent
== 0)
6753 fprintf (outfile
, "\n");
6756 /* Print the contents of the source code line number correspondence table.
6757 This routine is a debugging aid only. */
6760 print_dwarf_line_table (FILE *outfile
)
6763 dw_line_info_ref line_info
;
6765 fprintf (outfile
, "\n\nDWARF source line information\n");
6766 for (i
= 1; i
< line_info_table_in_use
; i
++)
6768 line_info
= &line_info_table
[i
];
6769 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
6770 line_info
->dw_file_num
,
6771 line_info
->dw_line_num
);
6774 fprintf (outfile
, "\n\n");
6777 /* Print the information collected for a given DIE. */
6780 debug_dwarf_die (dw_die_ref die
)
6782 print_die (die
, stderr
);
6785 /* Print all DWARF information collected for the compilation unit.
6786 This routine is a debugging aid only. */
6792 print_die (comp_unit_die
, stderr
);
6793 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
6794 print_dwarf_line_table (stderr
);
6797 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6798 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6799 DIE that marks the start of the DIEs for this include file. */
6802 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6804 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6805 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6807 new_unit
->die_sib
= old_unit
;
6811 /* Close an include-file CU and reopen the enclosing one. */
6814 pop_compile_unit (dw_die_ref old_unit
)
6816 dw_die_ref new_unit
= old_unit
->die_sib
;
6818 old_unit
->die_sib
= NULL
;
6822 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6823 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6825 /* Calculate the checksum of a location expression. */
6828 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6830 CHECKSUM (loc
->dw_loc_opc
);
6831 CHECKSUM (loc
->dw_loc_oprnd1
);
6832 CHECKSUM (loc
->dw_loc_oprnd2
);
6835 /* Calculate the checksum of an attribute. */
6838 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
6840 dw_loc_descr_ref loc
;
6843 CHECKSUM (at
->dw_attr
);
6845 /* We don't care that this was compiled with a different compiler
6846 snapshot; if the output is the same, that's what matters. */
6847 if (at
->dw_attr
== DW_AT_producer
)
6850 switch (AT_class (at
))
6852 case dw_val_class_const
:
6853 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6855 case dw_val_class_unsigned_const
:
6856 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6858 case dw_val_class_long_long
:
6859 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
6861 case dw_val_class_vec
:
6862 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6864 case dw_val_class_flag
:
6865 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6867 case dw_val_class_str
:
6868 CHECKSUM_STRING (AT_string (at
));
6871 case dw_val_class_addr
:
6873 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6874 CHECKSUM_STRING (XSTR (r
, 0));
6877 case dw_val_class_offset
:
6878 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6881 case dw_val_class_loc
:
6882 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6883 loc_checksum (loc
, ctx
);
6886 case dw_val_class_die_ref
:
6887 die_checksum (AT_ref (at
), ctx
, mark
);
6890 case dw_val_class_fde_ref
:
6891 case dw_val_class_lbl_id
:
6892 case dw_val_class_lineptr
:
6893 case dw_val_class_macptr
:
6896 case dw_val_class_file
:
6897 CHECKSUM_STRING (AT_file (at
)->filename
);
6905 /* Calculate the checksum of a DIE. */
6908 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6914 /* To avoid infinite recursion. */
6917 CHECKSUM (die
->die_mark
);
6920 die
->die_mark
= ++(*mark
);
6922 CHECKSUM (die
->die_tag
);
6924 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6925 attr_checksum (a
, ctx
, mark
);
6927 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6931 #undef CHECKSUM_STRING
6933 /* Do the location expressions look same? */
6935 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6937 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6938 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6939 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6942 /* Do the values look the same? */
6944 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6946 dw_loc_descr_ref loc1
, loc2
;
6949 if (v1
->val_class
!= v2
->val_class
)
6952 switch (v1
->val_class
)
6954 case dw_val_class_const
:
6955 return v1
->v
.val_int
== v2
->v
.val_int
;
6956 case dw_val_class_unsigned_const
:
6957 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6958 case dw_val_class_long_long
:
6959 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6960 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6961 case dw_val_class_vec
:
6962 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6963 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6965 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6966 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6969 case dw_val_class_flag
:
6970 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6971 case dw_val_class_str
:
6972 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6974 case dw_val_class_addr
:
6975 r1
= v1
->v
.val_addr
;
6976 r2
= v2
->v
.val_addr
;
6977 if (GET_CODE (r1
) != GET_CODE (r2
))
6979 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6980 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6982 case dw_val_class_offset
:
6983 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6985 case dw_val_class_loc
:
6986 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6988 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6989 if (!same_loc_p (loc1
, loc2
, mark
))
6991 return !loc1
&& !loc2
;
6993 case dw_val_class_die_ref
:
6994 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6996 case dw_val_class_fde_ref
:
6997 case dw_val_class_lbl_id
:
6998 case dw_val_class_lineptr
:
6999 case dw_val_class_macptr
:
7002 case dw_val_class_file
:
7003 return v1
->v
.val_file
== v2
->v
.val_file
;
7010 /* Do the attributes look the same? */
7013 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
7015 if (at1
->dw_attr
!= at2
->dw_attr
)
7018 /* We don't care that this was compiled with a different compiler
7019 snapshot; if the output is the same, that's what matters. */
7020 if (at1
->dw_attr
== DW_AT_producer
)
7023 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7026 /* Do the dies look the same? */
7029 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7035 /* To avoid infinite recursion. */
7037 return die1
->die_mark
== die2
->die_mark
;
7038 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7040 if (die1
->die_tag
!= die2
->die_tag
)
7043 if (VEC_length (dw_attr_node
, die1
->die_attr
)
7044 != VEC_length (dw_attr_node
, die2
->die_attr
))
7047 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
7048 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
7051 c1
= die1
->die_child
;
7052 c2
= die2
->die_child
;
7061 if (!same_die_p (c1
, c2
, mark
))
7065 if (c1
== die1
->die_child
)
7067 if (c2
== die2
->die_child
)
7077 /* Do the dies look the same? Wrapper around same_die_p. */
7080 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7083 int ret
= same_die_p (die1
, die2
, &mark
);
7085 unmark_all_dies (die1
);
7086 unmark_all_dies (die2
);
7091 /* The prefix to attach to symbols on DIEs in the current comdat debug
7093 static char *comdat_symbol_id
;
7095 /* The index of the current symbol within the current comdat CU. */
7096 static unsigned int comdat_symbol_number
;
7098 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7099 children, and set comdat_symbol_id accordingly. */
7102 compute_section_prefix (dw_die_ref unit_die
)
7104 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7105 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7106 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7109 unsigned char checksum
[16];
7112 /* Compute the checksum of the DIE, then append part of it as hex digits to
7113 the name filename of the unit. */
7115 md5_init_ctx (&ctx
);
7117 die_checksum (unit_die
, &ctx
, &mark
);
7118 unmark_all_dies (unit_die
);
7119 md5_finish_ctx (&ctx
, checksum
);
7121 sprintf (name
, "%s.", base
);
7122 clean_symbol_name (name
);
7124 p
= name
+ strlen (name
);
7125 for (i
= 0; i
< 4; i
++)
7127 sprintf (p
, "%.2x", checksum
[i
]);
7131 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
7132 comdat_symbol_number
= 0;
7135 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7138 is_type_die (dw_die_ref die
)
7140 switch (die
->die_tag
)
7142 case DW_TAG_array_type
:
7143 case DW_TAG_class_type
:
7144 case DW_TAG_interface_type
:
7145 case DW_TAG_enumeration_type
:
7146 case DW_TAG_pointer_type
:
7147 case DW_TAG_reference_type
:
7148 case DW_TAG_string_type
:
7149 case DW_TAG_structure_type
:
7150 case DW_TAG_subroutine_type
:
7151 case DW_TAG_union_type
:
7152 case DW_TAG_ptr_to_member_type
:
7153 case DW_TAG_set_type
:
7154 case DW_TAG_subrange_type
:
7155 case DW_TAG_base_type
:
7156 case DW_TAG_const_type
:
7157 case DW_TAG_file_type
:
7158 case DW_TAG_packed_type
:
7159 case DW_TAG_volatile_type
:
7160 case DW_TAG_typedef
:
7167 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7168 Basically, we want to choose the bits that are likely to be shared between
7169 compilations (types) and leave out the bits that are specific to individual
7170 compilations (functions). */
7173 is_comdat_die (dw_die_ref c
)
7175 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7176 we do for stabs. The advantage is a greater likelihood of sharing between
7177 objects that don't include headers in the same order (and therefore would
7178 put the base types in a different comdat). jason 8/28/00 */
7180 if (c
->die_tag
== DW_TAG_base_type
)
7183 if (c
->die_tag
== DW_TAG_pointer_type
7184 || c
->die_tag
== DW_TAG_reference_type
7185 || c
->die_tag
== DW_TAG_const_type
7186 || c
->die_tag
== DW_TAG_volatile_type
)
7188 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7190 return t
? is_comdat_die (t
) : 0;
7193 return is_type_die (c
);
7196 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7197 compilation unit. */
7200 is_symbol_die (dw_die_ref c
)
7202 return (is_type_die (c
)
7203 || (get_AT (c
, DW_AT_declaration
)
7204 && !get_AT (c
, DW_AT_specification
))
7205 || c
->die_tag
== DW_TAG_namespace
7206 || c
->die_tag
== DW_TAG_module
);
7210 gen_internal_sym (const char *prefix
)
7214 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7215 return xstrdup (buf
);
7218 /* Assign symbols to all worthy DIEs under DIE. */
7221 assign_symbol_names (dw_die_ref die
)
7225 if (is_symbol_die (die
))
7227 if (comdat_symbol_id
)
7229 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7231 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7232 comdat_symbol_id
, comdat_symbol_number
++);
7233 die
->die_symbol
= xstrdup (p
);
7236 die
->die_symbol
= gen_internal_sym ("LDIE");
7239 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7242 struct cu_hash_table_entry
7245 unsigned min_comdat_num
, max_comdat_num
;
7246 struct cu_hash_table_entry
*next
;
7249 /* Routines to manipulate hash table of CUs. */
7251 htab_cu_hash (const void *of
)
7253 const struct cu_hash_table_entry
*const entry
=
7254 (const struct cu_hash_table_entry
*) of
;
7256 return htab_hash_string (entry
->cu
->die_symbol
);
7260 htab_cu_eq (const void *of1
, const void *of2
)
7262 const struct cu_hash_table_entry
*const entry1
=
7263 (const struct cu_hash_table_entry
*) of1
;
7264 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7266 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
7270 htab_cu_del (void *what
)
7272 struct cu_hash_table_entry
*next
,
7273 *entry
= (struct cu_hash_table_entry
*) what
;
7283 /* Check whether we have already seen this CU and set up SYM_NUM
7286 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
7288 struct cu_hash_table_entry dummy
;
7289 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7291 dummy
.max_comdat_num
= 0;
7293 slot
= (struct cu_hash_table_entry
**)
7294 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7298 for (; entry
; last
= entry
, entry
= entry
->next
)
7300 if (same_die_p_wrap (cu
, entry
->cu
))
7306 *sym_num
= entry
->min_comdat_num
;
7310 entry
= XCNEW (struct cu_hash_table_entry
);
7312 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7313 entry
->next
= *slot
;
7319 /* Record SYM_NUM to record of CU in HTABLE. */
7321 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
7323 struct cu_hash_table_entry
**slot
, *entry
;
7325 slot
= (struct cu_hash_table_entry
**)
7326 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7330 entry
->max_comdat_num
= sym_num
;
7333 /* Traverse the DIE (which is always comp_unit_die), and set up
7334 additional compilation units for each of the include files we see
7335 bracketed by BINCL/EINCL. */
7338 break_out_includes (dw_die_ref die
)
7341 dw_die_ref unit
= NULL
;
7342 limbo_die_node
*node
, **pnode
;
7343 htab_t cu_hash_table
;
7347 dw_die_ref prev
= c
;
7349 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7350 || (unit
&& is_comdat_die (c
)))
7352 dw_die_ref next
= c
->die_sib
;
7354 /* This DIE is for a secondary CU; remove it from the main one. */
7355 remove_child_with_prev (c
, prev
);
7357 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7358 unit
= push_new_compile_unit (unit
, c
);
7359 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7360 unit
= pop_compile_unit (unit
);
7362 add_child_die (unit
, c
);
7364 if (c
== die
->die_child
)
7367 } while (c
!= die
->die_child
);
7370 /* We can only use this in debugging, since the frontend doesn't check
7371 to make sure that we leave every include file we enter. */
7375 assign_symbol_names (die
);
7376 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
7377 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7383 compute_section_prefix (node
->die
);
7384 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
7385 &comdat_symbol_number
);
7386 assign_symbol_names (node
->die
);
7388 *pnode
= node
->next
;
7391 pnode
= &node
->next
;
7392 record_comdat_symbol_number (node
->die
, cu_hash_table
,
7393 comdat_symbol_number
);
7396 htab_delete (cu_hash_table
);
7399 /* Traverse the DIE and add a sibling attribute if it may have the
7400 effect of speeding up access to siblings. To save some space,
7401 avoid generating sibling attributes for DIE's without children. */
7404 add_sibling_attributes (dw_die_ref die
)
7408 if (! die
->die_child
)
7411 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7412 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7414 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7417 /* Output all location lists for the DIE and its children. */
7420 output_location_lists (dw_die_ref die
)
7426 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7427 if (AT_class (a
) == dw_val_class_loc_list
)
7428 output_loc_list (AT_loc_list (a
));
7430 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7433 /* The format of each DIE (and its attribute value pairs) is encoded in an
7434 abbreviation table. This routine builds the abbreviation table and assigns
7435 a unique abbreviation id for each abbreviation entry. The children of each
7436 die are visited recursively. */
7439 build_abbrev_table (dw_die_ref die
)
7441 unsigned long abbrev_id
;
7442 unsigned int n_alloc
;
7447 /* Scan the DIE references, and mark as external any that refer to
7448 DIEs from other CUs (i.e. those which are not marked). */
7449 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7450 if (AT_class (a
) == dw_val_class_die_ref
7451 && AT_ref (a
)->die_mark
== 0)
7453 gcc_assert (AT_ref (a
)->die_symbol
);
7455 set_AT_ref_external (a
, 1);
7458 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7460 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7461 dw_attr_ref die_a
, abbrev_a
;
7465 if (abbrev
->die_tag
!= die
->die_tag
)
7467 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7470 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7471 != VEC_length (dw_attr_node
, die
->die_attr
))
7474 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
7476 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7477 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7478 || (value_format (abbrev_a
) != value_format (die_a
)))
7488 if (abbrev_id
>= abbrev_die_table_in_use
)
7490 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7492 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7493 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7496 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7497 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7498 abbrev_die_table_allocated
= n_alloc
;
7501 ++abbrev_die_table_in_use
;
7502 abbrev_die_table
[abbrev_id
] = die
;
7505 die
->die_abbrev
= abbrev_id
;
7506 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7509 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7512 constant_size (unsigned HOST_WIDE_INT value
)
7519 log
= floor_log2 (value
);
7522 log
= 1 << (floor_log2 (log
) + 1);
7527 /* Return the size of a DIE as it is represented in the
7528 .debug_info section. */
7530 static unsigned long
7531 size_of_die (dw_die_ref die
)
7533 unsigned long size
= 0;
7537 size
+= size_of_uleb128 (die
->die_abbrev
);
7538 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7540 switch (AT_class (a
))
7542 case dw_val_class_addr
:
7543 size
+= DWARF2_ADDR_SIZE
;
7545 case dw_val_class_offset
:
7546 size
+= DWARF_OFFSET_SIZE
;
7548 case dw_val_class_loc
:
7550 unsigned long lsize
= size_of_locs (AT_loc (a
));
7553 size
+= constant_size (lsize
);
7557 case dw_val_class_loc_list
:
7558 size
+= DWARF_OFFSET_SIZE
;
7560 case dw_val_class_range_list
:
7561 size
+= DWARF_OFFSET_SIZE
;
7563 case dw_val_class_const
:
7564 size
+= size_of_sleb128 (AT_int (a
));
7566 case dw_val_class_unsigned_const
:
7567 size
+= constant_size (AT_unsigned (a
));
7569 case dw_val_class_long_long
:
7570 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
7572 case dw_val_class_vec
:
7573 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7574 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7575 + a
->dw_attr_val
.v
.val_vec
.length
7576 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7578 case dw_val_class_flag
:
7581 case dw_val_class_die_ref
:
7582 if (AT_ref_external (a
))
7583 size
+= DWARF2_ADDR_SIZE
;
7585 size
+= DWARF_OFFSET_SIZE
;
7587 case dw_val_class_fde_ref
:
7588 size
+= DWARF_OFFSET_SIZE
;
7590 case dw_val_class_lbl_id
:
7591 size
+= DWARF2_ADDR_SIZE
;
7593 case dw_val_class_lineptr
:
7594 case dw_val_class_macptr
:
7595 size
+= DWARF_OFFSET_SIZE
;
7597 case dw_val_class_str
:
7598 if (AT_string_form (a
) == DW_FORM_strp
)
7599 size
+= DWARF_OFFSET_SIZE
;
7601 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7603 case dw_val_class_file
:
7604 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7614 /* Size the debugging information associated with a given DIE. Visits the
7615 DIE's children recursively. Updates the global variable next_die_offset, on
7616 each time through. Uses the current value of next_die_offset to update the
7617 die_offset field in each DIE. */
7620 calc_die_sizes (dw_die_ref die
)
7624 die
->die_offset
= next_die_offset
;
7625 next_die_offset
+= size_of_die (die
);
7627 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7629 if (die
->die_child
!= NULL
)
7630 /* Count the null byte used to terminate sibling lists. */
7631 next_die_offset
+= 1;
7634 /* Set the marks for a die and its children. We do this so
7635 that we know whether or not a reference needs to use FORM_ref_addr; only
7636 DIEs in the same CU will be marked. We used to clear out the offset
7637 and use that as the flag, but ran into ordering problems. */
7640 mark_dies (dw_die_ref die
)
7644 gcc_assert (!die
->die_mark
);
7647 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7650 /* Clear the marks for a die and its children. */
7653 unmark_dies (dw_die_ref die
)
7657 gcc_assert (die
->die_mark
);
7660 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7663 /* Clear the marks for a die, its children and referred dies. */
7666 unmark_all_dies (dw_die_ref die
)
7676 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7678 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7679 if (AT_class (a
) == dw_val_class_die_ref
)
7680 unmark_all_dies (AT_ref (a
));
7683 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7684 generated for the compilation unit. */
7686 static unsigned long
7687 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7693 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7694 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
7695 if (names
!= pubtype_table
7696 || p
->die
->die_offset
!= 0
7697 || !flag_eliminate_unused_debug_types
)
7698 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7700 size
+= DWARF_OFFSET_SIZE
;
7704 /* Return the size of the information in the .debug_aranges section. */
7706 static unsigned long
7707 size_of_aranges (void)
7711 size
= DWARF_ARANGES_HEADER_SIZE
;
7713 /* Count the address/length pair for this compilation unit. */
7714 if (text_section_used
)
7715 size
+= 2 * DWARF2_ADDR_SIZE
;
7716 if (cold_text_section_used
)
7717 size
+= 2 * DWARF2_ADDR_SIZE
;
7718 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
7720 /* Count the two zero words used to terminated the address range table. */
7721 size
+= 2 * DWARF2_ADDR_SIZE
;
7725 /* Select the encoding of an attribute value. */
7727 static enum dwarf_form
7728 value_format (dw_attr_ref a
)
7730 switch (a
->dw_attr_val
.val_class
)
7732 case dw_val_class_addr
:
7733 return DW_FORM_addr
;
7734 case dw_val_class_range_list
:
7735 case dw_val_class_offset
:
7736 case dw_val_class_loc_list
:
7737 switch (DWARF_OFFSET_SIZE
)
7740 return DW_FORM_data4
;
7742 return DW_FORM_data8
;
7746 case dw_val_class_loc
:
7747 switch (constant_size (size_of_locs (AT_loc (a
))))
7750 return DW_FORM_block1
;
7752 return DW_FORM_block2
;
7756 case dw_val_class_const
:
7757 return DW_FORM_sdata
;
7758 case dw_val_class_unsigned_const
:
7759 switch (constant_size (AT_unsigned (a
)))
7762 return DW_FORM_data1
;
7764 return DW_FORM_data2
;
7766 return DW_FORM_data4
;
7768 return DW_FORM_data8
;
7772 case dw_val_class_long_long
:
7773 return DW_FORM_block1
;
7774 case dw_val_class_vec
:
7775 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7776 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7779 return DW_FORM_block1
;
7781 return DW_FORM_block2
;
7783 return DW_FORM_block4
;
7787 case dw_val_class_flag
:
7788 return DW_FORM_flag
;
7789 case dw_val_class_die_ref
:
7790 if (AT_ref_external (a
))
7791 return DW_FORM_ref_addr
;
7794 case dw_val_class_fde_ref
:
7795 return DW_FORM_data
;
7796 case dw_val_class_lbl_id
:
7797 return DW_FORM_addr
;
7798 case dw_val_class_lineptr
:
7799 case dw_val_class_macptr
:
7800 return DW_FORM_data
;
7801 case dw_val_class_str
:
7802 return AT_string_form (a
);
7803 case dw_val_class_file
:
7804 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7807 return DW_FORM_data1
;
7809 return DW_FORM_data2
;
7811 return DW_FORM_data4
;
7821 /* Output the encoding of an attribute value. */
7824 output_value_format (dw_attr_ref a
)
7826 enum dwarf_form form
= value_format (a
);
7828 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7831 /* Output the .debug_abbrev section which defines the DIE abbreviation
7835 output_abbrev_section (void)
7837 unsigned long abbrev_id
;
7839 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7841 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7845 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7846 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7847 dwarf_tag_name (abbrev
->die_tag
));
7849 if (abbrev
->die_child
!= NULL
)
7850 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7852 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7854 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7857 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7858 dwarf_attr_name (a_attr
->dw_attr
));
7859 output_value_format (a_attr
);
7862 dw2_asm_output_data (1, 0, NULL
);
7863 dw2_asm_output_data (1, 0, NULL
);
7866 /* Terminate the table. */
7867 dw2_asm_output_data (1, 0, NULL
);
7870 /* Output a symbol we can use to refer to this DIE from another CU. */
7873 output_die_symbol (dw_die_ref die
)
7875 char *sym
= die
->die_symbol
;
7880 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7881 /* We make these global, not weak; if the target doesn't support
7882 .linkonce, it doesn't support combining the sections, so debugging
7884 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7886 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7889 /* Return a new location list, given the begin and end range, and the
7890 expression. gensym tells us whether to generate a new internal symbol for
7891 this location list node, which is done for the head of the list only. */
7893 static inline dw_loc_list_ref
7894 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7895 const char *section
, unsigned int gensym
)
7897 dw_loc_list_ref retlist
= GGC_CNEW (dw_loc_list_node
);
7899 retlist
->begin
= begin
;
7901 retlist
->expr
= expr
;
7902 retlist
->section
= section
;
7904 retlist
->ll_symbol
= gen_internal_sym ("LLST");
7909 /* Add a location description expression to a location list. */
7912 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
7913 const char *begin
, const char *end
,
7914 const char *section
)
7918 /* Find the end of the chain. */
7919 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
7922 /* Add a new location list node to the list. */
7923 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
7926 /* Output the location list given to us. */
7929 output_loc_list (dw_loc_list_ref list_head
)
7931 dw_loc_list_ref curr
= list_head
;
7933 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7935 /* Walk the location list, and output each range + expression. */
7936 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7939 /* Don't output an entry that starts and ends at the same address. */
7940 if (strcmp (curr
->begin
, curr
->end
) == 0)
7942 if (!have_multiple_function_sections
)
7944 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7945 "Location list begin address (%s)",
7946 list_head
->ll_symbol
);
7947 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7948 "Location list end address (%s)",
7949 list_head
->ll_symbol
);
7953 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7954 "Location list begin address (%s)",
7955 list_head
->ll_symbol
);
7956 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7957 "Location list end address (%s)",
7958 list_head
->ll_symbol
);
7960 size
= size_of_locs (curr
->expr
);
7962 /* Output the block length for this list of location operations. */
7963 gcc_assert (size
<= 0xffff);
7964 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7966 output_loc_sequence (curr
->expr
);
7969 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7970 "Location list terminator begin (%s)",
7971 list_head
->ll_symbol
);
7972 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7973 "Location list terminator end (%s)",
7974 list_head
->ll_symbol
);
7977 /* Output the DIE and its attributes. Called recursively to generate
7978 the definitions of each child DIE. */
7981 output_die (dw_die_ref die
)
7988 /* If someone in another CU might refer to us, set up a symbol for
7989 them to point to. */
7990 if (die
->die_symbol
)
7991 output_die_symbol (die
);
7993 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7994 (unsigned long)die
->die_offset
,
7995 dwarf_tag_name (die
->die_tag
));
7997 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7999 const char *name
= dwarf_attr_name (a
->dw_attr
);
8001 switch (AT_class (a
))
8003 case dw_val_class_addr
:
8004 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8007 case dw_val_class_offset
:
8008 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8012 case dw_val_class_range_list
:
8014 char *p
= strchr (ranges_section_label
, '\0');
8016 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
8017 a
->dw_attr_val
.v
.val_offset
);
8018 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8019 debug_ranges_section
, "%s", name
);
8024 case dw_val_class_loc
:
8025 size
= size_of_locs (AT_loc (a
));
8027 /* Output the block length for this list of location operations. */
8028 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8030 output_loc_sequence (AT_loc (a
));
8033 case dw_val_class_const
:
8034 /* ??? It would be slightly more efficient to use a scheme like is
8035 used for unsigned constants below, but gdb 4.x does not sign
8036 extend. Gdb 5.x does sign extend. */
8037 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8040 case dw_val_class_unsigned_const
:
8041 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
8042 AT_unsigned (a
), "%s", name
);
8045 case dw_val_class_long_long
:
8047 unsigned HOST_WIDE_INT first
, second
;
8049 dw2_asm_output_data (1,
8050 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8053 if (WORDS_BIG_ENDIAN
)
8055 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8056 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
8060 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
8061 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8064 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8065 first
, "long long constant");
8066 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8071 case dw_val_class_vec
:
8073 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8074 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8078 dw2_asm_output_data (constant_size (len
* elt_size
),
8079 len
* elt_size
, "%s", name
);
8080 if (elt_size
> sizeof (HOST_WIDE_INT
))
8085 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8088 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8089 "fp or vector constant word %u", i
);
8093 case dw_val_class_flag
:
8094 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8097 case dw_val_class_loc_list
:
8099 char *sym
= AT_loc_list (a
)->ll_symbol
;
8102 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8107 case dw_val_class_die_ref
:
8108 if (AT_ref_external (a
))
8110 char *sym
= AT_ref (a
)->die_symbol
;
8113 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
8118 gcc_assert (AT_ref (a
)->die_offset
);
8119 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8124 case dw_val_class_fde_ref
:
8128 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8129 a
->dw_attr_val
.v
.val_fde_index
* 2);
8130 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8135 case dw_val_class_lbl_id
:
8136 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8139 case dw_val_class_lineptr
:
8140 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8141 debug_line_section
, "%s", name
);
8144 case dw_val_class_macptr
:
8145 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8146 debug_macinfo_section
, "%s", name
);
8149 case dw_val_class_str
:
8150 if (AT_string_form (a
) == DW_FORM_strp
)
8151 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8152 a
->dw_attr_val
.v
.val_str
->label
,
8154 "%s: \"%s\"", name
, AT_string (a
));
8156 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8159 case dw_val_class_file
:
8161 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8163 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8164 a
->dw_attr_val
.v
.val_file
->filename
);
8173 FOR_EACH_CHILD (die
, c
, output_die (c
));
8175 /* Add null byte to terminate sibling list. */
8176 if (die
->die_child
!= NULL
)
8177 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8178 (unsigned long) die
->die_offset
);
8181 /* Output the compilation unit that appears at the beginning of the
8182 .debug_info section, and precedes the DIE descriptions. */
8185 output_compilation_unit_header (void)
8187 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8188 dw2_asm_output_data (4, 0xffffffff,
8189 "Initial length escape value indicating 64-bit DWARF extension");
8190 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8191 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8192 "Length of Compilation Unit Info");
8193 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
8194 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8195 debug_abbrev_section
,
8196 "Offset Into Abbrev. Section");
8197 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8200 /* Output the compilation unit DIE and its children. */
8203 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8205 const char *secname
;
8208 /* Unless we are outputting main CU, we may throw away empty ones. */
8209 if (!output_if_empty
&& die
->die_child
== NULL
)
8212 /* Even if there are no children of this DIE, we must output the information
8213 about the compilation unit. Otherwise, on an empty translation unit, we
8214 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8215 will then complain when examining the file. First mark all the DIEs in
8216 this CU so we know which get local refs. */
8219 build_abbrev_table (die
);
8221 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8222 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8223 calc_die_sizes (die
);
8225 oldsym
= die
->die_symbol
;
8228 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8230 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8232 die
->die_symbol
= NULL
;
8233 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8236 switch_to_section (debug_info_section
);
8238 /* Output debugging information. */
8239 output_compilation_unit_header ();
8242 /* Leave the marks on the main CU, so we can check them in
8247 die
->die_symbol
= oldsym
;
8251 /* Return the DWARF2/3 pubname associated with a decl. */
8254 dwarf2_name (tree decl
, int scope
)
8256 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8259 /* Add a new entry to .debug_pubnames if appropriate. */
8262 add_pubname_string (const char *str
, dw_die_ref die
)
8267 e
.name
= xstrdup (str
);
8268 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8272 add_pubname (tree decl
, dw_die_ref die
)
8275 if (TREE_PUBLIC (decl
))
8276 add_pubname_string (dwarf2_name (decl
, 1), die
);
8279 /* Add a new entry to .debug_pubtypes if appropriate. */
8282 add_pubtype (tree decl
, dw_die_ref die
)
8287 if ((TREE_PUBLIC (decl
)
8288 || die
->die_parent
== comp_unit_die
)
8289 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8294 if (TYPE_NAME (decl
))
8296 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
8297 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
8298 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
8299 && DECL_NAME (TYPE_NAME (decl
)))
8300 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
8302 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
8306 e
.name
= xstrdup (dwarf2_name (decl
, 1));
8308 /* If we don't have a name for the type, there's no point in adding
8310 if (e
.name
&& e
.name
[0] != '\0')
8311 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8315 /* Output the public names table used to speed up access to externally
8316 visible names; or the public types table used to find type definitions. */
8319 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8322 unsigned long pubnames_length
= size_of_pubnames (names
);
8325 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8326 dw2_asm_output_data (4, 0xffffffff,
8327 "Initial length escape value indicating 64-bit DWARF extension");
8328 if (names
== pubname_table
)
8329 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8330 "Length of Public Names Info");
8332 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8333 "Length of Public Type Names Info");
8334 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8335 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8337 "Offset of Compilation Unit Info");
8338 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8339 "Compilation Unit Length");
8341 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
8343 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8344 if (names
== pubname_table
)
8345 gcc_assert (pub
->die
->die_mark
);
8347 if (names
!= pubtype_table
8348 || pub
->die
->die_offset
!= 0
8349 || !flag_eliminate_unused_debug_types
)
8351 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
8354 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8358 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8361 /* Add a new entry to .debug_aranges if appropriate. */
8364 add_arange (tree decl
, dw_die_ref die
)
8366 if (! DECL_SECTION_NAME (decl
))
8369 if (arange_table_in_use
== arange_table_allocated
)
8371 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
8372 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
8373 arange_table_allocated
);
8374 memset (arange_table
+ arange_table_in_use
, 0,
8375 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8378 arange_table
[arange_table_in_use
++] = die
;
8381 /* Output the information that goes into the .debug_aranges table.
8382 Namely, define the beginning and ending address range of the
8383 text section generated for this compilation unit. */
8386 output_aranges (void)
8389 unsigned long aranges_length
= size_of_aranges ();
8391 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8392 dw2_asm_output_data (4, 0xffffffff,
8393 "Initial length escape value indicating 64-bit DWARF extension");
8394 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8395 "Length of Address Ranges Info");
8396 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8397 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8399 "Offset of Compilation Unit Info");
8400 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8401 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8403 /* We need to align to twice the pointer size here. */
8404 if (DWARF_ARANGES_PAD_SIZE
)
8406 /* Pad using a 2 byte words so that padding is correct for any
8408 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8409 2 * DWARF2_ADDR_SIZE
);
8410 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8411 dw2_asm_output_data (2, 0, NULL
);
8414 /* It is necessary not to output these entries if the sections were
8415 not used; if the sections were not used, the length will be 0 and
8416 the address may end up as 0 if the section is discarded by ld
8417 --gc-sections, leaving an invalid (0, 0) entry that can be
8418 confused with the terminator. */
8419 if (text_section_used
)
8421 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8422 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8423 text_section_label
, "Length");
8425 if (cold_text_section_used
)
8427 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8429 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8430 cold_text_section_label
, "Length");
8433 for (i
= 0; i
< arange_table_in_use
; i
++)
8435 dw_die_ref die
= arange_table
[i
];
8437 /* We shouldn't see aranges for DIEs outside of the main CU. */
8438 gcc_assert (die
->die_mark
);
8440 if (die
->die_tag
== DW_TAG_subprogram
)
8442 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
8444 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
8445 get_AT_low_pc (die
), "Length");
8449 /* A static variable; extract the symbol from DW_AT_location.
8450 Note that this code isn't currently hit, as we only emit
8451 aranges for functions (jason 9/23/99). */
8452 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
8453 dw_loc_descr_ref loc
;
8455 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
8458 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
8460 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
8461 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
8462 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
8463 get_AT_unsigned (die
, DW_AT_byte_size
),
8468 /* Output the terminator words. */
8469 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8470 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8473 /* Add a new entry to .debug_ranges. Return the offset at which it
8477 add_ranges_num (int num
)
8479 unsigned int in_use
= ranges_table_in_use
;
8481 if (in_use
== ranges_table_allocated
)
8483 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8484 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8485 ranges_table_allocated
);
8486 memset (ranges_table
+ ranges_table_in_use
, 0,
8487 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8490 ranges_table
[in_use
].num
= num
;
8491 ranges_table_in_use
= in_use
+ 1;
8493 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8496 /* Add a new entry to .debug_ranges corresponding to a block, or a
8497 range terminator if BLOCK is NULL. */
8500 add_ranges (const_tree block
)
8502 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8505 /* Add a new entry to .debug_ranges corresponding to a pair of
8509 add_ranges_by_labels (const char *begin
, const char *end
)
8511 unsigned int in_use
= ranges_by_label_in_use
;
8513 if (in_use
== ranges_by_label_allocated
)
8515 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8516 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8518 ranges_by_label_allocated
);
8519 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8520 RANGES_TABLE_INCREMENT
8521 * sizeof (struct dw_ranges_by_label_struct
));
8524 ranges_by_label
[in_use
].begin
= begin
;
8525 ranges_by_label
[in_use
].end
= end
;
8526 ranges_by_label_in_use
= in_use
+ 1;
8528 return add_ranges_num (-(int)in_use
- 1);
8532 output_ranges (void)
8535 static const char *const start_fmt
= "Offset 0x%x";
8536 const char *fmt
= start_fmt
;
8538 for (i
= 0; i
< ranges_table_in_use
; i
++)
8540 int block_num
= ranges_table
[i
].num
;
8544 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8545 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8547 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8548 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8550 /* If all code is in the text section, then the compilation
8551 unit base address defaults to DW_AT_low_pc, which is the
8552 base of the text section. */
8553 if (!have_multiple_function_sections
)
8555 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8557 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8558 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8559 text_section_label
, NULL
);
8562 /* Otherwise, the compilation unit base address is zero,
8563 which allows us to use absolute addresses, and not worry
8564 about whether the target supports cross-section
8568 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8569 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8570 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8576 /* Negative block_num stands for an index into ranges_by_label. */
8577 else if (block_num
< 0)
8579 int lab_idx
= - block_num
- 1;
8581 if (!have_multiple_function_sections
)
8585 /* If we ever use add_ranges_by_labels () for a single
8586 function section, all we have to do is to take out
8588 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8589 ranges_by_label
[lab_idx
].begin
,
8591 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8592 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8593 ranges_by_label
[lab_idx
].end
,
8594 text_section_label
, NULL
);
8599 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8600 ranges_by_label
[lab_idx
].begin
,
8601 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8602 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8603 ranges_by_label
[lab_idx
].end
,
8609 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8610 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8616 /* Data structure containing information about input files. */
8619 const char *path
; /* Complete file name. */
8620 const char *fname
; /* File name part. */
8621 int length
; /* Length of entire string. */
8622 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8623 int dir_idx
; /* Index in directory table. */
8626 /* Data structure containing information about directories with source
8630 const char *path
; /* Path including directory name. */
8631 int length
; /* Path length. */
8632 int prefix
; /* Index of directory entry which is a prefix. */
8633 int count
; /* Number of files in this directory. */
8634 int dir_idx
; /* Index of directory used as base. */
8637 /* Callback function for file_info comparison. We sort by looking at
8638 the directories in the path. */
8641 file_info_cmp (const void *p1
, const void *p2
)
8643 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8644 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8645 const unsigned char *cp1
;
8646 const unsigned char *cp2
;
8648 /* Take care of file names without directories. We need to make sure that
8649 we return consistent values to qsort since some will get confused if
8650 we return the same value when identical operands are passed in opposite
8651 orders. So if neither has a directory, return 0 and otherwise return
8652 1 or -1 depending on which one has the directory. */
8653 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8654 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8656 cp1
= (const unsigned char *) s1
->path
;
8657 cp2
= (const unsigned char *) s2
->path
;
8663 /* Reached the end of the first path? If so, handle like above. */
8664 if ((cp1
== (const unsigned char *) s1
->fname
)
8665 || (cp2
== (const unsigned char *) s2
->fname
))
8666 return ((cp2
== (const unsigned char *) s2
->fname
)
8667 - (cp1
== (const unsigned char *) s1
->fname
));
8669 /* Character of current path component the same? */
8670 else if (*cp1
!= *cp2
)
8675 struct file_name_acquire_data
8677 struct file_info
*files
;
8682 /* Traversal function for the hash table. */
8685 file_name_acquire (void ** slot
, void *data
)
8687 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8688 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8689 struct file_info
*fi
;
8692 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8694 if (! d
->emitted_number
)
8697 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8699 fi
= fnad
->files
+ fnad
->used_files
++;
8701 /* Skip all leading "./". */
8703 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8706 /* Create a new array entry. */
8708 fi
->length
= strlen (f
);
8711 /* Search for the file name part. */
8712 f
= strrchr (f
, DIR_SEPARATOR
);
8713 #if defined (DIR_SEPARATOR_2)
8715 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8719 if (f
== NULL
|| f
< g
)
8725 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8729 /* Output the directory table and the file name table. We try to minimize
8730 the total amount of memory needed. A heuristic is used to avoid large
8731 slowdowns with many input files. */
8734 output_file_names (void)
8736 struct file_name_acquire_data fnad
;
8738 struct file_info
*files
;
8739 struct dir_info
*dirs
;
8748 if (!last_emitted_file
)
8750 dw2_asm_output_data (1, 0, "End directory table");
8751 dw2_asm_output_data (1, 0, "End file name table");
8755 numfiles
= last_emitted_file
->emitted_number
;
8757 /* Allocate the various arrays we need. */
8758 files
= XALLOCAVEC (struct file_info
, numfiles
);
8759 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8762 fnad
.used_files
= 0;
8763 fnad
.max_files
= numfiles
;
8764 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8765 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8767 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8769 /* Find all the different directories used. */
8770 dirs
[0].path
= files
[0].path
;
8771 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8772 dirs
[0].prefix
= -1;
8774 dirs
[0].dir_idx
= 0;
8775 files
[0].dir_idx
= 0;
8778 for (i
= 1; i
< numfiles
; i
++)
8779 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8780 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8781 dirs
[ndirs
- 1].length
) == 0)
8783 /* Same directory as last entry. */
8784 files
[i
].dir_idx
= ndirs
- 1;
8785 ++dirs
[ndirs
- 1].count
;
8791 /* This is a new directory. */
8792 dirs
[ndirs
].path
= files
[i
].path
;
8793 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8794 dirs
[ndirs
].count
= 1;
8795 dirs
[ndirs
].dir_idx
= ndirs
;
8796 files
[i
].dir_idx
= ndirs
;
8798 /* Search for a prefix. */
8799 dirs
[ndirs
].prefix
= -1;
8800 for (j
= 0; j
< ndirs
; j
++)
8801 if (dirs
[j
].length
< dirs
[ndirs
].length
8802 && dirs
[j
].length
> 1
8803 && (dirs
[ndirs
].prefix
== -1
8804 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8805 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8806 dirs
[ndirs
].prefix
= j
;
8811 /* Now to the actual work. We have to find a subset of the directories which
8812 allow expressing the file name using references to the directory table
8813 with the least amount of characters. We do not do an exhaustive search
8814 where we would have to check out every combination of every single
8815 possible prefix. Instead we use a heuristic which provides nearly optimal
8816 results in most cases and never is much off. */
8817 saved
= XALLOCAVEC (int, ndirs
);
8818 savehere
= XALLOCAVEC (int, ndirs
);
8820 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8821 for (i
= 0; i
< ndirs
; i
++)
8826 /* We can always save some space for the current directory. But this
8827 does not mean it will be enough to justify adding the directory. */
8828 savehere
[i
] = dirs
[i
].length
;
8829 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8831 for (j
= i
+ 1; j
< ndirs
; j
++)
8834 if (saved
[j
] < dirs
[i
].length
)
8836 /* Determine whether the dirs[i] path is a prefix of the
8841 while (k
!= -1 && k
!= (int) i
)
8846 /* Yes it is. We can possibly save some memory by
8847 writing the filenames in dirs[j] relative to
8849 savehere
[j
] = dirs
[i
].length
;
8850 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8855 /* Check whether we can save enough to justify adding the dirs[i]
8857 if (total
> dirs
[i
].length
+ 1)
8859 /* It's worthwhile adding. */
8860 for (j
= i
; j
< ndirs
; j
++)
8861 if (savehere
[j
] > 0)
8863 /* Remember how much we saved for this directory so far. */
8864 saved
[j
] = savehere
[j
];
8866 /* Remember the prefix directory. */
8867 dirs
[j
].dir_idx
= i
;
8872 /* Emit the directory name table. */
8874 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8875 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8876 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
8877 "Directory Entry: 0x%x", i
+ idx_offset
);
8879 dw2_asm_output_data (1, 0, "End directory table");
8881 /* We have to emit them in the order of emitted_number since that's
8882 used in the debug info generation. To do this efficiently we
8883 generate a back-mapping of the indices first. */
8884 backmap
= XALLOCAVEC (int, numfiles
);
8885 for (i
= 0; i
< numfiles
; i
++)
8886 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8888 /* Now write all the file names. */
8889 for (i
= 0; i
< numfiles
; i
++)
8891 int file_idx
= backmap
[i
];
8892 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8894 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8895 "File Entry: 0x%x", (unsigned) i
+ 1);
8897 /* Include directory index. */
8898 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8900 /* Modification time. */
8901 dw2_asm_output_data_uleb128 (0, NULL
);
8903 /* File length in bytes. */
8904 dw2_asm_output_data_uleb128 (0, NULL
);
8907 dw2_asm_output_data (1, 0, "End file name table");
8911 /* Output the source line number correspondence information. This
8912 information goes into the .debug_line section. */
8915 output_line_info (void)
8917 char l1
[20], l2
[20], p1
[20], p2
[20];
8918 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8919 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8922 unsigned long lt_index
;
8923 unsigned long current_line
;
8926 unsigned long current_file
;
8927 unsigned long function
;
8929 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
8930 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
8931 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
8932 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
8934 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8935 dw2_asm_output_data (4, 0xffffffff,
8936 "Initial length escape value indicating 64-bit DWARF extension");
8937 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
8938 "Length of Source Line Info");
8939 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
8941 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8942 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
8943 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
8945 /* Define the architecture-dependent minimum instruction length (in
8946 bytes). In this implementation of DWARF, this field is used for
8947 information purposes only. Since GCC generates assembly language,
8948 we have no a priori knowledge of how many instruction bytes are
8949 generated for each source line, and therefore can use only the
8950 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8951 commands. Accordingly, we fix this as `1', which is "correct
8952 enough" for all architectures, and don't let the target override. */
8953 dw2_asm_output_data (1, 1,
8954 "Minimum Instruction Length");
8956 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
8957 "Default is_stmt_start flag");
8958 dw2_asm_output_data (1, DWARF_LINE_BASE
,
8959 "Line Base Value (Special Opcodes)");
8960 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
8961 "Line Range Value (Special Opcodes)");
8962 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
8963 "Special Opcode Base");
8965 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
8969 case DW_LNS_advance_pc
:
8970 case DW_LNS_advance_line
:
8971 case DW_LNS_set_file
:
8972 case DW_LNS_set_column
:
8973 case DW_LNS_fixed_advance_pc
:
8981 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
8985 /* Write out the information about the files we use. */
8986 output_file_names ();
8987 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
8989 /* We used to set the address register to the first location in the text
8990 section here, but that didn't accomplish anything since we already
8991 have a line note for the opening brace of the first function. */
8993 /* Generate the line number to PC correspondence table, encoded as
8994 a series of state machine operations. */
8998 if (cfun
&& in_cold_section_p
)
8999 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
9001 strcpy (prev_line_label
, text_section_label
);
9002 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
9004 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
9007 /* Disable this optimization for now; GDB wants to see two line notes
9008 at the beginning of a function so it can find the end of the
9011 /* Don't emit anything for redundant notes. Just updating the
9012 address doesn't accomplish anything, because we already assume
9013 that anything after the last address is this line. */
9014 if (line_info
->dw_line_num
== current_line
9015 && line_info
->dw_file_num
== current_file
)
9019 /* Emit debug info for the address of the current line.
9021 Unfortunately, we have little choice here currently, and must always
9022 use the most general form. GCC does not know the address delta
9023 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9024 attributes which will give an upper bound on the address range. We
9025 could perhaps use length attributes to determine when it is safe to
9026 use DW_LNS_fixed_advance_pc. */
9028 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
9031 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9032 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9033 "DW_LNS_fixed_advance_pc");
9034 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9038 /* This can handle any delta. This takes
9039 4+DWARF2_ADDR_SIZE bytes. */
9040 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9041 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9042 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9043 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9046 strcpy (prev_line_label
, line_label
);
9048 /* Emit debug info for the source file of the current line, if
9049 different from the previous line. */
9050 if (line_info
->dw_file_num
!= current_file
)
9052 current_file
= line_info
->dw_file_num
;
9053 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9054 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9057 /* Emit debug info for the current line number, choosing the encoding
9058 that uses the least amount of space. */
9059 if (line_info
->dw_line_num
!= current_line
)
9061 line_offset
= line_info
->dw_line_num
- current_line
;
9062 line_delta
= line_offset
- DWARF_LINE_BASE
;
9063 current_line
= line_info
->dw_line_num
;
9064 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9065 /* This can handle deltas from -10 to 234, using the current
9066 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9068 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9069 "line %lu", current_line
);
9072 /* This can handle any delta. This takes at least 4 bytes,
9073 depending on the value being encoded. */
9074 dw2_asm_output_data (1, DW_LNS_advance_line
,
9075 "advance to line %lu", current_line
);
9076 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9077 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9081 /* We still need to start a new row, so output a copy insn. */
9082 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9085 /* Emit debug info for the address of the end of the function. */
9088 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9089 "DW_LNS_fixed_advance_pc");
9090 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
9094 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9095 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9096 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9097 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
9100 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9101 dw2_asm_output_data_uleb128 (1, NULL
);
9102 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9107 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
9109 dw_separate_line_info_ref line_info
9110 = &separate_line_info_table
[lt_index
];
9113 /* Don't emit anything for redundant notes. */
9114 if (line_info
->dw_line_num
== current_line
9115 && line_info
->dw_file_num
== current_file
9116 && line_info
->function
== function
)
9120 /* Emit debug info for the address of the current line. If this is
9121 a new function, or the first line of a function, then we need
9122 to handle it differently. */
9123 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
9125 if (function
!= line_info
->function
)
9127 function
= line_info
->function
;
9129 /* Set the address register to the first line in the function. */
9130 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9131 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9132 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9133 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9137 /* ??? See the DW_LNS_advance_pc comment above. */
9140 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9141 "DW_LNS_fixed_advance_pc");
9142 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9146 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9147 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9148 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9149 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9153 strcpy (prev_line_label
, line_label
);
9155 /* Emit debug info for the source file of the current line, if
9156 different from the previous line. */
9157 if (line_info
->dw_file_num
!= current_file
)
9159 current_file
= line_info
->dw_file_num
;
9160 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9161 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9164 /* Emit debug info for the current line number, choosing the encoding
9165 that uses the least amount of space. */
9166 if (line_info
->dw_line_num
!= current_line
)
9168 line_offset
= line_info
->dw_line_num
- current_line
;
9169 line_delta
= line_offset
- DWARF_LINE_BASE
;
9170 current_line
= line_info
->dw_line_num
;
9171 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9172 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9173 "line %lu", current_line
);
9176 dw2_asm_output_data (1, DW_LNS_advance_line
,
9177 "advance to line %lu", current_line
);
9178 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9179 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9183 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9191 /* If we're done with a function, end its sequence. */
9192 if (lt_index
== separate_line_info_table_in_use
9193 || separate_line_info_table
[lt_index
].function
!= function
)
9198 /* Emit debug info for the address of the end of the function. */
9199 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
9202 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9203 "DW_LNS_fixed_advance_pc");
9204 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9208 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9209 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9210 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9211 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9214 /* Output the marker for the end of this sequence. */
9215 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9216 dw2_asm_output_data_uleb128 (1, NULL
);
9217 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9221 /* Output the marker for the end of the line number info. */
9222 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9225 /* Given a pointer to a tree node for some base type, return a pointer to
9226 a DIE that describes the given type.
9228 This routine must only be called for GCC type nodes that correspond to
9229 Dwarf base (fundamental) types. */
9232 base_type_die (tree type
)
9234 dw_die_ref base_type_result
;
9235 enum dwarf_type encoding
;
9237 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9240 switch (TREE_CODE (type
))
9243 if (TYPE_STRING_FLAG (type
))
9245 if (TYPE_UNSIGNED (type
))
9246 encoding
= DW_ATE_unsigned_char
;
9248 encoding
= DW_ATE_signed_char
;
9250 else if (TYPE_UNSIGNED (type
))
9251 encoding
= DW_ATE_unsigned
;
9253 encoding
= DW_ATE_signed
;
9257 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9258 encoding
= DW_ATE_decimal_float
;
9260 encoding
= DW_ATE_float
;
9263 case FIXED_POINT_TYPE
:
9264 if (TYPE_UNSIGNED (type
))
9265 encoding
= DW_ATE_unsigned_fixed
;
9267 encoding
= DW_ATE_signed_fixed
;
9270 /* Dwarf2 doesn't know anything about complex ints, so use
9271 a user defined type for it. */
9273 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9274 encoding
= DW_ATE_complex_float
;
9276 encoding
= DW_ATE_lo_user
;
9280 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9281 encoding
= DW_ATE_boolean
;
9285 /* No other TREE_CODEs are Dwarf fundamental types. */
9289 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
9291 /* This probably indicates a bug. */
9292 if (! TYPE_NAME (type
))
9293 add_name_attribute (base_type_result
, "__unknown__");
9295 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9296 int_size_in_bytes (type
));
9297 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9299 return base_type_result
;
9302 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9303 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9306 is_base_type (tree type
)
9308 switch (TREE_CODE (type
))
9314 case FIXED_POINT_TYPE
:
9322 case QUAL_UNION_TYPE
:
9327 case REFERENCE_TYPE
:
9340 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9341 node, return the size in bits for the type if it is a constant, or else
9342 return the alignment for the type if the type's size is not constant, or
9343 else return BITS_PER_WORD if the type actually turns out to be an
9346 static inline unsigned HOST_WIDE_INT
9347 simple_type_size_in_bits (const_tree type
)
9349 if (TREE_CODE (type
) == ERROR_MARK
)
9350 return BITS_PER_WORD
;
9351 else if (TYPE_SIZE (type
) == NULL_TREE
)
9353 else if (host_integerp (TYPE_SIZE (type
), 1))
9354 return tree_low_cst (TYPE_SIZE (type
), 1);
9356 return TYPE_ALIGN (type
);
9359 /* Return true if the debug information for the given type should be
9360 emitted as a subrange type. */
9363 is_subrange_type (const_tree type
)
9365 tree subtype
= TREE_TYPE (type
);
9367 /* Subrange types are identified by the fact that they are integer
9368 types, and that they have a subtype which is either an integer type
9369 or an enumeral type. */
9371 if (TREE_CODE (type
) != INTEGER_TYPE
9372 || subtype
== NULL_TREE
)
9375 if (TREE_CODE (subtype
) != INTEGER_TYPE
9376 && TREE_CODE (subtype
) != ENUMERAL_TYPE
9377 && TREE_CODE (subtype
) != BOOLEAN_TYPE
)
9380 if (TREE_CODE (type
) == TREE_CODE (subtype
)
9381 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
9382 && TYPE_MIN_VALUE (type
) != NULL
9383 && TYPE_MIN_VALUE (subtype
) != NULL
9384 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
9385 && TYPE_MAX_VALUE (type
) != NULL
9386 && TYPE_MAX_VALUE (subtype
) != NULL
9387 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
9389 /* The type and its subtype have the same representation. If in
9390 addition the two types also have the same name, then the given
9391 type is not a subrange type, but rather a plain base type. */
9392 /* FIXME: brobecker/2004-03-22:
9393 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9394 therefore be sufficient to check the TYPE_SIZE node pointers
9395 rather than checking the actual size. Unfortunately, we have
9396 found some cases, such as in the Ada "integer" type, where
9397 this is not the case. Until this problem is solved, we need to
9398 keep checking the actual size. */
9399 tree type_name
= TYPE_NAME (type
);
9400 tree subtype_name
= TYPE_NAME (subtype
);
9402 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
9403 type_name
= DECL_NAME (type_name
);
9405 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
9406 subtype_name
= DECL_NAME (subtype_name
);
9408 if (type_name
== subtype_name
)
9415 /* Given a pointer to a tree node for a subrange type, return a pointer
9416 to a DIE that describes the given type. */
9419 subrange_type_die (tree type
, dw_die_ref context_die
)
9421 dw_die_ref subrange_die
;
9422 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9424 if (context_die
== NULL
)
9425 context_die
= comp_unit_die
;
9427 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9429 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9431 /* The size of the subrange type and its base type do not match,
9432 so we need to generate a size attribute for the subrange type. */
9433 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9436 if (TYPE_MIN_VALUE (type
) != NULL
)
9437 add_bound_info (subrange_die
, DW_AT_lower_bound
,
9438 TYPE_MIN_VALUE (type
));
9439 if (TYPE_MAX_VALUE (type
) != NULL
)
9440 add_bound_info (subrange_die
, DW_AT_upper_bound
,
9441 TYPE_MAX_VALUE (type
));
9443 return subrange_die
;
9446 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9447 entry that chains various modifiers in front of the given type. */
9450 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9451 dw_die_ref context_die
)
9453 enum tree_code code
= TREE_CODE (type
);
9454 dw_die_ref mod_type_die
;
9455 dw_die_ref sub_die
= NULL
;
9456 tree item_type
= NULL
;
9457 tree qualified_type
;
9460 if (code
== ERROR_MARK
)
9463 /* See if we already have the appropriately qualified variant of
9466 = get_qualified_type (type
,
9467 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9468 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9470 /* If we do, then we can just use its DIE, if it exists. */
9473 mod_type_die
= lookup_type_die (qualified_type
);
9475 return mod_type_die
;
9478 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9480 /* Handle C typedef types. */
9481 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
9483 tree dtype
= TREE_TYPE (name
);
9485 if (qualified_type
== dtype
)
9487 /* For a named type, use the typedef. */
9488 gen_type_die (qualified_type
, context_die
);
9489 return lookup_type_die (qualified_type
);
9491 else if (is_const_type
< TYPE_READONLY (dtype
)
9492 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9493 || (is_const_type
<= TYPE_READONLY (dtype
)
9494 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9495 && DECL_ORIGINAL_TYPE (name
) != type
))
9496 /* cv-unqualified version of named type. Just use the unnamed
9497 type to which it refers. */
9498 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9499 is_const_type
, is_volatile_type
,
9501 /* Else cv-qualified version of named type; fall through. */
9506 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
9507 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9509 else if (is_volatile_type
)
9511 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
9512 sub_die
= modified_type_die (type
, 0, 0, context_die
);
9514 else if (code
== POINTER_TYPE
)
9516 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
9517 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9518 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9519 item_type
= TREE_TYPE (type
);
9521 else if (code
== REFERENCE_TYPE
)
9523 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
9524 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9525 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9526 item_type
= TREE_TYPE (type
);
9528 else if (is_subrange_type (type
))
9530 mod_type_die
= subrange_type_die (type
, context_die
);
9531 item_type
= TREE_TYPE (type
);
9533 else if (is_base_type (type
))
9534 mod_type_die
= base_type_die (type
);
9537 gen_type_die (type
, context_die
);
9539 /* We have to get the type_main_variant here (and pass that to the
9540 `lookup_type_die' routine) because the ..._TYPE node we have
9541 might simply be a *copy* of some original type node (where the
9542 copy was created to help us keep track of typedef names) and
9543 that copy might have a different TYPE_UID from the original
9545 if (TREE_CODE (type
) != VECTOR_TYPE
)
9546 return lookup_type_die (type_main_variant (type
));
9548 /* Vectors have the debugging information in the type,
9549 not the main variant. */
9550 return lookup_type_die (type
);
9553 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9554 don't output a DW_TAG_typedef, since there isn't one in the
9555 user's program; just attach a DW_AT_name to the type. */
9557 && (TREE_CODE (name
) != TYPE_DECL
9558 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
9560 if (TREE_CODE (name
) == TYPE_DECL
)
9561 /* Could just call add_name_and_src_coords_attributes here,
9562 but since this is a builtin type it doesn't have any
9563 useful source coordinates anyway. */
9564 name
= DECL_NAME (name
);
9565 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9569 equate_type_number_to_die (qualified_type
, mod_type_die
);
9572 /* We must do this after the equate_type_number_to_die call, in case
9573 this is a recursive type. This ensures that the modified_type_die
9574 recursion will terminate even if the type is recursive. Recursive
9575 types are possible in Ada. */
9576 sub_die
= modified_type_die (item_type
,
9577 TYPE_READONLY (item_type
),
9578 TYPE_VOLATILE (item_type
),
9581 if (sub_die
!= NULL
)
9582 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9584 return mod_type_die
;
9587 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9588 an enumerated type. */
9591 type_is_enum (const_tree type
)
9593 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9596 /* Return the DBX register number described by a given RTL node. */
9599 dbx_reg_number (const_rtx rtl
)
9601 unsigned regno
= REGNO (rtl
);
9603 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9605 #ifdef LEAF_REG_REMAP
9606 if (current_function_uses_only_leaf_regs
)
9608 int leaf_reg
= LEAF_REG_REMAP (regno
);
9610 regno
= (unsigned) leaf_reg
;
9614 return DBX_REGISTER_NUMBER (regno
);
9617 /* Optionally add a DW_OP_piece term to a location description expression.
9618 DW_OP_piece is only added if the location description expression already
9619 doesn't end with DW_OP_piece. */
9622 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9624 dw_loc_descr_ref loc
;
9626 if (*list_head
!= NULL
)
9628 /* Find the end of the chain. */
9629 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9632 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9633 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9637 /* Return a location descriptor that designates a machine register or
9638 zero if there is none. */
9640 static dw_loc_descr_ref
9641 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9645 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9648 regs
= targetm
.dwarf_register_span (rtl
);
9650 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9651 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9653 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9656 /* Return a location descriptor that designates a machine register for
9657 a given hard register number. */
9659 static dw_loc_descr_ref
9660 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9662 dw_loc_descr_ref reg_loc_descr
= new_reg_loc_descr (regno
, 0);
9664 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9665 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9667 return reg_loc_descr
;
9670 /* Given an RTL of a register, return a location descriptor that
9671 designates a value that spans more than one register. */
9673 static dw_loc_descr_ref
9674 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9675 enum var_init_status initialized
)
9679 dw_loc_descr_ref loc_result
= NULL
;
9682 #ifdef LEAF_REG_REMAP
9683 if (current_function_uses_only_leaf_regs
)
9685 int leaf_reg
= LEAF_REG_REMAP (reg
);
9687 reg
= (unsigned) leaf_reg
;
9690 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9691 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9693 /* Simple, contiguous registers. */
9694 if (regs
== NULL_RTX
)
9696 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9703 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9704 VAR_INIT_STATUS_INITIALIZED
);
9705 add_loc_descr (&loc_result
, t
);
9706 add_loc_descr_op_piece (&loc_result
, size
);
9712 /* Now onto stupid register sets in non contiguous locations. */
9714 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9716 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9719 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9723 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9724 VAR_INIT_STATUS_INITIALIZED
);
9725 add_loc_descr (&loc_result
, t
);
9726 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9727 add_loc_descr_op_piece (&loc_result
, size
);
9730 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9731 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9735 #endif /* DWARF2_DEBUGGING_INFO */
9737 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9739 /* Return a location descriptor that designates a constant. */
9741 static dw_loc_descr_ref
9742 int_loc_descriptor (HOST_WIDE_INT i
)
9744 enum dwarf_location_atom op
;
9746 /* Pick the smallest representation of a constant, rather than just
9747 defaulting to the LEB encoding. */
9751 op
= DW_OP_lit0
+ i
;
9754 else if (i
<= 0xffff)
9756 else if (HOST_BITS_PER_WIDE_INT
== 32
9766 else if (i
>= -0x8000)
9768 else if (HOST_BITS_PER_WIDE_INT
== 32
9769 || i
>= -0x80000000)
9775 return new_loc_descr (op
, i
, 0);
9779 #ifdef DWARF2_DEBUGGING_INFO
9781 /* Return a location descriptor that designates a base+offset location. */
9783 static dw_loc_descr_ref
9784 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
9785 enum var_init_status initialized
)
9788 dw_loc_descr_ref result
;
9789 dw_fde_ref fde
= current_fde ();
9791 /* We only use "frame base" when we're sure we're talking about the
9792 post-prologue local stack frame. We do this by *not* running
9793 register elimination until this point, and recognizing the special
9794 argument pointer and soft frame pointer rtx's. */
9795 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
9797 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9801 if (GET_CODE (elim
) == PLUS
)
9803 offset
+= INTVAL (XEXP (elim
, 1));
9804 elim
= XEXP (elim
, 0);
9806 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9807 && (elim
== hard_frame_pointer_rtx
9808 || elim
== stack_pointer_rtx
))
9809 || elim
== (frame_pointer_needed
9810 ? hard_frame_pointer_rtx
9811 : stack_pointer_rtx
));
9813 /* If drap register is used to align stack, use frame
9814 pointer + offset to access stack variables. If stack
9815 is aligned without drap, use stack pointer + offset to
9816 access stack variables. */
9817 if (crtl
->stack_realign_tried
9818 && cfa
.reg
== HARD_FRAME_POINTER_REGNUM
9819 && reg
== frame_pointer_rtx
)
9822 = DWARF_FRAME_REGNUM (cfa
.indirect
9823 ? HARD_FRAME_POINTER_REGNUM
9824 : STACK_POINTER_REGNUM
);
9825 return new_reg_loc_descr (base_reg
, offset
);
9828 offset
+= frame_pointer_fb_offset
;
9829 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9833 && fde
->drap_reg
!= INVALID_REGNUM
9834 && (fde
->drap_reg
== REGNO (reg
)
9835 || fde
->vdrap_reg
== REGNO (reg
)))
9837 /* Use cfa+offset to represent the location of arguments passed
9838 on stack when drap is used to align stack. */
9839 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9842 regno
= dbx_reg_number (reg
);
9844 result
= new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
9846 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
9848 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9849 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9854 /* Return true if this RTL expression describes a base+offset calculation. */
9857 is_based_loc (const_rtx rtl
)
9859 return (GET_CODE (rtl
) == PLUS
9860 && ((REG_P (XEXP (rtl
, 0))
9861 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
9862 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
9865 /* Return a descriptor that describes the concatenation of N locations
9866 used to form the address of a memory location. */
9868 static dw_loc_descr_ref
9869 concatn_mem_loc_descriptor (rtx concatn
, enum machine_mode mode
,
9870 enum var_init_status initialized
)
9873 dw_loc_descr_ref cc_loc_result
= NULL
;
9874 unsigned int n
= XVECLEN (concatn
, 0);
9876 for (i
= 0; i
< n
; ++i
)
9878 dw_loc_descr_ref ref
;
9879 rtx x
= XVECEXP (concatn
, 0, i
);
9881 ref
= mem_loc_descriptor (x
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9885 add_loc_descr (&cc_loc_result
, ref
);
9886 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9889 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9890 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9892 return cc_loc_result
;
9895 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
9898 static dw_loc_descr_ref
9899 tls_mem_loc_descriptor (rtx mem
)
9902 dw_loc_descr_ref loc_result
, loc_result2
;
9904 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
9907 base
= get_base_address (MEM_EXPR (mem
));
9909 || TREE_CODE (base
) != VAR_DECL
9910 || !DECL_THREAD_LOCAL_P (base
))
9913 loc_result
= loc_descriptor_from_tree_1 (MEM_EXPR (mem
), 2);
9914 if (loc_result
== NULL
)
9917 if (INTVAL (MEM_OFFSET (mem
)))
9919 if (INTVAL (MEM_OFFSET (mem
)) >= 0)
9920 add_loc_descr (&loc_result
,
9921 new_loc_descr (DW_OP_plus_uconst
,
9922 INTVAL (MEM_OFFSET (mem
)), 0));
9925 loc_result2
= mem_loc_descriptor (MEM_OFFSET (mem
), GET_MODE (mem
),
9926 VAR_INIT_STATUS_INITIALIZED
);
9927 if (loc_result2
== 0)
9929 add_loc_descr (&loc_result
, loc_result2
);
9930 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
9937 /* The following routine converts the RTL for a variable or parameter
9938 (resident in memory) into an equivalent Dwarf representation of a
9939 mechanism for getting the address of that same variable onto the top of a
9940 hypothetical "address evaluation" stack.
9942 When creating memory location descriptors, we are effectively transforming
9943 the RTL for a memory-resident object into its Dwarf postfix expression
9944 equivalent. This routine recursively descends an RTL tree, turning
9945 it into Dwarf postfix code as it goes.
9947 MODE is the mode of the memory reference, needed to handle some
9948 autoincrement addressing modes.
9950 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9951 location list for RTL.
9953 Return 0 if we can't represent the location. */
9955 static dw_loc_descr_ref
9956 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
9957 enum var_init_status initialized
)
9959 dw_loc_descr_ref mem_loc_result
= NULL
;
9960 enum dwarf_location_atom op
;
9962 /* Note that for a dynamically sized array, the location we will generate a
9963 description of here will be the lowest numbered location which is
9964 actually within the array. That's *not* necessarily the same as the
9965 zeroth element of the array. */
9967 rtl
= targetm
.delegitimize_address (rtl
);
9969 switch (GET_CODE (rtl
))
9974 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9975 just fall into the SUBREG code. */
9977 /* ... fall through ... */
9980 /* The case of a subreg may arise when we have a local (register)
9981 variable or a formal (register) parameter which doesn't quite fill
9982 up an entire register. For now, just assume that it is
9983 legitimate to make the Dwarf info refer to the whole register which
9984 contains the given subreg. */
9985 rtl
= XEXP (rtl
, 0);
9987 /* ... fall through ... */
9990 /* Whenever a register number forms a part of the description of the
9991 method for calculating the (dynamic) address of a memory resident
9992 object, DWARF rules require the register number be referred to as
9993 a "base register". This distinction is not based in any way upon
9994 what category of register the hardware believes the given register
9995 belongs to. This is strictly DWARF terminology we're dealing with
9996 here. Note that in cases where the location of a memory-resident
9997 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9998 OP_CONST (0)) the actual DWARF location descriptor that we generate
9999 may just be OP_BASEREG (basereg). This may look deceptively like
10000 the object in question was allocated to a register (rather than in
10001 memory) so DWARF consumers need to be aware of the subtle
10002 distinction between OP_REG and OP_BASEREG. */
10003 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
10004 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
10008 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
10009 VAR_INIT_STATUS_INITIALIZED
);
10010 if (mem_loc_result
== NULL
)
10011 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
10012 if (mem_loc_result
!= 0)
10013 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
10017 rtl
= XEXP (rtl
, 1);
10019 /* ... fall through ... */
10022 /* Some ports can transform a symbol ref into a label ref, because
10023 the symbol ref is too far away and has to be dumped into a constant
10027 /* Alternatively, the symbol in the constant pool might be referenced
10028 by a different symbol. */
10029 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
10032 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
10034 if (GET_CODE (tmp
) == SYMBOL_REF
)
10037 if (CONSTANT_POOL_ADDRESS_P (tmp
))
10038 get_pool_constant_mark (tmp
, &marked
);
10043 /* If all references to this pool constant were optimized away,
10044 it was not output and thus we can't represent it.
10045 FIXME: might try to use DW_OP_const_value here, though
10046 DW_OP_piece complicates it. */
10051 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
10052 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10053 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10054 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
10058 /* Extract the PLUS expression nested inside and fall into
10059 PLUS code below. */
10060 rtl
= XEXP (rtl
, 1);
10065 /* Turn these into a PLUS expression and fall into the PLUS code
10067 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
10068 GEN_INT (GET_CODE (rtl
) == PRE_INC
10069 ? GET_MODE_UNIT_SIZE (mode
)
10070 : -GET_MODE_UNIT_SIZE (mode
)));
10072 /* ... fall through ... */
10076 if (is_based_loc (rtl
))
10077 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
10078 INTVAL (XEXP (rtl
, 1)),
10079 VAR_INIT_STATUS_INITIALIZED
);
10082 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10083 VAR_INIT_STATUS_INITIALIZED
);
10084 if (mem_loc_result
== 0)
10087 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
10088 && INTVAL (XEXP (rtl
, 1)) >= 0)
10089 add_loc_descr (&mem_loc_result
,
10090 new_loc_descr (DW_OP_plus_uconst
,
10091 INTVAL (XEXP (rtl
, 1)), 0));
10094 dw_loc_descr_ref mem_loc_result2
10095 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10096 VAR_INIT_STATUS_INITIALIZED
);
10097 if (mem_loc_result2
== 0)
10099 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
10100 add_loc_descr (&mem_loc_result
,
10101 new_loc_descr (DW_OP_plus
, 0, 0));
10106 /* If a pseudo-reg is optimized away, it is possible for it to
10107 be replaced with a MEM containing a multiply or shift. */
10126 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10127 VAR_INIT_STATUS_INITIALIZED
);
10128 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10129 VAR_INIT_STATUS_INITIALIZED
);
10131 if (op0
== 0 || op1
== 0)
10134 mem_loc_result
= op0
;
10135 add_loc_descr (&mem_loc_result
, op1
);
10136 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
10141 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
10145 mem_loc_result
= concatn_mem_loc_descriptor (rtl
, mode
,
10146 VAR_INIT_STATUS_INITIALIZED
);
10150 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10151 can't express it in the debug info. This can happen e.g. with some
10156 gcc_unreachable ();
10159 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10160 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10162 return mem_loc_result
;
10165 /* Return a descriptor that describes the concatenation of two locations.
10166 This is typically a complex variable. */
10168 static dw_loc_descr_ref
10169 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
10171 dw_loc_descr_ref cc_loc_result
= NULL
;
10172 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, VAR_INIT_STATUS_INITIALIZED
);
10173 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, VAR_INIT_STATUS_INITIALIZED
);
10175 if (x0_ref
== 0 || x1_ref
== 0)
10178 cc_loc_result
= x0_ref
;
10179 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
10181 add_loc_descr (&cc_loc_result
, x1_ref
);
10182 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
10184 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10185 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10187 return cc_loc_result
;
10190 /* Return a descriptor that describes the concatenation of N
10193 static dw_loc_descr_ref
10194 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
10197 dw_loc_descr_ref cc_loc_result
= NULL
;
10198 unsigned int n
= XVECLEN (concatn
, 0);
10200 for (i
= 0; i
< n
; ++i
)
10202 dw_loc_descr_ref ref
;
10203 rtx x
= XVECEXP (concatn
, 0, i
);
10205 ref
= loc_descriptor (x
, VAR_INIT_STATUS_INITIALIZED
);
10209 add_loc_descr (&cc_loc_result
, ref
);
10210 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
10213 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10214 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10216 return cc_loc_result
;
10219 /* Output a proper Dwarf location descriptor for a variable or parameter
10220 which is either allocated in a register or in a memory location. For a
10221 register, we just generate an OP_REG and the register number. For a
10222 memory location we provide a Dwarf postfix expression describing how to
10223 generate the (dynamic) address of the object onto the address stack.
10225 If we don't know how to describe it, return 0. */
10227 static dw_loc_descr_ref
10228 loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10230 dw_loc_descr_ref loc_result
= NULL
;
10232 switch (GET_CODE (rtl
))
10235 /* The case of a subreg may arise when we have a local (register)
10236 variable or a formal (register) parameter which doesn't quite fill
10237 up an entire register. For now, just assume that it is
10238 legitimate to make the Dwarf info refer to the whole register which
10239 contains the given subreg. */
10240 rtl
= SUBREG_REG (rtl
);
10242 /* ... fall through ... */
10245 loc_result
= reg_loc_descriptor (rtl
, initialized
);
10249 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
10251 if (loc_result
== NULL
)
10252 loc_result
= tls_mem_loc_descriptor (rtl
);
10256 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
10261 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
10266 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
10268 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), initialized
);
10272 rtl
= XEXP (rtl
, 1);
10277 rtvec par_elems
= XVEC (rtl
, 0);
10278 int num_elem
= GET_NUM_ELEM (par_elems
);
10279 enum machine_mode mode
;
10282 /* Create the first one, so we have something to add to. */
10283 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
10285 if (loc_result
== NULL
)
10287 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
10288 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10289 for (i
= 1; i
< num_elem
; i
++)
10291 dw_loc_descr_ref temp
;
10293 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
10297 add_loc_descr (&loc_result
, temp
);
10298 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
10299 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10305 gcc_unreachable ();
10311 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10312 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10313 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10314 top-level invocation, and we require the address of LOC; is 0 if we require
10315 the value of LOC. */
10317 static dw_loc_descr_ref
10318 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
10320 dw_loc_descr_ref ret
, ret1
;
10321 int have_address
= 0;
10322 enum dwarf_location_atom op
;
10324 /* ??? Most of the time we do not take proper care for sign/zero
10325 extending the values properly. Hopefully this won't be a real
10328 switch (TREE_CODE (loc
))
10333 case PLACEHOLDER_EXPR
:
10334 /* This case involves extracting fields from an object to determine the
10335 position of other fields. We don't try to encode this here. The
10336 only user of this is Ada, which encodes the needed information using
10337 the names of types. */
10343 case PREINCREMENT_EXPR
:
10344 case PREDECREMENT_EXPR
:
10345 case POSTINCREMENT_EXPR
:
10346 case POSTDECREMENT_EXPR
:
10347 /* There are no opcodes for these operations. */
10351 /* If we already want an address, there's nothing we can do. */
10355 /* Otherwise, process the argument and look for the address. */
10356 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
10359 if (DECL_THREAD_LOCAL_P (loc
))
10363 unsigned second_op
;
10365 if (targetm
.have_tls
)
10367 /* If this is not defined, we have no way to emit the
10369 if (!targetm
.asm_out
.output_dwarf_dtprel
)
10372 /* The way DW_OP_GNU_push_tls_address is specified, we
10373 can only look up addresses of objects in the current
10375 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
10377 first_op
= INTERNAL_DW_OP_tls_addr
;
10378 second_op
= DW_OP_GNU_push_tls_address
;
10382 if (!targetm
.emutls
.debug_form_tls_address
)
10384 loc
= emutls_decl (loc
);
10385 first_op
= DW_OP_addr
;
10386 second_op
= DW_OP_form_tls_address
;
10389 rtl
= rtl_for_decl_location (loc
);
10390 if (rtl
== NULL_RTX
)
10395 rtl
= XEXP (rtl
, 0);
10396 if (! CONSTANT_P (rtl
))
10399 ret
= new_loc_descr (first_op
, 0, 0);
10400 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10401 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10403 ret1
= new_loc_descr (second_op
, 0, 0);
10404 add_loc_descr (&ret
, ret1
);
10412 if (DECL_HAS_VALUE_EXPR_P (loc
))
10413 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
10418 case FUNCTION_DECL
:
10420 rtx rtl
= rtl_for_decl_location (loc
);
10422 if (rtl
== NULL_RTX
)
10424 else if (GET_CODE (rtl
) == CONST_INT
)
10426 HOST_WIDE_INT val
= INTVAL (rtl
);
10427 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
10428 val
&= GET_MODE_MASK (DECL_MODE (loc
));
10429 ret
= int_loc_descriptor (val
);
10431 else if (GET_CODE (rtl
) == CONST_STRING
)
10433 else if (CONSTANT_P (rtl
))
10435 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
10436 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10437 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10441 enum machine_mode mode
;
10443 /* Certain constructs can only be represented at top-level. */
10444 if (want_address
== 2)
10445 return loc_descriptor (rtl
, VAR_INIT_STATUS_INITIALIZED
);
10447 mode
= GET_MODE (rtl
);
10450 rtl
= XEXP (rtl
, 0);
10453 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10459 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10463 case COMPOUND_EXPR
:
10464 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
10467 case VIEW_CONVERT_EXPR
:
10470 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
10472 case COMPONENT_REF
:
10473 case BIT_FIELD_REF
:
10475 case ARRAY_RANGE_REF
:
10478 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
10479 enum machine_mode mode
;
10481 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
10483 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
10484 &unsignedp
, &volatilep
, false);
10489 ret
= loc_descriptor_from_tree_1 (obj
, 1);
10491 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
10494 if (offset
!= NULL_TREE
)
10496 /* Variable offset. */
10497 ret1
= loc_descriptor_from_tree_1 (offset
, 0);
10500 add_loc_descr (&ret
, ret1
);
10501 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10504 bytepos
= bitpos
/ BITS_PER_UNIT
;
10506 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
10507 else if (bytepos
< 0)
10509 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
10510 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10518 if (host_integerp (loc
, 0))
10519 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
10526 /* Get an RTL for this, if something has been emitted. */
10527 rtx rtl
= lookup_constant_def (loc
);
10528 enum machine_mode mode
;
10530 if (!rtl
|| !MEM_P (rtl
))
10532 mode
= GET_MODE (rtl
);
10533 rtl
= XEXP (rtl
, 0);
10534 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10539 case TRUTH_AND_EXPR
:
10540 case TRUTH_ANDIF_EXPR
:
10545 case TRUTH_XOR_EXPR
:
10550 case TRUTH_OR_EXPR
:
10551 case TRUTH_ORIF_EXPR
:
10556 case FLOOR_DIV_EXPR
:
10557 case CEIL_DIV_EXPR
:
10558 case ROUND_DIV_EXPR
:
10559 case TRUNC_DIV_EXPR
:
10567 case FLOOR_MOD_EXPR
:
10568 case CEIL_MOD_EXPR
:
10569 case ROUND_MOD_EXPR
:
10570 case TRUNC_MOD_EXPR
:
10583 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
10586 case POINTER_PLUS_EXPR
:
10588 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
10589 && host_integerp (TREE_OPERAND (loc
, 1), 0))
10591 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10595 add_loc_descr (&ret
,
10596 new_loc_descr (DW_OP_plus_uconst
,
10597 tree_low_cst (TREE_OPERAND (loc
, 1),
10607 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10614 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10621 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10628 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10643 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10644 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10645 if (ret
== 0 || ret1
== 0)
10648 add_loc_descr (&ret
, ret1
);
10649 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10652 case TRUTH_NOT_EXPR
:
10666 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10670 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10676 const enum tree_code code
=
10677 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
10679 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
10680 build2 (code
, integer_type_node
,
10681 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
10682 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
10685 /* ... fall through ... */
10689 dw_loc_descr_ref lhs
10690 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10691 dw_loc_descr_ref rhs
10692 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
10693 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
10695 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10696 if (ret
== 0 || lhs
== 0 || rhs
== 0)
10699 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10700 add_loc_descr (&ret
, bra_node
);
10702 add_loc_descr (&ret
, rhs
);
10703 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
10704 add_loc_descr (&ret
, jump_node
);
10706 add_loc_descr (&ret
, lhs
);
10707 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10708 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
10710 /* ??? Need a node to point the skip at. Use a nop. */
10711 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
10712 add_loc_descr (&ret
, tmp
);
10713 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10714 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
10718 case FIX_TRUNC_EXPR
:
10722 /* Leave front-end specific codes as simply unknown. This comes
10723 up, for instance, with the C STMT_EXPR. */
10724 if ((unsigned int) TREE_CODE (loc
)
10725 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
10728 #ifdef ENABLE_CHECKING
10729 /* Otherwise this is a generic code; we should just lists all of
10730 these explicitly. We forgot one. */
10731 gcc_unreachable ();
10733 /* In a release build, we want to degrade gracefully: better to
10734 generate incomplete debugging information than to crash. */
10739 /* Show if we can't fill the request for an address. */
10740 if (want_address
&& !have_address
)
10743 /* If we've got an address and don't want one, dereference. */
10744 if (!want_address
&& have_address
&& ret
)
10746 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
10748 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
10750 else if (size
== DWARF2_ADDR_SIZE
)
10753 op
= DW_OP_deref_size
;
10755 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
10761 static inline dw_loc_descr_ref
10762 loc_descriptor_from_tree (tree loc
)
10764 return loc_descriptor_from_tree_1 (loc
, 2);
10767 /* Given a value, round it up to the lowest multiple of `boundary'
10768 which is not less than the value itself. */
10770 static inline HOST_WIDE_INT
10771 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
10773 return (((value
+ boundary
- 1) / boundary
) * boundary
);
10776 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10777 pointer to the declared type for the relevant field variable, or return
10778 `integer_type_node' if the given node turns out to be an
10779 ERROR_MARK node. */
10782 field_type (const_tree decl
)
10786 if (TREE_CODE (decl
) == ERROR_MARK
)
10787 return integer_type_node
;
10789 type
= DECL_BIT_FIELD_TYPE (decl
);
10790 if (type
== NULL_TREE
)
10791 type
= TREE_TYPE (decl
);
10796 /* Given a pointer to a tree node, return the alignment in bits for
10797 it, or else return BITS_PER_WORD if the node actually turns out to
10798 be an ERROR_MARK node. */
10800 static inline unsigned
10801 simple_type_align_in_bits (const_tree type
)
10803 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
10806 static inline unsigned
10807 simple_decl_align_in_bits (const_tree decl
)
10809 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
10812 /* Return the result of rounding T up to ALIGN. */
10814 static inline HOST_WIDE_INT
10815 round_up_to_align (HOST_WIDE_INT t
, unsigned int align
)
10817 /* We must be careful if T is negative because HOST_WIDE_INT can be
10818 either "above" or "below" unsigned int as per the C promotion
10819 rules, depending on the host, thus making the signedness of the
10820 direct multiplication and division unpredictable. */
10821 unsigned HOST_WIDE_INT u
= (unsigned HOST_WIDE_INT
) t
;
10827 return (HOST_WIDE_INT
) u
;
10830 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10831 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10832 or return 0 if we are unable to determine what that offset is, either
10833 because the argument turns out to be a pointer to an ERROR_MARK node, or
10834 because the offset is actually variable. (We can't handle the latter case
10837 static HOST_WIDE_INT
10838 field_byte_offset (const_tree decl
)
10840 HOST_WIDE_INT object_offset_in_bits
;
10841 HOST_WIDE_INT bitpos_int
;
10843 if (TREE_CODE (decl
) == ERROR_MARK
)
10846 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
10848 /* We cannot yet cope with fields whose positions are variable, so
10849 for now, when we see such things, we simply return 0. Someday, we may
10850 be able to handle such cases, but it will be damn difficult. */
10851 if (! host_integerp (bit_position (decl
), 0))
10854 bitpos_int
= int_bit_position (decl
);
10856 #ifdef PCC_BITFIELD_TYPE_MATTERS
10857 if (PCC_BITFIELD_TYPE_MATTERS
)
10860 tree field_size_tree
;
10861 HOST_WIDE_INT deepest_bitpos
;
10862 unsigned HOST_WIDE_INT field_size_in_bits
;
10863 unsigned int type_align_in_bits
;
10864 unsigned int decl_align_in_bits
;
10865 unsigned HOST_WIDE_INT type_size_in_bits
;
10867 type
= field_type (decl
);
10868 field_size_tree
= DECL_SIZE (decl
);
10870 /* The size could be unspecified if there was an error, or for
10871 a flexible array member. */
10872 if (! field_size_tree
)
10873 field_size_tree
= bitsize_zero_node
;
10875 /* If we don't know the size of the field, pretend it's a full word. */
10876 if (host_integerp (field_size_tree
, 1))
10877 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
10879 field_size_in_bits
= BITS_PER_WORD
;
10881 type_size_in_bits
= simple_type_size_in_bits (type
);
10882 type_align_in_bits
= simple_type_align_in_bits (type
);
10883 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
10885 /* The GCC front-end doesn't make any attempt to keep track of the
10886 starting bit offset (relative to the start of the containing
10887 structure type) of the hypothetical "containing object" for a
10888 bit-field. Thus, when computing the byte offset value for the
10889 start of the "containing object" of a bit-field, we must deduce
10890 this information on our own. This can be rather tricky to do in
10891 some cases. For example, handling the following structure type
10892 definition when compiling for an i386/i486 target (which only
10893 aligns long long's to 32-bit boundaries) can be very tricky:
10895 struct S { int field1; long long field2:31; };
10897 Fortunately, there is a simple rule-of-thumb which can be used
10898 in such cases. When compiling for an i386/i486, GCC will
10899 allocate 8 bytes for the structure shown above. It decides to
10900 do this based upon one simple rule for bit-field allocation.
10901 GCC allocates each "containing object" for each bit-field at
10902 the first (i.e. lowest addressed) legitimate alignment boundary
10903 (based upon the required minimum alignment for the declared
10904 type of the field) which it can possibly use, subject to the
10905 condition that there is still enough available space remaining
10906 in the containing object (when allocated at the selected point)
10907 to fully accommodate all of the bits of the bit-field itself.
10909 This simple rule makes it obvious why GCC allocates 8 bytes for
10910 each object of the structure type shown above. When looking
10911 for a place to allocate the "containing object" for `field2',
10912 the compiler simply tries to allocate a 64-bit "containing
10913 object" at each successive 32-bit boundary (starting at zero)
10914 until it finds a place to allocate that 64- bit field such that
10915 at least 31 contiguous (and previously unallocated) bits remain
10916 within that selected 64 bit field. (As it turns out, for the
10917 example above, the compiler finds it is OK to allocate the
10918 "containing object" 64-bit field at bit-offset zero within the
10921 Here we attempt to work backwards from the limited set of facts
10922 we're given, and we try to deduce from those facts, where GCC
10923 must have believed that the containing object started (within
10924 the structure type). The value we deduce is then used (by the
10925 callers of this routine) to generate DW_AT_location and
10926 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10927 the case of DW_AT_location, regular fields as well). */
10929 /* Figure out the bit-distance from the start of the structure to
10930 the "deepest" bit of the bit-field. */
10931 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
10933 /* This is the tricky part. Use some fancy footwork to deduce
10934 where the lowest addressed bit of the containing object must
10936 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10938 /* Round up to type_align by default. This works best for
10940 object_offset_in_bits
10941 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
10943 if (object_offset_in_bits
> bitpos_int
)
10945 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10947 /* Round up to decl_align instead. */
10948 object_offset_in_bits
10949 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
10954 object_offset_in_bits
= bitpos_int
;
10956 return object_offset_in_bits
/ BITS_PER_UNIT
;
10959 /* The following routines define various Dwarf attributes and any data
10960 associated with them. */
10962 /* Add a location description attribute value to a DIE.
10964 This emits location attributes suitable for whole variables and
10965 whole parameters. Note that the location attributes for struct fields are
10966 generated by the routine `data_member_location_attribute' below. */
10969 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10970 dw_loc_descr_ref descr
)
10973 add_AT_loc (die
, attr_kind
, descr
);
10976 /* Attach the specialized form of location attribute used for data members of
10977 struct and union types. In the special case of a FIELD_DECL node which
10978 represents a bit-field, the "offset" part of this special location
10979 descriptor must indicate the distance in bytes from the lowest-addressed
10980 byte of the containing struct or union type to the lowest-addressed byte of
10981 the "containing object" for the bit-field. (See the `field_byte_offset'
10984 For any given bit-field, the "containing object" is a hypothetical object
10985 (of some integral or enum type) within which the given bit-field lives. The
10986 type of this hypothetical "containing object" is always the same as the
10987 declared type of the individual bit-field itself (for GCC anyway... the
10988 DWARF spec doesn't actually mandate this). Note that it is the size (in
10989 bytes) of the hypothetical "containing object" which will be given in the
10990 DW_AT_byte_size attribute for this bit-field. (See the
10991 `byte_size_attribute' function below.) It is also used when calculating the
10992 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10993 function below.) */
10996 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
10998 HOST_WIDE_INT offset
;
10999 dw_loc_descr_ref loc_descr
= 0;
11001 if (TREE_CODE (decl
) == TREE_BINFO
)
11003 /* We're working on the TAG_inheritance for a base class. */
11004 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
11006 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11007 aren't at a fixed offset from all (sub)objects of the same
11008 type. We need to extract the appropriate offset from our
11009 vtable. The following dwarf expression means
11011 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11013 This is specific to the V3 ABI, of course. */
11015 dw_loc_descr_ref tmp
;
11017 /* Make a copy of the object address. */
11018 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
11019 add_loc_descr (&loc_descr
, tmp
);
11021 /* Extract the vtable address. */
11022 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
11023 add_loc_descr (&loc_descr
, tmp
);
11025 /* Calculate the address of the offset. */
11026 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
11027 gcc_assert (offset
< 0);
11029 tmp
= int_loc_descriptor (-offset
);
11030 add_loc_descr (&loc_descr
, tmp
);
11031 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
11032 add_loc_descr (&loc_descr
, tmp
);
11034 /* Extract the offset. */
11035 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
11036 add_loc_descr (&loc_descr
, tmp
);
11038 /* Add it to the object address. */
11039 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
11040 add_loc_descr (&loc_descr
, tmp
);
11043 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
11046 offset
= field_byte_offset (decl
);
11050 enum dwarf_location_atom op
;
11052 /* The DWARF2 standard says that we should assume that the structure
11053 address is already on the stack, so we can specify a structure field
11054 address by using DW_OP_plus_uconst. */
11056 #ifdef MIPS_DEBUGGING_INFO
11057 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11058 operator correctly. It works only if we leave the offset on the
11062 op
= DW_OP_plus_uconst
;
11065 loc_descr
= new_loc_descr (op
, offset
, 0);
11068 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
11071 /* Writes integer values to dw_vec_const array. */
11074 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
11078 *dest
++ = val
& 0xff;
11084 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11086 static HOST_WIDE_INT
11087 extract_int (const unsigned char *src
, unsigned int size
)
11089 HOST_WIDE_INT val
= 0;
11095 val
|= *--src
& 0xff;
11101 /* Writes floating point values to dw_vec_const array. */
11104 insert_float (const_rtx rtl
, unsigned char *array
)
11106 REAL_VALUE_TYPE rv
;
11110 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
11111 real_to_target (val
, &rv
, GET_MODE (rtl
));
11113 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11114 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
11116 insert_int (val
[i
], 4, array
);
11121 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11122 does not have a "location" either in memory or in a register. These
11123 things can arise in GNU C when a constant is passed as an actual parameter
11124 to an inlined function. They can also arise in C++ where declared
11125 constants do not necessarily get memory "homes". */
11128 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
11130 switch (GET_CODE (rtl
))
11134 HOST_WIDE_INT val
= INTVAL (rtl
);
11137 add_AT_int (die
, DW_AT_const_value
, val
);
11139 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
11144 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11145 floating-point constant. A CONST_DOUBLE is used whenever the
11146 constant requires more than one word in order to be adequately
11147 represented. We output CONST_DOUBLEs as blocks. */
11149 enum machine_mode mode
= GET_MODE (rtl
);
11151 if (SCALAR_FLOAT_MODE_P (mode
))
11153 unsigned int length
= GET_MODE_SIZE (mode
);
11154 unsigned char *array
= GGC_NEWVEC (unsigned char, length
);
11156 insert_float (rtl
, array
);
11157 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
11161 /* ??? We really should be using HOST_WIDE_INT throughout. */
11162 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
11164 add_AT_long_long (die
, DW_AT_const_value
,
11165 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
11172 enum machine_mode mode
= GET_MODE (rtl
);
11173 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
11174 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
11175 unsigned char *array
= GGC_NEWVEC (unsigned char, length
* elt_size
);
11179 switch (GET_MODE_CLASS (mode
))
11181 case MODE_VECTOR_INT
:
11182 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11184 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11185 HOST_WIDE_INT lo
, hi
;
11187 switch (GET_CODE (elt
))
11195 lo
= CONST_DOUBLE_LOW (elt
);
11196 hi
= CONST_DOUBLE_HIGH (elt
);
11200 gcc_unreachable ();
11203 if (elt_size
<= sizeof (HOST_WIDE_INT
))
11204 insert_int (lo
, elt_size
, p
);
11207 unsigned char *p0
= p
;
11208 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
11210 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
11211 if (WORDS_BIG_ENDIAN
)
11216 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
11217 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
11222 case MODE_VECTOR_FLOAT
:
11223 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11225 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11226 insert_float (elt
, p
);
11231 gcc_unreachable ();
11234 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
11239 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
11245 add_AT_addr (die
, DW_AT_const_value
, rtl
);
11246 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11250 /* In cases where an inlined instance of an inline function is passed
11251 the address of an `auto' variable (which is local to the caller) we
11252 can get a situation where the DECL_RTL of the artificial local
11253 variable (for the inlining) which acts as a stand-in for the
11254 corresponding formal parameter (of the inline function) will look
11255 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11256 exactly a compile-time constant expression, but it isn't the address
11257 of the (artificial) local variable either. Rather, it represents the
11258 *value* which the artificial local variable always has during its
11259 lifetime. We currently have no way to represent such quasi-constant
11260 values in Dwarf, so for now we just punt and generate nothing. */
11264 /* No other kinds of rtx should be possible here. */
11265 gcc_unreachable ();
11270 /* Determine whether the evaluation of EXPR references any variables
11271 or functions which aren't otherwise used (and therefore may not be
11274 reference_to_unused (tree
* tp
, int * walk_subtrees
,
11275 void * data ATTRIBUTE_UNUSED
)
11277 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
11278 *walk_subtrees
= 0;
11280 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
11281 && ! TREE_ASM_WRITTEN (*tp
))
11283 /* ??? The C++ FE emits debug information for using decls, so
11284 putting gcc_unreachable here falls over. See PR31899. For now
11285 be conservative. */
11286 else if (!cgraph_global_info_ready
11287 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
11289 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
11291 struct varpool_node
*node
= varpool_node (*tp
);
11295 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
11296 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
11298 struct cgraph_node
*node
= cgraph_node (*tp
);
11302 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
11308 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11309 for use in a later add_const_value_attribute call. */
11312 rtl_for_decl_init (tree init
, tree type
)
11314 rtx rtl
= NULL_RTX
;
11316 /* If a variable is initialized with a string constant without embedded
11317 zeros, build CONST_STRING. */
11318 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
11320 tree enttype
= TREE_TYPE (type
);
11321 tree domain
= TYPE_DOMAIN (type
);
11322 enum machine_mode mode
= TYPE_MODE (enttype
);
11324 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
11326 && integer_zerop (TYPE_MIN_VALUE (domain
))
11327 && compare_tree_int (TYPE_MAX_VALUE (domain
),
11328 TREE_STRING_LENGTH (init
) - 1) == 0
11329 && ((size_t) TREE_STRING_LENGTH (init
)
11330 == strlen (TREE_STRING_POINTER (init
)) + 1))
11331 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
11332 ggc_strdup (TREE_STRING_POINTER (init
)));
11334 /* Other aggregates, and complex values, could be represented using
11336 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
11338 /* Vectors only work if their mode is supported by the target.
11339 FIXME: generic vectors ought to work too. */
11340 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
11342 /* If the initializer is something that we know will expand into an
11343 immediate RTL constant, expand it now. We must be careful not to
11344 reference variables which won't be output. */
11345 else if (initializer_constant_valid_p (init
, type
)
11346 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
11348 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11350 if (TREE_CODE (type
) == VECTOR_TYPE
)
11351 switch (TREE_CODE (init
))
11356 if (TREE_CONSTANT (init
))
11358 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
11359 bool constant_p
= true;
11361 unsigned HOST_WIDE_INT ix
;
11363 /* Even when ctor is constant, it might contain non-*_CST
11364 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11365 belong into VECTOR_CST nodes. */
11366 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
11367 if (!CONSTANT_CLASS_P (value
))
11369 constant_p
= false;
11375 init
= build_vector_from_ctor (type
, elts
);
11385 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
11387 /* If expand_expr returns a MEM, it wasn't immediate. */
11388 gcc_assert (!rtl
|| !MEM_P (rtl
));
11394 /* Generate RTL for the variable DECL to represent its location. */
11397 rtl_for_decl_location (tree decl
)
11401 /* Here we have to decide where we are going to say the parameter "lives"
11402 (as far as the debugger is concerned). We only have a couple of
11403 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11405 DECL_RTL normally indicates where the parameter lives during most of the
11406 activation of the function. If optimization is enabled however, this
11407 could be either NULL or else a pseudo-reg. Both of those cases indicate
11408 that the parameter doesn't really live anywhere (as far as the code
11409 generation parts of GCC are concerned) during most of the function's
11410 activation. That will happen (for example) if the parameter is never
11411 referenced within the function.
11413 We could just generate a location descriptor here for all non-NULL
11414 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11415 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11416 where DECL_RTL is NULL or is a pseudo-reg.
11418 Note however that we can only get away with using DECL_INCOMING_RTL as
11419 a backup substitute for DECL_RTL in certain limited cases. In cases
11420 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11421 we can be sure that the parameter was passed using the same type as it is
11422 declared to have within the function, and that its DECL_INCOMING_RTL
11423 points us to a place where a value of that type is passed.
11425 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11426 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11427 because in these cases DECL_INCOMING_RTL points us to a value of some
11428 type which is *different* from the type of the parameter itself. Thus,
11429 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11430 such cases, the debugger would end up (for example) trying to fetch a
11431 `float' from a place which actually contains the first part of a
11432 `double'. That would lead to really incorrect and confusing
11433 output at debug-time.
11435 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11436 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11437 are a couple of exceptions however. On little-endian machines we can
11438 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11439 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11440 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11441 when (on a little-endian machine) a non-prototyped function has a
11442 parameter declared to be of type `short' or `char'. In such cases,
11443 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11444 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11445 passed `int' value. If the debugger then uses that address to fetch
11446 a `short' or a `char' (on a little-endian machine) the result will be
11447 the correct data, so we allow for such exceptional cases below.
11449 Note that our goal here is to describe the place where the given formal
11450 parameter lives during most of the function's activation (i.e. between the
11451 end of the prologue and the start of the epilogue). We'll do that as best
11452 as we can. Note however that if the given formal parameter is modified
11453 sometime during the execution of the function, then a stack backtrace (at
11454 debug-time) will show the function as having been called with the *new*
11455 value rather than the value which was originally passed in. This happens
11456 rarely enough that it is not a major problem, but it *is* a problem, and
11457 I'd like to fix it.
11459 A future version of dwarf2out.c may generate two additional attributes for
11460 any given DW_TAG_formal_parameter DIE which will describe the "passed
11461 type" and the "passed location" for the given formal parameter in addition
11462 to the attributes we now generate to indicate the "declared type" and the
11463 "active location" for each parameter. This additional set of attributes
11464 could be used by debuggers for stack backtraces. Separately, note that
11465 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11466 This happens (for example) for inlined-instances of inline function formal
11467 parameters which are never referenced. This really shouldn't be
11468 happening. All PARM_DECL nodes should get valid non-NULL
11469 DECL_INCOMING_RTL values. FIXME. */
11471 /* Use DECL_RTL as the "location" unless we find something better. */
11472 rtl
= DECL_RTL_IF_SET (decl
);
11474 /* When generating abstract instances, ignore everything except
11475 constants, symbols living in memory, and symbols living in
11476 fixed registers. */
11477 if (! reload_completed
)
11480 && (CONSTANT_P (rtl
)
11482 && CONSTANT_P (XEXP (rtl
, 0)))
11484 && TREE_CODE (decl
) == VAR_DECL
11485 && TREE_STATIC (decl
))))
11487 rtl
= targetm
.delegitimize_address (rtl
);
11492 else if (TREE_CODE (decl
) == PARM_DECL
)
11494 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
11496 tree declared_type
= TREE_TYPE (decl
);
11497 tree passed_type
= DECL_ARG_TYPE (decl
);
11498 enum machine_mode dmode
= TYPE_MODE (declared_type
);
11499 enum machine_mode pmode
= TYPE_MODE (passed_type
);
11501 /* This decl represents a formal parameter which was optimized out.
11502 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11503 all cases where (rtl == NULL_RTX) just below. */
11504 if (dmode
== pmode
)
11505 rtl
= DECL_INCOMING_RTL (decl
);
11506 else if (SCALAR_INT_MODE_P (dmode
)
11507 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
11508 && DECL_INCOMING_RTL (decl
))
11510 rtx inc
= DECL_INCOMING_RTL (decl
);
11513 else if (MEM_P (inc
))
11515 if (BYTES_BIG_ENDIAN
)
11516 rtl
= adjust_address_nv (inc
, dmode
,
11517 GET_MODE_SIZE (pmode
)
11518 - GET_MODE_SIZE (dmode
));
11525 /* If the parm was passed in registers, but lives on the stack, then
11526 make a big endian correction if the mode of the type of the
11527 parameter is not the same as the mode of the rtl. */
11528 /* ??? This is the same series of checks that are made in dbxout.c before
11529 we reach the big endian correction code there. It isn't clear if all
11530 of these checks are necessary here, but keeping them all is the safe
11532 else if (MEM_P (rtl
)
11533 && XEXP (rtl
, 0) != const0_rtx
11534 && ! CONSTANT_P (XEXP (rtl
, 0))
11535 /* Not passed in memory. */
11536 && !MEM_P (DECL_INCOMING_RTL (decl
))
11537 /* Not passed by invisible reference. */
11538 && (!REG_P (XEXP (rtl
, 0))
11539 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
11540 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
11541 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11542 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
11545 /* Big endian correction check. */
11546 && BYTES_BIG_ENDIAN
11547 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
11548 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
11551 int offset
= (UNITS_PER_WORD
11552 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
11554 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11555 plus_constant (XEXP (rtl
, 0), offset
));
11558 else if (TREE_CODE (decl
) == VAR_DECL
11561 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
11562 && BYTES_BIG_ENDIAN
)
11564 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
11565 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
11567 /* If a variable is declared "register" yet is smaller than
11568 a register, then if we store the variable to memory, it
11569 looks like we're storing a register-sized value, when in
11570 fact we are not. We need to adjust the offset of the
11571 storage location to reflect the actual value's bytes,
11572 else gdb will not be able to display it. */
11574 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11575 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
11578 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11579 and will have been substituted directly into all expressions that use it.
11580 C does not have such a concept, but C++ and other languages do. */
11581 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
11582 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
11585 rtl
= targetm
.delegitimize_address (rtl
);
11587 /* If we don't look past the constant pool, we risk emitting a
11588 reference to a constant pool entry that isn't referenced from
11589 code, and thus is not emitted. */
11591 rtl
= avoid_constant_pool_reference (rtl
);
11596 /* We need to figure out what section we should use as the base for the
11597 address ranges where a given location is valid.
11598 1. If this particular DECL has a section associated with it, use that.
11599 2. If this function has a section associated with it, use that.
11600 3. Otherwise, use the text section.
11601 XXX: If you split a variable across multiple sections, we won't notice. */
11603 static const char *
11604 secname_for_decl (const_tree decl
)
11606 const char *secname
;
11608 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
11610 tree sectree
= DECL_SECTION_NAME (decl
);
11611 secname
= TREE_STRING_POINTER (sectree
);
11613 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
11615 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
11616 secname
= TREE_STRING_POINTER (sectree
);
11618 else if (cfun
&& in_cold_section_p
)
11619 secname
= crtl
->subsections
.cold_section_label
;
11621 secname
= text_section_label
;
11626 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
11627 returned. If so, the decl for the COMMON block is returned, and the
11628 value is the offset into the common block for the symbol. */
11631 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
11633 tree val_expr
, cvar
;
11634 enum machine_mode mode
;
11635 HOST_WIDE_INT bitsize
, bitpos
;
11637 int volatilep
= 0, unsignedp
= 0;
11639 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11640 it does not have a value (the offset into the common area), or if it
11641 is thread local (as opposed to global) then it isn't common, and shouldn't
11642 be handled as such. */
11643 if (TREE_CODE (decl
) != VAR_DECL
11644 || !TREE_PUBLIC (decl
)
11645 || !TREE_STATIC (decl
)
11646 || !DECL_HAS_VALUE_EXPR_P (decl
)
11650 val_expr
= DECL_VALUE_EXPR (decl
);
11651 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
11654 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
11655 &mode
, &unsignedp
, &volatilep
, true);
11657 if (cvar
== NULL_TREE
11658 || TREE_CODE (cvar
) != VAR_DECL
11659 || DECL_ARTIFICIAL (cvar
)
11660 || !TREE_PUBLIC (cvar
))
11664 if (offset
!= NULL
)
11666 if (!host_integerp (offset
, 0))
11668 *value
= tree_low_cst (offset
, 0);
11671 *value
+= bitpos
/ BITS_PER_UNIT
;
11676 /* Dereference a location expression LOC if DECL is passed by invisible
11679 static dw_loc_descr_ref
11680 loc_by_reference (dw_loc_descr_ref loc
, tree decl
)
11682 HOST_WIDE_INT size
;
11683 enum dwarf_location_atom op
;
11688 if ((TREE_CODE (decl
) != PARM_DECL
&& TREE_CODE (decl
) != RESULT_DECL
)
11689 || !DECL_BY_REFERENCE (decl
))
11692 size
= int_size_in_bytes (TREE_TYPE (decl
));
11693 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
11695 else if (size
== DWARF2_ADDR_SIZE
)
11698 op
= DW_OP_deref_size
;
11699 add_loc_descr (&loc
, new_loc_descr (op
, size
, 0));
11703 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11704 data attribute for a variable or a parameter. We generate the
11705 DW_AT_const_value attribute only in those cases where the given variable
11706 or parameter does not have a true "location" either in memory or in a
11707 register. This can happen (for example) when a constant is passed as an
11708 actual argument in a call to an inline function. (It's possible that
11709 these things can crop up in other ways also.) Note that one type of
11710 constant value which can be passed into an inlined function is a constant
11711 pointer. This can happen for example if an actual argument in an inlined
11712 function call evaluates to a compile-time constant address. */
11715 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
11716 enum dwarf_attribute attr
)
11719 dw_loc_descr_ref descr
;
11720 var_loc_list
*loc_list
;
11721 struct var_loc_node
*node
;
11722 if (TREE_CODE (decl
) == ERROR_MARK
)
11725 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
11726 || TREE_CODE (decl
) == RESULT_DECL
);
11728 /* See if we possibly have multiple locations for this variable. */
11729 loc_list
= lookup_decl_loc (decl
);
11731 /* If it truly has multiple locations, the first and last node will
11733 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
11735 const char *endname
, *secname
;
11736 dw_loc_list_ref list
;
11738 enum var_init_status initialized
;
11740 /* Now that we know what section we are using for a base,
11741 actually construct the list of locations.
11742 The first location information is what is passed to the
11743 function that creates the location list, and the remaining
11744 locations just get added on to that list.
11745 Note that we only know the start address for a location
11746 (IE location changes), so to build the range, we use
11747 the range [current location start, next location start].
11748 This means we have to special case the last node, and generate
11749 a range of [last location start, end of function label]. */
11751 node
= loc_list
->first
;
11752 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11753 secname
= secname_for_decl (decl
);
11755 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
))
11756 initialized
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11758 initialized
= VAR_INIT_STATUS_INITIALIZED
;
11760 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
), decl
);
11761 list
= new_loc_list (descr
, node
->label
, node
->next
->label
, secname
, 1);
11764 for (; node
->next
; node
= node
->next
)
11765 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11767 /* The variable has a location between NODE->LABEL and
11768 NODE->NEXT->LABEL. */
11769 enum var_init_status initialized
=
11770 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11771 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11772 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
11774 add_loc_descr_to_loc_list (&list
, descr
,
11775 node
->label
, node
->next
->label
, secname
);
11778 /* If the variable has a location at the last label
11779 it keeps its location until the end of function. */
11780 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11782 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11783 enum var_init_status initialized
=
11784 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11786 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11787 if (!current_function_decl
)
11788 endname
= text_end_label
;
11791 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11792 current_function_funcdef_no
);
11793 endname
= ggc_strdup (label_id
);
11795 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
11797 add_loc_descr_to_loc_list (&list
, descr
,
11798 node
->label
, endname
, secname
);
11801 /* Finally, add the location list to the DIE, and we are done. */
11802 add_AT_loc_list (die
, attr
, list
);
11806 /* Try to get some constant RTL for this decl, and use that as the value of
11809 rtl
= rtl_for_decl_location (decl
);
11810 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
11812 add_const_value_attribute (die
, rtl
);
11816 /* If we have tried to generate the location otherwise, and it
11817 didn't work out (we wouldn't be here if we did), and we have a one entry
11818 location list, try generating a location from that. */
11819 if (loc_list
&& loc_list
->first
)
11821 enum var_init_status status
;
11822 node
= loc_list
->first
;
11823 status
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11824 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
), status
);
11827 descr
= loc_by_reference (descr
, decl
);
11828 add_AT_location_description (die
, attr
, descr
);
11833 /* We couldn't get any rtl, so try directly generating the location
11834 description from the tree. */
11835 descr
= loc_descriptor_from_tree (decl
);
11838 descr
= loc_by_reference (descr
, decl
);
11839 add_AT_location_description (die
, attr
, descr
);
11842 /* None of that worked, so it must not really have a location;
11843 try adding a constant value attribute from the DECL_INITIAL. */
11844 tree_add_const_value_attribute (die
, decl
);
11847 /* Helper function for tree_add_const_value_attribute. Natively encode
11848 initializer INIT into an array. Return true if successful. */
11851 native_encode_initializer (tree init
, unsigned char *array
, int size
)
11855 if (init
== NULL_TREE
)
11859 switch (TREE_CODE (init
))
11862 type
= TREE_TYPE (init
);
11863 if (TREE_CODE (type
) == ARRAY_TYPE
)
11865 tree enttype
= TREE_TYPE (type
);
11866 enum machine_mode mode
= TYPE_MODE (enttype
);
11868 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
11870 if (int_size_in_bytes (type
) != size
)
11872 if (size
> TREE_STRING_LENGTH (init
))
11874 memcpy (array
, TREE_STRING_POINTER (init
),
11875 TREE_STRING_LENGTH (init
));
11876 memset (array
+ TREE_STRING_LENGTH (init
),
11877 '\0', size
- TREE_STRING_LENGTH (init
));
11880 memcpy (array
, TREE_STRING_POINTER (init
), size
);
11885 type
= TREE_TYPE (init
);
11886 if (int_size_in_bytes (type
) != size
)
11888 if (TREE_CODE (type
) == ARRAY_TYPE
)
11890 HOST_WIDE_INT min_index
;
11891 unsigned HOST_WIDE_INT cnt
;
11892 int curpos
= 0, fieldsize
;
11893 constructor_elt
*ce
;
11895 if (TYPE_DOMAIN (type
) == NULL_TREE
11896 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
11899 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
11900 if (fieldsize
<= 0)
11903 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
11904 memset (array
, '\0', size
);
11906 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
11909 tree val
= ce
->value
;
11910 tree index
= ce
->index
;
11912 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
11913 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
11916 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
11921 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
11924 curpos
= pos
+ fieldsize
;
11925 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
11927 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
11928 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
11932 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
11933 curpos
+= fieldsize
;
11936 gcc_assert (curpos
<= size
);
11940 else if (TREE_CODE (type
) == RECORD_TYPE
11941 || TREE_CODE (type
) == UNION_TYPE
)
11943 tree field
= NULL_TREE
;
11944 unsigned HOST_WIDE_INT cnt
;
11945 constructor_elt
*ce
;
11947 if (int_size_in_bytes (type
) != size
)
11950 if (TREE_CODE (type
) == RECORD_TYPE
)
11951 field
= TYPE_FIELDS (type
);
11954 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
11955 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
11957 tree val
= ce
->value
;
11958 int pos
, fieldsize
;
11960 if (ce
->index
!= 0)
11966 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
11969 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
11970 && TYPE_DOMAIN (TREE_TYPE (field
))
11971 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
11973 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
11974 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
11976 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
11977 pos
= int_byte_position (field
);
11978 gcc_assert (pos
+ fieldsize
<= size
);
11980 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
11986 case VIEW_CONVERT_EXPR
:
11987 case NON_LVALUE_EXPR
:
11988 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
11990 return native_encode_expr (init
, array
, size
) == size
;
11994 /* If we don't have a copy of this variable in memory for some reason (such
11995 as a C++ member constant that doesn't have an out-of-line definition),
11996 we should tell the debugger about the constant value. */
11999 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
12002 tree type
= TREE_TYPE (decl
);
12005 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
12008 init
= DECL_INITIAL (decl
);
12009 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
12014 rtl
= rtl_for_decl_init (init
, type
);
12016 add_const_value_attribute (var_die
, rtl
);
12017 /* If the host and target are sane, try harder. */
12018 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
12019 && initializer_constant_valid_p (init
, type
))
12021 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
12022 if (size
> 0 && (int) size
== size
)
12024 unsigned char *array
= GGC_CNEWVEC (unsigned char, size
);
12026 if (native_encode_initializer (init
, array
, size
))
12027 add_AT_vec (var_die
, DW_AT_const_value
, size
, 1, array
);
12032 /* Convert the CFI instructions for the current function into a
12033 location list. This is used for DW_AT_frame_base when we targeting
12034 a dwarf2 consumer that does not support the dwarf3
12035 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12038 static dw_loc_list_ref
12039 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
12042 dw_loc_list_ref list
, *list_tail
;
12044 dw_cfa_location last_cfa
, next_cfa
;
12045 const char *start_label
, *last_label
, *section
;
12047 fde
= current_fde ();
12048 gcc_assert (fde
!= NULL
);
12050 section
= secname_for_decl (current_function_decl
);
12054 next_cfa
.reg
= INVALID_REGNUM
;
12055 next_cfa
.offset
= 0;
12056 next_cfa
.indirect
= 0;
12057 next_cfa
.base_offset
= 0;
12059 start_label
= fde
->dw_fde_begin
;
12061 /* ??? Bald assumption that the CIE opcode list does not contain
12062 advance opcodes. */
12063 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
12064 lookup_cfa_1 (cfi
, &next_cfa
);
12066 last_cfa
= next_cfa
;
12067 last_label
= start_label
;
12069 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
12070 switch (cfi
->dw_cfi_opc
)
12072 case DW_CFA_set_loc
:
12073 case DW_CFA_advance_loc1
:
12074 case DW_CFA_advance_loc2
:
12075 case DW_CFA_advance_loc4
:
12076 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12078 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12079 start_label
, last_label
, section
,
12082 list_tail
= &(*list_tail
)->dw_loc_next
;
12083 last_cfa
= next_cfa
;
12084 start_label
= last_label
;
12086 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
12089 case DW_CFA_advance_loc
:
12090 /* The encoding is complex enough that we should never emit this. */
12091 case DW_CFA_remember_state
:
12092 case DW_CFA_restore_state
:
12093 /* We don't handle these two in this function. It would be possible
12094 if it were to be required. */
12095 gcc_unreachable ();
12098 lookup_cfa_1 (cfi
, &next_cfa
);
12102 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12104 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12105 start_label
, last_label
, section
,
12107 list_tail
= &(*list_tail
)->dw_loc_next
;
12108 start_label
= last_label
;
12110 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
12111 start_label
, fde
->dw_fde_end
, section
,
12117 /* Compute a displacement from the "steady-state frame pointer" to the
12118 frame base (often the same as the CFA), and store it in
12119 frame_pointer_fb_offset. OFFSET is added to the displacement
12120 before the latter is negated. */
12123 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
12127 #ifdef FRAME_POINTER_CFA_OFFSET
12128 reg
= frame_pointer_rtx
;
12129 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
12131 reg
= arg_pointer_rtx
;
12132 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
12135 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
12136 if (GET_CODE (elim
) == PLUS
)
12138 offset
+= INTVAL (XEXP (elim
, 1));
12139 elim
= XEXP (elim
, 0);
12142 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12143 && (elim
== hard_frame_pointer_rtx
12144 || elim
== stack_pointer_rtx
))
12145 || elim
== (frame_pointer_needed
12146 ? hard_frame_pointer_rtx
12147 : stack_pointer_rtx
));
12149 frame_pointer_fb_offset
= -offset
;
12152 /* Generate a DW_AT_name attribute given some string value to be included as
12153 the value of the attribute. */
12156 add_name_attribute (dw_die_ref die
, const char *name_string
)
12158 if (name_string
!= NULL
&& *name_string
!= 0)
12160 if (demangle_name_func
)
12161 name_string
= (*demangle_name_func
) (name_string
);
12163 add_AT_string (die
, DW_AT_name
, name_string
);
12167 /* Generate a DW_AT_comp_dir attribute for DIE. */
12170 add_comp_dir_attribute (dw_die_ref die
)
12172 const char *wd
= get_src_pwd ();
12174 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
12177 /* Given a tree node describing an array bound (either lower or upper) output
12178 a representation for that bound. */
12181 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
12183 switch (TREE_CODE (bound
))
12188 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12190 if (! host_integerp (bound
, 0)
12191 || (bound_attr
== DW_AT_lower_bound
12192 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
12193 || (is_fortran () && integer_onep (bound
)))))
12194 /* Use the default. */
12197 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
12201 case VIEW_CONVERT_EXPR
:
12202 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
12212 dw_die_ref decl_die
= lookup_decl_die (bound
);
12213 dw_loc_descr_ref loc
;
12215 /* ??? Can this happen, or should the variable have been bound
12216 first? Probably it can, since I imagine that we try to create
12217 the types of parameters in the order in which they exist in
12218 the list, and won't have created a forward reference to a
12219 later parameter. */
12220 if (decl_die
!= NULL
)
12221 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12224 loc
= loc_descriptor_from_tree_1 (bound
, 0);
12225 add_AT_location_description (subrange_die
, bound_attr
, loc
);
12232 /* Otherwise try to create a stack operation procedure to
12233 evaluate the value of the array bound. */
12235 dw_die_ref ctx
, decl_die
;
12236 dw_loc_descr_ref loc
;
12238 loc
= loc_descriptor_from_tree (bound
);
12242 if (current_function_decl
== 0)
12243 ctx
= comp_unit_die
;
12245 ctx
= lookup_decl_die (current_function_decl
);
12247 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
12248 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12249 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
12250 add_AT_loc (decl_die
, DW_AT_location
, loc
);
12252 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12258 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12259 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12260 Note that the block of subscript information for an array type also
12261 includes information about the element type of the given array type. */
12264 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
12266 unsigned dimension_number
;
12268 dw_die_ref subrange_die
;
12270 for (dimension_number
= 0;
12271 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
12272 type
= TREE_TYPE (type
), dimension_number
++)
12274 tree domain
= TYPE_DOMAIN (type
);
12276 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
12279 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12280 and (in GNU C only) variable bounds. Handle all three forms
12282 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
12285 /* We have an array type with specified bounds. */
12286 lower
= TYPE_MIN_VALUE (domain
);
12287 upper
= TYPE_MAX_VALUE (domain
);
12289 /* Define the index type. */
12290 if (TREE_TYPE (domain
))
12292 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12293 TREE_TYPE field. We can't emit debug info for this
12294 because it is an unnamed integral type. */
12295 if (TREE_CODE (domain
) == INTEGER_TYPE
12296 && TYPE_NAME (domain
) == NULL_TREE
12297 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
12298 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
12301 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
12305 /* ??? If upper is NULL, the array has unspecified length,
12306 but it does have a lower bound. This happens with Fortran
12308 Since the debugger is definitely going to need to know N
12309 to produce useful results, go ahead and output the lower
12310 bound solo, and hope the debugger can cope. */
12312 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
12314 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
12317 /* Otherwise we have an array type with an unspecified length. The
12318 DWARF-2 spec does not say how to handle this; let's just leave out the
12324 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
12328 switch (TREE_CODE (tree_node
))
12333 case ENUMERAL_TYPE
:
12336 case QUAL_UNION_TYPE
:
12337 size
= int_size_in_bytes (tree_node
);
12340 /* For a data member of a struct or union, the DW_AT_byte_size is
12341 generally given as the number of bytes normally allocated for an
12342 object of the *declared* type of the member itself. This is true
12343 even for bit-fields. */
12344 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
12347 gcc_unreachable ();
12350 /* Note that `size' might be -1 when we get to this point. If it is, that
12351 indicates that the byte size of the entity in question is variable. We
12352 have no good way of expressing this fact in Dwarf at the present time,
12353 so just let the -1 pass on through. */
12354 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
12357 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12358 which specifies the distance in bits from the highest order bit of the
12359 "containing object" for the bit-field to the highest order bit of the
12362 For any given bit-field, the "containing object" is a hypothetical object
12363 (of some integral or enum type) within which the given bit-field lives. The
12364 type of this hypothetical "containing object" is always the same as the
12365 declared type of the individual bit-field itself. The determination of the
12366 exact location of the "containing object" for a bit-field is rather
12367 complicated. It's handled by the `field_byte_offset' function (above).
12369 Note that it is the size (in bytes) of the hypothetical "containing object"
12370 which will be given in the DW_AT_byte_size attribute for this bit-field.
12371 (See `byte_size_attribute' above). */
12374 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
12376 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
12377 tree type
= DECL_BIT_FIELD_TYPE (decl
);
12378 HOST_WIDE_INT bitpos_int
;
12379 HOST_WIDE_INT highest_order_object_bit_offset
;
12380 HOST_WIDE_INT highest_order_field_bit_offset
;
12381 HOST_WIDE_INT
unsigned bit_offset
;
12383 /* Must be a field and a bit field. */
12384 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
12386 /* We can't yet handle bit-fields whose offsets are variable, so if we
12387 encounter such things, just return without generating any attribute
12388 whatsoever. Likewise for variable or too large size. */
12389 if (! host_integerp (bit_position (decl
), 0)
12390 || ! host_integerp (DECL_SIZE (decl
), 1))
12393 bitpos_int
= int_bit_position (decl
);
12395 /* Note that the bit offset is always the distance (in bits) from the
12396 highest-order bit of the "containing object" to the highest-order bit of
12397 the bit-field itself. Since the "high-order end" of any object or field
12398 is different on big-endian and little-endian machines, the computation
12399 below must take account of these differences. */
12400 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
12401 highest_order_field_bit_offset
= bitpos_int
;
12403 if (! BYTES_BIG_ENDIAN
)
12405 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
12406 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
12410 = (! BYTES_BIG_ENDIAN
12411 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
12412 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
12414 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
12417 /* For a FIELD_DECL node which represents a bit field, output an attribute
12418 which specifies the length in bits of the given field. */
12421 add_bit_size_attribute (dw_die_ref die
, tree decl
)
12423 /* Must be a field and a bit field. */
12424 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
12425 && DECL_BIT_FIELD_TYPE (decl
));
12427 if (host_integerp (DECL_SIZE (decl
), 1))
12428 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
12431 /* If the compiled language is ANSI C, then add a 'prototyped'
12432 attribute, if arg types are given for the parameters of a function. */
12435 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
12437 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
12438 && TYPE_ARG_TYPES (func_type
) != NULL
)
12439 add_AT_flag (die
, DW_AT_prototyped
, 1);
12442 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12443 by looking in either the type declaration or object declaration
12447 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
12449 dw_die_ref origin_die
= NULL
;
12451 if (TREE_CODE (origin
) != FUNCTION_DECL
)
12453 /* We may have gotten separated from the block for the inlined
12454 function, if we're in an exception handler or some such; make
12455 sure that the abstract function has been written out.
12457 Doing this for nested functions is wrong, however; functions are
12458 distinct units, and our context might not even be inline. */
12462 fn
= TYPE_STUB_DECL (fn
);
12464 fn
= decl_function_context (fn
);
12466 dwarf2out_abstract_function (fn
);
12469 if (DECL_P (origin
))
12470 origin_die
= lookup_decl_die (origin
);
12471 else if (TYPE_P (origin
))
12472 origin_die
= lookup_type_die (origin
);
12474 /* XXX: Functions that are never lowered don't always have correct block
12475 trees (in the case of java, they simply have no block tree, in some other
12476 languages). For these functions, there is nothing we can really do to
12477 output correct debug info for inlined functions in all cases. Rather
12478 than die, we'll just produce deficient debug info now, in that we will
12479 have variables without a proper abstract origin. In the future, when all
12480 functions are lowered, we should re-add a gcc_assert (origin_die)
12484 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
12487 /* We do not currently support the pure_virtual attribute. */
12490 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
12492 if (DECL_VINDEX (func_decl
))
12494 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12496 if (host_integerp (DECL_VINDEX (func_decl
), 0))
12497 add_AT_loc (die
, DW_AT_vtable_elem_location
,
12498 new_loc_descr (DW_OP_constu
,
12499 tree_low_cst (DECL_VINDEX (func_decl
), 0),
12502 /* GNU extension: Record what type this method came from originally. */
12503 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12504 add_AT_die_ref (die
, DW_AT_containing_type
,
12505 lookup_type_die (DECL_CONTEXT (func_decl
)));
12509 /* Add source coordinate attributes for the given decl. */
12512 add_src_coords_attributes (dw_die_ref die
, tree decl
)
12514 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12516 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
12517 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
12520 /* Add a DW_AT_name attribute and source coordinate attribute for the
12521 given decl, but only if it actually has a name. */
12524 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
12528 decl_name
= DECL_NAME (decl
);
12529 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
12531 add_name_attribute (die
, dwarf2_name (decl
, 0));
12532 if (! DECL_ARTIFICIAL (decl
))
12533 add_src_coords_attributes (die
, decl
);
12535 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
12536 && TREE_PUBLIC (decl
)
12537 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
12538 && !DECL_ABSTRACT (decl
)
12539 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
12541 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
12542 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
12545 #ifdef VMS_DEBUGGING_INFO
12546 /* Get the function's name, as described by its RTL. This may be different
12547 from the DECL_NAME name used in the source file. */
12548 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
12550 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
12551 XEXP (DECL_RTL (decl
), 0));
12552 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
12557 /* Push a new declaration scope. */
12560 push_decl_scope (tree scope
)
12562 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
12565 /* Pop a declaration scope. */
12568 pop_decl_scope (void)
12570 VEC_pop (tree
, decl_scope_table
);
12573 /* Return the DIE for the scope that immediately contains this type.
12574 Non-named types get global scope. Named types nested in other
12575 types get their containing scope if it's open, or global scope
12576 otherwise. All other types (i.e. function-local named types) get
12577 the current active scope. */
12580 scope_die_for (tree t
, dw_die_ref context_die
)
12582 dw_die_ref scope_die
= NULL
;
12583 tree containing_scope
;
12586 /* Non-types always go in the current scope. */
12587 gcc_assert (TYPE_P (t
));
12589 containing_scope
= TYPE_CONTEXT (t
);
12591 /* Use the containing namespace if it was passed in (for a declaration). */
12592 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
12594 if (context_die
== lookup_decl_die (containing_scope
))
12597 containing_scope
= NULL_TREE
;
12600 /* Ignore function type "scopes" from the C frontend. They mean that
12601 a tagged type is local to a parmlist of a function declarator, but
12602 that isn't useful to DWARF. */
12603 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
12604 containing_scope
= NULL_TREE
;
12606 if (containing_scope
== NULL_TREE
)
12607 scope_die
= comp_unit_die
;
12608 else if (TYPE_P (containing_scope
))
12610 /* For types, we can just look up the appropriate DIE. But
12611 first we check to see if we're in the middle of emitting it
12612 so we know where the new DIE should go. */
12613 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
12614 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
12619 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
12620 || TREE_ASM_WRITTEN (containing_scope
));
12622 /* If none of the current dies are suitable, we get file scope. */
12623 scope_die
= comp_unit_die
;
12626 scope_die
= lookup_type_die (containing_scope
);
12629 scope_die
= context_die
;
12634 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12637 local_scope_p (dw_die_ref context_die
)
12639 for (; context_die
; context_die
= context_die
->die_parent
)
12640 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
12641 || context_die
->die_tag
== DW_TAG_subprogram
)
12647 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12648 whether or not to treat a DIE in this context as a declaration. */
12651 class_or_namespace_scope_p (dw_die_ref context_die
)
12653 return (context_die
12654 && (context_die
->die_tag
== DW_TAG_structure_type
12655 || context_die
->die_tag
== DW_TAG_class_type
12656 || context_die
->die_tag
== DW_TAG_interface_type
12657 || context_die
->die_tag
== DW_TAG_union_type
12658 || context_die
->die_tag
== DW_TAG_namespace
));
12661 /* Many forms of DIEs require a "type description" attribute. This
12662 routine locates the proper "type descriptor" die for the type given
12663 by 'type', and adds a DW_AT_type attribute below the given die. */
12666 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
12667 int decl_volatile
, dw_die_ref context_die
)
12669 enum tree_code code
= TREE_CODE (type
);
12670 dw_die_ref type_die
= NULL
;
12672 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12673 or fixed-point type, use the inner type. This is because we have no
12674 support for unnamed types in base_type_die. This can happen if this is
12675 an Ada subrange type. Correct solution is emit a subrange type die. */
12676 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
12677 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
12678 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
12680 if (code
== ERROR_MARK
12681 /* Handle a special case. For functions whose return type is void, we
12682 generate *no* type attribute. (Note that no object may have type
12683 `void', so this only applies to function return types). */
12684 || code
== VOID_TYPE
)
12687 type_die
= modified_type_die (type
,
12688 decl_const
|| TYPE_READONLY (type
),
12689 decl_volatile
|| TYPE_VOLATILE (type
),
12692 if (type_die
!= NULL
)
12693 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
12696 /* Given an object die, add the calling convention attribute for the
12697 function call type. */
12699 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
12701 enum dwarf_calling_convention value
= DW_CC_normal
;
12703 value
= targetm
.dwarf_calling_convention (TREE_TYPE (decl
));
12705 /* DWARF doesn't provide a way to identify a program's source-level
12706 entry point. DW_AT_calling_convention attributes are only meant
12707 to describe functions' calling conventions. However, lacking a
12708 better way to signal the Fortran main program, we use this for the
12709 time being, following existing custom. */
12711 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
12712 value
= DW_CC_program
;
12714 /* Only add the attribute if the backend requests it, and
12715 is not DW_CC_normal. */
12716 if (value
&& (value
!= DW_CC_normal
))
12717 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
12720 /* Given a tree pointer to a struct, class, union, or enum type node, return
12721 a pointer to the (string) tag name for the given type, or zero if the type
12722 was declared without a tag. */
12724 static const char *
12725 type_tag (const_tree type
)
12727 const char *name
= 0;
12729 if (TYPE_NAME (type
) != 0)
12733 /* Find the IDENTIFIER_NODE for the type name. */
12734 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
12735 t
= TYPE_NAME (type
);
12737 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12738 a TYPE_DECL node, regardless of whether or not a `typedef' was
12740 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12741 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
12743 /* We want to be extra verbose. Don't call dwarf_name if
12744 DECL_NAME isn't set. The default hook for decl_printable_name
12745 doesn't like that, and in this context it's correct to return
12746 0, instead of "<anonymous>" or the like. */
12747 if (DECL_NAME (TYPE_NAME (type
)))
12748 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
12751 /* Now get the name as a string, or invent one. */
12752 if (!name
&& t
!= 0)
12753 name
= IDENTIFIER_POINTER (t
);
12756 return (name
== 0 || *name
== '\0') ? 0 : name
;
12759 /* Return the type associated with a data member, make a special check
12760 for bit field types. */
12763 member_declared_type (const_tree member
)
12765 return (DECL_BIT_FIELD_TYPE (member
)
12766 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
12769 /* Get the decl's label, as described by its RTL. This may be different
12770 from the DECL_NAME name used in the source file. */
12773 static const char *
12774 decl_start_label (tree decl
)
12777 const char *fnname
;
12779 x
= DECL_RTL (decl
);
12780 gcc_assert (MEM_P (x
));
12783 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
12785 fnname
= XSTR (x
, 0);
12790 /* These routines generate the internal representation of the DIE's for
12791 the compilation unit. Debugging information is collected by walking
12792 the declaration trees passed in from dwarf2out_decl(). */
12795 gen_array_type_die (tree type
, dw_die_ref context_die
)
12797 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
12798 dw_die_ref array_die
;
12800 /* GNU compilers represent multidimensional array types as sequences of one
12801 dimensional array types whose element types are themselves array types.
12802 We sometimes squish that down to a single array_type DIE with multiple
12803 subscripts in the Dwarf debugging info. The draft Dwarf specification
12804 say that we are allowed to do this kind of compression in C, because
12805 there is no difference between an array of arrays and a multidimensional
12806 array. We don't do this for Ada to remain as close as possible to the
12807 actual representation, which is especially important against the language
12808 flexibilty wrt arrays of variable size. */
12810 bool collapse_nested_arrays
= !is_ada ();
12813 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
12814 DW_TAG_string_type doesn't have DW_AT_type attribute). */
12815 if (TYPE_STRING_FLAG (type
)
12816 && TREE_CODE (type
) == ARRAY_TYPE
12818 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
12820 HOST_WIDE_INT size
;
12822 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
12823 add_name_attribute (array_die
, type_tag (type
));
12824 equate_type_number_to_die (type
, array_die
);
12825 size
= int_size_in_bytes (type
);
12827 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
12828 else if (TYPE_DOMAIN (type
) != NULL_TREE
12829 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
12830 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
12832 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
12833 dw_loc_descr_ref loc
= loc_descriptor_from_tree (szdecl
);
12835 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
12836 if (loc
&& size
> 0)
12838 add_AT_loc (array_die
, DW_AT_string_length
, loc
);
12839 if (size
!= DWARF2_ADDR_SIZE
)
12840 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
12846 /* ??? The SGI dwarf reader fails for array of array of enum types
12847 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12848 array type comes before the outer array type. We thus call gen_type_die
12849 before we new_die and must prevent nested array types collapsing for this
12852 #ifdef MIPS_DEBUGGING_INFO
12853 gen_type_die (TREE_TYPE (type
), context_die
);
12854 collapse_nested_arrays
= false;
12857 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
12858 add_name_attribute (array_die
, type_tag (type
));
12859 equate_type_number_to_die (type
, array_die
);
12861 if (TREE_CODE (type
) == VECTOR_TYPE
)
12863 /* The frontend feeds us a representation for the vector as a struct
12864 containing an array. Pull out the array type. */
12865 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
12866 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
12869 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12871 && TREE_CODE (type
) == ARRAY_TYPE
12872 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
12873 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
12874 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
12877 /* We default the array ordering. SDB will probably do
12878 the right things even if DW_AT_ordering is not present. It's not even
12879 an issue until we start to get into multidimensional arrays anyway. If
12880 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12881 then we'll have to put the DW_AT_ordering attribute back in. (But if
12882 and when we find out that we need to put these in, we will only do so
12883 for multidimensional arrays. */
12884 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
12887 #ifdef MIPS_DEBUGGING_INFO
12888 /* The SGI compilers handle arrays of unknown bound by setting
12889 AT_declaration and not emitting any subrange DIEs. */
12890 if (! TYPE_DOMAIN (type
))
12891 add_AT_flag (array_die
, DW_AT_declaration
, 1);
12894 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
12896 /* Add representation of the type of the elements of this array type and
12897 emit the corresponding DIE if we haven't done it already. */
12898 element_type
= TREE_TYPE (type
);
12899 if (collapse_nested_arrays
)
12900 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
12902 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
12904 element_type
= TREE_TYPE (element_type
);
12907 #ifndef MIPS_DEBUGGING_INFO
12908 gen_type_die (element_type
, context_die
);
12911 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
12913 if (get_AT (array_die
, DW_AT_name
))
12914 add_pubtype (type
, array_die
);
12917 static dw_loc_descr_ref
12918 descr_info_loc (tree val
, tree base_decl
)
12920 HOST_WIDE_INT size
;
12921 dw_loc_descr_ref loc
, loc2
;
12922 enum dwarf_location_atom op
;
12924 if (val
== base_decl
)
12925 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
12927 switch (TREE_CODE (val
))
12930 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12932 return loc_descriptor_from_tree_1 (val
, 0);
12934 if (host_integerp (val
, 0))
12935 return int_loc_descriptor (tree_low_cst (val
, 0));
12938 size
= int_size_in_bytes (TREE_TYPE (val
));
12941 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12944 if (size
== DWARF2_ADDR_SIZE
)
12945 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
12947 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
12949 case POINTER_PLUS_EXPR
:
12951 if (host_integerp (TREE_OPERAND (val
, 1), 1)
12952 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
12955 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12958 add_loc_descr (&loc
,
12959 new_loc_descr (DW_OP_plus_uconst
,
12960 tree_low_cst (TREE_OPERAND (val
, 1),
12967 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12970 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
12973 add_loc_descr (&loc
, loc2
);
12974 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
12996 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
12997 tree val
, tree base_decl
)
12999 dw_loc_descr_ref loc
;
13001 if (host_integerp (val
, 0))
13003 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
13007 loc
= descr_info_loc (val
, base_decl
);
13011 add_AT_loc (die
, attr
, loc
);
13014 /* This routine generates DIE for array with hidden descriptor, details
13015 are filled into *info by a langhook. */
13018 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
13019 dw_die_ref context_die
)
13021 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
13022 dw_die_ref array_die
;
13025 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
13026 add_name_attribute (array_die
, type_tag (type
));
13027 equate_type_number_to_die (type
, array_die
);
13029 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13031 && info
->ndimensions
>= 2)
13032 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
13034 if (info
->data_location
)
13035 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
13037 if (info
->associated
)
13038 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
13040 if (info
->allocated
)
13041 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
13044 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
13046 dw_die_ref subrange_die
13047 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
13049 if (info
->dimen
[dim
].lower_bound
)
13051 /* If it is the default value, omit it. */
13052 if ((is_c_family () || is_java ())
13053 && integer_zerop (info
->dimen
[dim
].lower_bound
))
13055 else if (is_fortran ()
13056 && integer_onep (info
->dimen
[dim
].lower_bound
))
13059 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
13060 info
->dimen
[dim
].lower_bound
,
13063 if (info
->dimen
[dim
].upper_bound
)
13064 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
13065 info
->dimen
[dim
].upper_bound
,
13067 if (info
->dimen
[dim
].stride
)
13068 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
13069 info
->dimen
[dim
].stride
,
13073 gen_type_die (info
->element_type
, context_die
);
13074 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
13076 if (get_AT (array_die
, DW_AT_name
))
13077 add_pubtype (type
, array_die
);
13082 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
13084 tree origin
= decl_ultimate_origin (decl
);
13085 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
13087 if (origin
!= NULL
)
13088 add_abstract_origin_attribute (decl_die
, origin
);
13091 add_name_and_src_coords_attributes (decl_die
, decl
);
13092 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
13093 0, 0, context_die
);
13096 if (DECL_ABSTRACT (decl
))
13097 equate_decl_number_to_die (decl
, decl_die
);
13099 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
13103 /* Walk through the list of incomplete types again, trying once more to
13104 emit full debugging info for them. */
13107 retry_incomplete_types (void)
13111 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
13112 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
13115 /* Generate a DIE to represent an inlined instance of an enumeration type. */
13118 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
13120 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
13122 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
13123 be incomplete and such types are not marked. */
13124 add_abstract_origin_attribute (type_die
, type
);
13127 /* Determine what tag to use for a record type. */
13129 static enum dwarf_tag
13130 record_type_tag (tree type
)
13132 if (! lang_hooks
.types
.classify_record
)
13133 return DW_TAG_structure_type
;
13135 switch (lang_hooks
.types
.classify_record (type
))
13137 case RECORD_IS_STRUCT
:
13138 return DW_TAG_structure_type
;
13140 case RECORD_IS_CLASS
:
13141 return DW_TAG_class_type
;
13143 case RECORD_IS_INTERFACE
:
13144 return DW_TAG_interface_type
;
13147 gcc_unreachable ();
13151 /* Generate a DIE to represent an inlined instance of a structure type. */
13154 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
13156 dw_die_ref type_die
= new_die (record_type_tag (type
), context_die
, type
);
13158 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
13159 be incomplete and such types are not marked. */
13160 add_abstract_origin_attribute (type_die
, type
);
13163 /* Generate a DIE to represent an inlined instance of a union type. */
13166 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
13168 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
13170 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
13171 be incomplete and such types are not marked. */
13172 add_abstract_origin_attribute (type_die
, type
);
13175 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13176 include all of the information about the enumeration values also. Each
13177 enumerated type name/value is listed as a child of the enumerated type
13181 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
13183 dw_die_ref type_die
= lookup_type_die (type
);
13185 if (type_die
== NULL
)
13187 type_die
= new_die (DW_TAG_enumeration_type
,
13188 scope_die_for (type
, context_die
), type
);
13189 equate_type_number_to_die (type
, type_die
);
13190 add_name_attribute (type_die
, type_tag (type
));
13192 else if (! TYPE_SIZE (type
))
13195 remove_AT (type_die
, DW_AT_declaration
);
13197 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13198 given enum type is incomplete, do not generate the DW_AT_byte_size
13199 attribute or the DW_AT_element_list attribute. */
13200 if (TYPE_SIZE (type
))
13204 TREE_ASM_WRITTEN (type
) = 1;
13205 add_byte_size_attribute (type_die
, type
);
13206 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
13207 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
13209 /* If the first reference to this type was as the return type of an
13210 inline function, then it may not have a parent. Fix this now. */
13211 if (type_die
->die_parent
== NULL
)
13212 add_child_die (scope_die_for (type
, context_die
), type_die
);
13214 for (link
= TYPE_VALUES (type
);
13215 link
!= NULL
; link
= TREE_CHAIN (link
))
13217 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
13218 tree value
= TREE_VALUE (link
);
13220 add_name_attribute (enum_die
,
13221 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
13223 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
13224 /* DWARF2 does not provide a way of indicating whether or
13225 not enumeration constants are signed or unsigned. GDB
13226 always assumes the values are signed, so we output all
13227 values as if they were signed. That means that
13228 enumeration constants with very large unsigned values
13229 will appear to have negative values in the debugger. */
13230 add_AT_int (enum_die
, DW_AT_const_value
,
13231 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
13235 add_AT_flag (type_die
, DW_AT_declaration
, 1);
13237 if (get_AT (type_die
, DW_AT_name
))
13238 add_pubtype (type
, type_die
);
13243 /* Generate a DIE to represent either a real live formal parameter decl or to
13244 represent just the type of some formal parameter position in some function
13247 Note that this routine is a bit unusual because its argument may be a
13248 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13249 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13250 node. If it's the former then this function is being called to output a
13251 DIE to represent a formal parameter object (or some inlining thereof). If
13252 it's the latter, then this function is only being called to output a
13253 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13254 argument type of some subprogram type. */
13257 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
13259 dw_die_ref parm_die
13260 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
13263 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
13265 case tcc_declaration
:
13266 origin
= decl_ultimate_origin (node
);
13267 if (origin
!= NULL
)
13268 add_abstract_origin_attribute (parm_die
, origin
);
13271 tree type
= TREE_TYPE (node
);
13272 add_name_and_src_coords_attributes (parm_die
, node
);
13273 if (DECL_BY_REFERENCE (node
))
13274 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
13277 add_type_attribute (parm_die
, type
,
13278 TREE_READONLY (node
),
13279 TREE_THIS_VOLATILE (node
),
13281 if (DECL_ARTIFICIAL (node
))
13282 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13285 equate_decl_number_to_die (node
, parm_die
);
13286 if (! DECL_ABSTRACT (node
))
13287 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
13292 /* We were called with some kind of a ..._TYPE node. */
13293 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
13297 gcc_unreachable ();
13303 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13304 at the end of an (ANSI prototyped) formal parameters list. */
13307 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
13309 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
13312 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13313 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13314 parameters as specified in some function type specification (except for
13315 those which appear as part of a function *definition*). */
13318 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
13321 tree formal_type
= NULL
;
13322 tree first_parm_type
;
13325 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
13327 arg
= DECL_ARGUMENTS (function_or_method_type
);
13328 function_or_method_type
= TREE_TYPE (function_or_method_type
);
13333 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
13335 /* Make our first pass over the list of formal parameter types and output a
13336 DW_TAG_formal_parameter DIE for each one. */
13337 for (link
= first_parm_type
; link
; )
13339 dw_die_ref parm_die
;
13341 formal_type
= TREE_VALUE (link
);
13342 if (formal_type
== void_type_node
)
13345 /* Output a (nameless) DIE to represent the formal parameter itself. */
13346 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
13347 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
13348 && link
== first_parm_type
)
13349 || (arg
&& DECL_ARTIFICIAL (arg
)))
13350 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13352 link
= TREE_CHAIN (link
);
13354 arg
= TREE_CHAIN (arg
);
13357 /* If this function type has an ellipsis, add a
13358 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13359 if (formal_type
!= void_type_node
)
13360 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
13362 /* Make our second (and final) pass over the list of formal parameter types
13363 and output DIEs to represent those types (as necessary). */
13364 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
13365 link
&& TREE_VALUE (link
);
13366 link
= TREE_CHAIN (link
))
13367 gen_type_die (TREE_VALUE (link
), context_die
);
13370 /* We want to generate the DIE for TYPE so that we can generate the
13371 die for MEMBER, which has been defined; we will need to refer back
13372 to the member declaration nested within TYPE. If we're trying to
13373 generate minimal debug info for TYPE, processing TYPE won't do the
13374 trick; we need to attach the member declaration by hand. */
13377 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
13379 gen_type_die (type
, context_die
);
13381 /* If we're trying to avoid duplicate debug info, we may not have
13382 emitted the member decl for this function. Emit it now. */
13383 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
13384 && ! lookup_decl_die (member
))
13386 dw_die_ref type_die
;
13387 gcc_assert (!decl_ultimate_origin (member
));
13389 push_decl_scope (type
);
13390 type_die
= lookup_type_die (type
);
13391 if (TREE_CODE (member
) == FUNCTION_DECL
)
13392 gen_subprogram_die (member
, type_die
);
13393 else if (TREE_CODE (member
) == FIELD_DECL
)
13395 /* Ignore the nameless fields that are used to skip bits but handle
13396 C++ anonymous unions and structs. */
13397 if (DECL_NAME (member
) != NULL_TREE
13398 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
13399 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
13401 gen_type_die (member_declared_type (member
), type_die
);
13402 gen_field_die (member
, type_die
);
13406 gen_variable_die (member
, type_die
);
13412 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13413 may later generate inlined and/or out-of-line instances of. */
13416 dwarf2out_abstract_function (tree decl
)
13418 dw_die_ref old_die
;
13421 int was_abstract
= DECL_ABSTRACT (decl
);
13423 /* Make sure we have the actual abstract inline, not a clone. */
13424 decl
= DECL_ORIGIN (decl
);
13426 old_die
= lookup_decl_die (decl
);
13427 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
13428 /* We've already generated the abstract instance. */
13431 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13432 we don't get confused by DECL_ABSTRACT. */
13433 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13435 context
= decl_class_context (decl
);
13437 gen_type_die_for_member
13438 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
13441 /* Pretend we've just finished compiling this function. */
13442 save_fn
= current_function_decl
;
13443 current_function_decl
= decl
;
13444 push_cfun (DECL_STRUCT_FUNCTION (decl
));
13446 set_decl_abstract_flags (decl
, 1);
13447 dwarf2out_decl (decl
);
13448 if (! was_abstract
)
13449 set_decl_abstract_flags (decl
, 0);
13451 current_function_decl
= save_fn
;
13455 /* Helper function of premark_used_types() which gets called through
13456 htab_traverse_resize().
13458 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13459 marked as unused by prune_unused_types. */
13461 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
13466 type
= (tree
) *slot
;
13467 die
= lookup_type_die (type
);
13469 die
->die_perennial_p
= 1;
13473 /* Mark all members of used_types_hash as perennial. */
13475 premark_used_types (void)
13477 if (cfun
&& cfun
->used_types_hash
)
13478 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
13481 /* Generate a DIE to represent a declared function (either file-scope or
13485 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
13487 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13488 tree origin
= decl_ultimate_origin (decl
);
13489 dw_die_ref subr_die
;
13492 dw_die_ref old_die
= lookup_decl_die (decl
);
13493 int declaration
= (current_function_decl
!= decl
13494 || class_or_namespace_scope_p (context_die
));
13496 premark_used_types ();
13498 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13499 started to generate the abstract instance of an inline, decided to output
13500 its containing class, and proceeded to emit the declaration of the inline
13501 from the member list for the class. If so, DECLARATION takes priority;
13502 we'll get back to the abstract instance when done with the class. */
13504 /* The class-scope declaration DIE must be the primary DIE. */
13505 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
13508 gcc_assert (!old_die
);
13511 /* Now that the C++ front end lazily declares artificial member fns, we
13512 might need to retrofit the declaration into its class. */
13513 if (!declaration
&& !origin
&& !old_die
13514 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
13515 && !class_or_namespace_scope_p (context_die
)
13516 && debug_info_level
> DINFO_LEVEL_TERSE
)
13517 old_die
= force_decl_die (decl
);
13519 if (origin
!= NULL
)
13521 gcc_assert (!declaration
|| local_scope_p (context_die
));
13523 /* Fixup die_parent for the abstract instance of a nested
13524 inline function. */
13525 if (old_die
&& old_die
->die_parent
== NULL
)
13526 add_child_die (context_die
, old_die
);
13528 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13529 add_abstract_origin_attribute (subr_die
, origin
);
13533 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
13534 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
13536 if (!get_AT_flag (old_die
, DW_AT_declaration
)
13537 /* We can have a normal definition following an inline one in the
13538 case of redefinition of GNU C extern inlines.
13539 It seems reasonable to use AT_specification in this case. */
13540 && !get_AT (old_die
, DW_AT_inline
))
13542 /* Detect and ignore this case, where we are trying to output
13543 something we have already output. */
13547 /* If the definition comes from the same place as the declaration,
13548 maybe use the old DIE. We always want the DIE for this function
13549 that has the *_pc attributes to be under comp_unit_die so the
13550 debugger can find it. We also need to do this for abstract
13551 instances of inlines, since the spec requires the out-of-line copy
13552 to have the same parent. For local class methods, this doesn't
13553 apply; we just use the old DIE. */
13554 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
13555 && (DECL_ARTIFICIAL (decl
)
13556 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
13557 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
13558 == (unsigned) s
.line
))))
13560 subr_die
= old_die
;
13562 /* Clear out the declaration attribute and the formal parameters.
13563 Do not remove all children, because it is possible that this
13564 declaration die was forced using force_decl_die(). In such
13565 cases die that forced declaration die (e.g. TAG_imported_module)
13566 is one of the children that we do not want to remove. */
13567 remove_AT (subr_die
, DW_AT_declaration
);
13568 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
13572 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13573 add_AT_specification (subr_die
, old_die
);
13574 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
13575 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
13576 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
13577 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
13582 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13584 if (TREE_PUBLIC (decl
))
13585 add_AT_flag (subr_die
, DW_AT_external
, 1);
13587 add_name_and_src_coords_attributes (subr_die
, decl
);
13588 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13590 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
13591 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
13592 0, 0, context_die
);
13595 add_pure_or_virtual_attribute (subr_die
, decl
);
13596 if (DECL_ARTIFICIAL (decl
))
13597 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
13599 if (TREE_PROTECTED (decl
))
13600 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13601 else if (TREE_PRIVATE (decl
))
13602 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
13607 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
13609 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
13611 /* The first time we see a member function, it is in the context of
13612 the class to which it belongs. We make sure of this by emitting
13613 the class first. The next time is the definition, which is
13614 handled above. The two may come from the same source text.
13616 Note that force_decl_die() forces function declaration die. It is
13617 later reused to represent definition. */
13618 equate_decl_number_to_die (decl
, subr_die
);
13621 else if (DECL_ABSTRACT (decl
))
13623 if (DECL_DECLARED_INLINE_P (decl
))
13625 if (cgraph_function_possibly_inlined_p (decl
))
13626 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
13628 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
13632 if (cgraph_function_possibly_inlined_p (decl
))
13633 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
13635 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
13638 if (DECL_DECLARED_INLINE_P (decl
)
13639 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
13640 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
13642 equate_decl_number_to_die (decl
, subr_die
);
13644 else if (!DECL_EXTERNAL (decl
))
13646 HOST_WIDE_INT cfa_fb_offset
;
13648 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
13649 equate_decl_number_to_die (decl
, subr_die
);
13651 if (!flag_reorder_blocks_and_partition
)
13653 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
13654 current_function_funcdef_no
);
13655 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
13656 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13657 current_function_funcdef_no
);
13658 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
13660 add_pubname (decl
, subr_die
);
13661 add_arange (decl
, subr_die
);
13664 { /* Do nothing for now; maybe need to duplicate die, one for
13665 hot section and one for cold section, then use the hot/cold
13666 section begin/end labels to generate the aranges... */
13668 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13669 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13670 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13671 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13673 add_pubname (decl, subr_die);
13674 add_arange (decl, subr_die);
13675 add_arange (decl, subr_die);
13679 #ifdef MIPS_DEBUGGING_INFO
13680 /* Add a reference to the FDE for this routine. */
13681 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
13684 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
13686 /* We define the "frame base" as the function's CFA. This is more
13687 convenient for several reasons: (1) It's stable across the prologue
13688 and epilogue, which makes it better than just a frame pointer,
13689 (2) With dwarf3, there exists a one-byte encoding that allows us
13690 to reference the .debug_frame data by proxy, but failing that,
13691 (3) We can at least reuse the code inspection and interpretation
13692 code that determines the CFA position at various points in the
13694 /* ??? Use some command-line or configury switch to enable the use
13695 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13696 consumers that understand it; fall back to "pure" dwarf2 and
13697 convert the CFA data into a location list. */
13699 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
13700 if (list
->dw_loc_next
)
13701 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
13703 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
13706 /* Compute a displacement from the "steady-state frame pointer" to
13707 the CFA. The former is what all stack slots and argument slots
13708 will reference in the rtl; the later is what we've told the
13709 debugger about. We'll need to adjust all frame_base references
13710 by this displacement. */
13711 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
13713 if (cfun
->static_chain_decl
)
13714 add_AT_location_description (subr_die
, DW_AT_static_link
,
13715 loc_descriptor_from_tree (cfun
->static_chain_decl
));
13718 /* Now output descriptions of the arguments for this function. This gets
13719 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13720 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13721 `...' at the end of the formal parameter list. In order to find out if
13722 there was a trailing ellipsis or not, we must instead look at the type
13723 associated with the FUNCTION_DECL. This will be a node of type
13724 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13725 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13726 an ellipsis at the end. */
13728 /* In the case where we are describing a mere function declaration, all we
13729 need to do here (and all we *can* do here) is to describe the *types* of
13730 its formal parameters. */
13731 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13733 else if (declaration
)
13734 gen_formal_types_die (decl
, subr_die
);
13737 /* Generate DIEs to represent all known formal parameters. */
13738 tree arg_decls
= DECL_ARGUMENTS (decl
);
13741 /* When generating DIEs, generate the unspecified_parameters DIE
13742 instead if we come across the arg "__builtin_va_alist" */
13743 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
13744 if (TREE_CODE (parm
) == PARM_DECL
)
13746 if (DECL_NAME (parm
)
13747 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
13748 "__builtin_va_alist"))
13749 gen_unspecified_parameters_die (parm
, subr_die
);
13751 gen_decl_die (parm
, subr_die
);
13754 /* Decide whether we need an unspecified_parameters DIE at the end.
13755 There are 2 more cases to do this for: 1) the ansi ... declaration -
13756 this is detectable when the end of the arg list is not a
13757 void_type_node 2) an unprototyped function declaration (not a
13758 definition). This just means that we have no info about the
13759 parameters at all. */
13760 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
13761 if (fn_arg_types
!= NULL
)
13763 /* This is the prototyped case, check for.... */
13764 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
13765 gen_unspecified_parameters_die (decl
, subr_die
);
13767 else if (DECL_INITIAL (decl
) == NULL_TREE
)
13768 gen_unspecified_parameters_die (decl
, subr_die
);
13771 /* Output Dwarf info for all of the stuff within the body of the function
13772 (if it has one - it may be just a declaration). */
13773 outer_scope
= DECL_INITIAL (decl
);
13775 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13776 a function. This BLOCK actually represents the outermost binding contour
13777 for the function, i.e. the contour in which the function's formal
13778 parameters and labels get declared. Curiously, it appears that the front
13779 end doesn't actually put the PARM_DECL nodes for the current function onto
13780 the BLOCK_VARS list for this outer scope, but are strung off of the
13781 DECL_ARGUMENTS list for the function instead.
13783 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13784 the LABEL_DECL nodes for the function however, and we output DWARF info
13785 for those in decls_for_scope. Just within the `outer_scope' there will be
13786 a BLOCK node representing the function's outermost pair of curly braces,
13787 and any blocks used for the base and member initializers of a C++
13788 constructor function. */
13789 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
13791 /* Emit a DW_TAG_variable DIE for a named return value. */
13792 if (DECL_NAME (DECL_RESULT (decl
)))
13793 gen_decl_die (DECL_RESULT (decl
), subr_die
);
13795 current_function_has_inlines
= 0;
13796 decls_for_scope (outer_scope
, subr_die
, 0);
13798 #if 0 && defined (MIPS_DEBUGGING_INFO)
13799 if (current_function_has_inlines
)
13801 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
13802 if (! comp_unit_has_inlines
)
13804 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
13805 comp_unit_has_inlines
= 1;
13810 /* Add the calling convention attribute if requested. */
13811 add_calling_convention_attribute (subr_die
, decl
);
13815 /* Generate a DIE to represent a declared data object. */
13818 gen_variable_die (tree decl
, dw_die_ref context_die
)
13822 dw_die_ref var_die
;
13823 tree origin
= decl_ultimate_origin (decl
);
13824 dw_die_ref old_die
= lookup_decl_die (decl
);
13825 int declaration
= (DECL_EXTERNAL (decl
)
13826 /* If DECL is COMDAT and has not actually been
13827 emitted, we cannot take its address; there
13828 might end up being no definition anywhere in
13829 the program. For example, consider the C++
13833 struct S { static const int i = 7; };
13838 int f() { return S<int>::i; }
13840 Here, S<int>::i is not DECL_EXTERNAL, but no
13841 definition is required, so the compiler will
13842 not emit a definition. */
13843 || (TREE_CODE (decl
) == VAR_DECL
13844 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
13845 || class_or_namespace_scope_p (context_die
));
13847 com_decl
= fortran_common (decl
, &off
);
13849 /* Symbol in common gets emitted as a child of the common block, in the form
13850 of a data member. */
13854 dw_die_ref com_die
;
13855 dw_loc_descr_ref loc
;
13857 var_die
= lookup_decl_die (decl
);
13860 if (get_AT (var_die
, DW_AT_location
) == NULL
)
13862 loc
= loc_descriptor_from_tree (com_decl
);
13866 add_loc_descr (&loc
, new_loc_descr (DW_OP_plus_uconst
,
13868 add_AT_loc (var_die
, DW_AT_location
, loc
);
13869 remove_AT (var_die
, DW_AT_declaration
);
13874 field
= TREE_OPERAND (DECL_VALUE_EXPR (decl
), 0);
13875 com_die
= lookup_decl_die (com_decl
);
13876 loc
= loc_descriptor_from_tree (com_decl
);
13877 if (com_die
== NULL
)
13880 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
13882 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
13883 add_name_and_src_coords_attributes (com_die
, com_decl
);
13886 add_AT_loc (com_die
, DW_AT_location
, loc
);
13887 /* Avoid sharing the same loc descriptor between
13888 DW_TAG_common_block and DW_TAG_variable. */
13889 loc
= loc_descriptor_from_tree (com_decl
);
13891 else if (DECL_EXTERNAL (decl
))
13892 add_AT_flag (com_die
, DW_AT_declaration
, 1);
13893 add_pubname_string (cnam
, com_die
); /* ??? needed? */
13894 equate_decl_number_to_die (com_decl
, com_die
);
13896 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
13898 add_AT_loc (com_die
, DW_AT_location
, loc
);
13899 loc
= loc_descriptor_from_tree (com_decl
);
13900 remove_AT (com_die
, DW_AT_declaration
);
13902 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
13903 add_name_and_src_coords_attributes (var_die
, decl
);
13904 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
13905 TREE_THIS_VOLATILE (decl
), context_die
);
13906 add_AT_flag (var_die
, DW_AT_external
, 1);
13910 add_loc_descr (&loc
, new_loc_descr (DW_OP_plus_uconst
, off
, 0));
13911 add_AT_loc (var_die
, DW_AT_location
, loc
);
13913 else if (DECL_EXTERNAL (decl
))
13914 add_AT_flag (var_die
, DW_AT_declaration
, 1);
13915 equate_decl_number_to_die (decl
, var_die
);
13919 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
13921 if (origin
!= NULL
)
13922 add_abstract_origin_attribute (var_die
, origin
);
13924 /* Loop unrolling can create multiple blocks that refer to the same
13925 static variable, so we must test for the DW_AT_declaration flag.
13927 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13928 copy decls and set the DECL_ABSTRACT flag on them instead of
13931 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13933 ??? The declare_in_namespace support causes us to get two DIEs for one
13934 variable, both of which are declarations. We want to avoid considering
13935 one to be a specification, so we must test that this DIE is not a
13937 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
13938 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
13940 /* This is a definition of a C++ class level static. */
13941 add_AT_specification (var_die
, old_die
);
13942 if (DECL_NAME (decl
))
13944 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
13945 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
13947 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
13948 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
13950 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
13951 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
13956 tree type
= TREE_TYPE (decl
);
13958 add_name_and_src_coords_attributes (var_die
, decl
);
13959 if ((TREE_CODE (decl
) == PARM_DECL
13960 || TREE_CODE (decl
) == RESULT_DECL
)
13961 && DECL_BY_REFERENCE (decl
))
13962 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
13964 add_type_attribute (var_die
, type
, TREE_READONLY (decl
),
13965 TREE_THIS_VOLATILE (decl
), context_die
);
13967 if (TREE_PUBLIC (decl
))
13968 add_AT_flag (var_die
, DW_AT_external
, 1);
13970 if (DECL_ARTIFICIAL (decl
))
13971 add_AT_flag (var_die
, DW_AT_artificial
, 1);
13973 if (TREE_PROTECTED (decl
))
13974 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13975 else if (TREE_PRIVATE (decl
))
13976 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
13980 add_AT_flag (var_die
, DW_AT_declaration
, 1);
13982 if (DECL_ABSTRACT (decl
) || declaration
)
13983 equate_decl_number_to_die (decl
, var_die
);
13985 if (! declaration
&& ! DECL_ABSTRACT (decl
))
13987 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
13988 add_pubname (decl
, var_die
);
13991 tree_add_const_value_attribute (var_die
, decl
);
13994 /* Generate a DIE to represent a named constant. */
13997 gen_const_die (tree decl
, dw_die_ref context_die
)
13999 dw_die_ref const_die
;
14000 tree type
= TREE_TYPE (decl
);
14002 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
14003 add_name_and_src_coords_attributes (const_die
, decl
);
14004 add_type_attribute (const_die
, type
, 1, 0, context_die
);
14005 if (TREE_PUBLIC (decl
))
14006 add_AT_flag (const_die
, DW_AT_external
, 1);
14007 if (DECL_ARTIFICIAL (decl
))
14008 add_AT_flag (const_die
, DW_AT_artificial
, 1);
14009 tree_add_const_value_attribute (const_die
, decl
);
14012 /* Generate a DIE to represent a label identifier. */
14015 gen_label_die (tree decl
, dw_die_ref context_die
)
14017 tree origin
= decl_ultimate_origin (decl
);
14018 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
14020 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14022 if (origin
!= NULL
)
14023 add_abstract_origin_attribute (lbl_die
, origin
);
14025 add_name_and_src_coords_attributes (lbl_die
, decl
);
14027 if (DECL_ABSTRACT (decl
))
14028 equate_decl_number_to_die (decl
, lbl_die
);
14031 insn
= DECL_RTL_IF_SET (decl
);
14033 /* Deleted labels are programmer specified labels which have been
14034 eliminated because of various optimizations. We still emit them
14035 here so that it is possible to put breakpoints on them. */
14039 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
14041 /* When optimization is enabled (via -O) some parts of the compiler
14042 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14043 represent source-level labels which were explicitly declared by
14044 the user. This really shouldn't be happening though, so catch
14045 it if it ever does happen. */
14046 gcc_assert (!INSN_DELETED_P (insn
));
14048 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
14049 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
14054 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14055 attributes to the DIE for a block STMT, to describe where the inlined
14056 function was called from. This is similar to add_src_coords_attributes. */
14059 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
14061 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
14063 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
14064 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
14068 /* If STMT's abstract origin is a function declaration and STMT's
14069 first subblock's abstract origin is the function's outermost block,
14070 then we're looking at the main entry point. */
14072 is_inlined_entry_point (const_tree stmt
)
14076 if (!stmt
|| TREE_CODE (stmt
) != BLOCK
)
14079 decl
= block_ultimate_origin (stmt
);
14081 if (!decl
|| TREE_CODE (decl
) != FUNCTION_DECL
)
14084 block
= BLOCK_SUBBLOCKS (stmt
);
14088 if (TREE_CODE (block
) != BLOCK
)
14091 block
= block_ultimate_origin (block
);
14094 return block
== DECL_INITIAL (decl
);
14097 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14098 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14101 add_high_low_attributes (tree stmt
, dw_die_ref die
)
14103 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14105 if (BLOCK_FRAGMENT_CHAIN (stmt
))
14109 if (is_inlined_entry_point (stmt
))
14111 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14112 BLOCK_NUMBER (stmt
));
14113 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
14116 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
14118 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
14121 add_ranges (chain
);
14122 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
14129 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14130 BLOCK_NUMBER (stmt
));
14131 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
14132 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
14133 BLOCK_NUMBER (stmt
));
14134 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
14138 /* Generate a DIE for a lexical block. */
14141 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14143 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
14145 if (! BLOCK_ABSTRACT (stmt
))
14146 add_high_low_attributes (stmt
, stmt_die
);
14148 decls_for_scope (stmt
, stmt_die
, depth
);
14151 /* Generate a DIE for an inlined subprogram. */
14154 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
14156 tree decl
= block_ultimate_origin (stmt
);
14158 /* Emit info for the abstract instance first, if we haven't yet. We
14159 must emit this even if the block is abstract, otherwise when we
14160 emit the block below (or elsewhere), we may end up trying to emit
14161 a die whose origin die hasn't been emitted, and crashing. */
14162 dwarf2out_abstract_function (decl
);
14164 if (! BLOCK_ABSTRACT (stmt
))
14166 dw_die_ref subr_die
14167 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
14169 add_abstract_origin_attribute (subr_die
, decl
);
14170 add_high_low_attributes (stmt
, subr_die
);
14171 add_call_src_coords_attributes (stmt
, subr_die
);
14173 decls_for_scope (stmt
, subr_die
, depth
);
14174 current_function_has_inlines
= 1;
14177 /* We may get here if we're the outer block of function A that was
14178 inlined into function B that was inlined into function C. When
14179 generating debugging info for C, dwarf2out_abstract_function(B)
14180 would mark all inlined blocks as abstract, including this one.
14181 So, we wouldn't (and shouldn't) expect labels to be generated
14182 for this one. Instead, just emit debugging info for
14183 declarations within the block. This is particularly important
14184 in the case of initializers of arguments passed from B to us:
14185 if they're statement expressions containing declarations, we
14186 wouldn't generate dies for their abstract variables, and then,
14187 when generating dies for the real variables, we'd die (pun
14189 gen_lexical_block_die (stmt
, context_die
, depth
);
14192 /* Generate a DIE for a field in a record, or structure. */
14195 gen_field_die (tree decl
, dw_die_ref context_die
)
14197 dw_die_ref decl_die
;
14199 if (TREE_TYPE (decl
) == error_mark_node
)
14202 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
14203 add_name_and_src_coords_attributes (decl_die
, decl
);
14204 add_type_attribute (decl_die
, member_declared_type (decl
),
14205 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
14208 if (DECL_BIT_FIELD_TYPE (decl
))
14210 add_byte_size_attribute (decl_die
, decl
);
14211 add_bit_size_attribute (decl_die
, decl
);
14212 add_bit_offset_attribute (decl_die
, decl
);
14215 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
14216 add_data_member_location_attribute (decl_die
, decl
);
14218 if (DECL_ARTIFICIAL (decl
))
14219 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
14221 if (TREE_PROTECTED (decl
))
14222 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14223 else if (TREE_PRIVATE (decl
))
14224 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14226 /* Equate decl number to die, so that we can look up this decl later on. */
14227 equate_decl_number_to_die (decl
, decl_die
);
14231 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14232 Use modified_type_die instead.
14233 We keep this code here just in case these types of DIEs may be needed to
14234 represent certain things in other languages (e.g. Pascal) someday. */
14237 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
14240 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
14242 equate_type_number_to_die (type
, ptr_die
);
14243 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14244 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14247 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14248 Use modified_type_die instead.
14249 We keep this code here just in case these types of DIEs may be needed to
14250 represent certain things in other languages (e.g. Pascal) someday. */
14253 gen_reference_type_die (tree type
, dw_die_ref context_die
)
14256 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
14258 equate_type_number_to_die (type
, ref_die
);
14259 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
14260 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14264 /* Generate a DIE for a pointer to a member type. */
14267 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
14270 = new_die (DW_TAG_ptr_to_member_type
,
14271 scope_die_for (type
, context_die
), type
);
14273 equate_type_number_to_die (type
, ptr_die
);
14274 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
14275 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
14276 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14279 /* Generate the DIE for the compilation unit. */
14282 gen_compile_unit_die (const char *filename
)
14285 char producer
[250];
14286 const char *language_string
= lang_hooks
.name
;
14289 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
14293 add_name_attribute (die
, filename
);
14294 /* Don't add cwd for <built-in>. */
14295 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
14296 add_comp_dir_attribute (die
);
14299 sprintf (producer
, "%s %s", language_string
, version_string
);
14301 #ifdef MIPS_DEBUGGING_INFO
14302 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14303 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14304 not appear in the producer string, the debugger reaches the conclusion
14305 that the object file is stripped and has no debugging information.
14306 To get the MIPS/SGI debugger to believe that there is debugging
14307 information in the object file, we add a -g to the producer string. */
14308 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14309 strcat (producer
, " -g");
14312 add_AT_string (die
, DW_AT_producer
, producer
);
14314 if (strcmp (language_string
, "GNU C++") == 0)
14315 language
= DW_LANG_C_plus_plus
;
14316 else if (strcmp (language_string
, "GNU Ada") == 0)
14317 language
= DW_LANG_Ada95
;
14318 else if (strcmp (language_string
, "GNU F77") == 0)
14319 language
= DW_LANG_Fortran77
;
14320 else if (strcmp (language_string
, "GNU Fortran") == 0)
14321 language
= DW_LANG_Fortran95
;
14322 else if (strcmp (language_string
, "GNU Pascal") == 0)
14323 language
= DW_LANG_Pascal83
;
14324 else if (strcmp (language_string
, "GNU Java") == 0)
14325 language
= DW_LANG_Java
;
14326 else if (strcmp (language_string
, "GNU Objective-C") == 0)
14327 language
= DW_LANG_ObjC
;
14328 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
14329 language
= DW_LANG_ObjC_plus_plus
;
14331 language
= DW_LANG_C89
;
14333 add_AT_unsigned (die
, DW_AT_language
, language
);
14337 /* Generate the DIE for a base class. */
14340 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
14342 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
14344 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
14345 add_data_member_location_attribute (die
, binfo
);
14347 if (BINFO_VIRTUAL_P (binfo
))
14348 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
14350 if (access
== access_public_node
)
14351 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14352 else if (access
== access_protected_node
)
14353 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14356 /* Generate a DIE for a class member. */
14359 gen_member_die (tree type
, dw_die_ref context_die
)
14362 tree binfo
= TYPE_BINFO (type
);
14365 /* If this is not an incomplete type, output descriptions of each of its
14366 members. Note that as we output the DIEs necessary to represent the
14367 members of this record or union type, we will also be trying to output
14368 DIEs to represent the *types* of those members. However the `type'
14369 function (above) will specifically avoid generating type DIEs for member
14370 types *within* the list of member DIEs for this (containing) type except
14371 for those types (of members) which are explicitly marked as also being
14372 members of this (containing) type themselves. The g++ front- end can
14373 force any given type to be treated as a member of some other (containing)
14374 type by setting the TYPE_CONTEXT of the given (member) type to point to
14375 the TREE node representing the appropriate (containing) type. */
14377 /* First output info about the base classes. */
14380 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
14384 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
14385 gen_inheritance_die (base
,
14386 (accesses
? VEC_index (tree
, accesses
, i
)
14387 : access_public_node
), context_die
);
14390 /* Now output info about the data members and type members. */
14391 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
14393 /* If we thought we were generating minimal debug info for TYPE
14394 and then changed our minds, some of the member declarations
14395 may have already been defined. Don't define them again, but
14396 do put them in the right order. */
14398 child
= lookup_decl_die (member
);
14400 splice_child_die (context_die
, child
);
14402 gen_decl_die (member
, context_die
);
14405 /* Now output info about the function members (if any). */
14406 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
14408 /* Don't include clones in the member list. */
14409 if (DECL_ABSTRACT_ORIGIN (member
))
14412 child
= lookup_decl_die (member
);
14414 splice_child_die (context_die
, child
);
14416 gen_decl_die (member
, context_die
);
14420 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14421 is set, we pretend that the type was never defined, so we only get the
14422 member DIEs needed by later specification DIEs. */
14425 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
14426 enum debug_info_usage usage
)
14428 dw_die_ref type_die
= lookup_type_die (type
);
14429 dw_die_ref scope_die
= 0;
14431 int complete
= (TYPE_SIZE (type
)
14432 && (! TYPE_STUB_DECL (type
)
14433 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
14434 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
14435 complete
= complete
&& should_emit_struct_debug (type
, usage
);
14437 if (type_die
&& ! complete
)
14440 if (TYPE_CONTEXT (type
) != NULL_TREE
14441 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
14442 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
14445 scope_die
= scope_die_for (type
, context_die
);
14447 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
14448 /* First occurrence of type or toplevel definition of nested class. */
14450 dw_die_ref old_die
= type_die
;
14452 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
14453 ? record_type_tag (type
) : DW_TAG_union_type
,
14455 equate_type_number_to_die (type
, type_die
);
14457 add_AT_specification (type_die
, old_die
);
14459 add_name_attribute (type_die
, type_tag (type
));
14462 remove_AT (type_die
, DW_AT_declaration
);
14464 /* If this type has been completed, then give it a byte_size attribute and
14465 then give a list of members. */
14466 if (complete
&& !ns_decl
)
14468 /* Prevent infinite recursion in cases where the type of some member of
14469 this type is expressed in terms of this type itself. */
14470 TREE_ASM_WRITTEN (type
) = 1;
14471 add_byte_size_attribute (type_die
, type
);
14472 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
14473 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
14475 /* If the first reference to this type was as the return type of an
14476 inline function, then it may not have a parent. Fix this now. */
14477 if (type_die
->die_parent
== NULL
)
14478 add_child_die (scope_die
, type_die
);
14480 push_decl_scope (type
);
14481 gen_member_die (type
, type_die
);
14484 /* GNU extension: Record what type our vtable lives in. */
14485 if (TYPE_VFIELD (type
))
14487 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
14489 gen_type_die (vtype
, context_die
);
14490 add_AT_die_ref (type_die
, DW_AT_containing_type
,
14491 lookup_type_die (vtype
));
14496 add_AT_flag (type_die
, DW_AT_declaration
, 1);
14498 /* We don't need to do this for function-local types. */
14499 if (TYPE_STUB_DECL (type
)
14500 && ! decl_function_context (TYPE_STUB_DECL (type
)))
14501 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
14504 if (get_AT (type_die
, DW_AT_name
))
14505 add_pubtype (type
, type_die
);
14508 /* Generate a DIE for a subroutine _type_. */
14511 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
14513 tree return_type
= TREE_TYPE (type
);
14514 dw_die_ref subr_die
14515 = new_die (DW_TAG_subroutine_type
,
14516 scope_die_for (type
, context_die
), type
);
14518 equate_type_number_to_die (type
, subr_die
);
14519 add_prototyped_attribute (subr_die
, type
);
14520 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
14521 gen_formal_types_die (type
, subr_die
);
14523 if (get_AT (subr_die
, DW_AT_name
))
14524 add_pubtype (type
, subr_die
);
14527 /* Generate a DIE for a type definition. */
14530 gen_typedef_die (tree decl
, dw_die_ref context_die
)
14532 dw_die_ref type_die
;
14535 if (TREE_ASM_WRITTEN (decl
))
14538 TREE_ASM_WRITTEN (decl
) = 1;
14539 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
14540 origin
= decl_ultimate_origin (decl
);
14541 if (origin
!= NULL
)
14542 add_abstract_origin_attribute (type_die
, origin
);
14547 add_name_and_src_coords_attributes (type_die
, decl
);
14548 if (DECL_ORIGINAL_TYPE (decl
))
14550 type
= DECL_ORIGINAL_TYPE (decl
);
14552 gcc_assert (type
!= TREE_TYPE (decl
));
14553 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
14556 type
= TREE_TYPE (decl
);
14558 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
14559 TREE_THIS_VOLATILE (decl
), context_die
);
14562 if (DECL_ABSTRACT (decl
))
14563 equate_decl_number_to_die (decl
, type_die
);
14565 if (get_AT (type_die
, DW_AT_name
))
14566 add_pubtype (decl
, type_die
);
14569 /* Generate a type description DIE. */
14572 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
14573 enum debug_info_usage usage
)
14576 struct array_descr_info info
;
14578 if (type
== NULL_TREE
|| type
== error_mark_node
)
14581 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
14582 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
14584 if (TREE_ASM_WRITTEN (type
))
14587 /* Prevent broken recursion; we can't hand off to the same type. */
14588 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
14590 TREE_ASM_WRITTEN (type
) = 1;
14591 gen_decl_die (TYPE_NAME (type
), context_die
);
14595 /* If this is an array type with hidden descriptor, handle it first. */
14596 if (!TREE_ASM_WRITTEN (type
)
14597 && lang_hooks
.types
.get_array_descr_info
14598 && lang_hooks
.types
.get_array_descr_info (type
, &info
))
14600 gen_descr_array_type_die (type
, &info
, context_die
);
14601 TREE_ASM_WRITTEN (type
) = 1;
14605 /* We are going to output a DIE to represent the unqualified version
14606 of this type (i.e. without any const or volatile qualifiers) so
14607 get the main variant (i.e. the unqualified version) of this type
14608 now. (Vectors are special because the debugging info is in the
14609 cloned type itself). */
14610 if (TREE_CODE (type
) != VECTOR_TYPE
)
14611 type
= type_main_variant (type
);
14613 if (TREE_ASM_WRITTEN (type
))
14616 switch (TREE_CODE (type
))
14622 case REFERENCE_TYPE
:
14623 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14624 ensures that the gen_type_die recursion will terminate even if the
14625 type is recursive. Recursive types are possible in Ada. */
14626 /* ??? We could perhaps do this for all types before the switch
14628 TREE_ASM_WRITTEN (type
) = 1;
14630 /* For these types, all that is required is that we output a DIE (or a
14631 set of DIEs) to represent the "basis" type. */
14632 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14633 DINFO_USAGE_IND_USE
);
14637 /* This code is used for C++ pointer-to-data-member types.
14638 Output a description of the relevant class type. */
14639 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
14640 DINFO_USAGE_IND_USE
);
14642 /* Output a description of the type of the object pointed to. */
14643 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14644 DINFO_USAGE_IND_USE
);
14646 /* Now output a DIE to represent this pointer-to-data-member type
14648 gen_ptr_to_mbr_type_die (type
, context_die
);
14651 case FUNCTION_TYPE
:
14652 /* Force out return type (in case it wasn't forced out already). */
14653 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14654 DINFO_USAGE_DIR_USE
);
14655 gen_subroutine_type_die (type
, context_die
);
14659 /* Force out return type (in case it wasn't forced out already). */
14660 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14661 DINFO_USAGE_DIR_USE
);
14662 gen_subroutine_type_die (type
, context_die
);
14666 gen_array_type_die (type
, context_die
);
14670 gen_array_type_die (type
, context_die
);
14673 case ENUMERAL_TYPE
:
14676 case QUAL_UNION_TYPE
:
14677 /* If this is a nested type whose containing class hasn't been written
14678 out yet, writing it out will cover this one, too. This does not apply
14679 to instantiations of member class templates; they need to be added to
14680 the containing class as they are generated. FIXME: This hurts the
14681 idea of combining type decls from multiple TUs, since we can't predict
14682 what set of template instantiations we'll get. */
14683 if (TYPE_CONTEXT (type
)
14684 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
14685 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
14687 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
14689 if (TREE_ASM_WRITTEN (type
))
14692 /* If that failed, attach ourselves to the stub. */
14693 push_decl_scope (TYPE_CONTEXT (type
));
14694 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
14699 context_die
= declare_in_namespace (type
, context_die
);
14703 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
14705 /* This might have been written out by the call to
14706 declare_in_namespace. */
14707 if (!TREE_ASM_WRITTEN (type
))
14708 gen_enumeration_type_die (type
, context_die
);
14711 gen_struct_or_union_type_die (type
, context_die
, usage
);
14716 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14717 it up if it is ever completed. gen_*_type_die will set it for us
14718 when appropriate. */
14724 case FIXED_POINT_TYPE
:
14727 /* No DIEs needed for fundamental types. */
14731 /* No Dwarf representation currently defined. */
14735 gcc_unreachable ();
14738 TREE_ASM_WRITTEN (type
) = 1;
14742 gen_type_die (tree type
, dw_die_ref context_die
)
14744 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
14747 /* Generate a DIE for a tagged type instantiation. */
14750 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
14752 if (type
== NULL_TREE
|| type
== error_mark_node
)
14755 /* We are going to output a DIE to represent the unqualified version of
14756 this type (i.e. without any const or volatile qualifiers) so make sure
14757 that we have the main variant (i.e. the unqualified version) of this
14759 gcc_assert (type
== type_main_variant (type
));
14761 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14762 an instance of an unresolved type. */
14764 switch (TREE_CODE (type
))
14769 case ENUMERAL_TYPE
:
14770 gen_inlined_enumeration_type_die (type
, context_die
);
14774 gen_inlined_structure_type_die (type
, context_die
);
14778 case QUAL_UNION_TYPE
:
14779 gen_inlined_union_type_die (type
, context_die
);
14783 gcc_unreachable ();
14787 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14788 things which are local to the given block. */
14791 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14793 int must_output_die
= 0;
14796 enum tree_code origin_code
;
14798 /* Ignore blocks that are NULL. */
14799 if (stmt
== NULL_TREE
)
14802 /* If the block is one fragment of a non-contiguous block, do not
14803 process the variables, since they will have been done by the
14804 origin block. Do process subblocks. */
14805 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
14809 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
14810 gen_block_die (sub
, context_die
, depth
+ 1);
14815 /* Determine the "ultimate origin" of this block. This block may be an
14816 inlined instance of an inlined instance of inline function, so we have
14817 to trace all of the way back through the origin chain to find out what
14818 sort of node actually served as the original seed for the creation of
14819 the current block. */
14820 origin
= block_ultimate_origin (stmt
);
14821 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
14823 /* Determine if we need to output any Dwarf DIEs at all to represent this
14825 if (origin_code
== FUNCTION_DECL
)
14826 /* The outer scopes for inlinings *must* always be represented. We
14827 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14828 must_output_die
= 1;
14831 /* In the case where the current block represents an inlining of the
14832 "body block" of an inline function, we must *NOT* output any DIE for
14833 this block because we have already output a DIE to represent the whole
14834 inlined function scope and the "body block" of any function doesn't
14835 really represent a different scope according to ANSI C rules. So we
14836 check here to make sure that this block does not represent a "body
14837 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14838 if (! is_body_block (origin
? origin
: stmt
))
14840 /* Determine if this block directly contains any "significant"
14841 local declarations which we will need to output DIEs for. */
14842 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14843 /* We are not in terse mode so *any* local declaration counts
14844 as being a "significant" one. */
14845 must_output_die
= (BLOCK_VARS (stmt
) != NULL
14846 && (TREE_USED (stmt
)
14847 || TREE_ASM_WRITTEN (stmt
)
14848 || BLOCK_ABSTRACT (stmt
)));
14850 /* We are in terse mode, so only local (nested) function
14851 definitions count as "significant" local declarations. */
14852 for (decl
= BLOCK_VARS (stmt
);
14853 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
14854 if (TREE_CODE (decl
) == FUNCTION_DECL
14855 && DECL_INITIAL (decl
))
14857 must_output_die
= 1;
14863 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14864 DIE for any block which contains no significant local declarations at
14865 all. Rather, in such cases we just call `decls_for_scope' so that any
14866 needed Dwarf info for any sub-blocks will get properly generated. Note
14867 that in terse mode, our definition of what constitutes a "significant"
14868 local declaration gets restricted to include only inlined function
14869 instances and local (nested) function definitions. */
14870 if (must_output_die
)
14872 if (origin_code
== FUNCTION_DECL
)
14873 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
14875 gen_lexical_block_die (stmt
, context_die
, depth
);
14878 decls_for_scope (stmt
, context_die
, depth
);
14881 /* Generate all of the decls declared within a given scope and (recursively)
14882 all of its sub-blocks. */
14885 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
14890 /* Ignore NULL blocks. */
14891 if (stmt
== NULL_TREE
)
14894 if (TREE_USED (stmt
))
14896 /* Output the DIEs to represent all of the data objects and typedefs
14897 declared directly within this block but not within any nested
14898 sub-blocks. Also, nested function and tag DIEs have been
14899 generated with a parent of NULL; fix that up now. */
14900 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
14904 if (TREE_CODE (decl
) == FUNCTION_DECL
)
14905 die
= lookup_decl_die (decl
);
14906 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
14907 die
= lookup_type_die (TREE_TYPE (decl
));
14911 if (die
!= NULL
&& die
->die_parent
== NULL
)
14912 add_child_die (context_die
, die
);
14913 /* Do not produce debug information for static variables since
14914 these might be optimized out. We are called for these later
14915 in varpool_analyze_pending_decls.
14917 But *do* produce it for Fortran COMMON variables because,
14918 even though they are static, their names can differ depending
14919 on the scope, which we need to preserve. */
14920 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
)
14921 && !(is_fortran () && TREE_PUBLIC (decl
)))
14923 else if (TREE_CODE (decl
) == IMPORTED_DECL
)
14924 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
14925 stmt
, context_die
);
14927 gen_decl_die (decl
, context_die
);
14931 /* If we're at -g1, we're not interested in subblocks. */
14932 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14935 /* Output the DIEs to represent all sub-blocks (and the items declared
14936 therein) of this block. */
14937 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
14939 subblocks
= BLOCK_CHAIN (subblocks
))
14940 gen_block_die (subblocks
, context_die
, depth
+ 1);
14943 /* Is this a typedef we can avoid emitting? */
14946 is_redundant_typedef (const_tree decl
)
14948 if (TYPE_DECL_IS_STUB (decl
))
14951 if (DECL_ARTIFICIAL (decl
)
14952 && DECL_CONTEXT (decl
)
14953 && is_tagged_type (DECL_CONTEXT (decl
))
14954 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
14955 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
14956 /* Also ignore the artificial member typedef for the class name. */
14962 /* Returns the DIE for a context. */
14964 static inline dw_die_ref
14965 get_context_die (tree context
)
14969 /* Find die that represents this context. */
14970 if (TYPE_P (context
))
14971 return force_type_die (context
);
14973 return force_decl_die (context
);
14975 return comp_unit_die
;
14978 /* Returns the DIE for decl. A DIE will always be returned. */
14981 force_decl_die (tree decl
)
14983 dw_die_ref decl_die
;
14984 unsigned saved_external_flag
;
14985 tree save_fn
= NULL_TREE
;
14986 decl_die
= lookup_decl_die (decl
);
14989 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
14991 decl_die
= lookup_decl_die (decl
);
14995 switch (TREE_CODE (decl
))
14997 case FUNCTION_DECL
:
14998 /* Clear current_function_decl, so that gen_subprogram_die thinks
14999 that this is a declaration. At this point, we just want to force
15000 declaration die. */
15001 save_fn
= current_function_decl
;
15002 current_function_decl
= NULL_TREE
;
15003 gen_subprogram_die (decl
, context_die
);
15004 current_function_decl
= save_fn
;
15008 /* Set external flag to force declaration die. Restore it after
15009 gen_decl_die() call. */
15010 saved_external_flag
= DECL_EXTERNAL (decl
);
15011 DECL_EXTERNAL (decl
) = 1;
15012 gen_decl_die (decl
, context_die
);
15013 DECL_EXTERNAL (decl
) = saved_external_flag
;
15016 case NAMESPACE_DECL
:
15017 dwarf2out_decl (decl
);
15021 gcc_unreachable ();
15024 /* We should be able to find the DIE now. */
15026 decl_die
= lookup_decl_die (decl
);
15027 gcc_assert (decl_die
);
15033 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15034 always returned. */
15037 force_type_die (tree type
)
15039 dw_die_ref type_die
;
15041 type_die
= lookup_type_die (type
);
15044 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
15046 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
15047 TYPE_VOLATILE (type
), context_die
);
15048 gcc_assert (type_die
);
15053 /* Force out any required namespaces to be able to output DECL,
15054 and return the new context_die for it, if it's changed. */
15057 setup_namespace_context (tree thing
, dw_die_ref context_die
)
15059 tree context
= (DECL_P (thing
)
15060 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
15061 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
15062 /* Force out the namespace. */
15063 context_die
= force_decl_die (context
);
15065 return context_die
;
15068 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15069 type) within its namespace, if appropriate.
15071 For compatibility with older debuggers, namespace DIEs only contain
15072 declarations; all definitions are emitted at CU scope. */
15075 declare_in_namespace (tree thing
, dw_die_ref context_die
)
15077 dw_die_ref ns_context
;
15079 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15080 return context_die
;
15082 /* If this decl is from an inlined function, then don't try to emit it in its
15083 namespace, as we will get confused. It would have already been emitted
15084 when the abstract instance of the inline function was emitted anyways. */
15085 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
15086 return context_die
;
15088 ns_context
= setup_namespace_context (thing
, context_die
);
15090 if (ns_context
!= context_die
)
15094 if (DECL_P (thing
))
15095 gen_decl_die (thing
, ns_context
);
15097 gen_type_die (thing
, ns_context
);
15099 return context_die
;
15102 /* Generate a DIE for a namespace or namespace alias. */
15105 gen_namespace_die (tree decl
)
15107 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
15109 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15110 they are an alias of. */
15111 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
15113 /* Output a real namespace or module. */
15114 dw_die_ref namespace_die
15115 = new_die (is_fortran () ? DW_TAG_module
: DW_TAG_namespace
,
15116 context_die
, decl
);
15117 /* For Fortran modules defined in different CU don't add src coords. */
15118 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
15119 add_name_attribute (namespace_die
, dwarf2_name (decl
, 0));
15121 add_name_and_src_coords_attributes (namespace_die
, decl
);
15122 if (DECL_EXTERNAL (decl
))
15123 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
15124 equate_decl_number_to_die (decl
, namespace_die
);
15128 /* Output a namespace alias. */
15130 /* Force out the namespace we are an alias of, if necessary. */
15131 dw_die_ref origin_die
15132 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
15134 /* Now create the namespace alias DIE. */
15135 dw_die_ref namespace_die
15136 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
15137 add_name_and_src_coords_attributes (namespace_die
, decl
);
15138 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
15139 equate_decl_number_to_die (decl
, namespace_die
);
15143 /* Generate Dwarf debug information for a decl described by DECL. */
15146 gen_decl_die (tree decl
, dw_die_ref context_die
)
15150 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
15153 switch (TREE_CODE (decl
))
15159 if (!is_fortran ())
15161 /* The individual enumerators of an enum type get output when we output
15162 the Dwarf representation of the relevant enum type itself. */
15166 /* Emit its type. */
15167 gen_type_die (TREE_TYPE (decl
), context_die
);
15169 /* And its containing namespace. */
15170 context_die
= declare_in_namespace (decl
, context_die
);
15172 gen_const_die (decl
, context_die
);
15175 case FUNCTION_DECL
:
15176 /* Don't output any DIEs to represent mere function declarations,
15177 unless they are class members or explicit block externs. */
15178 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
15179 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
15184 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15185 on local redeclarations of global functions. That seems broken. */
15186 if (current_function_decl
!= decl
)
15187 /* This is only a declaration. */;
15190 /* If we're emitting a clone, emit info for the abstract instance. */
15191 if (DECL_ORIGIN (decl
) != decl
)
15192 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
15194 /* If we're emitting an out-of-line copy of an inline function,
15195 emit info for the abstract instance and set up to refer to it. */
15196 else if (cgraph_function_possibly_inlined_p (decl
)
15197 && ! DECL_ABSTRACT (decl
)
15198 && ! class_or_namespace_scope_p (context_die
)
15199 /* dwarf2out_abstract_function won't emit a die if this is just
15200 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15201 that case, because that works only if we have a die. */
15202 && DECL_INITIAL (decl
) != NULL_TREE
)
15204 dwarf2out_abstract_function (decl
);
15205 set_decl_origin_self (decl
);
15208 /* Otherwise we're emitting the primary DIE for this decl. */
15209 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15211 /* Before we describe the FUNCTION_DECL itself, make sure that we
15212 have described its return type. */
15213 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
15215 /* And its virtual context. */
15216 if (DECL_VINDEX (decl
) != NULL_TREE
)
15217 gen_type_die (DECL_CONTEXT (decl
), context_die
);
15219 /* And its containing type. */
15220 origin
= decl_class_context (decl
);
15221 if (origin
!= NULL_TREE
)
15222 gen_type_die_for_member (origin
, decl
, context_die
);
15224 /* And its containing namespace. */
15225 context_die
= declare_in_namespace (decl
, context_die
);
15228 /* Now output a DIE to represent the function itself. */
15229 gen_subprogram_die (decl
, context_die
);
15233 /* If we are in terse mode, don't generate any DIEs to represent any
15234 actual typedefs. */
15235 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15238 /* In the special case of a TYPE_DECL node representing the declaration
15239 of some type tag, if the given TYPE_DECL is marked as having been
15240 instantiated from some other (original) TYPE_DECL node (e.g. one which
15241 was generated within the original definition of an inline function) we
15242 have to generate a special (abbreviated) DW_TAG_structure_type,
15243 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
15244 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
15245 && is_tagged_type (TREE_TYPE (decl
)))
15247 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
15251 if (is_redundant_typedef (decl
))
15252 gen_type_die (TREE_TYPE (decl
), context_die
);
15254 /* Output a DIE to represent the typedef itself. */
15255 gen_typedef_die (decl
, context_die
);
15259 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
15260 gen_label_die (decl
, context_die
);
15265 /* If we are in terse mode, don't generate any DIEs to represent any
15266 variable declarations or definitions. */
15267 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15270 /* Output any DIEs that are needed to specify the type of this data
15272 if (TREE_CODE (decl
) == RESULT_DECL
&& DECL_BY_REFERENCE (decl
))
15273 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
15275 gen_type_die (TREE_TYPE (decl
), context_die
);
15277 /* And its containing type. */
15278 origin
= decl_class_context (decl
);
15279 if (origin
!= NULL_TREE
)
15280 gen_type_die_for_member (origin
, decl
, context_die
);
15282 /* And its containing namespace. */
15283 context_die
= declare_in_namespace (decl
, context_die
);
15285 /* Now output the DIE to represent the data object itself. This gets
15286 complicated because of the possibility that the VAR_DECL really
15287 represents an inlined instance of a formal parameter for an inline
15289 origin
= decl_ultimate_origin (decl
);
15290 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
15291 gen_formal_parameter_die (decl
, context_die
);
15293 gen_variable_die (decl
, context_die
);
15297 /* Ignore the nameless fields that are used to skip bits but handle C++
15298 anonymous unions and structs. */
15299 if (DECL_NAME (decl
) != NULL_TREE
15300 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
15301 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
15303 gen_type_die (member_declared_type (decl
), context_die
);
15304 gen_field_die (decl
, context_die
);
15309 if (DECL_BY_REFERENCE (decl
))
15310 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
15312 gen_type_die (TREE_TYPE (decl
), context_die
);
15313 gen_formal_parameter_die (decl
, context_die
);
15316 case NAMESPACE_DECL
:
15317 case IMPORTED_DECL
:
15318 gen_namespace_die (decl
);
15322 /* Probably some frontend-internal decl. Assume we don't care. */
15323 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
15328 /* Output debug information for global decl DECL. Called from toplev.c after
15329 compilation proper has finished. */
15332 dwarf2out_global_decl (tree decl
)
15334 /* Output DWARF2 information for file-scope tentative data object
15335 declarations, file-scope (extern) function declarations (which
15336 had no corresponding body) and file-scope tagged type declarations
15337 and definitions which have not yet been forced out. */
15338 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
15339 dwarf2out_decl (decl
);
15342 /* Output debug information for type decl DECL. Called from toplev.c
15343 and from language front ends (to record built-in types). */
15345 dwarf2out_type_decl (tree decl
, int local
)
15348 dwarf2out_decl (decl
);
15351 /* Output debug information for imported module or decl DECL.
15352 NAME is non-NULL name in the lexical block if the decl has been renamed.
15353 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15354 that DECL belongs to.
15355 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15357 dwarf2out_imported_module_or_decl_1 (tree decl
,
15359 tree lexical_block
,
15360 dw_die_ref lexical_block_die
)
15362 expanded_location xloc
;
15363 dw_die_ref imported_die
= NULL
;
15364 dw_die_ref at_import_die
;
15366 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
15368 if (is_base_type (TREE_TYPE (decl
)))
15369 at_import_die
= base_type_die (TREE_TYPE (decl
));
15371 at_import_die
= force_type_die (TREE_TYPE (decl
));
15372 /* For namespace N { typedef void T; } using N::T; base_type_die
15373 returns NULL, but DW_TAG_imported_declaration requires
15374 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15375 if (!at_import_die
)
15377 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
15378 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
15379 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
15380 gcc_assert (at_import_die
);
15383 else if (TREE_CODE (decl
) == IMPORTED_DECL
)
15385 tree imported_ns_decl
;
15386 /* IMPORTED_DECL nodes that are not imported namespace are just not
15388 gcc_assert (DECL_INITIAL (decl
)
15389 && TREE_CODE (DECL_INITIAL (decl
)) == NAMESPACE_DECL
);
15390 imported_ns_decl
= DECL_INITIAL (decl
);
15391 at_import_die
= lookup_decl_die (imported_ns_decl
);
15392 if (!at_import_die
)
15393 at_import_die
= force_decl_die (imported_ns_decl
);
15394 gcc_assert (at_import_die
);
15398 at_import_die
= lookup_decl_die (decl
);
15399 if (!at_import_die
)
15401 /* If we're trying to avoid duplicate debug info, we may not have
15402 emitted the member decl for this field. Emit it now. */
15403 if (TREE_CODE (decl
) == FIELD_DECL
)
15405 tree type
= DECL_CONTEXT (decl
);
15407 if (TYPE_CONTEXT (type
)
15408 && TYPE_P (TYPE_CONTEXT (type
))
15409 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
15410 DINFO_USAGE_DIR_USE
))
15412 gen_type_die_for_member (type
, decl
,
15413 get_context_die (TYPE_CONTEXT (type
)));
15415 at_import_die
= force_decl_die (decl
);
15419 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
15420 imported_die
= new_die (DW_TAG_imported_module
,
15424 imported_die
= new_die (DW_TAG_imported_declaration
,
15428 xloc
= expand_location (input_location
);
15429 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
15430 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
15432 add_AT_string (imported_die
, DW_AT_name
,
15433 IDENTIFIER_POINTER (name
));
15434 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
15437 /* Output debug information for imported module or decl DECL.
15438 NAME is non-NULL name in context if the decl has been renamed.
15439 CHILD is true if decl is one of the renamed decls as part of
15440 importing whole module. */
15443 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
15446 /* dw_die_ref at_import_die; */
15447 dw_die_ref scope_die
;
15449 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15454 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15455 We need decl DIE for reference and scope die. First, get DIE for the decl
15458 /* Get the scope die for decl context. Use comp_unit_die for global module
15459 or decl. If die is not found for non globals, force new die. */
15461 && TYPE_P (context
)
15462 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
15464 scope_die
= get_context_die (context
);
15468 gcc_assert (scope_die
->die_child
);
15469 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
15470 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
15471 scope_die
= scope_die
->die_child
;
15474 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15475 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
15479 /* Write the debugging output for DECL. */
15482 dwarf2out_decl (tree decl
)
15484 dw_die_ref context_die
= comp_unit_die
;
15486 switch (TREE_CODE (decl
))
15491 case FUNCTION_DECL
:
15492 /* What we would really like to do here is to filter out all mere
15493 file-scope declarations of file-scope functions which are never
15494 referenced later within this translation unit (and keep all of ones
15495 that *are* referenced later on) but we aren't clairvoyant, so we have
15496 no idea which functions will be referenced in the future (i.e. later
15497 on within the current translation unit). So here we just ignore all
15498 file-scope function declarations which are not also definitions. If
15499 and when the debugger needs to know something about these functions,
15500 it will have to hunt around and find the DWARF information associated
15501 with the definition of the function.
15503 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15504 nodes represent definitions and which ones represent mere
15505 declarations. We have to check DECL_INITIAL instead. That's because
15506 the C front-end supports some weird semantics for "extern inline"
15507 function definitions. These can get inlined within the current
15508 translation unit (and thus, we need to generate Dwarf info for their
15509 abstract instances so that the Dwarf info for the concrete inlined
15510 instances can have something to refer to) but the compiler never
15511 generates any out-of-lines instances of such things (despite the fact
15512 that they *are* definitions).
15514 The important point is that the C front-end marks these "extern
15515 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15516 them anyway. Note that the C++ front-end also plays some similar games
15517 for inline function definitions appearing within include files which
15518 also contain `#pragma interface' pragmas. */
15519 if (DECL_INITIAL (decl
) == NULL_TREE
)
15522 /* If we're a nested function, initially use a parent of NULL; if we're
15523 a plain function, this will be fixed up in decls_for_scope. If
15524 we're a method, it will be ignored, since we already have a DIE. */
15525 if (decl_function_context (decl
)
15526 /* But if we're in terse mode, we don't care about scope. */
15527 && debug_info_level
> DINFO_LEVEL_TERSE
)
15528 context_die
= NULL
;
15532 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15533 declaration and if the declaration was never even referenced from
15534 within this entire compilation unit. We suppress these DIEs in
15535 order to save space in the .debug section (by eliminating entries
15536 which are probably useless). Note that we must not suppress
15537 block-local extern declarations (whether used or not) because that
15538 would screw-up the debugger's name lookup mechanism and cause it to
15539 miss things which really ought to be in scope at a given point. */
15540 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
15543 /* For local statics lookup proper context die. */
15544 if (TREE_STATIC (decl
) && decl_function_context (decl
))
15545 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
15547 /* If we are in terse mode, don't generate any DIEs to represent any
15548 variable declarations or definitions. */
15549 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15554 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15556 if (!is_fortran ())
15558 if (TREE_STATIC (decl
) && decl_function_context (decl
))
15559 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
15562 case NAMESPACE_DECL
:
15563 case IMPORTED_DECL
:
15564 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15566 if (lookup_decl_die (decl
) != NULL
)
15571 /* Don't emit stubs for types unless they are needed by other DIEs. */
15572 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
15575 /* Don't bother trying to generate any DIEs to represent any of the
15576 normal built-in types for the language we are compiling. */
15577 if (DECL_IS_BUILTIN (decl
))
15579 /* OK, we need to generate one for `bool' so GDB knows what type
15580 comparisons have. */
15582 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
15583 && ! DECL_IGNORED_P (decl
))
15584 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
15589 /* If we are in terse mode, don't generate any DIEs for types. */
15590 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15593 /* If we're a function-scope tag, initially use a parent of NULL;
15594 this will be fixed up in decls_for_scope. */
15595 if (decl_function_context (decl
))
15596 context_die
= NULL
;
15604 gen_decl_die (decl
, context_die
);
15607 /* Output a marker (i.e. a label) for the beginning of the generated code for
15608 a lexical block. */
15611 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
15612 unsigned int blocknum
)
15614 switch_to_section (current_function_section ());
15615 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
15618 /* Output a marker (i.e. a label) for the end of the generated code for a
15622 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
15624 switch_to_section (current_function_section ());
15625 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
15628 /* Returns nonzero if it is appropriate not to emit any debugging
15629 information for BLOCK, because it doesn't contain any instructions.
15631 Don't allow this for blocks with nested functions or local classes
15632 as we would end up with orphans, and in the presence of scheduling
15633 we may end up calling them anyway. */
15636 dwarf2out_ignore_block (const_tree block
)
15640 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
15641 if (TREE_CODE (decl
) == FUNCTION_DECL
15642 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
15648 /* Hash table routines for file_hash. */
15651 file_table_eq (const void *p1_p
, const void *p2_p
)
15653 const struct dwarf_file_data
*const p1
=
15654 (const struct dwarf_file_data
*) p1_p
;
15655 const char *const p2
= (const char *) p2_p
;
15656 return strcmp (p1
->filename
, p2
) == 0;
15660 file_table_hash (const void *p_p
)
15662 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
15663 return htab_hash_string (p
->filename
);
15666 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15667 dwarf2out.c) and return its "index". The index of each (known) filename is
15668 just a unique number which is associated with only that one filename. We
15669 need such numbers for the sake of generating labels (in the .debug_sfnames
15670 section) and references to those files numbers (in the .debug_srcinfo
15671 and.debug_macinfo sections). If the filename given as an argument is not
15672 found in our current list, add it to the list and assign it the next
15673 available unique index number. In order to speed up searches, we remember
15674 the index of the filename was looked up last. This handles the majority of
15677 static struct dwarf_file_data
*
15678 lookup_filename (const char *file_name
)
15681 struct dwarf_file_data
* created
;
15683 /* Check to see if the file name that was searched on the previous
15684 call matches this file name. If so, return the index. */
15685 if (file_table_last_lookup
15686 && (file_name
== file_table_last_lookup
->filename
15687 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
15688 return file_table_last_lookup
;
15690 /* Didn't match the previous lookup, search the table. */
15691 slot
= htab_find_slot_with_hash (file_table
, file_name
,
15692 htab_hash_string (file_name
), INSERT
);
15694 return (struct dwarf_file_data
*) *slot
;
15696 created
= GGC_NEW (struct dwarf_file_data
);
15697 created
->filename
= file_name
;
15698 created
->emitted_number
= 0;
15703 /* If the assembler will construct the file table, then translate the compiler
15704 internal file table number into the assembler file table number, and emit
15705 a .file directive if we haven't already emitted one yet. The file table
15706 numbers are different because we prune debug info for unused variables and
15707 types, which may include filenames. */
15710 maybe_emit_file (struct dwarf_file_data
* fd
)
15712 if (! fd
->emitted_number
)
15714 if (last_emitted_file
)
15715 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
15717 fd
->emitted_number
= 1;
15718 last_emitted_file
= fd
;
15720 if (DWARF2_ASM_LINE_DEBUG_INFO
)
15722 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
15723 output_quoted_string (asm_out_file
,
15724 remap_debug_filename (fd
->filename
));
15725 fputc ('\n', asm_out_file
);
15729 return fd
->emitted_number
;
15732 /* Called by the final INSN scan whenever we see a var location. We
15733 use it to drop labels in the right places, and throw the location in
15734 our lookup table. */
15737 dwarf2out_var_location (rtx loc_note
)
15739 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
15740 struct var_loc_node
*newloc
;
15742 static rtx last_insn
;
15743 static const char *last_label
;
15746 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
15748 prev_insn
= PREV_INSN (loc_note
);
15750 newloc
= GGC_CNEW (struct var_loc_node
);
15751 /* If the insn we processed last time is the previous insn
15752 and it is also a var location note, use the label we emitted
15754 if (last_insn
!= NULL_RTX
15755 && last_insn
== prev_insn
15756 && NOTE_P (prev_insn
)
15757 && NOTE_KIND (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
15759 newloc
->label
= last_label
;
15763 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
15764 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
15766 newloc
->label
= ggc_strdup (loclabel
);
15768 newloc
->var_loc_note
= loc_note
;
15769 newloc
->next
= NULL
;
15771 if (cfun
&& in_cold_section_p
)
15772 newloc
->section_label
= crtl
->subsections
.cold_section_label
;
15774 newloc
->section_label
= text_section_label
;
15776 last_insn
= loc_note
;
15777 last_label
= newloc
->label
;
15778 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
15779 add_var_loc_to_decl (decl
, newloc
);
15782 /* We need to reset the locations at the beginning of each
15783 function. We can't do this in the end_function hook, because the
15784 declarations that use the locations won't have been output when
15785 that hook is called. Also compute have_multiple_function_sections here. */
15788 dwarf2out_begin_function (tree fun
)
15790 htab_empty (decl_loc_table
);
15792 if (function_section (fun
) != text_section
)
15793 have_multiple_function_sections
= true;
15795 dwarf2out_note_section_used ();
15798 /* Output a label to mark the beginning of a source code line entry
15799 and record information relating to this source line, in
15800 'line_info_table' for later output of the .debug_line section. */
15803 dwarf2out_source_line (unsigned int line
, const char *filename
)
15805 if (debug_info_level
>= DINFO_LEVEL_NORMAL
15808 int file_num
= maybe_emit_file (lookup_filename (filename
));
15810 switch_to_section (current_function_section ());
15812 /* If requested, emit something human-readable. */
15813 if (flag_debug_asm
)
15814 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
15817 if (DWARF2_ASM_LINE_DEBUG_INFO
)
15819 /* Emit the .loc directive understood by GNU as. */
15820 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
15822 /* Indicate that line number info exists. */
15823 line_info_table_in_use
++;
15825 else if (function_section (current_function_decl
) != text_section
)
15827 dw_separate_line_info_ref line_info
;
15828 targetm
.asm_out
.internal_label (asm_out_file
,
15829 SEPARATE_LINE_CODE_LABEL
,
15830 separate_line_info_table_in_use
);
15832 /* Expand the line info table if necessary. */
15833 if (separate_line_info_table_in_use
15834 == separate_line_info_table_allocated
)
15836 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15837 separate_line_info_table
15838 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
15839 separate_line_info_table
,
15840 separate_line_info_table_allocated
);
15841 memset (separate_line_info_table
15842 + separate_line_info_table_in_use
,
15844 (LINE_INFO_TABLE_INCREMENT
15845 * sizeof (dw_separate_line_info_entry
)));
15848 /* Add the new entry at the end of the line_info_table. */
15850 = &separate_line_info_table
[separate_line_info_table_in_use
++];
15851 line_info
->dw_file_num
= file_num
;
15852 line_info
->dw_line_num
= line
;
15853 line_info
->function
= current_function_funcdef_no
;
15857 dw_line_info_ref line_info
;
15859 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
15860 line_info_table_in_use
);
15862 /* Expand the line info table if necessary. */
15863 if (line_info_table_in_use
== line_info_table_allocated
)
15865 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15867 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
15868 line_info_table_allocated
);
15869 memset (line_info_table
+ line_info_table_in_use
, 0,
15870 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
15873 /* Add the new entry at the end of the line_info_table. */
15874 line_info
= &line_info_table
[line_info_table_in_use
++];
15875 line_info
->dw_file_num
= file_num
;
15876 line_info
->dw_line_num
= line
;
15881 /* Record the beginning of a new source file. */
15884 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
15886 if (flag_eliminate_dwarf2_dups
)
15888 /* Record the beginning of the file for break_out_includes. */
15889 dw_die_ref bincl_die
;
15891 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
15892 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
15895 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15897 int file_num
= maybe_emit_file (lookup_filename (filename
));
15899 switch_to_section (debug_macinfo_section
);
15900 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
15901 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
15904 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
15908 /* Record the end of a source file. */
15911 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
15913 if (flag_eliminate_dwarf2_dups
)
15914 /* Record the end of the file for break_out_includes. */
15915 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
15917 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15919 switch_to_section (debug_macinfo_section
);
15920 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
15924 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15925 the tail part of the directive line, i.e. the part which is past the
15926 initial whitespace, #, whitespace, directive-name, whitespace part. */
15929 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
15930 const char *buffer ATTRIBUTE_UNUSED
)
15932 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15934 switch_to_section (debug_macinfo_section
);
15935 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
15936 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15937 dw2_asm_output_nstring (buffer
, -1, "The macro");
15941 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15942 the tail part of the directive line, i.e. the part which is past the
15943 initial whitespace, #, whitespace, directive-name, whitespace part. */
15946 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
15947 const char *buffer ATTRIBUTE_UNUSED
)
15949 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15951 switch_to_section (debug_macinfo_section
);
15952 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
15953 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15954 dw2_asm_output_nstring (buffer
, -1, "The macro");
15958 /* Set up for Dwarf output at the start of compilation. */
15961 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
15963 /* Allocate the file_table. */
15964 file_table
= htab_create_ggc (50, file_table_hash
,
15965 file_table_eq
, NULL
);
15967 /* Allocate the decl_die_table. */
15968 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
15969 decl_die_table_eq
, NULL
);
15971 /* Allocate the decl_loc_table. */
15972 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
15973 decl_loc_table_eq
, NULL
);
15975 /* Allocate the initial hunk of the decl_scope_table. */
15976 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
15978 /* Allocate the initial hunk of the abbrev_die_table. */
15979 abbrev_die_table
= GGC_CNEWVEC (dw_die_ref
, ABBREV_DIE_TABLE_INCREMENT
);
15980 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
15981 /* Zero-th entry is allocated, but unused. */
15982 abbrev_die_table_in_use
= 1;
15984 /* Allocate the initial hunk of the line_info_table. */
15985 line_info_table
= GGC_CNEWVEC (dw_line_info_entry
, LINE_INFO_TABLE_INCREMENT
);
15986 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
15988 /* Zero-th entry is allocated, but unused. */
15989 line_info_table_in_use
= 1;
15991 /* Allocate the pubtypes and pubnames vectors. */
15992 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
15993 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
15995 /* Generate the initial DIE for the .debug section. Note that the (string)
15996 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15997 will (typically) be a relative pathname and that this pathname should be
15998 taken as being relative to the directory from which the compiler was
15999 invoked when the given (base) source file was compiled. We will fill
16000 in this value in dwarf2out_finish. */
16001 comp_unit_die
= gen_compile_unit_die (NULL
);
16003 incomplete_types
= VEC_alloc (tree
, gc
, 64);
16005 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
16007 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
16008 SECTION_DEBUG
, NULL
);
16009 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
16010 SECTION_DEBUG
, NULL
);
16011 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
16012 SECTION_DEBUG
, NULL
);
16013 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
16014 SECTION_DEBUG
, NULL
);
16015 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
16016 SECTION_DEBUG
, NULL
);
16017 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
16018 SECTION_DEBUG
, NULL
);
16019 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
16020 SECTION_DEBUG
, NULL
);
16021 #ifdef DEBUG_PUBTYPES_SECTION
16022 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
16023 SECTION_DEBUG
, NULL
);
16025 debug_str_section
= get_section (DEBUG_STR_SECTION
,
16026 DEBUG_STR_SECTION_FLAGS
, NULL
);
16027 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
16028 SECTION_DEBUG
, NULL
);
16029 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
16030 SECTION_DEBUG
, NULL
);
16032 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
16033 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
16034 DEBUG_ABBREV_SECTION_LABEL
, 0);
16035 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
16036 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
16037 COLD_TEXT_SECTION_LABEL
, 0);
16038 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
16040 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
16041 DEBUG_INFO_SECTION_LABEL
, 0);
16042 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
16043 DEBUG_LINE_SECTION_LABEL
, 0);
16044 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
16045 DEBUG_RANGES_SECTION_LABEL
, 0);
16046 switch_to_section (debug_abbrev_section
);
16047 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
16048 switch_to_section (debug_info_section
);
16049 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
16050 switch_to_section (debug_line_section
);
16051 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
16053 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16055 switch_to_section (debug_macinfo_section
);
16056 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
16057 DEBUG_MACINFO_SECTION_LABEL
, 0);
16058 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
16061 switch_to_section (text_section
);
16062 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
16063 if (flag_reorder_blocks_and_partition
)
16065 cold_text_section
= unlikely_text_section ();
16066 switch_to_section (cold_text_section
);
16067 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
16071 /* A helper function for dwarf2out_finish called through
16072 ht_forall. Emit one queued .debug_str string. */
16075 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
16077 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
16079 if (node
->form
== DW_FORM_strp
)
16081 switch_to_section (debug_str_section
);
16082 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
16083 assemble_string (node
->str
, strlen (node
->str
) + 1);
16089 #if ENABLE_ASSERT_CHECKING
16090 /* Verify that all marks are clear. */
16093 verify_marks_clear (dw_die_ref die
)
16097 gcc_assert (! die
->die_mark
);
16098 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
16100 #endif /* ENABLE_ASSERT_CHECKING */
16102 /* Clear the marks for a die and its children.
16103 Be cool if the mark isn't set. */
16106 prune_unmark_dies (dw_die_ref die
)
16112 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
16115 /* Given DIE that we're marking as used, find any other dies
16116 it references as attributes and mark them as used. */
16119 prune_unused_types_walk_attribs (dw_die_ref die
)
16124 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16126 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
16128 /* A reference to another DIE.
16129 Make sure that it will get emitted. */
16130 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
16132 /* Set the string's refcount to 0 so that prune_unused_types_mark
16133 accounts properly for it. */
16134 if (AT_class (a
) == dw_val_class_str
)
16135 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
16140 /* Mark DIE as being used. If DOKIDS is true, then walk down
16141 to DIE's children. */
16144 prune_unused_types_mark (dw_die_ref die
, int dokids
)
16148 if (die
->die_mark
== 0)
16150 /* We haven't done this node yet. Mark it as used. */
16153 /* We also have to mark its parents as used.
16154 (But we don't want to mark our parents' kids due to this.) */
16155 if (die
->die_parent
)
16156 prune_unused_types_mark (die
->die_parent
, 0);
16158 /* Mark any referenced nodes. */
16159 prune_unused_types_walk_attribs (die
);
16161 /* If this node is a specification,
16162 also mark the definition, if it exists. */
16163 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
16164 prune_unused_types_mark (die
->die_definition
, 1);
16167 if (dokids
&& die
->die_mark
!= 2)
16169 /* We need to walk the children, but haven't done so yet.
16170 Remember that we've walked the kids. */
16173 /* If this is an array type, we need to make sure our
16174 kids get marked, even if they're types. */
16175 if (die
->die_tag
== DW_TAG_array_type
)
16176 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
16178 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16183 /* Walk the tree DIE and mark types that we actually use. */
16186 prune_unused_types_walk (dw_die_ref die
)
16190 /* Don't do anything if this node is already marked. */
16194 switch (die
->die_tag
)
16196 case DW_TAG_const_type
:
16197 case DW_TAG_packed_type
:
16198 case DW_TAG_pointer_type
:
16199 case DW_TAG_reference_type
:
16200 case DW_TAG_volatile_type
:
16201 case DW_TAG_typedef
:
16202 case DW_TAG_array_type
:
16203 case DW_TAG_structure_type
:
16204 case DW_TAG_union_type
:
16205 case DW_TAG_class_type
:
16206 case DW_TAG_interface_type
:
16207 case DW_TAG_friend
:
16208 case DW_TAG_variant_part
:
16209 case DW_TAG_enumeration_type
:
16210 case DW_TAG_subroutine_type
:
16211 case DW_TAG_string_type
:
16212 case DW_TAG_set_type
:
16213 case DW_TAG_subrange_type
:
16214 case DW_TAG_ptr_to_member_type
:
16215 case DW_TAG_file_type
:
16216 if (die
->die_perennial_p
)
16219 /* It's a type node --- don't mark it. */
16223 /* Mark everything else. */
16229 /* Now, mark any dies referenced from here. */
16230 prune_unused_types_walk_attribs (die
);
16232 /* Mark children. */
16233 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16236 /* Increment the string counts on strings referred to from DIE's
16240 prune_unused_types_update_strings (dw_die_ref die
)
16245 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16246 if (AT_class (a
) == dw_val_class_str
)
16248 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
16250 /* Avoid unnecessarily putting strings that are used less than
16251 twice in the hash table. */
16253 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
16256 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
16257 htab_hash_string (s
->str
),
16259 gcc_assert (*slot
== NULL
);
16265 /* Remove from the tree DIE any dies that aren't marked. */
16268 prune_unused_types_prune (dw_die_ref die
)
16272 gcc_assert (die
->die_mark
);
16273 prune_unused_types_update_strings (die
);
16275 if (! die
->die_child
)
16278 c
= die
->die_child
;
16280 dw_die_ref prev
= c
;
16281 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
16282 if (c
== die
->die_child
)
16284 /* No marked children between 'prev' and the end of the list. */
16286 /* No marked children at all. */
16287 die
->die_child
= NULL
;
16290 prev
->die_sib
= c
->die_sib
;
16291 die
->die_child
= prev
;
16296 if (c
!= prev
->die_sib
)
16298 prune_unused_types_prune (c
);
16299 } while (c
!= die
->die_child
);
16303 /* Remove dies representing declarations that we never use. */
16306 prune_unused_types (void)
16309 limbo_die_node
*node
;
16312 #if ENABLE_ASSERT_CHECKING
16313 /* All the marks should already be clear. */
16314 verify_marks_clear (comp_unit_die
);
16315 for (node
= limbo_die_list
; node
; node
= node
->next
)
16316 verify_marks_clear (node
->die
);
16317 #endif /* ENABLE_ASSERT_CHECKING */
16319 /* Set the mark on nodes that are actually used. */
16320 prune_unused_types_walk (comp_unit_die
);
16321 for (node
= limbo_die_list
; node
; node
= node
->next
)
16322 prune_unused_types_walk (node
->die
);
16324 /* Also set the mark on nodes referenced from the
16325 pubname_table or arange_table. */
16326 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
16327 prune_unused_types_mark (pub
->die
, 1);
16328 for (i
= 0; i
< arange_table_in_use
; i
++)
16329 prune_unused_types_mark (arange_table
[i
], 1);
16331 /* Get rid of nodes that aren't marked; and update the string counts. */
16332 if (debug_str_hash
)
16333 htab_empty (debug_str_hash
);
16334 prune_unused_types_prune (comp_unit_die
);
16335 for (node
= limbo_die_list
; node
; node
= node
->next
)
16336 prune_unused_types_prune (node
->die
);
16338 /* Leave the marks clear. */
16339 prune_unmark_dies (comp_unit_die
);
16340 for (node
= limbo_die_list
; node
; node
= node
->next
)
16341 prune_unmark_dies (node
->die
);
16344 /* Set the parameter to true if there are any relative pathnames in
16347 file_table_relative_p (void ** slot
, void *param
)
16349 bool *p
= (bool *) param
;
16350 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
16351 if (!IS_ABSOLUTE_PATH (d
->filename
))
16359 /* Output stuff that dwarf requires at the end of every file,
16360 and generate the DWARF-2 debugging info. */
16363 dwarf2out_finish (const char *filename
)
16365 limbo_die_node
*node
, *next_node
;
16366 dw_die_ref die
= 0;
16368 /* Add the name for the main input file now. We delayed this from
16369 dwarf2out_init to avoid complications with PCH. */
16370 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
16371 if (!IS_ABSOLUTE_PATH (filename
))
16372 add_comp_dir_attribute (comp_unit_die
);
16373 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
16376 htab_traverse (file_table
, file_table_relative_p
, &p
);
16378 add_comp_dir_attribute (comp_unit_die
);
16381 /* Traverse the limbo die list, and add parent/child links. The only
16382 dies without parents that should be here are concrete instances of
16383 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16384 For concrete instances, we can get the parent die from the abstract
16386 for (node
= limbo_die_list
; node
; node
= next_node
)
16388 next_node
= node
->next
;
16391 if (die
->die_parent
== NULL
)
16393 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
16396 add_child_die (origin
->die_parent
, die
);
16397 else if (die
== comp_unit_die
)
16399 else if (errorcount
> 0 || sorrycount
> 0)
16400 /* It's OK to be confused by errors in the input. */
16401 add_child_die (comp_unit_die
, die
);
16404 /* In certain situations, the lexical block containing a
16405 nested function can be optimized away, which results
16406 in the nested function die being orphaned. Likewise
16407 with the return type of that nested function. Force
16408 this to be a child of the containing function.
16410 It may happen that even the containing function got fully
16411 inlined and optimized out. In that case we are lost and
16412 assign the empty child. This should not be big issue as
16413 the function is likely unreachable too. */
16414 tree context
= NULL_TREE
;
16416 gcc_assert (node
->created_for
);
16418 if (DECL_P (node
->created_for
))
16419 context
= DECL_CONTEXT (node
->created_for
);
16420 else if (TYPE_P (node
->created_for
))
16421 context
= TYPE_CONTEXT (node
->created_for
);
16423 gcc_assert (context
16424 && (TREE_CODE (context
) == FUNCTION_DECL
16425 || TREE_CODE (context
) == NAMESPACE_DECL
));
16427 origin
= lookup_decl_die (context
);
16429 add_child_die (origin
, die
);
16431 add_child_die (comp_unit_die
, die
);
16436 limbo_die_list
= NULL
;
16438 /* Walk through the list of incomplete types again, trying once more to
16439 emit full debugging info for them. */
16440 retry_incomplete_types ();
16442 if (flag_eliminate_unused_debug_types
)
16443 prune_unused_types ();
16445 /* Generate separate CUs for each of the include files we've seen.
16446 They will go into limbo_die_list. */
16447 if (flag_eliminate_dwarf2_dups
)
16448 break_out_includes (comp_unit_die
);
16450 /* Traverse the DIE's and add add sibling attributes to those DIE's
16451 that have children. */
16452 add_sibling_attributes (comp_unit_die
);
16453 for (node
= limbo_die_list
; node
; node
= node
->next
)
16454 add_sibling_attributes (node
->die
);
16456 /* Output a terminator label for the .text section. */
16457 switch_to_section (text_section
);
16458 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
16459 if (flag_reorder_blocks_and_partition
)
16461 switch_to_section (unlikely_text_section ());
16462 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
16465 /* We can only use the low/high_pc attributes if all of the code was
16467 if (!have_multiple_function_sections
)
16469 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
16470 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
16475 unsigned fde_idx
= 0;
16477 /* We need to give .debug_loc and .debug_ranges an appropriate
16478 "base address". Use zero so that these addresses become
16479 absolute. Historically, we've emitted the unexpected
16480 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16481 Emit both to give time for other tools to adapt. */
16482 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
16483 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
16485 add_AT_range_list (comp_unit_die
, DW_AT_ranges
,
16486 add_ranges_by_labels (text_section_label
,
16488 if (flag_reorder_blocks_and_partition
)
16489 add_ranges_by_labels (cold_text_section_label
,
16492 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
16494 dw_fde_ref fde
= &fde_table
[fde_idx
];
16496 if (fde
->dw_fde_switched_sections
)
16498 add_ranges_by_labels (fde
->dw_fde_hot_section_label
,
16499 fde
->dw_fde_hot_section_end_label
);
16500 add_ranges_by_labels (fde
->dw_fde_unlikely_section_label
,
16501 fde
->dw_fde_unlikely_section_end_label
);
16504 add_ranges_by_labels (fde
->dw_fde_begin
,
16511 /* Output location list section if necessary. */
16512 if (have_location_lists
)
16514 /* Output the location lists info. */
16515 switch_to_section (debug_loc_section
);
16516 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
16517 DEBUG_LOC_SECTION_LABEL
, 0);
16518 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
16519 output_location_lists (die
);
16522 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
16523 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
16524 debug_line_section_label
);
16526 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16527 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
16529 /* Output all of the compilation units. We put the main one last so that
16530 the offsets are available to output_pubnames. */
16531 for (node
= limbo_die_list
; node
; node
= node
->next
)
16532 output_comp_unit (node
->die
, 0);
16534 output_comp_unit (comp_unit_die
, 0);
16536 /* Output the abbreviation table. */
16537 switch_to_section (debug_abbrev_section
);
16538 output_abbrev_section ();
16540 /* Output public names table if necessary. */
16541 if (!VEC_empty (pubname_entry
, pubname_table
))
16543 switch_to_section (debug_pubnames_section
);
16544 output_pubnames (pubname_table
);
16547 #ifdef DEBUG_PUBTYPES_SECTION
16548 /* Output public types table if necessary. */
16549 if (!VEC_empty (pubname_entry
, pubtype_table
))
16551 switch_to_section (debug_pubtypes_section
);
16552 output_pubnames (pubtype_table
);
16556 /* Output the address range information. We only put functions in the arange
16557 table, so don't write it out if we don't have any. */
16558 if (fde_table_in_use
)
16560 switch_to_section (debug_aranges_section
);
16564 /* Output ranges section if necessary. */
16565 if (ranges_table_in_use
)
16567 switch_to_section (debug_ranges_section
);
16568 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
16572 /* Output the source line correspondence table. We must do this
16573 even if there is no line information. Otherwise, on an empty
16574 translation unit, we will generate a present, but empty,
16575 .debug_info section. IRIX 6.5 `nm' will then complain when
16576 examining the file. This is done late so that any filenames
16577 used by the debug_info section are marked as 'used'. */
16578 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
16580 switch_to_section (debug_line_section
);
16581 output_line_info ();
16584 /* Have to end the macro section. */
16585 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16587 switch_to_section (debug_macinfo_section
);
16588 dw2_asm_output_data (1, 0, "End compilation unit");
16591 /* If we emitted any DW_FORM_strp form attribute, output the string
16593 if (debug_str_hash
)
16594 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
16598 /* This should never be used, but its address is needed for comparisons. */
16599 const struct gcc_debug_hooks dwarf2_debug_hooks
;
16601 #endif /* DWARF2_DEBUGGING_INFO */
16603 #include "gt-dwarf2out.h"