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, 2009 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 /* Save the result of dwarf2out_do_frame across PCH. */
114 static GTY(()) bool saved_do_cfi_asm
= 0;
116 /* Decide whether we want to emit frame unwind information for the current
120 dwarf2out_do_frame (void)
122 /* We want to emit correct CFA location expressions or lists, so we
123 have to return true if we're going to output debug info, even if
124 we're not going to output frame or unwind info. */
125 return (write_symbols
== DWARF2_DEBUG
126 || write_symbols
== VMS_AND_DWARF2_DEBUG
127 || DWARF2_FRAME_INFO
|| saved_do_cfi_asm
128 #ifdef DWARF2_UNWIND_INFO
129 || (DWARF2_UNWIND_INFO
130 && (flag_unwind_tables
131 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
136 /* Decide whether to emit frame unwind via assembler directives. */
139 dwarf2out_do_cfi_asm (void)
143 #ifdef MIPS_DEBUGGING_INFO
146 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
148 if (saved_do_cfi_asm
|| !eh_personality_libfunc
)
150 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
153 /* Make sure the personality encoding is one the assembler can support.
154 In particular, aligned addresses can't be handled. */
155 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
156 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
158 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
159 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
162 saved_do_cfi_asm
= true;
166 /* The size of the target's pointer type. */
168 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
171 /* Array of RTXes referenced by the debugging information, which therefore
172 must be kept around forever. */
173 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
175 /* A pointer to the base of a list of incomplete types which might be
176 completed at some later time. incomplete_types_list needs to be a
177 VEC(tree,gc) because we want to tell the garbage collector about
179 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
181 /* A pointer to the base of a table of references to declaration
182 scopes. This table is a display which tracks the nesting
183 of declaration scopes at the current scope and containing
184 scopes. This table is used to find the proper place to
185 define type declaration DIE's. */
186 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
188 /* Pointers to various DWARF2 sections. */
189 static GTY(()) section
*debug_info_section
;
190 static GTY(()) section
*debug_abbrev_section
;
191 static GTY(()) section
*debug_aranges_section
;
192 static GTY(()) section
*debug_macinfo_section
;
193 static GTY(()) section
*debug_line_section
;
194 static GTY(()) section
*debug_loc_section
;
195 static GTY(()) section
*debug_pubnames_section
;
196 static GTY(()) section
*debug_pubtypes_section
;
197 static GTY(()) section
*debug_str_section
;
198 static GTY(()) section
*debug_ranges_section
;
199 static GTY(()) section
*debug_frame_section
;
201 /* How to start an assembler comment. */
202 #ifndef ASM_COMMENT_START
203 #define ASM_COMMENT_START ";#"
206 typedef struct dw_cfi_struct
*dw_cfi_ref
;
207 typedef struct dw_fde_struct
*dw_fde_ref
;
208 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
210 /* Call frames are described using a sequence of Call Frame
211 Information instructions. The register number, offset
212 and address fields are provided as possible operands;
213 their use is selected by the opcode field. */
215 enum dw_cfi_oprnd_type
{
217 dw_cfi_oprnd_reg_num
,
223 typedef union GTY(()) dw_cfi_oprnd_struct
{
224 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
225 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
226 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
227 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
231 typedef struct GTY(()) dw_cfi_struct
{
232 dw_cfi_ref dw_cfi_next
;
233 enum dwarf_call_frame_info dw_cfi_opc
;
234 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
236 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
241 /* This is how we define the location of the CFA. We use to handle it
242 as REG + OFFSET all the time, but now it can be more complex.
243 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
244 Instead of passing around REG and OFFSET, we pass a copy
245 of this structure. */
246 typedef struct GTY(()) cfa_loc
{
247 HOST_WIDE_INT offset
;
248 HOST_WIDE_INT base_offset
;
250 int indirect
; /* 1 if CFA is accessed via a dereference. */
253 /* All call frame descriptions (FDE's) in the GCC generated DWARF
254 refer to a single Common Information Entry (CIE), defined at
255 the beginning of the .debug_frame section. This use of a single
256 CIE obviates the need to keep track of multiple CIE's
257 in the DWARF generation routines below. */
259 typedef struct GTY(()) dw_fde_struct
{
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 GTY(()) indirect_string_node
{
377 unsigned int refcount
;
378 enum dwarf_form form
;
382 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
384 static GTY(()) int dw2_string_counter
;
385 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
387 /* True if the compilation unit places functions in more than one section. */
388 static GTY(()) bool have_multiple_function_sections
= false;
390 /* Whether the default text and cold text sections have been used at all. */
392 static GTY(()) bool text_section_used
= false;
393 static GTY(()) bool cold_text_section_used
= false;
395 /* The default cold text section. */
396 static GTY(()) section
*cold_text_section
;
398 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
400 /* Forward declarations for functions defined in this file. */
402 static char *stripattributes (const char *);
403 static const char *dwarf_cfi_name (unsigned);
404 static dw_cfi_ref
new_cfi (void);
405 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
406 static void add_fde_cfi (const char *, dw_cfi_ref
);
407 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
408 static void lookup_cfa (dw_cfa_location
*);
409 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
410 #ifdef DWARF2_UNWIND_INFO
411 static void initial_return_save (rtx
);
413 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
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
, HOST_WIDE_INT cur_args_size
,
1114 HOST_WIDE_INT cur_offset
)
1116 const_rtx src
= SET_SRC (pattern
);
1117 const_rtx dest
= SET_DEST (pattern
);
1118 HOST_WIDE_INT offset
= 0;
1121 if (dest
== stack_pointer_rtx
)
1123 code
= GET_CODE (src
);
1125 /* Assume (set (reg sp) (reg whatever)) sets args_size
1127 if (code
== REG
&& src
!= stack_pointer_rtx
)
1129 offset
= -cur_args_size
;
1130 #ifndef STACK_GROWS_DOWNWARD
1133 return offset
- cur_offset
;
1136 if (! (code
== PLUS
|| code
== MINUS
)
1137 || XEXP (src
, 0) != stack_pointer_rtx
1138 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1141 /* (set (reg sp) (plus (reg sp) (const_int))) */
1142 offset
= INTVAL (XEXP (src
, 1));
1148 if (MEM_P (src
) && !MEM_P (dest
))
1152 /* (set (mem (pre_dec (reg sp))) (foo)) */
1153 src
= XEXP (dest
, 0);
1154 code
= GET_CODE (src
);
1160 if (XEXP (src
, 0) == stack_pointer_rtx
)
1162 rtx val
= XEXP (XEXP (src
, 1), 1);
1163 /* We handle only adjustments by constant amount. */
1164 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1165 && GET_CODE (val
) == CONST_INT
);
1166 offset
= -INTVAL (val
);
1173 if (XEXP (src
, 0) == stack_pointer_rtx
)
1175 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1182 if (XEXP (src
, 0) == stack_pointer_rtx
)
1184 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1199 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1200 indexed by INSN_UID. */
1202 static HOST_WIDE_INT
*barrier_args_size
;
1204 /* Helper function for compute_barrier_args_size. Handle one insn. */
1206 static HOST_WIDE_INT
1207 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1208 VEC (rtx
, heap
) **next
)
1210 HOST_WIDE_INT offset
= 0;
1213 if (! RTX_FRAME_RELATED_P (insn
))
1215 if (prologue_epilogue_contains (insn
)
1216 || sibcall_epilogue_contains (insn
))
1218 else if (GET_CODE (PATTERN (insn
)) == SET
)
1219 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1220 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1221 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1223 /* There may be stack adjustments inside compound insns. Search
1225 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1226 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1227 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1228 cur_args_size
, offset
);
1233 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1237 expr
= XEXP (expr
, 0);
1238 if (GET_CODE (expr
) == PARALLEL
1239 || GET_CODE (expr
) == SEQUENCE
)
1240 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1242 rtx elem
= XVECEXP (expr
, 0, i
);
1244 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1245 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1250 #ifndef STACK_GROWS_DOWNWARD
1254 cur_args_size
+= offset
;
1255 if (cur_args_size
< 0)
1260 rtx dest
= JUMP_LABEL (insn
);
1264 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1266 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1267 VEC_safe_push (rtx
, heap
, *next
, dest
);
1272 return cur_args_size
;
1275 /* Walk the whole function and compute args_size on BARRIERs. */
1278 compute_barrier_args_size (void)
1280 int max_uid
= get_max_uid (), i
;
1282 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1284 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1285 for (i
= 0; i
< max_uid
; i
++)
1286 barrier_args_size
[i
] = -1;
1288 worklist
= VEC_alloc (rtx
, heap
, 20);
1289 next
= VEC_alloc (rtx
, heap
, 20);
1290 insn
= get_insns ();
1291 barrier_args_size
[INSN_UID (insn
)] = 0;
1292 VEC_quick_push (rtx
, worklist
, insn
);
1295 while (!VEC_empty (rtx
, worklist
))
1297 rtx prev
, body
, first_insn
;
1298 HOST_WIDE_INT cur_args_size
;
1300 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1301 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1302 prev
= prev_nonnote_insn (insn
);
1303 if (prev
&& BARRIER_P (prev
))
1304 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1306 for (; insn
; insn
= NEXT_INSN (insn
))
1308 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1310 if (BARRIER_P (insn
))
1315 if (insn
== first_insn
)
1317 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1319 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1324 /* The insns starting with this label have been
1325 already scanned or are in the worklist. */
1330 body
= PATTERN (insn
);
1331 if (GET_CODE (body
) == SEQUENCE
)
1333 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1334 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1335 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1336 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1338 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1339 dest_args_size
, &next
);
1342 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1343 cur_args_size
, &next
);
1345 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1346 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1347 dest_args_size
, &next
);
1350 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1351 cur_args_size
, &next
);
1355 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1359 if (VEC_empty (rtx
, next
))
1362 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1366 VEC_truncate (rtx
, next
, 0);
1369 VEC_free (rtx
, heap
, worklist
);
1370 VEC_free (rtx
, heap
, next
);
1374 /* Check INSN to see if it looks like a push or a stack adjustment, and
1375 make a note of it if it does. EH uses this information to find out how
1376 much extra space it needs to pop off the stack. */
1379 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1381 HOST_WIDE_INT offset
;
1385 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1386 with this function. Proper support would require all frame-related
1387 insns to be marked, and to be able to handle saving state around
1388 epilogues textually in the middle of the function. */
1389 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1392 /* If INSN is an instruction from target of an annulled branch, the
1393 effects are for the target only and so current argument size
1394 shouldn't change at all. */
1396 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1397 && INSN_FROM_TARGET_P (insn
))
1400 /* If only calls can throw, and we have a frame pointer,
1401 save up adjustments until we see the CALL_INSN. */
1402 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1404 if (CALL_P (insn
) && !after_p
)
1406 /* Extract the size of the args from the CALL rtx itself. */
1407 insn
= PATTERN (insn
);
1408 if (GET_CODE (insn
) == PARALLEL
)
1409 insn
= XVECEXP (insn
, 0, 0);
1410 if (GET_CODE (insn
) == SET
)
1411 insn
= SET_SRC (insn
);
1412 gcc_assert (GET_CODE (insn
) == CALL
);
1413 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1418 if (CALL_P (insn
) && !after_p
)
1420 if (!flag_asynchronous_unwind_tables
)
1421 dwarf2out_args_size ("", args_size
);
1424 else if (BARRIER_P (insn
))
1426 /* Don't call compute_barrier_args_size () if the only
1427 BARRIER is at the end of function. */
1428 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1429 compute_barrier_args_size ();
1430 if (barrier_args_size
== NULL
)
1434 offset
= barrier_args_size
[INSN_UID (insn
)];
1439 offset
-= args_size
;
1440 #ifndef STACK_GROWS_DOWNWARD
1444 else if (GET_CODE (PATTERN (insn
)) == SET
)
1445 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1446 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1447 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1449 /* There may be stack adjustments inside compound insns. Search
1451 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1452 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1453 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1462 label
= dwarf2out_cfi_label ();
1463 dwarf2out_args_size_adjust (offset
, label
);
1466 /* Adjust args_size based on stack adjustment OFFSET. */
1469 dwarf2out_args_size_adjust (HOST_WIDE_INT offset
, const char *label
)
1471 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1472 cfa
.offset
+= offset
;
1474 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1475 cfa_store
.offset
+= offset
;
1477 #ifndef STACK_GROWS_DOWNWARD
1481 args_size
+= offset
;
1485 def_cfa_1 (label
, &cfa
);
1486 if (flag_asynchronous_unwind_tables
)
1487 dwarf2out_args_size (label
, args_size
);
1492 /* We delay emitting a register save until either (a) we reach the end
1493 of the prologue or (b) the register is clobbered. This clusters
1494 register saves so that there are fewer pc advances. */
1496 struct GTY(()) queued_reg_save
{
1497 struct queued_reg_save
*next
;
1499 HOST_WIDE_INT cfa_offset
;
1503 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1505 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1506 struct GTY(()) reg_saved_in_data
{
1511 /* A list of registers saved in other registers.
1512 The list intentionally has a small maximum capacity of 4; if your
1513 port needs more than that, you might consider implementing a
1514 more efficient data structure. */
1515 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1516 static GTY(()) size_t num_regs_saved_in_regs
;
1518 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1519 static const char *last_reg_save_label
;
1521 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1522 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1525 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1527 struct queued_reg_save
*q
;
1529 /* Duplicates waste space, but it's also necessary to remove them
1530 for correctness, since the queue gets output in reverse
1532 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1533 if (REGNO (q
->reg
) == REGNO (reg
))
1538 q
= GGC_NEW (struct queued_reg_save
);
1539 q
->next
= queued_reg_saves
;
1540 queued_reg_saves
= q
;
1544 q
->cfa_offset
= offset
;
1545 q
->saved_reg
= sreg
;
1547 last_reg_save_label
= label
;
1550 /* Output all the entries in QUEUED_REG_SAVES. */
1553 flush_queued_reg_saves (void)
1555 struct queued_reg_save
*q
;
1557 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1560 unsigned int reg
, sreg
;
1562 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1563 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1565 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1567 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1568 num_regs_saved_in_regs
++;
1570 if (i
!= num_regs_saved_in_regs
)
1572 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1573 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1576 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1578 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1580 sreg
= INVALID_REGNUM
;
1581 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1584 queued_reg_saves
= NULL
;
1585 last_reg_save_label
= NULL
;
1588 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1589 location for? Or, does it clobber a register which we've previously
1590 said that some other register is saved in, and for which we now
1591 have a new location for? */
1594 clobbers_queued_reg_save (const_rtx insn
)
1596 struct queued_reg_save
*q
;
1598 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1601 if (modified_in_p (q
->reg
, insn
))
1603 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1604 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1605 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1612 /* Entry point for saving the first register into the second. */
1615 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1618 unsigned int regno
, sregno
;
1620 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1621 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1623 if (i
== num_regs_saved_in_regs
)
1625 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1626 num_regs_saved_in_regs
++;
1628 regs_saved_in_regs
[i
].orig_reg
= reg
;
1629 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1631 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1632 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1633 reg_save (label
, regno
, sregno
, 0);
1636 /* What register, if any, is currently saved in REG? */
1639 reg_saved_in (rtx reg
)
1641 unsigned int regn
= REGNO (reg
);
1643 struct queued_reg_save
*q
;
1645 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1646 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1649 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1650 if (regs_saved_in_regs
[i
].saved_in_reg
1651 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1652 return regs_saved_in_regs
[i
].orig_reg
;
1658 /* A temporary register holding an integral value used in adjusting SP
1659 or setting up the store_reg. The "offset" field holds the integer
1660 value, not an offset. */
1661 static dw_cfa_location cfa_temp
;
1663 /* Record call frame debugging information for an expression EXPR,
1664 which either sets SP or FP (adjusting how we calculate the frame
1665 address) or saves a register to the stack or another register.
1666 LABEL indicates the address of EXPR.
1668 This function encodes a state machine mapping rtxes to actions on
1669 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1670 users need not read the source code.
1672 The High-Level Picture
1674 Changes in the register we use to calculate the CFA: Currently we
1675 assume that if you copy the CFA register into another register, we
1676 should take the other one as the new CFA register; this seems to
1677 work pretty well. If it's wrong for some target, it's simple
1678 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1680 Changes in the register we use for saving registers to the stack:
1681 This is usually SP, but not always. Again, we deduce that if you
1682 copy SP into another register (and SP is not the CFA register),
1683 then the new register is the one we will be using for register
1684 saves. This also seems to work.
1686 Register saves: There's not much guesswork about this one; if
1687 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1688 register save, and the register used to calculate the destination
1689 had better be the one we think we're using for this purpose.
1690 It's also assumed that a copy from a call-saved register to another
1691 register is saving that register if RTX_FRAME_RELATED_P is set on
1692 that instruction. If the copy is from a call-saved register to
1693 the *same* register, that means that the register is now the same
1694 value as in the caller.
1696 Except: If the register being saved is the CFA register, and the
1697 offset is nonzero, we are saving the CFA, so we assume we have to
1698 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1699 the intent is to save the value of SP from the previous frame.
1701 In addition, if a register has previously been saved to a different
1704 Invariants / Summaries of Rules
1706 cfa current rule for calculating the CFA. It usually
1707 consists of a register and an offset.
1708 cfa_store register used by prologue code to save things to the stack
1709 cfa_store.offset is the offset from the value of
1710 cfa_store.reg to the actual CFA
1711 cfa_temp register holding an integral value. cfa_temp.offset
1712 stores the value, which will be used to adjust the
1713 stack pointer. cfa_temp is also used like cfa_store,
1714 to track stores to the stack via fp or a temp reg.
1716 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1717 with cfa.reg as the first operand changes the cfa.reg and its
1718 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1721 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1722 expression yielding a constant. This sets cfa_temp.reg
1723 and cfa_temp.offset.
1725 Rule 5: Create a new register cfa_store used to save items to the
1728 Rules 10-14: Save a register to the stack. Define offset as the
1729 difference of the original location and cfa_store's
1730 location (or cfa_temp's location if cfa_temp is used).
1732 Rules 16-20: If AND operation happens on sp in prologue, we assume
1733 stack is realigned. We will use a group of DW_OP_XXX
1734 expressions to represent the location of the stored
1735 register instead of CFA+offset.
1739 "{a,b}" indicates a choice of a xor b.
1740 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1743 (set <reg1> <reg2>:cfa.reg)
1744 effects: cfa.reg = <reg1>
1745 cfa.offset unchanged
1746 cfa_temp.reg = <reg1>
1747 cfa_temp.offset = cfa.offset
1750 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1751 {<const_int>,<reg>:cfa_temp.reg}))
1752 effects: cfa.reg = sp if fp used
1753 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1754 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1755 if cfa_store.reg==sp
1758 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1759 effects: cfa.reg = fp
1760 cfa_offset += +/- <const_int>
1763 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1764 constraints: <reg1> != fp
1766 effects: cfa.reg = <reg1>
1767 cfa_temp.reg = <reg1>
1768 cfa_temp.offset = cfa.offset
1771 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1772 constraints: <reg1> != fp
1774 effects: cfa_store.reg = <reg1>
1775 cfa_store.offset = cfa.offset - cfa_temp.offset
1778 (set <reg> <const_int>)
1779 effects: cfa_temp.reg = <reg>
1780 cfa_temp.offset = <const_int>
1783 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1784 effects: cfa_temp.reg = <reg1>
1785 cfa_temp.offset |= <const_int>
1788 (set <reg> (high <exp>))
1792 (set <reg> (lo_sum <exp> <const_int>))
1793 effects: cfa_temp.reg = <reg>
1794 cfa_temp.offset = <const_int>
1797 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1798 effects: cfa_store.offset -= <const_int>
1799 cfa.offset = cfa_store.offset if cfa.reg == sp
1801 cfa.base_offset = -cfa_store.offset
1804 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1805 effects: cfa_store.offset += -/+ mode_size(mem)
1806 cfa.offset = cfa_store.offset if cfa.reg == sp
1808 cfa.base_offset = -cfa_store.offset
1811 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1814 effects: cfa.reg = <reg1>
1815 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1818 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1819 effects: cfa.reg = <reg1>
1820 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1823 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1824 effects: cfa.reg = <reg1>
1825 cfa.base_offset = -cfa_temp.offset
1826 cfa_temp.offset -= mode_size(mem)
1829 (set <reg> {unspec, unspec_volatile})
1830 effects: target-dependent
1833 (set sp (and: sp <const_int>))
1834 constraints: cfa_store.reg == sp
1835 effects: current_fde.stack_realign = 1
1836 cfa_store.offset = 0
1837 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1840 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1841 effects: cfa_store.offset += -/+ mode_size(mem)
1844 (set (mem ({pre_inc, pre_dec} sp)) fp)
1845 constraints: fde->stack_realign == 1
1846 effects: cfa_store.offset = 0
1847 cfa.reg != HARD_FRAME_POINTER_REGNUM
1850 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1851 constraints: fde->stack_realign == 1
1853 && cfa.indirect == 0
1854 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1855 effects: Use DW_CFA_def_cfa_expression to define cfa
1856 cfa.reg == fde->drap_reg
1859 (set reg fde->drap_reg)
1860 constraints: fde->vdrap_reg == INVALID_REGNUM
1861 effects: fde->vdrap_reg = reg.
1862 (set mem fde->drap_reg)
1863 constraints: fde->drap_reg_saved == 1
1867 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1869 rtx src
, dest
, span
;
1870 HOST_WIDE_INT offset
;
1873 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1874 the PARALLEL independently. The first element is always processed if
1875 it is a SET. This is for backward compatibility. Other elements
1876 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1877 flag is set in them. */
1878 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1881 int limit
= XVECLEN (expr
, 0);
1884 /* PARALLELs have strict read-modify-write semantics, so we
1885 ought to evaluate every rvalue before changing any lvalue.
1886 It's cumbersome to do that in general, but there's an
1887 easy approximation that is enough for all current users:
1888 handle register saves before register assignments. */
1889 if (GET_CODE (expr
) == PARALLEL
)
1890 for (par_index
= 0; par_index
< limit
; par_index
++)
1892 elem
= XVECEXP (expr
, 0, par_index
);
1893 if (GET_CODE (elem
) == SET
1894 && MEM_P (SET_DEST (elem
))
1895 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1896 dwarf2out_frame_debug_expr (elem
, label
);
1899 for (par_index
= 0; par_index
< limit
; par_index
++)
1901 elem
= XVECEXP (expr
, 0, par_index
);
1902 if (GET_CODE (elem
) == SET
1903 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1904 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1905 dwarf2out_frame_debug_expr (elem
, label
);
1906 else if (GET_CODE (elem
) == SET
1908 && !RTX_FRAME_RELATED_P (elem
))
1910 /* Stack adjustment combining might combine some post-prologue
1911 stack adjustment into a prologue stack adjustment. */
1912 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
1915 dwarf2out_args_size_adjust (offset
, label
);
1921 gcc_assert (GET_CODE (expr
) == SET
);
1923 src
= SET_SRC (expr
);
1924 dest
= SET_DEST (expr
);
1928 rtx rsi
= reg_saved_in (src
);
1933 fde
= current_fde ();
1935 if (GET_CODE (src
) == REG
1937 && fde
->drap_reg
== REGNO (src
)
1938 && (fde
->drap_reg_saved
1939 || GET_CODE (dest
) == REG
))
1942 /* If we are saving dynamic realign argument pointer to a
1943 register, the destination is virtual dynamic realign
1944 argument pointer. It may be used to access argument. */
1945 if (GET_CODE (dest
) == REG
)
1947 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
1948 fde
->vdrap_reg
= REGNO (dest
);
1953 switch (GET_CODE (dest
))
1956 switch (GET_CODE (src
))
1958 /* Setting FP from SP. */
1960 if (cfa
.reg
== (unsigned) REGNO (src
))
1963 /* Update the CFA rule wrt SP or FP. Make sure src is
1964 relative to the current CFA register.
1966 We used to require that dest be either SP or FP, but the
1967 ARM copies SP to a temporary register, and from there to
1968 FP. So we just rely on the backends to only set
1969 RTX_FRAME_RELATED_P on appropriate insns. */
1970 cfa
.reg
= REGNO (dest
);
1971 cfa_temp
.reg
= cfa
.reg
;
1972 cfa_temp
.offset
= cfa
.offset
;
1976 /* Saving a register in a register. */
1977 gcc_assert (!fixed_regs
[REGNO (dest
)]
1978 /* For the SPARC and its register window. */
1979 || (DWARF_FRAME_REGNUM (REGNO (src
))
1980 == DWARF_FRAME_RETURN_COLUMN
));
1982 /* After stack is aligned, we can only save SP in FP
1983 if drap register is used. In this case, we have
1984 to restore stack pointer with the CFA value and we
1985 don't generate this DWARF information. */
1987 && fde
->stack_realign
1988 && REGNO (src
) == STACK_POINTER_REGNUM
)
1989 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
1990 && fde
->drap_reg
!= INVALID_REGNUM
1991 && cfa
.reg
!= REGNO (src
));
1993 queue_reg_save (label
, src
, dest
, 0);
2000 if (dest
== stack_pointer_rtx
)
2004 switch (GET_CODE (XEXP (src
, 1)))
2007 offset
= INTVAL (XEXP (src
, 1));
2010 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2012 offset
= cfa_temp
.offset
;
2018 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2020 /* Restoring SP from FP in the epilogue. */
2021 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2022 cfa
.reg
= STACK_POINTER_REGNUM
;
2024 else if (GET_CODE (src
) == LO_SUM
)
2025 /* Assume we've set the source reg of the LO_SUM from sp. */
2028 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2030 if (GET_CODE (src
) != MINUS
)
2032 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2033 cfa
.offset
+= offset
;
2034 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2035 cfa_store
.offset
+= offset
;
2037 else if (dest
== hard_frame_pointer_rtx
)
2040 /* Either setting the FP from an offset of the SP,
2041 or adjusting the FP */
2042 gcc_assert (frame_pointer_needed
);
2044 gcc_assert (REG_P (XEXP (src
, 0))
2045 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2046 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
2047 offset
= INTVAL (XEXP (src
, 1));
2048 if (GET_CODE (src
) != MINUS
)
2050 cfa
.offset
+= offset
;
2051 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2055 gcc_assert (GET_CODE (src
) != MINUS
);
2058 if (REG_P (XEXP (src
, 0))
2059 && REGNO (XEXP (src
, 0)) == cfa
.reg
2060 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2062 /* Setting a temporary CFA register that will be copied
2063 into the FP later on. */
2064 offset
= - INTVAL (XEXP (src
, 1));
2065 cfa
.offset
+= offset
;
2066 cfa
.reg
= REGNO (dest
);
2067 /* Or used to save regs to the stack. */
2068 cfa_temp
.reg
= cfa
.reg
;
2069 cfa_temp
.offset
= cfa
.offset
;
2073 else if (REG_P (XEXP (src
, 0))
2074 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2075 && XEXP (src
, 1) == stack_pointer_rtx
)
2077 /* Setting a scratch register that we will use instead
2078 of SP for saving registers to the stack. */
2079 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2080 cfa_store
.reg
= REGNO (dest
);
2081 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2085 else if (GET_CODE (src
) == LO_SUM
2086 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2088 cfa_temp
.reg
= REGNO (dest
);
2089 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2098 cfa_temp
.reg
= REGNO (dest
);
2099 cfa_temp
.offset
= INTVAL (src
);
2104 gcc_assert (REG_P (XEXP (src
, 0))
2105 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2106 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
2108 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2109 cfa_temp
.reg
= REGNO (dest
);
2110 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2113 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2114 which will fill in all of the bits. */
2121 case UNSPEC_VOLATILE
:
2122 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2123 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2128 /* If this AND operation happens on stack pointer in prologue,
2129 we assume the stack is realigned and we extract the
2131 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2133 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2134 fde
->stack_realign
= 1;
2135 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2136 cfa_store
.offset
= 0;
2138 if (cfa
.reg
!= STACK_POINTER_REGNUM
2139 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2140 fde
->drap_reg
= cfa
.reg
;
2148 def_cfa_1 (label
, &cfa
);
2153 /* Saving a register to the stack. Make sure dest is relative to the
2155 switch (GET_CODE (XEXP (dest
, 0)))
2160 /* We can't handle variable size modifications. */
2161 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2163 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2165 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2166 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2168 cfa_store
.offset
+= offset
;
2169 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2170 cfa
.offset
= cfa_store
.offset
;
2172 offset
= -cfa_store
.offset
;
2178 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2179 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2182 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2183 == STACK_POINTER_REGNUM
)
2184 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2186 cfa_store
.offset
+= offset
;
2188 /* Rule 18: If stack is aligned, we will use FP as a
2189 reference to represent the address of the stored
2192 && fde
->stack_realign
2193 && src
== hard_frame_pointer_rtx
)
2195 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2196 cfa_store
.offset
= 0;
2199 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2200 cfa
.offset
= cfa_store
.offset
;
2202 offset
= -cfa_store
.offset
;
2206 /* With an offset. */
2213 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
2214 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2215 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2216 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2219 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2221 if (cfa_store
.reg
== (unsigned) regno
)
2222 offset
-= cfa_store
.offset
;
2225 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2226 offset
-= cfa_temp
.offset
;
2232 /* Without an offset. */
2235 int regno
= REGNO (XEXP (dest
, 0));
2237 if (cfa_store
.reg
== (unsigned) regno
)
2238 offset
= -cfa_store
.offset
;
2241 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2242 offset
= -cfa_temp
.offset
;
2249 gcc_assert (cfa_temp
.reg
2250 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2251 offset
= -cfa_temp
.offset
;
2252 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2260 /* If the source operand of this MEM operation is not a
2261 register, basically the source is return address. Here
2262 we only care how much stack grew and we don't save it. */
2266 if (REGNO (src
) != STACK_POINTER_REGNUM
2267 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2268 && (unsigned) REGNO (src
) == cfa
.reg
)
2270 /* We're storing the current CFA reg into the stack. */
2272 if (cfa
.offset
== 0)
2275 /* If stack is aligned, putting CFA reg into stack means
2276 we can no longer use reg + offset to represent CFA.
2277 Here we use DW_CFA_def_cfa_expression instead. The
2278 result of this expression equals to the original CFA
2281 && fde
->stack_realign
2282 && cfa
.indirect
== 0
2283 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2285 dw_cfa_location cfa_exp
;
2287 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2289 cfa_exp
.indirect
= 1;
2290 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2291 cfa_exp
.base_offset
= offset
;
2294 fde
->drap_reg_saved
= 1;
2296 def_cfa_1 (label
, &cfa_exp
);
2300 /* If the source register is exactly the CFA, assume
2301 we're saving SP like any other register; this happens
2303 def_cfa_1 (label
, &cfa
);
2304 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2309 /* Otherwise, we'll need to look in the stack to
2310 calculate the CFA. */
2311 rtx x
= XEXP (dest
, 0);
2315 gcc_assert (REG_P (x
));
2317 cfa
.reg
= REGNO (x
);
2318 cfa
.base_offset
= offset
;
2320 def_cfa_1 (label
, &cfa
);
2325 def_cfa_1 (label
, &cfa
);
2327 span
= targetm
.dwarf_register_span (src
);
2330 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2333 /* We have a PARALLEL describing where the contents of SRC
2334 live. Queue register saves for each piece of the
2338 HOST_WIDE_INT span_offset
= offset
;
2340 gcc_assert (GET_CODE (span
) == PARALLEL
);
2342 limit
= XVECLEN (span
, 0);
2343 for (par_index
= 0; par_index
< limit
; par_index
++)
2345 rtx elem
= XVECEXP (span
, 0, par_index
);
2347 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2348 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2359 /* Record call frame debugging information for INSN, which either
2360 sets SP or FP (adjusting how we calculate the frame address) or saves a
2361 register to the stack. If INSN is NULL_RTX, initialize our state.
2363 If AFTER_P is false, we're being called before the insn is emitted,
2364 otherwise after. Call instructions get invoked twice. */
2367 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2372 if (insn
== NULL_RTX
)
2376 /* Flush any queued register saves. */
2377 flush_queued_reg_saves ();
2379 /* Set up state for generating call frame debug info. */
2382 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2384 cfa
.reg
= STACK_POINTER_REGNUM
;
2387 cfa_temp
.offset
= 0;
2389 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2391 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2392 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2394 num_regs_saved_in_regs
= 0;
2396 if (barrier_args_size
)
2398 XDELETEVEC (barrier_args_size
);
2399 barrier_args_size
= NULL
;
2404 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2405 flush_queued_reg_saves ();
2407 if (! RTX_FRAME_RELATED_P (insn
))
2409 if (!ACCUMULATE_OUTGOING_ARGS
)
2410 dwarf2out_stack_adjust (insn
, after_p
);
2414 label
= dwarf2out_cfi_label ();
2415 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
2417 insn
= XEXP (src
, 0);
2419 insn
= PATTERN (insn
);
2421 dwarf2out_frame_debug_expr (insn
, label
);
2426 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2427 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2428 (enum dwarf_call_frame_info cfi
);
2430 static enum dw_cfi_oprnd_type
2431 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2436 case DW_CFA_GNU_window_save
:
2437 return dw_cfi_oprnd_unused
;
2439 case DW_CFA_set_loc
:
2440 case DW_CFA_advance_loc1
:
2441 case DW_CFA_advance_loc2
:
2442 case DW_CFA_advance_loc4
:
2443 case DW_CFA_MIPS_advance_loc8
:
2444 return dw_cfi_oprnd_addr
;
2447 case DW_CFA_offset_extended
:
2448 case DW_CFA_def_cfa
:
2449 case DW_CFA_offset_extended_sf
:
2450 case DW_CFA_def_cfa_sf
:
2451 case DW_CFA_restore_extended
:
2452 case DW_CFA_undefined
:
2453 case DW_CFA_same_value
:
2454 case DW_CFA_def_cfa_register
:
2455 case DW_CFA_register
:
2456 return dw_cfi_oprnd_reg_num
;
2458 case DW_CFA_def_cfa_offset
:
2459 case DW_CFA_GNU_args_size
:
2460 case DW_CFA_def_cfa_offset_sf
:
2461 return dw_cfi_oprnd_offset
;
2463 case DW_CFA_def_cfa_expression
:
2464 case DW_CFA_expression
:
2465 return dw_cfi_oprnd_loc
;
2472 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2473 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2474 (enum dwarf_call_frame_info cfi
);
2476 static enum dw_cfi_oprnd_type
2477 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2481 case DW_CFA_def_cfa
:
2482 case DW_CFA_def_cfa_sf
:
2484 case DW_CFA_offset_extended_sf
:
2485 case DW_CFA_offset_extended
:
2486 return dw_cfi_oprnd_offset
;
2488 case DW_CFA_register
:
2489 return dw_cfi_oprnd_reg_num
;
2492 return dw_cfi_oprnd_unused
;
2496 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2498 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2499 switch to the data section instead, and write out a synthetic label
2503 switch_to_eh_frame_section (void)
2507 #ifdef EH_FRAME_SECTION_NAME
2508 if (eh_frame_section
== 0)
2512 if (EH_TABLES_CAN_BE_READ_ONLY
)
2518 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2520 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2522 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2524 flags
= ((! flag_pic
2525 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2526 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2527 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2528 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2529 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2530 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2531 ? 0 : SECTION_WRITE
);
2534 flags
= SECTION_WRITE
;
2535 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2539 if (eh_frame_section
)
2540 switch_to_section (eh_frame_section
);
2543 /* We have no special eh_frame section. Put the information in
2544 the data section and emit special labels to guide collect2. */
2545 switch_to_section (data_section
);
2546 label
= get_file_function_name ("F");
2547 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2548 targetm
.asm_out
.globalize_label (asm_out_file
,
2549 IDENTIFIER_POINTER (label
));
2550 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2554 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2556 static HOST_WIDE_INT
2557 div_data_align (HOST_WIDE_INT off
)
2559 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
2560 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
2564 /* Output a Call Frame Information opcode and its operand(s). */
2567 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2572 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2573 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2574 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2575 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2576 ((unsigned HOST_WIDE_INT
)
2577 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
2578 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2580 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2581 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2582 "DW_CFA_offset, column 0x%lx", r
);
2583 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2584 dw2_asm_output_data_uleb128 (off
, NULL
);
2586 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2588 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2589 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2590 "DW_CFA_restore, column 0x%lx", r
);
2594 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2595 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2597 switch (cfi
->dw_cfi_opc
)
2599 case DW_CFA_set_loc
:
2601 dw2_asm_output_encoded_addr_rtx (
2602 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2603 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2606 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2607 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2608 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2611 case DW_CFA_advance_loc1
:
2612 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2613 fde
->dw_fde_current_label
, NULL
);
2614 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2617 case DW_CFA_advance_loc2
:
2618 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2619 fde
->dw_fde_current_label
, NULL
);
2620 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2623 case DW_CFA_advance_loc4
:
2624 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2625 fde
->dw_fde_current_label
, NULL
);
2626 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2629 case DW_CFA_MIPS_advance_loc8
:
2630 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2631 fde
->dw_fde_current_label
, NULL
);
2632 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2635 case DW_CFA_offset_extended
:
2636 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2637 dw2_asm_output_data_uleb128 (r
, NULL
);
2638 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2639 dw2_asm_output_data_uleb128 (off
, NULL
);
2642 case DW_CFA_def_cfa
:
2643 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2644 dw2_asm_output_data_uleb128 (r
, NULL
);
2645 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2648 case DW_CFA_offset_extended_sf
:
2649 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2650 dw2_asm_output_data_uleb128 (r
, NULL
);
2651 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2652 dw2_asm_output_data_sleb128 (off
, NULL
);
2655 case DW_CFA_def_cfa_sf
:
2656 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2657 dw2_asm_output_data_uleb128 (r
, NULL
);
2658 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2659 dw2_asm_output_data_sleb128 (off
, NULL
);
2662 case DW_CFA_restore_extended
:
2663 case DW_CFA_undefined
:
2664 case DW_CFA_same_value
:
2665 case DW_CFA_def_cfa_register
:
2666 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2667 dw2_asm_output_data_uleb128 (r
, NULL
);
2670 case DW_CFA_register
:
2671 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2672 dw2_asm_output_data_uleb128 (r
, NULL
);
2673 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2674 dw2_asm_output_data_uleb128 (r
, NULL
);
2677 case DW_CFA_def_cfa_offset
:
2678 case DW_CFA_GNU_args_size
:
2679 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2682 case DW_CFA_def_cfa_offset_sf
:
2683 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2684 dw2_asm_output_data_sleb128 (off
, NULL
);
2687 case DW_CFA_GNU_window_save
:
2690 case DW_CFA_def_cfa_expression
:
2691 case DW_CFA_expression
:
2692 output_cfa_loc (cfi
);
2695 case DW_CFA_GNU_negative_offset_extended
:
2696 /* Obsoleted by DW_CFA_offset_extended_sf. */
2705 /* Similar, but do it via assembler directives instead. */
2708 output_cfi_directive (dw_cfi_ref cfi
)
2710 unsigned long r
, r2
;
2712 switch (cfi
->dw_cfi_opc
)
2714 case DW_CFA_advance_loc
:
2715 case DW_CFA_advance_loc1
:
2716 case DW_CFA_advance_loc2
:
2717 case DW_CFA_advance_loc4
:
2718 case DW_CFA_MIPS_advance_loc8
:
2719 case DW_CFA_set_loc
:
2720 /* Should only be created by add_fde_cfi in a code path not
2721 followed when emitting via directives. The assembler is
2722 going to take care of this for us. */
2726 case DW_CFA_offset_extended
:
2727 case DW_CFA_offset_extended_sf
:
2728 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2729 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
2730 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2733 case DW_CFA_restore
:
2734 case DW_CFA_restore_extended
:
2735 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2736 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
2739 case DW_CFA_undefined
:
2740 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2741 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
2744 case DW_CFA_same_value
:
2745 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2746 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
2749 case DW_CFA_def_cfa
:
2750 case DW_CFA_def_cfa_sf
:
2751 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2752 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
2753 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2756 case DW_CFA_def_cfa_register
:
2757 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2758 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
2761 case DW_CFA_register
:
2762 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 0);
2763 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 0);
2764 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
2767 case DW_CFA_def_cfa_offset
:
2768 case DW_CFA_def_cfa_offset_sf
:
2769 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
2770 HOST_WIDE_INT_PRINT_DEC
"\n",
2771 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2774 case DW_CFA_GNU_args_size
:
2775 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size
);
2776 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2778 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
2779 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2780 fputc ('\n', asm_out_file
);
2783 case DW_CFA_GNU_window_save
:
2784 fprintf (asm_out_file
, "\t.cfi_window_save\n");
2787 case DW_CFA_def_cfa_expression
:
2788 case DW_CFA_expression
:
2789 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", cfi
->dw_cfi_opc
);
2790 output_cfa_loc_raw (cfi
);
2791 fputc ('\n', asm_out_file
);
2799 /* Output the call frame information used to record information
2800 that relates to calculating the frame pointer, and records the
2801 location of saved registers. */
2804 output_call_frame_info (int for_eh
)
2809 char l1
[20], l2
[20], section_start_label
[20];
2810 bool any_lsda_needed
= false;
2811 char augmentation
[6];
2812 int augmentation_size
;
2813 int fde_encoding
= DW_EH_PE_absptr
;
2814 int per_encoding
= DW_EH_PE_absptr
;
2815 int lsda_encoding
= DW_EH_PE_absptr
;
2818 /* Don't emit a CIE if there won't be any FDEs. */
2819 if (fde_table_in_use
== 0)
2822 /* Nothing to do if the assembler's doing it all. */
2823 if (dwarf2out_do_cfi_asm ())
2826 /* If we make FDEs linkonce, we may have to emit an empty label for
2827 an FDE that wouldn't otherwise be emitted. We want to avoid
2828 having an FDE kept around when the function it refers to is
2829 discarded. Example where this matters: a primary function
2830 template in C++ requires EH information, but an explicit
2831 specialization doesn't. */
2832 if (TARGET_USES_WEAK_UNWIND_INFO
2833 && ! flag_asynchronous_unwind_tables
2836 for (i
= 0; i
< fde_table_in_use
; i
++)
2837 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2838 && !fde_table
[i
].uses_eh_lsda
2839 && ! DECL_WEAK (fde_table
[i
].decl
))
2840 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2841 for_eh
, /* empty */ 1);
2843 /* If we don't have any functions we'll want to unwind out of, don't
2844 emit any EH unwind information. Note that if exceptions aren't
2845 enabled, we won't have collected nothrow information, and if we
2846 asked for asynchronous tables, we always want this info. */
2849 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2851 for (i
= 0; i
< fde_table_in_use
; i
++)
2852 if (fde_table
[i
].uses_eh_lsda
)
2853 any_eh_needed
= any_lsda_needed
= true;
2854 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2855 any_eh_needed
= true;
2856 else if (! fde_table
[i
].nothrow
2857 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2858 any_eh_needed
= true;
2860 if (! any_eh_needed
)
2864 /* We're going to be generating comments, so turn on app. */
2869 switch_to_eh_frame_section ();
2872 if (!debug_frame_section
)
2873 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
2874 SECTION_DEBUG
, NULL
);
2875 switch_to_section (debug_frame_section
);
2878 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2879 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2881 /* Output the CIE. */
2882 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2883 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2884 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2885 dw2_asm_output_data (4, 0xffffffff,
2886 "Initial length escape value indicating 64-bit DWARF extension");
2887 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2888 "Length of Common Information Entry");
2889 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2891 /* Now that the CIE pointer is PC-relative for EH,
2892 use 0 to identify the CIE. */
2893 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2894 (for_eh
? 0 : DWARF_CIE_ID
),
2895 "CIE Identifier Tag");
2897 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2899 augmentation
[0] = 0;
2900 augmentation_size
= 0;
2906 z Indicates that a uleb128 is present to size the
2907 augmentation section.
2908 L Indicates the encoding (and thus presence) of
2909 an LSDA pointer in the FDE augmentation.
2910 R Indicates a non-default pointer encoding for
2912 P Indicates the presence of an encoding + language
2913 personality routine in the CIE augmentation. */
2915 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2916 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2917 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2919 p
= augmentation
+ 1;
2920 if (eh_personality_libfunc
)
2923 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2924 assemble_external_libcall (eh_personality_libfunc
);
2926 if (any_lsda_needed
)
2929 augmentation_size
+= 1;
2931 if (fde_encoding
!= DW_EH_PE_absptr
)
2934 augmentation_size
+= 1;
2936 if (p
> augmentation
+ 1)
2938 augmentation
[0] = 'z';
2942 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2943 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2945 int offset
= ( 4 /* Length */
2947 + 1 /* CIE version */
2948 + strlen (augmentation
) + 1 /* Augmentation */
2949 + size_of_uleb128 (1) /* Code alignment */
2950 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2952 + 1 /* Augmentation size */
2953 + 1 /* Personality encoding */ );
2954 int pad
= -offset
& (PTR_SIZE
- 1);
2956 augmentation_size
+= pad
;
2958 /* Augmentations should be small, so there's scarce need to
2959 iterate for a solution. Die if we exceed one uleb128 byte. */
2960 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2964 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2965 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2966 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2967 "CIE Data Alignment Factor");
2969 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2970 if (DW_CIE_VERSION
== 1)
2971 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2973 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2975 if (augmentation
[0])
2977 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2978 if (eh_personality_libfunc
)
2980 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2981 eh_data_format_name (per_encoding
));
2982 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2983 eh_personality_libfunc
,
2987 if (any_lsda_needed
)
2988 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2989 eh_data_format_name (lsda_encoding
));
2991 if (fde_encoding
!= DW_EH_PE_absptr
)
2992 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2993 eh_data_format_name (fde_encoding
));
2996 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2997 output_cfi (cfi
, NULL
, for_eh
);
2999 /* Pad the CIE out to an address sized boundary. */
3000 ASM_OUTPUT_ALIGN (asm_out_file
,
3001 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3002 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3004 /* Loop through all of the FDE's. */
3005 for (i
= 0; i
< fde_table_in_use
; i
++)
3007 fde
= &fde_table
[i
];
3009 /* Don't emit EH unwind info for leaf functions that don't need it. */
3010 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
3011 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
3012 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
3013 && !fde
->uses_eh_lsda
)
3016 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
3017 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
3018 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
3019 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
3020 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3021 dw2_asm_output_data (4, 0xffffffff,
3022 "Initial length escape value indicating 64-bit DWARF extension");
3023 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3025 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3028 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3030 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3031 debug_frame_section
, "FDE CIE offset");
3035 if (fde
->dw_fde_switched_sections
)
3037 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
3038 fde
->dw_fde_unlikely_section_label
);
3039 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
3040 fde
->dw_fde_hot_section_label
);
3041 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
3042 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
3043 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
3044 "FDE initial location");
3045 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3046 fde
->dw_fde_hot_section_end_label
,
3047 fde
->dw_fde_hot_section_label
,
3048 "FDE address range");
3049 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
3050 "FDE initial location");
3051 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3052 fde
->dw_fde_unlikely_section_end_label
,
3053 fde
->dw_fde_unlikely_section_label
,
3054 "FDE address range");
3058 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
3059 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3060 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
3063 "FDE initial location");
3064 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3065 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3066 "FDE address range");
3071 if (fde
->dw_fde_switched_sections
)
3073 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3074 fde
->dw_fde_hot_section_label
,
3075 "FDE initial location");
3076 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3077 fde
->dw_fde_hot_section_end_label
,
3078 fde
->dw_fde_hot_section_label
,
3079 "FDE address range");
3080 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3081 fde
->dw_fde_unlikely_section_label
,
3082 "FDE initial location");
3083 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3084 fde
->dw_fde_unlikely_section_end_label
,
3085 fde
->dw_fde_unlikely_section_label
,
3086 "FDE address range");
3090 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
3091 "FDE initial location");
3092 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3093 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3094 "FDE address range");
3098 if (augmentation
[0])
3100 if (any_lsda_needed
)
3102 int size
= size_of_encoded_value (lsda_encoding
);
3104 if (lsda_encoding
== DW_EH_PE_aligned
)
3106 int offset
= ( 4 /* Length */
3107 + 4 /* CIE offset */
3108 + 2 * size_of_encoded_value (fde_encoding
)
3109 + 1 /* Augmentation size */ );
3110 int pad
= -offset
& (PTR_SIZE
- 1);
3113 gcc_assert (size_of_uleb128 (size
) == 1);
3116 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3118 if (fde
->uses_eh_lsda
)
3120 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
3121 fde
->funcdef_number
);
3122 dw2_asm_output_encoded_addr_rtx (
3123 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
3124 false, "Language Specific Data Area");
3128 if (lsda_encoding
== DW_EH_PE_aligned
)
3129 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3131 (size_of_encoded_value (lsda_encoding
), 0,
3132 "Language Specific Data Area (none)");
3136 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3139 /* Loop through the Call Frame Instructions associated with
3141 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
3142 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3143 output_cfi (cfi
, fde
, for_eh
);
3145 /* Pad the FDE out to an address sized boundary. */
3146 ASM_OUTPUT_ALIGN (asm_out_file
,
3147 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3148 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3151 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3152 dw2_asm_output_data (4, 0, "End of Table");
3153 #ifdef MIPS_DEBUGGING_INFO
3154 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3155 get a value of 0. Putting .align 0 after the label fixes it. */
3156 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3159 /* Turn off app to make assembly quicker. */
3164 /* Output a marker (i.e. a label) for the beginning of a function, before
3168 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
3169 const char *file ATTRIBUTE_UNUSED
)
3171 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3175 current_function_func_begin_label
= NULL
;
3177 #ifdef TARGET_UNWIND_INFO
3178 /* ??? current_function_func_begin_label is also used by except.c
3179 for call-site information. We must emit this label if it might
3181 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
3182 && ! dwarf2out_do_frame ())
3185 if (! dwarf2out_do_frame ())
3189 switch_to_section (function_section (current_function_decl
));
3190 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
3191 current_function_funcdef_no
);
3192 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
3193 current_function_funcdef_no
);
3194 dup_label
= xstrdup (label
);
3195 current_function_func_begin_label
= dup_label
;
3197 #ifdef TARGET_UNWIND_INFO
3198 /* We can elide the fde allocation if we're not emitting debug info. */
3199 if (! dwarf2out_do_frame ())
3203 /* Expand the fde table if necessary. */
3204 if (fde_table_in_use
== fde_table_allocated
)
3206 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
3207 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
3208 memset (fde_table
+ fde_table_in_use
, 0,
3209 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
3212 /* Record the FDE associated with this function. */
3213 current_funcdef_fde
= fde_table_in_use
;
3215 /* Add the new FDE at the end of the fde_table. */
3216 fde
= &fde_table
[fde_table_in_use
++];
3217 fde
->decl
= current_function_decl
;
3218 fde
->dw_fde_begin
= dup_label
;
3219 fde
->dw_fde_current_label
= dup_label
;
3220 fde
->dw_fde_hot_section_label
= NULL
;
3221 fde
->dw_fde_hot_section_end_label
= NULL
;
3222 fde
->dw_fde_unlikely_section_label
= NULL
;
3223 fde
->dw_fde_unlikely_section_end_label
= NULL
;
3224 fde
->dw_fde_switched_sections
= false;
3225 fde
->dw_fde_end
= NULL
;
3226 fde
->dw_fde_cfi
= NULL
;
3227 fde
->funcdef_number
= current_function_funcdef_no
;
3228 fde
->nothrow
= crtl
->nothrow
;
3229 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
3230 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
3231 fde
->drap_reg
= INVALID_REGNUM
;
3232 fde
->vdrap_reg
= INVALID_REGNUM
;
3234 args_size
= old_args_size
= 0;
3236 /* We only want to output line number information for the genuine dwarf2
3237 prologue case, not the eh frame case. */
3238 #ifdef DWARF2_DEBUGGING_INFO
3240 dwarf2out_source_line (line
, file
);
3243 if (dwarf2out_do_cfi_asm ())
3248 fprintf (asm_out_file
, "\t.cfi_startproc\n");
3250 if (eh_personality_libfunc
)
3252 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3253 ref
= eh_personality_libfunc
;
3255 /* ??? The GAS support isn't entirely consistent. We have to
3256 handle indirect support ourselves, but PC-relative is done
3257 in the assembler. Further, the assembler can't handle any
3258 of the weirder relocation types. */
3259 if (enc
& DW_EH_PE_indirect
)
3260 ref
= dw2_force_const_mem (ref
, true);
3262 fprintf (asm_out_file
, "\t.cfi_personality 0x%x,", enc
);
3263 output_addr_const (asm_out_file
, ref
);
3264 fputc ('\n', asm_out_file
);
3267 if (crtl
->uses_eh_lsda
)
3271 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3272 ASM_GENERATE_INTERNAL_LABEL (lab
, "LLSDA",
3273 current_function_funcdef_no
);
3274 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
3275 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
3277 if (enc
& DW_EH_PE_indirect
)
3278 ref
= dw2_force_const_mem (ref
, true);
3280 fprintf (asm_out_file
, "\t.cfi_lsda 0x%x,", enc
);
3281 output_addr_const (asm_out_file
, ref
);
3282 fputc ('\n', asm_out_file
);
3287 /* Output a marker (i.e. a label) for the absolute end of the generated code
3288 for a function definition. This gets called *after* the epilogue code has
3292 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
3293 const char *file ATTRIBUTE_UNUSED
)
3296 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3298 if (dwarf2out_do_cfi_asm ())
3299 fprintf (asm_out_file
, "\t.cfi_endproc\n");
3301 /* Output a label to mark the endpoint of the code generated for this
3303 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
3304 current_function_funcdef_no
);
3305 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3306 fde
= current_fde ();
3307 gcc_assert (fde
!= NULL
);
3308 fde
->dw_fde_end
= xstrdup (label
);
3312 dwarf2out_frame_init (void)
3314 /* Allocate the initial hunk of the fde_table. */
3315 fde_table
= GGC_CNEWVEC (dw_fde_node
, FDE_TABLE_INCREMENT
);
3316 fde_table_allocated
= FDE_TABLE_INCREMENT
;
3317 fde_table_in_use
= 0;
3319 /* Generate the CFA instructions common to all FDE's. Do it now for the
3320 sake of lookup_cfa. */
3322 /* On entry, the Canonical Frame Address is at SP. */
3323 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
3325 #ifdef DWARF2_UNWIND_INFO
3326 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
3327 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
3332 dwarf2out_frame_finish (void)
3334 /* Output call frame information. */
3335 if (DWARF2_FRAME_INFO
)
3336 output_call_frame_info (0);
3338 #ifndef TARGET_UNWIND_INFO
3339 /* Output another copy for the unwinder. */
3340 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
3341 output_call_frame_info (1);
3345 /* Note that the current function section is being used for code. */
3348 dwarf2out_note_section_used (void)
3350 section
*sec
= current_function_section ();
3351 if (sec
== text_section
)
3352 text_section_used
= true;
3353 else if (sec
== cold_text_section
)
3354 cold_text_section_used
= true;
3358 dwarf2out_switch_text_section (void)
3360 dw_fde_ref fde
= current_fde ();
3362 gcc_assert (cfun
&& fde
);
3364 fde
->dw_fde_switched_sections
= true;
3365 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
3366 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
3367 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
3368 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
3369 have_multiple_function_sections
= true;
3371 /* Reset the current label on switching text sections, so that we
3372 don't attempt to advance_loc4 between labels in different sections. */
3373 fde
->dw_fde_current_label
= NULL
;
3375 /* There is no need to mark used sections when not debugging. */
3376 if (cold_text_section
!= NULL
)
3377 dwarf2out_note_section_used ();
3381 /* And now, the subset of the debugging information support code necessary
3382 for emitting location expressions. */
3384 /* Data about a single source file. */
3385 struct GTY(()) dwarf_file_data
{
3386 const char * filename
;
3390 /* We need some way to distinguish DW_OP_addr with a direct symbol
3391 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3392 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3395 typedef struct dw_val_struct
*dw_val_ref
;
3396 typedef struct die_struct
*dw_die_ref
;
3397 typedef const struct die_struct
*const_dw_die_ref
;
3398 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
3399 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
3401 typedef struct GTY(()) deferred_locations_struct
3405 } deferred_locations
;
3407 DEF_VEC_O(deferred_locations
);
3408 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
3410 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
3412 /* Each DIE may have a series of attribute/value pairs. Values
3413 can take on several forms. The forms that are used in this
3414 implementation are listed below. */
3419 dw_val_class_offset
,
3421 dw_val_class_loc_list
,
3422 dw_val_class_range_list
,
3424 dw_val_class_unsigned_const
,
3425 dw_val_class_long_long
,
3428 dw_val_class_die_ref
,
3429 dw_val_class_fde_ref
,
3430 dw_val_class_lbl_id
,
3431 dw_val_class_lineptr
,
3433 dw_val_class_macptr
,
3437 /* Describe a double word constant value. */
3438 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3440 typedef struct GTY(()) dw_long_long_struct
{
3446 /* Describe a floating point constant value, or a vector constant value. */
3448 typedef struct GTY(()) dw_vec_struct
{
3449 unsigned char * GTY((length ("%h.length"))) array
;
3455 /* The dw_val_node describes an attribute's value, as it is
3456 represented internally. */
3458 typedef struct GTY(()) dw_val_struct
{
3459 enum dw_val_class val_class
;
3460 union dw_val_struct_union
3462 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
3463 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
3464 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
3465 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
3466 HOST_WIDE_INT
GTY ((default)) val_int
;
3467 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
3468 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
3469 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
3470 struct dw_val_die_union
3474 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
3475 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
3476 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
3477 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
3478 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
3479 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
3481 GTY ((desc ("%1.val_class"))) v
;
3485 /* Locations in memory are described using a sequence of stack machine
3488 typedef struct GTY(()) dw_loc_descr_struct
{
3489 dw_loc_descr_ref dw_loc_next
;
3490 enum dwarf_location_atom dw_loc_opc
;
3492 dw_val_node dw_loc_oprnd1
;
3493 dw_val_node dw_loc_oprnd2
;
3497 /* Location lists are ranges + location descriptions for that range,
3498 so you can track variables that are in different places over
3499 their entire life. */
3500 typedef struct GTY(()) dw_loc_list_struct
{
3501 dw_loc_list_ref dw_loc_next
;
3502 const char *begin
; /* Label for begin address of range */
3503 const char *end
; /* Label for end address of range */
3504 char *ll_symbol
; /* Label for beginning of location list.
3505 Only on head of list */
3506 const char *section
; /* Section this loclist is relative to */
3507 dw_loc_descr_ref expr
;
3510 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3512 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3514 /* Convert a DWARF stack opcode into its string name. */
3517 dwarf_stack_op_name (unsigned int op
)
3522 case INTERNAL_DW_OP_tls_addr
:
3523 return "DW_OP_addr";
3525 return "DW_OP_deref";
3527 return "DW_OP_const1u";
3529 return "DW_OP_const1s";
3531 return "DW_OP_const2u";
3533 return "DW_OP_const2s";
3535 return "DW_OP_const4u";
3537 return "DW_OP_const4s";
3539 return "DW_OP_const8u";
3541 return "DW_OP_const8s";
3543 return "DW_OP_constu";
3545 return "DW_OP_consts";
3549 return "DW_OP_drop";
3551 return "DW_OP_over";
3553 return "DW_OP_pick";
3555 return "DW_OP_swap";
3559 return "DW_OP_xderef";
3567 return "DW_OP_minus";
3579 return "DW_OP_plus";
3580 case DW_OP_plus_uconst
:
3581 return "DW_OP_plus_uconst";
3587 return "DW_OP_shra";
3605 return "DW_OP_skip";
3607 return "DW_OP_lit0";
3609 return "DW_OP_lit1";
3611 return "DW_OP_lit2";
3613 return "DW_OP_lit3";
3615 return "DW_OP_lit4";
3617 return "DW_OP_lit5";
3619 return "DW_OP_lit6";
3621 return "DW_OP_lit7";
3623 return "DW_OP_lit8";
3625 return "DW_OP_lit9";
3627 return "DW_OP_lit10";
3629 return "DW_OP_lit11";
3631 return "DW_OP_lit12";
3633 return "DW_OP_lit13";
3635 return "DW_OP_lit14";
3637 return "DW_OP_lit15";
3639 return "DW_OP_lit16";
3641 return "DW_OP_lit17";
3643 return "DW_OP_lit18";
3645 return "DW_OP_lit19";
3647 return "DW_OP_lit20";
3649 return "DW_OP_lit21";
3651 return "DW_OP_lit22";
3653 return "DW_OP_lit23";
3655 return "DW_OP_lit24";
3657 return "DW_OP_lit25";
3659 return "DW_OP_lit26";
3661 return "DW_OP_lit27";
3663 return "DW_OP_lit28";
3665 return "DW_OP_lit29";
3667 return "DW_OP_lit30";
3669 return "DW_OP_lit31";
3671 return "DW_OP_reg0";
3673 return "DW_OP_reg1";
3675 return "DW_OP_reg2";
3677 return "DW_OP_reg3";
3679 return "DW_OP_reg4";
3681 return "DW_OP_reg5";
3683 return "DW_OP_reg6";
3685 return "DW_OP_reg7";
3687 return "DW_OP_reg8";
3689 return "DW_OP_reg9";
3691 return "DW_OP_reg10";
3693 return "DW_OP_reg11";
3695 return "DW_OP_reg12";
3697 return "DW_OP_reg13";
3699 return "DW_OP_reg14";
3701 return "DW_OP_reg15";
3703 return "DW_OP_reg16";
3705 return "DW_OP_reg17";
3707 return "DW_OP_reg18";
3709 return "DW_OP_reg19";
3711 return "DW_OP_reg20";
3713 return "DW_OP_reg21";
3715 return "DW_OP_reg22";
3717 return "DW_OP_reg23";
3719 return "DW_OP_reg24";
3721 return "DW_OP_reg25";
3723 return "DW_OP_reg26";
3725 return "DW_OP_reg27";
3727 return "DW_OP_reg28";
3729 return "DW_OP_reg29";
3731 return "DW_OP_reg30";
3733 return "DW_OP_reg31";
3735 return "DW_OP_breg0";
3737 return "DW_OP_breg1";
3739 return "DW_OP_breg2";
3741 return "DW_OP_breg3";
3743 return "DW_OP_breg4";
3745 return "DW_OP_breg5";
3747 return "DW_OP_breg6";
3749 return "DW_OP_breg7";
3751 return "DW_OP_breg8";
3753 return "DW_OP_breg9";
3755 return "DW_OP_breg10";
3757 return "DW_OP_breg11";
3759 return "DW_OP_breg12";
3761 return "DW_OP_breg13";
3763 return "DW_OP_breg14";
3765 return "DW_OP_breg15";
3767 return "DW_OP_breg16";
3769 return "DW_OP_breg17";
3771 return "DW_OP_breg18";
3773 return "DW_OP_breg19";
3775 return "DW_OP_breg20";
3777 return "DW_OP_breg21";
3779 return "DW_OP_breg22";
3781 return "DW_OP_breg23";
3783 return "DW_OP_breg24";
3785 return "DW_OP_breg25";
3787 return "DW_OP_breg26";
3789 return "DW_OP_breg27";
3791 return "DW_OP_breg28";
3793 return "DW_OP_breg29";
3795 return "DW_OP_breg30";
3797 return "DW_OP_breg31";
3799 return "DW_OP_regx";
3801 return "DW_OP_fbreg";
3803 return "DW_OP_bregx";
3805 return "DW_OP_piece";
3806 case DW_OP_deref_size
:
3807 return "DW_OP_deref_size";
3808 case DW_OP_xderef_size
:
3809 return "DW_OP_xderef_size";
3812 case DW_OP_push_object_address
:
3813 return "DW_OP_push_object_address";
3815 return "DW_OP_call2";
3817 return "DW_OP_call4";
3818 case DW_OP_call_ref
:
3819 return "DW_OP_call_ref";
3820 case DW_OP_GNU_push_tls_address
:
3821 return "DW_OP_GNU_push_tls_address";
3822 case DW_OP_GNU_uninit
:
3823 return "DW_OP_GNU_uninit";
3825 return "OP_<unknown>";
3829 /* Return a pointer to a newly allocated location description. Location
3830 descriptions are simple expression terms that can be strung
3831 together to form more complicated location (address) descriptions. */
3833 static inline dw_loc_descr_ref
3834 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3835 unsigned HOST_WIDE_INT oprnd2
)
3837 dw_loc_descr_ref descr
= GGC_CNEW (dw_loc_descr_node
);
3839 descr
->dw_loc_opc
= op
;
3840 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3841 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3842 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3843 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3848 /* Return a pointer to a newly allocated location description for
3851 static inline dw_loc_descr_ref
3852 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
3855 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
3858 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
3861 /* Add a location description term to a location description expression. */
3864 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3866 dw_loc_descr_ref
*d
;
3868 /* Find the end of the chain. */
3869 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3875 /* Add a constant OFFSET to a location expression. */
3878 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
3880 dw_loc_descr_ref loc
;
3883 gcc_assert (*list_head
!= NULL
);
3888 /* Find the end of the chain. */
3889 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
3893 if (loc
->dw_loc_opc
== DW_OP_fbreg
3894 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
3895 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
3896 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
3897 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
3899 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
3900 offset. Don't optimize if an signed integer overflow would happen. */
3902 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
3903 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
3906 else if (offset
> 0)
3907 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3911 loc
->dw_loc_next
= int_loc_descriptor (offset
);
3912 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
3916 /* Return the size of a location descriptor. */
3918 static unsigned long
3919 size_of_loc_descr (dw_loc_descr_ref loc
)
3921 unsigned long size
= 1;
3923 switch (loc
->dw_loc_opc
)
3926 case INTERNAL_DW_OP_tls_addr
:
3927 size
+= DWARF2_ADDR_SIZE
;
3946 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3949 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3954 case DW_OP_plus_uconst
:
3955 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3993 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3996 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3999 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4002 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4003 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4006 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4008 case DW_OP_deref_size
:
4009 case DW_OP_xderef_size
:
4018 case DW_OP_call_ref
:
4019 size
+= DWARF2_ADDR_SIZE
;
4028 /* Return the size of a series of location descriptors. */
4030 static unsigned long
4031 size_of_locs (dw_loc_descr_ref loc
)
4036 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4037 field, to avoid writing to a PCH file. */
4038 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4040 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
4042 size
+= size_of_loc_descr (l
);
4047 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4049 l
->dw_loc_addr
= size
;
4050 size
+= size_of_loc_descr (l
);
4056 /* Output location description stack opcode's operands (if any). */
4059 output_loc_operands (dw_loc_descr_ref loc
)
4061 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4062 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4064 switch (loc
->dw_loc_opc
)
4066 #ifdef DWARF2_DEBUGGING_INFO
4068 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
4072 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
4076 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
4080 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4081 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
4088 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4089 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4091 dw2_asm_output_data (2, offset
, NULL
);
4104 /* We currently don't make any attempt to make sure these are
4105 aligned properly like we do for the main unwind info, so
4106 don't support emitting things larger than a byte if we're
4107 only doing unwinding. */
4112 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4115 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4118 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4121 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4123 case DW_OP_plus_uconst
:
4124 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4158 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4161 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4164 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4167 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4168 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
4171 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4173 case DW_OP_deref_size
:
4174 case DW_OP_xderef_size
:
4175 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4178 case INTERNAL_DW_OP_tls_addr
:
4179 if (targetm
.asm_out
.output_dwarf_dtprel
)
4181 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
4184 fputc ('\n', asm_out_file
);
4191 /* Other codes have no operands. */
4196 /* Output a sequence of location operations. */
4199 output_loc_sequence (dw_loc_descr_ref loc
)
4201 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4203 /* Output the opcode. */
4204 dw2_asm_output_data (1, loc
->dw_loc_opc
,
4205 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
4207 /* Output the operand(s) (if any). */
4208 output_loc_operands (loc
);
4212 /* Output location description stack opcode's operands (if any).
4213 The output is single bytes on a line, suitable for .cfi_escape. */
4216 output_loc_operands_raw (dw_loc_descr_ref loc
)
4218 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4219 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4221 switch (loc
->dw_loc_opc
)
4224 /* We cannot output addresses in .cfi_escape, only bytes. */
4230 case DW_OP_deref_size
:
4231 case DW_OP_xderef_size
:
4232 fputc (',', asm_out_file
);
4233 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
4238 fputc (',', asm_out_file
);
4239 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
4244 fputc (',', asm_out_file
);
4245 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
4250 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4251 fputc (',', asm_out_file
);
4252 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
4260 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4261 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4263 fputc (',', asm_out_file
);
4264 dw2_asm_output_data_raw (2, offset
);
4269 case DW_OP_plus_uconst
:
4272 fputc (',', asm_out_file
);
4273 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4310 fputc (',', asm_out_file
);
4311 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
4315 fputc (',', asm_out_file
);
4316 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4317 fputc (',', asm_out_file
);
4318 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
4321 case INTERNAL_DW_OP_tls_addr
:
4325 /* Other codes have no operands. */
4331 output_loc_sequence_raw (dw_loc_descr_ref loc
)
4335 /* Output the opcode. */
4336 fprintf (asm_out_file
, "0x%x", loc
->dw_loc_opc
);
4337 output_loc_operands_raw (loc
);
4339 if (!loc
->dw_loc_next
)
4341 loc
= loc
->dw_loc_next
;
4343 fputc (',', asm_out_file
);
4347 /* This routine will generate the correct assembly data for a location
4348 description based on a cfi entry with a complex address. */
4351 output_cfa_loc (dw_cfi_ref cfi
)
4353 dw_loc_descr_ref loc
;
4356 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4357 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, NULL
);
4359 /* Output the size of the block. */
4360 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4361 size
= size_of_locs (loc
);
4362 dw2_asm_output_data_uleb128 (size
, NULL
);
4364 /* Now output the operations themselves. */
4365 output_loc_sequence (loc
);
4368 /* Similar, but used for .cfi_escape. */
4371 output_cfa_loc_raw (dw_cfi_ref cfi
)
4373 dw_loc_descr_ref loc
;
4376 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4377 fprintf (asm_out_file
, "0x%x,", cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
4379 /* Output the size of the block. */
4380 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4381 size
= size_of_locs (loc
);
4382 dw2_asm_output_data_uleb128_raw (size
);
4383 fputc (',', asm_out_file
);
4385 /* Now output the operations themselves. */
4386 output_loc_sequence_raw (loc
);
4389 /* This function builds a dwarf location descriptor sequence from a
4390 dw_cfa_location, adding the given OFFSET to the result of the
4393 static struct dw_loc_descr_struct
*
4394 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
4396 struct dw_loc_descr_struct
*head
, *tmp
;
4398 offset
+= cfa
->offset
;
4402 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
4403 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
4404 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
4405 add_loc_descr (&head
, tmp
);
4408 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4409 add_loc_descr (&head
, tmp
);
4413 head
= new_reg_loc_descr (cfa
->reg
, offset
);
4418 /* This function builds a dwarf location descriptor sequence for
4419 the address at OFFSET from the CFA when stack is aligned to
4422 static struct dw_loc_descr_struct
*
4423 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
4425 struct dw_loc_descr_struct
*head
;
4426 unsigned int dwarf_fp
4427 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
4429 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4430 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
4432 head
= new_reg_loc_descr (dwarf_fp
, 0);
4433 add_loc_descr (&head
, int_loc_descriptor (alignment
));
4434 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
4435 loc_descr_plus_const (&head
, offset
);
4438 head
= new_reg_loc_descr (dwarf_fp
, offset
);
4442 /* This function fills in aa dw_cfa_location structure from a dwarf location
4443 descriptor sequence. */
4446 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
4448 struct dw_loc_descr_struct
*ptr
;
4450 cfa
->base_offset
= 0;
4454 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
4456 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
4492 cfa
->reg
= op
- DW_OP_reg0
;
4495 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4529 cfa
->reg
= op
- DW_OP_breg0
;
4530 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4533 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4534 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
4539 case DW_OP_plus_uconst
:
4540 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
4543 internal_error ("DW_LOC_OP %s not implemented",
4544 dwarf_stack_op_name (ptr
->dw_loc_opc
));
4548 #endif /* .debug_frame support */
4550 /* And now, the support for symbolic debugging information. */
4551 #ifdef DWARF2_DEBUGGING_INFO
4553 /* .debug_str support. */
4554 static int output_indirect_string (void **, void *);
4556 static void dwarf2out_init (const char *);
4557 static void dwarf2out_finish (const char *);
4558 static void dwarf2out_define (unsigned int, const char *);
4559 static void dwarf2out_undef (unsigned int, const char *);
4560 static void dwarf2out_start_source_file (unsigned, const char *);
4561 static void dwarf2out_end_source_file (unsigned);
4562 static void dwarf2out_begin_block (unsigned, unsigned);
4563 static void dwarf2out_end_block (unsigned, unsigned);
4564 static bool dwarf2out_ignore_block (const_tree
);
4565 static void dwarf2out_global_decl (tree
);
4566 static void dwarf2out_type_decl (tree
, int);
4567 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
4568 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
4570 static void dwarf2out_abstract_function (tree
);
4571 static void dwarf2out_var_location (rtx
);
4572 static void dwarf2out_begin_function (tree
);
4573 static void dwarf2out_set_name (tree
, tree
);
4575 /* The debug hooks structure. */
4577 const struct gcc_debug_hooks dwarf2_debug_hooks
=
4583 dwarf2out_start_source_file
,
4584 dwarf2out_end_source_file
,
4585 dwarf2out_begin_block
,
4586 dwarf2out_end_block
,
4587 dwarf2out_ignore_block
,
4588 dwarf2out_source_line
,
4589 dwarf2out_begin_prologue
,
4590 debug_nothing_int_charstar
, /* end_prologue */
4591 dwarf2out_end_epilogue
,
4592 dwarf2out_begin_function
,
4593 debug_nothing_int
, /* end_function */
4594 dwarf2out_decl
, /* function_decl */
4595 dwarf2out_global_decl
,
4596 dwarf2out_type_decl
, /* type_decl */
4597 dwarf2out_imported_module_or_decl
,
4598 debug_nothing_tree
, /* deferred_inline_function */
4599 /* The DWARF 2 backend tries to reduce debugging bloat by not
4600 emitting the abstract description of inline functions until
4601 something tries to reference them. */
4602 dwarf2out_abstract_function
, /* outlining_inline_function */
4603 debug_nothing_rtx
, /* label */
4604 debug_nothing_int
, /* handle_pch */
4605 dwarf2out_var_location
,
4606 dwarf2out_switch_text_section
,
4608 1 /* start_end_main_source_file */
4612 /* NOTE: In the comments in this file, many references are made to
4613 "Debugging Information Entries". This term is abbreviated as `DIE'
4614 throughout the remainder of this file. */
4616 /* An internal representation of the DWARF output is built, and then
4617 walked to generate the DWARF debugging info. The walk of the internal
4618 representation is done after the entire program has been compiled.
4619 The types below are used to describe the internal representation. */
4621 /* Various DIE's use offsets relative to the beginning of the
4622 .debug_info section to refer to each other. */
4624 typedef long int dw_offset
;
4626 /* Define typedefs here to avoid circular dependencies. */
4628 typedef struct dw_attr_struct
*dw_attr_ref
;
4629 typedef struct dw_line_info_struct
*dw_line_info_ref
;
4630 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
4631 typedef struct pubname_struct
*pubname_ref
;
4632 typedef struct dw_ranges_struct
*dw_ranges_ref
;
4633 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
4635 /* Each entry in the line_info_table maintains the file and
4636 line number associated with the label generated for that
4637 entry. The label gives the PC value associated with
4638 the line number entry. */
4640 typedef struct GTY(()) dw_line_info_struct
{
4641 unsigned long dw_file_num
;
4642 unsigned long dw_line_num
;
4646 /* Line information for functions in separate sections; each one gets its
4648 typedef struct GTY(()) dw_separate_line_info_struct
{
4649 unsigned long dw_file_num
;
4650 unsigned long dw_line_num
;
4651 unsigned long function
;
4653 dw_separate_line_info_entry
;
4655 /* Each DIE attribute has a field specifying the attribute kind,
4656 a link to the next attribute in the chain, and an attribute value.
4657 Attributes are typically linked below the DIE they modify. */
4659 typedef struct GTY(()) dw_attr_struct
{
4660 enum dwarf_attribute dw_attr
;
4661 dw_val_node dw_attr_val
;
4665 DEF_VEC_O(dw_attr_node
);
4666 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
4668 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4669 The children of each node form a circular list linked by
4670 die_sib. die_child points to the node *before* the "first" child node. */
4672 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
4673 enum dwarf_tag die_tag
;
4675 VEC(dw_attr_node
,gc
) * die_attr
;
4676 dw_die_ref die_parent
;
4677 dw_die_ref die_child
;
4679 dw_die_ref die_definition
; /* ref from a specification to its definition */
4680 dw_offset die_offset
;
4681 unsigned long die_abbrev
;
4683 /* Die is used and must not be pruned as unused. */
4684 int die_perennial_p
;
4685 unsigned int decl_id
;
4689 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4690 #define FOR_EACH_CHILD(die, c, expr) do { \
4691 c = die->die_child; \
4695 } while (c != die->die_child); \
4698 /* The pubname structure */
4700 typedef struct GTY(()) pubname_struct
{
4706 DEF_VEC_O(pubname_entry
);
4707 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
4709 struct GTY(()) dw_ranges_struct
{
4710 /* If this is positive, it's a block number, otherwise it's a
4711 bitwise-negated index into dw_ranges_by_label. */
4715 struct GTY(()) dw_ranges_by_label_struct
{
4720 /* The limbo die list structure. */
4721 typedef struct GTY(()) limbo_die_struct
{
4724 struct limbo_die_struct
*next
;
4728 /* How to start an assembler comment. */
4729 #ifndef ASM_COMMENT_START
4730 #define ASM_COMMENT_START ";#"
4733 /* Define a macro which returns nonzero for a TYPE_DECL which was
4734 implicitly generated for a tagged type.
4736 Note that unlike the gcc front end (which generates a NULL named
4737 TYPE_DECL node for each complete tagged type, each array type, and
4738 each function type node created) the g++ front end generates a
4739 _named_ TYPE_DECL node for each tagged type node created.
4740 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4741 generate a DW_TAG_typedef DIE for them. */
4743 #define TYPE_DECL_IS_STUB(decl) \
4744 (DECL_NAME (decl) == NULL_TREE \
4745 || (DECL_ARTIFICIAL (decl) \
4746 && is_tagged_type (TREE_TYPE (decl)) \
4747 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4748 /* This is necessary for stub decls that \
4749 appear in nested inline functions. */ \
4750 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4751 && (decl_ultimate_origin (decl) \
4752 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4754 /* Information concerning the compilation unit's programming
4755 language, and compiler version. */
4757 /* Fixed size portion of the DWARF compilation unit header. */
4758 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4759 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4761 /* Fixed size portion of public names info. */
4762 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4764 /* Fixed size portion of the address range info. */
4765 #define DWARF_ARANGES_HEADER_SIZE \
4766 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4767 DWARF2_ADDR_SIZE * 2) \
4768 - DWARF_INITIAL_LENGTH_SIZE)
4770 /* Size of padding portion in the address range info. It must be
4771 aligned to twice the pointer size. */
4772 #define DWARF_ARANGES_PAD_SIZE \
4773 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4774 DWARF2_ADDR_SIZE * 2) \
4775 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4777 /* Use assembler line directives if available. */
4778 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4779 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4780 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4782 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4786 /* Minimum line offset in a special line info. opcode.
4787 This value was chosen to give a reasonable range of values. */
4788 #define DWARF_LINE_BASE -10
4790 /* First special line opcode - leave room for the standard opcodes. */
4791 #define DWARF_LINE_OPCODE_BASE 10
4793 /* Range of line offsets in a special line info. opcode. */
4794 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4796 /* Flag that indicates the initial value of the is_stmt_start flag.
4797 In the present implementation, we do not mark any lines as
4798 the beginning of a source statement, because that information
4799 is not made available by the GCC front-end. */
4800 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4802 #ifdef DWARF2_DEBUGGING_INFO
4803 /* This location is used by calc_die_sizes() to keep track
4804 the offset of each DIE within the .debug_info section. */
4805 static unsigned long next_die_offset
;
4808 /* Record the root of the DIE's built for the current compilation unit. */
4809 static GTY(()) dw_die_ref comp_unit_die
;
4811 /* A list of DIEs with a NULL parent waiting to be relocated. */
4812 static GTY(()) limbo_die_node
*limbo_die_list
;
4814 /* Filenames referenced by this compilation unit. */
4815 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
4817 /* A hash table of references to DIE's that describe declarations.
4818 The key is a DECL_UID() which is a unique number identifying each decl. */
4819 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
4821 /* A hash table of references to DIE's that describe COMMON blocks.
4822 The key is DECL_UID() ^ die_parent. */
4823 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
4825 /* Node of the variable location list. */
4826 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
4827 rtx
GTY (()) var_loc_note
;
4828 const char * GTY (()) label
;
4829 const char * GTY (()) section_label
;
4830 struct var_loc_node
* GTY (()) next
;
4833 /* Variable location list. */
4834 struct GTY (()) var_loc_list_def
{
4835 struct var_loc_node
* GTY (()) first
;
4837 /* Do not mark the last element of the chained list because
4838 it is marked through the chain. */
4839 struct var_loc_node
* GTY ((skip ("%h"))) last
;
4841 /* DECL_UID of the variable decl. */
4842 unsigned int decl_id
;
4844 typedef struct var_loc_list_def var_loc_list
;
4847 /* Table of decl location linked lists. */
4848 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
4850 /* A pointer to the base of a list of references to DIE's that
4851 are uniquely identified by their tag, presence/absence of
4852 children DIE's, and list of attribute/value pairs. */
4853 static GTY((length ("abbrev_die_table_allocated")))
4854 dw_die_ref
*abbrev_die_table
;
4856 /* Number of elements currently allocated for abbrev_die_table. */
4857 static GTY(()) unsigned abbrev_die_table_allocated
;
4859 /* Number of elements in type_die_table currently in use. */
4860 static GTY(()) unsigned abbrev_die_table_in_use
;
4862 /* Size (in elements) of increments by which we may expand the
4863 abbrev_die_table. */
4864 #define ABBREV_DIE_TABLE_INCREMENT 256
4866 /* A pointer to the base of a table that contains line information
4867 for each source code line in .text in the compilation unit. */
4868 static GTY((length ("line_info_table_allocated")))
4869 dw_line_info_ref line_info_table
;
4871 /* Number of elements currently allocated for line_info_table. */
4872 static GTY(()) unsigned line_info_table_allocated
;
4874 /* Number of elements in line_info_table currently in use. */
4875 static GTY(()) unsigned line_info_table_in_use
;
4877 /* A pointer to the base of a table that contains line information
4878 for each source code line outside of .text in the compilation unit. */
4879 static GTY ((length ("separate_line_info_table_allocated")))
4880 dw_separate_line_info_ref separate_line_info_table
;
4882 /* Number of elements currently allocated for separate_line_info_table. */
4883 static GTY(()) unsigned separate_line_info_table_allocated
;
4885 /* Number of elements in separate_line_info_table currently in use. */
4886 static GTY(()) unsigned separate_line_info_table_in_use
;
4888 /* Size (in elements) of increments by which we may expand the
4890 #define LINE_INFO_TABLE_INCREMENT 1024
4892 /* A pointer to the base of a table that contains a list of publicly
4893 accessible names. */
4894 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
4896 /* A pointer to the base of a table that contains a list of publicly
4897 accessible types. */
4898 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
4900 /* Array of dies for which we should generate .debug_arange info. */
4901 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
4903 /* Number of elements currently allocated for arange_table. */
4904 static GTY(()) unsigned arange_table_allocated
;
4906 /* Number of elements in arange_table currently in use. */
4907 static GTY(()) unsigned arange_table_in_use
;
4909 /* Size (in elements) of increments by which we may expand the
4911 #define ARANGE_TABLE_INCREMENT 64
4913 /* Array of dies for which we should generate .debug_ranges info. */
4914 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
4916 /* Number of elements currently allocated for ranges_table. */
4917 static GTY(()) unsigned ranges_table_allocated
;
4919 /* Number of elements in ranges_table currently in use. */
4920 static GTY(()) unsigned ranges_table_in_use
;
4922 /* Array of pairs of labels referenced in ranges_table. */
4923 static GTY ((length ("ranges_by_label_allocated")))
4924 dw_ranges_by_label_ref ranges_by_label
;
4926 /* Number of elements currently allocated for ranges_by_label. */
4927 static GTY(()) unsigned ranges_by_label_allocated
;
4929 /* Number of elements in ranges_by_label currently in use. */
4930 static GTY(()) unsigned ranges_by_label_in_use
;
4932 /* Size (in elements) of increments by which we may expand the
4934 #define RANGES_TABLE_INCREMENT 64
4936 /* Whether we have location lists that need outputting */
4937 static GTY(()) bool have_location_lists
;
4939 /* Unique label counter. */
4940 static GTY(()) unsigned int loclabel_num
;
4942 #ifdef DWARF2_DEBUGGING_INFO
4943 /* Record whether the function being analyzed contains inlined functions. */
4944 static int current_function_has_inlines
;
4946 #if 0 && defined (MIPS_DEBUGGING_INFO)
4947 static int comp_unit_has_inlines
;
4950 /* The last file entry emitted by maybe_emit_file(). */
4951 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
4953 /* Number of internal labels generated by gen_internal_sym(). */
4954 static GTY(()) int label_num
;
4956 /* Cached result of previous call to lookup_filename. */
4957 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
4959 #ifdef DWARF2_DEBUGGING_INFO
4961 /* Offset from the "steady-state frame pointer" to the frame base,
4962 within the current function. */
4963 static HOST_WIDE_INT frame_pointer_fb_offset
;
4965 /* Forward declarations for functions defined in this file. */
4967 static int is_pseudo_reg (const_rtx
);
4968 static tree
type_main_variant (tree
);
4969 static int is_tagged_type (const_tree
);
4970 static const char *dwarf_tag_name (unsigned);
4971 static const char *dwarf_attr_name (unsigned);
4972 static const char *dwarf_form_name (unsigned);
4973 static tree
decl_ultimate_origin (const_tree
);
4974 static tree
decl_class_context (tree
);
4975 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
4976 static inline enum dw_val_class
AT_class (dw_attr_ref
);
4977 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
4978 static inline unsigned AT_flag (dw_attr_ref
);
4979 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
4980 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
4981 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
4982 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
4983 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
4985 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
4986 unsigned int, unsigned char *);
4987 static hashval_t
debug_str_do_hash (const void *);
4988 static int debug_str_eq (const void *, const void *);
4989 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
4990 static inline const char *AT_string (dw_attr_ref
);
4991 static enum dwarf_form
AT_string_form (dw_attr_ref
);
4992 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
4993 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
4994 static inline dw_die_ref
AT_ref (dw_attr_ref
);
4995 static inline int AT_ref_external (dw_attr_ref
);
4996 static inline void set_AT_ref_external (dw_attr_ref
, int);
4997 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
4998 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
4999 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
5000 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
5002 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
5003 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
5004 static inline rtx
AT_addr (dw_attr_ref
);
5005 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
5006 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
5007 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
5008 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
5009 unsigned HOST_WIDE_INT
);
5010 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
5012 static inline const char *AT_lbl (dw_attr_ref
);
5013 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
5014 static const char *get_AT_low_pc (dw_die_ref
);
5015 static const char *get_AT_hi_pc (dw_die_ref
);
5016 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
5017 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
5018 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
5019 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
5020 static bool is_c_family (void);
5021 static bool is_cxx (void);
5022 static bool is_java (void);
5023 static bool is_fortran (void);
5024 static bool is_ada (void);
5025 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
5026 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
5027 static void add_child_die (dw_die_ref
, dw_die_ref
);
5028 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
5029 static dw_die_ref
lookup_type_die (tree
);
5030 static void equate_type_number_to_die (tree
, dw_die_ref
);
5031 static hashval_t
decl_die_table_hash (const void *);
5032 static int decl_die_table_eq (const void *, const void *);
5033 static dw_die_ref
lookup_decl_die (tree
);
5034 static hashval_t
common_block_die_table_hash (const void *);
5035 static int common_block_die_table_eq (const void *, const void *);
5036 static hashval_t
decl_loc_table_hash (const void *);
5037 static int decl_loc_table_eq (const void *, const void *);
5038 static var_loc_list
*lookup_decl_loc (const_tree
);
5039 static void equate_decl_number_to_die (tree
, dw_die_ref
);
5040 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
5041 static void print_spaces (FILE *);
5042 static void print_die (dw_die_ref
, FILE *);
5043 static void print_dwarf_line_table (FILE *);
5044 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
5045 static dw_die_ref
pop_compile_unit (dw_die_ref
);
5046 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
5047 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
5048 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
5049 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
5050 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
5051 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
5052 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
5053 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
5054 static void compute_section_prefix (dw_die_ref
);
5055 static int is_type_die (dw_die_ref
);
5056 static int is_comdat_die (dw_die_ref
);
5057 static int is_symbol_die (dw_die_ref
);
5058 static void assign_symbol_names (dw_die_ref
);
5059 static void break_out_includes (dw_die_ref
);
5060 static hashval_t
htab_cu_hash (const void *);
5061 static int htab_cu_eq (const void *, const void *);
5062 static void htab_cu_del (void *);
5063 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
5064 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
5065 static void add_sibling_attributes (dw_die_ref
);
5066 static void build_abbrev_table (dw_die_ref
);
5067 static void output_location_lists (dw_die_ref
);
5068 static int constant_size (unsigned HOST_WIDE_INT
);
5069 static unsigned long size_of_die (dw_die_ref
);
5070 static void calc_die_sizes (dw_die_ref
);
5071 static void mark_dies (dw_die_ref
);
5072 static void unmark_dies (dw_die_ref
);
5073 static void unmark_all_dies (dw_die_ref
);
5074 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
5075 static unsigned long size_of_aranges (void);
5076 static enum dwarf_form
value_format (dw_attr_ref
);
5077 static void output_value_format (dw_attr_ref
);
5078 static void output_abbrev_section (void);
5079 static void output_die_symbol (dw_die_ref
);
5080 static void output_die (dw_die_ref
);
5081 static void output_compilation_unit_header (void);
5082 static void output_comp_unit (dw_die_ref
, int);
5083 static const char *dwarf2_name (tree
, int);
5084 static void add_pubname (tree
, dw_die_ref
);
5085 static void add_pubname_string (const char *, dw_die_ref
);
5086 static void add_pubtype (tree
, dw_die_ref
);
5087 static void output_pubnames (VEC (pubname_entry
,gc
) *);
5088 static void add_arange (tree
, dw_die_ref
);
5089 static void output_aranges (void);
5090 static unsigned int add_ranges_num (int);
5091 static unsigned int add_ranges (const_tree
);
5092 static unsigned int add_ranges_by_labels (const char *, const char *);
5093 static void output_ranges (void);
5094 static void output_line_info (void);
5095 static void output_file_names (void);
5096 static dw_die_ref
base_type_die (tree
);
5097 static int is_base_type (tree
);
5098 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
5099 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
5100 static int type_is_enum (const_tree
);
5101 static unsigned int dbx_reg_number (const_rtx
);
5102 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
5103 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
5104 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
5105 enum var_init_status
);
5106 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
5107 enum var_init_status
);
5108 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
5109 enum var_init_status
);
5110 static int is_based_loc (const_rtx
);
5111 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
5112 enum var_init_status
);
5113 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
5114 enum var_init_status
);
5115 static dw_loc_descr_ref
loc_descriptor (rtx
, enum var_init_status
);
5116 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
5117 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
5118 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
5119 static tree
field_type (const_tree
);
5120 static unsigned int simple_type_align_in_bits (const_tree
);
5121 static unsigned int simple_decl_align_in_bits (const_tree
);
5122 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
5123 static HOST_WIDE_INT
field_byte_offset (const_tree
);
5124 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
5126 static void add_data_member_location_attribute (dw_die_ref
, tree
);
5127 static void add_const_value_attribute (dw_die_ref
, rtx
);
5128 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
5129 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
5130 static void insert_float (const_rtx
, unsigned char *);
5131 static rtx
rtl_for_decl_location (tree
);
5132 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
5133 enum dwarf_attribute
);
5134 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
5135 static void add_name_attribute (dw_die_ref
, const char *);
5136 static void add_comp_dir_attribute (dw_die_ref
);
5137 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
5138 static void add_subscript_info (dw_die_ref
, tree
, bool);
5139 static void add_byte_size_attribute (dw_die_ref
, tree
);
5140 static void add_bit_offset_attribute (dw_die_ref
, tree
);
5141 static void add_bit_size_attribute (dw_die_ref
, tree
);
5142 static void add_prototyped_attribute (dw_die_ref
, tree
);
5143 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
5144 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
5145 static void add_src_coords_attributes (dw_die_ref
, tree
);
5146 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
5147 static void push_decl_scope (tree
);
5148 static void pop_decl_scope (void);
5149 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
5150 static inline int local_scope_p (dw_die_ref
);
5151 static inline int class_scope_p (dw_die_ref
);
5152 static inline int class_or_namespace_scope_p (dw_die_ref
);
5153 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
5154 static void add_calling_convention_attribute (dw_die_ref
, tree
);
5155 static const char *type_tag (const_tree
);
5156 static tree
member_declared_type (const_tree
);
5158 static const char *decl_start_label (tree
);
5160 static void gen_array_type_die (tree
, dw_die_ref
);
5161 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
5163 static void gen_entry_point_die (tree
, dw_die_ref
);
5165 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
5166 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, dw_die_ref
);
5167 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
5168 static void gen_formal_types_die (tree
, dw_die_ref
);
5169 static void gen_subprogram_die (tree
, dw_die_ref
);
5170 static void gen_variable_die (tree
, tree
, dw_die_ref
);
5171 static void gen_const_die (tree
, dw_die_ref
);
5172 static void gen_label_die (tree
, dw_die_ref
);
5173 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
5174 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
5175 static void gen_field_die (tree
, dw_die_ref
);
5176 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
5177 static dw_die_ref
gen_compile_unit_die (const char *);
5178 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
5179 static void gen_member_die (tree
, dw_die_ref
);
5180 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
5181 enum debug_info_usage
);
5182 static void gen_subroutine_type_die (tree
, dw_die_ref
);
5183 static void gen_typedef_die (tree
, dw_die_ref
);
5184 static void gen_type_die (tree
, dw_die_ref
);
5185 static void gen_block_die (tree
, dw_die_ref
, int);
5186 static void decls_for_scope (tree
, dw_die_ref
, int);
5187 static int is_redundant_typedef (const_tree
);
5188 static void gen_namespace_die (tree
, dw_die_ref
);
5189 static void gen_decl_die (tree
, tree
, dw_die_ref
);
5190 static dw_die_ref
force_decl_die (tree
);
5191 static dw_die_ref
force_type_die (tree
);
5192 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
5193 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
5194 static struct dwarf_file_data
* lookup_filename (const char *);
5195 static void retry_incomplete_types (void);
5196 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
5197 static void splice_child_die (dw_die_ref
, dw_die_ref
);
5198 static int file_info_cmp (const void *, const void *);
5199 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
5200 const char *, const char *, unsigned);
5201 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
5202 const char *, const char *,
5204 static void output_loc_list (dw_loc_list_ref
);
5205 static char *gen_internal_sym (const char *);
5207 static void prune_unmark_dies (dw_die_ref
);
5208 static void prune_unused_types_mark (dw_die_ref
, int);
5209 static void prune_unused_types_walk (dw_die_ref
);
5210 static void prune_unused_types_walk_attribs (dw_die_ref
);
5211 static void prune_unused_types_prune (dw_die_ref
);
5212 static void prune_unused_types (void);
5213 static int maybe_emit_file (struct dwarf_file_data
*fd
);
5215 /* Section names used to hold DWARF debugging information. */
5216 #ifndef DEBUG_INFO_SECTION
5217 #define DEBUG_INFO_SECTION ".debug_info"
5219 #ifndef DEBUG_ABBREV_SECTION
5220 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5222 #ifndef DEBUG_ARANGES_SECTION
5223 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5225 #ifndef DEBUG_MACINFO_SECTION
5226 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5228 #ifndef DEBUG_LINE_SECTION
5229 #define DEBUG_LINE_SECTION ".debug_line"
5231 #ifndef DEBUG_LOC_SECTION
5232 #define DEBUG_LOC_SECTION ".debug_loc"
5234 #ifndef DEBUG_PUBNAMES_SECTION
5235 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5237 #ifndef DEBUG_STR_SECTION
5238 #define DEBUG_STR_SECTION ".debug_str"
5240 #ifndef DEBUG_RANGES_SECTION
5241 #define DEBUG_RANGES_SECTION ".debug_ranges"
5244 /* Standard ELF section names for compiled code and data. */
5245 #ifndef TEXT_SECTION_NAME
5246 #define TEXT_SECTION_NAME ".text"
5249 /* Section flags for .debug_str section. */
5250 #define DEBUG_STR_SECTION_FLAGS \
5251 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5252 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5255 /* Labels we insert at beginning sections we can reference instead of
5256 the section names themselves. */
5258 #ifndef TEXT_SECTION_LABEL
5259 #define TEXT_SECTION_LABEL "Ltext"
5261 #ifndef COLD_TEXT_SECTION_LABEL
5262 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5264 #ifndef DEBUG_LINE_SECTION_LABEL
5265 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5267 #ifndef DEBUG_INFO_SECTION_LABEL
5268 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5270 #ifndef DEBUG_ABBREV_SECTION_LABEL
5271 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5273 #ifndef DEBUG_LOC_SECTION_LABEL
5274 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5276 #ifndef DEBUG_RANGES_SECTION_LABEL
5277 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5279 #ifndef DEBUG_MACINFO_SECTION_LABEL
5280 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5283 /* Definitions of defaults for formats and names of various special
5284 (artificial) labels which may be generated within this file (when the -g
5285 options is used and DWARF2_DEBUGGING_INFO is in effect.
5286 If necessary, these may be overridden from within the tm.h file, but
5287 typically, overriding these defaults is unnecessary. */
5289 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5290 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5291 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5292 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5293 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5294 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5295 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5296 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5297 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5298 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
5300 #ifndef TEXT_END_LABEL
5301 #define TEXT_END_LABEL "Letext"
5303 #ifndef COLD_END_LABEL
5304 #define COLD_END_LABEL "Letext_cold"
5306 #ifndef BLOCK_BEGIN_LABEL
5307 #define BLOCK_BEGIN_LABEL "LBB"
5309 #ifndef BLOCK_END_LABEL
5310 #define BLOCK_END_LABEL "LBE"
5312 #ifndef LINE_CODE_LABEL
5313 #define LINE_CODE_LABEL "LM"
5315 #ifndef SEPARATE_LINE_CODE_LABEL
5316 #define SEPARATE_LINE_CODE_LABEL "LSM"
5320 /* We allow a language front-end to designate a function that is to be
5321 called to "demangle" any name before it is put into a DIE. */
5323 static const char *(*demangle_name_func
) (const char *);
5326 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
5328 demangle_name_func
= func
;
5331 /* Test if rtl node points to a pseudo register. */
5334 is_pseudo_reg (const_rtx rtl
)
5336 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
5337 || (GET_CODE (rtl
) == SUBREG
5338 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
5341 /* Return a reference to a type, with its const and volatile qualifiers
5345 type_main_variant (tree type
)
5347 type
= TYPE_MAIN_VARIANT (type
);
5349 /* ??? There really should be only one main variant among any group of
5350 variants of a given type (and all of the MAIN_VARIANT values for all
5351 members of the group should point to that one type) but sometimes the C
5352 front-end messes this up for array types, so we work around that bug
5354 if (TREE_CODE (type
) == ARRAY_TYPE
)
5355 while (type
!= TYPE_MAIN_VARIANT (type
))
5356 type
= TYPE_MAIN_VARIANT (type
);
5361 /* Return nonzero if the given type node represents a tagged type. */
5364 is_tagged_type (const_tree type
)
5366 enum tree_code code
= TREE_CODE (type
);
5368 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
5369 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
5372 /* Convert a DIE tag into its string name. */
5375 dwarf_tag_name (unsigned int tag
)
5379 case DW_TAG_padding
:
5380 return "DW_TAG_padding";
5381 case DW_TAG_array_type
:
5382 return "DW_TAG_array_type";
5383 case DW_TAG_class_type
:
5384 return "DW_TAG_class_type";
5385 case DW_TAG_entry_point
:
5386 return "DW_TAG_entry_point";
5387 case DW_TAG_enumeration_type
:
5388 return "DW_TAG_enumeration_type";
5389 case DW_TAG_formal_parameter
:
5390 return "DW_TAG_formal_parameter";
5391 case DW_TAG_imported_declaration
:
5392 return "DW_TAG_imported_declaration";
5394 return "DW_TAG_label";
5395 case DW_TAG_lexical_block
:
5396 return "DW_TAG_lexical_block";
5398 return "DW_TAG_member";
5399 case DW_TAG_pointer_type
:
5400 return "DW_TAG_pointer_type";
5401 case DW_TAG_reference_type
:
5402 return "DW_TAG_reference_type";
5403 case DW_TAG_compile_unit
:
5404 return "DW_TAG_compile_unit";
5405 case DW_TAG_string_type
:
5406 return "DW_TAG_string_type";
5407 case DW_TAG_structure_type
:
5408 return "DW_TAG_structure_type";
5409 case DW_TAG_subroutine_type
:
5410 return "DW_TAG_subroutine_type";
5411 case DW_TAG_typedef
:
5412 return "DW_TAG_typedef";
5413 case DW_TAG_union_type
:
5414 return "DW_TAG_union_type";
5415 case DW_TAG_unspecified_parameters
:
5416 return "DW_TAG_unspecified_parameters";
5417 case DW_TAG_variant
:
5418 return "DW_TAG_variant";
5419 case DW_TAG_common_block
:
5420 return "DW_TAG_common_block";
5421 case DW_TAG_common_inclusion
:
5422 return "DW_TAG_common_inclusion";
5423 case DW_TAG_inheritance
:
5424 return "DW_TAG_inheritance";
5425 case DW_TAG_inlined_subroutine
:
5426 return "DW_TAG_inlined_subroutine";
5428 return "DW_TAG_module";
5429 case DW_TAG_ptr_to_member_type
:
5430 return "DW_TAG_ptr_to_member_type";
5431 case DW_TAG_set_type
:
5432 return "DW_TAG_set_type";
5433 case DW_TAG_subrange_type
:
5434 return "DW_TAG_subrange_type";
5435 case DW_TAG_with_stmt
:
5436 return "DW_TAG_with_stmt";
5437 case DW_TAG_access_declaration
:
5438 return "DW_TAG_access_declaration";
5439 case DW_TAG_base_type
:
5440 return "DW_TAG_base_type";
5441 case DW_TAG_catch_block
:
5442 return "DW_TAG_catch_block";
5443 case DW_TAG_const_type
:
5444 return "DW_TAG_const_type";
5445 case DW_TAG_constant
:
5446 return "DW_TAG_constant";
5447 case DW_TAG_enumerator
:
5448 return "DW_TAG_enumerator";
5449 case DW_TAG_file_type
:
5450 return "DW_TAG_file_type";
5452 return "DW_TAG_friend";
5453 case DW_TAG_namelist
:
5454 return "DW_TAG_namelist";
5455 case DW_TAG_namelist_item
:
5456 return "DW_TAG_namelist_item";
5457 case DW_TAG_packed_type
:
5458 return "DW_TAG_packed_type";
5459 case DW_TAG_subprogram
:
5460 return "DW_TAG_subprogram";
5461 case DW_TAG_template_type_param
:
5462 return "DW_TAG_template_type_param";
5463 case DW_TAG_template_value_param
:
5464 return "DW_TAG_template_value_param";
5465 case DW_TAG_thrown_type
:
5466 return "DW_TAG_thrown_type";
5467 case DW_TAG_try_block
:
5468 return "DW_TAG_try_block";
5469 case DW_TAG_variant_part
:
5470 return "DW_TAG_variant_part";
5471 case DW_TAG_variable
:
5472 return "DW_TAG_variable";
5473 case DW_TAG_volatile_type
:
5474 return "DW_TAG_volatile_type";
5475 case DW_TAG_dwarf_procedure
:
5476 return "DW_TAG_dwarf_procedure";
5477 case DW_TAG_restrict_type
:
5478 return "DW_TAG_restrict_type";
5479 case DW_TAG_interface_type
:
5480 return "DW_TAG_interface_type";
5481 case DW_TAG_namespace
:
5482 return "DW_TAG_namespace";
5483 case DW_TAG_imported_module
:
5484 return "DW_TAG_imported_module";
5485 case DW_TAG_unspecified_type
:
5486 return "DW_TAG_unspecified_type";
5487 case DW_TAG_partial_unit
:
5488 return "DW_TAG_partial_unit";
5489 case DW_TAG_imported_unit
:
5490 return "DW_TAG_imported_unit";
5491 case DW_TAG_condition
:
5492 return "DW_TAG_condition";
5493 case DW_TAG_shared_type
:
5494 return "DW_TAG_shared_type";
5495 case DW_TAG_MIPS_loop
:
5496 return "DW_TAG_MIPS_loop";
5497 case DW_TAG_format_label
:
5498 return "DW_TAG_format_label";
5499 case DW_TAG_function_template
:
5500 return "DW_TAG_function_template";
5501 case DW_TAG_class_template
:
5502 return "DW_TAG_class_template";
5503 case DW_TAG_GNU_BINCL
:
5504 return "DW_TAG_GNU_BINCL";
5505 case DW_TAG_GNU_EINCL
:
5506 return "DW_TAG_GNU_EINCL";
5508 return "DW_TAG_<unknown>";
5512 /* Convert a DWARF attribute code into its string name. */
5515 dwarf_attr_name (unsigned int attr
)
5520 return "DW_AT_sibling";
5521 case DW_AT_location
:
5522 return "DW_AT_location";
5524 return "DW_AT_name";
5525 case DW_AT_ordering
:
5526 return "DW_AT_ordering";
5527 case DW_AT_subscr_data
:
5528 return "DW_AT_subscr_data";
5529 case DW_AT_byte_size
:
5530 return "DW_AT_byte_size";
5531 case DW_AT_bit_offset
:
5532 return "DW_AT_bit_offset";
5533 case DW_AT_bit_size
:
5534 return "DW_AT_bit_size";
5535 case DW_AT_element_list
:
5536 return "DW_AT_element_list";
5537 case DW_AT_stmt_list
:
5538 return "DW_AT_stmt_list";
5540 return "DW_AT_low_pc";
5542 return "DW_AT_high_pc";
5543 case DW_AT_language
:
5544 return "DW_AT_language";
5546 return "DW_AT_member";
5548 return "DW_AT_discr";
5549 case DW_AT_discr_value
:
5550 return "DW_AT_discr_value";
5551 case DW_AT_visibility
:
5552 return "DW_AT_visibility";
5554 return "DW_AT_import";
5555 case DW_AT_string_length
:
5556 return "DW_AT_string_length";
5557 case DW_AT_common_reference
:
5558 return "DW_AT_common_reference";
5559 case DW_AT_comp_dir
:
5560 return "DW_AT_comp_dir";
5561 case DW_AT_const_value
:
5562 return "DW_AT_const_value";
5563 case DW_AT_containing_type
:
5564 return "DW_AT_containing_type";
5565 case DW_AT_default_value
:
5566 return "DW_AT_default_value";
5568 return "DW_AT_inline";
5569 case DW_AT_is_optional
:
5570 return "DW_AT_is_optional";
5571 case DW_AT_lower_bound
:
5572 return "DW_AT_lower_bound";
5573 case DW_AT_producer
:
5574 return "DW_AT_producer";
5575 case DW_AT_prototyped
:
5576 return "DW_AT_prototyped";
5577 case DW_AT_return_addr
:
5578 return "DW_AT_return_addr";
5579 case DW_AT_start_scope
:
5580 return "DW_AT_start_scope";
5581 case DW_AT_bit_stride
:
5582 return "DW_AT_bit_stride";
5583 case DW_AT_upper_bound
:
5584 return "DW_AT_upper_bound";
5585 case DW_AT_abstract_origin
:
5586 return "DW_AT_abstract_origin";
5587 case DW_AT_accessibility
:
5588 return "DW_AT_accessibility";
5589 case DW_AT_address_class
:
5590 return "DW_AT_address_class";
5591 case DW_AT_artificial
:
5592 return "DW_AT_artificial";
5593 case DW_AT_base_types
:
5594 return "DW_AT_base_types";
5595 case DW_AT_calling_convention
:
5596 return "DW_AT_calling_convention";
5598 return "DW_AT_count";
5599 case DW_AT_data_member_location
:
5600 return "DW_AT_data_member_location";
5601 case DW_AT_decl_column
:
5602 return "DW_AT_decl_column";
5603 case DW_AT_decl_file
:
5604 return "DW_AT_decl_file";
5605 case DW_AT_decl_line
:
5606 return "DW_AT_decl_line";
5607 case DW_AT_declaration
:
5608 return "DW_AT_declaration";
5609 case DW_AT_discr_list
:
5610 return "DW_AT_discr_list";
5611 case DW_AT_encoding
:
5612 return "DW_AT_encoding";
5613 case DW_AT_external
:
5614 return "DW_AT_external";
5615 case DW_AT_explicit
:
5616 return "DW_AT_explicit";
5617 case DW_AT_frame_base
:
5618 return "DW_AT_frame_base";
5620 return "DW_AT_friend";
5621 case DW_AT_identifier_case
:
5622 return "DW_AT_identifier_case";
5623 case DW_AT_macro_info
:
5624 return "DW_AT_macro_info";
5625 case DW_AT_namelist_items
:
5626 return "DW_AT_namelist_items";
5627 case DW_AT_priority
:
5628 return "DW_AT_priority";
5630 return "DW_AT_segment";
5631 case DW_AT_specification
:
5632 return "DW_AT_specification";
5633 case DW_AT_static_link
:
5634 return "DW_AT_static_link";
5636 return "DW_AT_type";
5637 case DW_AT_use_location
:
5638 return "DW_AT_use_location";
5639 case DW_AT_variable_parameter
:
5640 return "DW_AT_variable_parameter";
5641 case DW_AT_virtuality
:
5642 return "DW_AT_virtuality";
5643 case DW_AT_vtable_elem_location
:
5644 return "DW_AT_vtable_elem_location";
5646 case DW_AT_allocated
:
5647 return "DW_AT_allocated";
5648 case DW_AT_associated
:
5649 return "DW_AT_associated";
5650 case DW_AT_data_location
:
5651 return "DW_AT_data_location";
5652 case DW_AT_byte_stride
:
5653 return "DW_AT_byte_stride";
5654 case DW_AT_entry_pc
:
5655 return "DW_AT_entry_pc";
5656 case DW_AT_use_UTF8
:
5657 return "DW_AT_use_UTF8";
5658 case DW_AT_extension
:
5659 return "DW_AT_extension";
5661 return "DW_AT_ranges";
5662 case DW_AT_trampoline
:
5663 return "DW_AT_trampoline";
5664 case DW_AT_call_column
:
5665 return "DW_AT_call_column";
5666 case DW_AT_call_file
:
5667 return "DW_AT_call_file";
5668 case DW_AT_call_line
:
5669 return "DW_AT_call_line";
5671 case DW_AT_MIPS_fde
:
5672 return "DW_AT_MIPS_fde";
5673 case DW_AT_MIPS_loop_begin
:
5674 return "DW_AT_MIPS_loop_begin";
5675 case DW_AT_MIPS_tail_loop_begin
:
5676 return "DW_AT_MIPS_tail_loop_begin";
5677 case DW_AT_MIPS_epilog_begin
:
5678 return "DW_AT_MIPS_epilog_begin";
5679 case DW_AT_MIPS_loop_unroll_factor
:
5680 return "DW_AT_MIPS_loop_unroll_factor";
5681 case DW_AT_MIPS_software_pipeline_depth
:
5682 return "DW_AT_MIPS_software_pipeline_depth";
5683 case DW_AT_MIPS_linkage_name
:
5684 return "DW_AT_MIPS_linkage_name";
5685 case DW_AT_MIPS_stride
:
5686 return "DW_AT_MIPS_stride";
5687 case DW_AT_MIPS_abstract_name
:
5688 return "DW_AT_MIPS_abstract_name";
5689 case DW_AT_MIPS_clone_origin
:
5690 return "DW_AT_MIPS_clone_origin";
5691 case DW_AT_MIPS_has_inlines
:
5692 return "DW_AT_MIPS_has_inlines";
5694 case DW_AT_sf_names
:
5695 return "DW_AT_sf_names";
5696 case DW_AT_src_info
:
5697 return "DW_AT_src_info";
5698 case DW_AT_mac_info
:
5699 return "DW_AT_mac_info";
5700 case DW_AT_src_coords
:
5701 return "DW_AT_src_coords";
5702 case DW_AT_body_begin
:
5703 return "DW_AT_body_begin";
5704 case DW_AT_body_end
:
5705 return "DW_AT_body_end";
5706 case DW_AT_GNU_vector
:
5707 return "DW_AT_GNU_vector";
5709 case DW_AT_VMS_rtnbeg_pd_address
:
5710 return "DW_AT_VMS_rtnbeg_pd_address";
5713 return "DW_AT_<unknown>";
5717 /* Convert a DWARF value form code into its string name. */
5720 dwarf_form_name (unsigned int form
)
5725 return "DW_FORM_addr";
5726 case DW_FORM_block2
:
5727 return "DW_FORM_block2";
5728 case DW_FORM_block4
:
5729 return "DW_FORM_block4";
5731 return "DW_FORM_data2";
5733 return "DW_FORM_data4";
5735 return "DW_FORM_data8";
5736 case DW_FORM_string
:
5737 return "DW_FORM_string";
5739 return "DW_FORM_block";
5740 case DW_FORM_block1
:
5741 return "DW_FORM_block1";
5743 return "DW_FORM_data1";
5745 return "DW_FORM_flag";
5747 return "DW_FORM_sdata";
5749 return "DW_FORM_strp";
5751 return "DW_FORM_udata";
5752 case DW_FORM_ref_addr
:
5753 return "DW_FORM_ref_addr";
5755 return "DW_FORM_ref1";
5757 return "DW_FORM_ref2";
5759 return "DW_FORM_ref4";
5761 return "DW_FORM_ref8";
5762 case DW_FORM_ref_udata
:
5763 return "DW_FORM_ref_udata";
5764 case DW_FORM_indirect
:
5765 return "DW_FORM_indirect";
5767 return "DW_FORM_<unknown>";
5771 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5772 instance of an inlined instance of a decl which is local to an inline
5773 function, so we have to trace all of the way back through the origin chain
5774 to find out what sort of node actually served as the original seed for the
5778 decl_ultimate_origin (const_tree decl
)
5780 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
5783 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5784 nodes in the function to point to themselves; ignore that if
5785 we're trying to output the abstract instance of this function. */
5786 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
5789 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5790 most distant ancestor, this should never happen. */
5791 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
5793 return DECL_ABSTRACT_ORIGIN (decl
);
5796 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5797 of a virtual function may refer to a base class, so we check the 'this'
5801 decl_class_context (tree decl
)
5803 tree context
= NULL_TREE
;
5805 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
5806 context
= DECL_CONTEXT (decl
);
5808 context
= TYPE_MAIN_VARIANT
5809 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
5811 if (context
&& !TYPE_P (context
))
5812 context
= NULL_TREE
;
5817 /* Add an attribute/value pair to a DIE. */
5820 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
5822 /* Maybe this should be an assert? */
5826 if (die
->die_attr
== NULL
)
5827 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
5828 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
5831 static inline enum dw_val_class
5832 AT_class (dw_attr_ref a
)
5834 return a
->dw_attr_val
.val_class
;
5837 /* Add a flag value attribute to a DIE. */
5840 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
5844 attr
.dw_attr
= attr_kind
;
5845 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
5846 attr
.dw_attr_val
.v
.val_flag
= flag
;
5847 add_dwarf_attr (die
, &attr
);
5850 static inline unsigned
5851 AT_flag (dw_attr_ref a
)
5853 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
5854 return a
->dw_attr_val
.v
.val_flag
;
5857 /* Add a signed integer attribute value to a DIE. */
5860 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
5864 attr
.dw_attr
= attr_kind
;
5865 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
5866 attr
.dw_attr_val
.v
.val_int
= int_val
;
5867 add_dwarf_attr (die
, &attr
);
5870 static inline HOST_WIDE_INT
5871 AT_int (dw_attr_ref a
)
5873 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
5874 return a
->dw_attr_val
.v
.val_int
;
5877 /* Add an unsigned integer attribute value to a DIE. */
5880 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5881 unsigned HOST_WIDE_INT unsigned_val
)
5885 attr
.dw_attr
= attr_kind
;
5886 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
5887 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
5888 add_dwarf_attr (die
, &attr
);
5891 static inline unsigned HOST_WIDE_INT
5892 AT_unsigned (dw_attr_ref a
)
5894 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
5895 return a
->dw_attr_val
.v
.val_unsigned
;
5898 /* Add an unsigned double integer attribute value to a DIE. */
5901 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5902 long unsigned int val_hi
, long unsigned int val_low
)
5906 attr
.dw_attr
= attr_kind
;
5907 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
5908 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
5909 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
5910 add_dwarf_attr (die
, &attr
);
5913 /* Add a floating point attribute value to a DIE and return it. */
5916 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5917 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
5921 attr
.dw_attr
= attr_kind
;
5922 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
5923 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
5924 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
5925 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
5926 add_dwarf_attr (die
, &attr
);
5929 /* Hash and equality functions for debug_str_hash. */
5932 debug_str_do_hash (const void *x
)
5934 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
5938 debug_str_eq (const void *x1
, const void *x2
)
5940 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
5941 (const char *)x2
) == 0;
5944 static struct indirect_string_node
*
5945 find_AT_string (const char *str
)
5947 struct indirect_string_node
*node
;
5950 if (! debug_str_hash
)
5951 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
5952 debug_str_eq
, NULL
);
5954 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
5955 htab_hash_string (str
), INSERT
);
5958 node
= (struct indirect_string_node
*)
5959 ggc_alloc_cleared (sizeof (struct indirect_string_node
));
5960 node
->str
= ggc_strdup (str
);
5964 node
= (struct indirect_string_node
*) *slot
;
5970 /* Add a string attribute value to a DIE. */
5973 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
5976 struct indirect_string_node
*node
;
5978 node
= find_AT_string (str
);
5980 attr
.dw_attr
= attr_kind
;
5981 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
5982 attr
.dw_attr_val
.v
.val_str
= node
;
5983 add_dwarf_attr (die
, &attr
);
5986 static inline const char *
5987 AT_string (dw_attr_ref a
)
5989 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5990 return a
->dw_attr_val
.v
.val_str
->str
;
5993 /* Find out whether a string should be output inline in DIE
5994 or out-of-line in .debug_str section. */
5996 static enum dwarf_form
5997 AT_string_form (dw_attr_ref a
)
5999 struct indirect_string_node
*node
;
6003 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
6005 node
= a
->dw_attr_val
.v
.val_str
;
6009 len
= strlen (node
->str
) + 1;
6011 /* If the string is shorter or equal to the size of the reference, it is
6012 always better to put it inline. */
6013 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
6014 return node
->form
= DW_FORM_string
;
6016 /* If we cannot expect the linker to merge strings in .debug_str
6017 section, only put it into .debug_str if it is worth even in this
6019 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
6020 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
6021 return node
->form
= DW_FORM_string
;
6023 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
6024 ++dw2_string_counter
;
6025 node
->label
= xstrdup (label
);
6027 return node
->form
= DW_FORM_strp
;
6030 /* Add a DIE reference attribute value to a DIE. */
6033 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
6037 attr
.dw_attr
= attr_kind
;
6038 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
6039 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
6040 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
6041 add_dwarf_attr (die
, &attr
);
6044 /* Add an AT_specification attribute to a DIE, and also make the back
6045 pointer from the specification to the definition. */
6048 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
6050 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
6051 gcc_assert (!targ_die
->die_definition
);
6052 targ_die
->die_definition
= die
;
6055 static inline dw_die_ref
6056 AT_ref (dw_attr_ref a
)
6058 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6059 return a
->dw_attr_val
.v
.val_die_ref
.die
;
6063 AT_ref_external (dw_attr_ref a
)
6065 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
6066 return a
->dw_attr_val
.v
.val_die_ref
.external
;
6072 set_AT_ref_external (dw_attr_ref a
, int i
)
6074 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6075 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
6078 /* Add an FDE reference attribute value to a DIE. */
6081 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
6085 attr
.dw_attr
= attr_kind
;
6086 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
6087 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
6088 add_dwarf_attr (die
, &attr
);
6091 /* Add a location description attribute value to a DIE. */
6094 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
6098 attr
.dw_attr
= attr_kind
;
6099 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
6100 attr
.dw_attr_val
.v
.val_loc
= loc
;
6101 add_dwarf_attr (die
, &attr
);
6104 static inline dw_loc_descr_ref
6105 AT_loc (dw_attr_ref a
)
6107 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
6108 return a
->dw_attr_val
.v
.val_loc
;
6112 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
6116 attr
.dw_attr
= attr_kind
;
6117 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
6118 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
6119 add_dwarf_attr (die
, &attr
);
6120 have_location_lists
= true;
6123 static inline dw_loc_list_ref
6124 AT_loc_list (dw_attr_ref a
)
6126 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
6127 return a
->dw_attr_val
.v
.val_loc_list
;
6130 /* Add an address constant attribute value to a DIE. */
6133 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
6137 attr
.dw_attr
= attr_kind
;
6138 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
6139 attr
.dw_attr_val
.v
.val_addr
= addr
;
6140 add_dwarf_attr (die
, &attr
);
6143 /* Get the RTX from to an address DIE attribute. */
6146 AT_addr (dw_attr_ref a
)
6148 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
6149 return a
->dw_attr_val
.v
.val_addr
;
6152 /* Add a file attribute value to a DIE. */
6155 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6156 struct dwarf_file_data
*fd
)
6160 attr
.dw_attr
= attr_kind
;
6161 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
6162 attr
.dw_attr_val
.v
.val_file
= fd
;
6163 add_dwarf_attr (die
, &attr
);
6166 /* Get the dwarf_file_data from a file DIE attribute. */
6168 static inline struct dwarf_file_data
*
6169 AT_file (dw_attr_ref a
)
6171 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
6172 return a
->dw_attr_val
.v
.val_file
;
6175 /* Add a label identifier attribute value to a DIE. */
6178 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
6182 attr
.dw_attr
= attr_kind
;
6183 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
6184 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
6185 add_dwarf_attr (die
, &attr
);
6188 /* Add a section offset attribute value to a DIE, an offset into the
6189 debug_line section. */
6192 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6197 attr
.dw_attr
= attr_kind
;
6198 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
6199 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6200 add_dwarf_attr (die
, &attr
);
6203 /* Add a section offset attribute value to a DIE, an offset into the
6204 debug_macinfo section. */
6207 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6212 attr
.dw_attr
= attr_kind
;
6213 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
6214 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6215 add_dwarf_attr (die
, &attr
);
6218 /* Add an offset attribute value to a DIE. */
6221 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6222 unsigned HOST_WIDE_INT offset
)
6226 attr
.dw_attr
= attr_kind
;
6227 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
6228 attr
.dw_attr_val
.v
.val_offset
= offset
;
6229 add_dwarf_attr (die
, &attr
);
6232 /* Add an range_list attribute value to a DIE. */
6235 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6236 long unsigned int offset
)
6240 attr
.dw_attr
= attr_kind
;
6241 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
6242 attr
.dw_attr_val
.v
.val_offset
= offset
;
6243 add_dwarf_attr (die
, &attr
);
6246 static inline const char *
6247 AT_lbl (dw_attr_ref a
)
6249 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
6250 || AT_class (a
) == dw_val_class_lineptr
6251 || AT_class (a
) == dw_val_class_macptr
));
6252 return a
->dw_attr_val
.v
.val_lbl_id
;
6255 /* Get the attribute of type attr_kind. */
6258 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6262 dw_die_ref spec
= NULL
;
6267 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6268 if (a
->dw_attr
== attr_kind
)
6270 else if (a
->dw_attr
== DW_AT_specification
6271 || a
->dw_attr
== DW_AT_abstract_origin
)
6275 return get_AT (spec
, attr_kind
);
6280 /* Return the "low pc" attribute value, typically associated with a subprogram
6281 DIE. Return null if the "low pc" attribute is either not present, or if it
6282 cannot be represented as an assembler label identifier. */
6284 static inline const char *
6285 get_AT_low_pc (dw_die_ref die
)
6287 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
6289 return a
? AT_lbl (a
) : NULL
;
6292 /* Return the "high pc" attribute value, typically associated with a subprogram
6293 DIE. Return null if the "high pc" attribute is either not present, or if it
6294 cannot be represented as an assembler label identifier. */
6296 static inline const char *
6297 get_AT_hi_pc (dw_die_ref die
)
6299 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
6301 return a
? AT_lbl (a
) : NULL
;
6304 /* Return the value of the string attribute designated by ATTR_KIND, or
6305 NULL if it is not present. */
6307 static inline const char *
6308 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6310 dw_attr_ref a
= get_AT (die
, attr_kind
);
6312 return a
? AT_string (a
) : NULL
;
6315 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6316 if it is not present. */
6319 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6321 dw_attr_ref a
= get_AT (die
, attr_kind
);
6323 return a
? AT_flag (a
) : 0;
6326 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6327 if it is not present. */
6329 static inline unsigned
6330 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6332 dw_attr_ref a
= get_AT (die
, attr_kind
);
6334 return a
? AT_unsigned (a
) : 0;
6337 static inline dw_die_ref
6338 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6340 dw_attr_ref a
= get_AT (die
, attr_kind
);
6342 return a
? AT_ref (a
) : NULL
;
6345 static inline struct dwarf_file_data
*
6346 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6348 dw_attr_ref a
= get_AT (die
, attr_kind
);
6350 return a
? AT_file (a
) : NULL
;
6353 /* Return TRUE if the language is C or C++. */
6358 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6360 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
6361 || lang
== DW_LANG_C99
6362 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
6365 /* Return TRUE if the language is C++. */
6370 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6372 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
6375 /* Return TRUE if the language is Fortran. */
6380 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6382 return (lang
== DW_LANG_Fortran77
6383 || lang
== DW_LANG_Fortran90
6384 || lang
== DW_LANG_Fortran95
);
6387 /* Return TRUE if the language is Java. */
6392 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6394 return lang
== DW_LANG_Java
;
6397 /* Return TRUE if the language is Ada. */
6402 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6404 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
6407 /* Remove the specified attribute if present. */
6410 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6418 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6419 if (a
->dw_attr
== attr_kind
)
6421 if (AT_class (a
) == dw_val_class_str
)
6422 if (a
->dw_attr_val
.v
.val_str
->refcount
)
6423 a
->dw_attr_val
.v
.val_str
->refcount
--;
6425 /* VEC_ordered_remove should help reduce the number of abbrevs
6427 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
6432 /* Remove CHILD from its parent. PREV must have the property that
6433 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6436 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
6438 gcc_assert (child
->die_parent
== prev
->die_parent
);
6439 gcc_assert (prev
->die_sib
== child
);
6442 gcc_assert (child
->die_parent
->die_child
== child
);
6446 prev
->die_sib
= child
->die_sib
;
6447 if (child
->die_parent
->die_child
== child
)
6448 child
->die_parent
->die_child
= prev
;
6451 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6455 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
6461 dw_die_ref prev
= c
;
6463 while (c
->die_tag
== tag
)
6465 remove_child_with_prev (c
, prev
);
6466 /* Might have removed every child. */
6467 if (c
== c
->die_sib
)
6471 } while (c
!= die
->die_child
);
6474 /* Add a CHILD_DIE as the last child of DIE. */
6477 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
6479 /* FIXME this should probably be an assert. */
6480 if (! die
|| ! child_die
)
6482 gcc_assert (die
!= child_die
);
6484 child_die
->die_parent
= die
;
6487 child_die
->die_sib
= die
->die_child
->die_sib
;
6488 die
->die_child
->die_sib
= child_die
;
6491 child_die
->die_sib
= child_die
;
6492 die
->die_child
= child_die
;
6495 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6496 is the specification, to the end of PARENT's list of children.
6497 This is done by removing and re-adding it. */
6500 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
6504 /* We want the declaration DIE from inside the class, not the
6505 specification DIE at toplevel. */
6506 if (child
->die_parent
!= parent
)
6508 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
6514 gcc_assert (child
->die_parent
== parent
6515 || (child
->die_parent
6516 == get_AT_ref (parent
, DW_AT_specification
)));
6518 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
6519 if (p
->die_sib
== child
)
6521 remove_child_with_prev (child
, p
);
6525 add_child_die (parent
, child
);
6528 /* Return a pointer to a newly created DIE node. */
6530 static inline dw_die_ref
6531 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
6533 dw_die_ref die
= GGC_CNEW (die_node
);
6535 die
->die_tag
= tag_value
;
6537 if (parent_die
!= NULL
)
6538 add_child_die (parent_die
, die
);
6541 limbo_die_node
*limbo_node
;
6543 limbo_node
= GGC_CNEW (limbo_die_node
);
6544 limbo_node
->die
= die
;
6545 limbo_node
->created_for
= t
;
6546 limbo_node
->next
= limbo_die_list
;
6547 limbo_die_list
= limbo_node
;
6553 /* Return the DIE associated with the given type specifier. */
6555 static inline dw_die_ref
6556 lookup_type_die (tree type
)
6558 return TYPE_SYMTAB_DIE (type
);
6561 /* Equate a DIE to a given type specifier. */
6564 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
6566 TYPE_SYMTAB_DIE (type
) = type_die
;
6569 /* Returns a hash value for X (which really is a die_struct). */
6572 decl_die_table_hash (const void *x
)
6574 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
6577 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6580 decl_die_table_eq (const void *x
, const void *y
)
6582 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6585 /* Return the DIE associated with a given declaration. */
6587 static inline dw_die_ref
6588 lookup_decl_die (tree decl
)
6590 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
6593 /* Returns a hash value for X (which really is a var_loc_list). */
6596 decl_loc_table_hash (const void *x
)
6598 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
6601 /* Return nonzero if decl_id of var_loc_list X is the same as
6605 decl_loc_table_eq (const void *x
, const void *y
)
6607 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6610 /* Return the var_loc list associated with a given declaration. */
6612 static inline var_loc_list
*
6613 lookup_decl_loc (const_tree decl
)
6615 return (var_loc_list
*)
6616 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
6619 /* Equate a DIE to a particular declaration. */
6622 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6624 unsigned int decl_id
= DECL_UID (decl
);
6627 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
6629 decl_die
->decl_id
= decl_id
;
6632 /* Add a variable location node to the linked list for DECL. */
6635 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
6637 unsigned int decl_id
= DECL_UID (decl
);
6641 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
6644 temp
= GGC_CNEW (var_loc_list
);
6645 temp
->decl_id
= decl_id
;
6649 temp
= (var_loc_list
*) *slot
;
6653 /* If the current location is the same as the end of the list,
6654 and either both or neither of the locations is uninitialized,
6655 we have nothing to do. */
6656 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
6657 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
6658 || ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6659 != NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
))
6660 && ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6661 == VAR_INIT_STATUS_UNINITIALIZED
)
6662 || (NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
)
6663 == VAR_INIT_STATUS_UNINITIALIZED
))))
6665 /* Add LOC to the end of list and update LAST. */
6666 temp
->last
->next
= loc
;
6670 /* Do not add empty location to the beginning of the list. */
6671 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
6678 /* Keep track of the number of spaces used to indent the
6679 output of the debugging routines that print the structure of
6680 the DIE internal representation. */
6681 static int print_indent
;
6683 /* Indent the line the number of spaces given by print_indent. */
6686 print_spaces (FILE *outfile
)
6688 fprintf (outfile
, "%*s", print_indent
, "");
6691 /* Print the information associated with a given DIE, and its children.
6692 This routine is a debugging aid only. */
6695 print_die (dw_die_ref die
, FILE *outfile
)
6701 print_spaces (outfile
);
6702 fprintf (outfile
, "DIE %4ld: %s\n",
6703 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6704 print_spaces (outfile
);
6705 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6706 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
6708 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6710 print_spaces (outfile
);
6711 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6713 switch (AT_class (a
))
6715 case dw_val_class_addr
:
6716 fprintf (outfile
, "address");
6718 case dw_val_class_offset
:
6719 fprintf (outfile
, "offset");
6721 case dw_val_class_loc
:
6722 fprintf (outfile
, "location descriptor");
6724 case dw_val_class_loc_list
:
6725 fprintf (outfile
, "location list -> label:%s",
6726 AT_loc_list (a
)->ll_symbol
);
6728 case dw_val_class_range_list
:
6729 fprintf (outfile
, "range list");
6731 case dw_val_class_const
:
6732 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
6734 case dw_val_class_unsigned_const
:
6735 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
6737 case dw_val_class_long_long
:
6738 fprintf (outfile
, "constant (%lu,%lu)",
6739 a
->dw_attr_val
.v
.val_long_long
.hi
,
6740 a
->dw_attr_val
.v
.val_long_long
.low
);
6742 case dw_val_class_vec
:
6743 fprintf (outfile
, "floating-point or vector constant");
6745 case dw_val_class_flag
:
6746 fprintf (outfile
, "%u", AT_flag (a
));
6748 case dw_val_class_die_ref
:
6749 if (AT_ref (a
) != NULL
)
6751 if (AT_ref (a
)->die_symbol
)
6752 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
6754 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
6757 fprintf (outfile
, "die -> <null>");
6759 case dw_val_class_lbl_id
:
6760 case dw_val_class_lineptr
:
6761 case dw_val_class_macptr
:
6762 fprintf (outfile
, "label: %s", AT_lbl (a
));
6764 case dw_val_class_str
:
6765 if (AT_string (a
) != NULL
)
6766 fprintf (outfile
, "\"%s\"", AT_string (a
));
6768 fprintf (outfile
, "<null>");
6770 case dw_val_class_file
:
6771 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
6772 AT_file (a
)->emitted_number
);
6778 fprintf (outfile
, "\n");
6781 if (die
->die_child
!= NULL
)
6784 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6787 if (print_indent
== 0)
6788 fprintf (outfile
, "\n");
6791 /* Print the contents of the source code line number correspondence table.
6792 This routine is a debugging aid only. */
6795 print_dwarf_line_table (FILE *outfile
)
6798 dw_line_info_ref line_info
;
6800 fprintf (outfile
, "\n\nDWARF source line information\n");
6801 for (i
= 1; i
< line_info_table_in_use
; i
++)
6803 line_info
= &line_info_table
[i
];
6804 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
6805 line_info
->dw_file_num
,
6806 line_info
->dw_line_num
);
6809 fprintf (outfile
, "\n\n");
6812 /* Print the information collected for a given DIE. */
6815 debug_dwarf_die (dw_die_ref die
)
6817 print_die (die
, stderr
);
6820 /* Print all DWARF information collected for the compilation unit.
6821 This routine is a debugging aid only. */
6827 print_die (comp_unit_die
, stderr
);
6828 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
6829 print_dwarf_line_table (stderr
);
6832 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6833 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6834 DIE that marks the start of the DIEs for this include file. */
6837 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6839 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6840 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6842 new_unit
->die_sib
= old_unit
;
6846 /* Close an include-file CU and reopen the enclosing one. */
6849 pop_compile_unit (dw_die_ref old_unit
)
6851 dw_die_ref new_unit
= old_unit
->die_sib
;
6853 old_unit
->die_sib
= NULL
;
6857 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6858 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6860 /* Calculate the checksum of a location expression. */
6863 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6865 CHECKSUM (loc
->dw_loc_opc
);
6866 CHECKSUM (loc
->dw_loc_oprnd1
);
6867 CHECKSUM (loc
->dw_loc_oprnd2
);
6870 /* Calculate the checksum of an attribute. */
6873 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
6875 dw_loc_descr_ref loc
;
6878 CHECKSUM (at
->dw_attr
);
6880 /* We don't care that this was compiled with a different compiler
6881 snapshot; if the output is the same, that's what matters. */
6882 if (at
->dw_attr
== DW_AT_producer
)
6885 switch (AT_class (at
))
6887 case dw_val_class_const
:
6888 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6890 case dw_val_class_unsigned_const
:
6891 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6893 case dw_val_class_long_long
:
6894 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
6896 case dw_val_class_vec
:
6897 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6899 case dw_val_class_flag
:
6900 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6902 case dw_val_class_str
:
6903 CHECKSUM_STRING (AT_string (at
));
6906 case dw_val_class_addr
:
6908 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6909 CHECKSUM_STRING (XSTR (r
, 0));
6912 case dw_val_class_offset
:
6913 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6916 case dw_val_class_loc
:
6917 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6918 loc_checksum (loc
, ctx
);
6921 case dw_val_class_die_ref
:
6922 die_checksum (AT_ref (at
), ctx
, mark
);
6925 case dw_val_class_fde_ref
:
6926 case dw_val_class_lbl_id
:
6927 case dw_val_class_lineptr
:
6928 case dw_val_class_macptr
:
6931 case dw_val_class_file
:
6932 CHECKSUM_STRING (AT_file (at
)->filename
);
6940 /* Calculate the checksum of a DIE. */
6943 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6949 /* To avoid infinite recursion. */
6952 CHECKSUM (die
->die_mark
);
6955 die
->die_mark
= ++(*mark
);
6957 CHECKSUM (die
->die_tag
);
6959 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6960 attr_checksum (a
, ctx
, mark
);
6962 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6966 #undef CHECKSUM_STRING
6968 /* Do the location expressions look same? */
6970 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6972 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6973 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6974 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6977 /* Do the values look the same? */
6979 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6981 dw_loc_descr_ref loc1
, loc2
;
6984 if (v1
->val_class
!= v2
->val_class
)
6987 switch (v1
->val_class
)
6989 case dw_val_class_const
:
6990 return v1
->v
.val_int
== v2
->v
.val_int
;
6991 case dw_val_class_unsigned_const
:
6992 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6993 case dw_val_class_long_long
:
6994 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6995 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6996 case dw_val_class_vec
:
6997 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6998 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7000 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7001 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7004 case dw_val_class_flag
:
7005 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7006 case dw_val_class_str
:
7007 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7009 case dw_val_class_addr
:
7010 r1
= v1
->v
.val_addr
;
7011 r2
= v2
->v
.val_addr
;
7012 if (GET_CODE (r1
) != GET_CODE (r2
))
7014 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
7015 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
7017 case dw_val_class_offset
:
7018 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7020 case dw_val_class_loc
:
7021 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7023 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7024 if (!same_loc_p (loc1
, loc2
, mark
))
7026 return !loc1
&& !loc2
;
7028 case dw_val_class_die_ref
:
7029 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7031 case dw_val_class_fde_ref
:
7032 case dw_val_class_lbl_id
:
7033 case dw_val_class_lineptr
:
7034 case dw_val_class_macptr
:
7037 case dw_val_class_file
:
7038 return v1
->v
.val_file
== v2
->v
.val_file
;
7045 /* Do the attributes look the same? */
7048 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
7050 if (at1
->dw_attr
!= at2
->dw_attr
)
7053 /* We don't care that this was compiled with a different compiler
7054 snapshot; if the output is the same, that's what matters. */
7055 if (at1
->dw_attr
== DW_AT_producer
)
7058 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7061 /* Do the dies look the same? */
7064 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7070 /* To avoid infinite recursion. */
7072 return die1
->die_mark
== die2
->die_mark
;
7073 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7075 if (die1
->die_tag
!= die2
->die_tag
)
7078 if (VEC_length (dw_attr_node
, die1
->die_attr
)
7079 != VEC_length (dw_attr_node
, die2
->die_attr
))
7082 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
7083 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
7086 c1
= die1
->die_child
;
7087 c2
= die2
->die_child
;
7096 if (!same_die_p (c1
, c2
, mark
))
7100 if (c1
== die1
->die_child
)
7102 if (c2
== die2
->die_child
)
7112 /* Do the dies look the same? Wrapper around same_die_p. */
7115 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7118 int ret
= same_die_p (die1
, die2
, &mark
);
7120 unmark_all_dies (die1
);
7121 unmark_all_dies (die2
);
7126 /* The prefix to attach to symbols on DIEs in the current comdat debug
7128 static char *comdat_symbol_id
;
7130 /* The index of the current symbol within the current comdat CU. */
7131 static unsigned int comdat_symbol_number
;
7133 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7134 children, and set comdat_symbol_id accordingly. */
7137 compute_section_prefix (dw_die_ref unit_die
)
7139 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7140 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7141 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7144 unsigned char checksum
[16];
7147 /* Compute the checksum of the DIE, then append part of it as hex digits to
7148 the name filename of the unit. */
7150 md5_init_ctx (&ctx
);
7152 die_checksum (unit_die
, &ctx
, &mark
);
7153 unmark_all_dies (unit_die
);
7154 md5_finish_ctx (&ctx
, checksum
);
7156 sprintf (name
, "%s.", base
);
7157 clean_symbol_name (name
);
7159 p
= name
+ strlen (name
);
7160 for (i
= 0; i
< 4; i
++)
7162 sprintf (p
, "%.2x", checksum
[i
]);
7166 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
7167 comdat_symbol_number
= 0;
7170 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7173 is_type_die (dw_die_ref die
)
7175 switch (die
->die_tag
)
7177 case DW_TAG_array_type
:
7178 case DW_TAG_class_type
:
7179 case DW_TAG_interface_type
:
7180 case DW_TAG_enumeration_type
:
7181 case DW_TAG_pointer_type
:
7182 case DW_TAG_reference_type
:
7183 case DW_TAG_string_type
:
7184 case DW_TAG_structure_type
:
7185 case DW_TAG_subroutine_type
:
7186 case DW_TAG_union_type
:
7187 case DW_TAG_ptr_to_member_type
:
7188 case DW_TAG_set_type
:
7189 case DW_TAG_subrange_type
:
7190 case DW_TAG_base_type
:
7191 case DW_TAG_const_type
:
7192 case DW_TAG_file_type
:
7193 case DW_TAG_packed_type
:
7194 case DW_TAG_volatile_type
:
7195 case DW_TAG_typedef
:
7202 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7203 Basically, we want to choose the bits that are likely to be shared between
7204 compilations (types) and leave out the bits that are specific to individual
7205 compilations (functions). */
7208 is_comdat_die (dw_die_ref c
)
7210 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7211 we do for stabs. The advantage is a greater likelihood of sharing between
7212 objects that don't include headers in the same order (and therefore would
7213 put the base types in a different comdat). jason 8/28/00 */
7215 if (c
->die_tag
== DW_TAG_base_type
)
7218 if (c
->die_tag
== DW_TAG_pointer_type
7219 || c
->die_tag
== DW_TAG_reference_type
7220 || c
->die_tag
== DW_TAG_const_type
7221 || c
->die_tag
== DW_TAG_volatile_type
)
7223 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7225 return t
? is_comdat_die (t
) : 0;
7228 return is_type_die (c
);
7231 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7232 compilation unit. */
7235 is_symbol_die (dw_die_ref c
)
7237 return (is_type_die (c
)
7238 || (get_AT (c
, DW_AT_declaration
)
7239 && !get_AT (c
, DW_AT_specification
))
7240 || c
->die_tag
== DW_TAG_namespace
7241 || c
->die_tag
== DW_TAG_module
);
7245 gen_internal_sym (const char *prefix
)
7249 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7250 return xstrdup (buf
);
7253 /* Assign symbols to all worthy DIEs under DIE. */
7256 assign_symbol_names (dw_die_ref die
)
7260 if (is_symbol_die (die
))
7262 if (comdat_symbol_id
)
7264 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7266 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7267 comdat_symbol_id
, comdat_symbol_number
++);
7268 die
->die_symbol
= xstrdup (p
);
7271 die
->die_symbol
= gen_internal_sym ("LDIE");
7274 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7277 struct cu_hash_table_entry
7280 unsigned min_comdat_num
, max_comdat_num
;
7281 struct cu_hash_table_entry
*next
;
7284 /* Routines to manipulate hash table of CUs. */
7286 htab_cu_hash (const void *of
)
7288 const struct cu_hash_table_entry
*const entry
=
7289 (const struct cu_hash_table_entry
*) of
;
7291 return htab_hash_string (entry
->cu
->die_symbol
);
7295 htab_cu_eq (const void *of1
, const void *of2
)
7297 const struct cu_hash_table_entry
*const entry1
=
7298 (const struct cu_hash_table_entry
*) of1
;
7299 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7301 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
7305 htab_cu_del (void *what
)
7307 struct cu_hash_table_entry
*next
,
7308 *entry
= (struct cu_hash_table_entry
*) what
;
7318 /* Check whether we have already seen this CU and set up SYM_NUM
7321 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
7323 struct cu_hash_table_entry dummy
;
7324 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7326 dummy
.max_comdat_num
= 0;
7328 slot
= (struct cu_hash_table_entry
**)
7329 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7333 for (; entry
; last
= entry
, entry
= entry
->next
)
7335 if (same_die_p_wrap (cu
, entry
->cu
))
7341 *sym_num
= entry
->min_comdat_num
;
7345 entry
= XCNEW (struct cu_hash_table_entry
);
7347 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7348 entry
->next
= *slot
;
7354 /* Record SYM_NUM to record of CU in HTABLE. */
7356 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
7358 struct cu_hash_table_entry
**slot
, *entry
;
7360 slot
= (struct cu_hash_table_entry
**)
7361 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7365 entry
->max_comdat_num
= sym_num
;
7368 /* Traverse the DIE (which is always comp_unit_die), and set up
7369 additional compilation units for each of the include files we see
7370 bracketed by BINCL/EINCL. */
7373 break_out_includes (dw_die_ref die
)
7376 dw_die_ref unit
= NULL
;
7377 limbo_die_node
*node
, **pnode
;
7378 htab_t cu_hash_table
;
7382 dw_die_ref prev
= c
;
7384 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7385 || (unit
&& is_comdat_die (c
)))
7387 dw_die_ref next
= c
->die_sib
;
7389 /* This DIE is for a secondary CU; remove it from the main one. */
7390 remove_child_with_prev (c
, prev
);
7392 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7393 unit
= push_new_compile_unit (unit
, c
);
7394 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7395 unit
= pop_compile_unit (unit
);
7397 add_child_die (unit
, c
);
7399 if (c
== die
->die_child
)
7402 } while (c
!= die
->die_child
);
7405 /* We can only use this in debugging, since the frontend doesn't check
7406 to make sure that we leave every include file we enter. */
7410 assign_symbol_names (die
);
7411 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
7412 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7418 compute_section_prefix (node
->die
);
7419 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
7420 &comdat_symbol_number
);
7421 assign_symbol_names (node
->die
);
7423 *pnode
= node
->next
;
7426 pnode
= &node
->next
;
7427 record_comdat_symbol_number (node
->die
, cu_hash_table
,
7428 comdat_symbol_number
);
7431 htab_delete (cu_hash_table
);
7434 /* Traverse the DIE and add a sibling attribute if it may have the
7435 effect of speeding up access to siblings. To save some space,
7436 avoid generating sibling attributes for DIE's without children. */
7439 add_sibling_attributes (dw_die_ref die
)
7443 if (! die
->die_child
)
7446 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7447 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7449 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7452 /* Output all location lists for the DIE and its children. */
7455 output_location_lists (dw_die_ref die
)
7461 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7462 if (AT_class (a
) == dw_val_class_loc_list
)
7463 output_loc_list (AT_loc_list (a
));
7465 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7468 /* The format of each DIE (and its attribute value pairs) is encoded in an
7469 abbreviation table. This routine builds the abbreviation table and assigns
7470 a unique abbreviation id for each abbreviation entry. The children of each
7471 die are visited recursively. */
7474 build_abbrev_table (dw_die_ref die
)
7476 unsigned long abbrev_id
;
7477 unsigned int n_alloc
;
7482 /* Scan the DIE references, and mark as external any that refer to
7483 DIEs from other CUs (i.e. those which are not marked). */
7484 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7485 if (AT_class (a
) == dw_val_class_die_ref
7486 && AT_ref (a
)->die_mark
== 0)
7488 gcc_assert (AT_ref (a
)->die_symbol
);
7490 set_AT_ref_external (a
, 1);
7493 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7495 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7496 dw_attr_ref die_a
, abbrev_a
;
7500 if (abbrev
->die_tag
!= die
->die_tag
)
7502 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7505 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7506 != VEC_length (dw_attr_node
, die
->die_attr
))
7509 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
7511 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7512 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7513 || (value_format (abbrev_a
) != value_format (die_a
)))
7523 if (abbrev_id
>= abbrev_die_table_in_use
)
7525 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7527 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7528 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7531 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7532 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7533 abbrev_die_table_allocated
= n_alloc
;
7536 ++abbrev_die_table_in_use
;
7537 abbrev_die_table
[abbrev_id
] = die
;
7540 die
->die_abbrev
= abbrev_id
;
7541 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7544 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7547 constant_size (unsigned HOST_WIDE_INT value
)
7554 log
= floor_log2 (value
);
7557 log
= 1 << (floor_log2 (log
) + 1);
7562 /* Return the size of a DIE as it is represented in the
7563 .debug_info section. */
7565 static unsigned long
7566 size_of_die (dw_die_ref die
)
7568 unsigned long size
= 0;
7572 size
+= size_of_uleb128 (die
->die_abbrev
);
7573 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7575 switch (AT_class (a
))
7577 case dw_val_class_addr
:
7578 size
+= DWARF2_ADDR_SIZE
;
7580 case dw_val_class_offset
:
7581 size
+= DWARF_OFFSET_SIZE
;
7583 case dw_val_class_loc
:
7585 unsigned long lsize
= size_of_locs (AT_loc (a
));
7588 size
+= constant_size (lsize
);
7592 case dw_val_class_loc_list
:
7593 size
+= DWARF_OFFSET_SIZE
;
7595 case dw_val_class_range_list
:
7596 size
+= DWARF_OFFSET_SIZE
;
7598 case dw_val_class_const
:
7599 size
+= size_of_sleb128 (AT_int (a
));
7601 case dw_val_class_unsigned_const
:
7602 size
+= constant_size (AT_unsigned (a
));
7604 case dw_val_class_long_long
:
7605 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
7607 case dw_val_class_vec
:
7608 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7609 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7610 + a
->dw_attr_val
.v
.val_vec
.length
7611 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7613 case dw_val_class_flag
:
7616 case dw_val_class_die_ref
:
7617 if (AT_ref_external (a
))
7618 size
+= DWARF2_ADDR_SIZE
;
7620 size
+= DWARF_OFFSET_SIZE
;
7622 case dw_val_class_fde_ref
:
7623 size
+= DWARF_OFFSET_SIZE
;
7625 case dw_val_class_lbl_id
:
7626 size
+= DWARF2_ADDR_SIZE
;
7628 case dw_val_class_lineptr
:
7629 case dw_val_class_macptr
:
7630 size
+= DWARF_OFFSET_SIZE
;
7632 case dw_val_class_str
:
7633 if (AT_string_form (a
) == DW_FORM_strp
)
7634 size
+= DWARF_OFFSET_SIZE
;
7636 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7638 case dw_val_class_file
:
7639 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7649 /* Size the debugging information associated with a given DIE. Visits the
7650 DIE's children recursively. Updates the global variable next_die_offset, on
7651 each time through. Uses the current value of next_die_offset to update the
7652 die_offset field in each DIE. */
7655 calc_die_sizes (dw_die_ref die
)
7659 die
->die_offset
= next_die_offset
;
7660 next_die_offset
+= size_of_die (die
);
7662 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7664 if (die
->die_child
!= NULL
)
7665 /* Count the null byte used to terminate sibling lists. */
7666 next_die_offset
+= 1;
7669 /* Set the marks for a die and its children. We do this so
7670 that we know whether or not a reference needs to use FORM_ref_addr; only
7671 DIEs in the same CU will be marked. We used to clear out the offset
7672 and use that as the flag, but ran into ordering problems. */
7675 mark_dies (dw_die_ref die
)
7679 gcc_assert (!die
->die_mark
);
7682 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7685 /* Clear the marks for a die and its children. */
7688 unmark_dies (dw_die_ref die
)
7692 gcc_assert (die
->die_mark
);
7695 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7698 /* Clear the marks for a die, its children and referred dies. */
7701 unmark_all_dies (dw_die_ref die
)
7711 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7713 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7714 if (AT_class (a
) == dw_val_class_die_ref
)
7715 unmark_all_dies (AT_ref (a
));
7718 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7719 generated for the compilation unit. */
7721 static unsigned long
7722 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7728 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7729 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
7730 if (names
!= pubtype_table
7731 || p
->die
->die_offset
!= 0
7732 || !flag_eliminate_unused_debug_types
)
7733 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7735 size
+= DWARF_OFFSET_SIZE
;
7739 /* Return the size of the information in the .debug_aranges section. */
7741 static unsigned long
7742 size_of_aranges (void)
7746 size
= DWARF_ARANGES_HEADER_SIZE
;
7748 /* Count the address/length pair for this compilation unit. */
7749 if (text_section_used
)
7750 size
+= 2 * DWARF2_ADDR_SIZE
;
7751 if (cold_text_section_used
)
7752 size
+= 2 * DWARF2_ADDR_SIZE
;
7753 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
7755 /* Count the two zero words used to terminated the address range table. */
7756 size
+= 2 * DWARF2_ADDR_SIZE
;
7760 /* Select the encoding of an attribute value. */
7762 static enum dwarf_form
7763 value_format (dw_attr_ref a
)
7765 switch (a
->dw_attr_val
.val_class
)
7767 case dw_val_class_addr
:
7768 return DW_FORM_addr
;
7769 case dw_val_class_range_list
:
7770 case dw_val_class_offset
:
7771 case dw_val_class_loc_list
:
7772 switch (DWARF_OFFSET_SIZE
)
7775 return DW_FORM_data4
;
7777 return DW_FORM_data8
;
7781 case dw_val_class_loc
:
7782 switch (constant_size (size_of_locs (AT_loc (a
))))
7785 return DW_FORM_block1
;
7787 return DW_FORM_block2
;
7791 case dw_val_class_const
:
7792 return DW_FORM_sdata
;
7793 case dw_val_class_unsigned_const
:
7794 switch (constant_size (AT_unsigned (a
)))
7797 return DW_FORM_data1
;
7799 return DW_FORM_data2
;
7801 return DW_FORM_data4
;
7803 return DW_FORM_data8
;
7807 case dw_val_class_long_long
:
7808 return DW_FORM_block1
;
7809 case dw_val_class_vec
:
7810 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7811 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7814 return DW_FORM_block1
;
7816 return DW_FORM_block2
;
7818 return DW_FORM_block4
;
7822 case dw_val_class_flag
:
7823 return DW_FORM_flag
;
7824 case dw_val_class_die_ref
:
7825 if (AT_ref_external (a
))
7826 return DW_FORM_ref_addr
;
7829 case dw_val_class_fde_ref
:
7830 return DW_FORM_data
;
7831 case dw_val_class_lbl_id
:
7832 return DW_FORM_addr
;
7833 case dw_val_class_lineptr
:
7834 case dw_val_class_macptr
:
7835 return DW_FORM_data
;
7836 case dw_val_class_str
:
7837 return AT_string_form (a
);
7838 case dw_val_class_file
:
7839 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7842 return DW_FORM_data1
;
7844 return DW_FORM_data2
;
7846 return DW_FORM_data4
;
7856 /* Output the encoding of an attribute value. */
7859 output_value_format (dw_attr_ref a
)
7861 enum dwarf_form form
= value_format (a
);
7863 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7866 /* Output the .debug_abbrev section which defines the DIE abbreviation
7870 output_abbrev_section (void)
7872 unsigned long abbrev_id
;
7874 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7876 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7880 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7881 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7882 dwarf_tag_name (abbrev
->die_tag
));
7884 if (abbrev
->die_child
!= NULL
)
7885 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7887 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7889 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7892 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7893 dwarf_attr_name (a_attr
->dw_attr
));
7894 output_value_format (a_attr
);
7897 dw2_asm_output_data (1, 0, NULL
);
7898 dw2_asm_output_data (1, 0, NULL
);
7901 /* Terminate the table. */
7902 dw2_asm_output_data (1, 0, NULL
);
7905 /* Output a symbol we can use to refer to this DIE from another CU. */
7908 output_die_symbol (dw_die_ref die
)
7910 char *sym
= die
->die_symbol
;
7915 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7916 /* We make these global, not weak; if the target doesn't support
7917 .linkonce, it doesn't support combining the sections, so debugging
7919 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7921 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7924 /* Return a new location list, given the begin and end range, and the
7925 expression. gensym tells us whether to generate a new internal symbol for
7926 this location list node, which is done for the head of the list only. */
7928 static inline dw_loc_list_ref
7929 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7930 const char *section
, unsigned int gensym
)
7932 dw_loc_list_ref retlist
= GGC_CNEW (dw_loc_list_node
);
7934 retlist
->begin
= begin
;
7936 retlist
->expr
= expr
;
7937 retlist
->section
= section
;
7939 retlist
->ll_symbol
= gen_internal_sym ("LLST");
7944 /* Add a location description expression to a location list. */
7947 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
7948 const char *begin
, const char *end
,
7949 const char *section
)
7953 /* Find the end of the chain. */
7954 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
7957 /* Add a new location list node to the list. */
7958 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
7961 /* Output the location list given to us. */
7964 output_loc_list (dw_loc_list_ref list_head
)
7966 dw_loc_list_ref curr
= list_head
;
7968 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7970 /* Walk the location list, and output each range + expression. */
7971 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7974 /* Don't output an entry that starts and ends at the same address. */
7975 if (strcmp (curr
->begin
, curr
->end
) == 0)
7977 if (!have_multiple_function_sections
)
7979 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7980 "Location list begin address (%s)",
7981 list_head
->ll_symbol
);
7982 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7983 "Location list end address (%s)",
7984 list_head
->ll_symbol
);
7988 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7989 "Location list begin address (%s)",
7990 list_head
->ll_symbol
);
7991 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7992 "Location list end address (%s)",
7993 list_head
->ll_symbol
);
7995 size
= size_of_locs (curr
->expr
);
7997 /* Output the block length for this list of location operations. */
7998 gcc_assert (size
<= 0xffff);
7999 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8001 output_loc_sequence (curr
->expr
);
8004 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8005 "Location list terminator begin (%s)",
8006 list_head
->ll_symbol
);
8007 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8008 "Location list terminator end (%s)",
8009 list_head
->ll_symbol
);
8012 /* Output the DIE and its attributes. Called recursively to generate
8013 the definitions of each child DIE. */
8016 output_die (dw_die_ref die
)
8023 /* If someone in another CU might refer to us, set up a symbol for
8024 them to point to. */
8025 if (die
->die_symbol
)
8026 output_die_symbol (die
);
8028 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
8029 (unsigned long)die
->die_offset
,
8030 dwarf_tag_name (die
->die_tag
));
8032 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8034 const char *name
= dwarf_attr_name (a
->dw_attr
);
8036 switch (AT_class (a
))
8038 case dw_val_class_addr
:
8039 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8042 case dw_val_class_offset
:
8043 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8047 case dw_val_class_range_list
:
8049 char *p
= strchr (ranges_section_label
, '\0');
8051 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
8052 a
->dw_attr_val
.v
.val_offset
);
8053 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8054 debug_ranges_section
, "%s", name
);
8059 case dw_val_class_loc
:
8060 size
= size_of_locs (AT_loc (a
));
8062 /* Output the block length for this list of location operations. */
8063 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8065 output_loc_sequence (AT_loc (a
));
8068 case dw_val_class_const
:
8069 /* ??? It would be slightly more efficient to use a scheme like is
8070 used for unsigned constants below, but gdb 4.x does not sign
8071 extend. Gdb 5.x does sign extend. */
8072 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8075 case dw_val_class_unsigned_const
:
8076 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
8077 AT_unsigned (a
), "%s", name
);
8080 case dw_val_class_long_long
:
8082 unsigned HOST_WIDE_INT first
, second
;
8084 dw2_asm_output_data (1,
8085 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8088 if (WORDS_BIG_ENDIAN
)
8090 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8091 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
8095 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
8096 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8099 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8100 first
, "long long constant");
8101 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8106 case dw_val_class_vec
:
8108 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8109 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8113 dw2_asm_output_data (constant_size (len
* elt_size
),
8114 len
* elt_size
, "%s", name
);
8115 if (elt_size
> sizeof (HOST_WIDE_INT
))
8120 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8123 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8124 "fp or vector constant word %u", i
);
8128 case dw_val_class_flag
:
8129 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8132 case dw_val_class_loc_list
:
8134 char *sym
= AT_loc_list (a
)->ll_symbol
;
8137 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8142 case dw_val_class_die_ref
:
8143 if (AT_ref_external (a
))
8145 char *sym
= AT_ref (a
)->die_symbol
;
8148 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
8153 gcc_assert (AT_ref (a
)->die_offset
);
8154 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8159 case dw_val_class_fde_ref
:
8163 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8164 a
->dw_attr_val
.v
.val_fde_index
* 2);
8165 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8170 case dw_val_class_lbl_id
:
8171 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8174 case dw_val_class_lineptr
:
8175 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8176 debug_line_section
, "%s", name
);
8179 case dw_val_class_macptr
:
8180 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8181 debug_macinfo_section
, "%s", name
);
8184 case dw_val_class_str
:
8185 if (AT_string_form (a
) == DW_FORM_strp
)
8186 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8187 a
->dw_attr_val
.v
.val_str
->label
,
8189 "%s: \"%s\"", name
, AT_string (a
));
8191 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8194 case dw_val_class_file
:
8196 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8198 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8199 a
->dw_attr_val
.v
.val_file
->filename
);
8208 FOR_EACH_CHILD (die
, c
, output_die (c
));
8210 /* Add null byte to terminate sibling list. */
8211 if (die
->die_child
!= NULL
)
8212 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8213 (unsigned long) die
->die_offset
);
8216 /* Output the compilation unit that appears at the beginning of the
8217 .debug_info section, and precedes the DIE descriptions. */
8220 output_compilation_unit_header (void)
8222 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8223 dw2_asm_output_data (4, 0xffffffff,
8224 "Initial length escape value indicating 64-bit DWARF extension");
8225 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8226 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8227 "Length of Compilation Unit Info");
8228 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
8229 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8230 debug_abbrev_section
,
8231 "Offset Into Abbrev. Section");
8232 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8235 /* Output the compilation unit DIE and its children. */
8238 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8240 const char *secname
;
8243 /* Unless we are outputting main CU, we may throw away empty ones. */
8244 if (!output_if_empty
&& die
->die_child
== NULL
)
8247 /* Even if there are no children of this DIE, we must output the information
8248 about the compilation unit. Otherwise, on an empty translation unit, we
8249 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8250 will then complain when examining the file. First mark all the DIEs in
8251 this CU so we know which get local refs. */
8254 build_abbrev_table (die
);
8256 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8257 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8258 calc_die_sizes (die
);
8260 oldsym
= die
->die_symbol
;
8263 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8265 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8267 die
->die_symbol
= NULL
;
8268 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8271 switch_to_section (debug_info_section
);
8273 /* Output debugging information. */
8274 output_compilation_unit_header ();
8277 /* Leave the marks on the main CU, so we can check them in
8282 die
->die_symbol
= oldsym
;
8286 /* Return the DWARF2/3 pubname associated with a decl. */
8289 dwarf2_name (tree decl
, int scope
)
8291 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8294 /* Add a new entry to .debug_pubnames if appropriate. */
8297 add_pubname_string (const char *str
, dw_die_ref die
)
8302 e
.name
= xstrdup (str
);
8303 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8307 add_pubname (tree decl
, dw_die_ref die
)
8310 if (TREE_PUBLIC (decl
))
8311 add_pubname_string (dwarf2_name (decl
, 1), die
);
8314 /* Add a new entry to .debug_pubtypes if appropriate. */
8317 add_pubtype (tree decl
, dw_die_ref die
)
8322 if ((TREE_PUBLIC (decl
)
8323 || die
->die_parent
== comp_unit_die
)
8324 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8329 if (TYPE_NAME (decl
))
8331 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
8332 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
8333 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
8334 && DECL_NAME (TYPE_NAME (decl
)))
8335 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
8337 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
8341 e
.name
= xstrdup (dwarf2_name (decl
, 1));
8343 /* If we don't have a name for the type, there's no point in adding
8345 if (e
.name
&& e
.name
[0] != '\0')
8346 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8350 /* Output the public names table used to speed up access to externally
8351 visible names; or the public types table used to find type definitions. */
8354 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8357 unsigned long pubnames_length
= size_of_pubnames (names
);
8360 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8361 dw2_asm_output_data (4, 0xffffffff,
8362 "Initial length escape value indicating 64-bit DWARF extension");
8363 if (names
== pubname_table
)
8364 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8365 "Length of Public Names Info");
8367 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8368 "Length of Public Type Names Info");
8369 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8370 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8372 "Offset of Compilation Unit Info");
8373 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8374 "Compilation Unit Length");
8376 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
8378 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8379 if (names
== pubname_table
)
8380 gcc_assert (pub
->die
->die_mark
);
8382 if (names
!= pubtype_table
8383 || pub
->die
->die_offset
!= 0
8384 || !flag_eliminate_unused_debug_types
)
8386 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
8389 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8393 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8396 /* Add a new entry to .debug_aranges if appropriate. */
8399 add_arange (tree decl
, dw_die_ref die
)
8401 if (! DECL_SECTION_NAME (decl
))
8404 if (arange_table_in_use
== arange_table_allocated
)
8406 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
8407 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
8408 arange_table_allocated
);
8409 memset (arange_table
+ arange_table_in_use
, 0,
8410 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8413 arange_table
[arange_table_in_use
++] = die
;
8416 /* Output the information that goes into the .debug_aranges table.
8417 Namely, define the beginning and ending address range of the
8418 text section generated for this compilation unit. */
8421 output_aranges (void)
8424 unsigned long aranges_length
= size_of_aranges ();
8426 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8427 dw2_asm_output_data (4, 0xffffffff,
8428 "Initial length escape value indicating 64-bit DWARF extension");
8429 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8430 "Length of Address Ranges Info");
8431 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8432 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8434 "Offset of Compilation Unit Info");
8435 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8436 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8438 /* We need to align to twice the pointer size here. */
8439 if (DWARF_ARANGES_PAD_SIZE
)
8441 /* Pad using a 2 byte words so that padding is correct for any
8443 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8444 2 * DWARF2_ADDR_SIZE
);
8445 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8446 dw2_asm_output_data (2, 0, NULL
);
8449 /* It is necessary not to output these entries if the sections were
8450 not used; if the sections were not used, the length will be 0 and
8451 the address may end up as 0 if the section is discarded by ld
8452 --gc-sections, leaving an invalid (0, 0) entry that can be
8453 confused with the terminator. */
8454 if (text_section_used
)
8456 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8457 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8458 text_section_label
, "Length");
8460 if (cold_text_section_used
)
8462 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8464 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8465 cold_text_section_label
, "Length");
8468 for (i
= 0; i
< arange_table_in_use
; i
++)
8470 dw_die_ref die
= arange_table
[i
];
8472 /* We shouldn't see aranges for DIEs outside of the main CU. */
8473 gcc_assert (die
->die_mark
);
8475 if (die
->die_tag
== DW_TAG_subprogram
)
8477 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
8479 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
8480 get_AT_low_pc (die
), "Length");
8484 /* A static variable; extract the symbol from DW_AT_location.
8485 Note that this code isn't currently hit, as we only emit
8486 aranges for functions (jason 9/23/99). */
8487 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
8488 dw_loc_descr_ref loc
;
8490 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
8493 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
8495 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
8496 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
8497 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
8498 get_AT_unsigned (die
, DW_AT_byte_size
),
8503 /* Output the terminator words. */
8504 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8505 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8508 /* Add a new entry to .debug_ranges. Return the offset at which it
8512 add_ranges_num (int num
)
8514 unsigned int in_use
= ranges_table_in_use
;
8516 if (in_use
== ranges_table_allocated
)
8518 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8519 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8520 ranges_table_allocated
);
8521 memset (ranges_table
+ ranges_table_in_use
, 0,
8522 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8525 ranges_table
[in_use
].num
= num
;
8526 ranges_table_in_use
= in_use
+ 1;
8528 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8531 /* Add a new entry to .debug_ranges corresponding to a block, or a
8532 range terminator if BLOCK is NULL. */
8535 add_ranges (const_tree block
)
8537 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8540 /* Add a new entry to .debug_ranges corresponding to a pair of
8544 add_ranges_by_labels (const char *begin
, const char *end
)
8546 unsigned int in_use
= ranges_by_label_in_use
;
8548 if (in_use
== ranges_by_label_allocated
)
8550 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8551 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8553 ranges_by_label_allocated
);
8554 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8555 RANGES_TABLE_INCREMENT
8556 * sizeof (struct dw_ranges_by_label_struct
));
8559 ranges_by_label
[in_use
].begin
= begin
;
8560 ranges_by_label
[in_use
].end
= end
;
8561 ranges_by_label_in_use
= in_use
+ 1;
8563 return add_ranges_num (-(int)in_use
- 1);
8567 output_ranges (void)
8570 static const char *const start_fmt
= "Offset 0x%x";
8571 const char *fmt
= start_fmt
;
8573 for (i
= 0; i
< ranges_table_in_use
; i
++)
8575 int block_num
= ranges_table
[i
].num
;
8579 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8580 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8582 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8583 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8585 /* If all code is in the text section, then the compilation
8586 unit base address defaults to DW_AT_low_pc, which is the
8587 base of the text section. */
8588 if (!have_multiple_function_sections
)
8590 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8592 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8593 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8594 text_section_label
, NULL
);
8597 /* Otherwise, the compilation unit base address is zero,
8598 which allows us to use absolute addresses, and not worry
8599 about whether the target supports cross-section
8603 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8604 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8605 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8611 /* Negative block_num stands for an index into ranges_by_label. */
8612 else if (block_num
< 0)
8614 int lab_idx
= - block_num
- 1;
8616 if (!have_multiple_function_sections
)
8620 /* If we ever use add_ranges_by_labels () for a single
8621 function section, all we have to do is to take out
8623 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8624 ranges_by_label
[lab_idx
].begin
,
8626 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8627 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8628 ranges_by_label
[lab_idx
].end
,
8629 text_section_label
, NULL
);
8634 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8635 ranges_by_label
[lab_idx
].begin
,
8636 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8637 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8638 ranges_by_label
[lab_idx
].end
,
8644 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8645 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8651 /* Data structure containing information about input files. */
8654 const char *path
; /* Complete file name. */
8655 const char *fname
; /* File name part. */
8656 int length
; /* Length of entire string. */
8657 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8658 int dir_idx
; /* Index in directory table. */
8661 /* Data structure containing information about directories with source
8665 const char *path
; /* Path including directory name. */
8666 int length
; /* Path length. */
8667 int prefix
; /* Index of directory entry which is a prefix. */
8668 int count
; /* Number of files in this directory. */
8669 int dir_idx
; /* Index of directory used as base. */
8672 /* Callback function for file_info comparison. We sort by looking at
8673 the directories in the path. */
8676 file_info_cmp (const void *p1
, const void *p2
)
8678 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8679 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8680 const unsigned char *cp1
;
8681 const unsigned char *cp2
;
8683 /* Take care of file names without directories. We need to make sure that
8684 we return consistent values to qsort since some will get confused if
8685 we return the same value when identical operands are passed in opposite
8686 orders. So if neither has a directory, return 0 and otherwise return
8687 1 or -1 depending on which one has the directory. */
8688 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8689 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8691 cp1
= (const unsigned char *) s1
->path
;
8692 cp2
= (const unsigned char *) s2
->path
;
8698 /* Reached the end of the first path? If so, handle like above. */
8699 if ((cp1
== (const unsigned char *) s1
->fname
)
8700 || (cp2
== (const unsigned char *) s2
->fname
))
8701 return ((cp2
== (const unsigned char *) s2
->fname
)
8702 - (cp1
== (const unsigned char *) s1
->fname
));
8704 /* Character of current path component the same? */
8705 else if (*cp1
!= *cp2
)
8710 struct file_name_acquire_data
8712 struct file_info
*files
;
8717 /* Traversal function for the hash table. */
8720 file_name_acquire (void ** slot
, void *data
)
8722 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8723 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8724 struct file_info
*fi
;
8727 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8729 if (! d
->emitted_number
)
8732 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8734 fi
= fnad
->files
+ fnad
->used_files
++;
8736 /* Skip all leading "./". */
8738 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8741 /* Create a new array entry. */
8743 fi
->length
= strlen (f
);
8746 /* Search for the file name part. */
8747 f
= strrchr (f
, DIR_SEPARATOR
);
8748 #if defined (DIR_SEPARATOR_2)
8750 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8754 if (f
== NULL
|| f
< g
)
8760 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8764 /* Output the directory table and the file name table. We try to minimize
8765 the total amount of memory needed. A heuristic is used to avoid large
8766 slowdowns with many input files. */
8769 output_file_names (void)
8771 struct file_name_acquire_data fnad
;
8773 struct file_info
*files
;
8774 struct dir_info
*dirs
;
8783 if (!last_emitted_file
)
8785 dw2_asm_output_data (1, 0, "End directory table");
8786 dw2_asm_output_data (1, 0, "End file name table");
8790 numfiles
= last_emitted_file
->emitted_number
;
8792 /* Allocate the various arrays we need. */
8793 files
= XALLOCAVEC (struct file_info
, numfiles
);
8794 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8797 fnad
.used_files
= 0;
8798 fnad
.max_files
= numfiles
;
8799 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8800 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8802 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8804 /* Find all the different directories used. */
8805 dirs
[0].path
= files
[0].path
;
8806 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8807 dirs
[0].prefix
= -1;
8809 dirs
[0].dir_idx
= 0;
8810 files
[0].dir_idx
= 0;
8813 for (i
= 1; i
< numfiles
; i
++)
8814 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8815 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8816 dirs
[ndirs
- 1].length
) == 0)
8818 /* Same directory as last entry. */
8819 files
[i
].dir_idx
= ndirs
- 1;
8820 ++dirs
[ndirs
- 1].count
;
8826 /* This is a new directory. */
8827 dirs
[ndirs
].path
= files
[i
].path
;
8828 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8829 dirs
[ndirs
].count
= 1;
8830 dirs
[ndirs
].dir_idx
= ndirs
;
8831 files
[i
].dir_idx
= ndirs
;
8833 /* Search for a prefix. */
8834 dirs
[ndirs
].prefix
= -1;
8835 for (j
= 0; j
< ndirs
; j
++)
8836 if (dirs
[j
].length
< dirs
[ndirs
].length
8837 && dirs
[j
].length
> 1
8838 && (dirs
[ndirs
].prefix
== -1
8839 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8840 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8841 dirs
[ndirs
].prefix
= j
;
8846 /* Now to the actual work. We have to find a subset of the directories which
8847 allow expressing the file name using references to the directory table
8848 with the least amount of characters. We do not do an exhaustive search
8849 where we would have to check out every combination of every single
8850 possible prefix. Instead we use a heuristic which provides nearly optimal
8851 results in most cases and never is much off. */
8852 saved
= XALLOCAVEC (int, ndirs
);
8853 savehere
= XALLOCAVEC (int, ndirs
);
8855 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8856 for (i
= 0; i
< ndirs
; i
++)
8861 /* We can always save some space for the current directory. But this
8862 does not mean it will be enough to justify adding the directory. */
8863 savehere
[i
] = dirs
[i
].length
;
8864 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8866 for (j
= i
+ 1; j
< ndirs
; j
++)
8869 if (saved
[j
] < dirs
[i
].length
)
8871 /* Determine whether the dirs[i] path is a prefix of the
8876 while (k
!= -1 && k
!= (int) i
)
8881 /* Yes it is. We can possibly save some memory by
8882 writing the filenames in dirs[j] relative to
8884 savehere
[j
] = dirs
[i
].length
;
8885 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8890 /* Check whether we can save enough to justify adding the dirs[i]
8892 if (total
> dirs
[i
].length
+ 1)
8894 /* It's worthwhile adding. */
8895 for (j
= i
; j
< ndirs
; j
++)
8896 if (savehere
[j
] > 0)
8898 /* Remember how much we saved for this directory so far. */
8899 saved
[j
] = savehere
[j
];
8901 /* Remember the prefix directory. */
8902 dirs
[j
].dir_idx
= i
;
8907 /* Emit the directory name table. */
8909 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8910 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8911 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
8912 "Directory Entry: 0x%x", i
+ idx_offset
);
8914 dw2_asm_output_data (1, 0, "End directory table");
8916 /* We have to emit them in the order of emitted_number since that's
8917 used in the debug info generation. To do this efficiently we
8918 generate a back-mapping of the indices first. */
8919 backmap
= XALLOCAVEC (int, numfiles
);
8920 for (i
= 0; i
< numfiles
; i
++)
8921 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8923 /* Now write all the file names. */
8924 for (i
= 0; i
< numfiles
; i
++)
8926 int file_idx
= backmap
[i
];
8927 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8929 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8930 "File Entry: 0x%x", (unsigned) i
+ 1);
8932 /* Include directory index. */
8933 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8935 /* Modification time. */
8936 dw2_asm_output_data_uleb128 (0, NULL
);
8938 /* File length in bytes. */
8939 dw2_asm_output_data_uleb128 (0, NULL
);
8942 dw2_asm_output_data (1, 0, "End file name table");
8946 /* Output the source line number correspondence information. This
8947 information goes into the .debug_line section. */
8950 output_line_info (void)
8952 char l1
[20], l2
[20], p1
[20], p2
[20];
8953 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8954 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8957 unsigned long lt_index
;
8958 unsigned long current_line
;
8961 unsigned long current_file
;
8962 unsigned long function
;
8964 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
8965 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
8966 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
8967 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
8969 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8970 dw2_asm_output_data (4, 0xffffffff,
8971 "Initial length escape value indicating 64-bit DWARF extension");
8972 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
8973 "Length of Source Line Info");
8974 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
8976 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8977 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
8978 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
8980 /* Define the architecture-dependent minimum instruction length (in
8981 bytes). In this implementation of DWARF, this field is used for
8982 information purposes only. Since GCC generates assembly language,
8983 we have no a priori knowledge of how many instruction bytes are
8984 generated for each source line, and therefore can use only the
8985 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8986 commands. Accordingly, we fix this as `1', which is "correct
8987 enough" for all architectures, and don't let the target override. */
8988 dw2_asm_output_data (1, 1,
8989 "Minimum Instruction Length");
8991 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
8992 "Default is_stmt_start flag");
8993 dw2_asm_output_data (1, DWARF_LINE_BASE
,
8994 "Line Base Value (Special Opcodes)");
8995 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
8996 "Line Range Value (Special Opcodes)");
8997 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
8998 "Special Opcode Base");
9000 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9004 case DW_LNS_advance_pc
:
9005 case DW_LNS_advance_line
:
9006 case DW_LNS_set_file
:
9007 case DW_LNS_set_column
:
9008 case DW_LNS_fixed_advance_pc
:
9016 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
9020 /* Write out the information about the files we use. */
9021 output_file_names ();
9022 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9024 /* We used to set the address register to the first location in the text
9025 section here, but that didn't accomplish anything since we already
9026 have a line note for the opening brace of the first function. */
9028 /* Generate the line number to PC correspondence table, encoded as
9029 a series of state machine operations. */
9033 if (cfun
&& in_cold_section_p
)
9034 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
9036 strcpy (prev_line_label
, text_section_label
);
9037 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
9039 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
9042 /* Disable this optimization for now; GDB wants to see two line notes
9043 at the beginning of a function so it can find the end of the
9046 /* Don't emit anything for redundant notes. Just updating the
9047 address doesn't accomplish anything, because we already assume
9048 that anything after the last address is this line. */
9049 if (line_info
->dw_line_num
== current_line
9050 && line_info
->dw_file_num
== current_file
)
9054 /* Emit debug info for the address of the current line.
9056 Unfortunately, we have little choice here currently, and must always
9057 use the most general form. GCC does not know the address delta
9058 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9059 attributes which will give an upper bound on the address range. We
9060 could perhaps use length attributes to determine when it is safe to
9061 use DW_LNS_fixed_advance_pc. */
9063 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
9066 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9067 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9068 "DW_LNS_fixed_advance_pc");
9069 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9073 /* This can handle any delta. This takes
9074 4+DWARF2_ADDR_SIZE bytes. */
9075 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9076 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9077 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9078 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9081 strcpy (prev_line_label
, line_label
);
9083 /* Emit debug info for the source file of the current line, if
9084 different from the previous line. */
9085 if (line_info
->dw_file_num
!= current_file
)
9087 current_file
= line_info
->dw_file_num
;
9088 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9089 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9092 /* Emit debug info for the current line number, choosing the encoding
9093 that uses the least amount of space. */
9094 if (line_info
->dw_line_num
!= current_line
)
9096 line_offset
= line_info
->dw_line_num
- current_line
;
9097 line_delta
= line_offset
- DWARF_LINE_BASE
;
9098 current_line
= line_info
->dw_line_num
;
9099 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9100 /* This can handle deltas from -10 to 234, using the current
9101 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9103 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9104 "line %lu", current_line
);
9107 /* This can handle any delta. This takes at least 4 bytes,
9108 depending on the value being encoded. */
9109 dw2_asm_output_data (1, DW_LNS_advance_line
,
9110 "advance to line %lu", current_line
);
9111 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9112 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9116 /* We still need to start a new row, so output a copy insn. */
9117 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9120 /* Emit debug info for the address of the end of the function. */
9123 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9124 "DW_LNS_fixed_advance_pc");
9125 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
9129 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9130 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9131 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9132 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
9135 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9136 dw2_asm_output_data_uleb128 (1, NULL
);
9137 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9142 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
9144 dw_separate_line_info_ref line_info
9145 = &separate_line_info_table
[lt_index
];
9148 /* Don't emit anything for redundant notes. */
9149 if (line_info
->dw_line_num
== current_line
9150 && line_info
->dw_file_num
== current_file
9151 && line_info
->function
== function
)
9155 /* Emit debug info for the address of the current line. If this is
9156 a new function, or the first line of a function, then we need
9157 to handle it differently. */
9158 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
9160 if (function
!= line_info
->function
)
9162 function
= line_info
->function
;
9164 /* Set the address register to the first line in the function. */
9165 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9166 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9167 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9168 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9172 /* ??? See the DW_LNS_advance_pc comment above. */
9175 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9176 "DW_LNS_fixed_advance_pc");
9177 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9181 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9182 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9183 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9184 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9188 strcpy (prev_line_label
, line_label
);
9190 /* Emit debug info for the source file of the current line, if
9191 different from the previous line. */
9192 if (line_info
->dw_file_num
!= current_file
)
9194 current_file
= line_info
->dw_file_num
;
9195 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9196 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9199 /* Emit debug info for the current line number, choosing the encoding
9200 that uses the least amount of space. */
9201 if (line_info
->dw_line_num
!= current_line
)
9203 line_offset
= line_info
->dw_line_num
- current_line
;
9204 line_delta
= line_offset
- DWARF_LINE_BASE
;
9205 current_line
= line_info
->dw_line_num
;
9206 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9207 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9208 "line %lu", current_line
);
9211 dw2_asm_output_data (1, DW_LNS_advance_line
,
9212 "advance to line %lu", current_line
);
9213 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9214 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9218 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9226 /* If we're done with a function, end its sequence. */
9227 if (lt_index
== separate_line_info_table_in_use
9228 || separate_line_info_table
[lt_index
].function
!= function
)
9233 /* Emit debug info for the address of the end of the function. */
9234 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
9237 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9238 "DW_LNS_fixed_advance_pc");
9239 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9243 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9244 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9245 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9246 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9249 /* Output the marker for the end of this sequence. */
9250 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9251 dw2_asm_output_data_uleb128 (1, NULL
);
9252 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9256 /* Output the marker for the end of the line number info. */
9257 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9260 /* Given a pointer to a tree node for some base type, return a pointer to
9261 a DIE that describes the given type.
9263 This routine must only be called for GCC type nodes that correspond to
9264 Dwarf base (fundamental) types. */
9267 base_type_die (tree type
)
9269 dw_die_ref base_type_result
;
9270 enum dwarf_type encoding
;
9272 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9275 /* If this is a subtype that should not be emitted as a subrange type,
9276 use the base type. See subrange_type_for_debug_p. */
9277 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9278 type
= TREE_TYPE (type
);
9280 switch (TREE_CODE (type
))
9283 if (TYPE_STRING_FLAG (type
))
9285 if (TYPE_UNSIGNED (type
))
9286 encoding
= DW_ATE_unsigned_char
;
9288 encoding
= DW_ATE_signed_char
;
9290 else if (TYPE_UNSIGNED (type
))
9291 encoding
= DW_ATE_unsigned
;
9293 encoding
= DW_ATE_signed
;
9297 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9298 encoding
= DW_ATE_decimal_float
;
9300 encoding
= DW_ATE_float
;
9303 case FIXED_POINT_TYPE
:
9304 if (TYPE_UNSIGNED (type
))
9305 encoding
= DW_ATE_unsigned_fixed
;
9307 encoding
= DW_ATE_signed_fixed
;
9310 /* Dwarf2 doesn't know anything about complex ints, so use
9311 a user defined type for it. */
9313 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9314 encoding
= DW_ATE_complex_float
;
9316 encoding
= DW_ATE_lo_user
;
9320 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9321 encoding
= DW_ATE_boolean
;
9325 /* No other TREE_CODEs are Dwarf fundamental types. */
9329 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
9331 /* This probably indicates a bug. */
9332 if (! TYPE_NAME (type
))
9333 add_name_attribute (base_type_result
, "__unknown__");
9335 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9336 int_size_in_bytes (type
));
9337 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9339 return base_type_result
;
9342 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9343 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9346 is_base_type (tree type
)
9348 switch (TREE_CODE (type
))
9354 case FIXED_POINT_TYPE
:
9362 case QUAL_UNION_TYPE
:
9367 case REFERENCE_TYPE
:
9380 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9381 node, return the size in bits for the type if it is a constant, or else
9382 return the alignment for the type if the type's size is not constant, or
9383 else return BITS_PER_WORD if the type actually turns out to be an
9386 static inline unsigned HOST_WIDE_INT
9387 simple_type_size_in_bits (const_tree type
)
9389 if (TREE_CODE (type
) == ERROR_MARK
)
9390 return BITS_PER_WORD
;
9391 else if (TYPE_SIZE (type
) == NULL_TREE
)
9393 else if (host_integerp (TYPE_SIZE (type
), 1))
9394 return tree_low_cst (TYPE_SIZE (type
), 1);
9396 return TYPE_ALIGN (type
);
9399 /* Given a pointer to a tree node for a subrange type, return a pointer
9400 to a DIE that describes the given type. */
9403 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9405 dw_die_ref subrange_die
;
9406 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9408 if (context_die
== NULL
)
9409 context_die
= comp_unit_die
;
9411 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9413 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9415 /* The size of the subrange type and its base type do not match,
9416 so we need to generate a size attribute for the subrange type. */
9417 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9421 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9423 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9425 return subrange_die
;
9428 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9429 entry that chains various modifiers in front of the given type. */
9432 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9433 dw_die_ref context_die
)
9435 enum tree_code code
= TREE_CODE (type
);
9436 dw_die_ref mod_type_die
;
9437 dw_die_ref sub_die
= NULL
;
9438 tree item_type
= NULL
;
9439 tree qualified_type
;
9440 tree name
, low
, high
;
9442 if (code
== ERROR_MARK
)
9445 /* See if we already have the appropriately qualified variant of
9448 = get_qualified_type (type
,
9449 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9450 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9452 /* If we do, then we can just use its DIE, if it exists. */
9455 mod_type_die
= lookup_type_die (qualified_type
);
9457 return mod_type_die
;
9460 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9462 /* Handle C typedef types. */
9463 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
9465 tree dtype
= TREE_TYPE (name
);
9467 if (qualified_type
== dtype
)
9469 /* For a named type, use the typedef. */
9470 gen_type_die (qualified_type
, context_die
);
9471 return lookup_type_die (qualified_type
);
9473 else if (is_const_type
< TYPE_READONLY (dtype
)
9474 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9475 || (is_const_type
<= TYPE_READONLY (dtype
)
9476 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9477 && DECL_ORIGINAL_TYPE (name
) != type
))
9478 /* cv-unqualified version of named type. Just use the unnamed
9479 type to which it refers. */
9480 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9481 is_const_type
, is_volatile_type
,
9483 /* Else cv-qualified version of named type; fall through. */
9488 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
9489 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9491 else if (is_volatile_type
)
9493 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
9494 sub_die
= modified_type_die (type
, 0, 0, context_die
);
9496 else if (code
== POINTER_TYPE
)
9498 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
9499 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9500 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9501 item_type
= TREE_TYPE (type
);
9503 else if (code
== REFERENCE_TYPE
)
9505 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
9506 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9507 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9508 item_type
= TREE_TYPE (type
);
9510 else if (code
== INTEGER_TYPE
9511 && TREE_TYPE (type
) != NULL_TREE
9512 && subrange_type_for_debug_p (type
, &low
, &high
))
9514 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9515 item_type
= TREE_TYPE (type
);
9517 else if (is_base_type (type
))
9518 mod_type_die
= base_type_die (type
);
9521 gen_type_die (type
, context_die
);
9523 /* We have to get the type_main_variant here (and pass that to the
9524 `lookup_type_die' routine) because the ..._TYPE node we have
9525 might simply be a *copy* of some original type node (where the
9526 copy was created to help us keep track of typedef names) and
9527 that copy might have a different TYPE_UID from the original
9529 if (TREE_CODE (type
) != VECTOR_TYPE
)
9530 return lookup_type_die (type_main_variant (type
));
9532 /* Vectors have the debugging information in the type,
9533 not the main variant. */
9534 return lookup_type_die (type
);
9537 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9538 don't output a DW_TAG_typedef, since there isn't one in the
9539 user's program; just attach a DW_AT_name to the type. */
9541 && (TREE_CODE (name
) != TYPE_DECL
9542 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
9544 if (TREE_CODE (name
) == TYPE_DECL
)
9545 /* Could just call add_name_and_src_coords_attributes here,
9546 but since this is a builtin type it doesn't have any
9547 useful source coordinates anyway. */
9548 name
= DECL_NAME (name
);
9549 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9553 equate_type_number_to_die (qualified_type
, mod_type_die
);
9556 /* We must do this after the equate_type_number_to_die call, in case
9557 this is a recursive type. This ensures that the modified_type_die
9558 recursion will terminate even if the type is recursive. Recursive
9559 types are possible in Ada. */
9560 sub_die
= modified_type_die (item_type
,
9561 TYPE_READONLY (item_type
),
9562 TYPE_VOLATILE (item_type
),
9565 if (sub_die
!= NULL
)
9566 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9568 return mod_type_die
;
9571 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9572 an enumerated type. */
9575 type_is_enum (const_tree type
)
9577 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9580 /* Return the DBX register number described by a given RTL node. */
9583 dbx_reg_number (const_rtx rtl
)
9585 unsigned regno
= REGNO (rtl
);
9587 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9589 #ifdef LEAF_REG_REMAP
9590 if (current_function_uses_only_leaf_regs
)
9592 int leaf_reg
= LEAF_REG_REMAP (regno
);
9594 regno
= (unsigned) leaf_reg
;
9598 return DBX_REGISTER_NUMBER (regno
);
9601 /* Optionally add a DW_OP_piece term to a location description expression.
9602 DW_OP_piece is only added if the location description expression already
9603 doesn't end with DW_OP_piece. */
9606 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9608 dw_loc_descr_ref loc
;
9610 if (*list_head
!= NULL
)
9612 /* Find the end of the chain. */
9613 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9616 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9617 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9621 /* Return a location descriptor that designates a machine register or
9622 zero if there is none. */
9624 static dw_loc_descr_ref
9625 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9629 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9632 regs
= targetm
.dwarf_register_span (rtl
);
9634 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9635 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9637 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9640 /* Return a location descriptor that designates a machine register for
9641 a given hard register number. */
9643 static dw_loc_descr_ref
9644 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9646 dw_loc_descr_ref reg_loc_descr
;
9650 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
9652 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
9654 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9655 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9657 return reg_loc_descr
;
9660 /* Given an RTL of a register, return a location descriptor that
9661 designates a value that spans more than one register. */
9663 static dw_loc_descr_ref
9664 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9665 enum var_init_status initialized
)
9669 dw_loc_descr_ref loc_result
= NULL
;
9672 #ifdef LEAF_REG_REMAP
9673 if (current_function_uses_only_leaf_regs
)
9675 int leaf_reg
= LEAF_REG_REMAP (reg
);
9677 reg
= (unsigned) leaf_reg
;
9680 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9681 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9683 /* Simple, contiguous registers. */
9684 if (regs
== NULL_RTX
)
9686 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9693 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9694 VAR_INIT_STATUS_INITIALIZED
);
9695 add_loc_descr (&loc_result
, t
);
9696 add_loc_descr_op_piece (&loc_result
, size
);
9702 /* Now onto stupid register sets in non contiguous locations. */
9704 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9706 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9709 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9713 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9714 VAR_INIT_STATUS_INITIALIZED
);
9715 add_loc_descr (&loc_result
, t
);
9716 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9717 add_loc_descr_op_piece (&loc_result
, size
);
9720 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9721 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9725 #endif /* DWARF2_DEBUGGING_INFO */
9727 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9729 /* Return a location descriptor that designates a constant. */
9731 static dw_loc_descr_ref
9732 int_loc_descriptor (HOST_WIDE_INT i
)
9734 enum dwarf_location_atom op
;
9736 /* Pick the smallest representation of a constant, rather than just
9737 defaulting to the LEB encoding. */
9741 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
9744 else if (i
<= 0xffff)
9746 else if (HOST_BITS_PER_WIDE_INT
== 32
9756 else if (i
>= -0x8000)
9758 else if (HOST_BITS_PER_WIDE_INT
== 32
9759 || i
>= -0x80000000)
9765 return new_loc_descr (op
, i
, 0);
9769 #ifdef DWARF2_DEBUGGING_INFO
9771 /* Return a location descriptor that designates a base+offset location. */
9773 static dw_loc_descr_ref
9774 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
9775 enum var_init_status initialized
)
9778 dw_loc_descr_ref result
;
9779 dw_fde_ref fde
= current_fde ();
9781 /* We only use "frame base" when we're sure we're talking about the
9782 post-prologue local stack frame. We do this by *not* running
9783 register elimination until this point, and recognizing the special
9784 argument pointer and soft frame pointer rtx's. */
9785 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
9787 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9791 if (GET_CODE (elim
) == PLUS
)
9793 offset
+= INTVAL (XEXP (elim
, 1));
9794 elim
= XEXP (elim
, 0);
9796 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9797 && (elim
== hard_frame_pointer_rtx
9798 || elim
== stack_pointer_rtx
))
9799 || elim
== (frame_pointer_needed
9800 ? hard_frame_pointer_rtx
9801 : stack_pointer_rtx
));
9803 /* If drap register is used to align stack, use frame
9804 pointer + offset to access stack variables. If stack
9805 is aligned without drap, use stack pointer + offset to
9806 access stack variables. */
9807 if (crtl
->stack_realign_tried
9808 && cfa
.reg
== HARD_FRAME_POINTER_REGNUM
9809 && reg
== frame_pointer_rtx
)
9812 = DWARF_FRAME_REGNUM (cfa
.indirect
9813 ? HARD_FRAME_POINTER_REGNUM
9814 : STACK_POINTER_REGNUM
);
9815 return new_reg_loc_descr (base_reg
, offset
);
9818 offset
+= frame_pointer_fb_offset
;
9819 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9823 && fde
->drap_reg
!= INVALID_REGNUM
9824 && (fde
->drap_reg
== REGNO (reg
)
9825 || fde
->vdrap_reg
== REGNO (reg
)))
9827 /* Use cfa+offset to represent the location of arguments passed
9828 on stack when drap is used to align stack. */
9829 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9832 regno
= dbx_reg_number (reg
);
9834 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
9837 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
9839 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9840 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9845 /* Return true if this RTL expression describes a base+offset calculation. */
9848 is_based_loc (const_rtx rtl
)
9850 return (GET_CODE (rtl
) == PLUS
9851 && ((REG_P (XEXP (rtl
, 0))
9852 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
9853 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
9856 /* Return a descriptor that describes the concatenation of N locations
9857 used to form the address of a memory location. */
9859 static dw_loc_descr_ref
9860 concatn_mem_loc_descriptor (rtx concatn
, enum machine_mode mode
,
9861 enum var_init_status initialized
)
9864 dw_loc_descr_ref cc_loc_result
= NULL
;
9865 unsigned int n
= XVECLEN (concatn
, 0);
9867 for (i
= 0; i
< n
; ++i
)
9869 dw_loc_descr_ref ref
;
9870 rtx x
= XVECEXP (concatn
, 0, i
);
9872 ref
= mem_loc_descriptor (x
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9876 add_loc_descr (&cc_loc_result
, ref
);
9877 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9880 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9881 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9883 return cc_loc_result
;
9886 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
9889 static dw_loc_descr_ref
9890 tls_mem_loc_descriptor (rtx mem
)
9893 dw_loc_descr_ref loc_result
;
9895 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
9898 base
= get_base_address (MEM_EXPR (mem
));
9900 || TREE_CODE (base
) != VAR_DECL
9901 || !DECL_THREAD_LOCAL_P (base
))
9904 loc_result
= loc_descriptor_from_tree_1 (MEM_EXPR (mem
), 2);
9905 if (loc_result
== NULL
)
9908 if (INTVAL (MEM_OFFSET (mem
)))
9909 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
9914 /* The following routine converts the RTL for a variable or parameter
9915 (resident in memory) into an equivalent Dwarf representation of a
9916 mechanism for getting the address of that same variable onto the top of a
9917 hypothetical "address evaluation" stack.
9919 When creating memory location descriptors, we are effectively transforming
9920 the RTL for a memory-resident object into its Dwarf postfix expression
9921 equivalent. This routine recursively descends an RTL tree, turning
9922 it into Dwarf postfix code as it goes.
9924 MODE is the mode of the memory reference, needed to handle some
9925 autoincrement addressing modes.
9927 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9928 location list for RTL.
9930 Return 0 if we can't represent the location. */
9932 static dw_loc_descr_ref
9933 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
9934 enum var_init_status initialized
)
9936 dw_loc_descr_ref mem_loc_result
= NULL
;
9937 enum dwarf_location_atom op
;
9939 /* Note that for a dynamically sized array, the location we will generate a
9940 description of here will be the lowest numbered location which is
9941 actually within the array. That's *not* necessarily the same as the
9942 zeroth element of the array. */
9944 rtl
= targetm
.delegitimize_address (rtl
);
9946 switch (GET_CODE (rtl
))
9951 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9952 just fall into the SUBREG code. */
9954 /* ... fall through ... */
9957 /* The case of a subreg may arise when we have a local (register)
9958 variable or a formal (register) parameter which doesn't quite fill
9959 up an entire register. For now, just assume that it is
9960 legitimate to make the Dwarf info refer to the whole register which
9961 contains the given subreg. */
9962 rtl
= XEXP (rtl
, 0);
9964 /* ... fall through ... */
9967 /* Whenever a register number forms a part of the description of the
9968 method for calculating the (dynamic) address of a memory resident
9969 object, DWARF rules require the register number be referred to as
9970 a "base register". This distinction is not based in any way upon
9971 what category of register the hardware believes the given register
9972 belongs to. This is strictly DWARF terminology we're dealing with
9973 here. Note that in cases where the location of a memory-resident
9974 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9975 OP_CONST (0)) the actual DWARF location descriptor that we generate
9976 may just be OP_BASEREG (basereg). This may look deceptively like
9977 the object in question was allocated to a register (rather than in
9978 memory) so DWARF consumers need to be aware of the subtle
9979 distinction between OP_REG and OP_BASEREG. */
9980 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
9981 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
9982 else if (stack_realign_drap
9984 && crtl
->args
.internal_arg_pointer
== rtl
9985 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
9987 /* If RTL is internal_arg_pointer, which has been optimized
9988 out, use DRAP instead. */
9989 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
9990 VAR_INIT_STATUS_INITIALIZED
);
9995 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
9996 VAR_INIT_STATUS_INITIALIZED
);
9997 if (mem_loc_result
== NULL
)
9998 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
9999 if (mem_loc_result
!= 0)
10000 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
10004 rtl
= XEXP (rtl
, 1);
10006 /* ... fall through ... */
10009 /* Some ports can transform a symbol ref into a label ref, because
10010 the symbol ref is too far away and has to be dumped into a constant
10014 /* Alternatively, the symbol in the constant pool might be referenced
10015 by a different symbol. */
10016 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
10019 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
10021 if (GET_CODE (tmp
) == SYMBOL_REF
)
10024 if (CONSTANT_POOL_ADDRESS_P (tmp
))
10025 get_pool_constant_mark (tmp
, &marked
);
10030 /* If all references to this pool constant were optimized away,
10031 it was not output and thus we can't represent it.
10032 FIXME: might try to use DW_OP_const_value here, though
10033 DW_OP_piece complicates it. */
10038 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
10039 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10040 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10041 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
10045 /* Extract the PLUS expression nested inside and fall into
10046 PLUS code below. */
10047 rtl
= XEXP (rtl
, 1);
10052 /* Turn these into a PLUS expression and fall into the PLUS code
10054 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
10055 GEN_INT (GET_CODE (rtl
) == PRE_INC
10056 ? GET_MODE_UNIT_SIZE (mode
)
10057 : -GET_MODE_UNIT_SIZE (mode
)));
10059 /* ... fall through ... */
10063 if (is_based_loc (rtl
))
10064 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
10065 INTVAL (XEXP (rtl
, 1)),
10066 VAR_INIT_STATUS_INITIALIZED
);
10069 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10070 VAR_INIT_STATUS_INITIALIZED
);
10071 if (mem_loc_result
== 0)
10074 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)
10075 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
10078 dw_loc_descr_ref mem_loc_result2
10079 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10080 VAR_INIT_STATUS_INITIALIZED
);
10081 if (mem_loc_result2
== 0)
10083 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
10084 add_loc_descr (&mem_loc_result
,
10085 new_loc_descr (DW_OP_plus
, 0, 0));
10090 /* If a pseudo-reg is optimized away, it is possible for it to
10091 be replaced with a MEM containing a multiply or shift. */
10110 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10111 VAR_INIT_STATUS_INITIALIZED
);
10112 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10113 VAR_INIT_STATUS_INITIALIZED
);
10115 if (op0
== 0 || op1
== 0)
10118 mem_loc_result
= op0
;
10119 add_loc_descr (&mem_loc_result
, op1
);
10120 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
10125 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
10129 mem_loc_result
= concatn_mem_loc_descriptor (rtl
, mode
,
10130 VAR_INIT_STATUS_INITIALIZED
);
10134 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10135 can't express it in the debug info. This can happen e.g. with some
10140 gcc_unreachable ();
10143 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10144 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10146 return mem_loc_result
;
10149 /* Return a descriptor that describes the concatenation of two locations.
10150 This is typically a complex variable. */
10152 static dw_loc_descr_ref
10153 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
10155 dw_loc_descr_ref cc_loc_result
= NULL
;
10156 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, VAR_INIT_STATUS_INITIALIZED
);
10157 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, VAR_INIT_STATUS_INITIALIZED
);
10159 if (x0_ref
== 0 || x1_ref
== 0)
10162 cc_loc_result
= x0_ref
;
10163 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
10165 add_loc_descr (&cc_loc_result
, x1_ref
);
10166 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
10168 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10169 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10171 return cc_loc_result
;
10174 /* Return a descriptor that describes the concatenation of N
10177 static dw_loc_descr_ref
10178 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
10181 dw_loc_descr_ref cc_loc_result
= NULL
;
10182 unsigned int n
= XVECLEN (concatn
, 0);
10184 for (i
= 0; i
< n
; ++i
)
10186 dw_loc_descr_ref ref
;
10187 rtx x
= XVECEXP (concatn
, 0, i
);
10189 ref
= loc_descriptor (x
, VAR_INIT_STATUS_INITIALIZED
);
10193 add_loc_descr (&cc_loc_result
, ref
);
10194 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
10197 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10198 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10200 return cc_loc_result
;
10203 /* Output a proper Dwarf location descriptor for a variable or parameter
10204 which is either allocated in a register or in a memory location. For a
10205 register, we just generate an OP_REG and the register number. For a
10206 memory location we provide a Dwarf postfix expression describing how to
10207 generate the (dynamic) address of the object onto the address stack.
10209 If we don't know how to describe it, return 0. */
10211 static dw_loc_descr_ref
10212 loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10214 dw_loc_descr_ref loc_result
= NULL
;
10216 switch (GET_CODE (rtl
))
10219 /* The case of a subreg may arise when we have a local (register)
10220 variable or a formal (register) parameter which doesn't quite fill
10221 up an entire register. For now, just assume that it is
10222 legitimate to make the Dwarf info refer to the whole register which
10223 contains the given subreg. */
10224 rtl
= SUBREG_REG (rtl
);
10226 /* ... fall through ... */
10229 loc_result
= reg_loc_descriptor (rtl
, initialized
);
10233 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
10235 if (loc_result
== NULL
)
10236 loc_result
= tls_mem_loc_descriptor (rtl
);
10240 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
10245 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
10250 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
10252 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), initialized
);
10256 rtl
= XEXP (rtl
, 1);
10261 rtvec par_elems
= XVEC (rtl
, 0);
10262 int num_elem
= GET_NUM_ELEM (par_elems
);
10263 enum machine_mode mode
;
10266 /* Create the first one, so we have something to add to. */
10267 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
10269 if (loc_result
== NULL
)
10271 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
10272 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10273 for (i
= 1; i
< num_elem
; i
++)
10275 dw_loc_descr_ref temp
;
10277 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
10281 add_loc_descr (&loc_result
, temp
);
10282 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
10283 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10289 gcc_unreachable ();
10295 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10296 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10297 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10298 top-level invocation, and we require the address of LOC; is 0 if we require
10299 the value of LOC. */
10301 static dw_loc_descr_ref
10302 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
10304 dw_loc_descr_ref ret
, ret1
;
10305 int have_address
= 0;
10306 enum dwarf_location_atom op
;
10308 /* ??? Most of the time we do not take proper care for sign/zero
10309 extending the values properly. Hopefully this won't be a real
10312 switch (TREE_CODE (loc
))
10317 case PLACEHOLDER_EXPR
:
10318 /* This case involves extracting fields from an object to determine the
10319 position of other fields. We don't try to encode this here. The
10320 only user of this is Ada, which encodes the needed information using
10321 the names of types. */
10327 case PREINCREMENT_EXPR
:
10328 case PREDECREMENT_EXPR
:
10329 case POSTINCREMENT_EXPR
:
10330 case POSTDECREMENT_EXPR
:
10331 /* There are no opcodes for these operations. */
10335 /* If we already want an address, there's nothing we can do. */
10339 /* Otherwise, process the argument and look for the address. */
10340 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
10343 if (DECL_THREAD_LOCAL_P (loc
))
10346 enum dwarf_location_atom first_op
;
10347 enum dwarf_location_atom second_op
;
10349 if (targetm
.have_tls
)
10351 /* If this is not defined, we have no way to emit the
10353 if (!targetm
.asm_out
.output_dwarf_dtprel
)
10356 /* The way DW_OP_GNU_push_tls_address is specified, we
10357 can only look up addresses of objects in the current
10359 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
10361 first_op
= (enum dwarf_location_atom
) INTERNAL_DW_OP_tls_addr
;
10362 second_op
= DW_OP_GNU_push_tls_address
;
10366 if (!targetm
.emutls
.debug_form_tls_address
)
10368 loc
= emutls_decl (loc
);
10369 first_op
= DW_OP_addr
;
10370 second_op
= DW_OP_form_tls_address
;
10373 rtl
= rtl_for_decl_location (loc
);
10374 if (rtl
== NULL_RTX
)
10379 rtl
= XEXP (rtl
, 0);
10380 if (! CONSTANT_P (rtl
))
10383 ret
= new_loc_descr (first_op
, 0, 0);
10384 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10385 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10387 ret1
= new_loc_descr (second_op
, 0, 0);
10388 add_loc_descr (&ret
, ret1
);
10396 if (DECL_HAS_VALUE_EXPR_P (loc
))
10397 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
10402 case FUNCTION_DECL
:
10404 rtx rtl
= rtl_for_decl_location (loc
);
10406 if (rtl
== NULL_RTX
)
10408 else if (GET_CODE (rtl
) == CONST_INT
)
10410 HOST_WIDE_INT val
= INTVAL (rtl
);
10411 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
10412 val
&= GET_MODE_MASK (DECL_MODE (loc
));
10413 ret
= int_loc_descriptor (val
);
10415 else if (GET_CODE (rtl
) == CONST_STRING
)
10417 else if (CONSTANT_P (rtl
))
10419 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
10420 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10421 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10425 enum machine_mode mode
;
10427 /* Certain constructs can only be represented at top-level. */
10428 if (want_address
== 2)
10429 return loc_descriptor (rtl
, VAR_INIT_STATUS_INITIALIZED
);
10431 mode
= GET_MODE (rtl
);
10434 rtl
= XEXP (rtl
, 0);
10437 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10443 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10447 case COMPOUND_EXPR
:
10448 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
10451 case VIEW_CONVERT_EXPR
:
10454 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
10456 case COMPONENT_REF
:
10457 case BIT_FIELD_REF
:
10459 case ARRAY_RANGE_REF
:
10462 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
10463 enum machine_mode mode
;
10465 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
10467 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
10468 &unsignedp
, &volatilep
, false);
10473 ret
= loc_descriptor_from_tree_1 (obj
, 1);
10475 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
10478 if (offset
!= NULL_TREE
)
10480 /* Variable offset. */
10481 ret1
= loc_descriptor_from_tree_1 (offset
, 0);
10484 add_loc_descr (&ret
, ret1
);
10485 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10488 bytepos
= bitpos
/ BITS_PER_UNIT
;
10489 loc_descr_plus_const (&ret
, bytepos
);
10496 if (host_integerp (loc
, 0))
10497 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
10504 /* Get an RTL for this, if something has been emitted. */
10505 rtx rtl
= lookup_constant_def (loc
);
10506 enum machine_mode mode
;
10508 if (!rtl
|| !MEM_P (rtl
))
10510 mode
= GET_MODE (rtl
);
10511 rtl
= XEXP (rtl
, 0);
10512 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10517 case TRUTH_AND_EXPR
:
10518 case TRUTH_ANDIF_EXPR
:
10523 case TRUTH_XOR_EXPR
:
10528 case TRUTH_OR_EXPR
:
10529 case TRUTH_ORIF_EXPR
:
10534 case FLOOR_DIV_EXPR
:
10535 case CEIL_DIV_EXPR
:
10536 case ROUND_DIV_EXPR
:
10537 case TRUNC_DIV_EXPR
:
10545 case FLOOR_MOD_EXPR
:
10546 case CEIL_MOD_EXPR
:
10547 case ROUND_MOD_EXPR
:
10548 case TRUNC_MOD_EXPR
:
10561 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
10564 case POINTER_PLUS_EXPR
:
10566 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
10567 && host_integerp (TREE_OPERAND (loc
, 1), 0))
10569 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10573 loc_descr_plus_const (&ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
10581 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10588 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10595 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10602 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10617 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10618 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10619 if (ret
== 0 || ret1
== 0)
10622 add_loc_descr (&ret
, ret1
);
10623 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10626 case TRUTH_NOT_EXPR
:
10640 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10644 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10650 const enum tree_code code
=
10651 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
10653 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
10654 build2 (code
, integer_type_node
,
10655 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
10656 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
10659 /* ... fall through ... */
10663 dw_loc_descr_ref lhs
10664 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10665 dw_loc_descr_ref rhs
10666 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
10667 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
10669 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10670 if (ret
== 0 || lhs
== 0 || rhs
== 0)
10673 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10674 add_loc_descr (&ret
, bra_node
);
10676 add_loc_descr (&ret
, rhs
);
10677 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
10678 add_loc_descr (&ret
, jump_node
);
10680 add_loc_descr (&ret
, lhs
);
10681 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10682 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
10684 /* ??? Need a node to point the skip at. Use a nop. */
10685 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
10686 add_loc_descr (&ret
, tmp
);
10687 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10688 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
10692 case FIX_TRUNC_EXPR
:
10696 /* Leave front-end specific codes as simply unknown. This comes
10697 up, for instance, with the C STMT_EXPR. */
10698 if ((unsigned int) TREE_CODE (loc
)
10699 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
10702 #ifdef ENABLE_CHECKING
10703 /* Otherwise this is a generic code; we should just lists all of
10704 these explicitly. We forgot one. */
10705 gcc_unreachable ();
10707 /* In a release build, we want to degrade gracefully: better to
10708 generate incomplete debugging information than to crash. */
10713 /* Show if we can't fill the request for an address. */
10714 if (want_address
&& !have_address
)
10717 /* If we've got an address and don't want one, dereference. */
10718 if (!want_address
&& have_address
&& ret
)
10720 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
10722 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
10724 else if (size
== DWARF2_ADDR_SIZE
)
10727 op
= DW_OP_deref_size
;
10729 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
10735 static inline dw_loc_descr_ref
10736 loc_descriptor_from_tree (tree loc
)
10738 return loc_descriptor_from_tree_1 (loc
, 2);
10741 /* Given a value, round it up to the lowest multiple of `boundary'
10742 which is not less than the value itself. */
10744 static inline HOST_WIDE_INT
10745 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
10747 return (((value
+ boundary
- 1) / boundary
) * boundary
);
10750 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10751 pointer to the declared type for the relevant field variable, or return
10752 `integer_type_node' if the given node turns out to be an
10753 ERROR_MARK node. */
10756 field_type (const_tree decl
)
10760 if (TREE_CODE (decl
) == ERROR_MARK
)
10761 return integer_type_node
;
10763 type
= DECL_BIT_FIELD_TYPE (decl
);
10764 if (type
== NULL_TREE
)
10765 type
= TREE_TYPE (decl
);
10770 /* Given a pointer to a tree node, return the alignment in bits for
10771 it, or else return BITS_PER_WORD if the node actually turns out to
10772 be an ERROR_MARK node. */
10774 static inline unsigned
10775 simple_type_align_in_bits (const_tree type
)
10777 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
10780 static inline unsigned
10781 simple_decl_align_in_bits (const_tree decl
)
10783 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
10786 /* Return the result of rounding T up to ALIGN. */
10788 static inline HOST_WIDE_INT
10789 round_up_to_align (HOST_WIDE_INT t
, unsigned int align
)
10791 /* We must be careful if T is negative because HOST_WIDE_INT can be
10792 either "above" or "below" unsigned int as per the C promotion
10793 rules, depending on the host, thus making the signedness of the
10794 direct multiplication and division unpredictable. */
10795 unsigned HOST_WIDE_INT u
= (unsigned HOST_WIDE_INT
) t
;
10801 return (HOST_WIDE_INT
) u
;
10804 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10805 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10806 or return 0 if we are unable to determine what that offset is, either
10807 because the argument turns out to be a pointer to an ERROR_MARK node, or
10808 because the offset is actually variable. (We can't handle the latter case
10811 static HOST_WIDE_INT
10812 field_byte_offset (const_tree decl
)
10814 HOST_WIDE_INT object_offset_in_bits
;
10815 HOST_WIDE_INT bitpos_int
;
10817 if (TREE_CODE (decl
) == ERROR_MARK
)
10820 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
10822 /* We cannot yet cope with fields whose positions are variable, so
10823 for now, when we see such things, we simply return 0. Someday, we may
10824 be able to handle such cases, but it will be damn difficult. */
10825 if (! host_integerp (bit_position (decl
), 0))
10828 bitpos_int
= int_bit_position (decl
);
10830 #ifdef PCC_BITFIELD_TYPE_MATTERS
10831 if (PCC_BITFIELD_TYPE_MATTERS
)
10834 tree field_size_tree
;
10835 HOST_WIDE_INT deepest_bitpos
;
10836 unsigned HOST_WIDE_INT field_size_in_bits
;
10837 unsigned int type_align_in_bits
;
10838 unsigned int decl_align_in_bits
;
10839 unsigned HOST_WIDE_INT type_size_in_bits
;
10841 type
= field_type (decl
);
10842 type_size_in_bits
= simple_type_size_in_bits (type
);
10843 type_align_in_bits
= simple_type_align_in_bits (type
);
10845 field_size_tree
= DECL_SIZE (decl
);
10847 /* The size could be unspecified if there was an error, or for
10848 a flexible array member. */
10849 if (!field_size_tree
)
10850 field_size_tree
= bitsize_zero_node
;
10852 /* If the size of the field is not constant, use the type size. */
10853 if (host_integerp (field_size_tree
, 1))
10854 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
10856 field_size_in_bits
= type_size_in_bits
;
10858 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
10860 /* The GCC front-end doesn't make any attempt to keep track of the
10861 starting bit offset (relative to the start of the containing
10862 structure type) of the hypothetical "containing object" for a
10863 bit-field. Thus, when computing the byte offset value for the
10864 start of the "containing object" of a bit-field, we must deduce
10865 this information on our own. This can be rather tricky to do in
10866 some cases. For example, handling the following structure type
10867 definition when compiling for an i386/i486 target (which only
10868 aligns long long's to 32-bit boundaries) can be very tricky:
10870 struct S { int field1; long long field2:31; };
10872 Fortunately, there is a simple rule-of-thumb which can be used
10873 in such cases. When compiling for an i386/i486, GCC will
10874 allocate 8 bytes for the structure shown above. It decides to
10875 do this based upon one simple rule for bit-field allocation.
10876 GCC allocates each "containing object" for each bit-field at
10877 the first (i.e. lowest addressed) legitimate alignment boundary
10878 (based upon the required minimum alignment for the declared
10879 type of the field) which it can possibly use, subject to the
10880 condition that there is still enough available space remaining
10881 in the containing object (when allocated at the selected point)
10882 to fully accommodate all of the bits of the bit-field itself.
10884 This simple rule makes it obvious why GCC allocates 8 bytes for
10885 each object of the structure type shown above. When looking
10886 for a place to allocate the "containing object" for `field2',
10887 the compiler simply tries to allocate a 64-bit "containing
10888 object" at each successive 32-bit boundary (starting at zero)
10889 until it finds a place to allocate that 64- bit field such that
10890 at least 31 contiguous (and previously unallocated) bits remain
10891 within that selected 64 bit field. (As it turns out, for the
10892 example above, the compiler finds it is OK to allocate the
10893 "containing object" 64-bit field at bit-offset zero within the
10896 Here we attempt to work backwards from the limited set of facts
10897 we're given, and we try to deduce from those facts, where GCC
10898 must have believed that the containing object started (within
10899 the structure type). The value we deduce is then used (by the
10900 callers of this routine) to generate DW_AT_location and
10901 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10902 the case of DW_AT_location, regular fields as well). */
10904 /* Figure out the bit-distance from the start of the structure to
10905 the "deepest" bit of the bit-field. */
10906 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
10908 /* This is the tricky part. Use some fancy footwork to deduce
10909 where the lowest addressed bit of the containing object must
10911 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10913 /* Round up to type_align by default. This works best for
10915 object_offset_in_bits
10916 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
10918 if (object_offset_in_bits
> bitpos_int
)
10920 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10922 /* Round up to decl_align instead. */
10923 object_offset_in_bits
10924 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
10929 object_offset_in_bits
= bitpos_int
;
10931 return object_offset_in_bits
/ BITS_PER_UNIT
;
10934 /* The following routines define various Dwarf attributes and any data
10935 associated with them. */
10937 /* Add a location description attribute value to a DIE.
10939 This emits location attributes suitable for whole variables and
10940 whole parameters. Note that the location attributes for struct fields are
10941 generated by the routine `data_member_location_attribute' below. */
10944 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10945 dw_loc_descr_ref descr
)
10948 add_AT_loc (die
, attr_kind
, descr
);
10951 /* Attach the specialized form of location attribute used for data members of
10952 struct and union types. In the special case of a FIELD_DECL node which
10953 represents a bit-field, the "offset" part of this special location
10954 descriptor must indicate the distance in bytes from the lowest-addressed
10955 byte of the containing struct or union type to the lowest-addressed byte of
10956 the "containing object" for the bit-field. (See the `field_byte_offset'
10959 For any given bit-field, the "containing object" is a hypothetical object
10960 (of some integral or enum type) within which the given bit-field lives. The
10961 type of this hypothetical "containing object" is always the same as the
10962 declared type of the individual bit-field itself (for GCC anyway... the
10963 DWARF spec doesn't actually mandate this). Note that it is the size (in
10964 bytes) of the hypothetical "containing object" which will be given in the
10965 DW_AT_byte_size attribute for this bit-field. (See the
10966 `byte_size_attribute' function below.) It is also used when calculating the
10967 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10968 function below.) */
10971 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
10973 HOST_WIDE_INT offset
;
10974 dw_loc_descr_ref loc_descr
= 0;
10976 if (TREE_CODE (decl
) == TREE_BINFO
)
10978 /* We're working on the TAG_inheritance for a base class. */
10979 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
10981 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10982 aren't at a fixed offset from all (sub)objects of the same
10983 type. We need to extract the appropriate offset from our
10984 vtable. The following dwarf expression means
10986 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10988 This is specific to the V3 ABI, of course. */
10990 dw_loc_descr_ref tmp
;
10992 /* Make a copy of the object address. */
10993 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
10994 add_loc_descr (&loc_descr
, tmp
);
10996 /* Extract the vtable address. */
10997 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
10998 add_loc_descr (&loc_descr
, tmp
);
11000 /* Calculate the address of the offset. */
11001 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
11002 gcc_assert (offset
< 0);
11004 tmp
= int_loc_descriptor (-offset
);
11005 add_loc_descr (&loc_descr
, tmp
);
11006 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
11007 add_loc_descr (&loc_descr
, tmp
);
11009 /* Extract the offset. */
11010 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
11011 add_loc_descr (&loc_descr
, tmp
);
11013 /* Add it to the object address. */
11014 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
11015 add_loc_descr (&loc_descr
, tmp
);
11018 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
11021 offset
= field_byte_offset (decl
);
11025 enum dwarf_location_atom op
;
11027 /* The DWARF2 standard says that we should assume that the structure
11028 address is already on the stack, so we can specify a structure field
11029 address by using DW_OP_plus_uconst. */
11031 #ifdef MIPS_DEBUGGING_INFO
11032 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11033 operator correctly. It works only if we leave the offset on the
11037 op
= DW_OP_plus_uconst
;
11040 loc_descr
= new_loc_descr (op
, offset
, 0);
11043 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
11046 /* Writes integer values to dw_vec_const array. */
11049 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
11053 *dest
++ = val
& 0xff;
11059 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11061 static HOST_WIDE_INT
11062 extract_int (const unsigned char *src
, unsigned int size
)
11064 HOST_WIDE_INT val
= 0;
11070 val
|= *--src
& 0xff;
11076 /* Writes floating point values to dw_vec_const array. */
11079 insert_float (const_rtx rtl
, unsigned char *array
)
11081 REAL_VALUE_TYPE rv
;
11085 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
11086 real_to_target (val
, &rv
, GET_MODE (rtl
));
11088 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11089 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
11091 insert_int (val
[i
], 4, array
);
11096 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11097 does not have a "location" either in memory or in a register. These
11098 things can arise in GNU C when a constant is passed as an actual parameter
11099 to an inlined function. They can also arise in C++ where declared
11100 constants do not necessarily get memory "homes". */
11103 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
11105 switch (GET_CODE (rtl
))
11109 HOST_WIDE_INT val
= INTVAL (rtl
);
11112 add_AT_int (die
, DW_AT_const_value
, val
);
11114 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
11119 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11120 floating-point constant. A CONST_DOUBLE is used whenever the
11121 constant requires more than one word in order to be adequately
11122 represented. We output CONST_DOUBLEs as blocks. */
11124 enum machine_mode mode
= GET_MODE (rtl
);
11126 if (SCALAR_FLOAT_MODE_P (mode
))
11128 unsigned int length
= GET_MODE_SIZE (mode
);
11129 unsigned char *array
= GGC_NEWVEC (unsigned char, length
);
11131 insert_float (rtl
, array
);
11132 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
11136 /* ??? We really should be using HOST_WIDE_INT throughout. */
11137 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
11139 add_AT_long_long (die
, DW_AT_const_value
,
11140 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
11147 enum machine_mode mode
= GET_MODE (rtl
);
11148 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
11149 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
11150 unsigned char *array
= GGC_NEWVEC (unsigned char, length
* elt_size
);
11154 switch (GET_MODE_CLASS (mode
))
11156 case MODE_VECTOR_INT
:
11157 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11159 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11160 HOST_WIDE_INT lo
, hi
;
11162 switch (GET_CODE (elt
))
11170 lo
= CONST_DOUBLE_LOW (elt
);
11171 hi
= CONST_DOUBLE_HIGH (elt
);
11175 gcc_unreachable ();
11178 if (elt_size
<= sizeof (HOST_WIDE_INT
))
11179 insert_int (lo
, elt_size
, p
);
11182 unsigned char *p0
= p
;
11183 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
11185 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
11186 if (WORDS_BIG_ENDIAN
)
11191 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
11192 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
11197 case MODE_VECTOR_FLOAT
:
11198 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11200 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11201 insert_float (elt
, p
);
11206 gcc_unreachable ();
11209 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
11214 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
11220 add_AT_addr (die
, DW_AT_const_value
, rtl
);
11221 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11225 /* In cases where an inlined instance of an inline function is passed
11226 the address of an `auto' variable (which is local to the caller) we
11227 can get a situation where the DECL_RTL of the artificial local
11228 variable (for the inlining) which acts as a stand-in for the
11229 corresponding formal parameter (of the inline function) will look
11230 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11231 exactly a compile-time constant expression, but it isn't the address
11232 of the (artificial) local variable either. Rather, it represents the
11233 *value* which the artificial local variable always has during its
11234 lifetime. We currently have no way to represent such quasi-constant
11235 values in Dwarf, so for now we just punt and generate nothing. */
11239 /* No other kinds of rtx should be possible here. */
11240 gcc_unreachable ();
11245 /* Determine whether the evaluation of EXPR references any variables
11246 or functions which aren't otherwise used (and therefore may not be
11249 reference_to_unused (tree
* tp
, int * walk_subtrees
,
11250 void * data ATTRIBUTE_UNUSED
)
11252 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
11253 *walk_subtrees
= 0;
11255 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
11256 && ! TREE_ASM_WRITTEN (*tp
))
11258 /* ??? The C++ FE emits debug information for using decls, so
11259 putting gcc_unreachable here falls over. See PR31899. For now
11260 be conservative. */
11261 else if (!cgraph_global_info_ready
11262 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
11264 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
11266 struct varpool_node
*node
= varpool_node (*tp
);
11270 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
11271 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
11273 struct cgraph_node
*node
= cgraph_node (*tp
);
11274 if (node
->process
|| TREE_ASM_WRITTEN (*tp
))
11277 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
11283 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11284 for use in a later add_const_value_attribute call. */
11287 rtl_for_decl_init (tree init
, tree type
)
11289 rtx rtl
= NULL_RTX
;
11291 /* If a variable is initialized with a string constant without embedded
11292 zeros, build CONST_STRING. */
11293 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
11295 tree enttype
= TREE_TYPE (type
);
11296 tree domain
= TYPE_DOMAIN (type
);
11297 enum machine_mode mode
= TYPE_MODE (enttype
);
11299 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
11301 && integer_zerop (TYPE_MIN_VALUE (domain
))
11302 && compare_tree_int (TYPE_MAX_VALUE (domain
),
11303 TREE_STRING_LENGTH (init
) - 1) == 0
11304 && ((size_t) TREE_STRING_LENGTH (init
)
11305 == strlen (TREE_STRING_POINTER (init
)) + 1))
11306 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
11307 ggc_strdup (TREE_STRING_POINTER (init
)));
11309 /* Other aggregates, and complex values, could be represented using
11311 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
11313 /* Vectors only work if their mode is supported by the target.
11314 FIXME: generic vectors ought to work too. */
11315 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
11317 /* If the initializer is something that we know will expand into an
11318 immediate RTL constant, expand it now. We must be careful not to
11319 reference variables which won't be output. */
11320 else if (initializer_constant_valid_p (init
, type
)
11321 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
11323 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11325 if (TREE_CODE (type
) == VECTOR_TYPE
)
11326 switch (TREE_CODE (init
))
11331 if (TREE_CONSTANT (init
))
11333 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
11334 bool constant_p
= true;
11336 unsigned HOST_WIDE_INT ix
;
11338 /* Even when ctor is constant, it might contain non-*_CST
11339 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11340 belong into VECTOR_CST nodes. */
11341 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
11342 if (!CONSTANT_CLASS_P (value
))
11344 constant_p
= false;
11350 init
= build_vector_from_ctor (type
, elts
);
11360 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
11362 /* If expand_expr returns a MEM, it wasn't immediate. */
11363 gcc_assert (!rtl
|| !MEM_P (rtl
));
11369 /* Generate RTL for the variable DECL to represent its location. */
11372 rtl_for_decl_location (tree decl
)
11376 /* Here we have to decide where we are going to say the parameter "lives"
11377 (as far as the debugger is concerned). We only have a couple of
11378 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11380 DECL_RTL normally indicates where the parameter lives during most of the
11381 activation of the function. If optimization is enabled however, this
11382 could be either NULL or else a pseudo-reg. Both of those cases indicate
11383 that the parameter doesn't really live anywhere (as far as the code
11384 generation parts of GCC are concerned) during most of the function's
11385 activation. That will happen (for example) if the parameter is never
11386 referenced within the function.
11388 We could just generate a location descriptor here for all non-NULL
11389 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11390 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11391 where DECL_RTL is NULL or is a pseudo-reg.
11393 Note however that we can only get away with using DECL_INCOMING_RTL as
11394 a backup substitute for DECL_RTL in certain limited cases. In cases
11395 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11396 we can be sure that the parameter was passed using the same type as it is
11397 declared to have within the function, and that its DECL_INCOMING_RTL
11398 points us to a place where a value of that type is passed.
11400 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11401 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11402 because in these cases DECL_INCOMING_RTL points us to a value of some
11403 type which is *different* from the type of the parameter itself. Thus,
11404 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11405 such cases, the debugger would end up (for example) trying to fetch a
11406 `float' from a place which actually contains the first part of a
11407 `double'. That would lead to really incorrect and confusing
11408 output at debug-time.
11410 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11411 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11412 are a couple of exceptions however. On little-endian machines we can
11413 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11414 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11415 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11416 when (on a little-endian machine) a non-prototyped function has a
11417 parameter declared to be of type `short' or `char'. In such cases,
11418 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11419 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11420 passed `int' value. If the debugger then uses that address to fetch
11421 a `short' or a `char' (on a little-endian machine) the result will be
11422 the correct data, so we allow for such exceptional cases below.
11424 Note that our goal here is to describe the place where the given formal
11425 parameter lives during most of the function's activation (i.e. between the
11426 end of the prologue and the start of the epilogue). We'll do that as best
11427 as we can. Note however that if the given formal parameter is modified
11428 sometime during the execution of the function, then a stack backtrace (at
11429 debug-time) will show the function as having been called with the *new*
11430 value rather than the value which was originally passed in. This happens
11431 rarely enough that it is not a major problem, but it *is* a problem, and
11432 I'd like to fix it.
11434 A future version of dwarf2out.c may generate two additional attributes for
11435 any given DW_TAG_formal_parameter DIE which will describe the "passed
11436 type" and the "passed location" for the given formal parameter in addition
11437 to the attributes we now generate to indicate the "declared type" and the
11438 "active location" for each parameter. This additional set of attributes
11439 could be used by debuggers for stack backtraces. Separately, note that
11440 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11441 This happens (for example) for inlined-instances of inline function formal
11442 parameters which are never referenced. This really shouldn't be
11443 happening. All PARM_DECL nodes should get valid non-NULL
11444 DECL_INCOMING_RTL values. FIXME. */
11446 /* Use DECL_RTL as the "location" unless we find something better. */
11447 rtl
= DECL_RTL_IF_SET (decl
);
11449 /* When generating abstract instances, ignore everything except
11450 constants, symbols living in memory, and symbols living in
11451 fixed registers. */
11452 if (! reload_completed
)
11455 && (CONSTANT_P (rtl
)
11457 && CONSTANT_P (XEXP (rtl
, 0)))
11459 && TREE_CODE (decl
) == VAR_DECL
11460 && TREE_STATIC (decl
))))
11462 rtl
= targetm
.delegitimize_address (rtl
);
11467 else if (TREE_CODE (decl
) == PARM_DECL
)
11469 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
11471 tree declared_type
= TREE_TYPE (decl
);
11472 tree passed_type
= DECL_ARG_TYPE (decl
);
11473 enum machine_mode dmode
= TYPE_MODE (declared_type
);
11474 enum machine_mode pmode
= TYPE_MODE (passed_type
);
11476 /* This decl represents a formal parameter which was optimized out.
11477 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11478 all cases where (rtl == NULL_RTX) just below. */
11479 if (dmode
== pmode
)
11480 rtl
= DECL_INCOMING_RTL (decl
);
11481 else if (SCALAR_INT_MODE_P (dmode
)
11482 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
11483 && DECL_INCOMING_RTL (decl
))
11485 rtx inc
= DECL_INCOMING_RTL (decl
);
11488 else if (MEM_P (inc
))
11490 if (BYTES_BIG_ENDIAN
)
11491 rtl
= adjust_address_nv (inc
, dmode
,
11492 GET_MODE_SIZE (pmode
)
11493 - GET_MODE_SIZE (dmode
));
11500 /* If the parm was passed in registers, but lives on the stack, then
11501 make a big endian correction if the mode of the type of the
11502 parameter is not the same as the mode of the rtl. */
11503 /* ??? This is the same series of checks that are made in dbxout.c before
11504 we reach the big endian correction code there. It isn't clear if all
11505 of these checks are necessary here, but keeping them all is the safe
11507 else if (MEM_P (rtl
)
11508 && XEXP (rtl
, 0) != const0_rtx
11509 && ! CONSTANT_P (XEXP (rtl
, 0))
11510 /* Not passed in memory. */
11511 && !MEM_P (DECL_INCOMING_RTL (decl
))
11512 /* Not passed by invisible reference. */
11513 && (!REG_P (XEXP (rtl
, 0))
11514 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
11515 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
11516 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11517 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
11520 /* Big endian correction check. */
11521 && BYTES_BIG_ENDIAN
11522 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
11523 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
11526 int offset
= (UNITS_PER_WORD
11527 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
11529 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11530 plus_constant (XEXP (rtl
, 0), offset
));
11533 else if (TREE_CODE (decl
) == VAR_DECL
11536 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
11537 && BYTES_BIG_ENDIAN
)
11539 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
11540 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
11542 /* If a variable is declared "register" yet is smaller than
11543 a register, then if we store the variable to memory, it
11544 looks like we're storing a register-sized value, when in
11545 fact we are not. We need to adjust the offset of the
11546 storage location to reflect the actual value's bytes,
11547 else gdb will not be able to display it. */
11549 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11550 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
11553 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11554 and will have been substituted directly into all expressions that use it.
11555 C does not have such a concept, but C++ and other languages do. */
11556 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
11557 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
11560 rtl
= targetm
.delegitimize_address (rtl
);
11562 /* If we don't look past the constant pool, we risk emitting a
11563 reference to a constant pool entry that isn't referenced from
11564 code, and thus is not emitted. */
11566 rtl
= avoid_constant_pool_reference (rtl
);
11571 /* We need to figure out what section we should use as the base for the
11572 address ranges where a given location is valid.
11573 1. If this particular DECL has a section associated with it, use that.
11574 2. If this function has a section associated with it, use that.
11575 3. Otherwise, use the text section.
11576 XXX: If you split a variable across multiple sections, we won't notice. */
11578 static const char *
11579 secname_for_decl (const_tree decl
)
11581 const char *secname
;
11583 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
11585 tree sectree
= DECL_SECTION_NAME (decl
);
11586 secname
= TREE_STRING_POINTER (sectree
);
11588 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
11590 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
11591 secname
= TREE_STRING_POINTER (sectree
);
11593 else if (cfun
&& in_cold_section_p
)
11594 secname
= crtl
->subsections
.cold_section_label
;
11596 secname
= text_section_label
;
11601 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
11602 returned. If so, the decl for the COMMON block is returned, and the
11603 value is the offset into the common block for the symbol. */
11606 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
11608 tree val_expr
, cvar
;
11609 enum machine_mode mode
;
11610 HOST_WIDE_INT bitsize
, bitpos
;
11612 int volatilep
= 0, unsignedp
= 0;
11614 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11615 it does not have a value (the offset into the common area), or if it
11616 is thread local (as opposed to global) then it isn't common, and shouldn't
11617 be handled as such. */
11618 if (TREE_CODE (decl
) != VAR_DECL
11619 || !TREE_PUBLIC (decl
)
11620 || !TREE_STATIC (decl
)
11621 || !DECL_HAS_VALUE_EXPR_P (decl
)
11625 val_expr
= DECL_VALUE_EXPR (decl
);
11626 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
11629 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
11630 &mode
, &unsignedp
, &volatilep
, true);
11632 if (cvar
== NULL_TREE
11633 || TREE_CODE (cvar
) != VAR_DECL
11634 || DECL_ARTIFICIAL (cvar
)
11635 || !TREE_PUBLIC (cvar
))
11639 if (offset
!= NULL
)
11641 if (!host_integerp (offset
, 0))
11643 *value
= tree_low_cst (offset
, 0);
11646 *value
+= bitpos
/ BITS_PER_UNIT
;
11651 /* Dereference a location expression LOC if DECL is passed by invisible
11654 static dw_loc_descr_ref
11655 loc_by_reference (dw_loc_descr_ref loc
, tree decl
)
11657 HOST_WIDE_INT size
;
11658 enum dwarf_location_atom op
;
11663 if ((TREE_CODE (decl
) != PARM_DECL
11664 && TREE_CODE (decl
) != RESULT_DECL
11665 && TREE_CODE (decl
) != VAR_DECL
)
11666 || !DECL_BY_REFERENCE (decl
))
11669 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
11670 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
11671 location expression is considered to be address of a memory location,
11672 rather than the register itself. */
11673 if (((loc
->dw_loc_opc
>= DW_OP_reg0
&& loc
->dw_loc_opc
<= DW_OP_reg31
)
11674 || loc
->dw_loc_opc
== DW_OP_regx
)
11675 && (loc
->dw_loc_next
== NULL
11676 || (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_uninit
11677 && loc
->dw_loc_next
->dw_loc_next
== NULL
)))
11679 if (loc
->dw_loc_opc
== DW_OP_regx
)
11681 loc
->dw_loc_opc
= DW_OP_bregx
;
11682 loc
->dw_loc_oprnd2
.v
.val_int
= 0;
11687 = (enum dwarf_location_atom
)
11688 (loc
->dw_loc_opc
+ (DW_OP_breg0
- DW_OP_reg0
));
11689 loc
->dw_loc_oprnd1
.v
.val_int
= 0;
11694 size
= int_size_in_bytes (TREE_TYPE (decl
));
11695 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
11697 else if (size
== DWARF2_ADDR_SIZE
)
11700 op
= DW_OP_deref_size
;
11701 add_loc_descr (&loc
, new_loc_descr (op
, size
, 0));
11705 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11706 data attribute for a variable or a parameter. We generate the
11707 DW_AT_const_value attribute only in those cases where the given variable
11708 or parameter does not have a true "location" either in memory or in a
11709 register. This can happen (for example) when a constant is passed as an
11710 actual argument in a call to an inline function. (It's possible that
11711 these things can crop up in other ways also.) Note that one type of
11712 constant value which can be passed into an inlined function is a constant
11713 pointer. This can happen for example if an actual argument in an inlined
11714 function call evaluates to a compile-time constant address. */
11717 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
11718 enum dwarf_attribute attr
)
11721 dw_loc_descr_ref descr
;
11722 var_loc_list
*loc_list
;
11723 struct var_loc_node
*node
;
11724 if (TREE_CODE (decl
) == ERROR_MARK
)
11727 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
11728 || TREE_CODE (decl
) == RESULT_DECL
);
11730 /* See if we possibly have multiple locations for this variable. */
11731 loc_list
= lookup_decl_loc (decl
);
11733 /* If it truly has multiple locations, the first and last node will
11735 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
11737 const char *endname
, *secname
;
11738 dw_loc_list_ref list
;
11740 enum var_init_status initialized
;
11742 /* Now that we know what section we are using for a base,
11743 actually construct the list of locations.
11744 The first location information is what is passed to the
11745 function that creates the location list, and the remaining
11746 locations just get added on to that list.
11747 Note that we only know the start address for a location
11748 (IE location changes), so to build the range, we use
11749 the range [current location start, next location start].
11750 This means we have to special case the last node, and generate
11751 a range of [last location start, end of function label]. */
11753 node
= loc_list
->first
;
11754 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11755 secname
= secname_for_decl (decl
);
11757 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
))
11758 initialized
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11760 initialized
= VAR_INIT_STATUS_INITIALIZED
;
11762 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
), decl
);
11763 list
= new_loc_list (descr
, node
->label
, node
->next
->label
, secname
, 1);
11766 for (; node
->next
; node
= node
->next
)
11767 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11769 /* The variable has a location between NODE->LABEL and
11770 NODE->NEXT->LABEL. */
11771 enum var_init_status initialized
=
11772 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11773 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11774 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
11776 add_loc_descr_to_loc_list (&list
, descr
,
11777 node
->label
, node
->next
->label
, secname
);
11780 /* If the variable has a location at the last label
11781 it keeps its location until the end of function. */
11782 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11784 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11785 enum var_init_status initialized
=
11786 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11788 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11789 if (!current_function_decl
)
11790 endname
= text_end_label
;
11793 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11794 current_function_funcdef_no
);
11795 endname
= ggc_strdup (label_id
);
11797 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
11799 add_loc_descr_to_loc_list (&list
, descr
,
11800 node
->label
, endname
, secname
);
11803 /* Finally, add the location list to the DIE, and we are done. */
11804 add_AT_loc_list (die
, attr
, list
);
11808 /* Try to get some constant RTL for this decl, and use that as the value of
11811 rtl
= rtl_for_decl_location (decl
);
11812 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
11814 add_const_value_attribute (die
, rtl
);
11818 /* If we have tried to generate the location otherwise, and it
11819 didn't work out (we wouldn't be here if we did), and we have a one entry
11820 location list, try generating a location from that. */
11821 if (loc_list
&& loc_list
->first
)
11823 enum var_init_status status
;
11824 node
= loc_list
->first
;
11825 status
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11826 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
), status
);
11829 descr
= loc_by_reference (descr
, decl
);
11830 add_AT_location_description (die
, attr
, descr
);
11835 /* We couldn't get any rtl, so try directly generating the location
11836 description from the tree. */
11837 descr
= loc_descriptor_from_tree (decl
);
11840 descr
= loc_by_reference (descr
, decl
);
11841 add_AT_location_description (die
, attr
, descr
);
11844 /* None of that worked, so it must not really have a location;
11845 try adding a constant value attribute from the DECL_INITIAL. */
11846 tree_add_const_value_attribute (die
, decl
);
11849 /* Add VARIABLE and DIE into deferred locations list. */
11852 defer_location (tree variable
, dw_die_ref die
)
11854 deferred_locations entry
;
11855 entry
.variable
= variable
;
11857 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
11860 /* Helper function for tree_add_const_value_attribute. Natively encode
11861 initializer INIT into an array. Return true if successful. */
11864 native_encode_initializer (tree init
, unsigned char *array
, int size
)
11868 if (init
== NULL_TREE
)
11872 switch (TREE_CODE (init
))
11875 type
= TREE_TYPE (init
);
11876 if (TREE_CODE (type
) == ARRAY_TYPE
)
11878 tree enttype
= TREE_TYPE (type
);
11879 enum machine_mode mode
= TYPE_MODE (enttype
);
11881 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
11883 if (int_size_in_bytes (type
) != size
)
11885 if (size
> TREE_STRING_LENGTH (init
))
11887 memcpy (array
, TREE_STRING_POINTER (init
),
11888 TREE_STRING_LENGTH (init
));
11889 memset (array
+ TREE_STRING_LENGTH (init
),
11890 '\0', size
- TREE_STRING_LENGTH (init
));
11893 memcpy (array
, TREE_STRING_POINTER (init
), size
);
11898 type
= TREE_TYPE (init
);
11899 if (int_size_in_bytes (type
) != size
)
11901 if (TREE_CODE (type
) == ARRAY_TYPE
)
11903 HOST_WIDE_INT min_index
;
11904 unsigned HOST_WIDE_INT cnt
;
11905 int curpos
= 0, fieldsize
;
11906 constructor_elt
*ce
;
11908 if (TYPE_DOMAIN (type
) == NULL_TREE
11909 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
11912 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
11913 if (fieldsize
<= 0)
11916 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
11917 memset (array
, '\0', size
);
11919 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
11922 tree val
= ce
->value
;
11923 tree index
= ce
->index
;
11925 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
11926 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
11929 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
11934 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
11937 curpos
= pos
+ fieldsize
;
11938 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
11940 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
11941 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
11945 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
11946 curpos
+= fieldsize
;
11949 gcc_assert (curpos
<= size
);
11953 else if (TREE_CODE (type
) == RECORD_TYPE
11954 || TREE_CODE (type
) == UNION_TYPE
)
11956 tree field
= NULL_TREE
;
11957 unsigned HOST_WIDE_INT cnt
;
11958 constructor_elt
*ce
;
11960 if (int_size_in_bytes (type
) != size
)
11963 if (TREE_CODE (type
) == RECORD_TYPE
)
11964 field
= TYPE_FIELDS (type
);
11967 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
11968 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
11970 tree val
= ce
->value
;
11971 int pos
, fieldsize
;
11973 if (ce
->index
!= 0)
11979 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
11982 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
11983 && TYPE_DOMAIN (TREE_TYPE (field
))
11984 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
11986 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
11987 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
11989 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
11990 pos
= int_byte_position (field
);
11991 gcc_assert (pos
+ fieldsize
<= size
);
11993 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
11999 case VIEW_CONVERT_EXPR
:
12000 case NON_LVALUE_EXPR
:
12001 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
12003 return native_encode_expr (init
, array
, size
) == size
;
12007 /* If we don't have a copy of this variable in memory for some reason (such
12008 as a C++ member constant that doesn't have an out-of-line definition),
12009 we should tell the debugger about the constant value. */
12012 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
12015 tree type
= TREE_TYPE (decl
);
12018 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
12021 init
= DECL_INITIAL (decl
);
12022 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
12027 rtl
= rtl_for_decl_init (init
, type
);
12029 add_const_value_attribute (var_die
, rtl
);
12030 /* If the host and target are sane, try harder. */
12031 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
12032 && initializer_constant_valid_p (init
, type
))
12034 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
12035 if (size
> 0 && (int) size
== size
)
12037 unsigned char *array
= GGC_CNEWVEC (unsigned char, size
);
12039 if (native_encode_initializer (init
, array
, size
))
12040 add_AT_vec (var_die
, DW_AT_const_value
, size
, 1, array
);
12045 /* Convert the CFI instructions for the current function into a
12046 location list. This is used for DW_AT_frame_base when we targeting
12047 a dwarf2 consumer that does not support the dwarf3
12048 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12051 static dw_loc_list_ref
12052 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
12055 dw_loc_list_ref list
, *list_tail
;
12057 dw_cfa_location last_cfa
, next_cfa
;
12058 const char *start_label
, *last_label
, *section
;
12060 fde
= current_fde ();
12061 gcc_assert (fde
!= NULL
);
12063 section
= secname_for_decl (current_function_decl
);
12067 next_cfa
.reg
= INVALID_REGNUM
;
12068 next_cfa
.offset
= 0;
12069 next_cfa
.indirect
= 0;
12070 next_cfa
.base_offset
= 0;
12072 start_label
= fde
->dw_fde_begin
;
12074 /* ??? Bald assumption that the CIE opcode list does not contain
12075 advance opcodes. */
12076 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
12077 lookup_cfa_1 (cfi
, &next_cfa
);
12079 last_cfa
= next_cfa
;
12080 last_label
= start_label
;
12082 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
12083 switch (cfi
->dw_cfi_opc
)
12085 case DW_CFA_set_loc
:
12086 case DW_CFA_advance_loc1
:
12087 case DW_CFA_advance_loc2
:
12088 case DW_CFA_advance_loc4
:
12089 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12091 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12092 start_label
, last_label
, section
,
12095 list_tail
= &(*list_tail
)->dw_loc_next
;
12096 last_cfa
= next_cfa
;
12097 start_label
= last_label
;
12099 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
12102 case DW_CFA_advance_loc
:
12103 /* The encoding is complex enough that we should never emit this. */
12104 case DW_CFA_remember_state
:
12105 case DW_CFA_restore_state
:
12106 /* We don't handle these two in this function. It would be possible
12107 if it were to be required. */
12108 gcc_unreachable ();
12111 lookup_cfa_1 (cfi
, &next_cfa
);
12115 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12117 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12118 start_label
, last_label
, section
,
12120 list_tail
= &(*list_tail
)->dw_loc_next
;
12121 start_label
= last_label
;
12123 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
12124 start_label
, fde
->dw_fde_end
, section
,
12130 /* Compute a displacement from the "steady-state frame pointer" to the
12131 frame base (often the same as the CFA), and store it in
12132 frame_pointer_fb_offset. OFFSET is added to the displacement
12133 before the latter is negated. */
12136 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
12140 #ifdef FRAME_POINTER_CFA_OFFSET
12141 reg
= frame_pointer_rtx
;
12142 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
12144 reg
= arg_pointer_rtx
;
12145 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
12148 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
12149 if (GET_CODE (elim
) == PLUS
)
12151 offset
+= INTVAL (XEXP (elim
, 1));
12152 elim
= XEXP (elim
, 0);
12155 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12156 && (elim
== hard_frame_pointer_rtx
12157 || elim
== stack_pointer_rtx
))
12158 || elim
== (frame_pointer_needed
12159 ? hard_frame_pointer_rtx
12160 : stack_pointer_rtx
));
12162 frame_pointer_fb_offset
= -offset
;
12165 /* Generate a DW_AT_name attribute given some string value to be included as
12166 the value of the attribute. */
12169 add_name_attribute (dw_die_ref die
, const char *name_string
)
12171 if (name_string
!= NULL
&& *name_string
!= 0)
12173 if (demangle_name_func
)
12174 name_string
= (*demangle_name_func
) (name_string
);
12176 add_AT_string (die
, DW_AT_name
, name_string
);
12180 /* Generate a DW_AT_comp_dir attribute for DIE. */
12183 add_comp_dir_attribute (dw_die_ref die
)
12185 const char *wd
= get_src_pwd ();
12187 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
12190 /* Given a tree node describing an array bound (either lower or upper) output
12191 a representation for that bound. */
12194 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
12196 switch (TREE_CODE (bound
))
12201 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12203 if (! host_integerp (bound
, 0)
12204 || (bound_attr
== DW_AT_lower_bound
12205 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
12206 || (is_fortran () && integer_onep (bound
)))))
12207 /* Use the default. */
12210 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
12214 case VIEW_CONVERT_EXPR
:
12215 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
12225 dw_die_ref decl_die
= lookup_decl_die (bound
);
12226 dw_loc_descr_ref loc
;
12228 /* ??? Can this happen, or should the variable have been bound
12229 first? Probably it can, since I imagine that we try to create
12230 the types of parameters in the order in which they exist in
12231 the list, and won't have created a forward reference to a
12232 later parameter. */
12233 if (decl_die
!= NULL
)
12234 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12237 loc
= loc_descriptor_from_tree_1 (bound
, 0);
12238 add_AT_location_description (subrange_die
, bound_attr
, loc
);
12245 /* Otherwise try to create a stack operation procedure to
12246 evaluate the value of the array bound. */
12248 dw_die_ref ctx
, decl_die
;
12249 dw_loc_descr_ref loc
;
12251 loc
= loc_descriptor_from_tree (bound
);
12255 if (current_function_decl
== 0)
12256 ctx
= comp_unit_die
;
12258 ctx
= lookup_decl_die (current_function_decl
);
12260 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
12261 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12262 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
12263 add_AT_loc (decl_die
, DW_AT_location
, loc
);
12265 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12271 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12272 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12273 Note that the block of subscript information for an array type also
12274 includes information about the element type of the given array type. */
12277 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
12279 unsigned dimension_number
;
12281 dw_die_ref subrange_die
;
12283 for (dimension_number
= 0;
12284 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
12285 type
= TREE_TYPE (type
), dimension_number
++)
12287 tree domain
= TYPE_DOMAIN (type
);
12289 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
12292 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12293 and (in GNU C only) variable bounds. Handle all three forms
12295 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
12298 /* We have an array type with specified bounds. */
12299 lower
= TYPE_MIN_VALUE (domain
);
12300 upper
= TYPE_MAX_VALUE (domain
);
12302 /* Define the index type. */
12303 if (TREE_TYPE (domain
))
12305 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12306 TREE_TYPE field. We can't emit debug info for this
12307 because it is an unnamed integral type. */
12308 if (TREE_CODE (domain
) == INTEGER_TYPE
12309 && TYPE_NAME (domain
) == NULL_TREE
12310 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
12311 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
12314 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
12318 /* ??? If upper is NULL, the array has unspecified length,
12319 but it does have a lower bound. This happens with Fortran
12321 Since the debugger is definitely going to need to know N
12322 to produce useful results, go ahead and output the lower
12323 bound solo, and hope the debugger can cope. */
12325 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
12327 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
12330 /* Otherwise we have an array type with an unspecified length. The
12331 DWARF-2 spec does not say how to handle this; let's just leave out the
12337 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
12341 switch (TREE_CODE (tree_node
))
12346 case ENUMERAL_TYPE
:
12349 case QUAL_UNION_TYPE
:
12350 size
= int_size_in_bytes (tree_node
);
12353 /* For a data member of a struct or union, the DW_AT_byte_size is
12354 generally given as the number of bytes normally allocated for an
12355 object of the *declared* type of the member itself. This is true
12356 even for bit-fields. */
12357 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
12360 gcc_unreachable ();
12363 /* Note that `size' might be -1 when we get to this point. If it is, that
12364 indicates that the byte size of the entity in question is variable. We
12365 have no good way of expressing this fact in Dwarf at the present time,
12366 so just let the -1 pass on through. */
12367 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
12370 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12371 which specifies the distance in bits from the highest order bit of the
12372 "containing object" for the bit-field to the highest order bit of the
12375 For any given bit-field, the "containing object" is a hypothetical object
12376 (of some integral or enum type) within which the given bit-field lives. The
12377 type of this hypothetical "containing object" is always the same as the
12378 declared type of the individual bit-field itself. The determination of the
12379 exact location of the "containing object" for a bit-field is rather
12380 complicated. It's handled by the `field_byte_offset' function (above).
12382 Note that it is the size (in bytes) of the hypothetical "containing object"
12383 which will be given in the DW_AT_byte_size attribute for this bit-field.
12384 (See `byte_size_attribute' above). */
12387 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
12389 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
12390 tree type
= DECL_BIT_FIELD_TYPE (decl
);
12391 HOST_WIDE_INT bitpos_int
;
12392 HOST_WIDE_INT highest_order_object_bit_offset
;
12393 HOST_WIDE_INT highest_order_field_bit_offset
;
12394 HOST_WIDE_INT
unsigned bit_offset
;
12396 /* Must be a field and a bit field. */
12397 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
12399 /* We can't yet handle bit-fields whose offsets are variable, so if we
12400 encounter such things, just return without generating any attribute
12401 whatsoever. Likewise for variable or too large size. */
12402 if (! host_integerp (bit_position (decl
), 0)
12403 || ! host_integerp (DECL_SIZE (decl
), 1))
12406 bitpos_int
= int_bit_position (decl
);
12408 /* Note that the bit offset is always the distance (in bits) from the
12409 highest-order bit of the "containing object" to the highest-order bit of
12410 the bit-field itself. Since the "high-order end" of any object or field
12411 is different on big-endian and little-endian machines, the computation
12412 below must take account of these differences. */
12413 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
12414 highest_order_field_bit_offset
= bitpos_int
;
12416 if (! BYTES_BIG_ENDIAN
)
12418 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
12419 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
12423 = (! BYTES_BIG_ENDIAN
12424 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
12425 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
12427 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
12430 /* For a FIELD_DECL node which represents a bit field, output an attribute
12431 which specifies the length in bits of the given field. */
12434 add_bit_size_attribute (dw_die_ref die
, tree decl
)
12436 /* Must be a field and a bit field. */
12437 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
12438 && DECL_BIT_FIELD_TYPE (decl
));
12440 if (host_integerp (DECL_SIZE (decl
), 1))
12441 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
12444 /* If the compiled language is ANSI C, then add a 'prototyped'
12445 attribute, if arg types are given for the parameters of a function. */
12448 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
12450 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
12451 && TYPE_ARG_TYPES (func_type
) != NULL
)
12452 add_AT_flag (die
, DW_AT_prototyped
, 1);
12455 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12456 by looking in either the type declaration or object declaration
12459 static inline dw_die_ref
12460 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
12462 dw_die_ref origin_die
= NULL
;
12464 if (TREE_CODE (origin
) != FUNCTION_DECL
)
12466 /* We may have gotten separated from the block for the inlined
12467 function, if we're in an exception handler or some such; make
12468 sure that the abstract function has been written out.
12470 Doing this for nested functions is wrong, however; functions are
12471 distinct units, and our context might not even be inline. */
12475 fn
= TYPE_STUB_DECL (fn
);
12477 fn
= decl_function_context (fn
);
12479 dwarf2out_abstract_function (fn
);
12482 if (DECL_P (origin
))
12483 origin_die
= lookup_decl_die (origin
);
12484 else if (TYPE_P (origin
))
12485 origin_die
= lookup_type_die (origin
);
12487 /* XXX: Functions that are never lowered don't always have correct block
12488 trees (in the case of java, they simply have no block tree, in some other
12489 languages). For these functions, there is nothing we can really do to
12490 output correct debug info for inlined functions in all cases. Rather
12491 than die, we'll just produce deficient debug info now, in that we will
12492 have variables without a proper abstract origin. In the future, when all
12493 functions are lowered, we should re-add a gcc_assert (origin_die)
12497 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
12501 /* We do not currently support the pure_virtual attribute. */
12504 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
12506 if (DECL_VINDEX (func_decl
))
12508 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12510 if (host_integerp (DECL_VINDEX (func_decl
), 0))
12511 add_AT_loc (die
, DW_AT_vtable_elem_location
,
12512 new_loc_descr (DW_OP_constu
,
12513 tree_low_cst (DECL_VINDEX (func_decl
), 0),
12516 /* GNU extension: Record what type this method came from originally. */
12517 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12518 add_AT_die_ref (die
, DW_AT_containing_type
,
12519 lookup_type_die (DECL_CONTEXT (func_decl
)));
12523 /* Add source coordinate attributes for the given decl. */
12526 add_src_coords_attributes (dw_die_ref die
, tree decl
)
12528 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12530 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
12531 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
12534 /* Add a DW_AT_name attribute and source coordinate attribute for the
12535 given decl, but only if it actually has a name. */
12538 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
12542 decl_name
= DECL_NAME (decl
);
12543 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
12545 add_name_attribute (die
, dwarf2_name (decl
, 0));
12546 if (! DECL_ARTIFICIAL (decl
))
12547 add_src_coords_attributes (die
, decl
);
12549 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
12550 && TREE_PUBLIC (decl
)
12551 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
12552 && !DECL_ABSTRACT (decl
)
12553 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
12555 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
12556 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
12559 #ifdef VMS_DEBUGGING_INFO
12560 /* Get the function's name, as described by its RTL. This may be different
12561 from the DECL_NAME name used in the source file. */
12562 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
12564 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
12565 XEXP (DECL_RTL (decl
), 0));
12566 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
12571 /* Push a new declaration scope. */
12574 push_decl_scope (tree scope
)
12576 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
12579 /* Pop a declaration scope. */
12582 pop_decl_scope (void)
12584 VEC_pop (tree
, decl_scope_table
);
12587 /* Return the DIE for the scope that immediately contains this type.
12588 Non-named types get global scope. Named types nested in other
12589 types get their containing scope if it's open, or global scope
12590 otherwise. All other types (i.e. function-local named types) get
12591 the current active scope. */
12594 scope_die_for (tree t
, dw_die_ref context_die
)
12596 dw_die_ref scope_die
= NULL
;
12597 tree containing_scope
;
12600 /* Non-types always go in the current scope. */
12601 gcc_assert (TYPE_P (t
));
12603 containing_scope
= TYPE_CONTEXT (t
);
12605 /* Use the containing namespace if it was passed in (for a declaration). */
12606 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
12608 if (context_die
== lookup_decl_die (containing_scope
))
12611 containing_scope
= NULL_TREE
;
12614 /* Ignore function type "scopes" from the C frontend. They mean that
12615 a tagged type is local to a parmlist of a function declarator, but
12616 that isn't useful to DWARF. */
12617 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
12618 containing_scope
= NULL_TREE
;
12620 if (containing_scope
== NULL_TREE
)
12621 scope_die
= comp_unit_die
;
12622 else if (TYPE_P (containing_scope
))
12624 /* For types, we can just look up the appropriate DIE. But
12625 first we check to see if we're in the middle of emitting it
12626 so we know where the new DIE should go. */
12627 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
12628 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
12633 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
12634 || TREE_ASM_WRITTEN (containing_scope
));
12636 /* If none of the current dies are suitable, we get file scope. */
12637 scope_die
= comp_unit_die
;
12640 scope_die
= lookup_type_die (containing_scope
);
12643 scope_die
= context_die
;
12648 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12651 local_scope_p (dw_die_ref context_die
)
12653 for (; context_die
; context_die
= context_die
->die_parent
)
12654 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
12655 || context_die
->die_tag
== DW_TAG_subprogram
)
12661 /* Returns nonzero if CONTEXT_DIE is a class. */
12664 class_scope_p (dw_die_ref context_die
)
12666 return (context_die
12667 && (context_die
->die_tag
== DW_TAG_structure_type
12668 || context_die
->die_tag
== DW_TAG_class_type
12669 || context_die
->die_tag
== DW_TAG_interface_type
12670 || context_die
->die_tag
== DW_TAG_union_type
));
12673 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12674 whether or not to treat a DIE in this context as a declaration. */
12677 class_or_namespace_scope_p (dw_die_ref context_die
)
12679 return (class_scope_p (context_die
)
12680 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
12683 /* Many forms of DIEs require a "type description" attribute. This
12684 routine locates the proper "type descriptor" die for the type given
12685 by 'type', and adds a DW_AT_type attribute below the given die. */
12688 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
12689 int decl_volatile
, dw_die_ref context_die
)
12691 enum tree_code code
= TREE_CODE (type
);
12692 dw_die_ref type_die
= NULL
;
12694 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12695 or fixed-point type, use the inner type. This is because we have no
12696 support for unnamed types in base_type_die. This can happen if this is
12697 an Ada subrange type. Correct solution is emit a subrange type die. */
12698 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
12699 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
12700 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
12702 if (code
== ERROR_MARK
12703 /* Handle a special case. For functions whose return type is void, we
12704 generate *no* type attribute. (Note that no object may have type
12705 `void', so this only applies to function return types). */
12706 || code
== VOID_TYPE
)
12709 type_die
= modified_type_die (type
,
12710 decl_const
|| TYPE_READONLY (type
),
12711 decl_volatile
|| TYPE_VOLATILE (type
),
12714 if (type_die
!= NULL
)
12715 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
12718 /* Given an object die, add the calling convention attribute for the
12719 function call type. */
12721 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
12723 enum dwarf_calling_convention value
= DW_CC_normal
;
12725 value
= ((enum dwarf_calling_convention
)
12726 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
12728 /* DWARF doesn't provide a way to identify a program's source-level
12729 entry point. DW_AT_calling_convention attributes are only meant
12730 to describe functions' calling conventions. However, lacking a
12731 better way to signal the Fortran main program, we use this for the
12732 time being, following existing custom. */
12734 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
12735 value
= DW_CC_program
;
12737 /* Only add the attribute if the backend requests it, and
12738 is not DW_CC_normal. */
12739 if (value
&& (value
!= DW_CC_normal
))
12740 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
12743 /* Given a tree pointer to a struct, class, union, or enum type node, return
12744 a pointer to the (string) tag name for the given type, or zero if the type
12745 was declared without a tag. */
12747 static const char *
12748 type_tag (const_tree type
)
12750 const char *name
= 0;
12752 if (TYPE_NAME (type
) != 0)
12756 /* Find the IDENTIFIER_NODE for the type name. */
12757 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
12758 t
= TYPE_NAME (type
);
12760 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12761 a TYPE_DECL node, regardless of whether or not a `typedef' was
12763 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12764 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
12766 /* We want to be extra verbose. Don't call dwarf_name if
12767 DECL_NAME isn't set. The default hook for decl_printable_name
12768 doesn't like that, and in this context it's correct to return
12769 0, instead of "<anonymous>" or the like. */
12770 if (DECL_NAME (TYPE_NAME (type
)))
12771 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
12774 /* Now get the name as a string, or invent one. */
12775 if (!name
&& t
!= 0)
12776 name
= IDENTIFIER_POINTER (t
);
12779 return (name
== 0 || *name
== '\0') ? 0 : name
;
12782 /* Return the type associated with a data member, make a special check
12783 for bit field types. */
12786 member_declared_type (const_tree member
)
12788 return (DECL_BIT_FIELD_TYPE (member
)
12789 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
12792 /* Get the decl's label, as described by its RTL. This may be different
12793 from the DECL_NAME name used in the source file. */
12796 static const char *
12797 decl_start_label (tree decl
)
12800 const char *fnname
;
12802 x
= DECL_RTL (decl
);
12803 gcc_assert (MEM_P (x
));
12806 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
12808 fnname
= XSTR (x
, 0);
12813 /* These routines generate the internal representation of the DIE's for
12814 the compilation unit. Debugging information is collected by walking
12815 the declaration trees passed in from dwarf2out_decl(). */
12818 gen_array_type_die (tree type
, dw_die_ref context_die
)
12820 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
12821 dw_die_ref array_die
;
12823 /* GNU compilers represent multidimensional array types as sequences of one
12824 dimensional array types whose element types are themselves array types.
12825 We sometimes squish that down to a single array_type DIE with multiple
12826 subscripts in the Dwarf debugging info. The draft Dwarf specification
12827 say that we are allowed to do this kind of compression in C, because
12828 there is no difference between an array of arrays and a multidimensional
12829 array. We don't do this for Ada to remain as close as possible to the
12830 actual representation, which is especially important against the language
12831 flexibilty wrt arrays of variable size. */
12833 bool collapse_nested_arrays
= !is_ada ();
12836 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
12837 DW_TAG_string_type doesn't have DW_AT_type attribute). */
12838 if (TYPE_STRING_FLAG (type
)
12839 && TREE_CODE (type
) == ARRAY_TYPE
12841 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
12843 HOST_WIDE_INT size
;
12845 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
12846 add_name_attribute (array_die
, type_tag (type
));
12847 equate_type_number_to_die (type
, array_die
);
12848 size
= int_size_in_bytes (type
);
12850 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
12851 else if (TYPE_DOMAIN (type
) != NULL_TREE
12852 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
12853 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
12855 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
12856 dw_loc_descr_ref loc
= loc_descriptor_from_tree (szdecl
);
12858 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
12859 if (loc
&& size
> 0)
12861 add_AT_loc (array_die
, DW_AT_string_length
, loc
);
12862 if (size
!= DWARF2_ADDR_SIZE
)
12863 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
12869 /* ??? The SGI dwarf reader fails for array of array of enum types
12870 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12871 array type comes before the outer array type. We thus call gen_type_die
12872 before we new_die and must prevent nested array types collapsing for this
12875 #ifdef MIPS_DEBUGGING_INFO
12876 gen_type_die (TREE_TYPE (type
), context_die
);
12877 collapse_nested_arrays
= false;
12880 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
12881 add_name_attribute (array_die
, type_tag (type
));
12882 equate_type_number_to_die (type
, array_die
);
12884 if (TREE_CODE (type
) == VECTOR_TYPE
)
12886 /* The frontend feeds us a representation for the vector as a struct
12887 containing an array. Pull out the array type. */
12888 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
12889 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
12892 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12894 && TREE_CODE (type
) == ARRAY_TYPE
12895 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
12896 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
12897 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
12900 /* We default the array ordering. SDB will probably do
12901 the right things even if DW_AT_ordering is not present. It's not even
12902 an issue until we start to get into multidimensional arrays anyway. If
12903 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12904 then we'll have to put the DW_AT_ordering attribute back in. (But if
12905 and when we find out that we need to put these in, we will only do so
12906 for multidimensional arrays. */
12907 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
12910 #ifdef MIPS_DEBUGGING_INFO
12911 /* The SGI compilers handle arrays of unknown bound by setting
12912 AT_declaration and not emitting any subrange DIEs. */
12913 if (! TYPE_DOMAIN (type
))
12914 add_AT_flag (array_die
, DW_AT_declaration
, 1);
12917 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
12919 /* Add representation of the type of the elements of this array type and
12920 emit the corresponding DIE if we haven't done it already. */
12921 element_type
= TREE_TYPE (type
);
12922 if (collapse_nested_arrays
)
12923 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
12925 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
12927 element_type
= TREE_TYPE (element_type
);
12930 #ifndef MIPS_DEBUGGING_INFO
12931 gen_type_die (element_type
, context_die
);
12934 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
12936 if (get_AT (array_die
, DW_AT_name
))
12937 add_pubtype (type
, array_die
);
12940 static dw_loc_descr_ref
12941 descr_info_loc (tree val
, tree base_decl
)
12943 HOST_WIDE_INT size
;
12944 dw_loc_descr_ref loc
, loc2
;
12945 enum dwarf_location_atom op
;
12947 if (val
== base_decl
)
12948 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
12950 switch (TREE_CODE (val
))
12953 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12955 return loc_descriptor_from_tree_1 (val
, 0);
12957 if (host_integerp (val
, 0))
12958 return int_loc_descriptor (tree_low_cst (val
, 0));
12961 size
= int_size_in_bytes (TREE_TYPE (val
));
12964 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12967 if (size
== DWARF2_ADDR_SIZE
)
12968 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
12970 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
12972 case POINTER_PLUS_EXPR
:
12974 if (host_integerp (TREE_OPERAND (val
, 1), 1)
12975 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
12978 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12981 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
12987 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12990 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
12993 add_loc_descr (&loc
, loc2
);
12994 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
13016 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
13017 tree val
, tree base_decl
)
13019 dw_loc_descr_ref loc
;
13021 if (host_integerp (val
, 0))
13023 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
13027 loc
= descr_info_loc (val
, base_decl
);
13031 add_AT_loc (die
, attr
, loc
);
13034 /* This routine generates DIE for array with hidden descriptor, details
13035 are filled into *info by a langhook. */
13038 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
13039 dw_die_ref context_die
)
13041 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
13042 dw_die_ref array_die
;
13045 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
13046 add_name_attribute (array_die
, type_tag (type
));
13047 equate_type_number_to_die (type
, array_die
);
13049 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13051 && info
->ndimensions
>= 2)
13052 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
13054 if (info
->data_location
)
13055 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
13057 if (info
->associated
)
13058 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
13060 if (info
->allocated
)
13061 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
13064 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
13066 dw_die_ref subrange_die
13067 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
13069 if (info
->dimen
[dim
].lower_bound
)
13071 /* If it is the default value, omit it. */
13072 if ((is_c_family () || is_java ())
13073 && integer_zerop (info
->dimen
[dim
].lower_bound
))
13075 else if (is_fortran ()
13076 && integer_onep (info
->dimen
[dim
].lower_bound
))
13079 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
13080 info
->dimen
[dim
].lower_bound
,
13083 if (info
->dimen
[dim
].upper_bound
)
13084 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
13085 info
->dimen
[dim
].upper_bound
,
13087 if (info
->dimen
[dim
].stride
)
13088 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
13089 info
->dimen
[dim
].stride
,
13093 gen_type_die (info
->element_type
, context_die
);
13094 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
13096 if (get_AT (array_die
, DW_AT_name
))
13097 add_pubtype (type
, array_die
);
13102 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
13104 tree origin
= decl_ultimate_origin (decl
);
13105 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
13107 if (origin
!= NULL
)
13108 add_abstract_origin_attribute (decl_die
, origin
);
13111 add_name_and_src_coords_attributes (decl_die
, decl
);
13112 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
13113 0, 0, context_die
);
13116 if (DECL_ABSTRACT (decl
))
13117 equate_decl_number_to_die (decl
, decl_die
);
13119 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
13123 /* Walk through the list of incomplete types again, trying once more to
13124 emit full debugging info for them. */
13127 retry_incomplete_types (void)
13131 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
13132 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
13135 /* Determine what tag to use for a record type. */
13137 static enum dwarf_tag
13138 record_type_tag (tree type
)
13140 if (! lang_hooks
.types
.classify_record
)
13141 return DW_TAG_structure_type
;
13143 switch (lang_hooks
.types
.classify_record (type
))
13145 case RECORD_IS_STRUCT
:
13146 return DW_TAG_structure_type
;
13148 case RECORD_IS_CLASS
:
13149 return DW_TAG_class_type
;
13151 case RECORD_IS_INTERFACE
:
13152 return DW_TAG_interface_type
;
13155 gcc_unreachable ();
13159 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13160 include all of the information about the enumeration values also. Each
13161 enumerated type name/value is listed as a child of the enumerated type
13165 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
13167 dw_die_ref type_die
= lookup_type_die (type
);
13169 if (type_die
== NULL
)
13171 type_die
= new_die (DW_TAG_enumeration_type
,
13172 scope_die_for (type
, context_die
), type
);
13173 equate_type_number_to_die (type
, type_die
);
13174 add_name_attribute (type_die
, type_tag (type
));
13176 else if (! TYPE_SIZE (type
))
13179 remove_AT (type_die
, DW_AT_declaration
);
13181 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13182 given enum type is incomplete, do not generate the DW_AT_byte_size
13183 attribute or the DW_AT_element_list attribute. */
13184 if (TYPE_SIZE (type
))
13188 TREE_ASM_WRITTEN (type
) = 1;
13189 add_byte_size_attribute (type_die
, type
);
13190 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
13191 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
13193 /* If the first reference to this type was as the return type of an
13194 inline function, then it may not have a parent. Fix this now. */
13195 if (type_die
->die_parent
== NULL
)
13196 add_child_die (scope_die_for (type
, context_die
), type_die
);
13198 for (link
= TYPE_VALUES (type
);
13199 link
!= NULL
; link
= TREE_CHAIN (link
))
13201 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
13202 tree value
= TREE_VALUE (link
);
13204 add_name_attribute (enum_die
,
13205 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
13207 if (TREE_CODE (value
) == CONST_DECL
)
13208 value
= DECL_INITIAL (value
);
13210 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
13211 /* DWARF2 does not provide a way of indicating whether or
13212 not enumeration constants are signed or unsigned. GDB
13213 always assumes the values are signed, so we output all
13214 values as if they were signed. That means that
13215 enumeration constants with very large unsigned values
13216 will appear to have negative values in the debugger. */
13217 add_AT_int (enum_die
, DW_AT_const_value
,
13218 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
13222 add_AT_flag (type_die
, DW_AT_declaration
, 1);
13224 if (get_AT (type_die
, DW_AT_name
))
13225 add_pubtype (type
, type_die
);
13230 /* Generate a DIE to represent either a real live formal parameter decl or to
13231 represent just the type of some formal parameter position in some function
13234 Note that this routine is a bit unusual because its argument may be a
13235 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13236 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13237 node. If it's the former then this function is being called to output a
13238 DIE to represent a formal parameter object (or some inlining thereof). If
13239 it's the latter, then this function is only being called to output a
13240 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13241 argument type of some subprogram type. */
13244 gen_formal_parameter_die (tree node
, tree origin
, dw_die_ref context_die
)
13246 tree node_or_origin
= node
? node
: origin
;
13247 dw_die_ref parm_die
13248 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
13250 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
13252 case tcc_declaration
:
13254 origin
= decl_ultimate_origin (node
);
13255 if (origin
!= NULL
)
13256 add_abstract_origin_attribute (parm_die
, origin
);
13259 tree type
= TREE_TYPE (node
);
13260 add_name_and_src_coords_attributes (parm_die
, node
);
13261 if (DECL_BY_REFERENCE (node
))
13262 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
13265 add_type_attribute (parm_die
, type
,
13266 TREE_READONLY (node
),
13267 TREE_THIS_VOLATILE (node
),
13269 if (DECL_ARTIFICIAL (node
))
13270 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13274 equate_decl_number_to_die (node
, parm_die
);
13275 if (! DECL_ABSTRACT (node_or_origin
))
13276 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
13282 /* We were called with some kind of a ..._TYPE node. */
13283 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
13287 gcc_unreachable ();
13293 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13294 at the end of an (ANSI prototyped) formal parameters list. */
13297 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
13299 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
13302 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13303 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13304 parameters as specified in some function type specification (except for
13305 those which appear as part of a function *definition*). */
13308 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
13311 tree formal_type
= NULL
;
13312 tree first_parm_type
;
13315 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
13317 arg
= DECL_ARGUMENTS (function_or_method_type
);
13318 function_or_method_type
= TREE_TYPE (function_or_method_type
);
13323 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
13325 /* Make our first pass over the list of formal parameter types and output a
13326 DW_TAG_formal_parameter DIE for each one. */
13327 for (link
= first_parm_type
; link
; )
13329 dw_die_ref parm_die
;
13331 formal_type
= TREE_VALUE (link
);
13332 if (formal_type
== void_type_node
)
13335 /* Output a (nameless) DIE to represent the formal parameter itself. */
13336 parm_die
= gen_formal_parameter_die (formal_type
, NULL
, context_die
);
13337 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
13338 && link
== first_parm_type
)
13339 || (arg
&& DECL_ARTIFICIAL (arg
)))
13340 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13342 link
= TREE_CHAIN (link
);
13344 arg
= TREE_CHAIN (arg
);
13347 /* If this function type has an ellipsis, add a
13348 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13349 if (formal_type
!= void_type_node
)
13350 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
13352 /* Make our second (and final) pass over the list of formal parameter types
13353 and output DIEs to represent those types (as necessary). */
13354 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
13355 link
&& TREE_VALUE (link
);
13356 link
= TREE_CHAIN (link
))
13357 gen_type_die (TREE_VALUE (link
), context_die
);
13360 /* We want to generate the DIE for TYPE so that we can generate the
13361 die for MEMBER, which has been defined; we will need to refer back
13362 to the member declaration nested within TYPE. If we're trying to
13363 generate minimal debug info for TYPE, processing TYPE won't do the
13364 trick; we need to attach the member declaration by hand. */
13367 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
13369 gen_type_die (type
, context_die
);
13371 /* If we're trying to avoid duplicate debug info, we may not have
13372 emitted the member decl for this function. Emit it now. */
13373 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
13374 && ! lookup_decl_die (member
))
13376 dw_die_ref type_die
;
13377 gcc_assert (!decl_ultimate_origin (member
));
13379 push_decl_scope (type
);
13380 type_die
= lookup_type_die (type
);
13381 if (TREE_CODE (member
) == FUNCTION_DECL
)
13382 gen_subprogram_die (member
, type_die
);
13383 else if (TREE_CODE (member
) == FIELD_DECL
)
13385 /* Ignore the nameless fields that are used to skip bits but handle
13386 C++ anonymous unions and structs. */
13387 if (DECL_NAME (member
) != NULL_TREE
13388 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
13389 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
13391 gen_type_die (member_declared_type (member
), type_die
);
13392 gen_field_die (member
, type_die
);
13396 gen_variable_die (member
, NULL_TREE
, type_die
);
13402 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13403 may later generate inlined and/or out-of-line instances of. */
13406 dwarf2out_abstract_function (tree decl
)
13408 dw_die_ref old_die
;
13411 int was_abstract
= DECL_ABSTRACT (decl
);
13413 /* Make sure we have the actual abstract inline, not a clone. */
13414 decl
= DECL_ORIGIN (decl
);
13416 old_die
= lookup_decl_die (decl
);
13417 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
13418 /* We've already generated the abstract instance. */
13421 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13422 we don't get confused by DECL_ABSTRACT. */
13423 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13425 context
= decl_class_context (decl
);
13427 gen_type_die_for_member
13428 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
13431 /* Pretend we've just finished compiling this function. */
13432 save_fn
= current_function_decl
;
13433 current_function_decl
= decl
;
13434 push_cfun (DECL_STRUCT_FUNCTION (decl
));
13436 set_decl_abstract_flags (decl
, 1);
13437 dwarf2out_decl (decl
);
13438 if (! was_abstract
)
13439 set_decl_abstract_flags (decl
, 0);
13441 current_function_decl
= save_fn
;
13445 /* Helper function of premark_used_types() which gets called through
13446 htab_traverse_resize().
13448 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13449 marked as unused by prune_unused_types. */
13451 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
13456 type
= (tree
) *slot
;
13457 die
= lookup_type_die (type
);
13459 die
->die_perennial_p
= 1;
13463 /* Mark all members of used_types_hash as perennial. */
13465 premark_used_types (void)
13467 if (cfun
&& cfun
->used_types_hash
)
13468 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
13471 /* Generate a DIE to represent a declared function (either file-scope or
13475 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
13477 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13478 tree origin
= decl_ultimate_origin (decl
);
13479 dw_die_ref subr_die
;
13482 dw_die_ref old_die
= lookup_decl_die (decl
);
13483 int declaration
= (current_function_decl
!= decl
13484 || class_or_namespace_scope_p (context_die
));
13486 premark_used_types ();
13488 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13489 started to generate the abstract instance of an inline, decided to output
13490 its containing class, and proceeded to emit the declaration of the inline
13491 from the member list for the class. If so, DECLARATION takes priority;
13492 we'll get back to the abstract instance when done with the class. */
13494 /* The class-scope declaration DIE must be the primary DIE. */
13495 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
13498 gcc_assert (!old_die
);
13501 /* Now that the C++ front end lazily declares artificial member fns, we
13502 might need to retrofit the declaration into its class. */
13503 if (!declaration
&& !origin
&& !old_die
13504 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
13505 && !class_or_namespace_scope_p (context_die
)
13506 && debug_info_level
> DINFO_LEVEL_TERSE
)
13507 old_die
= force_decl_die (decl
);
13509 if (origin
!= NULL
)
13511 gcc_assert (!declaration
|| local_scope_p (context_die
));
13513 /* Fixup die_parent for the abstract instance of a nested
13514 inline function. */
13515 if (old_die
&& old_die
->die_parent
== NULL
)
13516 add_child_die (context_die
, old_die
);
13518 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13519 add_abstract_origin_attribute (subr_die
, origin
);
13523 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
13524 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
13526 if (!get_AT_flag (old_die
, DW_AT_declaration
)
13527 /* We can have a normal definition following an inline one in the
13528 case of redefinition of GNU C extern inlines.
13529 It seems reasonable to use AT_specification in this case. */
13530 && !get_AT (old_die
, DW_AT_inline
))
13532 /* Detect and ignore this case, where we are trying to output
13533 something we have already output. */
13537 /* If the definition comes from the same place as the declaration,
13538 maybe use the old DIE. We always want the DIE for this function
13539 that has the *_pc attributes to be under comp_unit_die so the
13540 debugger can find it. We also need to do this for abstract
13541 instances of inlines, since the spec requires the out-of-line copy
13542 to have the same parent. For local class methods, this doesn't
13543 apply; we just use the old DIE. */
13544 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
13545 && (DECL_ARTIFICIAL (decl
)
13546 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
13547 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
13548 == (unsigned) s
.line
))))
13550 subr_die
= old_die
;
13552 /* Clear out the declaration attribute and the formal parameters.
13553 Do not remove all children, because it is possible that this
13554 declaration die was forced using force_decl_die(). In such
13555 cases die that forced declaration die (e.g. TAG_imported_module)
13556 is one of the children that we do not want to remove. */
13557 remove_AT (subr_die
, DW_AT_declaration
);
13558 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
13562 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13563 add_AT_specification (subr_die
, old_die
);
13564 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
13565 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
13566 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
13567 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
13572 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13574 if (TREE_PUBLIC (decl
))
13575 add_AT_flag (subr_die
, DW_AT_external
, 1);
13577 add_name_and_src_coords_attributes (subr_die
, decl
);
13578 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13580 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
13581 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
13582 0, 0, context_die
);
13585 add_pure_or_virtual_attribute (subr_die
, decl
);
13586 if (DECL_ARTIFICIAL (decl
))
13587 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
13589 if (TREE_PROTECTED (decl
))
13590 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13591 else if (TREE_PRIVATE (decl
))
13592 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
13597 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
13599 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
13601 /* If this is an explicit function declaration then generate
13602 a DW_AT_explicit attribute. */
13603 if (lang_hooks
.decls
.function_decl_explicit_p (decl
))
13604 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
13606 /* The first time we see a member function, it is in the context of
13607 the class to which it belongs. We make sure of this by emitting
13608 the class first. The next time is the definition, which is
13609 handled above. The two may come from the same source text.
13611 Note that force_decl_die() forces function declaration die. It is
13612 later reused to represent definition. */
13613 equate_decl_number_to_die (decl
, subr_die
);
13616 else if (DECL_ABSTRACT (decl
))
13618 if (DECL_DECLARED_INLINE_P (decl
))
13620 if (cgraph_function_possibly_inlined_p (decl
))
13621 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
13623 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
13627 if (cgraph_function_possibly_inlined_p (decl
))
13628 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
13630 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
13633 if (DECL_DECLARED_INLINE_P (decl
)
13634 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
13635 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
13637 equate_decl_number_to_die (decl
, subr_die
);
13639 else if (!DECL_EXTERNAL (decl
))
13641 HOST_WIDE_INT cfa_fb_offset
;
13643 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
13644 equate_decl_number_to_die (decl
, subr_die
);
13646 if (!flag_reorder_blocks_and_partition
)
13648 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
13649 current_function_funcdef_no
);
13650 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
13651 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13652 current_function_funcdef_no
);
13653 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
13655 add_pubname (decl
, subr_die
);
13656 add_arange (decl
, subr_die
);
13659 { /* Do nothing for now; maybe need to duplicate die, one for
13660 hot section and one for cold section, then use the hot/cold
13661 section begin/end labels to generate the aranges... */
13663 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13664 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13665 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13666 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13668 add_pubname (decl, subr_die);
13669 add_arange (decl, subr_die);
13670 add_arange (decl, subr_die);
13674 #ifdef MIPS_DEBUGGING_INFO
13675 /* Add a reference to the FDE for this routine. */
13676 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
13679 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
13681 /* We define the "frame base" as the function's CFA. This is more
13682 convenient for several reasons: (1) It's stable across the prologue
13683 and epilogue, which makes it better than just a frame pointer,
13684 (2) With dwarf3, there exists a one-byte encoding that allows us
13685 to reference the .debug_frame data by proxy, but failing that,
13686 (3) We can at least reuse the code inspection and interpretation
13687 code that determines the CFA position at various points in the
13689 /* ??? Use some command-line or configury switch to enable the use
13690 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13691 consumers that understand it; fall back to "pure" dwarf2 and
13692 convert the CFA data into a location list. */
13694 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
13695 if (list
->dw_loc_next
)
13696 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
13698 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
13701 /* Compute a displacement from the "steady-state frame pointer" to
13702 the CFA. The former is what all stack slots and argument slots
13703 will reference in the rtl; the later is what we've told the
13704 debugger about. We'll need to adjust all frame_base references
13705 by this displacement. */
13706 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
13708 if (cfun
->static_chain_decl
)
13709 add_AT_location_description (subr_die
, DW_AT_static_link
,
13710 loc_descriptor_from_tree (cfun
->static_chain_decl
));
13713 /* Now output descriptions of the arguments for this function. This gets
13714 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13715 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13716 `...' at the end of the formal parameter list. In order to find out if
13717 there was a trailing ellipsis or not, we must instead look at the type
13718 associated with the FUNCTION_DECL. This will be a node of type
13719 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13720 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13721 an ellipsis at the end. */
13723 /* In the case where we are describing a mere function declaration, all we
13724 need to do here (and all we *can* do here) is to describe the *types* of
13725 its formal parameters. */
13726 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13728 else if (declaration
)
13729 gen_formal_types_die (decl
, subr_die
);
13732 /* Generate DIEs to represent all known formal parameters. */
13733 tree arg_decls
= DECL_ARGUMENTS (decl
);
13736 /* When generating DIEs, generate the unspecified_parameters DIE
13737 instead if we come across the arg "__builtin_va_alist" */
13738 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
13739 if (TREE_CODE (parm
) == PARM_DECL
)
13741 if (DECL_NAME (parm
)
13742 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
13743 "__builtin_va_alist"))
13744 gen_unspecified_parameters_die (parm
, subr_die
);
13746 gen_decl_die (parm
, NULL
, subr_die
);
13749 /* Decide whether we need an unspecified_parameters DIE at the end.
13750 There are 2 more cases to do this for: 1) the ansi ... declaration -
13751 this is detectable when the end of the arg list is not a
13752 void_type_node 2) an unprototyped function declaration (not a
13753 definition). This just means that we have no info about the
13754 parameters at all. */
13755 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
13756 if (fn_arg_types
!= NULL
)
13758 /* This is the prototyped case, check for.... */
13759 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
13760 gen_unspecified_parameters_die (decl
, subr_die
);
13762 else if (DECL_INITIAL (decl
) == NULL_TREE
)
13763 gen_unspecified_parameters_die (decl
, subr_die
);
13766 /* Output Dwarf info for all of the stuff within the body of the function
13767 (if it has one - it may be just a declaration). */
13768 outer_scope
= DECL_INITIAL (decl
);
13770 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13771 a function. This BLOCK actually represents the outermost binding contour
13772 for the function, i.e. the contour in which the function's formal
13773 parameters and labels get declared. Curiously, it appears that the front
13774 end doesn't actually put the PARM_DECL nodes for the current function onto
13775 the BLOCK_VARS list for this outer scope, but are strung off of the
13776 DECL_ARGUMENTS list for the function instead.
13778 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13779 the LABEL_DECL nodes for the function however, and we output DWARF info
13780 for those in decls_for_scope. Just within the `outer_scope' there will be
13781 a BLOCK node representing the function's outermost pair of curly braces,
13782 and any blocks used for the base and member initializers of a C++
13783 constructor function. */
13784 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
13786 /* Emit a DW_TAG_variable DIE for a named return value. */
13787 if (DECL_NAME (DECL_RESULT (decl
)))
13788 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
13790 current_function_has_inlines
= 0;
13791 decls_for_scope (outer_scope
, subr_die
, 0);
13793 #if 0 && defined (MIPS_DEBUGGING_INFO)
13794 if (current_function_has_inlines
)
13796 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
13797 if (! comp_unit_has_inlines
)
13799 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
13800 comp_unit_has_inlines
= 1;
13805 /* Add the calling convention attribute if requested. */
13806 add_calling_convention_attribute (subr_die
, decl
);
13810 /* Returns a hash value for X (which really is a die_struct). */
13813 common_block_die_table_hash (const void *x
)
13815 const_dw_die_ref d
= (const_dw_die_ref
) x
;
13816 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
13819 /* Return nonzero if decl_id and die_parent of die_struct X is the same
13820 as decl_id and die_parent of die_struct Y. */
13823 common_block_die_table_eq (const void *x
, const void *y
)
13825 const_dw_die_ref d
= (const_dw_die_ref
) x
;
13826 const_dw_die_ref e
= (const_dw_die_ref
) y
;
13827 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
13830 /* Generate a DIE to represent a declared data object.
13831 Either DECL or ORIGIN must be non-null. */
13834 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
13838 tree decl_or_origin
= decl
? decl
: origin
;
13839 dw_die_ref var_die
;
13840 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
13841 dw_die_ref origin_die
;
13842 int declaration
= (DECL_EXTERNAL (decl_or_origin
)
13843 /* If DECL is COMDAT and has not actually been
13844 emitted, we cannot take its address; there
13845 might end up being no definition anywhere in
13846 the program. For example, consider the C++
13850 struct S { static const int i = 7; };
13855 int f() { return S<int>::i; }
13857 Here, S<int>::i is not DECL_EXTERNAL, but no
13858 definition is required, so the compiler will
13859 not emit a definition. */
13860 || (TREE_CODE (decl_or_origin
) == VAR_DECL
13861 && DECL_COMDAT (decl_or_origin
)
13862 && !TREE_ASM_WRITTEN (decl_or_origin
))
13863 || class_or_namespace_scope_p (context_die
));
13866 origin
= decl_ultimate_origin (decl
);
13868 com_decl
= fortran_common (decl_or_origin
, &off
);
13870 /* Symbol in common gets emitted as a child of the common block, in the form
13871 of a data member. */
13875 dw_die_ref com_die
;
13876 dw_loc_descr_ref loc
;
13877 die_node com_die_arg
;
13879 var_die
= lookup_decl_die (decl_or_origin
);
13882 if (get_AT (var_die
, DW_AT_location
) == NULL
)
13884 loc
= loc_descriptor_from_tree (com_decl
);
13889 /* Optimize the common case. */
13890 if (loc
->dw_loc_opc
== DW_OP_addr
13891 && loc
->dw_loc_next
== NULL
13892 && GET_CODE (loc
->dw_loc_oprnd1
.v
.val_addr
)
13894 loc
->dw_loc_oprnd1
.v
.val_addr
13895 = plus_constant (loc
->dw_loc_oprnd1
.v
.val_addr
, off
);
13897 loc_descr_plus_const (&loc
, off
);
13899 add_AT_loc (var_die
, DW_AT_location
, loc
);
13900 remove_AT (var_die
, DW_AT_declaration
);
13906 if (common_block_die_table
== NULL
)
13907 common_block_die_table
13908 = htab_create_ggc (10, common_block_die_table_hash
,
13909 common_block_die_table_eq
, NULL
);
13911 field
= TREE_OPERAND (DECL_VALUE_EXPR (decl
), 0);
13912 com_die_arg
.decl_id
= DECL_UID (com_decl
);
13913 com_die_arg
.die_parent
= context_die
;
13914 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
13915 loc
= loc_descriptor_from_tree (com_decl
);
13916 if (com_die
== NULL
)
13919 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
13922 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
13923 add_name_and_src_coords_attributes (com_die
, com_decl
);
13926 add_AT_loc (com_die
, DW_AT_location
, loc
);
13927 /* Avoid sharing the same loc descriptor between
13928 DW_TAG_common_block and DW_TAG_variable. */
13929 loc
= loc_descriptor_from_tree (com_decl
);
13931 else if (DECL_EXTERNAL (decl
))
13932 add_AT_flag (com_die
, DW_AT_declaration
, 1);
13933 add_pubname_string (cnam
, com_die
); /* ??? needed? */
13934 com_die
->decl_id
= DECL_UID (com_decl
);
13935 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
13936 *slot
= (void *) com_die
;
13938 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
13940 add_AT_loc (com_die
, DW_AT_location
, loc
);
13941 loc
= loc_descriptor_from_tree (com_decl
);
13942 remove_AT (com_die
, DW_AT_declaration
);
13944 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
13945 add_name_and_src_coords_attributes (var_die
, decl
);
13946 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
13947 TREE_THIS_VOLATILE (decl
), context_die
);
13948 add_AT_flag (var_die
, DW_AT_external
, 1);
13953 /* Optimize the common case. */
13954 if (loc
->dw_loc_opc
== DW_OP_addr
13955 && loc
->dw_loc_next
== NULL
13956 && GET_CODE (loc
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
13957 loc
->dw_loc_oprnd1
.v
.val_addr
13958 = plus_constant (loc
->dw_loc_oprnd1
.v
.val_addr
, off
);
13960 loc_descr_plus_const (&loc
, off
);
13962 add_AT_loc (var_die
, DW_AT_location
, loc
);
13964 else if (DECL_EXTERNAL (decl
))
13965 add_AT_flag (var_die
, DW_AT_declaration
, 1);
13966 equate_decl_number_to_die (decl
, var_die
);
13970 /* If the compiler emitted a definition for the DECL declaration
13971 and if we already emitted a DIE for it, don't emit a second
13972 DIE for it again. */
13975 && old_die
->die_parent
== context_die
)
13978 /* For static data members, the declaration in the class is supposed
13979 to have DW_TAG_member tag; the specification should still be
13980 DW_TAG_variable referencing the DW_TAG_member DIE. */
13981 if (declaration
&& class_scope_p (context_die
))
13982 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
13984 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
13987 if (origin
!= NULL
)
13988 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
13990 /* Loop unrolling can create multiple blocks that refer to the same
13991 static variable, so we must test for the DW_AT_declaration flag.
13993 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13994 copy decls and set the DECL_ABSTRACT flag on them instead of
13997 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13999 ??? The declare_in_namespace support causes us to get two DIEs for one
14000 variable, both of which are declarations. We want to avoid considering
14001 one to be a specification, so we must test that this DIE is not a
14003 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
14004 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
14006 /* This is a definition of a C++ class level static. */
14007 add_AT_specification (var_die
, old_die
);
14008 if (DECL_NAME (decl
))
14010 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
14011 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
14013 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
14014 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
14016 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
14017 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
14022 tree type
= TREE_TYPE (decl
);
14024 add_name_and_src_coords_attributes (var_die
, decl
);
14025 if ((TREE_CODE (decl
) == PARM_DECL
14026 || TREE_CODE (decl
) == RESULT_DECL
14027 || TREE_CODE (decl
) == VAR_DECL
)
14028 && DECL_BY_REFERENCE (decl
))
14029 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
14031 add_type_attribute (var_die
, type
, TREE_READONLY (decl
),
14032 TREE_THIS_VOLATILE (decl
), context_die
);
14034 if (TREE_PUBLIC (decl
))
14035 add_AT_flag (var_die
, DW_AT_external
, 1);
14037 if (DECL_ARTIFICIAL (decl
))
14038 add_AT_flag (var_die
, DW_AT_artificial
, 1);
14040 if (TREE_PROTECTED (decl
))
14041 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14042 else if (TREE_PRIVATE (decl
))
14043 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14047 add_AT_flag (var_die
, DW_AT_declaration
, 1);
14049 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
))
14050 equate_decl_number_to_die (decl
, var_die
);
14053 && (! DECL_ABSTRACT (decl_or_origin
)
14054 /* Local static vars are shared between all clones/inlines,
14055 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14057 || (TREE_CODE (decl_or_origin
) == VAR_DECL
14058 && TREE_STATIC (decl_or_origin
)
14059 && DECL_RTL_SET_P (decl_or_origin
)))
14060 /* When abstract origin already has DW_AT_location attribute, no need
14061 to add it again. */
14062 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
14064 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
14065 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
14066 defer_location (decl_or_origin
, var_die
);
14068 add_location_or_const_value_attribute (var_die
,
14071 add_pubname (decl_or_origin
, var_die
);
14074 tree_add_const_value_attribute (var_die
, decl_or_origin
);
14077 /* Generate a DIE to represent a named constant. */
14080 gen_const_die (tree decl
, dw_die_ref context_die
)
14082 dw_die_ref const_die
;
14083 tree type
= TREE_TYPE (decl
);
14085 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
14086 add_name_and_src_coords_attributes (const_die
, decl
);
14087 add_type_attribute (const_die
, type
, 1, 0, context_die
);
14088 if (TREE_PUBLIC (decl
))
14089 add_AT_flag (const_die
, DW_AT_external
, 1);
14090 if (DECL_ARTIFICIAL (decl
))
14091 add_AT_flag (const_die
, DW_AT_artificial
, 1);
14092 tree_add_const_value_attribute (const_die
, decl
);
14095 /* Generate a DIE to represent a label identifier. */
14098 gen_label_die (tree decl
, dw_die_ref context_die
)
14100 tree origin
= decl_ultimate_origin (decl
);
14101 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
14103 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14105 if (origin
!= NULL
)
14106 add_abstract_origin_attribute (lbl_die
, origin
);
14108 add_name_and_src_coords_attributes (lbl_die
, decl
);
14110 if (DECL_ABSTRACT (decl
))
14111 equate_decl_number_to_die (decl
, lbl_die
);
14114 insn
= DECL_RTL_IF_SET (decl
);
14116 /* Deleted labels are programmer specified labels which have been
14117 eliminated because of various optimizations. We still emit them
14118 here so that it is possible to put breakpoints on them. */
14122 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
14124 /* When optimization is enabled (via -O) some parts of the compiler
14125 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14126 represent source-level labels which were explicitly declared by
14127 the user. This really shouldn't be happening though, so catch
14128 it if it ever does happen. */
14129 gcc_assert (!INSN_DELETED_P (insn
));
14131 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
14132 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
14137 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14138 attributes to the DIE for a block STMT, to describe where the inlined
14139 function was called from. This is similar to add_src_coords_attributes. */
14142 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
14144 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
14146 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
14147 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
14151 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14152 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14155 add_high_low_attributes (tree stmt
, dw_die_ref die
)
14157 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14159 if (BLOCK_FRAGMENT_CHAIN (stmt
))
14163 if (inlined_function_outer_scope_p (stmt
))
14165 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14166 BLOCK_NUMBER (stmt
));
14167 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
14170 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
14172 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
14175 add_ranges (chain
);
14176 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
14183 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14184 BLOCK_NUMBER (stmt
));
14185 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
14186 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
14187 BLOCK_NUMBER (stmt
));
14188 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
14192 /* Generate a DIE for a lexical block. */
14195 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14197 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
14199 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
14200 add_high_low_attributes (stmt
, stmt_die
);
14202 decls_for_scope (stmt
, stmt_die
, depth
);
14205 /* Generate a DIE for an inlined subprogram. */
14208 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
14210 tree decl
= block_ultimate_origin (stmt
);
14212 /* Emit info for the abstract instance first, if we haven't yet. We
14213 must emit this even if the block is abstract, otherwise when we
14214 emit the block below (or elsewhere), we may end up trying to emit
14215 a die whose origin die hasn't been emitted, and crashing. */
14216 dwarf2out_abstract_function (decl
);
14218 if (! BLOCK_ABSTRACT (stmt
))
14220 dw_die_ref subr_die
14221 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
14223 add_abstract_origin_attribute (subr_die
, decl
);
14224 if (TREE_ASM_WRITTEN (stmt
))
14225 add_high_low_attributes (stmt
, subr_die
);
14226 add_call_src_coords_attributes (stmt
, subr_die
);
14228 decls_for_scope (stmt
, subr_die
, depth
);
14229 current_function_has_inlines
= 1;
14232 /* We may get here if we're the outer block of function A that was
14233 inlined into function B that was inlined into function C. When
14234 generating debugging info for C, dwarf2out_abstract_function(B)
14235 would mark all inlined blocks as abstract, including this one.
14236 So, we wouldn't (and shouldn't) expect labels to be generated
14237 for this one. Instead, just emit debugging info for
14238 declarations within the block. This is particularly important
14239 in the case of initializers of arguments passed from B to us:
14240 if they're statement expressions containing declarations, we
14241 wouldn't generate dies for their abstract variables, and then,
14242 when generating dies for the real variables, we'd die (pun
14244 gen_lexical_block_die (stmt
, context_die
, depth
);
14247 /* Generate a DIE for a field in a record, or structure. */
14250 gen_field_die (tree decl
, dw_die_ref context_die
)
14252 dw_die_ref decl_die
;
14254 if (TREE_TYPE (decl
) == error_mark_node
)
14257 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
14258 add_name_and_src_coords_attributes (decl_die
, decl
);
14259 add_type_attribute (decl_die
, member_declared_type (decl
),
14260 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
14263 if (DECL_BIT_FIELD_TYPE (decl
))
14265 add_byte_size_attribute (decl_die
, decl
);
14266 add_bit_size_attribute (decl_die
, decl
);
14267 add_bit_offset_attribute (decl_die
, decl
);
14270 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
14271 add_data_member_location_attribute (decl_die
, decl
);
14273 if (DECL_ARTIFICIAL (decl
))
14274 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
14276 if (TREE_PROTECTED (decl
))
14277 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14278 else if (TREE_PRIVATE (decl
))
14279 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14281 /* Equate decl number to die, so that we can look up this decl later on. */
14282 equate_decl_number_to_die (decl
, decl_die
);
14286 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14287 Use modified_type_die instead.
14288 We keep this code here just in case these types of DIEs may be needed to
14289 represent certain things in other languages (e.g. Pascal) someday. */
14292 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
14295 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
14297 equate_type_number_to_die (type
, ptr_die
);
14298 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14299 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14302 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14303 Use modified_type_die instead.
14304 We keep this code here just in case these types of DIEs may be needed to
14305 represent certain things in other languages (e.g. Pascal) someday. */
14308 gen_reference_type_die (tree type
, dw_die_ref context_die
)
14311 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
14313 equate_type_number_to_die (type
, ref_die
);
14314 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
14315 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14319 /* Generate a DIE for a pointer to a member type. */
14322 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
14325 = new_die (DW_TAG_ptr_to_member_type
,
14326 scope_die_for (type
, context_die
), type
);
14328 equate_type_number_to_die (type
, ptr_die
);
14329 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
14330 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
14331 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14334 /* Generate the DIE for the compilation unit. */
14337 gen_compile_unit_die (const char *filename
)
14340 char producer
[250];
14341 const char *language_string
= lang_hooks
.name
;
14344 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
14348 add_name_attribute (die
, filename
);
14349 /* Don't add cwd for <built-in>. */
14350 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
14351 add_comp_dir_attribute (die
);
14354 sprintf (producer
, "%s %s", language_string
, version_string
);
14356 #ifdef MIPS_DEBUGGING_INFO
14357 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14358 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14359 not appear in the producer string, the debugger reaches the conclusion
14360 that the object file is stripped and has no debugging information.
14361 To get the MIPS/SGI debugger to believe that there is debugging
14362 information in the object file, we add a -g to the producer string. */
14363 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14364 strcat (producer
, " -g");
14367 add_AT_string (die
, DW_AT_producer
, producer
);
14369 if (strcmp (language_string
, "GNU C++") == 0)
14370 language
= DW_LANG_C_plus_plus
;
14371 else if (strcmp (language_string
, "GNU Ada") == 0)
14372 language
= DW_LANG_Ada95
;
14373 else if (strcmp (language_string
, "GNU F77") == 0)
14374 language
= DW_LANG_Fortran77
;
14375 else if (strcmp (language_string
, "GNU Fortran") == 0)
14376 language
= DW_LANG_Fortran95
;
14377 else if (strcmp (language_string
, "GNU Pascal") == 0)
14378 language
= DW_LANG_Pascal83
;
14379 else if (strcmp (language_string
, "GNU Java") == 0)
14380 language
= DW_LANG_Java
;
14381 else if (strcmp (language_string
, "GNU Objective-C") == 0)
14382 language
= DW_LANG_ObjC
;
14383 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
14384 language
= DW_LANG_ObjC_plus_plus
;
14386 language
= DW_LANG_C89
;
14388 add_AT_unsigned (die
, DW_AT_language
, language
);
14392 /* Generate the DIE for a base class. */
14395 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
14397 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
14399 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
14400 add_data_member_location_attribute (die
, binfo
);
14402 if (BINFO_VIRTUAL_P (binfo
))
14403 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
14405 if (access
== access_public_node
)
14406 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14407 else if (access
== access_protected_node
)
14408 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14411 /* Generate a DIE for a class member. */
14414 gen_member_die (tree type
, dw_die_ref context_die
)
14417 tree binfo
= TYPE_BINFO (type
);
14420 /* If this is not an incomplete type, output descriptions of each of its
14421 members. Note that as we output the DIEs necessary to represent the
14422 members of this record or union type, we will also be trying to output
14423 DIEs to represent the *types* of those members. However the `type'
14424 function (above) will specifically avoid generating type DIEs for member
14425 types *within* the list of member DIEs for this (containing) type except
14426 for those types (of members) which are explicitly marked as also being
14427 members of this (containing) type themselves. The g++ front- end can
14428 force any given type to be treated as a member of some other (containing)
14429 type by setting the TYPE_CONTEXT of the given (member) type to point to
14430 the TREE node representing the appropriate (containing) type. */
14432 /* First output info about the base classes. */
14435 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
14439 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
14440 gen_inheritance_die (base
,
14441 (accesses
? VEC_index (tree
, accesses
, i
)
14442 : access_public_node
), context_die
);
14445 /* Now output info about the data members and type members. */
14446 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
14448 /* If we thought we were generating minimal debug info for TYPE
14449 and then changed our minds, some of the member declarations
14450 may have already been defined. Don't define them again, but
14451 do put them in the right order. */
14453 child
= lookup_decl_die (member
);
14455 splice_child_die (context_die
, child
);
14457 gen_decl_die (member
, NULL
, context_die
);
14460 /* Now output info about the function members (if any). */
14461 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
14463 /* Don't include clones in the member list. */
14464 if (DECL_ABSTRACT_ORIGIN (member
))
14467 child
= lookup_decl_die (member
);
14469 splice_child_die (context_die
, child
);
14471 gen_decl_die (member
, NULL
, context_die
);
14475 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14476 is set, we pretend that the type was never defined, so we only get the
14477 member DIEs needed by later specification DIEs. */
14480 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
14481 enum debug_info_usage usage
)
14483 dw_die_ref type_die
= lookup_type_die (type
);
14484 dw_die_ref scope_die
= 0;
14486 int complete
= (TYPE_SIZE (type
)
14487 && (! TYPE_STUB_DECL (type
)
14488 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
14489 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
14490 complete
= complete
&& should_emit_struct_debug (type
, usage
);
14492 if (type_die
&& ! complete
)
14495 if (TYPE_CONTEXT (type
) != NULL_TREE
14496 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
14497 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
14500 scope_die
= scope_die_for (type
, context_die
);
14502 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
14503 /* First occurrence of type or toplevel definition of nested class. */
14505 dw_die_ref old_die
= type_die
;
14507 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
14508 ? record_type_tag (type
) : DW_TAG_union_type
,
14510 equate_type_number_to_die (type
, type_die
);
14512 add_AT_specification (type_die
, old_die
);
14514 add_name_attribute (type_die
, type_tag (type
));
14517 remove_AT (type_die
, DW_AT_declaration
);
14519 /* If this type has been completed, then give it a byte_size attribute and
14520 then give a list of members. */
14521 if (complete
&& !ns_decl
)
14523 /* Prevent infinite recursion in cases where the type of some member of
14524 this type is expressed in terms of this type itself. */
14525 TREE_ASM_WRITTEN (type
) = 1;
14526 add_byte_size_attribute (type_die
, type
);
14527 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
14528 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
14530 /* If the first reference to this type was as the return type of an
14531 inline function, then it may not have a parent. Fix this now. */
14532 if (type_die
->die_parent
== NULL
)
14533 add_child_die (scope_die
, type_die
);
14535 push_decl_scope (type
);
14536 gen_member_die (type
, type_die
);
14539 /* GNU extension: Record what type our vtable lives in. */
14540 if (TYPE_VFIELD (type
))
14542 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
14544 gen_type_die (vtype
, context_die
);
14545 add_AT_die_ref (type_die
, DW_AT_containing_type
,
14546 lookup_type_die (vtype
));
14551 add_AT_flag (type_die
, DW_AT_declaration
, 1);
14553 /* We don't need to do this for function-local types. */
14554 if (TYPE_STUB_DECL (type
)
14555 && ! decl_function_context (TYPE_STUB_DECL (type
)))
14556 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
14559 if (get_AT (type_die
, DW_AT_name
))
14560 add_pubtype (type
, type_die
);
14563 /* Generate a DIE for a subroutine _type_. */
14566 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
14568 tree return_type
= TREE_TYPE (type
);
14569 dw_die_ref subr_die
14570 = new_die (DW_TAG_subroutine_type
,
14571 scope_die_for (type
, context_die
), type
);
14573 equate_type_number_to_die (type
, subr_die
);
14574 add_prototyped_attribute (subr_die
, type
);
14575 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
14576 gen_formal_types_die (type
, subr_die
);
14578 if (get_AT (subr_die
, DW_AT_name
))
14579 add_pubtype (type
, subr_die
);
14582 /* Generate a DIE for a type definition. */
14585 gen_typedef_die (tree decl
, dw_die_ref context_die
)
14587 dw_die_ref type_die
;
14590 if (TREE_ASM_WRITTEN (decl
))
14593 TREE_ASM_WRITTEN (decl
) = 1;
14594 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
14595 origin
= decl_ultimate_origin (decl
);
14596 if (origin
!= NULL
)
14597 add_abstract_origin_attribute (type_die
, origin
);
14602 add_name_and_src_coords_attributes (type_die
, decl
);
14603 if (DECL_ORIGINAL_TYPE (decl
))
14605 type
= DECL_ORIGINAL_TYPE (decl
);
14607 gcc_assert (type
!= TREE_TYPE (decl
));
14608 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
14611 type
= TREE_TYPE (decl
);
14613 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
14614 TREE_THIS_VOLATILE (decl
), context_die
);
14617 if (DECL_ABSTRACT (decl
))
14618 equate_decl_number_to_die (decl
, type_die
);
14620 if (get_AT (type_die
, DW_AT_name
))
14621 add_pubtype (decl
, type_die
);
14624 /* Generate a type description DIE. */
14627 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
14628 enum debug_info_usage usage
)
14631 struct array_descr_info info
;
14633 if (type
== NULL_TREE
|| type
== error_mark_node
)
14636 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
14637 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
14639 if (TREE_ASM_WRITTEN (type
))
14642 /* Prevent broken recursion; we can't hand off to the same type. */
14643 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
14645 /* Use the DIE of the containing namespace as the parent DIE of
14646 the type description DIE we want to generate. */
14647 if (DECL_CONTEXT (TYPE_NAME (type
))
14648 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
14649 context_die
= lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type
)));
14651 TREE_ASM_WRITTEN (type
) = 1;
14652 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
14656 /* If this is an array type with hidden descriptor, handle it first. */
14657 if (!TREE_ASM_WRITTEN (type
)
14658 && lang_hooks
.types
.get_array_descr_info
14659 && lang_hooks
.types
.get_array_descr_info (type
, &info
))
14661 gen_descr_array_type_die (type
, &info
, context_die
);
14662 TREE_ASM_WRITTEN (type
) = 1;
14666 /* We are going to output a DIE to represent the unqualified version
14667 of this type (i.e. without any const or volatile qualifiers) so
14668 get the main variant (i.e. the unqualified version) of this type
14669 now. (Vectors are special because the debugging info is in the
14670 cloned type itself). */
14671 if (TREE_CODE (type
) != VECTOR_TYPE
)
14672 type
= type_main_variant (type
);
14674 if (TREE_ASM_WRITTEN (type
))
14677 switch (TREE_CODE (type
))
14683 case REFERENCE_TYPE
:
14684 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14685 ensures that the gen_type_die recursion will terminate even if the
14686 type is recursive. Recursive types are possible in Ada. */
14687 /* ??? We could perhaps do this for all types before the switch
14689 TREE_ASM_WRITTEN (type
) = 1;
14691 /* For these types, all that is required is that we output a DIE (or a
14692 set of DIEs) to represent the "basis" type. */
14693 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14694 DINFO_USAGE_IND_USE
);
14698 /* This code is used for C++ pointer-to-data-member types.
14699 Output a description of the relevant class type. */
14700 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
14701 DINFO_USAGE_IND_USE
);
14703 /* Output a description of the type of the object pointed to. */
14704 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14705 DINFO_USAGE_IND_USE
);
14707 /* Now output a DIE to represent this pointer-to-data-member type
14709 gen_ptr_to_mbr_type_die (type
, context_die
);
14712 case FUNCTION_TYPE
:
14713 /* Force out return type (in case it wasn't forced out already). */
14714 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14715 DINFO_USAGE_DIR_USE
);
14716 gen_subroutine_type_die (type
, context_die
);
14720 /* Force out return type (in case it wasn't forced out already). */
14721 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
14722 DINFO_USAGE_DIR_USE
);
14723 gen_subroutine_type_die (type
, context_die
);
14727 gen_array_type_die (type
, context_die
);
14731 gen_array_type_die (type
, context_die
);
14734 case ENUMERAL_TYPE
:
14737 case QUAL_UNION_TYPE
:
14738 /* If this is a nested type whose containing class hasn't been written
14739 out yet, writing it out will cover this one, too. This does not apply
14740 to instantiations of member class templates; they need to be added to
14741 the containing class as they are generated. FIXME: This hurts the
14742 idea of combining type decls from multiple TUs, since we can't predict
14743 what set of template instantiations we'll get. */
14744 if (TYPE_CONTEXT (type
)
14745 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
14746 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
14748 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
14750 if (TREE_ASM_WRITTEN (type
))
14753 /* If that failed, attach ourselves to the stub. */
14754 push_decl_scope (TYPE_CONTEXT (type
));
14755 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
14760 context_die
= declare_in_namespace (type
, context_die
);
14764 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
14766 /* This might have been written out by the call to
14767 declare_in_namespace. */
14768 if (!TREE_ASM_WRITTEN (type
))
14769 gen_enumeration_type_die (type
, context_die
);
14772 gen_struct_or_union_type_die (type
, context_die
, usage
);
14777 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14778 it up if it is ever completed. gen_*_type_die will set it for us
14779 when appropriate. */
14785 case FIXED_POINT_TYPE
:
14788 /* No DIEs needed for fundamental types. */
14792 /* No Dwarf representation currently defined. */
14796 gcc_unreachable ();
14799 TREE_ASM_WRITTEN (type
) = 1;
14803 gen_type_die (tree type
, dw_die_ref context_die
)
14805 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
14808 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14809 things which are local to the given block. */
14812 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14814 int must_output_die
= 0;
14817 /* Ignore blocks that are NULL. */
14818 if (stmt
== NULL_TREE
)
14821 inlined_func
= inlined_function_outer_scope_p (stmt
);
14823 /* If the block is one fragment of a non-contiguous block, do not
14824 process the variables, since they will have been done by the
14825 origin block. Do process subblocks. */
14826 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
14830 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
14831 gen_block_die (sub
, context_die
, depth
+ 1);
14836 /* Determine if we need to output any Dwarf DIEs at all to represent this
14839 /* The outer scopes for inlinings *must* always be represented. We
14840 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14841 must_output_die
= 1;
14844 /* Determine if this block directly contains any "significant"
14845 local declarations which we will need to output DIEs for. */
14846 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14847 /* We are not in terse mode so *any* local declaration counts
14848 as being a "significant" one. */
14849 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
14850 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
14851 && (TREE_USED (stmt
)
14852 || TREE_ASM_WRITTEN (stmt
)
14853 || BLOCK_ABSTRACT (stmt
)));
14854 else if ((TREE_USED (stmt
)
14855 || TREE_ASM_WRITTEN (stmt
)
14856 || BLOCK_ABSTRACT (stmt
))
14857 && !dwarf2out_ignore_block (stmt
))
14858 must_output_die
= 1;
14861 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14862 DIE for any block which contains no significant local declarations at
14863 all. Rather, in such cases we just call `decls_for_scope' so that any
14864 needed Dwarf info for any sub-blocks will get properly generated. Note
14865 that in terse mode, our definition of what constitutes a "significant"
14866 local declaration gets restricted to include only inlined function
14867 instances and local (nested) function definitions. */
14868 if (must_output_die
)
14871 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
14873 gen_lexical_block_die (stmt
, context_die
, depth
);
14876 decls_for_scope (stmt
, context_die
, depth
);
14879 /* Process variable DECL (or variable with origin ORIGIN) within
14880 block STMT and add it to CONTEXT_DIE. */
14882 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
14885 tree decl_or_origin
= decl
? decl
: origin
;
14886 tree ultimate_origin
= origin
? decl_ultimate_origin (origin
) : NULL
;
14888 if (ultimate_origin
)
14889 origin
= ultimate_origin
;
14891 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
14892 die
= lookup_decl_die (decl_or_origin
);
14893 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
14894 && TYPE_DECL_IS_STUB (decl_or_origin
))
14895 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
14899 if (die
!= NULL
&& die
->die_parent
== NULL
)
14900 add_child_die (context_die
, die
);
14901 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
14902 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
14903 stmt
, context_die
);
14905 gen_decl_die (decl
, origin
, context_die
);
14908 /* Generate all of the decls declared within a given scope and (recursively)
14909 all of its sub-blocks. */
14912 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
14918 /* Ignore NULL blocks. */
14919 if (stmt
== NULL_TREE
)
14922 /* Output the DIEs to represent all of the data objects and typedefs
14923 declared directly within this block but not within any nested
14924 sub-blocks. Also, nested function and tag DIEs have been
14925 generated with a parent of NULL; fix that up now. */
14926 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
14927 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
14928 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
14929 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
14932 /* If we're at -g1, we're not interested in subblocks. */
14933 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14936 /* Output the DIEs to represent all sub-blocks (and the items declared
14937 therein) of this block. */
14938 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
14940 subblocks
= BLOCK_CHAIN (subblocks
))
14941 gen_block_die (subblocks
, context_die
, depth
+ 1);
14944 /* Is this a typedef we can avoid emitting? */
14947 is_redundant_typedef (const_tree decl
)
14949 if (TYPE_DECL_IS_STUB (decl
))
14952 if (DECL_ARTIFICIAL (decl
)
14953 && DECL_CONTEXT (decl
)
14954 && is_tagged_type (DECL_CONTEXT (decl
))
14955 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
14956 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
14957 /* Also ignore the artificial member typedef for the class name. */
14963 /* Returns the DIE for a context. */
14965 static inline dw_die_ref
14966 get_context_die (tree context
)
14970 /* Find die that represents this context. */
14971 if (TYPE_P (context
))
14972 return force_type_die (context
);
14974 return force_decl_die (context
);
14976 return comp_unit_die
;
14979 /* Returns the DIE for decl. A DIE will always be returned. */
14982 force_decl_die (tree decl
)
14984 dw_die_ref decl_die
;
14985 unsigned saved_external_flag
;
14986 tree save_fn
= NULL_TREE
;
14987 decl_die
= lookup_decl_die (decl
);
14990 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
14992 decl_die
= lookup_decl_die (decl
);
14996 switch (TREE_CODE (decl
))
14998 case FUNCTION_DECL
:
14999 /* Clear current_function_decl, so that gen_subprogram_die thinks
15000 that this is a declaration. At this point, we just want to force
15001 declaration die. */
15002 save_fn
= current_function_decl
;
15003 current_function_decl
= NULL_TREE
;
15004 gen_subprogram_die (decl
, context_die
);
15005 current_function_decl
= save_fn
;
15009 /* Set external flag to force declaration die. Restore it after
15010 gen_decl_die() call. */
15011 saved_external_flag
= DECL_EXTERNAL (decl
);
15012 DECL_EXTERNAL (decl
) = 1;
15013 gen_decl_die (decl
, NULL
, context_die
);
15014 DECL_EXTERNAL (decl
) = saved_external_flag
;
15017 case NAMESPACE_DECL
:
15018 dwarf2out_decl (decl
);
15022 gcc_unreachable ();
15025 /* We should be able to find the DIE now. */
15027 decl_die
= lookup_decl_die (decl
);
15028 gcc_assert (decl_die
);
15034 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15035 always returned. */
15038 force_type_die (tree type
)
15040 dw_die_ref type_die
;
15042 type_die
= lookup_type_die (type
);
15045 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
15047 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
15048 TYPE_VOLATILE (type
), context_die
);
15049 gcc_assert (type_die
);
15054 /* Force out any required namespaces to be able to output DECL,
15055 and return the new context_die for it, if it's changed. */
15058 setup_namespace_context (tree thing
, dw_die_ref context_die
)
15060 tree context
= (DECL_P (thing
)
15061 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
15062 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
15063 /* Force out the namespace. */
15064 context_die
= force_decl_die (context
);
15066 return context_die
;
15069 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15070 type) within its namespace, if appropriate.
15072 For compatibility with older debuggers, namespace DIEs only contain
15073 declarations; all definitions are emitted at CU scope. */
15076 declare_in_namespace (tree thing
, dw_die_ref context_die
)
15078 dw_die_ref ns_context
;
15080 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15081 return context_die
;
15083 /* If this decl is from an inlined function, then don't try to emit it in its
15084 namespace, as we will get confused. It would have already been emitted
15085 when the abstract instance of the inline function was emitted anyways. */
15086 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
15087 return context_die
;
15089 ns_context
= setup_namespace_context (thing
, context_die
);
15091 if (ns_context
!= context_die
)
15095 if (DECL_P (thing
))
15096 gen_decl_die (thing
, NULL
, ns_context
);
15098 gen_type_die (thing
, ns_context
);
15100 return context_die
;
15103 /* Generate a DIE for a namespace or namespace alias. */
15106 gen_namespace_die (tree decl
, dw_die_ref context_die
)
15108 dw_die_ref namespace_die
;
15110 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15111 they are an alias of. */
15112 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
15114 /* Output a real namespace or module. */
15115 context_die
= setup_namespace_context (decl
, comp_unit_die
);
15116 namespace_die
= new_die (is_fortran ()
15117 ? DW_TAG_module
: DW_TAG_namespace
,
15118 context_die
, decl
);
15119 /* For Fortran modules defined in different CU don't add src coords. */
15120 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
15121 add_name_attribute (namespace_die
, dwarf2_name (decl
, 0));
15123 add_name_and_src_coords_attributes (namespace_die
, decl
);
15124 if (DECL_EXTERNAL (decl
))
15125 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
15126 equate_decl_number_to_die (decl
, namespace_die
);
15130 /* Output a namespace alias. */
15132 /* Force out the namespace we are an alias of, if necessary. */
15133 dw_die_ref origin_die
15134 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
15136 if (DECL_CONTEXT (decl
) == NULL_TREE
15137 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
15138 context_die
= setup_namespace_context (decl
, comp_unit_die
);
15139 /* Now create the namespace alias DIE. */
15140 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
15141 add_name_and_src_coords_attributes (namespace_die
, decl
);
15142 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
15143 equate_decl_number_to_die (decl
, namespace_die
);
15147 /* Generate Dwarf debug information for a decl described by DECL. */
15150 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
15152 tree decl_or_origin
= decl
? decl
: origin
;
15153 tree class_origin
= NULL
;
15155 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
15158 switch (TREE_CODE (decl_or_origin
))
15164 if (!is_fortran ())
15166 /* The individual enumerators of an enum type get output when we output
15167 the Dwarf representation of the relevant enum type itself. */
15171 /* Emit its type. */
15172 gen_type_die (TREE_TYPE (decl
), context_die
);
15174 /* And its containing namespace. */
15175 context_die
= declare_in_namespace (decl
, context_die
);
15177 gen_const_die (decl
, context_die
);
15180 case FUNCTION_DECL
:
15181 /* Don't output any DIEs to represent mere function declarations,
15182 unless they are class members or explicit block externs. */
15183 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
15184 && DECL_CONTEXT (decl_or_origin
) == NULL_TREE
15185 && (current_function_decl
== NULL_TREE
15186 || DECL_ARTIFICIAL (decl_or_origin
)))
15191 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15192 on local redeclarations of global functions. That seems broken. */
15193 if (current_function_decl
!= decl
)
15194 /* This is only a declaration. */;
15197 /* If we're emitting a clone, emit info for the abstract instance. */
15198 if (origin
|| DECL_ORIGIN (decl
) != decl
)
15199 dwarf2out_abstract_function (origin
? origin
: DECL_ABSTRACT_ORIGIN (decl
));
15201 /* If we're emitting an out-of-line copy of an inline function,
15202 emit info for the abstract instance and set up to refer to it. */
15203 else if (cgraph_function_possibly_inlined_p (decl
)
15204 && ! DECL_ABSTRACT (decl
)
15205 && ! class_or_namespace_scope_p (context_die
)
15206 /* dwarf2out_abstract_function won't emit a die if this is just
15207 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15208 that case, because that works only if we have a die. */
15209 && DECL_INITIAL (decl
) != NULL_TREE
)
15211 dwarf2out_abstract_function (decl
);
15212 set_decl_origin_self (decl
);
15215 /* Otherwise we're emitting the primary DIE for this decl. */
15216 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15218 /* Before we describe the FUNCTION_DECL itself, make sure that we
15219 have described its return type. */
15220 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
15222 /* And its virtual context. */
15223 if (DECL_VINDEX (decl
) != NULL_TREE
)
15224 gen_type_die (DECL_CONTEXT (decl
), context_die
);
15226 /* And its containing type. */
15228 origin
= decl_class_context (decl
);
15229 if (origin
!= NULL_TREE
)
15230 gen_type_die_for_member (origin
, decl
, context_die
);
15232 /* And its containing namespace. */
15233 context_die
= declare_in_namespace (decl
, context_die
);
15236 /* Now output a DIE to represent the function itself. */
15238 gen_subprogram_die (decl
, context_die
);
15242 /* If we are in terse mode, don't generate any DIEs to represent any
15243 actual typedefs. */
15244 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15247 /* In the special case of a TYPE_DECL node representing the declaration
15248 of some type tag, if the given TYPE_DECL is marked as having been
15249 instantiated from some other (original) TYPE_DECL node (e.g. one which
15250 was generated within the original definition of an inline function) we
15251 used to generate a special (abbreviated) DW_TAG_structure_type,
15252 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15253 should be actually referencing those DIEs, as variable DIEs with that
15254 type would be emitted already in the abstract origin, so it was always
15255 removed during unused type prunning. Don't add anything in this
15257 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
15260 if (is_redundant_typedef (decl
))
15261 gen_type_die (TREE_TYPE (decl
), context_die
);
15263 /* Output a DIE to represent the typedef itself. */
15264 gen_typedef_die (decl
, context_die
);
15268 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
15269 gen_label_die (decl
, context_die
);
15274 /* If we are in terse mode, don't generate any DIEs to represent any
15275 variable declarations or definitions. */
15276 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15279 /* Output any DIEs that are needed to specify the type of this data
15281 if ((TREE_CODE (decl_or_origin
) == RESULT_DECL
15282 || TREE_CODE (decl_or_origin
) == VAR_DECL
)
15283 && DECL_BY_REFERENCE (decl_or_origin
))
15284 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
15286 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
15288 /* And its containing type. */
15289 class_origin
= decl_class_context (decl_or_origin
);
15290 if (class_origin
!= NULL_TREE
)
15291 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
15293 /* And its containing namespace. */
15294 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
15296 /* Now output the DIE to represent the data object itself. This gets
15297 complicated because of the possibility that the VAR_DECL really
15298 represents an inlined instance of a formal parameter for an inline
15301 origin
= decl_ultimate_origin (decl
);
15302 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
15303 gen_formal_parameter_die (decl
, origin
, context_die
);
15305 gen_variable_die (decl
, origin
, context_die
);
15309 /* Ignore the nameless fields that are used to skip bits but handle C++
15310 anonymous unions and structs. */
15311 if (DECL_NAME (decl
) != NULL_TREE
15312 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
15313 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
15315 gen_type_die (member_declared_type (decl
), context_die
);
15316 gen_field_die (decl
, context_die
);
15321 if (DECL_BY_REFERENCE (decl_or_origin
))
15322 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
15324 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
15325 gen_formal_parameter_die (decl
, origin
, context_die
);
15328 case NAMESPACE_DECL
:
15329 case IMPORTED_DECL
:
15330 gen_namespace_die (decl
, context_die
);
15334 /* Probably some frontend-internal decl. Assume we don't care. */
15335 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
15340 /* Output debug information for global decl DECL. Called from toplev.c after
15341 compilation proper has finished. */
15344 dwarf2out_global_decl (tree decl
)
15346 /* Output DWARF2 information for file-scope tentative data object
15347 declarations, file-scope (extern) function declarations (which
15348 had no corresponding body) and file-scope tagged type declarations
15349 and definitions which have not yet been forced out. */
15350 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
15351 dwarf2out_decl (decl
);
15354 /* Output debug information for type decl DECL. Called from toplev.c
15355 and from language front ends (to record built-in types). */
15357 dwarf2out_type_decl (tree decl
, int local
)
15360 dwarf2out_decl (decl
);
15363 /* Output debug information for imported module or decl DECL.
15364 NAME is non-NULL name in the lexical block if the decl has been renamed.
15365 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15366 that DECL belongs to.
15367 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15369 dwarf2out_imported_module_or_decl_1 (tree decl
,
15371 tree lexical_block
,
15372 dw_die_ref lexical_block_die
)
15374 expanded_location xloc
;
15375 dw_die_ref imported_die
= NULL
;
15376 dw_die_ref at_import_die
;
15378 if (TREE_CODE (decl
) == IMPORTED_DECL
)
15380 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
15381 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
15385 xloc
= expand_location (input_location
);
15387 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
15389 if (is_base_type (TREE_TYPE (decl
)))
15390 at_import_die
= base_type_die (TREE_TYPE (decl
));
15392 at_import_die
= force_type_die (TREE_TYPE (decl
));
15393 /* For namespace N { typedef void T; } using N::T; base_type_die
15394 returns NULL, but DW_TAG_imported_declaration requires
15395 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15396 if (!at_import_die
)
15398 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
15399 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
15400 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
15401 gcc_assert (at_import_die
);
15406 at_import_die
= lookup_decl_die (decl
);
15407 if (!at_import_die
)
15409 /* If we're trying to avoid duplicate debug info, we may not have
15410 emitted the member decl for this field. Emit it now. */
15411 if (TREE_CODE (decl
) == FIELD_DECL
)
15413 tree type
= DECL_CONTEXT (decl
);
15415 if (TYPE_CONTEXT (type
)
15416 && TYPE_P (TYPE_CONTEXT (type
))
15417 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
15418 DINFO_USAGE_DIR_USE
))
15420 gen_type_die_for_member (type
, decl
,
15421 get_context_die (TYPE_CONTEXT (type
)));
15423 at_import_die
= force_decl_die (decl
);
15427 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
15428 imported_die
= new_die (DW_TAG_imported_module
,
15432 imported_die
= new_die (DW_TAG_imported_declaration
,
15436 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
15437 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
15439 add_AT_string (imported_die
, DW_AT_name
,
15440 IDENTIFIER_POINTER (name
));
15441 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
15444 /* Output debug information for imported module or decl DECL.
15445 NAME is non-NULL name in context if the decl has been renamed.
15446 CHILD is true if decl is one of the renamed decls as part of
15447 importing whole module. */
15450 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
15453 /* dw_die_ref at_import_die; */
15454 dw_die_ref scope_die
;
15456 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15461 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15462 We need decl DIE for reference and scope die. First, get DIE for the decl
15465 /* Get the scope die for decl context. Use comp_unit_die for global module
15466 or decl. If die is not found for non globals, force new die. */
15468 && TYPE_P (context
)
15469 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
15471 scope_die
= get_context_die (context
);
15475 gcc_assert (scope_die
->die_child
);
15476 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
15477 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
15478 scope_die
= scope_die
->die_child
;
15481 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15482 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
15486 /* Write the debugging output for DECL. */
15489 dwarf2out_decl (tree decl
)
15491 dw_die_ref context_die
= comp_unit_die
;
15493 switch (TREE_CODE (decl
))
15498 case FUNCTION_DECL
:
15499 /* What we would really like to do here is to filter out all mere
15500 file-scope declarations of file-scope functions which are never
15501 referenced later within this translation unit (and keep all of ones
15502 that *are* referenced later on) but we aren't clairvoyant, so we have
15503 no idea which functions will be referenced in the future (i.e. later
15504 on within the current translation unit). So here we just ignore all
15505 file-scope function declarations which are not also definitions. If
15506 and when the debugger needs to know something about these functions,
15507 it will have to hunt around and find the DWARF information associated
15508 with the definition of the function.
15510 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15511 nodes represent definitions and which ones represent mere
15512 declarations. We have to check DECL_INITIAL instead. That's because
15513 the C front-end supports some weird semantics for "extern inline"
15514 function definitions. These can get inlined within the current
15515 translation unit (and thus, we need to generate Dwarf info for their
15516 abstract instances so that the Dwarf info for the concrete inlined
15517 instances can have something to refer to) but the compiler never
15518 generates any out-of-lines instances of such things (despite the fact
15519 that they *are* definitions).
15521 The important point is that the C front-end marks these "extern
15522 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15523 them anyway. Note that the C++ front-end also plays some similar games
15524 for inline function definitions appearing within include files which
15525 also contain `#pragma interface' pragmas. */
15526 if (DECL_INITIAL (decl
) == NULL_TREE
)
15529 /* If we're a nested function, initially use a parent of NULL; if we're
15530 a plain function, this will be fixed up in decls_for_scope. If
15531 we're a method, it will be ignored, since we already have a DIE. */
15532 if (decl_function_context (decl
)
15533 /* But if we're in terse mode, we don't care about scope. */
15534 && debug_info_level
> DINFO_LEVEL_TERSE
)
15535 context_die
= NULL
;
15539 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15540 declaration and if the declaration was never even referenced from
15541 within this entire compilation unit. We suppress these DIEs in
15542 order to save space in the .debug section (by eliminating entries
15543 which are probably useless). Note that we must not suppress
15544 block-local extern declarations (whether used or not) because that
15545 would screw-up the debugger's name lookup mechanism and cause it to
15546 miss things which really ought to be in scope at a given point. */
15547 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
15550 /* For local statics lookup proper context die. */
15551 if (TREE_STATIC (decl
) && decl_function_context (decl
))
15552 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
15554 /* If we are in terse mode, don't generate any DIEs to represent any
15555 variable declarations or definitions. */
15556 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15561 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15563 if (!is_fortran ())
15565 if (TREE_STATIC (decl
) && decl_function_context (decl
))
15566 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
15569 case NAMESPACE_DECL
:
15570 case IMPORTED_DECL
:
15571 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15573 if (lookup_decl_die (decl
) != NULL
)
15578 /* Don't emit stubs for types unless they are needed by other DIEs. */
15579 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
15582 /* Don't bother trying to generate any DIEs to represent any of the
15583 normal built-in types for the language we are compiling. */
15584 if (DECL_IS_BUILTIN (decl
))
15586 /* OK, we need to generate one for `bool' so GDB knows what type
15587 comparisons have. */
15589 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
15590 && ! DECL_IGNORED_P (decl
))
15591 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
15596 /* If we are in terse mode, don't generate any DIEs for types. */
15597 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15600 /* If we're a function-scope tag, initially use a parent of NULL;
15601 this will be fixed up in decls_for_scope. */
15602 if (decl_function_context (decl
))
15603 context_die
= NULL
;
15611 gen_decl_die (decl
, NULL
, context_die
);
15614 /* Output a marker (i.e. a label) for the beginning of the generated code for
15615 a lexical block. */
15618 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
15619 unsigned int blocknum
)
15621 switch_to_section (current_function_section ());
15622 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
15625 /* Output a marker (i.e. a label) for the end of the generated code for a
15629 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
15631 switch_to_section (current_function_section ());
15632 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
15635 /* Returns nonzero if it is appropriate not to emit any debugging
15636 information for BLOCK, because it doesn't contain any instructions.
15638 Don't allow this for blocks with nested functions or local classes
15639 as we would end up with orphans, and in the presence of scheduling
15640 we may end up calling them anyway. */
15643 dwarf2out_ignore_block (const_tree block
)
15648 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
15649 if (TREE_CODE (decl
) == FUNCTION_DECL
15650 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
15652 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
15654 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
15655 if (TREE_CODE (decl
) == FUNCTION_DECL
15656 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
15663 /* Hash table routines for file_hash. */
15666 file_table_eq (const void *p1_p
, const void *p2_p
)
15668 const struct dwarf_file_data
*const p1
=
15669 (const struct dwarf_file_data
*) p1_p
;
15670 const char *const p2
= (const char *) p2_p
;
15671 return strcmp (p1
->filename
, p2
) == 0;
15675 file_table_hash (const void *p_p
)
15677 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
15678 return htab_hash_string (p
->filename
);
15681 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15682 dwarf2out.c) and return its "index". The index of each (known) filename is
15683 just a unique number which is associated with only that one filename. We
15684 need such numbers for the sake of generating labels (in the .debug_sfnames
15685 section) and references to those files numbers (in the .debug_srcinfo
15686 and.debug_macinfo sections). If the filename given as an argument is not
15687 found in our current list, add it to the list and assign it the next
15688 available unique index number. In order to speed up searches, we remember
15689 the index of the filename was looked up last. This handles the majority of
15692 static struct dwarf_file_data
*
15693 lookup_filename (const char *file_name
)
15696 struct dwarf_file_data
* created
;
15698 /* Check to see if the file name that was searched on the previous
15699 call matches this file name. If so, return the index. */
15700 if (file_table_last_lookup
15701 && (file_name
== file_table_last_lookup
->filename
15702 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
15703 return file_table_last_lookup
;
15705 /* Didn't match the previous lookup, search the table. */
15706 slot
= htab_find_slot_with_hash (file_table
, file_name
,
15707 htab_hash_string (file_name
), INSERT
);
15709 return (struct dwarf_file_data
*) *slot
;
15711 created
= GGC_NEW (struct dwarf_file_data
);
15712 created
->filename
= file_name
;
15713 created
->emitted_number
= 0;
15718 /* If the assembler will construct the file table, then translate the compiler
15719 internal file table number into the assembler file table number, and emit
15720 a .file directive if we haven't already emitted one yet. The file table
15721 numbers are different because we prune debug info for unused variables and
15722 types, which may include filenames. */
15725 maybe_emit_file (struct dwarf_file_data
* fd
)
15727 if (! fd
->emitted_number
)
15729 if (last_emitted_file
)
15730 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
15732 fd
->emitted_number
= 1;
15733 last_emitted_file
= fd
;
15735 if (DWARF2_ASM_LINE_DEBUG_INFO
)
15737 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
15738 output_quoted_string (asm_out_file
,
15739 remap_debug_filename (fd
->filename
));
15740 fputc ('\n', asm_out_file
);
15744 return fd
->emitted_number
;
15747 /* Replace DW_AT_name for the decl with name. */
15750 dwarf2out_set_name (tree decl
, tree name
)
15755 die
= TYPE_SYMTAB_DIE (decl
);
15759 attr
= get_AT (die
, DW_AT_name
);
15762 struct indirect_string_node
*node
;
15764 node
= find_AT_string (dwarf2_name (name
, 0));
15765 /* replace the string. */
15766 attr
->dw_attr_val
.v
.val_str
= node
;
15770 add_name_attribute (die
, dwarf2_name (name
, 0));
15772 /* Called by the final INSN scan whenever we see a var location. We
15773 use it to drop labels in the right places, and throw the location in
15774 our lookup table. */
15777 dwarf2out_var_location (rtx loc_note
)
15779 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
15780 struct var_loc_node
*newloc
;
15782 static rtx last_insn
;
15783 static const char *last_label
;
15786 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
15788 prev_insn
= PREV_INSN (loc_note
);
15790 newloc
= GGC_CNEW (struct var_loc_node
);
15791 /* If the insn we processed last time is the previous insn
15792 and it is also a var location note, use the label we emitted
15794 if (last_insn
!= NULL_RTX
15795 && last_insn
== prev_insn
15796 && NOTE_P (prev_insn
)
15797 && NOTE_KIND (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
15799 newloc
->label
= last_label
;
15803 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
15804 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
15806 newloc
->label
= ggc_strdup (loclabel
);
15808 newloc
->var_loc_note
= loc_note
;
15809 newloc
->next
= NULL
;
15811 if (cfun
&& in_cold_section_p
)
15812 newloc
->section_label
= crtl
->subsections
.cold_section_label
;
15814 newloc
->section_label
= text_section_label
;
15816 last_insn
= loc_note
;
15817 last_label
= newloc
->label
;
15818 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
15819 add_var_loc_to_decl (decl
, newloc
);
15822 /* We need to reset the locations at the beginning of each
15823 function. We can't do this in the end_function hook, because the
15824 declarations that use the locations won't have been output when
15825 that hook is called. Also compute have_multiple_function_sections here. */
15828 dwarf2out_begin_function (tree fun
)
15830 htab_empty (decl_loc_table
);
15832 if (function_section (fun
) != text_section
)
15833 have_multiple_function_sections
= true;
15835 dwarf2out_note_section_used ();
15838 /* Output a label to mark the beginning of a source code line entry
15839 and record information relating to this source line, in
15840 'line_info_table' for later output of the .debug_line section. */
15843 dwarf2out_source_line (unsigned int line
, const char *filename
)
15845 if (debug_info_level
>= DINFO_LEVEL_NORMAL
15848 int file_num
= maybe_emit_file (lookup_filename (filename
));
15850 switch_to_section (current_function_section ());
15852 /* If requested, emit something human-readable. */
15853 if (flag_debug_asm
)
15854 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
15857 if (DWARF2_ASM_LINE_DEBUG_INFO
)
15859 /* Emit the .loc directive understood by GNU as. */
15860 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
15862 /* Indicate that line number info exists. */
15863 line_info_table_in_use
++;
15865 else if (function_section (current_function_decl
) != text_section
)
15867 dw_separate_line_info_ref line_info
;
15868 targetm
.asm_out
.internal_label (asm_out_file
,
15869 SEPARATE_LINE_CODE_LABEL
,
15870 separate_line_info_table_in_use
);
15872 /* Expand the line info table if necessary. */
15873 if (separate_line_info_table_in_use
15874 == separate_line_info_table_allocated
)
15876 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15877 separate_line_info_table
15878 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
15879 separate_line_info_table
,
15880 separate_line_info_table_allocated
);
15881 memset (separate_line_info_table
15882 + separate_line_info_table_in_use
,
15884 (LINE_INFO_TABLE_INCREMENT
15885 * sizeof (dw_separate_line_info_entry
)));
15888 /* Add the new entry at the end of the line_info_table. */
15890 = &separate_line_info_table
[separate_line_info_table_in_use
++];
15891 line_info
->dw_file_num
= file_num
;
15892 line_info
->dw_line_num
= line
;
15893 line_info
->function
= current_function_funcdef_no
;
15897 dw_line_info_ref line_info
;
15899 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
15900 line_info_table_in_use
);
15902 /* Expand the line info table if necessary. */
15903 if (line_info_table_in_use
== line_info_table_allocated
)
15905 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15907 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
15908 line_info_table_allocated
);
15909 memset (line_info_table
+ line_info_table_in_use
, 0,
15910 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
15913 /* Add the new entry at the end of the line_info_table. */
15914 line_info
= &line_info_table
[line_info_table_in_use
++];
15915 line_info
->dw_file_num
= file_num
;
15916 line_info
->dw_line_num
= line
;
15921 /* Record the beginning of a new source file. */
15924 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
15926 if (flag_eliminate_dwarf2_dups
)
15928 /* Record the beginning of the file for break_out_includes. */
15929 dw_die_ref bincl_die
;
15931 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
15932 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
15935 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15937 int file_num
= maybe_emit_file (lookup_filename (filename
));
15939 switch_to_section (debug_macinfo_section
);
15940 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
15941 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
15944 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
15948 /* Record the end of a source file. */
15951 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
15953 if (flag_eliminate_dwarf2_dups
)
15954 /* Record the end of the file for break_out_includes. */
15955 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
15957 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15959 switch_to_section (debug_macinfo_section
);
15960 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
15964 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15965 the tail part of the directive line, i.e. the part which is past the
15966 initial whitespace, #, whitespace, directive-name, whitespace part. */
15969 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
15970 const char *buffer ATTRIBUTE_UNUSED
)
15972 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15974 switch_to_section (debug_macinfo_section
);
15975 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
15976 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15977 dw2_asm_output_nstring (buffer
, -1, "The macro");
15981 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15982 the tail part of the directive line, i.e. the part which is past the
15983 initial whitespace, #, whitespace, directive-name, whitespace part. */
15986 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
15987 const char *buffer ATTRIBUTE_UNUSED
)
15989 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15991 switch_to_section (debug_macinfo_section
);
15992 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
15993 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15994 dw2_asm_output_nstring (buffer
, -1, "The macro");
15998 /* Set up for Dwarf output at the start of compilation. */
16001 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
16003 /* Allocate the file_table. */
16004 file_table
= htab_create_ggc (50, file_table_hash
,
16005 file_table_eq
, NULL
);
16007 /* Allocate the decl_die_table. */
16008 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
16009 decl_die_table_eq
, NULL
);
16011 /* Allocate the decl_loc_table. */
16012 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
16013 decl_loc_table_eq
, NULL
);
16015 /* Allocate the initial hunk of the decl_scope_table. */
16016 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
16018 /* Allocate the initial hunk of the abbrev_die_table. */
16019 abbrev_die_table
= GGC_CNEWVEC (dw_die_ref
, ABBREV_DIE_TABLE_INCREMENT
);
16020 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
16021 /* Zero-th entry is allocated, but unused. */
16022 abbrev_die_table_in_use
= 1;
16024 /* Allocate the initial hunk of the line_info_table. */
16025 line_info_table
= GGC_CNEWVEC (dw_line_info_entry
, LINE_INFO_TABLE_INCREMENT
);
16026 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
16028 /* Zero-th entry is allocated, but unused. */
16029 line_info_table_in_use
= 1;
16031 /* Allocate the pubtypes and pubnames vectors. */
16032 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
16033 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
16035 /* Generate the initial DIE for the .debug section. Note that the (string)
16036 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16037 will (typically) be a relative pathname and that this pathname should be
16038 taken as being relative to the directory from which the compiler was
16039 invoked when the given (base) source file was compiled. We will fill
16040 in this value in dwarf2out_finish. */
16041 comp_unit_die
= gen_compile_unit_die (NULL
);
16043 incomplete_types
= VEC_alloc (tree
, gc
, 64);
16045 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
16047 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
16048 SECTION_DEBUG
, NULL
);
16049 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
16050 SECTION_DEBUG
, NULL
);
16051 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
16052 SECTION_DEBUG
, NULL
);
16053 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
16054 SECTION_DEBUG
, NULL
);
16055 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
16056 SECTION_DEBUG
, NULL
);
16057 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
16058 SECTION_DEBUG
, NULL
);
16059 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
16060 SECTION_DEBUG
, NULL
);
16061 #ifdef DEBUG_PUBTYPES_SECTION
16062 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
16063 SECTION_DEBUG
, NULL
);
16065 debug_str_section
= get_section (DEBUG_STR_SECTION
,
16066 DEBUG_STR_SECTION_FLAGS
, NULL
);
16067 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
16068 SECTION_DEBUG
, NULL
);
16069 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
16070 SECTION_DEBUG
, NULL
);
16072 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
16073 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
16074 DEBUG_ABBREV_SECTION_LABEL
, 0);
16075 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
16076 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
16077 COLD_TEXT_SECTION_LABEL
, 0);
16078 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
16080 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
16081 DEBUG_INFO_SECTION_LABEL
, 0);
16082 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
16083 DEBUG_LINE_SECTION_LABEL
, 0);
16084 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
16085 DEBUG_RANGES_SECTION_LABEL
, 0);
16086 switch_to_section (debug_abbrev_section
);
16087 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
16088 switch_to_section (debug_info_section
);
16089 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
16090 switch_to_section (debug_line_section
);
16091 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
16093 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16095 switch_to_section (debug_macinfo_section
);
16096 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
16097 DEBUG_MACINFO_SECTION_LABEL
, 0);
16098 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
16101 switch_to_section (text_section
);
16102 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
16103 if (flag_reorder_blocks_and_partition
)
16105 cold_text_section
= unlikely_text_section ();
16106 switch_to_section (cold_text_section
);
16107 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
16111 /* A helper function for dwarf2out_finish called through
16112 ht_forall. Emit one queued .debug_str string. */
16115 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
16117 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
16119 if (node
->form
== DW_FORM_strp
)
16121 switch_to_section (debug_str_section
);
16122 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
16123 assemble_string (node
->str
, strlen (node
->str
) + 1);
16129 #if ENABLE_ASSERT_CHECKING
16130 /* Verify that all marks are clear. */
16133 verify_marks_clear (dw_die_ref die
)
16137 gcc_assert (! die
->die_mark
);
16138 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
16140 #endif /* ENABLE_ASSERT_CHECKING */
16142 /* Clear the marks for a die and its children.
16143 Be cool if the mark isn't set. */
16146 prune_unmark_dies (dw_die_ref die
)
16152 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
16155 /* Given DIE that we're marking as used, find any other dies
16156 it references as attributes and mark them as used. */
16159 prune_unused_types_walk_attribs (dw_die_ref die
)
16164 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16166 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
16168 /* A reference to another DIE.
16169 Make sure that it will get emitted. */
16170 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
16172 /* Set the string's refcount to 0 so that prune_unused_types_mark
16173 accounts properly for it. */
16174 if (AT_class (a
) == dw_val_class_str
)
16175 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
16180 /* Mark DIE as being used. If DOKIDS is true, then walk down
16181 to DIE's children. */
16184 prune_unused_types_mark (dw_die_ref die
, int dokids
)
16188 if (die
->die_mark
== 0)
16190 /* We haven't done this node yet. Mark it as used. */
16193 /* We also have to mark its parents as used.
16194 (But we don't want to mark our parents' kids due to this.) */
16195 if (die
->die_parent
)
16196 prune_unused_types_mark (die
->die_parent
, 0);
16198 /* Mark any referenced nodes. */
16199 prune_unused_types_walk_attribs (die
);
16201 /* If this node is a specification,
16202 also mark the definition, if it exists. */
16203 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
16204 prune_unused_types_mark (die
->die_definition
, 1);
16207 if (dokids
&& die
->die_mark
!= 2)
16209 /* We need to walk the children, but haven't done so yet.
16210 Remember that we've walked the kids. */
16213 /* If this is an array type, we need to make sure our
16214 kids get marked, even if they're types. */
16215 if (die
->die_tag
== DW_TAG_array_type
)
16216 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
16218 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16222 /* For local classes, look if any static member functions were emitted
16223 and if so, mark them. */
16226 prune_unused_types_walk_local_classes (dw_die_ref die
)
16230 if (die
->die_mark
== 2)
16233 switch (die
->die_tag
)
16235 case DW_TAG_structure_type
:
16236 case DW_TAG_union_type
:
16237 case DW_TAG_class_type
:
16240 case DW_TAG_subprogram
:
16241 if (!get_AT_flag (die
, DW_AT_declaration
)
16242 || die
->die_definition
!= NULL
)
16243 prune_unused_types_mark (die
, 1);
16250 /* Mark children. */
16251 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
16254 /* Walk the tree DIE and mark types that we actually use. */
16257 prune_unused_types_walk (dw_die_ref die
)
16261 /* Don't do anything if this node is already marked and
16262 children have been marked as well. */
16263 if (die
->die_mark
== 2)
16266 switch (die
->die_tag
)
16268 case DW_TAG_structure_type
:
16269 case DW_TAG_union_type
:
16270 case DW_TAG_class_type
:
16271 if (die
->die_perennial_p
)
16274 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
16275 if (c
->die_tag
== DW_TAG_subprogram
)
16278 /* Finding used static member functions inside of classes
16279 is needed just for local classes, because for other classes
16280 static member function DIEs with DW_AT_specification
16281 are emitted outside of the DW_TAG_*_type. If we ever change
16282 it, we'd need to call this even for non-local classes. */
16284 prune_unused_types_walk_local_classes (die
);
16286 /* It's a type node --- don't mark it. */
16289 case DW_TAG_const_type
:
16290 case DW_TAG_packed_type
:
16291 case DW_TAG_pointer_type
:
16292 case DW_TAG_reference_type
:
16293 case DW_TAG_volatile_type
:
16294 case DW_TAG_typedef
:
16295 case DW_TAG_array_type
:
16296 case DW_TAG_interface_type
:
16297 case DW_TAG_friend
:
16298 case DW_TAG_variant_part
:
16299 case DW_TAG_enumeration_type
:
16300 case DW_TAG_subroutine_type
:
16301 case DW_TAG_string_type
:
16302 case DW_TAG_set_type
:
16303 case DW_TAG_subrange_type
:
16304 case DW_TAG_ptr_to_member_type
:
16305 case DW_TAG_file_type
:
16306 if (die
->die_perennial_p
)
16309 /* It's a type node --- don't mark it. */
16313 /* Mark everything else. */
16317 if (die
->die_mark
== 0)
16321 /* Now, mark any dies referenced from here. */
16322 prune_unused_types_walk_attribs (die
);
16327 /* Mark children. */
16328 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16331 /* Increment the string counts on strings referred to from DIE's
16335 prune_unused_types_update_strings (dw_die_ref die
)
16340 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16341 if (AT_class (a
) == dw_val_class_str
)
16343 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
16345 /* Avoid unnecessarily putting strings that are used less than
16346 twice in the hash table. */
16348 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
16351 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
16352 htab_hash_string (s
->str
),
16354 gcc_assert (*slot
== NULL
);
16360 /* Remove from the tree DIE any dies that aren't marked. */
16363 prune_unused_types_prune (dw_die_ref die
)
16367 gcc_assert (die
->die_mark
);
16368 prune_unused_types_update_strings (die
);
16370 if (! die
->die_child
)
16373 c
= die
->die_child
;
16375 dw_die_ref prev
= c
;
16376 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
16377 if (c
== die
->die_child
)
16379 /* No marked children between 'prev' and the end of the list. */
16381 /* No marked children at all. */
16382 die
->die_child
= NULL
;
16385 prev
->die_sib
= c
->die_sib
;
16386 die
->die_child
= prev
;
16391 if (c
!= prev
->die_sib
)
16393 prune_unused_types_prune (c
);
16394 } while (c
!= die
->die_child
);
16398 /* Remove dies representing declarations that we never use. */
16401 prune_unused_types (void)
16404 limbo_die_node
*node
;
16407 #if ENABLE_ASSERT_CHECKING
16408 /* All the marks should already be clear. */
16409 verify_marks_clear (comp_unit_die
);
16410 for (node
= limbo_die_list
; node
; node
= node
->next
)
16411 verify_marks_clear (node
->die
);
16412 #endif /* ENABLE_ASSERT_CHECKING */
16414 /* Set the mark on nodes that are actually used. */
16415 prune_unused_types_walk (comp_unit_die
);
16416 for (node
= limbo_die_list
; node
; node
= node
->next
)
16417 prune_unused_types_walk (node
->die
);
16419 /* Also set the mark on nodes referenced from the
16420 pubname_table or arange_table. */
16421 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
16422 prune_unused_types_mark (pub
->die
, 1);
16423 for (i
= 0; i
< arange_table_in_use
; i
++)
16424 prune_unused_types_mark (arange_table
[i
], 1);
16426 /* Get rid of nodes that aren't marked; and update the string counts. */
16427 if (debug_str_hash
)
16428 htab_empty (debug_str_hash
);
16429 prune_unused_types_prune (comp_unit_die
);
16430 for (node
= limbo_die_list
; node
; node
= node
->next
)
16431 prune_unused_types_prune (node
->die
);
16433 /* Leave the marks clear. */
16434 prune_unmark_dies (comp_unit_die
);
16435 for (node
= limbo_die_list
; node
; node
= node
->next
)
16436 prune_unmark_dies (node
->die
);
16439 /* Set the parameter to true if there are any relative pathnames in
16442 file_table_relative_p (void ** slot
, void *param
)
16444 bool *p
= (bool *) param
;
16445 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
16446 if (!IS_ABSOLUTE_PATH (d
->filename
))
16454 /* Output stuff that dwarf requires at the end of every file,
16455 and generate the DWARF-2 debugging info. */
16458 dwarf2out_finish (const char *filename
)
16460 limbo_die_node
*node
, *next_node
;
16461 dw_die_ref die
= 0;
16464 /* Add the name for the main input file now. We delayed this from
16465 dwarf2out_init to avoid complications with PCH. */
16466 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
16467 if (!IS_ABSOLUTE_PATH (filename
))
16468 add_comp_dir_attribute (comp_unit_die
);
16469 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
16472 htab_traverse (file_table
, file_table_relative_p
, &p
);
16474 add_comp_dir_attribute (comp_unit_die
);
16477 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
16479 add_location_or_const_value_attribute (
16480 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
16481 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
16485 /* Traverse the limbo die list, and add parent/child links. The only
16486 dies without parents that should be here are concrete instances of
16487 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16488 For concrete instances, we can get the parent die from the abstract
16490 for (node
= limbo_die_list
; node
; node
= next_node
)
16492 next_node
= node
->next
;
16495 if (die
->die_parent
== NULL
)
16497 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
16500 add_child_die (origin
->die_parent
, die
);
16501 else if (die
== comp_unit_die
)
16503 else if (errorcount
> 0 || sorrycount
> 0)
16504 /* It's OK to be confused by errors in the input. */
16505 add_child_die (comp_unit_die
, die
);
16508 /* In certain situations, the lexical block containing a
16509 nested function can be optimized away, which results
16510 in the nested function die being orphaned. Likewise
16511 with the return type of that nested function. Force
16512 this to be a child of the containing function.
16514 It may happen that even the containing function got fully
16515 inlined and optimized out. In that case we are lost and
16516 assign the empty child. This should not be big issue as
16517 the function is likely unreachable too. */
16518 tree context
= NULL_TREE
;
16520 gcc_assert (node
->created_for
);
16522 if (DECL_P (node
->created_for
))
16523 context
= DECL_CONTEXT (node
->created_for
);
16524 else if (TYPE_P (node
->created_for
))
16525 context
= TYPE_CONTEXT (node
->created_for
);
16527 gcc_assert (context
16528 && (TREE_CODE (context
) == FUNCTION_DECL
16529 || TREE_CODE (context
) == NAMESPACE_DECL
));
16531 origin
= lookup_decl_die (context
);
16533 add_child_die (origin
, die
);
16535 add_child_die (comp_unit_die
, die
);
16540 limbo_die_list
= NULL
;
16542 /* Walk through the list of incomplete types again, trying once more to
16543 emit full debugging info for them. */
16544 retry_incomplete_types ();
16546 if (flag_eliminate_unused_debug_types
)
16547 prune_unused_types ();
16549 /* Generate separate CUs for each of the include files we've seen.
16550 They will go into limbo_die_list. */
16551 if (flag_eliminate_dwarf2_dups
)
16552 break_out_includes (comp_unit_die
);
16554 /* Traverse the DIE's and add add sibling attributes to those DIE's
16555 that have children. */
16556 add_sibling_attributes (comp_unit_die
);
16557 for (node
= limbo_die_list
; node
; node
= node
->next
)
16558 add_sibling_attributes (node
->die
);
16560 /* Output a terminator label for the .text section. */
16561 switch_to_section (text_section
);
16562 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
16563 if (flag_reorder_blocks_and_partition
)
16565 switch_to_section (unlikely_text_section ());
16566 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
16569 /* We can only use the low/high_pc attributes if all of the code was
16571 if (!have_multiple_function_sections
)
16573 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
16574 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
16579 unsigned fde_idx
= 0;
16581 /* We need to give .debug_loc and .debug_ranges an appropriate
16582 "base address". Use zero so that these addresses become
16583 absolute. Historically, we've emitted the unexpected
16584 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16585 Emit both to give time for other tools to adapt. */
16586 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
16587 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
16589 add_AT_range_list (comp_unit_die
, DW_AT_ranges
,
16590 add_ranges_by_labels (text_section_label
,
16592 if (flag_reorder_blocks_and_partition
)
16593 add_ranges_by_labels (cold_text_section_label
,
16596 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
16598 dw_fde_ref fde
= &fde_table
[fde_idx
];
16600 if (fde
->dw_fde_switched_sections
)
16602 add_ranges_by_labels (fde
->dw_fde_hot_section_label
,
16603 fde
->dw_fde_hot_section_end_label
);
16604 add_ranges_by_labels (fde
->dw_fde_unlikely_section_label
,
16605 fde
->dw_fde_unlikely_section_end_label
);
16608 add_ranges_by_labels (fde
->dw_fde_begin
,
16615 /* Output location list section if necessary. */
16616 if (have_location_lists
)
16618 /* Output the location lists info. */
16619 switch_to_section (debug_loc_section
);
16620 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
16621 DEBUG_LOC_SECTION_LABEL
, 0);
16622 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
16623 output_location_lists (die
);
16626 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
16627 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
16628 debug_line_section_label
);
16630 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16631 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
16633 /* Output all of the compilation units. We put the main one last so that
16634 the offsets are available to output_pubnames. */
16635 for (node
= limbo_die_list
; node
; node
= node
->next
)
16636 output_comp_unit (node
->die
, 0);
16638 /* Output the main compilation unit if non-empty or if .debug_macinfo
16639 has been emitted. */
16640 output_comp_unit (comp_unit_die
, debug_info_level
>= DINFO_LEVEL_VERBOSE
);
16642 /* Output the abbreviation table. */
16643 switch_to_section (debug_abbrev_section
);
16644 output_abbrev_section ();
16646 /* Output public names table if necessary. */
16647 if (!VEC_empty (pubname_entry
, pubname_table
))
16649 switch_to_section (debug_pubnames_section
);
16650 output_pubnames (pubname_table
);
16653 #ifdef DEBUG_PUBTYPES_SECTION
16654 /* Output public types table if necessary. */
16655 if (!VEC_empty (pubname_entry
, pubtype_table
))
16657 switch_to_section (debug_pubtypes_section
);
16658 output_pubnames (pubtype_table
);
16662 /* Output the address range information. We only put functions in the arange
16663 table, so don't write it out if we don't have any. */
16664 if (fde_table_in_use
)
16666 switch_to_section (debug_aranges_section
);
16670 /* Output ranges section if necessary. */
16671 if (ranges_table_in_use
)
16673 switch_to_section (debug_ranges_section
);
16674 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
16678 /* Output the source line correspondence table. We must do this
16679 even if there is no line information. Otherwise, on an empty
16680 translation unit, we will generate a present, but empty,
16681 .debug_info section. IRIX 6.5 `nm' will then complain when
16682 examining the file. This is done late so that any filenames
16683 used by the debug_info section are marked as 'used'. */
16684 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
16686 switch_to_section (debug_line_section
);
16687 output_line_info ();
16690 /* Have to end the macro section. */
16691 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16693 switch_to_section (debug_macinfo_section
);
16694 dw2_asm_output_data (1, 0, "End compilation unit");
16697 /* If we emitted any DW_FORM_strp form attribute, output the string
16699 if (debug_str_hash
)
16700 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
16704 /* This should never be used, but its address is needed for comparisons. */
16705 const struct gcc_debug_hooks dwarf2_debug_hooks
;
16707 #endif /* DWARF2_DEBUGGING_INFO */
16709 #include "gt-dwarf2out.h"