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"
77 #include "elf/dwarf2.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 *, int, bool);
96 static rtx last_var_location_insn
;
99 #ifndef DWARF2_FRAME_INFO
100 # ifdef DWARF2_DEBUGGING_INFO
101 # define DWARF2_FRAME_INFO \
102 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
104 # define DWARF2_FRAME_INFO 0
108 /* Map register numbers held in the call frame info that gcc has
109 collected using DWARF_FRAME_REGNUM to those that should be output in
110 .debug_frame and .eh_frame. */
111 #ifndef DWARF2_FRAME_REG_OUT
112 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
115 /* Save the result of dwarf2out_do_frame across PCH. */
116 static GTY(()) bool saved_do_cfi_asm
= 0;
118 /* Decide whether we want to emit frame unwind information for the current
122 dwarf2out_do_frame (void)
124 /* We want to emit correct CFA location expressions or lists, so we
125 have to return true if we're going to output debug info, even if
126 we're not going to output frame or unwind info. */
127 return (write_symbols
== DWARF2_DEBUG
128 || write_symbols
== VMS_AND_DWARF2_DEBUG
129 || DWARF2_FRAME_INFO
|| saved_do_cfi_asm
130 #ifdef DWARF2_UNWIND_INFO
131 || (DWARF2_UNWIND_INFO
132 && (flag_unwind_tables
133 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
138 /* Decide whether to emit frame unwind via assembler directives. */
141 dwarf2out_do_cfi_asm (void)
145 #ifdef MIPS_DEBUGGING_INFO
148 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
150 if (saved_do_cfi_asm
|| !eh_personality_libfunc
)
152 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
155 /* Make sure the personality encoding is one the assembler can support.
156 In particular, aligned addresses can't be handled. */
157 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
158 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
160 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
161 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
164 saved_do_cfi_asm
= true;
168 /* The size of the target's pointer type. */
170 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
173 /* Array of RTXes referenced by the debugging information, which therefore
174 must be kept around forever. */
175 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
177 /* A pointer to the base of a list of incomplete types which might be
178 completed at some later time. incomplete_types_list needs to be a
179 VEC(tree,gc) because we want to tell the garbage collector about
181 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
183 /* A pointer to the base of a table of references to declaration
184 scopes. This table is a display which tracks the nesting
185 of declaration scopes at the current scope and containing
186 scopes. This table is used to find the proper place to
187 define type declaration DIE's. */
188 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
190 /* Pointers to various DWARF2 sections. */
191 static GTY(()) section
*debug_info_section
;
192 static GTY(()) section
*debug_abbrev_section
;
193 static GTY(()) section
*debug_aranges_section
;
194 static GTY(()) section
*debug_macinfo_section
;
195 static GTY(()) section
*debug_line_section
;
196 static GTY(()) section
*debug_loc_section
;
197 static GTY(()) section
*debug_pubnames_section
;
198 static GTY(()) section
*debug_pubtypes_section
;
199 static GTY(()) section
*debug_str_section
;
200 static GTY(()) section
*debug_ranges_section
;
201 static GTY(()) section
*debug_frame_section
;
203 /* How to start an assembler comment. */
204 #ifndef ASM_COMMENT_START
205 #define ASM_COMMENT_START ";#"
208 typedef struct dw_cfi_struct
*dw_cfi_ref
;
209 typedef struct dw_fde_struct
*dw_fde_ref
;
210 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
212 /* Call frames are described using a sequence of Call Frame
213 Information instructions. The register number, offset
214 and address fields are provided as possible operands;
215 their use is selected by the opcode field. */
217 enum dw_cfi_oprnd_type
{
219 dw_cfi_oprnd_reg_num
,
225 typedef union GTY(()) dw_cfi_oprnd_struct
{
226 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
227 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
228 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
229 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
233 typedef struct GTY(()) dw_cfi_struct
{
234 dw_cfi_ref dw_cfi_next
;
235 enum dwarf_call_frame_info dw_cfi_opc
;
236 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
238 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
243 /* This is how we define the location of the CFA. We use to handle it
244 as REG + OFFSET all the time, but now it can be more complex.
245 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
246 Instead of passing around REG and OFFSET, we pass a copy
247 of this structure. */
248 typedef struct GTY(()) cfa_loc
{
249 HOST_WIDE_INT offset
;
250 HOST_WIDE_INT base_offset
;
252 BOOL_BITFIELD indirect
: 1; /* 1 if CFA is accessed via a dereference. */
253 BOOL_BITFIELD in_use
: 1; /* 1 if a saved cfa is stored here. */
256 /* All call frame descriptions (FDE's) in the GCC generated DWARF
257 refer to a single Common Information Entry (CIE), defined at
258 the beginning of the .debug_frame section. This use of a single
259 CIE obviates the need to keep track of multiple CIE's
260 in the DWARF generation routines below. */
262 typedef struct GTY(()) dw_fde_struct
{
264 const char *dw_fde_begin
;
265 const char *dw_fde_current_label
;
266 const char *dw_fde_end
;
267 const char *dw_fde_hot_section_label
;
268 const char *dw_fde_hot_section_end_label
;
269 const char *dw_fde_unlikely_section_label
;
270 const char *dw_fde_unlikely_section_end_label
;
271 bool dw_fde_switched_sections
;
272 dw_cfi_ref dw_fde_cfi
;
273 unsigned funcdef_number
;
274 HOST_WIDE_INT stack_realignment
;
275 /* Dynamic realign argument pointer register. */
276 unsigned int drap_reg
;
277 /* Virtual dynamic realign argument pointer register. */
278 unsigned int vdrap_reg
;
279 unsigned all_throwers_are_sibcalls
: 1;
280 unsigned nothrow
: 1;
281 unsigned uses_eh_lsda
: 1;
282 /* Whether we did stack realign in this call frame. */
283 unsigned stack_realign
: 1;
284 /* Whether dynamic realign argument pointer register has been saved. */
285 unsigned drap_reg_saved
: 1;
289 /* Maximum size (in bytes) of an artificially generated label. */
290 #define MAX_ARTIFICIAL_LABEL_BYTES 30
292 /* The size of addresses as they appear in the Dwarf 2 data.
293 Some architectures use word addresses to refer to code locations,
294 but Dwarf 2 info always uses byte addresses. On such machines,
295 Dwarf 2 addresses need to be larger than the architecture's
297 #ifndef DWARF2_ADDR_SIZE
298 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
301 /* The size in bytes of a DWARF field indicating an offset or length
302 relative to a debug info section, specified to be 4 bytes in the
303 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
306 #ifndef DWARF_OFFSET_SIZE
307 #define DWARF_OFFSET_SIZE 4
310 /* According to the (draft) DWARF 3 specification, the initial length
311 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
312 bytes are 0xffffffff, followed by the length stored in the next 8
315 However, the SGI/MIPS ABI uses an initial length which is equal to
316 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
318 #ifndef DWARF_INITIAL_LENGTH_SIZE
319 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
322 /* Round SIZE up to the nearest BOUNDARY. */
323 #define DWARF_ROUND(SIZE,BOUNDARY) \
324 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
326 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
327 #ifndef DWARF_CIE_DATA_ALIGNMENT
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
331 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
335 /* CIE identifier. */
336 #if HOST_BITS_PER_WIDE_INT >= 64
337 #define DWARF_CIE_ID \
338 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
340 #define DWARF_CIE_ID DW_CIE_ID
343 /* A pointer to the base of a table that contains frame description
344 information for each routine. */
345 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
347 /* Number of elements currently allocated for fde_table. */
348 static GTY(()) unsigned fde_table_allocated
;
350 /* Number of elements in fde_table currently in use. */
351 static GTY(()) unsigned fde_table_in_use
;
353 /* Size (in elements) of increments by which we may expand the
355 #define FDE_TABLE_INCREMENT 256
357 /* Get the current fde_table entry we should use. */
359 static inline dw_fde_ref
362 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
365 /* A list of call frame insns for the CIE. */
366 static GTY(()) dw_cfi_ref cie_cfi_head
;
368 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
369 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
370 attribute that accelerates the lookup of the FDE associated
371 with the subprogram. This variable holds the table index of the FDE
372 associated with the current function (body) definition. */
373 static unsigned current_funcdef_fde
;
376 struct GTY(()) indirect_string_node
{
378 unsigned int refcount
;
379 enum dwarf_form form
;
383 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
385 static GTY(()) int dw2_string_counter
;
386 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
388 /* True if the compilation unit places functions in more than one section. */
389 static GTY(()) bool have_multiple_function_sections
= false;
391 /* Whether the default text and cold text sections have been used at all. */
393 static GTY(()) bool text_section_used
= false;
394 static GTY(()) bool cold_text_section_used
= false;
396 /* The default cold text section. */
397 static GTY(()) section
*cold_text_section
;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
401 /* Forward declarations for functions defined in this file. */
403 static char *stripattributes (const char *);
404 static const char *dwarf_cfi_name (unsigned);
405 static dw_cfi_ref
new_cfi (void);
406 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
407 static void add_fde_cfi (const char *, dw_cfi_ref
);
408 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*, dw_cfa_location
*);
409 static void lookup_cfa (dw_cfa_location
*);
410 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
411 #ifdef DWARF2_UNWIND_INFO
412 static void initial_return_save (rtx
);
414 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
, HOST_WIDE_INT
,
416 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
417 static void output_cfi_directive (dw_cfi_ref
);
418 static void output_call_frame_info (int);
419 static void dwarf2out_note_section_used (void);
420 static void dwarf2out_stack_adjust (rtx
, bool);
421 static void dwarf2out_args_size_adjust (HOST_WIDE_INT
, const char *);
422 static void flush_queued_reg_saves (void);
423 static bool clobbers_queued_reg_save (const_rtx
);
424 static void dwarf2out_frame_debug_expr (rtx
, const char *);
426 /* Support for complex CFA locations. */
427 static void output_cfa_loc (dw_cfi_ref
);
428 static void output_cfa_loc_raw (dw_cfi_ref
);
429 static void get_cfa_from_loc_descr (dw_cfa_location
*,
430 struct dw_loc_descr_struct
*);
431 static struct dw_loc_descr_struct
*build_cfa_loc
432 (dw_cfa_location
*, HOST_WIDE_INT
);
433 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
434 (HOST_WIDE_INT
, HOST_WIDE_INT
);
435 static void def_cfa_1 (const char *, dw_cfa_location
*);
437 /* How to start an assembler comment. */
438 #ifndef ASM_COMMENT_START
439 #define ASM_COMMENT_START ";#"
442 /* Data and reference forms for relocatable data. */
443 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
444 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
446 #ifndef DEBUG_FRAME_SECTION
447 #define DEBUG_FRAME_SECTION ".debug_frame"
450 #ifndef FUNC_BEGIN_LABEL
451 #define FUNC_BEGIN_LABEL "LFB"
454 #ifndef FUNC_END_LABEL
455 #define FUNC_END_LABEL "LFE"
458 #ifndef FRAME_BEGIN_LABEL
459 #define FRAME_BEGIN_LABEL "Lframe"
461 #define CIE_AFTER_SIZE_LABEL "LSCIE"
462 #define CIE_END_LABEL "LECIE"
463 #define FDE_LABEL "LSFDE"
464 #define FDE_AFTER_SIZE_LABEL "LASFDE"
465 #define FDE_END_LABEL "LEFDE"
466 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
467 #define LINE_NUMBER_END_LABEL "LELT"
468 #define LN_PROLOG_AS_LABEL "LASLTP"
469 #define LN_PROLOG_END_LABEL "LELTP"
470 #define DIE_LABEL_PREFIX "DW"
472 /* The DWARF 2 CFA column which tracks the return address. Normally this
473 is the column for PC, or the first column after all of the hard
475 #ifndef DWARF_FRAME_RETURN_COLUMN
477 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
479 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
483 /* The mapping from gcc register number to DWARF 2 CFA column number. By
484 default, we just provide columns for all registers. */
485 #ifndef DWARF_FRAME_REGNUM
486 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
489 /* Hook used by __throw. */
492 expand_builtin_dwarf_sp_column (void)
494 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
495 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
498 /* Return a pointer to a copy of the section string name S with all
499 attributes stripped off, and an asterisk prepended (for assemble_name). */
502 stripattributes (const char *s
)
504 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
509 while (*s
&& *s
!= ',')
516 /* MEM is a memory reference for the register size table, each element of
517 which has mode MODE. Initialize column C as a return address column. */
520 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
522 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
523 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
524 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
527 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
529 static inline HOST_WIDE_INT
530 div_data_align (HOST_WIDE_INT off
)
532 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
533 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
537 /* Return true if we need a signed version of a given opcode
538 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
541 need_data_align_sf_opcode (HOST_WIDE_INT off
)
543 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
546 /* Generate code to initialize the register size table. */
549 expand_builtin_init_dwarf_reg_sizes (tree address
)
552 enum machine_mode mode
= TYPE_MODE (char_type_node
);
553 rtx addr
= expand_normal (address
);
554 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
555 bool wrote_return_column
= false;
557 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
559 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
561 if (rnum
< DWARF_FRAME_REGISTERS
)
563 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
564 enum machine_mode save_mode
= reg_raw_mode
[i
];
567 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
568 save_mode
= choose_hard_reg_mode (i
, 1, true);
569 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
571 if (save_mode
== VOIDmode
)
573 wrote_return_column
= true;
575 size
= GET_MODE_SIZE (save_mode
);
579 emit_move_insn (adjust_address (mem
, mode
, offset
),
580 gen_int_mode (size
, mode
));
584 if (!wrote_return_column
)
585 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
587 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
588 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
591 targetm
.init_dwarf_reg_sizes_extra (address
);
594 /* Convert a DWARF call frame info. operation to its string name */
597 dwarf_cfi_name (unsigned int cfi_opc
)
601 case DW_CFA_advance_loc
:
602 return "DW_CFA_advance_loc";
604 return "DW_CFA_offset";
606 return "DW_CFA_restore";
610 return "DW_CFA_set_loc";
611 case DW_CFA_advance_loc1
:
612 return "DW_CFA_advance_loc1";
613 case DW_CFA_advance_loc2
:
614 return "DW_CFA_advance_loc2";
615 case DW_CFA_advance_loc4
:
616 return "DW_CFA_advance_loc4";
617 case DW_CFA_offset_extended
:
618 return "DW_CFA_offset_extended";
619 case DW_CFA_restore_extended
:
620 return "DW_CFA_restore_extended";
621 case DW_CFA_undefined
:
622 return "DW_CFA_undefined";
623 case DW_CFA_same_value
:
624 return "DW_CFA_same_value";
625 case DW_CFA_register
:
626 return "DW_CFA_register";
627 case DW_CFA_remember_state
:
628 return "DW_CFA_remember_state";
629 case DW_CFA_restore_state
:
630 return "DW_CFA_restore_state";
632 return "DW_CFA_def_cfa";
633 case DW_CFA_def_cfa_register
:
634 return "DW_CFA_def_cfa_register";
635 case DW_CFA_def_cfa_offset
:
636 return "DW_CFA_def_cfa_offset";
639 case DW_CFA_def_cfa_expression
:
640 return "DW_CFA_def_cfa_expression";
641 case DW_CFA_expression
:
642 return "DW_CFA_expression";
643 case DW_CFA_offset_extended_sf
:
644 return "DW_CFA_offset_extended_sf";
645 case DW_CFA_def_cfa_sf
:
646 return "DW_CFA_def_cfa_sf";
647 case DW_CFA_def_cfa_offset_sf
:
648 return "DW_CFA_def_cfa_offset_sf";
650 /* SGI/MIPS specific */
651 case DW_CFA_MIPS_advance_loc8
:
652 return "DW_CFA_MIPS_advance_loc8";
655 case DW_CFA_GNU_window_save
:
656 return "DW_CFA_GNU_window_save";
657 case DW_CFA_GNU_args_size
:
658 return "DW_CFA_GNU_args_size";
659 case DW_CFA_GNU_negative_offset_extended
:
660 return "DW_CFA_GNU_negative_offset_extended";
663 return "DW_CFA_<unknown>";
667 /* Return a pointer to a newly allocated Call Frame Instruction. */
669 static inline dw_cfi_ref
672 dw_cfi_ref cfi
= GGC_NEW (dw_cfi_node
);
674 cfi
->dw_cfi_next
= NULL
;
675 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
676 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
681 /* Add a Call Frame Instruction to list of instructions. */
684 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
687 dw_fde_ref fde
= current_fde ();
689 /* When DRAP is used, CFA is defined with an expression. Redefine
690 CFA may lead to a different CFA value. */
691 /* ??? Of course, this heuristic fails when we're annotating epilogues,
692 because of course we'll always want to redefine the CFA back to the
693 stack pointer on the way out. Where should we move this check? */
694 if (0 && fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
695 switch (cfi
->dw_cfi_opc
)
697 case DW_CFA_def_cfa_register
:
698 case DW_CFA_def_cfa_offset
:
699 case DW_CFA_def_cfa_offset_sf
:
701 case DW_CFA_def_cfa_sf
:
708 /* Find the end of the chain. */
709 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
715 /* Generate a new label for the CFI info to refer to. FORCE is true
716 if a label needs to be output even when using .cfi_* directives. */
719 dwarf2out_cfi_label (bool force
)
721 static char label
[20];
723 if (!force
&& dwarf2out_do_cfi_asm ())
725 /* In this case, we will be emitting the asm directive instead of
726 the label, so just return a placeholder to keep the rest of the
728 strcpy (label
, "<do not output>");
732 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
733 ASM_OUTPUT_LABEL (asm_out_file
, label
);
739 /* True if remember_state should be emitted before following CFI directive. */
740 static bool emit_cfa_remember
;
742 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
743 or to the CIE if LABEL is NULL. */
746 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
748 dw_cfi_ref
*list_head
;
750 if (emit_cfa_remember
)
752 dw_cfi_ref cfi_remember
;
754 /* Emit the state save. */
755 emit_cfa_remember
= false;
756 cfi_remember
= new_cfi ();
757 cfi_remember
->dw_cfi_opc
= DW_CFA_remember_state
;
758 add_fde_cfi (label
, cfi_remember
);
761 list_head
= &cie_cfi_head
;
763 if (dwarf2out_do_cfi_asm ())
767 dw_fde_ref fde
= current_fde ();
769 gcc_assert (fde
!= NULL
);
771 /* We still have to add the cfi to the list so that lookup_cfa
772 works later on. When -g2 and above we even need to force
773 emitting of CFI labels and add to list a DW_CFA_set_loc for
774 convert_cfa_to_fb_loc_list purposes. If we're generating
775 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
776 convert_cfa_to_fb_loc_list. */
777 if (dwarf_version
== 2
778 && debug_info_level
> DINFO_LEVEL_TERSE
779 && (write_symbols
== DWARF2_DEBUG
780 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
782 switch (cfi
->dw_cfi_opc
)
784 case DW_CFA_def_cfa_offset
:
785 case DW_CFA_def_cfa_offset_sf
:
786 case DW_CFA_def_cfa_register
:
788 case DW_CFA_def_cfa_sf
:
789 case DW_CFA_def_cfa_expression
:
790 case DW_CFA_restore_state
:
791 if (*label
== 0 || strcmp (label
, "<do not output>") == 0)
792 label
= dwarf2out_cfi_label (true);
794 if (fde
->dw_fde_current_label
== NULL
795 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
799 label
= xstrdup (label
);
801 /* Set the location counter to the new label. */
803 /* It doesn't metter whether DW_CFA_set_loc
804 or DW_CFA_advance_loc4 is added here, those aren't
805 emitted into assembly, only looked up by
806 convert_cfa_to_fb_loc_list. */
807 xcfi
->dw_cfi_opc
= DW_CFA_set_loc
;
808 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
809 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
810 fde
->dw_fde_current_label
= label
;
818 output_cfi_directive (cfi
);
820 list_head
= &fde
->dw_fde_cfi
;
822 /* ??? If this is a CFI for the CIE, we don't emit. This
823 assumes that the standard CIE contents that the assembler
824 uses matches the standard CIE contents that the compiler
825 uses. This is probably a bad assumption. I'm not quite
826 sure how to address this for now. */
830 dw_fde_ref fde
= current_fde ();
832 gcc_assert (fde
!= NULL
);
835 label
= dwarf2out_cfi_label (false);
837 if (fde
->dw_fde_current_label
== NULL
838 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
842 label
= xstrdup (label
);
844 /* Set the location counter to the new label. */
846 /* If we have a current label, advance from there, otherwise
847 set the location directly using set_loc. */
848 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
849 ? DW_CFA_advance_loc4
851 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
852 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
854 fde
->dw_fde_current_label
= label
;
857 list_head
= &fde
->dw_fde_cfi
;
860 add_cfi (list_head
, cfi
);
863 /* Subroutine of lookup_cfa. */
866 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
868 switch (cfi
->dw_cfi_opc
)
870 case DW_CFA_def_cfa_offset
:
871 case DW_CFA_def_cfa_offset_sf
:
872 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
874 case DW_CFA_def_cfa_register
:
875 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
878 case DW_CFA_def_cfa_sf
:
879 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
880 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
882 case DW_CFA_def_cfa_expression
:
883 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
886 case DW_CFA_remember_state
:
887 gcc_assert (!remember
->in_use
);
889 remember
->in_use
= 1;
891 case DW_CFA_restore_state
:
892 gcc_assert (remember
->in_use
);
894 remember
->in_use
= 0;
902 /* Find the previous value for the CFA. */
905 lookup_cfa (dw_cfa_location
*loc
)
909 dw_cfa_location remember
;
911 memset (loc
, 0, sizeof (*loc
));
912 loc
->reg
= INVALID_REGNUM
;
915 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
916 lookup_cfa_1 (cfi
, loc
, &remember
);
918 fde
= current_fde ();
920 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
921 lookup_cfa_1 (cfi
, loc
, &remember
);
924 /* The current rule for calculating the DWARF2 canonical frame address. */
925 static dw_cfa_location cfa
;
927 /* The register used for saving registers to the stack, and its offset
929 static dw_cfa_location cfa_store
;
931 /* The current save location around an epilogue. */
932 static dw_cfa_location cfa_remember
;
934 /* The running total of the size of arguments pushed onto the stack. */
935 static HOST_WIDE_INT args_size
;
937 /* The last args_size we actually output. */
938 static HOST_WIDE_INT old_args_size
;
940 /* Entry point to update the canonical frame address (CFA).
941 LABEL is passed to add_fde_cfi. The value of CFA is now to be
942 calculated from REG+OFFSET. */
945 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
952 def_cfa_1 (label
, &loc
);
955 /* Determine if two dw_cfa_location structures define the same data. */
958 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
960 return (loc1
->reg
== loc2
->reg
961 && loc1
->offset
== loc2
->offset
962 && loc1
->indirect
== loc2
->indirect
963 && (loc1
->indirect
== 0
964 || loc1
->base_offset
== loc2
->base_offset
));
967 /* This routine does the actual work. The CFA is now calculated from
968 the dw_cfa_location structure. */
971 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
974 dw_cfa_location old_cfa
, loc
;
979 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
980 cfa_store
.offset
= loc
.offset
;
982 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
983 lookup_cfa (&old_cfa
);
985 /* If nothing changed, no need to issue any call frame instructions. */
986 if (cfa_equal_p (&loc
, &old_cfa
))
991 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
993 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
994 the CFA register did not change but the offset did. The data
995 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
996 in the assembler via the .cfi_def_cfa_offset directive. */
998 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
1000 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
1001 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
1004 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1005 else if (loc
.offset
== old_cfa
.offset
1006 && old_cfa
.reg
!= INVALID_REGNUM
1009 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1010 indicating the CFA register has changed to <register> but the
1011 offset has not changed. */
1012 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
1013 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1017 else if (loc
.indirect
== 0)
1019 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1020 indicating the CFA register has changed to <register> with
1021 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1022 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1025 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
1027 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
1028 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
1029 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
1033 /* Construct a DW_CFA_def_cfa_expression instruction to
1034 calculate the CFA using a full location expression since no
1035 register-offset pair is available. */
1036 struct dw_loc_descr_struct
*loc_list
;
1038 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
1039 loc_list
= build_cfa_loc (&loc
, 0);
1040 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
1043 add_fde_cfi (label
, cfi
);
1046 /* Add the CFI for saving a register. REG is the CFA column number.
1047 LABEL is passed to add_fde_cfi.
1048 If SREG is -1, the register is saved at OFFSET from the CFA;
1049 otherwise it is saved in SREG. */
1052 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
1054 dw_cfi_ref cfi
= new_cfi ();
1055 dw_fde_ref fde
= current_fde ();
1057 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1059 /* When stack is aligned, store REG using DW_CFA_expression with
1062 && fde
->stack_realign
1063 && sreg
== INVALID_REGNUM
)
1065 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1066 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= reg
;
1067 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
1068 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
1070 else if (sreg
== INVALID_REGNUM
)
1072 if (need_data_align_sf_opcode (offset
))
1073 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1074 else if (reg
& ~0x3f)
1075 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1077 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1078 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
1080 else if (sreg
== reg
)
1081 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
1084 cfi
->dw_cfi_opc
= DW_CFA_register
;
1085 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
1088 add_fde_cfi (label
, cfi
);
1091 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1092 This CFI tells the unwinder that it needs to restore the window registers
1093 from the previous frame's window save area.
1095 ??? Perhaps we should note in the CIE where windows are saved (instead of
1096 assuming 0(cfa)) and what registers are in the window. */
1099 dwarf2out_window_save (const char *label
)
1101 dw_cfi_ref cfi
= new_cfi ();
1103 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1104 add_fde_cfi (label
, cfi
);
1107 /* Add a CFI to update the running total of the size of arguments
1108 pushed onto the stack. */
1111 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
1115 if (size
== old_args_size
)
1118 old_args_size
= size
;
1121 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
1122 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
1123 add_fde_cfi (label
, cfi
);
1126 /* Entry point for saving a register to the stack. REG is the GCC register
1127 number. LABEL and OFFSET are passed to reg_save. */
1130 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1132 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1135 /* Entry point for saving the return address in the stack.
1136 LABEL and OFFSET are passed to reg_save. */
1139 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1141 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1144 /* Entry point for saving the return address in a register.
1145 LABEL and SREG are passed to reg_save. */
1148 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1150 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1153 #ifdef DWARF2_UNWIND_INFO
1154 /* Record the initial position of the return address. RTL is
1155 INCOMING_RETURN_ADDR_RTX. */
1158 initial_return_save (rtx rtl
)
1160 unsigned int reg
= INVALID_REGNUM
;
1161 HOST_WIDE_INT offset
= 0;
1163 switch (GET_CODE (rtl
))
1166 /* RA is in a register. */
1167 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1171 /* RA is on the stack. */
1172 rtl
= XEXP (rtl
, 0);
1173 switch (GET_CODE (rtl
))
1176 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1181 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1182 offset
= INTVAL (XEXP (rtl
, 1));
1186 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1187 offset
= -INTVAL (XEXP (rtl
, 1));
1197 /* The return address is at some offset from any value we can
1198 actually load. For instance, on the SPARC it is in %i7+8. Just
1199 ignore the offset for now; it doesn't matter for unwinding frames. */
1200 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
1201 initial_return_save (XEXP (rtl
, 0));
1208 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1209 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1213 /* Given a SET, calculate the amount of stack adjustment it
1216 static HOST_WIDE_INT
1217 stack_adjust_offset (const_rtx pattern
, HOST_WIDE_INT cur_args_size
,
1218 HOST_WIDE_INT cur_offset
)
1220 const_rtx src
= SET_SRC (pattern
);
1221 const_rtx dest
= SET_DEST (pattern
);
1222 HOST_WIDE_INT offset
= 0;
1225 if (dest
== stack_pointer_rtx
)
1227 code
= GET_CODE (src
);
1229 /* Assume (set (reg sp) (reg whatever)) sets args_size
1231 if (code
== REG
&& src
!= stack_pointer_rtx
)
1233 offset
= -cur_args_size
;
1234 #ifndef STACK_GROWS_DOWNWARD
1237 return offset
- cur_offset
;
1240 if (! (code
== PLUS
|| code
== MINUS
)
1241 || XEXP (src
, 0) != stack_pointer_rtx
1242 || !CONST_INT_P (XEXP (src
, 1)))
1245 /* (set (reg sp) (plus (reg sp) (const_int))) */
1246 offset
= INTVAL (XEXP (src
, 1));
1252 if (MEM_P (src
) && !MEM_P (dest
))
1256 /* (set (mem (pre_dec (reg sp))) (foo)) */
1257 src
= XEXP (dest
, 0);
1258 code
= GET_CODE (src
);
1264 if (XEXP (src
, 0) == stack_pointer_rtx
)
1266 rtx val
= XEXP (XEXP (src
, 1), 1);
1267 /* We handle only adjustments by constant amount. */
1268 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1269 && CONST_INT_P (val
));
1270 offset
= -INTVAL (val
);
1277 if (XEXP (src
, 0) == stack_pointer_rtx
)
1279 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1286 if (XEXP (src
, 0) == stack_pointer_rtx
)
1288 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1303 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1304 indexed by INSN_UID. */
1306 static HOST_WIDE_INT
*barrier_args_size
;
1308 /* Helper function for compute_barrier_args_size. Handle one insn. */
1310 static HOST_WIDE_INT
1311 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1312 VEC (rtx
, heap
) **next
)
1314 HOST_WIDE_INT offset
= 0;
1317 if (! RTX_FRAME_RELATED_P (insn
))
1319 if (prologue_epilogue_contains (insn
))
1321 else if (GET_CODE (PATTERN (insn
)) == SET
)
1322 offset
= stack_adjust_offset (PATTERN (insn
), cur_args_size
, 0);
1323 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1324 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1326 /* There may be stack adjustments inside compound insns. Search
1328 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1329 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1330 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1331 cur_args_size
, offset
);
1336 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1340 expr
= XEXP (expr
, 0);
1341 if (GET_CODE (expr
) == PARALLEL
1342 || GET_CODE (expr
) == SEQUENCE
)
1343 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1345 rtx elem
= XVECEXP (expr
, 0, i
);
1347 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1348 offset
+= stack_adjust_offset (elem
, cur_args_size
, offset
);
1353 #ifndef STACK_GROWS_DOWNWARD
1357 cur_args_size
+= offset
;
1358 if (cur_args_size
< 0)
1363 rtx dest
= JUMP_LABEL (insn
);
1367 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1369 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1370 VEC_safe_push (rtx
, heap
, *next
, dest
);
1375 return cur_args_size
;
1378 /* Walk the whole function and compute args_size on BARRIERs. */
1381 compute_barrier_args_size (void)
1383 int max_uid
= get_max_uid (), i
;
1385 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1387 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1388 for (i
= 0; i
< max_uid
; i
++)
1389 barrier_args_size
[i
] = -1;
1391 worklist
= VEC_alloc (rtx
, heap
, 20);
1392 next
= VEC_alloc (rtx
, heap
, 20);
1393 insn
= get_insns ();
1394 barrier_args_size
[INSN_UID (insn
)] = 0;
1395 VEC_quick_push (rtx
, worklist
, insn
);
1398 while (!VEC_empty (rtx
, worklist
))
1400 rtx prev
, body
, first_insn
;
1401 HOST_WIDE_INT cur_args_size
;
1403 first_insn
= insn
= VEC_pop (rtx
, worklist
);
1404 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1405 prev
= prev_nonnote_insn (insn
);
1406 if (prev
&& BARRIER_P (prev
))
1407 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1409 for (; insn
; insn
= NEXT_INSN (insn
))
1411 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1413 if (BARRIER_P (insn
))
1418 if (insn
== first_insn
)
1420 else if (barrier_args_size
[INSN_UID (insn
)] < 0)
1422 barrier_args_size
[INSN_UID (insn
)] = cur_args_size
;
1427 /* The insns starting with this label have been
1428 already scanned or are in the worklist. */
1433 body
= PATTERN (insn
);
1434 if (GET_CODE (body
) == SEQUENCE
)
1436 HOST_WIDE_INT dest_args_size
= cur_args_size
;
1437 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1438 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0))
1439 && INSN_FROM_TARGET_P (XVECEXP (body
, 0, i
)))
1441 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1442 dest_args_size
, &next
);
1445 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1446 cur_args_size
, &next
);
1448 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body
, 0, 0)))
1449 compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1450 dest_args_size
, &next
);
1453 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1454 cur_args_size
, &next
);
1458 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1462 if (VEC_empty (rtx
, next
))
1465 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1469 VEC_truncate (rtx
, next
, 0);
1472 VEC_free (rtx
, heap
, worklist
);
1473 VEC_free (rtx
, heap
, next
);
1477 /* Check INSN to see if it looks like a push or a stack adjustment, and
1478 make a note of it if it does. EH uses this information to find out how
1479 much extra space it needs to pop off the stack. */
1482 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1484 HOST_WIDE_INT offset
;
1488 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1489 with this function. Proper support would require all frame-related
1490 insns to be marked, and to be able to handle saving state around
1491 epilogues textually in the middle of the function. */
1492 if (prologue_epilogue_contains (insn
))
1495 /* If INSN is an instruction from target of an annulled branch, the
1496 effects are for the target only and so current argument size
1497 shouldn't change at all. */
1499 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence
, 0, 0))
1500 && INSN_FROM_TARGET_P (insn
))
1503 /* If only calls can throw, and we have a frame pointer,
1504 save up adjustments until we see the CALL_INSN. */
1505 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1507 if (CALL_P (insn
) && !after_p
)
1509 /* Extract the size of the args from the CALL rtx itself. */
1510 insn
= PATTERN (insn
);
1511 if (GET_CODE (insn
) == PARALLEL
)
1512 insn
= XVECEXP (insn
, 0, 0);
1513 if (GET_CODE (insn
) == SET
)
1514 insn
= SET_SRC (insn
);
1515 gcc_assert (GET_CODE (insn
) == CALL
);
1516 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1521 if (CALL_P (insn
) && !after_p
)
1523 if (!flag_asynchronous_unwind_tables
)
1524 dwarf2out_args_size ("", args_size
);
1527 else if (BARRIER_P (insn
))
1529 /* Don't call compute_barrier_args_size () if the only
1530 BARRIER is at the end of function. */
1531 if (barrier_args_size
== NULL
&& next_nonnote_insn (insn
))
1532 compute_barrier_args_size ();
1533 if (barrier_args_size
== NULL
)
1537 offset
= barrier_args_size
[INSN_UID (insn
)];
1542 offset
-= args_size
;
1543 #ifndef STACK_GROWS_DOWNWARD
1547 else if (GET_CODE (PATTERN (insn
)) == SET
)
1548 offset
= stack_adjust_offset (PATTERN (insn
), args_size
, 0);
1549 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1550 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1552 /* There may be stack adjustments inside compound insns. Search
1554 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1555 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1556 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
),
1565 label
= dwarf2out_cfi_label (false);
1566 dwarf2out_args_size_adjust (offset
, label
);
1569 /* Adjust args_size based on stack adjustment OFFSET. */
1572 dwarf2out_args_size_adjust (HOST_WIDE_INT offset
, const char *label
)
1574 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1575 cfa
.offset
+= offset
;
1577 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1578 cfa_store
.offset
+= offset
;
1580 #ifndef STACK_GROWS_DOWNWARD
1584 args_size
+= offset
;
1588 def_cfa_1 (label
, &cfa
);
1589 if (flag_asynchronous_unwind_tables
)
1590 dwarf2out_args_size (label
, args_size
);
1595 /* We delay emitting a register save until either (a) we reach the end
1596 of the prologue or (b) the register is clobbered. This clusters
1597 register saves so that there are fewer pc advances. */
1599 struct GTY(()) queued_reg_save
{
1600 struct queued_reg_save
*next
;
1602 HOST_WIDE_INT cfa_offset
;
1606 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1608 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1609 struct GTY(()) reg_saved_in_data
{
1614 /* A list of registers saved in other registers.
1615 The list intentionally has a small maximum capacity of 4; if your
1616 port needs more than that, you might consider implementing a
1617 more efficient data structure. */
1618 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1619 static GTY(()) size_t num_regs_saved_in_regs
;
1621 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1622 static const char *last_reg_save_label
;
1624 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1625 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1628 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1630 struct queued_reg_save
*q
;
1632 /* Duplicates waste space, but it's also necessary to remove them
1633 for correctness, since the queue gets output in reverse
1635 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1636 if (REGNO (q
->reg
) == REGNO (reg
))
1641 q
= GGC_NEW (struct queued_reg_save
);
1642 q
->next
= queued_reg_saves
;
1643 queued_reg_saves
= q
;
1647 q
->cfa_offset
= offset
;
1648 q
->saved_reg
= sreg
;
1650 last_reg_save_label
= label
;
1653 /* Output all the entries in QUEUED_REG_SAVES. */
1656 flush_queued_reg_saves (void)
1658 struct queued_reg_save
*q
;
1660 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1663 unsigned int reg
, sreg
;
1665 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1666 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1668 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1670 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1671 num_regs_saved_in_regs
++;
1673 if (i
!= num_regs_saved_in_regs
)
1675 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1676 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1679 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1681 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1683 sreg
= INVALID_REGNUM
;
1684 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1687 queued_reg_saves
= NULL
;
1688 last_reg_save_label
= NULL
;
1691 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1692 location for? Or, does it clobber a register which we've previously
1693 said that some other register is saved in, and for which we now
1694 have a new location for? */
1697 clobbers_queued_reg_save (const_rtx insn
)
1699 struct queued_reg_save
*q
;
1701 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1704 if (modified_in_p (q
->reg
, insn
))
1706 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1707 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1708 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1715 /* Entry point for saving the first register into the second. */
1718 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1721 unsigned int regno
, sregno
;
1723 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1724 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1726 if (i
== num_regs_saved_in_regs
)
1728 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1729 num_regs_saved_in_regs
++;
1731 regs_saved_in_regs
[i
].orig_reg
= reg
;
1732 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1734 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1735 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1736 reg_save (label
, regno
, sregno
, 0);
1739 /* What register, if any, is currently saved in REG? */
1742 reg_saved_in (rtx reg
)
1744 unsigned int regn
= REGNO (reg
);
1746 struct queued_reg_save
*q
;
1748 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1749 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1752 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1753 if (regs_saved_in_regs
[i
].saved_in_reg
1754 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1755 return regs_saved_in_regs
[i
].orig_reg
;
1761 /* A temporary register holding an integral value used in adjusting SP
1762 or setting up the store_reg. The "offset" field holds the integer
1763 value, not an offset. */
1764 static dw_cfa_location cfa_temp
;
1766 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1769 dwarf2out_frame_debug_def_cfa (rtx pat
, const char *label
)
1771 memset (&cfa
, 0, sizeof (cfa
));
1773 switch (GET_CODE (pat
))
1776 cfa
.reg
= REGNO (XEXP (pat
, 0));
1777 cfa
.offset
= INTVAL (XEXP (pat
, 1));
1781 cfa
.reg
= REGNO (pat
);
1785 /* Recurse and define an expression. */
1789 def_cfa_1 (label
, &cfa
);
1792 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1795 dwarf2out_frame_debug_adjust_cfa (rtx pat
, const char *label
)
1799 gcc_assert (GET_CODE (pat
) == SET
);
1800 dest
= XEXP (pat
, 0);
1801 src
= XEXP (pat
, 1);
1803 switch (GET_CODE (src
))
1806 gcc_assert (REGNO (XEXP (src
, 0)) == cfa
.reg
);
1807 cfa
.offset
-= INTVAL (XEXP (src
, 1));
1817 cfa
.reg
= REGNO (dest
);
1818 gcc_assert (cfa
.indirect
== 0);
1820 def_cfa_1 (label
, &cfa
);
1823 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1826 dwarf2out_frame_debug_cfa_offset (rtx set
, const char *label
)
1828 HOST_WIDE_INT offset
;
1829 rtx src
, addr
, span
;
1831 src
= XEXP (set
, 1);
1832 addr
= XEXP (set
, 0);
1833 gcc_assert (MEM_P (addr
));
1834 addr
= XEXP (addr
, 0);
1836 /* As documented, only consider extremely simple addresses. */
1837 switch (GET_CODE (addr
))
1840 gcc_assert (REGNO (addr
) == cfa
.reg
);
1841 offset
= -cfa
.offset
;
1844 gcc_assert (REGNO (XEXP (addr
, 0)) == cfa
.reg
);
1845 offset
= INTVAL (XEXP (addr
, 1)) - cfa
.offset
;
1851 span
= targetm
.dwarf_register_span (src
);
1853 /* ??? We'd like to use queue_reg_save, but we need to come up with
1854 a different flushing heuristic for epilogues. */
1856 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (src
)), INVALID_REGNUM
, offset
);
1859 /* We have a PARALLEL describing where the contents of SRC live.
1860 Queue register saves for each piece of the PARALLEL. */
1863 HOST_WIDE_INT span_offset
= offset
;
1865 gcc_assert (GET_CODE (span
) == PARALLEL
);
1867 limit
= XVECLEN (span
, 0);
1868 for (par_index
= 0; par_index
< limit
; par_index
++)
1870 rtx elem
= XVECEXP (span
, 0, par_index
);
1872 reg_save (label
, DWARF_FRAME_REGNUM (REGNO (elem
)),
1873 INVALID_REGNUM
, span_offset
);
1874 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
1879 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1882 dwarf2out_frame_debug_cfa_register (rtx set
, const char *label
)
1885 unsigned sregno
, dregno
;
1887 src
= XEXP (set
, 1);
1888 dest
= XEXP (set
, 0);
1891 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1893 sregno
= DWARF_FRAME_REGNUM (REGNO (src
));
1895 dregno
= DWARF_FRAME_REGNUM (REGNO (dest
));
1897 /* ??? We'd like to use queue_reg_save, but we need to come up with
1898 a different flushing heuristic for epilogues. */
1899 reg_save (label
, sregno
, dregno
, 0);
1902 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1905 dwarf2out_frame_debug_cfa_restore (rtx reg
, const char *label
)
1907 dw_cfi_ref cfi
= new_cfi ();
1908 unsigned int regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1910 cfi
->dw_cfi_opc
= (regno
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
1911 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
1913 add_fde_cfi (label
, cfi
);
1916 /* Record call frame debugging information for an expression EXPR,
1917 which either sets SP or FP (adjusting how we calculate the frame
1918 address) or saves a register to the stack or another register.
1919 LABEL indicates the address of EXPR.
1921 This function encodes a state machine mapping rtxes to actions on
1922 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1923 users need not read the source code.
1925 The High-Level Picture
1927 Changes in the register we use to calculate the CFA: Currently we
1928 assume that if you copy the CFA register into another register, we
1929 should take the other one as the new CFA register; this seems to
1930 work pretty well. If it's wrong for some target, it's simple
1931 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1933 Changes in the register we use for saving registers to the stack:
1934 This is usually SP, but not always. Again, we deduce that if you
1935 copy SP into another register (and SP is not the CFA register),
1936 then the new register is the one we will be using for register
1937 saves. This also seems to work.
1939 Register saves: There's not much guesswork about this one; if
1940 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1941 register save, and the register used to calculate the destination
1942 had better be the one we think we're using for this purpose.
1943 It's also assumed that a copy from a call-saved register to another
1944 register is saving that register if RTX_FRAME_RELATED_P is set on
1945 that instruction. If the copy is from a call-saved register to
1946 the *same* register, that means that the register is now the same
1947 value as in the caller.
1949 Except: If the register being saved is the CFA register, and the
1950 offset is nonzero, we are saving the CFA, so we assume we have to
1951 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1952 the intent is to save the value of SP from the previous frame.
1954 In addition, if a register has previously been saved to a different
1957 Invariants / Summaries of Rules
1959 cfa current rule for calculating the CFA. It usually
1960 consists of a register and an offset.
1961 cfa_store register used by prologue code to save things to the stack
1962 cfa_store.offset is the offset from the value of
1963 cfa_store.reg to the actual CFA
1964 cfa_temp register holding an integral value. cfa_temp.offset
1965 stores the value, which will be used to adjust the
1966 stack pointer. cfa_temp is also used like cfa_store,
1967 to track stores to the stack via fp or a temp reg.
1969 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1970 with cfa.reg as the first operand changes the cfa.reg and its
1971 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1974 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1975 expression yielding a constant. This sets cfa_temp.reg
1976 and cfa_temp.offset.
1978 Rule 5: Create a new register cfa_store used to save items to the
1981 Rules 10-14: Save a register to the stack. Define offset as the
1982 difference of the original location and cfa_store's
1983 location (or cfa_temp's location if cfa_temp is used).
1985 Rules 16-20: If AND operation happens on sp in prologue, we assume
1986 stack is realigned. We will use a group of DW_OP_XXX
1987 expressions to represent the location of the stored
1988 register instead of CFA+offset.
1992 "{a,b}" indicates a choice of a xor b.
1993 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1996 (set <reg1> <reg2>:cfa.reg)
1997 effects: cfa.reg = <reg1>
1998 cfa.offset unchanged
1999 cfa_temp.reg = <reg1>
2000 cfa_temp.offset = cfa.offset
2003 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2004 {<const_int>,<reg>:cfa_temp.reg}))
2005 effects: cfa.reg = sp if fp used
2006 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2007 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2008 if cfa_store.reg==sp
2011 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2012 effects: cfa.reg = fp
2013 cfa_offset += +/- <const_int>
2016 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2017 constraints: <reg1> != fp
2019 effects: cfa.reg = <reg1>
2020 cfa_temp.reg = <reg1>
2021 cfa_temp.offset = cfa.offset
2024 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2025 constraints: <reg1> != fp
2027 effects: cfa_store.reg = <reg1>
2028 cfa_store.offset = cfa.offset - cfa_temp.offset
2031 (set <reg> <const_int>)
2032 effects: cfa_temp.reg = <reg>
2033 cfa_temp.offset = <const_int>
2036 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2037 effects: cfa_temp.reg = <reg1>
2038 cfa_temp.offset |= <const_int>
2041 (set <reg> (high <exp>))
2045 (set <reg> (lo_sum <exp> <const_int>))
2046 effects: cfa_temp.reg = <reg>
2047 cfa_temp.offset = <const_int>
2050 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2051 effects: cfa_store.offset -= <const_int>
2052 cfa.offset = cfa_store.offset if cfa.reg == sp
2054 cfa.base_offset = -cfa_store.offset
2057 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2058 effects: cfa_store.offset += -/+ mode_size(mem)
2059 cfa.offset = cfa_store.offset if cfa.reg == sp
2061 cfa.base_offset = -cfa_store.offset
2064 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2067 effects: cfa.reg = <reg1>
2068 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2071 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2072 effects: cfa.reg = <reg1>
2073 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2076 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2077 effects: cfa.reg = <reg1>
2078 cfa.base_offset = -cfa_temp.offset
2079 cfa_temp.offset -= mode_size(mem)
2082 (set <reg> {unspec, unspec_volatile})
2083 effects: target-dependent
2086 (set sp (and: sp <const_int>))
2087 constraints: cfa_store.reg == sp
2088 effects: current_fde.stack_realign = 1
2089 cfa_store.offset = 0
2090 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2093 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2094 effects: cfa_store.offset += -/+ mode_size(mem)
2097 (set (mem ({pre_inc, pre_dec} sp)) fp)
2098 constraints: fde->stack_realign == 1
2099 effects: cfa_store.offset = 0
2100 cfa.reg != HARD_FRAME_POINTER_REGNUM
2103 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2104 constraints: fde->stack_realign == 1
2106 && cfa.indirect == 0
2107 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2108 effects: Use DW_CFA_def_cfa_expression to define cfa
2109 cfa.reg == fde->drap_reg
2112 (set reg fde->drap_reg)
2113 constraints: fde->vdrap_reg == INVALID_REGNUM
2114 effects: fde->vdrap_reg = reg.
2115 (set mem fde->drap_reg)
2116 constraints: fde->drap_reg_saved == 1
2120 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
2122 rtx src
, dest
, span
;
2123 HOST_WIDE_INT offset
;
2126 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2127 the PARALLEL independently. The first element is always processed if
2128 it is a SET. This is for backward compatibility. Other elements
2129 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2130 flag is set in them. */
2131 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
2134 int limit
= XVECLEN (expr
, 0);
2137 /* PARALLELs have strict read-modify-write semantics, so we
2138 ought to evaluate every rvalue before changing any lvalue.
2139 It's cumbersome to do that in general, but there's an
2140 easy approximation that is enough for all current users:
2141 handle register saves before register assignments. */
2142 if (GET_CODE (expr
) == PARALLEL
)
2143 for (par_index
= 0; par_index
< limit
; par_index
++)
2145 elem
= XVECEXP (expr
, 0, par_index
);
2146 if (GET_CODE (elem
) == SET
2147 && MEM_P (SET_DEST (elem
))
2148 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2149 dwarf2out_frame_debug_expr (elem
, label
);
2152 for (par_index
= 0; par_index
< limit
; par_index
++)
2154 elem
= XVECEXP (expr
, 0, par_index
);
2155 if (GET_CODE (elem
) == SET
2156 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
2157 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
2158 dwarf2out_frame_debug_expr (elem
, label
);
2159 else if (GET_CODE (elem
) == SET
2161 && !RTX_FRAME_RELATED_P (elem
))
2163 /* Stack adjustment combining might combine some post-prologue
2164 stack adjustment into a prologue stack adjustment. */
2165 HOST_WIDE_INT offset
= stack_adjust_offset (elem
, args_size
, 0);
2168 dwarf2out_args_size_adjust (offset
, label
);
2174 gcc_assert (GET_CODE (expr
) == SET
);
2176 src
= SET_SRC (expr
);
2177 dest
= SET_DEST (expr
);
2181 rtx rsi
= reg_saved_in (src
);
2186 fde
= current_fde ();
2190 && fde
->drap_reg
== REGNO (src
)
2191 && (fde
->drap_reg_saved
2195 /* If we are saving dynamic realign argument pointer to a
2196 register, the destination is virtual dynamic realign
2197 argument pointer. It may be used to access argument. */
2200 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2201 fde
->vdrap_reg
= REGNO (dest
);
2206 switch (GET_CODE (dest
))
2209 switch (GET_CODE (src
))
2211 /* Setting FP from SP. */
2213 if (cfa
.reg
== (unsigned) REGNO (src
))
2216 /* Update the CFA rule wrt SP or FP. Make sure src is
2217 relative to the current CFA register.
2219 We used to require that dest be either SP or FP, but the
2220 ARM copies SP to a temporary register, and from there to
2221 FP. So we just rely on the backends to only set
2222 RTX_FRAME_RELATED_P on appropriate insns. */
2223 cfa
.reg
= REGNO (dest
);
2224 cfa_temp
.reg
= cfa
.reg
;
2225 cfa_temp
.offset
= cfa
.offset
;
2229 /* Saving a register in a register. */
2230 gcc_assert (!fixed_regs
[REGNO (dest
)]
2231 /* For the SPARC and its register window. */
2232 || (DWARF_FRAME_REGNUM (REGNO (src
))
2233 == DWARF_FRAME_RETURN_COLUMN
));
2235 /* After stack is aligned, we can only save SP in FP
2236 if drap register is used. In this case, we have
2237 to restore stack pointer with the CFA value and we
2238 don't generate this DWARF information. */
2240 && fde
->stack_realign
2241 && REGNO (src
) == STACK_POINTER_REGNUM
)
2242 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
2243 && fde
->drap_reg
!= INVALID_REGNUM
2244 && cfa
.reg
!= REGNO (src
));
2246 queue_reg_save (label
, src
, dest
, 0);
2253 if (dest
== stack_pointer_rtx
)
2257 switch (GET_CODE (XEXP (src
, 1)))
2260 offset
= INTVAL (XEXP (src
, 1));
2263 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
2265 offset
= cfa_temp
.offset
;
2271 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
2273 /* Restoring SP from FP in the epilogue. */
2274 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
2275 cfa
.reg
= STACK_POINTER_REGNUM
;
2277 else if (GET_CODE (src
) == LO_SUM
)
2278 /* Assume we've set the source reg of the LO_SUM from sp. */
2281 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
2283 if (GET_CODE (src
) != MINUS
)
2285 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2286 cfa
.offset
+= offset
;
2287 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
2288 cfa_store
.offset
+= offset
;
2290 else if (dest
== hard_frame_pointer_rtx
)
2293 /* Either setting the FP from an offset of the SP,
2294 or adjusting the FP */
2295 gcc_assert (frame_pointer_needed
);
2297 gcc_assert (REG_P (XEXP (src
, 0))
2298 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
2299 && CONST_INT_P (XEXP (src
, 1)));
2300 offset
= INTVAL (XEXP (src
, 1));
2301 if (GET_CODE (src
) != MINUS
)
2303 cfa
.offset
+= offset
;
2304 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
2308 gcc_assert (GET_CODE (src
) != MINUS
);
2311 if (REG_P (XEXP (src
, 0))
2312 && REGNO (XEXP (src
, 0)) == cfa
.reg
2313 && CONST_INT_P (XEXP (src
, 1)))
2315 /* Setting a temporary CFA register that will be copied
2316 into the FP later on. */
2317 offset
= - INTVAL (XEXP (src
, 1));
2318 cfa
.offset
+= offset
;
2319 cfa
.reg
= REGNO (dest
);
2320 /* Or used to save regs to the stack. */
2321 cfa_temp
.reg
= cfa
.reg
;
2322 cfa_temp
.offset
= cfa
.offset
;
2326 else if (REG_P (XEXP (src
, 0))
2327 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2328 && XEXP (src
, 1) == stack_pointer_rtx
)
2330 /* Setting a scratch register that we will use instead
2331 of SP for saving registers to the stack. */
2332 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2333 cfa_store
.reg
= REGNO (dest
);
2334 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2338 else if (GET_CODE (src
) == LO_SUM
2339 && CONST_INT_P (XEXP (src
, 1)))
2341 cfa_temp
.reg
= REGNO (dest
);
2342 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2351 cfa_temp
.reg
= REGNO (dest
);
2352 cfa_temp
.offset
= INTVAL (src
);
2357 gcc_assert (REG_P (XEXP (src
, 0))
2358 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2359 && CONST_INT_P (XEXP (src
, 1)));
2361 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2362 cfa_temp
.reg
= REGNO (dest
);
2363 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2366 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2367 which will fill in all of the bits. */
2374 case UNSPEC_VOLATILE
:
2375 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2376 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2381 /* If this AND operation happens on stack pointer in prologue,
2382 we assume the stack is realigned and we extract the
2384 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2386 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2387 fde
->stack_realign
= 1;
2388 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2389 cfa_store
.offset
= 0;
2391 if (cfa
.reg
!= STACK_POINTER_REGNUM
2392 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2393 fde
->drap_reg
= cfa
.reg
;
2401 def_cfa_1 (label
, &cfa
);
2406 /* Saving a register to the stack. Make sure dest is relative to the
2408 switch (GET_CODE (XEXP (dest
, 0)))
2413 /* We can't handle variable size modifications. */
2414 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2416 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2418 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2419 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2421 cfa_store
.offset
+= offset
;
2422 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2423 cfa
.offset
= cfa_store
.offset
;
2425 offset
= -cfa_store
.offset
;
2431 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2432 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2435 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2436 == STACK_POINTER_REGNUM
)
2437 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2439 cfa_store
.offset
+= offset
;
2441 /* Rule 18: If stack is aligned, we will use FP as a
2442 reference to represent the address of the stored
2445 && fde
->stack_realign
2446 && src
== hard_frame_pointer_rtx
)
2448 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2449 cfa_store
.offset
= 0;
2452 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2453 cfa
.offset
= cfa_store
.offset
;
2455 offset
= -cfa_store
.offset
;
2459 /* With an offset. */
2466 gcc_assert (CONST_INT_P (XEXP (XEXP (dest
, 0), 1))
2467 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2468 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2469 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2472 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2474 if (cfa_store
.reg
== (unsigned) regno
)
2475 offset
-= cfa_store
.offset
;
2478 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2479 offset
-= cfa_temp
.offset
;
2485 /* Without an offset. */
2488 int regno
= REGNO (XEXP (dest
, 0));
2490 if (cfa_store
.reg
== (unsigned) regno
)
2491 offset
= -cfa_store
.offset
;
2494 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2495 offset
= -cfa_temp
.offset
;
2502 gcc_assert (cfa_temp
.reg
2503 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2504 offset
= -cfa_temp
.offset
;
2505 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2513 /* If the source operand of this MEM operation is not a
2514 register, basically the source is return address. Here
2515 we only care how much stack grew and we don't save it. */
2519 if (REGNO (src
) != STACK_POINTER_REGNUM
2520 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2521 && (unsigned) REGNO (src
) == cfa
.reg
)
2523 /* We're storing the current CFA reg into the stack. */
2525 if (cfa
.offset
== 0)
2528 /* If stack is aligned, putting CFA reg into stack means
2529 we can no longer use reg + offset to represent CFA.
2530 Here we use DW_CFA_def_cfa_expression instead. The
2531 result of this expression equals to the original CFA
2534 && fde
->stack_realign
2535 && cfa
.indirect
== 0
2536 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2538 dw_cfa_location cfa_exp
;
2540 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2542 cfa_exp
.indirect
= 1;
2543 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2544 cfa_exp
.base_offset
= offset
;
2547 fde
->drap_reg_saved
= 1;
2549 def_cfa_1 (label
, &cfa_exp
);
2553 /* If the source register is exactly the CFA, assume
2554 we're saving SP like any other register; this happens
2556 def_cfa_1 (label
, &cfa
);
2557 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2562 /* Otherwise, we'll need to look in the stack to
2563 calculate the CFA. */
2564 rtx x
= XEXP (dest
, 0);
2568 gcc_assert (REG_P (x
));
2570 cfa
.reg
= REGNO (x
);
2571 cfa
.base_offset
= offset
;
2573 def_cfa_1 (label
, &cfa
);
2578 def_cfa_1 (label
, &cfa
);
2580 span
= targetm
.dwarf_register_span (src
);
2583 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2586 /* We have a PARALLEL describing where the contents of SRC
2587 live. Queue register saves for each piece of the
2591 HOST_WIDE_INT span_offset
= offset
;
2593 gcc_assert (GET_CODE (span
) == PARALLEL
);
2595 limit
= XVECLEN (span
, 0);
2596 for (par_index
= 0; par_index
< limit
; par_index
++)
2598 rtx elem
= XVECEXP (span
, 0, par_index
);
2600 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2601 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2612 /* Record call frame debugging information for INSN, which either
2613 sets SP or FP (adjusting how we calculate the frame address) or saves a
2614 register to the stack. If INSN is NULL_RTX, initialize our state.
2616 If AFTER_P is false, we're being called before the insn is emitted,
2617 otherwise after. Call instructions get invoked twice. */
2620 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2624 bool handled_one
= false;
2626 if (insn
== NULL_RTX
)
2630 /* Flush any queued register saves. */
2631 flush_queued_reg_saves ();
2633 /* Set up state for generating call frame debug info. */
2636 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2638 cfa
.reg
= STACK_POINTER_REGNUM
;
2641 cfa_temp
.offset
= 0;
2643 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2645 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2646 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2648 num_regs_saved_in_regs
= 0;
2650 if (barrier_args_size
)
2652 XDELETEVEC (barrier_args_size
);
2653 barrier_args_size
= NULL
;
2658 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2659 flush_queued_reg_saves ();
2661 if (! RTX_FRAME_RELATED_P (insn
))
2663 if (!ACCUMULATE_OUTGOING_ARGS
)
2664 dwarf2out_stack_adjust (insn
, after_p
);
2668 label
= dwarf2out_cfi_label (false);
2670 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2671 switch (REG_NOTE_KIND (note
))
2673 case REG_FRAME_RELATED_EXPR
:
2674 insn
= XEXP (note
, 0);
2677 case REG_CFA_DEF_CFA
:
2678 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0), label
);
2682 case REG_CFA_ADJUST_CFA
:
2687 if (GET_CODE (n
) == PARALLEL
)
2688 n
= XVECEXP (n
, 0, 0);
2690 dwarf2out_frame_debug_adjust_cfa (n
, label
);
2694 case REG_CFA_OFFSET
:
2697 n
= single_set (insn
);
2698 dwarf2out_frame_debug_cfa_offset (n
, label
);
2702 case REG_CFA_REGISTER
:
2707 if (GET_CODE (n
) == PARALLEL
)
2708 n
= XVECEXP (n
, 0, 0);
2710 dwarf2out_frame_debug_cfa_register (n
, label
);
2714 case REG_CFA_RESTORE
:
2719 if (GET_CODE (n
) == PARALLEL
)
2720 n
= XVECEXP (n
, 0, 0);
2723 dwarf2out_frame_debug_cfa_restore (n
, label
);
2733 insn
= PATTERN (insn
);
2735 dwarf2out_frame_debug_expr (insn
, label
);
2738 /* Determine if we need to save and restore CFI information around this
2739 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2740 we do need to save/restore, then emit the save now, and insert a
2741 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2744 dwarf2out_begin_epilogue (rtx insn
)
2746 bool saw_frp
= false;
2749 /* Scan forward to the return insn, noticing if there are possible
2750 frame related insns. */
2751 for (i
= NEXT_INSN (insn
); i
; i
= NEXT_INSN (i
))
2756 /* Look for both regular and sibcalls to end the block. */
2757 if (returnjump_p (i
))
2759 if (CALL_P (i
) && SIBLING_CALL_P (i
))
2762 if (GET_CODE (PATTERN (i
)) == SEQUENCE
)
2765 rtx seq
= PATTERN (i
);
2767 if (returnjump_p (XVECEXP (seq
, 0, 0)))
2769 if (CALL_P (XVECEXP (seq
, 0, 0))
2770 && SIBLING_CALL_P (XVECEXP (seq
, 0, 0)))
2773 for (idx
= 0; idx
< XVECLEN (seq
, 0); idx
++)
2774 if (RTX_FRAME_RELATED_P (XVECEXP (seq
, 0, idx
)))
2778 if (RTX_FRAME_RELATED_P (i
))
2782 /* If the port doesn't emit epilogue unwind info, we don't need a
2783 save/restore pair. */
2787 /* Otherwise, search forward to see if the return insn was the last
2788 basic block of the function. If so, we don't need save/restore. */
2789 gcc_assert (i
!= NULL
);
2790 i
= next_real_insn (i
);
2794 /* Insert the restore before that next real insn in the stream, and before
2795 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2796 properly nested. This should be after any label or alignment. This
2797 will be pushed into the CFI stream by the function below. */
2800 rtx p
= PREV_INSN (i
);
2803 if (NOTE_KIND (p
) == NOTE_INSN_BASIC_BLOCK
)
2807 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE
, i
);
2809 emit_cfa_remember
= true;
2811 /* And emulate the state save. */
2812 gcc_assert (!cfa_remember
.in_use
);
2814 cfa_remember
.in_use
= 1;
2817 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2820 dwarf2out_frame_debug_restore_state (void)
2822 dw_cfi_ref cfi
= new_cfi ();
2823 const char *label
= dwarf2out_cfi_label (false);
2825 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
2826 add_fde_cfi (label
, cfi
);
2828 gcc_assert (cfa_remember
.in_use
);
2830 cfa_remember
.in_use
= 0;
2835 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2836 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2837 (enum dwarf_call_frame_info cfi
);
2839 static enum dw_cfi_oprnd_type
2840 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2845 case DW_CFA_GNU_window_save
:
2846 case DW_CFA_remember_state
:
2847 case DW_CFA_restore_state
:
2848 return dw_cfi_oprnd_unused
;
2850 case DW_CFA_set_loc
:
2851 case DW_CFA_advance_loc1
:
2852 case DW_CFA_advance_loc2
:
2853 case DW_CFA_advance_loc4
:
2854 case DW_CFA_MIPS_advance_loc8
:
2855 return dw_cfi_oprnd_addr
;
2858 case DW_CFA_offset_extended
:
2859 case DW_CFA_def_cfa
:
2860 case DW_CFA_offset_extended_sf
:
2861 case DW_CFA_def_cfa_sf
:
2862 case DW_CFA_restore
:
2863 case DW_CFA_restore_extended
:
2864 case DW_CFA_undefined
:
2865 case DW_CFA_same_value
:
2866 case DW_CFA_def_cfa_register
:
2867 case DW_CFA_register
:
2868 return dw_cfi_oprnd_reg_num
;
2870 case DW_CFA_def_cfa_offset
:
2871 case DW_CFA_GNU_args_size
:
2872 case DW_CFA_def_cfa_offset_sf
:
2873 return dw_cfi_oprnd_offset
;
2875 case DW_CFA_def_cfa_expression
:
2876 case DW_CFA_expression
:
2877 return dw_cfi_oprnd_loc
;
2884 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2885 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2886 (enum dwarf_call_frame_info cfi
);
2888 static enum dw_cfi_oprnd_type
2889 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2893 case DW_CFA_def_cfa
:
2894 case DW_CFA_def_cfa_sf
:
2896 case DW_CFA_offset_extended_sf
:
2897 case DW_CFA_offset_extended
:
2898 return dw_cfi_oprnd_offset
;
2900 case DW_CFA_register
:
2901 return dw_cfi_oprnd_reg_num
;
2904 return dw_cfi_oprnd_unused
;
2908 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2910 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2911 switch to the data section instead, and write out a synthetic label
2915 switch_to_eh_frame_section (void)
2919 #ifdef EH_FRAME_SECTION_NAME
2920 if (eh_frame_section
== 0)
2924 if (EH_TABLES_CAN_BE_READ_ONLY
)
2930 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2932 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2934 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2936 flags
= ((! flag_pic
2937 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2938 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2939 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2940 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2941 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2942 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2943 ? 0 : SECTION_WRITE
);
2946 flags
= SECTION_WRITE
;
2947 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2951 if (eh_frame_section
)
2952 switch_to_section (eh_frame_section
);
2955 /* We have no special eh_frame section. Put the information in
2956 the data section and emit special labels to guide collect2. */
2957 switch_to_section (data_section
);
2958 label
= get_file_function_name ("F");
2959 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2960 targetm
.asm_out
.globalize_label (asm_out_file
,
2961 IDENTIFIER_POINTER (label
));
2962 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2966 /* Output a Call Frame Information opcode and its operand(s). */
2969 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2974 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2975 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2976 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2977 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2978 ((unsigned HOST_WIDE_INT
)
2979 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
2980 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2982 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2983 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2984 "DW_CFA_offset, column 0x%lx", r
);
2985 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
2986 dw2_asm_output_data_uleb128 (off
, NULL
);
2988 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2990 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2991 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2992 "DW_CFA_restore, column 0x%lx", r
);
2996 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2997 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2999 switch (cfi
->dw_cfi_opc
)
3001 case DW_CFA_set_loc
:
3003 dw2_asm_output_encoded_addr_rtx (
3004 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3005 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3008 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3009 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3010 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3013 case DW_CFA_advance_loc1
:
3014 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3015 fde
->dw_fde_current_label
, NULL
);
3016 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3019 case DW_CFA_advance_loc2
:
3020 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3021 fde
->dw_fde_current_label
, NULL
);
3022 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3025 case DW_CFA_advance_loc4
:
3026 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3027 fde
->dw_fde_current_label
, NULL
);
3028 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3031 case DW_CFA_MIPS_advance_loc8
:
3032 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3033 fde
->dw_fde_current_label
, NULL
);
3034 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3037 case DW_CFA_offset_extended
:
3038 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3039 dw2_asm_output_data_uleb128 (r
, NULL
);
3040 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3041 dw2_asm_output_data_uleb128 (off
, NULL
);
3044 case DW_CFA_def_cfa
:
3045 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3046 dw2_asm_output_data_uleb128 (r
, NULL
);
3047 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3050 case DW_CFA_offset_extended_sf
:
3051 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3052 dw2_asm_output_data_uleb128 (r
, NULL
);
3053 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3054 dw2_asm_output_data_sleb128 (off
, NULL
);
3057 case DW_CFA_def_cfa_sf
:
3058 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3059 dw2_asm_output_data_uleb128 (r
, NULL
);
3060 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3061 dw2_asm_output_data_sleb128 (off
, NULL
);
3064 case DW_CFA_restore_extended
:
3065 case DW_CFA_undefined
:
3066 case DW_CFA_same_value
:
3067 case DW_CFA_def_cfa_register
:
3068 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3069 dw2_asm_output_data_uleb128 (r
, NULL
);
3072 case DW_CFA_register
:
3073 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3074 dw2_asm_output_data_uleb128 (r
, NULL
);
3075 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3076 dw2_asm_output_data_uleb128 (r
, NULL
);
3079 case DW_CFA_def_cfa_offset
:
3080 case DW_CFA_GNU_args_size
:
3081 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3084 case DW_CFA_def_cfa_offset_sf
:
3085 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3086 dw2_asm_output_data_sleb128 (off
, NULL
);
3089 case DW_CFA_GNU_window_save
:
3092 case DW_CFA_def_cfa_expression
:
3093 case DW_CFA_expression
:
3094 output_cfa_loc (cfi
);
3097 case DW_CFA_GNU_negative_offset_extended
:
3098 /* Obsoleted by DW_CFA_offset_extended_sf. */
3107 /* Similar, but do it via assembler directives instead. */
3110 output_cfi_directive (dw_cfi_ref cfi
)
3112 unsigned long r
, r2
;
3114 switch (cfi
->dw_cfi_opc
)
3116 case DW_CFA_advance_loc
:
3117 case DW_CFA_advance_loc1
:
3118 case DW_CFA_advance_loc2
:
3119 case DW_CFA_advance_loc4
:
3120 case DW_CFA_MIPS_advance_loc8
:
3121 case DW_CFA_set_loc
:
3122 /* Should only be created by add_fde_cfi in a code path not
3123 followed when emitting via directives. The assembler is
3124 going to take care of this for us. */
3128 case DW_CFA_offset_extended
:
3129 case DW_CFA_offset_extended_sf
:
3130 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3131 fprintf (asm_out_file
, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3132 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3135 case DW_CFA_restore
:
3136 case DW_CFA_restore_extended
:
3137 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3138 fprintf (asm_out_file
, "\t.cfi_restore %lu\n", r
);
3141 case DW_CFA_undefined
:
3142 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3143 fprintf (asm_out_file
, "\t.cfi_undefined %lu\n", r
);
3146 case DW_CFA_same_value
:
3147 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3148 fprintf (asm_out_file
, "\t.cfi_same_value %lu\n", r
);
3151 case DW_CFA_def_cfa
:
3152 case DW_CFA_def_cfa_sf
:
3153 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3154 fprintf (asm_out_file
, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC
"\n",
3155 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3158 case DW_CFA_def_cfa_register
:
3159 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3160 fprintf (asm_out_file
, "\t.cfi_def_cfa_register %lu\n", r
);
3163 case DW_CFA_register
:
3164 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3165 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3166 fprintf (asm_out_file
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3169 case DW_CFA_def_cfa_offset
:
3170 case DW_CFA_def_cfa_offset_sf
:
3171 fprintf (asm_out_file
, "\t.cfi_def_cfa_offset "
3172 HOST_WIDE_INT_PRINT_DEC
"\n",
3173 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3176 case DW_CFA_remember_state
:
3177 fprintf (asm_out_file
, "\t.cfi_remember_state\n");
3179 case DW_CFA_restore_state
:
3180 fprintf (asm_out_file
, "\t.cfi_restore_state\n");
3183 case DW_CFA_GNU_args_size
:
3184 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size
);
3185 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3187 fprintf (asm_out_file
, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC
,
3188 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3189 fputc ('\n', asm_out_file
);
3192 case DW_CFA_GNU_window_save
:
3193 fprintf (asm_out_file
, "\t.cfi_window_save\n");
3196 case DW_CFA_def_cfa_expression
:
3197 case DW_CFA_expression
:
3198 fprintf (asm_out_file
, "\t.cfi_escape 0x%x,", cfi
->dw_cfi_opc
);
3199 output_cfa_loc_raw (cfi
);
3200 fputc ('\n', asm_out_file
);
3208 /* Output the call frame information used to record information
3209 that relates to calculating the frame pointer, and records the
3210 location of saved registers. */
3213 output_call_frame_info (int for_eh
)
3218 char l1
[20], l2
[20], section_start_label
[20];
3219 bool any_lsda_needed
= false;
3220 char augmentation
[6];
3221 int augmentation_size
;
3222 int fde_encoding
= DW_EH_PE_absptr
;
3223 int per_encoding
= DW_EH_PE_absptr
;
3224 int lsda_encoding
= DW_EH_PE_absptr
;
3228 /* Don't emit a CIE if there won't be any FDEs. */
3229 if (fde_table_in_use
== 0)
3232 /* Nothing to do if the assembler's doing it all. */
3233 if (dwarf2out_do_cfi_asm ())
3236 /* If we make FDEs linkonce, we may have to emit an empty label for
3237 an FDE that wouldn't otherwise be emitted. We want to avoid
3238 having an FDE kept around when the function it refers to is
3239 discarded. Example where this matters: a primary function
3240 template in C++ requires EH information, but an explicit
3241 specialization doesn't. */
3242 if (TARGET_USES_WEAK_UNWIND_INFO
3243 && ! flag_asynchronous_unwind_tables
3246 for (i
= 0; i
< fde_table_in_use
; i
++)
3247 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
3248 && !fde_table
[i
].uses_eh_lsda
3249 && ! DECL_WEAK (fde_table
[i
].decl
))
3250 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
3251 for_eh
, /* empty */ 1);
3253 /* If we don't have any functions we'll want to unwind out of, don't
3254 emit any EH unwind information. Note that if exceptions aren't
3255 enabled, we won't have collected nothrow information, and if we
3256 asked for asynchronous tables, we always want this info. */
3259 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
3261 for (i
= 0; i
< fde_table_in_use
; i
++)
3262 if (fde_table
[i
].uses_eh_lsda
)
3263 any_eh_needed
= any_lsda_needed
= true;
3264 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
3265 any_eh_needed
= true;
3266 else if (! fde_table
[i
].nothrow
3267 && ! fde_table
[i
].all_throwers_are_sibcalls
)
3268 any_eh_needed
= true;
3270 if (! any_eh_needed
)
3274 /* We're going to be generating comments, so turn on app. */
3279 switch_to_eh_frame_section ();
3282 if (!debug_frame_section
)
3283 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
3284 SECTION_DEBUG
, NULL
);
3285 switch_to_section (debug_frame_section
);
3288 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
3289 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
3291 /* Output the CIE. */
3292 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
3293 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
3294 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3295 dw2_asm_output_data (4, 0xffffffff,
3296 "Initial length escape value indicating 64-bit DWARF extension");
3297 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3298 "Length of Common Information Entry");
3299 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3301 /* Now that the CIE pointer is PC-relative for EH,
3302 use 0 to identify the CIE. */
3303 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
3304 (for_eh
? 0 : DWARF_CIE_ID
),
3305 "CIE Identifier Tag");
3307 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3308 use CIE version 1, unless that would produce incorrect results
3309 due to overflowing the return register column. */
3310 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
3312 if (return_reg
>= 256 || dwarf_version
> 2)
3314 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
3316 augmentation
[0] = 0;
3317 augmentation_size
= 0;
3323 z Indicates that a uleb128 is present to size the
3324 augmentation section.
3325 L Indicates the encoding (and thus presence) of
3326 an LSDA pointer in the FDE augmentation.
3327 R Indicates a non-default pointer encoding for
3329 P Indicates the presence of an encoding + language
3330 personality routine in the CIE augmentation. */
3332 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3333 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3334 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3336 p
= augmentation
+ 1;
3337 if (eh_personality_libfunc
)
3340 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
3341 assemble_external_libcall (eh_personality_libfunc
);
3343 if (any_lsda_needed
)
3346 augmentation_size
+= 1;
3348 if (fde_encoding
!= DW_EH_PE_absptr
)
3351 augmentation_size
+= 1;
3353 if (p
> augmentation
+ 1)
3355 augmentation
[0] = 'z';
3359 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3360 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
3362 int offset
= ( 4 /* Length */
3364 + 1 /* CIE version */
3365 + strlen (augmentation
) + 1 /* Augmentation */
3366 + size_of_uleb128 (1) /* Code alignment */
3367 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
3369 + 1 /* Augmentation size */
3370 + 1 /* Personality encoding */ );
3371 int pad
= -offset
& (PTR_SIZE
- 1);
3373 augmentation_size
+= pad
;
3375 /* Augmentations should be small, so there's scarce need to
3376 iterate for a solution. Die if we exceed one uleb128 byte. */
3377 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
3381 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
3382 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3383 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
3384 "CIE Data Alignment Factor");
3386 if (dw_cie_version
== 1)
3387 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
3389 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
3391 if (augmentation
[0])
3393 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
3394 if (eh_personality_libfunc
)
3396 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
3397 eh_data_format_name (per_encoding
));
3398 dw2_asm_output_encoded_addr_rtx (per_encoding
,
3399 eh_personality_libfunc
,
3403 if (any_lsda_needed
)
3404 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
3405 eh_data_format_name (lsda_encoding
));
3407 if (fde_encoding
!= DW_EH_PE_absptr
)
3408 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
3409 eh_data_format_name (fde_encoding
));
3412 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3413 output_cfi (cfi
, NULL
, for_eh
);
3415 /* Pad the CIE out to an address sized boundary. */
3416 ASM_OUTPUT_ALIGN (asm_out_file
,
3417 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
3418 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3420 /* Loop through all of the FDE's. */
3421 for (i
= 0; i
< fde_table_in_use
; i
++)
3423 fde
= &fde_table
[i
];
3425 /* Don't emit EH unwind info for leaf functions that don't need it. */
3426 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
3427 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
3428 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
3429 && !fde
->uses_eh_lsda
)
3432 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
3433 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
3434 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
3435 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
3436 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
3437 dw2_asm_output_data (4, 0xffffffff,
3438 "Initial length escape value indicating 64-bit DWARF extension");
3439 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
3441 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
3444 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
3446 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
3447 debug_frame_section
, "FDE CIE offset");
3451 if (fde
->dw_fde_switched_sections
)
3453 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
3454 fde
->dw_fde_unlikely_section_label
);
3455 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
3456 fde
->dw_fde_hot_section_label
);
3457 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
3458 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
3459 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
3460 "FDE initial location");
3461 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3462 fde
->dw_fde_hot_section_end_label
,
3463 fde
->dw_fde_hot_section_label
,
3464 "FDE address range");
3465 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
3466 "FDE initial location");
3467 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3468 fde
->dw_fde_unlikely_section_end_label
,
3469 fde
->dw_fde_unlikely_section_label
,
3470 "FDE address range");
3474 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
3475 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
3476 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
3479 "FDE initial location");
3480 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
3481 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3482 "FDE address range");
3487 if (fde
->dw_fde_switched_sections
)
3489 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3490 fde
->dw_fde_hot_section_label
,
3491 "FDE initial location");
3492 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3493 fde
->dw_fde_hot_section_end_label
,
3494 fde
->dw_fde_hot_section_label
,
3495 "FDE address range");
3496 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3497 fde
->dw_fde_unlikely_section_label
,
3498 "FDE initial location");
3499 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3500 fde
->dw_fde_unlikely_section_end_label
,
3501 fde
->dw_fde_unlikely_section_label
,
3502 "FDE address range");
3506 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
3507 "FDE initial location");
3508 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
3509 fde
->dw_fde_end
, fde
->dw_fde_begin
,
3510 "FDE address range");
3514 if (augmentation
[0])
3516 if (any_lsda_needed
)
3518 int size
= size_of_encoded_value (lsda_encoding
);
3520 if (lsda_encoding
== DW_EH_PE_aligned
)
3522 int offset
= ( 4 /* Length */
3523 + 4 /* CIE offset */
3524 + 2 * size_of_encoded_value (fde_encoding
)
3525 + 1 /* Augmentation size */ );
3526 int pad
= -offset
& (PTR_SIZE
- 1);
3529 gcc_assert (size_of_uleb128 (size
) == 1);
3532 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
3534 if (fde
->uses_eh_lsda
)
3536 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
3537 fde
->funcdef_number
);
3538 dw2_asm_output_encoded_addr_rtx (
3539 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
3540 false, "Language Specific Data Area");
3544 if (lsda_encoding
== DW_EH_PE_aligned
)
3545 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
3547 (size_of_encoded_value (lsda_encoding
), 0,
3548 "Language Specific Data Area (none)");
3552 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3555 /* Loop through the Call Frame Instructions associated with
3557 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
3558 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3559 output_cfi (cfi
, fde
, for_eh
);
3561 /* Pad the FDE out to an address sized boundary. */
3562 ASM_OUTPUT_ALIGN (asm_out_file
,
3563 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
3564 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
3567 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
3568 dw2_asm_output_data (4, 0, "End of Table");
3569 #ifdef MIPS_DEBUGGING_INFO
3570 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3571 get a value of 0. Putting .align 0 after the label fixes it. */
3572 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
3575 /* Turn off app to make assembly quicker. */
3580 /* Output a marker (i.e. a label) for the beginning of a function, before
3584 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
3585 const char *file ATTRIBUTE_UNUSED
)
3587 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3591 current_function_func_begin_label
= NULL
;
3593 #ifdef TARGET_UNWIND_INFO
3594 /* ??? current_function_func_begin_label is also used by except.c
3595 for call-site information. We must emit this label if it might
3597 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
3598 && ! dwarf2out_do_frame ())
3601 if (! dwarf2out_do_frame ())
3605 switch_to_section (function_section (current_function_decl
));
3606 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
3607 current_function_funcdef_no
);
3608 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
3609 current_function_funcdef_no
);
3610 dup_label
= xstrdup (label
);
3611 current_function_func_begin_label
= dup_label
;
3613 #ifdef TARGET_UNWIND_INFO
3614 /* We can elide the fde allocation if we're not emitting debug info. */
3615 if (! dwarf2out_do_frame ())
3619 /* Expand the fde table if necessary. */
3620 if (fde_table_in_use
== fde_table_allocated
)
3622 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
3623 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
3624 memset (fde_table
+ fde_table_in_use
, 0,
3625 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
3628 /* Record the FDE associated with this function. */
3629 current_funcdef_fde
= fde_table_in_use
;
3631 /* Add the new FDE at the end of the fde_table. */
3632 fde
= &fde_table
[fde_table_in_use
++];
3633 fde
->decl
= current_function_decl
;
3634 fde
->dw_fde_begin
= dup_label
;
3635 fde
->dw_fde_current_label
= dup_label
;
3636 fde
->dw_fde_hot_section_label
= NULL
;
3637 fde
->dw_fde_hot_section_end_label
= NULL
;
3638 fde
->dw_fde_unlikely_section_label
= NULL
;
3639 fde
->dw_fde_unlikely_section_end_label
= NULL
;
3640 fde
->dw_fde_switched_sections
= false;
3641 fde
->dw_fde_end
= NULL
;
3642 fde
->dw_fde_cfi
= NULL
;
3643 fde
->funcdef_number
= current_function_funcdef_no
;
3644 fde
->nothrow
= crtl
->nothrow
;
3645 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
3646 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
3647 fde
->drap_reg
= INVALID_REGNUM
;
3648 fde
->vdrap_reg
= INVALID_REGNUM
;
3650 args_size
= old_args_size
= 0;
3652 /* We only want to output line number information for the genuine dwarf2
3653 prologue case, not the eh frame case. */
3654 #ifdef DWARF2_DEBUGGING_INFO
3656 dwarf2out_source_line (line
, file
, 0, true);
3659 if (dwarf2out_do_cfi_asm ())
3664 fprintf (asm_out_file
, "\t.cfi_startproc\n");
3666 if (eh_personality_libfunc
)
3668 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3669 ref
= eh_personality_libfunc
;
3671 /* ??? The GAS support isn't entirely consistent. We have to
3672 handle indirect support ourselves, but PC-relative is done
3673 in the assembler. Further, the assembler can't handle any
3674 of the weirder relocation types. */
3675 if (enc
& DW_EH_PE_indirect
)
3676 ref
= dw2_force_const_mem (ref
, true);
3678 fprintf (asm_out_file
, "\t.cfi_personality 0x%x,", enc
);
3679 output_addr_const (asm_out_file
, ref
);
3680 fputc ('\n', asm_out_file
);
3683 if (crtl
->uses_eh_lsda
)
3687 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3688 ASM_GENERATE_INTERNAL_LABEL (lab
, "LLSDA",
3689 current_function_funcdef_no
);
3690 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
3691 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
3693 if (enc
& DW_EH_PE_indirect
)
3694 ref
= dw2_force_const_mem (ref
, true);
3696 fprintf (asm_out_file
, "\t.cfi_lsda 0x%x,", enc
);
3697 output_addr_const (asm_out_file
, ref
);
3698 fputc ('\n', asm_out_file
);
3703 /* Output a marker (i.e. a label) for the absolute end of the generated code
3704 for a function definition. This gets called *after* the epilogue code has
3708 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
3709 const char *file ATTRIBUTE_UNUSED
)
3712 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3714 #ifdef DWARF2_DEBUGGING_INFO
3715 last_var_location_insn
= NULL_RTX
;
3718 if (dwarf2out_do_cfi_asm ())
3719 fprintf (asm_out_file
, "\t.cfi_endproc\n");
3721 /* Output a label to mark the endpoint of the code generated for this
3723 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
3724 current_function_funcdef_no
);
3725 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3726 fde
= current_fde ();
3727 gcc_assert (fde
!= NULL
);
3728 fde
->dw_fde_end
= xstrdup (label
);
3732 dwarf2out_frame_init (void)
3734 /* Allocate the initial hunk of the fde_table. */
3735 fde_table
= GGC_CNEWVEC (dw_fde_node
, FDE_TABLE_INCREMENT
);
3736 fde_table_allocated
= FDE_TABLE_INCREMENT
;
3737 fde_table_in_use
= 0;
3739 /* Generate the CFA instructions common to all FDE's. Do it now for the
3740 sake of lookup_cfa. */
3742 /* On entry, the Canonical Frame Address is at SP. */
3743 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
3745 #ifdef DWARF2_UNWIND_INFO
3746 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
3747 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
3752 dwarf2out_frame_finish (void)
3754 /* Output call frame information. */
3755 if (DWARF2_FRAME_INFO
)
3756 output_call_frame_info (0);
3758 #ifndef TARGET_UNWIND_INFO
3759 /* Output another copy for the unwinder. */
3760 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
3761 output_call_frame_info (1);
3765 /* Note that the current function section is being used for code. */
3768 dwarf2out_note_section_used (void)
3770 section
*sec
= current_function_section ();
3771 if (sec
== text_section
)
3772 text_section_used
= true;
3773 else if (sec
== cold_text_section
)
3774 cold_text_section_used
= true;
3778 dwarf2out_switch_text_section (void)
3780 dw_fde_ref fde
= current_fde ();
3782 gcc_assert (cfun
&& fde
);
3784 fde
->dw_fde_switched_sections
= true;
3785 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
3786 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
3787 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
3788 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
3789 have_multiple_function_sections
= true;
3791 /* Reset the current label on switching text sections, so that we
3792 don't attempt to advance_loc4 between labels in different sections. */
3793 fde
->dw_fde_current_label
= NULL
;
3795 /* There is no need to mark used sections when not debugging. */
3796 if (cold_text_section
!= NULL
)
3797 dwarf2out_note_section_used ();
3801 /* And now, the subset of the debugging information support code necessary
3802 for emitting location expressions. */
3804 /* Data about a single source file. */
3805 struct GTY(()) dwarf_file_data
{
3806 const char * filename
;
3810 typedef struct dw_val_struct
*dw_val_ref
;
3811 typedef struct die_struct
*dw_die_ref
;
3812 typedef const struct die_struct
*const_dw_die_ref
;
3813 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
3814 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
3816 typedef struct GTY(()) deferred_locations_struct
3820 } deferred_locations
;
3822 DEF_VEC_O(deferred_locations
);
3823 DEF_VEC_ALLOC_O(deferred_locations
,gc
);
3825 static GTY(()) VEC(deferred_locations
, gc
) *deferred_locations_list
;
3827 /* Each DIE may have a series of attribute/value pairs. Values
3828 can take on several forms. The forms that are used in this
3829 implementation are listed below. */
3834 dw_val_class_offset
,
3836 dw_val_class_loc_list
,
3837 dw_val_class_range_list
,
3839 dw_val_class_unsigned_const
,
3840 dw_val_class_long_long
,
3843 dw_val_class_die_ref
,
3844 dw_val_class_fde_ref
,
3845 dw_val_class_lbl_id
,
3846 dw_val_class_lineptr
,
3848 dw_val_class_macptr
,
3852 /* Describe a double word constant value. */
3853 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3855 typedef struct GTY(()) dw_long_long_struct
{
3861 /* Describe a floating point constant value, or a vector constant value. */
3863 typedef struct GTY(()) dw_vec_struct
{
3864 unsigned char * GTY((length ("%h.length"))) array
;
3870 /* The dw_val_node describes an attribute's value, as it is
3871 represented internally. */
3873 typedef struct GTY(()) dw_val_struct
{
3874 enum dw_val_class val_class
;
3875 union dw_val_struct_union
3877 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
3878 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
3879 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
3880 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
3881 HOST_WIDE_INT
GTY ((default)) val_int
;
3882 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
3883 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
3884 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
3885 struct dw_val_die_union
3889 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
3890 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
3891 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
3892 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
3893 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
3894 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
3896 GTY ((desc ("%1.val_class"))) v
;
3900 /* Locations in memory are described using a sequence of stack machine
3903 typedef struct GTY(()) dw_loc_descr_struct
{
3904 dw_loc_descr_ref dw_loc_next
;
3905 ENUM_BITFIELD (dwarf_location_atom
) dw_loc_opc
: 8;
3906 /* Used to distinguish DW_OP_addr with a direct symbol relocation
3907 from DW_OP_addr with a dtp-relative symbol relocation. */
3908 unsigned int dtprel
: 1;
3910 dw_val_node dw_loc_oprnd1
;
3911 dw_val_node dw_loc_oprnd2
;
3915 /* Location lists are ranges + location descriptions for that range,
3916 so you can track variables that are in different places over
3917 their entire life. */
3918 typedef struct GTY(()) dw_loc_list_struct
{
3919 dw_loc_list_ref dw_loc_next
;
3920 const char *begin
; /* Label for begin address of range */
3921 const char *end
; /* Label for end address of range */
3922 char *ll_symbol
; /* Label for beginning of location list.
3923 Only on head of list */
3924 const char *section
; /* Section this loclist is relative to */
3925 dw_loc_descr_ref expr
;
3928 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3930 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3932 /* Convert a DWARF stack opcode into its string name. */
3935 dwarf_stack_op_name (unsigned int op
)
3940 return "DW_OP_addr";
3942 return "DW_OP_deref";
3944 return "DW_OP_const1u";
3946 return "DW_OP_const1s";
3948 return "DW_OP_const2u";
3950 return "DW_OP_const2s";
3952 return "DW_OP_const4u";
3954 return "DW_OP_const4s";
3956 return "DW_OP_const8u";
3958 return "DW_OP_const8s";
3960 return "DW_OP_constu";
3962 return "DW_OP_consts";
3966 return "DW_OP_drop";
3968 return "DW_OP_over";
3970 return "DW_OP_pick";
3972 return "DW_OP_swap";
3976 return "DW_OP_xderef";
3984 return "DW_OP_minus";
3996 return "DW_OP_plus";
3997 case DW_OP_plus_uconst
:
3998 return "DW_OP_plus_uconst";
4004 return "DW_OP_shra";
4022 return "DW_OP_skip";
4024 return "DW_OP_lit0";
4026 return "DW_OP_lit1";
4028 return "DW_OP_lit2";
4030 return "DW_OP_lit3";
4032 return "DW_OP_lit4";
4034 return "DW_OP_lit5";
4036 return "DW_OP_lit6";
4038 return "DW_OP_lit7";
4040 return "DW_OP_lit8";
4042 return "DW_OP_lit9";
4044 return "DW_OP_lit10";
4046 return "DW_OP_lit11";
4048 return "DW_OP_lit12";
4050 return "DW_OP_lit13";
4052 return "DW_OP_lit14";
4054 return "DW_OP_lit15";
4056 return "DW_OP_lit16";
4058 return "DW_OP_lit17";
4060 return "DW_OP_lit18";
4062 return "DW_OP_lit19";
4064 return "DW_OP_lit20";
4066 return "DW_OP_lit21";
4068 return "DW_OP_lit22";
4070 return "DW_OP_lit23";
4072 return "DW_OP_lit24";
4074 return "DW_OP_lit25";
4076 return "DW_OP_lit26";
4078 return "DW_OP_lit27";
4080 return "DW_OP_lit28";
4082 return "DW_OP_lit29";
4084 return "DW_OP_lit30";
4086 return "DW_OP_lit31";
4088 return "DW_OP_reg0";
4090 return "DW_OP_reg1";
4092 return "DW_OP_reg2";
4094 return "DW_OP_reg3";
4096 return "DW_OP_reg4";
4098 return "DW_OP_reg5";
4100 return "DW_OP_reg6";
4102 return "DW_OP_reg7";
4104 return "DW_OP_reg8";
4106 return "DW_OP_reg9";
4108 return "DW_OP_reg10";
4110 return "DW_OP_reg11";
4112 return "DW_OP_reg12";
4114 return "DW_OP_reg13";
4116 return "DW_OP_reg14";
4118 return "DW_OP_reg15";
4120 return "DW_OP_reg16";
4122 return "DW_OP_reg17";
4124 return "DW_OP_reg18";
4126 return "DW_OP_reg19";
4128 return "DW_OP_reg20";
4130 return "DW_OP_reg21";
4132 return "DW_OP_reg22";
4134 return "DW_OP_reg23";
4136 return "DW_OP_reg24";
4138 return "DW_OP_reg25";
4140 return "DW_OP_reg26";
4142 return "DW_OP_reg27";
4144 return "DW_OP_reg28";
4146 return "DW_OP_reg29";
4148 return "DW_OP_reg30";
4150 return "DW_OP_reg31";
4152 return "DW_OP_breg0";
4154 return "DW_OP_breg1";
4156 return "DW_OP_breg2";
4158 return "DW_OP_breg3";
4160 return "DW_OP_breg4";
4162 return "DW_OP_breg5";
4164 return "DW_OP_breg6";
4166 return "DW_OP_breg7";
4168 return "DW_OP_breg8";
4170 return "DW_OP_breg9";
4172 return "DW_OP_breg10";
4174 return "DW_OP_breg11";
4176 return "DW_OP_breg12";
4178 return "DW_OP_breg13";
4180 return "DW_OP_breg14";
4182 return "DW_OP_breg15";
4184 return "DW_OP_breg16";
4186 return "DW_OP_breg17";
4188 return "DW_OP_breg18";
4190 return "DW_OP_breg19";
4192 return "DW_OP_breg20";
4194 return "DW_OP_breg21";
4196 return "DW_OP_breg22";
4198 return "DW_OP_breg23";
4200 return "DW_OP_breg24";
4202 return "DW_OP_breg25";
4204 return "DW_OP_breg26";
4206 return "DW_OP_breg27";
4208 return "DW_OP_breg28";
4210 return "DW_OP_breg29";
4212 return "DW_OP_breg30";
4214 return "DW_OP_breg31";
4216 return "DW_OP_regx";
4218 return "DW_OP_fbreg";
4220 return "DW_OP_bregx";
4222 return "DW_OP_piece";
4223 case DW_OP_deref_size
:
4224 return "DW_OP_deref_size";
4225 case DW_OP_xderef_size
:
4226 return "DW_OP_xderef_size";
4230 case DW_OP_push_object_address
:
4231 return "DW_OP_push_object_address";
4233 return "DW_OP_call2";
4235 return "DW_OP_call4";
4236 case DW_OP_call_ref
:
4237 return "DW_OP_call_ref";
4238 case DW_OP_form_tls_address
:
4239 return "DW_OP_form_tls_address";
4240 case DW_OP_call_frame_cfa
:
4241 return "DW_OP_call_frame_cfa";
4242 case DW_OP_bit_piece
:
4243 return "DW_OP_bit_piece";
4245 case DW_OP_GNU_push_tls_address
:
4246 return "DW_OP_GNU_push_tls_address";
4247 case DW_OP_GNU_uninit
:
4248 return "DW_OP_GNU_uninit";
4249 case DW_OP_GNU_encoded_addr
:
4250 return "DW_OP_GNU_encoded_addr";
4253 return "OP_<unknown>";
4257 /* Return a pointer to a newly allocated location description. Location
4258 descriptions are simple expression terms that can be strung
4259 together to form more complicated location (address) descriptions. */
4261 static inline dw_loc_descr_ref
4262 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
4263 unsigned HOST_WIDE_INT oprnd2
)
4265 dw_loc_descr_ref descr
= GGC_CNEW (dw_loc_descr_node
);
4267 descr
->dw_loc_opc
= op
;
4268 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
4269 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
4270 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
4271 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
4276 /* Return a pointer to a newly allocated location description for
4279 static inline dw_loc_descr_ref
4280 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
4283 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
4286 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
4289 /* Add a location description term to a location description expression. */
4292 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
4294 dw_loc_descr_ref
*d
;
4296 /* Find the end of the chain. */
4297 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
4303 /* Add a constant OFFSET to a location expression. */
4306 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
4308 dw_loc_descr_ref loc
;
4311 gcc_assert (*list_head
!= NULL
);
4316 /* Find the end of the chain. */
4317 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
4321 if (loc
->dw_loc_opc
== DW_OP_fbreg
4322 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
4323 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
4324 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
4325 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
4327 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4328 offset. Don't optimize if an signed integer overflow would happen. */
4330 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
4331 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
4334 else if (offset
> 0)
4335 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4339 loc
->dw_loc_next
= int_loc_descriptor (offset
);
4340 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_plus
, 0, 0));
4344 /* Return the size of a location descriptor. */
4346 static unsigned long
4347 size_of_loc_descr (dw_loc_descr_ref loc
)
4349 unsigned long size
= 1;
4351 switch (loc
->dw_loc_opc
)
4354 size
+= DWARF2_ADDR_SIZE
;
4373 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4376 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4381 case DW_OP_plus_uconst
:
4382 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4420 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4423 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4426 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
4429 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4430 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
4433 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
4435 case DW_OP_deref_size
:
4436 case DW_OP_xderef_size
:
4445 case DW_OP_call_ref
:
4446 size
+= DWARF2_ADDR_SIZE
;
4455 /* Return the size of a series of location descriptors. */
4457 static unsigned long
4458 size_of_locs (dw_loc_descr_ref loc
)
4463 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4464 field, to avoid writing to a PCH file. */
4465 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4467 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
4469 size
+= size_of_loc_descr (l
);
4474 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
4476 l
->dw_loc_addr
= size
;
4477 size
+= size_of_loc_descr (l
);
4483 /* Output location description stack opcode's operands (if any). */
4486 output_loc_operands (dw_loc_descr_ref loc
)
4488 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4489 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4491 switch (loc
->dw_loc_opc
)
4493 #ifdef DWARF2_DEBUGGING_INFO
4496 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
4500 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
4504 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4505 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
4512 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4513 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4515 dw2_asm_output_data (2, offset
, NULL
);
4527 /* We currently don't make any attempt to make sure these are
4528 aligned properly like we do for the main unwind info, so
4529 don't support emitting things larger than a byte if we're
4530 only doing unwinding. */
4535 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4538 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4541 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4544 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4546 case DW_OP_plus_uconst
:
4547 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4581 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4584 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4587 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
4590 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4591 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
4594 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
4596 case DW_OP_deref_size
:
4597 case DW_OP_xderef_size
:
4598 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
4604 if (targetm
.asm_out
.output_dwarf_dtprel
)
4606 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
4609 fputc ('\n', asm_out_file
);
4616 #ifdef DWARF2_DEBUGGING_INFO
4617 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
4625 /* Other codes have no operands. */
4630 /* Output a sequence of location operations. */
4633 output_loc_sequence (dw_loc_descr_ref loc
)
4635 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
4637 /* Output the opcode. */
4638 dw2_asm_output_data (1, loc
->dw_loc_opc
,
4639 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
4641 /* Output the operand(s) (if any). */
4642 output_loc_operands (loc
);
4646 /* Output location description stack opcode's operands (if any).
4647 The output is single bytes on a line, suitable for .cfi_escape. */
4650 output_loc_operands_raw (dw_loc_descr_ref loc
)
4652 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
4653 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
4655 switch (loc
->dw_loc_opc
)
4658 /* We cannot output addresses in .cfi_escape, only bytes. */
4664 case DW_OP_deref_size
:
4665 case DW_OP_xderef_size
:
4666 fputc (',', asm_out_file
);
4667 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
4672 fputc (',', asm_out_file
);
4673 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
4678 fputc (',', asm_out_file
);
4679 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
4684 gcc_assert (HOST_BITS_PER_LONG
>= 64);
4685 fputc (',', asm_out_file
);
4686 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
4694 gcc_assert (val1
->val_class
== dw_val_class_loc
);
4695 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
4697 fputc (',', asm_out_file
);
4698 dw2_asm_output_data_raw (2, offset
);
4703 case DW_OP_plus_uconst
:
4706 fputc (',', asm_out_file
);
4707 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4744 fputc (',', asm_out_file
);
4745 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
4749 fputc (',', asm_out_file
);
4750 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
4751 fputc (',', asm_out_file
);
4752 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
4756 /* Other codes have no operands. */
4762 output_loc_sequence_raw (dw_loc_descr_ref loc
)
4766 /* Output the opcode. */
4767 fprintf (asm_out_file
, "0x%x", loc
->dw_loc_opc
);
4768 output_loc_operands_raw (loc
);
4770 if (!loc
->dw_loc_next
)
4772 loc
= loc
->dw_loc_next
;
4774 fputc (',', asm_out_file
);
4778 /* This routine will generate the correct assembly data for a location
4779 description based on a cfi entry with a complex address. */
4782 output_cfa_loc (dw_cfi_ref cfi
)
4784 dw_loc_descr_ref loc
;
4787 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4788 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, NULL
);
4790 /* Output the size of the block. */
4791 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4792 size
= size_of_locs (loc
);
4793 dw2_asm_output_data_uleb128 (size
, NULL
);
4795 /* Now output the operations themselves. */
4796 output_loc_sequence (loc
);
4799 /* Similar, but used for .cfi_escape. */
4802 output_cfa_loc_raw (dw_cfi_ref cfi
)
4804 dw_loc_descr_ref loc
;
4807 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
4808 fprintf (asm_out_file
, "0x%x,", cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
4810 /* Output the size of the block. */
4811 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
4812 size
= size_of_locs (loc
);
4813 dw2_asm_output_data_uleb128_raw (size
);
4814 fputc (',', asm_out_file
);
4816 /* Now output the operations themselves. */
4817 output_loc_sequence_raw (loc
);
4820 /* This function builds a dwarf location descriptor sequence from a
4821 dw_cfa_location, adding the given OFFSET to the result of the
4824 static struct dw_loc_descr_struct
*
4825 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
4827 struct dw_loc_descr_struct
*head
, *tmp
;
4829 offset
+= cfa
->offset
;
4833 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
4834 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
4835 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
4836 add_loc_descr (&head
, tmp
);
4839 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
4840 add_loc_descr (&head
, tmp
);
4844 head
= new_reg_loc_descr (cfa
->reg
, offset
);
4849 /* This function builds a dwarf location descriptor sequence for
4850 the address at OFFSET from the CFA when stack is aligned to
4853 static struct dw_loc_descr_struct
*
4854 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
4856 struct dw_loc_descr_struct
*head
;
4857 unsigned int dwarf_fp
4858 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
4860 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4861 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
4863 head
= new_reg_loc_descr (dwarf_fp
, 0);
4864 add_loc_descr (&head
, int_loc_descriptor (alignment
));
4865 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
4866 loc_descr_plus_const (&head
, offset
);
4869 head
= new_reg_loc_descr (dwarf_fp
, offset
);
4873 /* This function fills in aa dw_cfa_location structure from a dwarf location
4874 descriptor sequence. */
4877 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
4879 struct dw_loc_descr_struct
*ptr
;
4881 cfa
->base_offset
= 0;
4885 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
4887 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
4923 cfa
->reg
= op
- DW_OP_reg0
;
4926 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4960 cfa
->reg
= op
- DW_OP_breg0
;
4961 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4964 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4965 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
4970 case DW_OP_plus_uconst
:
4971 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
4974 internal_error ("DW_LOC_OP %s not implemented",
4975 dwarf_stack_op_name (ptr
->dw_loc_opc
));
4979 #endif /* .debug_frame support */
4981 /* And now, the support for symbolic debugging information. */
4982 #ifdef DWARF2_DEBUGGING_INFO
4984 /* .debug_str support. */
4985 static int output_indirect_string (void **, void *);
4987 static void dwarf2out_init (const char *);
4988 static void dwarf2out_finish (const char *);
4989 static void dwarf2out_define (unsigned int, const char *);
4990 static void dwarf2out_undef (unsigned int, const char *);
4991 static void dwarf2out_start_source_file (unsigned, const char *);
4992 static void dwarf2out_end_source_file (unsigned);
4993 static void dwarf2out_begin_block (unsigned, unsigned);
4994 static void dwarf2out_end_block (unsigned, unsigned);
4995 static bool dwarf2out_ignore_block (const_tree
);
4996 static void dwarf2out_global_decl (tree
);
4997 static void dwarf2out_type_decl (tree
, int);
4998 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
4999 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
5001 static void dwarf2out_abstract_function (tree
);
5002 static void dwarf2out_var_location (rtx
);
5003 static void dwarf2out_begin_function (tree
);
5004 static void dwarf2out_set_name (tree
, tree
);
5006 /* The debug hooks structure. */
5008 const struct gcc_debug_hooks dwarf2_debug_hooks
=
5014 dwarf2out_start_source_file
,
5015 dwarf2out_end_source_file
,
5016 dwarf2out_begin_block
,
5017 dwarf2out_end_block
,
5018 dwarf2out_ignore_block
,
5019 dwarf2out_source_line
,
5020 dwarf2out_begin_prologue
,
5021 debug_nothing_int_charstar
, /* end_prologue */
5022 dwarf2out_end_epilogue
,
5023 dwarf2out_begin_function
,
5024 debug_nothing_int
, /* end_function */
5025 dwarf2out_decl
, /* function_decl */
5026 dwarf2out_global_decl
,
5027 dwarf2out_type_decl
, /* type_decl */
5028 dwarf2out_imported_module_or_decl
,
5029 debug_nothing_tree
, /* deferred_inline_function */
5030 /* The DWARF 2 backend tries to reduce debugging bloat by not
5031 emitting the abstract description of inline functions until
5032 something tries to reference them. */
5033 dwarf2out_abstract_function
, /* outlining_inline_function */
5034 debug_nothing_rtx
, /* label */
5035 debug_nothing_int
, /* handle_pch */
5036 dwarf2out_var_location
,
5037 dwarf2out_switch_text_section
,
5039 1 /* start_end_main_source_file */
5043 /* NOTE: In the comments in this file, many references are made to
5044 "Debugging Information Entries". This term is abbreviated as `DIE'
5045 throughout the remainder of this file. */
5047 /* An internal representation of the DWARF output is built, and then
5048 walked to generate the DWARF debugging info. The walk of the internal
5049 representation is done after the entire program has been compiled.
5050 The types below are used to describe the internal representation. */
5052 /* Various DIE's use offsets relative to the beginning of the
5053 .debug_info section to refer to each other. */
5055 typedef long int dw_offset
;
5057 /* Define typedefs here to avoid circular dependencies. */
5059 typedef struct dw_attr_struct
*dw_attr_ref
;
5060 typedef struct dw_line_info_struct
*dw_line_info_ref
;
5061 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
5062 typedef struct pubname_struct
*pubname_ref
;
5063 typedef struct dw_ranges_struct
*dw_ranges_ref
;
5064 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
5066 /* Each entry in the line_info_table maintains the file and
5067 line number associated with the label generated for that
5068 entry. The label gives the PC value associated with
5069 the line number entry. */
5071 typedef struct GTY(()) dw_line_info_struct
{
5072 unsigned long dw_file_num
;
5073 unsigned long dw_line_num
;
5077 /* Line information for functions in separate sections; each one gets its
5079 typedef struct GTY(()) dw_separate_line_info_struct
{
5080 unsigned long dw_file_num
;
5081 unsigned long dw_line_num
;
5082 unsigned long function
;
5084 dw_separate_line_info_entry
;
5086 /* Each DIE attribute has a field specifying the attribute kind,
5087 a link to the next attribute in the chain, and an attribute value.
5088 Attributes are typically linked below the DIE they modify. */
5090 typedef struct GTY(()) dw_attr_struct
{
5091 enum dwarf_attribute dw_attr
;
5092 dw_val_node dw_attr_val
;
5096 DEF_VEC_O(dw_attr_node
);
5097 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
5099 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5100 The children of each node form a circular list linked by
5101 die_sib. die_child points to the node *before* the "first" child node. */
5103 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
5104 enum dwarf_tag die_tag
;
5106 VEC(dw_attr_node
,gc
) * die_attr
;
5107 dw_die_ref die_parent
;
5108 dw_die_ref die_child
;
5110 dw_die_ref die_definition
; /* ref from a specification to its definition */
5111 dw_offset die_offset
;
5112 unsigned long die_abbrev
;
5114 /* Die is used and must not be pruned as unused. */
5115 int die_perennial_p
;
5116 unsigned int decl_id
;
5120 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5121 #define FOR_EACH_CHILD(die, c, expr) do { \
5122 c = die->die_child; \
5126 } while (c != die->die_child); \
5129 /* The pubname structure */
5131 typedef struct GTY(()) pubname_struct
{
5137 DEF_VEC_O(pubname_entry
);
5138 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
5140 struct GTY(()) dw_ranges_struct
{
5141 /* If this is positive, it's a block number, otherwise it's a
5142 bitwise-negated index into dw_ranges_by_label. */
5146 struct GTY(()) dw_ranges_by_label_struct
{
5151 /* The limbo die list structure. */
5152 typedef struct GTY(()) limbo_die_struct
{
5155 struct limbo_die_struct
*next
;
5159 /* How to start an assembler comment. */
5160 #ifndef ASM_COMMENT_START
5161 #define ASM_COMMENT_START ";#"
5164 /* Define a macro which returns nonzero for a TYPE_DECL which was
5165 implicitly generated for a tagged type.
5167 Note that unlike the gcc front end (which generates a NULL named
5168 TYPE_DECL node for each complete tagged type, each array type, and
5169 each function type node created) the g++ front end generates a
5170 _named_ TYPE_DECL node for each tagged type node created.
5171 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5172 generate a DW_TAG_typedef DIE for them. */
5174 #define TYPE_DECL_IS_STUB(decl) \
5175 (DECL_NAME (decl) == NULL_TREE \
5176 || (DECL_ARTIFICIAL (decl) \
5177 && is_tagged_type (TREE_TYPE (decl)) \
5178 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5179 /* This is necessary for stub decls that \
5180 appear in nested inline functions. */ \
5181 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5182 && (decl_ultimate_origin (decl) \
5183 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5185 /* Information concerning the compilation unit's programming
5186 language, and compiler version. */
5188 /* Fixed size portion of the DWARF compilation unit header. */
5189 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5190 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5192 /* Fixed size portion of public names info. */
5193 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5195 /* Fixed size portion of the address range info. */
5196 #define DWARF_ARANGES_HEADER_SIZE \
5197 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5198 DWARF2_ADDR_SIZE * 2) \
5199 - DWARF_INITIAL_LENGTH_SIZE)
5201 /* Size of padding portion in the address range info. It must be
5202 aligned to twice the pointer size. */
5203 #define DWARF_ARANGES_PAD_SIZE \
5204 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5205 DWARF2_ADDR_SIZE * 2) \
5206 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5208 /* Use assembler line directives if available. */
5209 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5210 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5211 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5213 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5217 /* Minimum line offset in a special line info. opcode.
5218 This value was chosen to give a reasonable range of values. */
5219 #define DWARF_LINE_BASE -10
5221 /* First special line opcode - leave room for the standard opcodes. */
5222 #define DWARF_LINE_OPCODE_BASE 10
5224 /* Range of line offsets in a special line info. opcode. */
5225 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5227 /* Flag that indicates the initial value of the is_stmt_start flag.
5228 In the present implementation, we do not mark any lines as
5229 the beginning of a source statement, because that information
5230 is not made available by the GCC front-end. */
5231 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5233 #ifdef DWARF2_DEBUGGING_INFO
5234 /* This location is used by calc_die_sizes() to keep track
5235 the offset of each DIE within the .debug_info section. */
5236 static unsigned long next_die_offset
;
5239 /* Record the root of the DIE's built for the current compilation unit. */
5240 static GTY(()) dw_die_ref comp_unit_die
;
5242 /* A list of DIEs with a NULL parent waiting to be relocated. */
5243 static GTY(()) limbo_die_node
*limbo_die_list
;
5245 /* A list of DIEs for which we may have to generate
5246 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5248 static GTY(()) limbo_die_node
*deferred_asm_name
;
5250 /* Filenames referenced by this compilation unit. */
5251 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
5253 /* A hash table of references to DIE's that describe declarations.
5254 The key is a DECL_UID() which is a unique number identifying each decl. */
5255 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
5257 /* A hash table of references to DIE's that describe COMMON blocks.
5258 The key is DECL_UID() ^ die_parent. */
5259 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
5261 /* Node of the variable location list. */
5262 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
5263 rtx
GTY (()) var_loc_note
;
5264 const char * GTY (()) label
;
5265 const char * GTY (()) section_label
;
5266 struct var_loc_node
* GTY (()) next
;
5269 /* Variable location list. */
5270 struct GTY (()) var_loc_list_def
{
5271 struct var_loc_node
* GTY (()) first
;
5273 /* Do not mark the last element of the chained list because
5274 it is marked through the chain. */
5275 struct var_loc_node
* GTY ((skip ("%h"))) last
;
5277 /* DECL_UID of the variable decl. */
5278 unsigned int decl_id
;
5280 typedef struct var_loc_list_def var_loc_list
;
5283 /* Table of decl location linked lists. */
5284 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
5286 /* A pointer to the base of a list of references to DIE's that
5287 are uniquely identified by their tag, presence/absence of
5288 children DIE's, and list of attribute/value pairs. */
5289 static GTY((length ("abbrev_die_table_allocated")))
5290 dw_die_ref
*abbrev_die_table
;
5292 /* Number of elements currently allocated for abbrev_die_table. */
5293 static GTY(()) unsigned abbrev_die_table_allocated
;
5295 /* Number of elements in type_die_table currently in use. */
5296 static GTY(()) unsigned abbrev_die_table_in_use
;
5298 /* Size (in elements) of increments by which we may expand the
5299 abbrev_die_table. */
5300 #define ABBREV_DIE_TABLE_INCREMENT 256
5302 /* A pointer to the base of a table that contains line information
5303 for each source code line in .text in the compilation unit. */
5304 static GTY((length ("line_info_table_allocated")))
5305 dw_line_info_ref line_info_table
;
5307 /* Number of elements currently allocated for line_info_table. */
5308 static GTY(()) unsigned line_info_table_allocated
;
5310 /* Number of elements in line_info_table currently in use. */
5311 static GTY(()) unsigned line_info_table_in_use
;
5313 /* A pointer to the base of a table that contains line information
5314 for each source code line outside of .text in the compilation unit. */
5315 static GTY ((length ("separate_line_info_table_allocated")))
5316 dw_separate_line_info_ref separate_line_info_table
;
5318 /* Number of elements currently allocated for separate_line_info_table. */
5319 static GTY(()) unsigned separate_line_info_table_allocated
;
5321 /* Number of elements in separate_line_info_table currently in use. */
5322 static GTY(()) unsigned separate_line_info_table_in_use
;
5324 /* Size (in elements) of increments by which we may expand the
5326 #define LINE_INFO_TABLE_INCREMENT 1024
5328 /* A pointer to the base of a table that contains a list of publicly
5329 accessible names. */
5330 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
5332 /* A pointer to the base of a table that contains a list of publicly
5333 accessible types. */
5334 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
5336 /* Array of dies for which we should generate .debug_arange info. */
5337 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
5339 /* Number of elements currently allocated for arange_table. */
5340 static GTY(()) unsigned arange_table_allocated
;
5342 /* Number of elements in arange_table currently in use. */
5343 static GTY(()) unsigned arange_table_in_use
;
5345 /* Size (in elements) of increments by which we may expand the
5347 #define ARANGE_TABLE_INCREMENT 64
5349 /* Array of dies for which we should generate .debug_ranges info. */
5350 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
5352 /* Number of elements currently allocated for ranges_table. */
5353 static GTY(()) unsigned ranges_table_allocated
;
5355 /* Number of elements in ranges_table currently in use. */
5356 static GTY(()) unsigned ranges_table_in_use
;
5358 /* Array of pairs of labels referenced in ranges_table. */
5359 static GTY ((length ("ranges_by_label_allocated")))
5360 dw_ranges_by_label_ref ranges_by_label
;
5362 /* Number of elements currently allocated for ranges_by_label. */
5363 static GTY(()) unsigned ranges_by_label_allocated
;
5365 /* Number of elements in ranges_by_label currently in use. */
5366 static GTY(()) unsigned ranges_by_label_in_use
;
5368 /* Size (in elements) of increments by which we may expand the
5370 #define RANGES_TABLE_INCREMENT 64
5372 /* Whether we have location lists that need outputting */
5373 static GTY(()) bool have_location_lists
;
5375 /* Unique label counter. */
5376 static GTY(()) unsigned int loclabel_num
;
5378 #ifdef DWARF2_DEBUGGING_INFO
5379 /* Record whether the function being analyzed contains inlined functions. */
5380 static int current_function_has_inlines
;
5382 #if 0 && defined (MIPS_DEBUGGING_INFO)
5383 static int comp_unit_has_inlines
;
5386 /* The last file entry emitted by maybe_emit_file(). */
5387 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
5389 /* Number of internal labels generated by gen_internal_sym(). */
5390 static GTY(()) int label_num
;
5392 /* Cached result of previous call to lookup_filename. */
5393 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
5395 #ifdef DWARF2_DEBUGGING_INFO
5397 /* Offset from the "steady-state frame pointer" to the frame base,
5398 within the current function. */
5399 static HOST_WIDE_INT frame_pointer_fb_offset
;
5401 /* Forward declarations for functions defined in this file. */
5403 static int is_pseudo_reg (const_rtx
);
5404 static tree
type_main_variant (tree
);
5405 static int is_tagged_type (const_tree
);
5406 static const char *dwarf_tag_name (unsigned);
5407 static const char *dwarf_attr_name (unsigned);
5408 static const char *dwarf_form_name (unsigned);
5409 static tree
decl_ultimate_origin (const_tree
);
5410 static tree
decl_class_context (tree
);
5411 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
5412 static inline enum dw_val_class
AT_class (dw_attr_ref
);
5413 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
5414 static inline unsigned AT_flag (dw_attr_ref
);
5415 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
5416 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
5417 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
5418 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
5419 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
5421 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
5422 unsigned int, unsigned char *);
5423 static hashval_t
debug_str_do_hash (const void *);
5424 static int debug_str_eq (const void *, const void *);
5425 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
5426 static inline const char *AT_string (dw_attr_ref
);
5427 static enum dwarf_form
AT_string_form (dw_attr_ref
);
5428 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
5429 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
5430 static inline dw_die_ref
AT_ref (dw_attr_ref
);
5431 static inline int AT_ref_external (dw_attr_ref
);
5432 static inline void set_AT_ref_external (dw_attr_ref
, int);
5433 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
5434 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
5435 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
5436 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
5438 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
5439 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
5440 static inline rtx
AT_addr (dw_attr_ref
);
5441 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
5442 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
5443 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
5444 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
5445 unsigned HOST_WIDE_INT
);
5446 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
5448 static inline const char *AT_lbl (dw_attr_ref
);
5449 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
5450 static const char *get_AT_low_pc (dw_die_ref
);
5451 static const char *get_AT_hi_pc (dw_die_ref
);
5452 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
5453 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
5454 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
5455 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
5456 static bool is_c_family (void);
5457 static bool is_cxx (void);
5458 static bool is_java (void);
5459 static bool is_fortran (void);
5460 static bool is_ada (void);
5461 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
5462 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
5463 static void add_child_die (dw_die_ref
, dw_die_ref
);
5464 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
5465 static dw_die_ref
lookup_type_die (tree
);
5466 static void equate_type_number_to_die (tree
, dw_die_ref
);
5467 static hashval_t
decl_die_table_hash (const void *);
5468 static int decl_die_table_eq (const void *, const void *);
5469 static dw_die_ref
lookup_decl_die (tree
);
5470 static hashval_t
common_block_die_table_hash (const void *);
5471 static int common_block_die_table_eq (const void *, const void *);
5472 static hashval_t
decl_loc_table_hash (const void *);
5473 static int decl_loc_table_eq (const void *, const void *);
5474 static var_loc_list
*lookup_decl_loc (const_tree
);
5475 static void equate_decl_number_to_die (tree
, dw_die_ref
);
5476 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
5477 static void print_spaces (FILE *);
5478 static void print_die (dw_die_ref
, FILE *);
5479 static void print_dwarf_line_table (FILE *);
5480 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
5481 static dw_die_ref
pop_compile_unit (dw_die_ref
);
5482 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
5483 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
5484 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
5485 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
5486 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
5487 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
5488 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
5489 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
5490 static void compute_section_prefix (dw_die_ref
);
5491 static int is_type_die (dw_die_ref
);
5492 static int is_comdat_die (dw_die_ref
);
5493 static int is_symbol_die (dw_die_ref
);
5494 static void assign_symbol_names (dw_die_ref
);
5495 static void break_out_includes (dw_die_ref
);
5496 static hashval_t
htab_cu_hash (const void *);
5497 static int htab_cu_eq (const void *, const void *);
5498 static void htab_cu_del (void *);
5499 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
5500 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
5501 static void add_sibling_attributes (dw_die_ref
);
5502 static void build_abbrev_table (dw_die_ref
);
5503 static void output_location_lists (dw_die_ref
);
5504 static int constant_size (unsigned HOST_WIDE_INT
);
5505 static unsigned long size_of_die (dw_die_ref
);
5506 static void calc_die_sizes (dw_die_ref
);
5507 static void mark_dies (dw_die_ref
);
5508 static void unmark_dies (dw_die_ref
);
5509 static void unmark_all_dies (dw_die_ref
);
5510 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
5511 static unsigned long size_of_aranges (void);
5512 static enum dwarf_form
value_format (dw_attr_ref
);
5513 static void output_value_format (dw_attr_ref
);
5514 static void output_abbrev_section (void);
5515 static void output_die_symbol (dw_die_ref
);
5516 static void output_die (dw_die_ref
);
5517 static void output_compilation_unit_header (void);
5518 static void output_comp_unit (dw_die_ref
, int);
5519 static const char *dwarf2_name (tree
, int);
5520 static void add_pubname (tree
, dw_die_ref
);
5521 static void add_pubname_string (const char *, dw_die_ref
);
5522 static void add_pubtype (tree
, dw_die_ref
);
5523 static void output_pubnames (VEC (pubname_entry
,gc
) *);
5524 static void add_arange (tree
, dw_die_ref
);
5525 static void output_aranges (void);
5526 static unsigned int add_ranges_num (int);
5527 static unsigned int add_ranges (const_tree
);
5528 static unsigned int add_ranges_by_labels (const char *, const char *);
5529 static void output_ranges (void);
5530 static void output_line_info (void);
5531 static void output_file_names (void);
5532 static dw_die_ref
base_type_die (tree
);
5533 static int is_base_type (tree
);
5534 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
5535 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
5536 static int type_is_enum (const_tree
);
5537 static unsigned int dbx_reg_number (const_rtx
);
5538 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
5539 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
5540 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
5541 enum var_init_status
);
5542 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
5543 enum var_init_status
);
5544 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
5545 enum var_init_status
);
5546 static int is_based_loc (const_rtx
);
5547 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
5548 enum var_init_status
);
5549 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
5550 enum var_init_status
);
5551 static dw_loc_descr_ref
loc_descriptor (rtx
, enum var_init_status
);
5552 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
5553 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
5554 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
5555 static tree
field_type (const_tree
);
5556 static unsigned int simple_type_align_in_bits (const_tree
);
5557 static unsigned int simple_decl_align_in_bits (const_tree
);
5558 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
5559 static HOST_WIDE_INT
field_byte_offset (const_tree
);
5560 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
5562 static void add_data_member_location_attribute (dw_die_ref
, tree
);
5563 static void add_const_value_attribute (dw_die_ref
, rtx
);
5564 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
5565 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
5566 static void insert_float (const_rtx
, unsigned char *);
5567 static rtx
rtl_for_decl_location (tree
);
5568 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
5569 enum dwarf_attribute
);
5570 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
5571 static void add_name_attribute (dw_die_ref
, const char *);
5572 static void add_comp_dir_attribute (dw_die_ref
);
5573 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
5574 static void add_subscript_info (dw_die_ref
, tree
, bool);
5575 static void add_byte_size_attribute (dw_die_ref
, tree
);
5576 static void add_bit_offset_attribute (dw_die_ref
, tree
);
5577 static void add_bit_size_attribute (dw_die_ref
, tree
);
5578 static void add_prototyped_attribute (dw_die_ref
, tree
);
5579 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
5580 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
5581 static void add_src_coords_attributes (dw_die_ref
, tree
);
5582 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
5583 static void push_decl_scope (tree
);
5584 static void pop_decl_scope (void);
5585 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
5586 static inline int local_scope_p (dw_die_ref
);
5587 static inline int class_scope_p (dw_die_ref
);
5588 static inline int class_or_namespace_scope_p (dw_die_ref
);
5589 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
5590 static void add_calling_convention_attribute (dw_die_ref
, tree
);
5591 static const char *type_tag (const_tree
);
5592 static tree
member_declared_type (const_tree
);
5594 static const char *decl_start_label (tree
);
5596 static void gen_array_type_die (tree
, dw_die_ref
);
5597 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
5599 static void gen_entry_point_die (tree
, dw_die_ref
);
5601 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
5602 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, dw_die_ref
);
5603 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
5604 static void gen_formal_types_die (tree
, dw_die_ref
);
5605 static void gen_subprogram_die (tree
, dw_die_ref
);
5606 static void gen_variable_die (tree
, tree
, dw_die_ref
);
5607 static void gen_const_die (tree
, dw_die_ref
);
5608 static void gen_label_die (tree
, dw_die_ref
);
5609 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
5610 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
5611 static void gen_field_die (tree
, dw_die_ref
);
5612 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
5613 static dw_die_ref
gen_compile_unit_die (const char *);
5614 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
5615 static void gen_member_die (tree
, dw_die_ref
);
5616 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
5617 enum debug_info_usage
);
5618 static void gen_subroutine_type_die (tree
, dw_die_ref
);
5619 static void gen_typedef_die (tree
, dw_die_ref
);
5620 static void gen_type_die (tree
, dw_die_ref
);
5621 static void gen_block_die (tree
, dw_die_ref
, int);
5622 static void decls_for_scope (tree
, dw_die_ref
, int);
5623 static int is_redundant_typedef (const_tree
);
5624 static void gen_namespace_die (tree
, dw_die_ref
);
5625 static void gen_decl_die (tree
, tree
, dw_die_ref
);
5626 static dw_die_ref
force_decl_die (tree
);
5627 static dw_die_ref
force_type_die (tree
);
5628 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
5629 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
5630 static struct dwarf_file_data
* lookup_filename (const char *);
5631 static void retry_incomplete_types (void);
5632 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
5633 static void splice_child_die (dw_die_ref
, dw_die_ref
);
5634 static int file_info_cmp (const void *, const void *);
5635 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
5636 const char *, const char *, unsigned);
5637 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
5638 const char *, const char *,
5640 static void output_loc_list (dw_loc_list_ref
);
5641 static char *gen_internal_sym (const char *);
5643 static void prune_unmark_dies (dw_die_ref
);
5644 static void prune_unused_types_mark (dw_die_ref
, int);
5645 static void prune_unused_types_walk (dw_die_ref
);
5646 static void prune_unused_types_walk_attribs (dw_die_ref
);
5647 static void prune_unused_types_prune (dw_die_ref
);
5648 static void prune_unused_types (void);
5649 static int maybe_emit_file (struct dwarf_file_data
*fd
);
5651 /* Section names used to hold DWARF debugging information. */
5652 #ifndef DEBUG_INFO_SECTION
5653 #define DEBUG_INFO_SECTION ".debug_info"
5655 #ifndef DEBUG_ABBREV_SECTION
5656 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5658 #ifndef DEBUG_ARANGES_SECTION
5659 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5661 #ifndef DEBUG_MACINFO_SECTION
5662 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5664 #ifndef DEBUG_LINE_SECTION
5665 #define DEBUG_LINE_SECTION ".debug_line"
5667 #ifndef DEBUG_LOC_SECTION
5668 #define DEBUG_LOC_SECTION ".debug_loc"
5670 #ifndef DEBUG_PUBNAMES_SECTION
5671 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5673 #ifndef DEBUG_PUBTYPES_SECTION
5674 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
5676 #ifndef DEBUG_STR_SECTION
5677 #define DEBUG_STR_SECTION ".debug_str"
5679 #ifndef DEBUG_RANGES_SECTION
5680 #define DEBUG_RANGES_SECTION ".debug_ranges"
5683 /* Standard ELF section names for compiled code and data. */
5684 #ifndef TEXT_SECTION_NAME
5685 #define TEXT_SECTION_NAME ".text"
5688 /* Section flags for .debug_str section. */
5689 #define DEBUG_STR_SECTION_FLAGS \
5690 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5691 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5694 /* Labels we insert at beginning sections we can reference instead of
5695 the section names themselves. */
5697 #ifndef TEXT_SECTION_LABEL
5698 #define TEXT_SECTION_LABEL "Ltext"
5700 #ifndef COLD_TEXT_SECTION_LABEL
5701 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5703 #ifndef DEBUG_LINE_SECTION_LABEL
5704 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5706 #ifndef DEBUG_INFO_SECTION_LABEL
5707 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5709 #ifndef DEBUG_ABBREV_SECTION_LABEL
5710 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5712 #ifndef DEBUG_LOC_SECTION_LABEL
5713 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5715 #ifndef DEBUG_RANGES_SECTION_LABEL
5716 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5718 #ifndef DEBUG_MACINFO_SECTION_LABEL
5719 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5722 /* Definitions of defaults for formats and names of various special
5723 (artificial) labels which may be generated within this file (when the -g
5724 options is used and DWARF2_DEBUGGING_INFO is in effect.
5725 If necessary, these may be overridden from within the tm.h file, but
5726 typically, overriding these defaults is unnecessary. */
5728 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5729 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5730 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5731 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5732 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5733 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5734 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5735 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5736 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
5737 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
5739 #ifndef TEXT_END_LABEL
5740 #define TEXT_END_LABEL "Letext"
5742 #ifndef COLD_END_LABEL
5743 #define COLD_END_LABEL "Letext_cold"
5745 #ifndef BLOCK_BEGIN_LABEL
5746 #define BLOCK_BEGIN_LABEL "LBB"
5748 #ifndef BLOCK_END_LABEL
5749 #define BLOCK_END_LABEL "LBE"
5751 #ifndef LINE_CODE_LABEL
5752 #define LINE_CODE_LABEL "LM"
5754 #ifndef SEPARATE_LINE_CODE_LABEL
5755 #define SEPARATE_LINE_CODE_LABEL "LSM"
5759 /* We allow a language front-end to designate a function that is to be
5760 called to "demangle" any name before it is put into a DIE. */
5762 static const char *(*demangle_name_func
) (const char *);
5765 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
5767 demangle_name_func
= func
;
5770 /* Test if rtl node points to a pseudo register. */
5773 is_pseudo_reg (const_rtx rtl
)
5775 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
5776 || (GET_CODE (rtl
) == SUBREG
5777 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
5780 /* Return a reference to a type, with its const and volatile qualifiers
5784 type_main_variant (tree type
)
5786 type
= TYPE_MAIN_VARIANT (type
);
5788 /* ??? There really should be only one main variant among any group of
5789 variants of a given type (and all of the MAIN_VARIANT values for all
5790 members of the group should point to that one type) but sometimes the C
5791 front-end messes this up for array types, so we work around that bug
5793 if (TREE_CODE (type
) == ARRAY_TYPE
)
5794 while (type
!= TYPE_MAIN_VARIANT (type
))
5795 type
= TYPE_MAIN_VARIANT (type
);
5800 /* Return nonzero if the given type node represents a tagged type. */
5803 is_tagged_type (const_tree type
)
5805 enum tree_code code
= TREE_CODE (type
);
5807 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
5808 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
5811 /* Convert a DIE tag into its string name. */
5814 dwarf_tag_name (unsigned int tag
)
5818 case DW_TAG_padding
:
5819 return "DW_TAG_padding";
5820 case DW_TAG_array_type
:
5821 return "DW_TAG_array_type";
5822 case DW_TAG_class_type
:
5823 return "DW_TAG_class_type";
5824 case DW_TAG_entry_point
:
5825 return "DW_TAG_entry_point";
5826 case DW_TAG_enumeration_type
:
5827 return "DW_TAG_enumeration_type";
5828 case DW_TAG_formal_parameter
:
5829 return "DW_TAG_formal_parameter";
5830 case DW_TAG_imported_declaration
:
5831 return "DW_TAG_imported_declaration";
5833 return "DW_TAG_label";
5834 case DW_TAG_lexical_block
:
5835 return "DW_TAG_lexical_block";
5837 return "DW_TAG_member";
5838 case DW_TAG_pointer_type
:
5839 return "DW_TAG_pointer_type";
5840 case DW_TAG_reference_type
:
5841 return "DW_TAG_reference_type";
5842 case DW_TAG_compile_unit
:
5843 return "DW_TAG_compile_unit";
5844 case DW_TAG_string_type
:
5845 return "DW_TAG_string_type";
5846 case DW_TAG_structure_type
:
5847 return "DW_TAG_structure_type";
5848 case DW_TAG_subroutine_type
:
5849 return "DW_TAG_subroutine_type";
5850 case DW_TAG_typedef
:
5851 return "DW_TAG_typedef";
5852 case DW_TAG_union_type
:
5853 return "DW_TAG_union_type";
5854 case DW_TAG_unspecified_parameters
:
5855 return "DW_TAG_unspecified_parameters";
5856 case DW_TAG_variant
:
5857 return "DW_TAG_variant";
5858 case DW_TAG_common_block
:
5859 return "DW_TAG_common_block";
5860 case DW_TAG_common_inclusion
:
5861 return "DW_TAG_common_inclusion";
5862 case DW_TAG_inheritance
:
5863 return "DW_TAG_inheritance";
5864 case DW_TAG_inlined_subroutine
:
5865 return "DW_TAG_inlined_subroutine";
5867 return "DW_TAG_module";
5868 case DW_TAG_ptr_to_member_type
:
5869 return "DW_TAG_ptr_to_member_type";
5870 case DW_TAG_set_type
:
5871 return "DW_TAG_set_type";
5872 case DW_TAG_subrange_type
:
5873 return "DW_TAG_subrange_type";
5874 case DW_TAG_with_stmt
:
5875 return "DW_TAG_with_stmt";
5876 case DW_TAG_access_declaration
:
5877 return "DW_TAG_access_declaration";
5878 case DW_TAG_base_type
:
5879 return "DW_TAG_base_type";
5880 case DW_TAG_catch_block
:
5881 return "DW_TAG_catch_block";
5882 case DW_TAG_const_type
:
5883 return "DW_TAG_const_type";
5884 case DW_TAG_constant
:
5885 return "DW_TAG_constant";
5886 case DW_TAG_enumerator
:
5887 return "DW_TAG_enumerator";
5888 case DW_TAG_file_type
:
5889 return "DW_TAG_file_type";
5891 return "DW_TAG_friend";
5892 case DW_TAG_namelist
:
5893 return "DW_TAG_namelist";
5894 case DW_TAG_namelist_item
:
5895 return "DW_TAG_namelist_item";
5896 case DW_TAG_packed_type
:
5897 return "DW_TAG_packed_type";
5898 case DW_TAG_subprogram
:
5899 return "DW_TAG_subprogram";
5900 case DW_TAG_template_type_param
:
5901 return "DW_TAG_template_type_param";
5902 case DW_TAG_template_value_param
:
5903 return "DW_TAG_template_value_param";
5904 case DW_TAG_thrown_type
:
5905 return "DW_TAG_thrown_type";
5906 case DW_TAG_try_block
:
5907 return "DW_TAG_try_block";
5908 case DW_TAG_variant_part
:
5909 return "DW_TAG_variant_part";
5910 case DW_TAG_variable
:
5911 return "DW_TAG_variable";
5912 case DW_TAG_volatile_type
:
5913 return "DW_TAG_volatile_type";
5914 case DW_TAG_dwarf_procedure
:
5915 return "DW_TAG_dwarf_procedure";
5916 case DW_TAG_restrict_type
:
5917 return "DW_TAG_restrict_type";
5918 case DW_TAG_interface_type
:
5919 return "DW_TAG_interface_type";
5920 case DW_TAG_namespace
:
5921 return "DW_TAG_namespace";
5922 case DW_TAG_imported_module
:
5923 return "DW_TAG_imported_module";
5924 case DW_TAG_unspecified_type
:
5925 return "DW_TAG_unspecified_type";
5926 case DW_TAG_partial_unit
:
5927 return "DW_TAG_partial_unit";
5928 case DW_TAG_imported_unit
:
5929 return "DW_TAG_imported_unit";
5930 case DW_TAG_condition
:
5931 return "DW_TAG_condition";
5932 case DW_TAG_shared_type
:
5933 return "DW_TAG_shared_type";
5934 case DW_TAG_MIPS_loop
:
5935 return "DW_TAG_MIPS_loop";
5936 case DW_TAG_format_label
:
5937 return "DW_TAG_format_label";
5938 case DW_TAG_function_template
:
5939 return "DW_TAG_function_template";
5940 case DW_TAG_class_template
:
5941 return "DW_TAG_class_template";
5942 case DW_TAG_GNU_BINCL
:
5943 return "DW_TAG_GNU_BINCL";
5944 case DW_TAG_GNU_EINCL
:
5945 return "DW_TAG_GNU_EINCL";
5947 return "DW_TAG_<unknown>";
5951 /* Convert a DWARF attribute code into its string name. */
5954 dwarf_attr_name (unsigned int attr
)
5959 return "DW_AT_sibling";
5960 case DW_AT_location
:
5961 return "DW_AT_location";
5963 return "DW_AT_name";
5964 case DW_AT_ordering
:
5965 return "DW_AT_ordering";
5966 case DW_AT_subscr_data
:
5967 return "DW_AT_subscr_data";
5968 case DW_AT_byte_size
:
5969 return "DW_AT_byte_size";
5970 case DW_AT_bit_offset
:
5971 return "DW_AT_bit_offset";
5972 case DW_AT_bit_size
:
5973 return "DW_AT_bit_size";
5974 case DW_AT_element_list
:
5975 return "DW_AT_element_list";
5976 case DW_AT_stmt_list
:
5977 return "DW_AT_stmt_list";
5979 return "DW_AT_low_pc";
5981 return "DW_AT_high_pc";
5982 case DW_AT_language
:
5983 return "DW_AT_language";
5985 return "DW_AT_member";
5987 return "DW_AT_discr";
5988 case DW_AT_discr_value
:
5989 return "DW_AT_discr_value";
5990 case DW_AT_visibility
:
5991 return "DW_AT_visibility";
5993 return "DW_AT_import";
5994 case DW_AT_string_length
:
5995 return "DW_AT_string_length";
5996 case DW_AT_common_reference
:
5997 return "DW_AT_common_reference";
5998 case DW_AT_comp_dir
:
5999 return "DW_AT_comp_dir";
6000 case DW_AT_const_value
:
6001 return "DW_AT_const_value";
6002 case DW_AT_containing_type
:
6003 return "DW_AT_containing_type";
6004 case DW_AT_default_value
:
6005 return "DW_AT_default_value";
6007 return "DW_AT_inline";
6008 case DW_AT_is_optional
:
6009 return "DW_AT_is_optional";
6010 case DW_AT_lower_bound
:
6011 return "DW_AT_lower_bound";
6012 case DW_AT_producer
:
6013 return "DW_AT_producer";
6014 case DW_AT_prototyped
:
6015 return "DW_AT_prototyped";
6016 case DW_AT_return_addr
:
6017 return "DW_AT_return_addr";
6018 case DW_AT_start_scope
:
6019 return "DW_AT_start_scope";
6020 case DW_AT_bit_stride
:
6021 return "DW_AT_bit_stride";
6022 case DW_AT_upper_bound
:
6023 return "DW_AT_upper_bound";
6024 case DW_AT_abstract_origin
:
6025 return "DW_AT_abstract_origin";
6026 case DW_AT_accessibility
:
6027 return "DW_AT_accessibility";
6028 case DW_AT_address_class
:
6029 return "DW_AT_address_class";
6030 case DW_AT_artificial
:
6031 return "DW_AT_artificial";
6032 case DW_AT_base_types
:
6033 return "DW_AT_base_types";
6034 case DW_AT_calling_convention
:
6035 return "DW_AT_calling_convention";
6037 return "DW_AT_count";
6038 case DW_AT_data_member_location
:
6039 return "DW_AT_data_member_location";
6040 case DW_AT_decl_column
:
6041 return "DW_AT_decl_column";
6042 case DW_AT_decl_file
:
6043 return "DW_AT_decl_file";
6044 case DW_AT_decl_line
:
6045 return "DW_AT_decl_line";
6046 case DW_AT_declaration
:
6047 return "DW_AT_declaration";
6048 case DW_AT_discr_list
:
6049 return "DW_AT_discr_list";
6050 case DW_AT_encoding
:
6051 return "DW_AT_encoding";
6052 case DW_AT_external
:
6053 return "DW_AT_external";
6054 case DW_AT_explicit
:
6055 return "DW_AT_explicit";
6056 case DW_AT_frame_base
:
6057 return "DW_AT_frame_base";
6059 return "DW_AT_friend";
6060 case DW_AT_identifier_case
:
6061 return "DW_AT_identifier_case";
6062 case DW_AT_macro_info
:
6063 return "DW_AT_macro_info";
6064 case DW_AT_namelist_items
:
6065 return "DW_AT_namelist_items";
6066 case DW_AT_priority
:
6067 return "DW_AT_priority";
6069 return "DW_AT_segment";
6070 case DW_AT_specification
:
6071 return "DW_AT_specification";
6072 case DW_AT_static_link
:
6073 return "DW_AT_static_link";
6075 return "DW_AT_type";
6076 case DW_AT_use_location
:
6077 return "DW_AT_use_location";
6078 case DW_AT_variable_parameter
:
6079 return "DW_AT_variable_parameter";
6080 case DW_AT_virtuality
:
6081 return "DW_AT_virtuality";
6082 case DW_AT_vtable_elem_location
:
6083 return "DW_AT_vtable_elem_location";
6085 case DW_AT_allocated
:
6086 return "DW_AT_allocated";
6087 case DW_AT_associated
:
6088 return "DW_AT_associated";
6089 case DW_AT_data_location
:
6090 return "DW_AT_data_location";
6091 case DW_AT_byte_stride
:
6092 return "DW_AT_byte_stride";
6093 case DW_AT_entry_pc
:
6094 return "DW_AT_entry_pc";
6095 case DW_AT_use_UTF8
:
6096 return "DW_AT_use_UTF8";
6097 case DW_AT_extension
:
6098 return "DW_AT_extension";
6100 return "DW_AT_ranges";
6101 case DW_AT_trampoline
:
6102 return "DW_AT_trampoline";
6103 case DW_AT_call_column
:
6104 return "DW_AT_call_column";
6105 case DW_AT_call_file
:
6106 return "DW_AT_call_file";
6107 case DW_AT_call_line
:
6108 return "DW_AT_call_line";
6110 case DW_AT_MIPS_fde
:
6111 return "DW_AT_MIPS_fde";
6112 case DW_AT_MIPS_loop_begin
:
6113 return "DW_AT_MIPS_loop_begin";
6114 case DW_AT_MIPS_tail_loop_begin
:
6115 return "DW_AT_MIPS_tail_loop_begin";
6116 case DW_AT_MIPS_epilog_begin
:
6117 return "DW_AT_MIPS_epilog_begin";
6118 case DW_AT_MIPS_loop_unroll_factor
:
6119 return "DW_AT_MIPS_loop_unroll_factor";
6120 case DW_AT_MIPS_software_pipeline_depth
:
6121 return "DW_AT_MIPS_software_pipeline_depth";
6122 case DW_AT_MIPS_linkage_name
:
6123 return "DW_AT_MIPS_linkage_name";
6124 case DW_AT_MIPS_stride
:
6125 return "DW_AT_MIPS_stride";
6126 case DW_AT_MIPS_abstract_name
:
6127 return "DW_AT_MIPS_abstract_name";
6128 case DW_AT_MIPS_clone_origin
:
6129 return "DW_AT_MIPS_clone_origin";
6130 case DW_AT_MIPS_has_inlines
:
6131 return "DW_AT_MIPS_has_inlines";
6133 case DW_AT_sf_names
:
6134 return "DW_AT_sf_names";
6135 case DW_AT_src_info
:
6136 return "DW_AT_src_info";
6137 case DW_AT_mac_info
:
6138 return "DW_AT_mac_info";
6139 case DW_AT_src_coords
:
6140 return "DW_AT_src_coords";
6141 case DW_AT_body_begin
:
6142 return "DW_AT_body_begin";
6143 case DW_AT_body_end
:
6144 return "DW_AT_body_end";
6145 case DW_AT_GNU_vector
:
6146 return "DW_AT_GNU_vector";
6148 case DW_AT_VMS_rtnbeg_pd_address
:
6149 return "DW_AT_VMS_rtnbeg_pd_address";
6152 return "DW_AT_<unknown>";
6156 /* Convert a DWARF value form code into its string name. */
6159 dwarf_form_name (unsigned int form
)
6164 return "DW_FORM_addr";
6165 case DW_FORM_block2
:
6166 return "DW_FORM_block2";
6167 case DW_FORM_block4
:
6168 return "DW_FORM_block4";
6170 return "DW_FORM_data2";
6172 return "DW_FORM_data4";
6174 return "DW_FORM_data8";
6175 case DW_FORM_string
:
6176 return "DW_FORM_string";
6178 return "DW_FORM_block";
6179 case DW_FORM_block1
:
6180 return "DW_FORM_block1";
6182 return "DW_FORM_data1";
6184 return "DW_FORM_flag";
6186 return "DW_FORM_sdata";
6188 return "DW_FORM_strp";
6190 return "DW_FORM_udata";
6191 case DW_FORM_ref_addr
:
6192 return "DW_FORM_ref_addr";
6194 return "DW_FORM_ref1";
6196 return "DW_FORM_ref2";
6198 return "DW_FORM_ref4";
6200 return "DW_FORM_ref8";
6201 case DW_FORM_ref_udata
:
6202 return "DW_FORM_ref_udata";
6203 case DW_FORM_indirect
:
6204 return "DW_FORM_indirect";
6206 return "DW_FORM_<unknown>";
6210 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6211 instance of an inlined instance of a decl which is local to an inline
6212 function, so we have to trace all of the way back through the origin chain
6213 to find out what sort of node actually served as the original seed for the
6217 decl_ultimate_origin (const_tree decl
)
6219 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
6222 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6223 nodes in the function to point to themselves; ignore that if
6224 we're trying to output the abstract instance of this function. */
6225 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
6228 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6229 most distant ancestor, this should never happen. */
6230 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
6232 return DECL_ABSTRACT_ORIGIN (decl
);
6235 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6236 of a virtual function may refer to a base class, so we check the 'this'
6240 decl_class_context (tree decl
)
6242 tree context
= NULL_TREE
;
6244 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
6245 context
= DECL_CONTEXT (decl
);
6247 context
= TYPE_MAIN_VARIANT
6248 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6250 if (context
&& !TYPE_P (context
))
6251 context
= NULL_TREE
;
6256 /* Add an attribute/value pair to a DIE. */
6259 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
6261 /* Maybe this should be an assert? */
6265 if (die
->die_attr
== NULL
)
6266 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
6267 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
6270 static inline enum dw_val_class
6271 AT_class (dw_attr_ref a
)
6273 return a
->dw_attr_val
.val_class
;
6276 /* Add a flag value attribute to a DIE. */
6279 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
6283 attr
.dw_attr
= attr_kind
;
6284 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
6285 attr
.dw_attr_val
.v
.val_flag
= flag
;
6286 add_dwarf_attr (die
, &attr
);
6289 static inline unsigned
6290 AT_flag (dw_attr_ref a
)
6292 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
6293 return a
->dw_attr_val
.v
.val_flag
;
6296 /* Add a signed integer attribute value to a DIE. */
6299 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
6303 attr
.dw_attr
= attr_kind
;
6304 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
6305 attr
.dw_attr_val
.v
.val_int
= int_val
;
6306 add_dwarf_attr (die
, &attr
);
6309 static inline HOST_WIDE_INT
6310 AT_int (dw_attr_ref a
)
6312 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
6313 return a
->dw_attr_val
.v
.val_int
;
6316 /* Add an unsigned integer attribute value to a DIE. */
6319 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6320 unsigned HOST_WIDE_INT unsigned_val
)
6324 attr
.dw_attr
= attr_kind
;
6325 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
6326 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
6327 add_dwarf_attr (die
, &attr
);
6330 static inline unsigned HOST_WIDE_INT
6331 AT_unsigned (dw_attr_ref a
)
6333 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
6334 return a
->dw_attr_val
.v
.val_unsigned
;
6337 /* Add an unsigned double integer attribute value to a DIE. */
6340 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6341 long unsigned int val_hi
, long unsigned int val_low
)
6345 attr
.dw_attr
= attr_kind
;
6346 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
6347 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
6348 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
6349 add_dwarf_attr (die
, &attr
);
6352 /* Add a floating point attribute value to a DIE and return it. */
6355 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6356 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
6360 attr
.dw_attr
= attr_kind
;
6361 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
6362 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
6363 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
6364 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
6365 add_dwarf_attr (die
, &attr
);
6368 /* Hash and equality functions for debug_str_hash. */
6371 debug_str_do_hash (const void *x
)
6373 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
6377 debug_str_eq (const void *x1
, const void *x2
)
6379 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
6380 (const char *)x2
) == 0;
6383 static struct indirect_string_node
*
6384 find_AT_string (const char *str
)
6386 struct indirect_string_node
*node
;
6389 if (! debug_str_hash
)
6390 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
6391 debug_str_eq
, NULL
);
6393 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
6394 htab_hash_string (str
), INSERT
);
6397 node
= (struct indirect_string_node
*)
6398 ggc_alloc_cleared (sizeof (struct indirect_string_node
));
6399 node
->str
= ggc_strdup (str
);
6403 node
= (struct indirect_string_node
*) *slot
;
6409 /* Add a string attribute value to a DIE. */
6412 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
6415 struct indirect_string_node
*node
;
6417 node
= find_AT_string (str
);
6419 attr
.dw_attr
= attr_kind
;
6420 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
6421 attr
.dw_attr_val
.v
.val_str
= node
;
6422 add_dwarf_attr (die
, &attr
);
6425 static inline const char *
6426 AT_string (dw_attr_ref a
)
6428 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
6429 return a
->dw_attr_val
.v
.val_str
->str
;
6432 /* Find out whether a string should be output inline in DIE
6433 or out-of-line in .debug_str section. */
6435 static enum dwarf_form
6436 AT_string_form (dw_attr_ref a
)
6438 struct indirect_string_node
*node
;
6442 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
6444 node
= a
->dw_attr_val
.v
.val_str
;
6448 len
= strlen (node
->str
) + 1;
6450 /* If the string is shorter or equal to the size of the reference, it is
6451 always better to put it inline. */
6452 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
6453 return node
->form
= DW_FORM_string
;
6455 /* If we cannot expect the linker to merge strings in .debug_str
6456 section, only put it into .debug_str if it is worth even in this
6458 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
6459 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
6460 return node
->form
= DW_FORM_string
;
6462 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
6463 ++dw2_string_counter
;
6464 node
->label
= xstrdup (label
);
6466 return node
->form
= DW_FORM_strp
;
6469 /* Add a DIE reference attribute value to a DIE. */
6472 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
6476 attr
.dw_attr
= attr_kind
;
6477 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
6478 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
6479 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
6480 add_dwarf_attr (die
, &attr
);
6483 /* Add an AT_specification attribute to a DIE, and also make the back
6484 pointer from the specification to the definition. */
6487 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
6489 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
6490 gcc_assert (!targ_die
->die_definition
);
6491 targ_die
->die_definition
= die
;
6494 static inline dw_die_ref
6495 AT_ref (dw_attr_ref a
)
6497 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6498 return a
->dw_attr_val
.v
.val_die_ref
.die
;
6502 AT_ref_external (dw_attr_ref a
)
6504 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
6505 return a
->dw_attr_val
.v
.val_die_ref
.external
;
6511 set_AT_ref_external (dw_attr_ref a
, int i
)
6513 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
6514 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
6517 /* Add an FDE reference attribute value to a DIE. */
6520 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
6524 attr
.dw_attr
= attr_kind
;
6525 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
6526 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
6527 add_dwarf_attr (die
, &attr
);
6530 /* Add a location description attribute value to a DIE. */
6533 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
6537 attr
.dw_attr
= attr_kind
;
6538 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
6539 attr
.dw_attr_val
.v
.val_loc
= loc
;
6540 add_dwarf_attr (die
, &attr
);
6543 static inline dw_loc_descr_ref
6544 AT_loc (dw_attr_ref a
)
6546 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
6547 return a
->dw_attr_val
.v
.val_loc
;
6551 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
6555 attr
.dw_attr
= attr_kind
;
6556 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
6557 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
6558 add_dwarf_attr (die
, &attr
);
6559 have_location_lists
= true;
6562 static inline dw_loc_list_ref
6563 AT_loc_list (dw_attr_ref a
)
6565 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
6566 return a
->dw_attr_val
.v
.val_loc_list
;
6569 /* Add an address constant attribute value to a DIE. */
6572 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
6576 attr
.dw_attr
= attr_kind
;
6577 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
6578 attr
.dw_attr_val
.v
.val_addr
= addr
;
6579 add_dwarf_attr (die
, &attr
);
6582 /* Get the RTX from to an address DIE attribute. */
6585 AT_addr (dw_attr_ref a
)
6587 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
6588 return a
->dw_attr_val
.v
.val_addr
;
6591 /* Add a file attribute value to a DIE. */
6594 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6595 struct dwarf_file_data
*fd
)
6599 attr
.dw_attr
= attr_kind
;
6600 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
6601 attr
.dw_attr_val
.v
.val_file
= fd
;
6602 add_dwarf_attr (die
, &attr
);
6605 /* Get the dwarf_file_data from a file DIE attribute. */
6607 static inline struct dwarf_file_data
*
6608 AT_file (dw_attr_ref a
)
6610 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
6611 return a
->dw_attr_val
.v
.val_file
;
6614 /* Add a label identifier attribute value to a DIE. */
6617 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
6621 attr
.dw_attr
= attr_kind
;
6622 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
6623 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
6624 add_dwarf_attr (die
, &attr
);
6627 /* Add a section offset attribute value to a DIE, an offset into the
6628 debug_line section. */
6631 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6636 attr
.dw_attr
= attr_kind
;
6637 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
6638 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6639 add_dwarf_attr (die
, &attr
);
6642 /* Add a section offset attribute value to a DIE, an offset into the
6643 debug_macinfo section. */
6646 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6651 attr
.dw_attr
= attr_kind
;
6652 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
6653 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
6654 add_dwarf_attr (die
, &attr
);
6657 /* Add an offset attribute value to a DIE. */
6660 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6661 unsigned HOST_WIDE_INT offset
)
6665 attr
.dw_attr
= attr_kind
;
6666 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
6667 attr
.dw_attr_val
.v
.val_offset
= offset
;
6668 add_dwarf_attr (die
, &attr
);
6671 /* Add an range_list attribute value to a DIE. */
6674 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
6675 long unsigned int offset
)
6679 attr
.dw_attr
= attr_kind
;
6680 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
6681 attr
.dw_attr_val
.v
.val_offset
= offset
;
6682 add_dwarf_attr (die
, &attr
);
6685 static inline const char *
6686 AT_lbl (dw_attr_ref a
)
6688 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
6689 || AT_class (a
) == dw_val_class_lineptr
6690 || AT_class (a
) == dw_val_class_macptr
));
6691 return a
->dw_attr_val
.v
.val_lbl_id
;
6694 /* Get the attribute of type attr_kind. */
6697 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6701 dw_die_ref spec
= NULL
;
6706 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6707 if (a
->dw_attr
== attr_kind
)
6709 else if (a
->dw_attr
== DW_AT_specification
6710 || a
->dw_attr
== DW_AT_abstract_origin
)
6714 return get_AT (spec
, attr_kind
);
6719 /* Return the "low pc" attribute value, typically associated with a subprogram
6720 DIE. Return null if the "low pc" attribute is either not present, or if it
6721 cannot be represented as an assembler label identifier. */
6723 static inline const char *
6724 get_AT_low_pc (dw_die_ref die
)
6726 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
6728 return a
? AT_lbl (a
) : NULL
;
6731 /* Return the "high pc" attribute value, typically associated with a subprogram
6732 DIE. Return null if the "high pc" attribute is either not present, or if it
6733 cannot be represented as an assembler label identifier. */
6735 static inline const char *
6736 get_AT_hi_pc (dw_die_ref die
)
6738 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
6740 return a
? AT_lbl (a
) : NULL
;
6743 /* Return the value of the string attribute designated by ATTR_KIND, or
6744 NULL if it is not present. */
6746 static inline const char *
6747 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6749 dw_attr_ref a
= get_AT (die
, attr_kind
);
6751 return a
? AT_string (a
) : NULL
;
6754 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6755 if it is not present. */
6758 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6760 dw_attr_ref a
= get_AT (die
, attr_kind
);
6762 return a
? AT_flag (a
) : 0;
6765 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6766 if it is not present. */
6768 static inline unsigned
6769 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6771 dw_attr_ref a
= get_AT (die
, attr_kind
);
6773 return a
? AT_unsigned (a
) : 0;
6776 static inline dw_die_ref
6777 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6779 dw_attr_ref a
= get_AT (die
, attr_kind
);
6781 return a
? AT_ref (a
) : NULL
;
6784 static inline struct dwarf_file_data
*
6785 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6787 dw_attr_ref a
= get_AT (die
, attr_kind
);
6789 return a
? AT_file (a
) : NULL
;
6792 /* Return TRUE if the language is C or C++. */
6797 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6799 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
6800 || lang
== DW_LANG_C99
6801 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
6804 /* Return TRUE if the language is C++. */
6809 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6811 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
6814 /* Return TRUE if the language is Fortran. */
6819 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6821 return (lang
== DW_LANG_Fortran77
6822 || lang
== DW_LANG_Fortran90
6823 || lang
== DW_LANG_Fortran95
);
6826 /* Return TRUE if the language is Java. */
6831 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6833 return lang
== DW_LANG_Java
;
6836 /* Return TRUE if the language is Ada. */
6841 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6843 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
6846 /* Remove the specified attribute if present. */
6849 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6857 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6858 if (a
->dw_attr
== attr_kind
)
6860 if (AT_class (a
) == dw_val_class_str
)
6861 if (a
->dw_attr_val
.v
.val_str
->refcount
)
6862 a
->dw_attr_val
.v
.val_str
->refcount
--;
6864 /* VEC_ordered_remove should help reduce the number of abbrevs
6866 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
6871 /* Remove CHILD from its parent. PREV must have the property that
6872 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6875 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
6877 gcc_assert (child
->die_parent
== prev
->die_parent
);
6878 gcc_assert (prev
->die_sib
== child
);
6881 gcc_assert (child
->die_parent
->die_child
== child
);
6885 prev
->die_sib
= child
->die_sib
;
6886 if (child
->die_parent
->die_child
== child
)
6887 child
->die_parent
->die_child
= prev
;
6890 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6894 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
6900 dw_die_ref prev
= c
;
6902 while (c
->die_tag
== tag
)
6904 remove_child_with_prev (c
, prev
);
6905 /* Might have removed every child. */
6906 if (c
== c
->die_sib
)
6910 } while (c
!= die
->die_child
);
6913 /* Add a CHILD_DIE as the last child of DIE. */
6916 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
6918 /* FIXME this should probably be an assert. */
6919 if (! die
|| ! child_die
)
6921 gcc_assert (die
!= child_die
);
6923 child_die
->die_parent
= die
;
6926 child_die
->die_sib
= die
->die_child
->die_sib
;
6927 die
->die_child
->die_sib
= child_die
;
6930 child_die
->die_sib
= child_die
;
6931 die
->die_child
= child_die
;
6934 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6935 is the specification, to the end of PARENT's list of children.
6936 This is done by removing and re-adding it. */
6939 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
6943 /* We want the declaration DIE from inside the class, not the
6944 specification DIE at toplevel. */
6945 if (child
->die_parent
!= parent
)
6947 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
6953 gcc_assert (child
->die_parent
== parent
6954 || (child
->die_parent
6955 == get_AT_ref (parent
, DW_AT_specification
)));
6957 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
6958 if (p
->die_sib
== child
)
6960 remove_child_with_prev (child
, p
);
6964 add_child_die (parent
, child
);
6967 /* Return a pointer to a newly created DIE node. */
6969 static inline dw_die_ref
6970 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
6972 dw_die_ref die
= GGC_CNEW (die_node
);
6974 die
->die_tag
= tag_value
;
6976 if (parent_die
!= NULL
)
6977 add_child_die (parent_die
, die
);
6980 limbo_die_node
*limbo_node
;
6982 limbo_node
= GGC_CNEW (limbo_die_node
);
6983 limbo_node
->die
= die
;
6984 limbo_node
->created_for
= t
;
6985 limbo_node
->next
= limbo_die_list
;
6986 limbo_die_list
= limbo_node
;
6992 /* Return the DIE associated with the given type specifier. */
6994 static inline dw_die_ref
6995 lookup_type_die (tree type
)
6997 return TYPE_SYMTAB_DIE (type
);
7000 /* Equate a DIE to a given type specifier. */
7003 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
7005 TYPE_SYMTAB_DIE (type
) = type_die
;
7008 /* Returns a hash value for X (which really is a die_struct). */
7011 decl_die_table_hash (const void *x
)
7013 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
7016 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7019 decl_die_table_eq (const void *x
, const void *y
)
7021 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7024 /* Return the DIE associated with a given declaration. */
7026 static inline dw_die_ref
7027 lookup_decl_die (tree decl
)
7029 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
7032 /* Returns a hash value for X (which really is a var_loc_list). */
7035 decl_loc_table_hash (const void *x
)
7037 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
7040 /* Return nonzero if decl_id of var_loc_list X is the same as
7044 decl_loc_table_eq (const void *x
, const void *y
)
7046 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
7049 /* Return the var_loc list associated with a given declaration. */
7051 static inline var_loc_list
*
7052 lookup_decl_loc (const_tree decl
)
7054 return (var_loc_list
*)
7055 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
7058 /* Equate a DIE to a particular declaration. */
7061 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
7063 unsigned int decl_id
= DECL_UID (decl
);
7066 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
7068 decl_die
->decl_id
= decl_id
;
7071 /* Add a variable location node to the linked list for DECL. */
7074 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
7076 unsigned int decl_id
= DECL_UID (decl
);
7080 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
7083 temp
= GGC_CNEW (var_loc_list
);
7084 temp
->decl_id
= decl_id
;
7088 temp
= (var_loc_list
*) *slot
;
7092 /* If the current location is the same as the end of the list,
7093 and either both or neither of the locations is uninitialized,
7094 we have nothing to do. */
7095 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
7096 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
7097 || ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
7098 != NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
))
7099 && ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
7100 == VAR_INIT_STATUS_UNINITIALIZED
)
7101 || (NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
)
7102 == VAR_INIT_STATUS_UNINITIALIZED
))))
7104 /* Add LOC to the end of list and update LAST. */
7105 temp
->last
->next
= loc
;
7109 /* Do not add empty location to the beginning of the list. */
7110 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
7117 /* Keep track of the number of spaces used to indent the
7118 output of the debugging routines that print the structure of
7119 the DIE internal representation. */
7120 static int print_indent
;
7122 /* Indent the line the number of spaces given by print_indent. */
7125 print_spaces (FILE *outfile
)
7127 fprintf (outfile
, "%*s", print_indent
, "");
7130 /* Print the information associated with a given DIE, and its children.
7131 This routine is a debugging aid only. */
7134 print_die (dw_die_ref die
, FILE *outfile
)
7140 print_spaces (outfile
);
7141 fprintf (outfile
, "DIE %4ld: %s\n",
7142 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
7143 print_spaces (outfile
);
7144 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
7145 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
7147 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7149 print_spaces (outfile
);
7150 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
7152 switch (AT_class (a
))
7154 case dw_val_class_addr
:
7155 fprintf (outfile
, "address");
7157 case dw_val_class_offset
:
7158 fprintf (outfile
, "offset");
7160 case dw_val_class_loc
:
7161 fprintf (outfile
, "location descriptor");
7163 case dw_val_class_loc_list
:
7164 fprintf (outfile
, "location list -> label:%s",
7165 AT_loc_list (a
)->ll_symbol
);
7167 case dw_val_class_range_list
:
7168 fprintf (outfile
, "range list");
7170 case dw_val_class_const
:
7171 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
7173 case dw_val_class_unsigned_const
:
7174 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
7176 case dw_val_class_long_long
:
7177 fprintf (outfile
, "constant (%lu,%lu)",
7178 a
->dw_attr_val
.v
.val_long_long
.hi
,
7179 a
->dw_attr_val
.v
.val_long_long
.low
);
7181 case dw_val_class_vec
:
7182 fprintf (outfile
, "floating-point or vector constant");
7184 case dw_val_class_flag
:
7185 fprintf (outfile
, "%u", AT_flag (a
));
7187 case dw_val_class_die_ref
:
7188 if (AT_ref (a
) != NULL
)
7190 if (AT_ref (a
)->die_symbol
)
7191 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
7193 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
7196 fprintf (outfile
, "die -> <null>");
7198 case dw_val_class_lbl_id
:
7199 case dw_val_class_lineptr
:
7200 case dw_val_class_macptr
:
7201 fprintf (outfile
, "label: %s", AT_lbl (a
));
7203 case dw_val_class_str
:
7204 if (AT_string (a
) != NULL
)
7205 fprintf (outfile
, "\"%s\"", AT_string (a
));
7207 fprintf (outfile
, "<null>");
7209 case dw_val_class_file
:
7210 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
7211 AT_file (a
)->emitted_number
);
7217 fprintf (outfile
, "\n");
7220 if (die
->die_child
!= NULL
)
7223 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
7226 if (print_indent
== 0)
7227 fprintf (outfile
, "\n");
7230 /* Print the contents of the source code line number correspondence table.
7231 This routine is a debugging aid only. */
7234 print_dwarf_line_table (FILE *outfile
)
7237 dw_line_info_ref line_info
;
7239 fprintf (outfile
, "\n\nDWARF source line information\n");
7240 for (i
= 1; i
< line_info_table_in_use
; i
++)
7242 line_info
= &line_info_table
[i
];
7243 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
7244 line_info
->dw_file_num
,
7245 line_info
->dw_line_num
);
7248 fprintf (outfile
, "\n\n");
7251 /* Print the information collected for a given DIE. */
7254 debug_dwarf_die (dw_die_ref die
)
7256 print_die (die
, stderr
);
7259 /* Print all DWARF information collected for the compilation unit.
7260 This routine is a debugging aid only. */
7266 print_die (comp_unit_die
, stderr
);
7267 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
7268 print_dwarf_line_table (stderr
);
7271 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7272 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7273 DIE that marks the start of the DIEs for this include file. */
7276 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
7278 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
7279 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
7281 new_unit
->die_sib
= old_unit
;
7285 /* Close an include-file CU and reopen the enclosing one. */
7288 pop_compile_unit (dw_die_ref old_unit
)
7290 dw_die_ref new_unit
= old_unit
->die_sib
;
7292 old_unit
->die_sib
= NULL
;
7296 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7297 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7299 /* Calculate the checksum of a location expression. */
7302 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
7306 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
7308 CHECKSUM (loc
->dw_loc_oprnd1
);
7309 CHECKSUM (loc
->dw_loc_oprnd2
);
7312 /* Calculate the checksum of an attribute. */
7315 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
7317 dw_loc_descr_ref loc
;
7320 CHECKSUM (at
->dw_attr
);
7322 /* We don't care that this was compiled with a different compiler
7323 snapshot; if the output is the same, that's what matters. */
7324 if (at
->dw_attr
== DW_AT_producer
)
7327 switch (AT_class (at
))
7329 case dw_val_class_const
:
7330 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
7332 case dw_val_class_unsigned_const
:
7333 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
7335 case dw_val_class_long_long
:
7336 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
7338 case dw_val_class_vec
:
7339 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
7341 case dw_val_class_flag
:
7342 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
7344 case dw_val_class_str
:
7345 CHECKSUM_STRING (AT_string (at
));
7348 case dw_val_class_addr
:
7350 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
7351 CHECKSUM_STRING (XSTR (r
, 0));
7354 case dw_val_class_offset
:
7355 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
7358 case dw_val_class_loc
:
7359 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
7360 loc_checksum (loc
, ctx
);
7363 case dw_val_class_die_ref
:
7364 die_checksum (AT_ref (at
), ctx
, mark
);
7367 case dw_val_class_fde_ref
:
7368 case dw_val_class_lbl_id
:
7369 case dw_val_class_lineptr
:
7370 case dw_val_class_macptr
:
7373 case dw_val_class_file
:
7374 CHECKSUM_STRING (AT_file (at
)->filename
);
7382 /* Calculate the checksum of a DIE. */
7385 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
7391 /* To avoid infinite recursion. */
7394 CHECKSUM (die
->die_mark
);
7397 die
->die_mark
= ++(*mark
);
7399 CHECKSUM (die
->die_tag
);
7401 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7402 attr_checksum (a
, ctx
, mark
);
7404 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
7408 #undef CHECKSUM_STRING
7410 /* Do the location expressions look same? */
7412 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
7414 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
7415 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
7416 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
7419 /* Do the values look the same? */
7421 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
7423 dw_loc_descr_ref loc1
, loc2
;
7426 if (v1
->val_class
!= v2
->val_class
)
7429 switch (v1
->val_class
)
7431 case dw_val_class_const
:
7432 return v1
->v
.val_int
== v2
->v
.val_int
;
7433 case dw_val_class_unsigned_const
:
7434 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
7435 case dw_val_class_long_long
:
7436 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
7437 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
7438 case dw_val_class_vec
:
7439 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
7440 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
7442 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
7443 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
7446 case dw_val_class_flag
:
7447 return v1
->v
.val_flag
== v2
->v
.val_flag
;
7448 case dw_val_class_str
:
7449 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
7451 case dw_val_class_addr
:
7452 r1
= v1
->v
.val_addr
;
7453 r2
= v2
->v
.val_addr
;
7454 if (GET_CODE (r1
) != GET_CODE (r2
))
7456 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
7457 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
7459 case dw_val_class_offset
:
7460 return v1
->v
.val_offset
== v2
->v
.val_offset
;
7462 case dw_val_class_loc
:
7463 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
7465 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
7466 if (!same_loc_p (loc1
, loc2
, mark
))
7468 return !loc1
&& !loc2
;
7470 case dw_val_class_die_ref
:
7471 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
7473 case dw_val_class_fde_ref
:
7474 case dw_val_class_lbl_id
:
7475 case dw_val_class_lineptr
:
7476 case dw_val_class_macptr
:
7479 case dw_val_class_file
:
7480 return v1
->v
.val_file
== v2
->v
.val_file
;
7487 /* Do the attributes look the same? */
7490 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
7492 if (at1
->dw_attr
!= at2
->dw_attr
)
7495 /* We don't care that this was compiled with a different compiler
7496 snapshot; if the output is the same, that's what matters. */
7497 if (at1
->dw_attr
== DW_AT_producer
)
7500 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
7503 /* Do the dies look the same? */
7506 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
7512 /* To avoid infinite recursion. */
7514 return die1
->die_mark
== die2
->die_mark
;
7515 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
7517 if (die1
->die_tag
!= die2
->die_tag
)
7520 if (VEC_length (dw_attr_node
, die1
->die_attr
)
7521 != VEC_length (dw_attr_node
, die2
->die_attr
))
7524 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
7525 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
7528 c1
= die1
->die_child
;
7529 c2
= die2
->die_child
;
7538 if (!same_die_p (c1
, c2
, mark
))
7542 if (c1
== die1
->die_child
)
7544 if (c2
== die2
->die_child
)
7554 /* Do the dies look the same? Wrapper around same_die_p. */
7557 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
7560 int ret
= same_die_p (die1
, die2
, &mark
);
7562 unmark_all_dies (die1
);
7563 unmark_all_dies (die2
);
7568 /* The prefix to attach to symbols on DIEs in the current comdat debug
7570 static char *comdat_symbol_id
;
7572 /* The index of the current symbol within the current comdat CU. */
7573 static unsigned int comdat_symbol_number
;
7575 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7576 children, and set comdat_symbol_id accordingly. */
7579 compute_section_prefix (dw_die_ref unit_die
)
7581 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
7582 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
7583 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
7586 unsigned char checksum
[16];
7589 /* Compute the checksum of the DIE, then append part of it as hex digits to
7590 the name filename of the unit. */
7592 md5_init_ctx (&ctx
);
7594 die_checksum (unit_die
, &ctx
, &mark
);
7595 unmark_all_dies (unit_die
);
7596 md5_finish_ctx (&ctx
, checksum
);
7598 sprintf (name
, "%s.", base
);
7599 clean_symbol_name (name
);
7601 p
= name
+ strlen (name
);
7602 for (i
= 0; i
< 4; i
++)
7604 sprintf (p
, "%.2x", checksum
[i
]);
7608 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
7609 comdat_symbol_number
= 0;
7612 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7615 is_type_die (dw_die_ref die
)
7617 switch (die
->die_tag
)
7619 case DW_TAG_array_type
:
7620 case DW_TAG_class_type
:
7621 case DW_TAG_interface_type
:
7622 case DW_TAG_enumeration_type
:
7623 case DW_TAG_pointer_type
:
7624 case DW_TAG_reference_type
:
7625 case DW_TAG_string_type
:
7626 case DW_TAG_structure_type
:
7627 case DW_TAG_subroutine_type
:
7628 case DW_TAG_union_type
:
7629 case DW_TAG_ptr_to_member_type
:
7630 case DW_TAG_set_type
:
7631 case DW_TAG_subrange_type
:
7632 case DW_TAG_base_type
:
7633 case DW_TAG_const_type
:
7634 case DW_TAG_file_type
:
7635 case DW_TAG_packed_type
:
7636 case DW_TAG_volatile_type
:
7637 case DW_TAG_typedef
:
7644 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7645 Basically, we want to choose the bits that are likely to be shared between
7646 compilations (types) and leave out the bits that are specific to individual
7647 compilations (functions). */
7650 is_comdat_die (dw_die_ref c
)
7652 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7653 we do for stabs. The advantage is a greater likelihood of sharing between
7654 objects that don't include headers in the same order (and therefore would
7655 put the base types in a different comdat). jason 8/28/00 */
7657 if (c
->die_tag
== DW_TAG_base_type
)
7660 if (c
->die_tag
== DW_TAG_pointer_type
7661 || c
->die_tag
== DW_TAG_reference_type
7662 || c
->die_tag
== DW_TAG_const_type
7663 || c
->die_tag
== DW_TAG_volatile_type
)
7665 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
7667 return t
? is_comdat_die (t
) : 0;
7670 return is_type_die (c
);
7673 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7674 compilation unit. */
7677 is_symbol_die (dw_die_ref c
)
7679 return (is_type_die (c
)
7680 || (get_AT (c
, DW_AT_declaration
)
7681 && !get_AT (c
, DW_AT_specification
))
7682 || c
->die_tag
== DW_TAG_namespace
7683 || c
->die_tag
== DW_TAG_module
);
7687 gen_internal_sym (const char *prefix
)
7691 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7692 return xstrdup (buf
);
7695 /* Assign symbols to all worthy DIEs under DIE. */
7698 assign_symbol_names (dw_die_ref die
)
7702 if (is_symbol_die (die
))
7704 if (comdat_symbol_id
)
7706 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7708 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7709 comdat_symbol_id
, comdat_symbol_number
++);
7710 die
->die_symbol
= xstrdup (p
);
7713 die
->die_symbol
= gen_internal_sym ("LDIE");
7716 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7719 struct cu_hash_table_entry
7722 unsigned min_comdat_num
, max_comdat_num
;
7723 struct cu_hash_table_entry
*next
;
7726 /* Routines to manipulate hash table of CUs. */
7728 htab_cu_hash (const void *of
)
7730 const struct cu_hash_table_entry
*const entry
=
7731 (const struct cu_hash_table_entry
*) of
;
7733 return htab_hash_string (entry
->cu
->die_symbol
);
7737 htab_cu_eq (const void *of1
, const void *of2
)
7739 const struct cu_hash_table_entry
*const entry1
=
7740 (const struct cu_hash_table_entry
*) of1
;
7741 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7743 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
7747 htab_cu_del (void *what
)
7749 struct cu_hash_table_entry
*next
,
7750 *entry
= (struct cu_hash_table_entry
*) what
;
7760 /* Check whether we have already seen this CU and set up SYM_NUM
7763 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
7765 struct cu_hash_table_entry dummy
;
7766 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7768 dummy
.max_comdat_num
= 0;
7770 slot
= (struct cu_hash_table_entry
**)
7771 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7775 for (; entry
; last
= entry
, entry
= entry
->next
)
7777 if (same_die_p_wrap (cu
, entry
->cu
))
7783 *sym_num
= entry
->min_comdat_num
;
7787 entry
= XCNEW (struct cu_hash_table_entry
);
7789 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7790 entry
->next
= *slot
;
7796 /* Record SYM_NUM to record of CU in HTABLE. */
7798 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
7800 struct cu_hash_table_entry
**slot
, *entry
;
7802 slot
= (struct cu_hash_table_entry
**)
7803 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
7807 entry
->max_comdat_num
= sym_num
;
7810 /* Traverse the DIE (which is always comp_unit_die), and set up
7811 additional compilation units for each of the include files we see
7812 bracketed by BINCL/EINCL. */
7815 break_out_includes (dw_die_ref die
)
7818 dw_die_ref unit
= NULL
;
7819 limbo_die_node
*node
, **pnode
;
7820 htab_t cu_hash_table
;
7824 dw_die_ref prev
= c
;
7826 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7827 || (unit
&& is_comdat_die (c
)))
7829 dw_die_ref next
= c
->die_sib
;
7831 /* This DIE is for a secondary CU; remove it from the main one. */
7832 remove_child_with_prev (c
, prev
);
7834 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7835 unit
= push_new_compile_unit (unit
, c
);
7836 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7837 unit
= pop_compile_unit (unit
);
7839 add_child_die (unit
, c
);
7841 if (c
== die
->die_child
)
7844 } while (c
!= die
->die_child
);
7847 /* We can only use this in debugging, since the frontend doesn't check
7848 to make sure that we leave every include file we enter. */
7852 assign_symbol_names (die
);
7853 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
7854 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7860 compute_section_prefix (node
->die
);
7861 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
7862 &comdat_symbol_number
);
7863 assign_symbol_names (node
->die
);
7865 *pnode
= node
->next
;
7868 pnode
= &node
->next
;
7869 record_comdat_symbol_number (node
->die
, cu_hash_table
,
7870 comdat_symbol_number
);
7873 htab_delete (cu_hash_table
);
7876 /* Traverse the DIE and add a sibling attribute if it may have the
7877 effect of speeding up access to siblings. To save some space,
7878 avoid generating sibling attributes for DIE's without children. */
7881 add_sibling_attributes (dw_die_ref die
)
7885 if (! die
->die_child
)
7888 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7889 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7891 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7894 /* Output all location lists for the DIE and its children. */
7897 output_location_lists (dw_die_ref die
)
7903 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7904 if (AT_class (a
) == dw_val_class_loc_list
)
7905 output_loc_list (AT_loc_list (a
));
7907 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7910 /* The format of each DIE (and its attribute value pairs) is encoded in an
7911 abbreviation table. This routine builds the abbreviation table and assigns
7912 a unique abbreviation id for each abbreviation entry. The children of each
7913 die are visited recursively. */
7916 build_abbrev_table (dw_die_ref die
)
7918 unsigned long abbrev_id
;
7919 unsigned int n_alloc
;
7924 /* Scan the DIE references, and mark as external any that refer to
7925 DIEs from other CUs (i.e. those which are not marked). */
7926 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7927 if (AT_class (a
) == dw_val_class_die_ref
7928 && AT_ref (a
)->die_mark
== 0)
7930 gcc_assert (AT_ref (a
)->die_symbol
);
7931 set_AT_ref_external (a
, 1);
7934 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7936 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7937 dw_attr_ref die_a
, abbrev_a
;
7941 if (abbrev
->die_tag
!= die
->die_tag
)
7943 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7946 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7947 != VEC_length (dw_attr_node
, die
->die_attr
))
7950 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
7952 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7953 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7954 || (value_format (abbrev_a
) != value_format (die_a
)))
7964 if (abbrev_id
>= abbrev_die_table_in_use
)
7966 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7968 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7969 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7972 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7973 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7974 abbrev_die_table_allocated
= n_alloc
;
7977 ++abbrev_die_table_in_use
;
7978 abbrev_die_table
[abbrev_id
] = die
;
7981 die
->die_abbrev
= abbrev_id
;
7982 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7985 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7988 constant_size (unsigned HOST_WIDE_INT value
)
7995 log
= floor_log2 (value
);
7998 log
= 1 << (floor_log2 (log
) + 1);
8003 /* Return the size of a DIE as it is represented in the
8004 .debug_info section. */
8006 static unsigned long
8007 size_of_die (dw_die_ref die
)
8009 unsigned long size
= 0;
8013 size
+= size_of_uleb128 (die
->die_abbrev
);
8014 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8016 switch (AT_class (a
))
8018 case dw_val_class_addr
:
8019 size
+= DWARF2_ADDR_SIZE
;
8021 case dw_val_class_offset
:
8022 size
+= DWARF_OFFSET_SIZE
;
8024 case dw_val_class_loc
:
8026 unsigned long lsize
= size_of_locs (AT_loc (a
));
8029 size
+= constant_size (lsize
);
8033 case dw_val_class_loc_list
:
8034 size
+= DWARF_OFFSET_SIZE
;
8036 case dw_val_class_range_list
:
8037 size
+= DWARF_OFFSET_SIZE
;
8039 case dw_val_class_const
:
8040 size
+= size_of_sleb128 (AT_int (a
));
8042 case dw_val_class_unsigned_const
:
8043 size
+= constant_size (AT_unsigned (a
));
8045 case dw_val_class_long_long
:
8046 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
8048 case dw_val_class_vec
:
8049 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8050 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8051 + a
->dw_attr_val
.v
.val_vec
.length
8052 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8054 case dw_val_class_flag
:
8057 case dw_val_class_die_ref
:
8058 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8059 whereas in DWARF3 it's always sized as an offset. */
8060 if (AT_ref_external (a
) && dwarf_version
== 2)
8061 size
+= DWARF2_ADDR_SIZE
;
8063 size
+= DWARF_OFFSET_SIZE
;
8065 case dw_val_class_fde_ref
:
8066 size
+= DWARF_OFFSET_SIZE
;
8068 case dw_val_class_lbl_id
:
8069 size
+= DWARF2_ADDR_SIZE
;
8071 case dw_val_class_lineptr
:
8072 case dw_val_class_macptr
:
8073 size
+= DWARF_OFFSET_SIZE
;
8075 case dw_val_class_str
:
8076 if (AT_string_form (a
) == DW_FORM_strp
)
8077 size
+= DWARF_OFFSET_SIZE
;
8079 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8081 case dw_val_class_file
:
8082 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8092 /* Size the debugging information associated with a given DIE. Visits the
8093 DIE's children recursively. Updates the global variable next_die_offset, on
8094 each time through. Uses the current value of next_die_offset to update the
8095 die_offset field in each DIE. */
8098 calc_die_sizes (dw_die_ref die
)
8102 die
->die_offset
= next_die_offset
;
8103 next_die_offset
+= size_of_die (die
);
8105 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8107 if (die
->die_child
!= NULL
)
8108 /* Count the null byte used to terminate sibling lists. */
8109 next_die_offset
+= 1;
8112 /* Set the marks for a die and its children. We do this so
8113 that we know whether or not a reference needs to use FORM_ref_addr; only
8114 DIEs in the same CU will be marked. We used to clear out the offset
8115 and use that as the flag, but ran into ordering problems. */
8118 mark_dies (dw_die_ref die
)
8122 gcc_assert (!die
->die_mark
);
8125 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8128 /* Clear the marks for a die and its children. */
8131 unmark_dies (dw_die_ref die
)
8135 gcc_assert (die
->die_mark
);
8138 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8141 /* Clear the marks for a die, its children and referred dies. */
8144 unmark_all_dies (dw_die_ref die
)
8154 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8156 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8157 if (AT_class (a
) == dw_val_class_die_ref
)
8158 unmark_all_dies (AT_ref (a
));
8161 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8162 generated for the compilation unit. */
8164 static unsigned long
8165 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
8171 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8172 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
8173 if (names
!= pubtype_table
8174 || p
->die
->die_offset
!= 0
8175 || !flag_eliminate_unused_debug_types
)
8176 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
8178 size
+= DWARF_OFFSET_SIZE
;
8182 /* Return the size of the information in the .debug_aranges section. */
8184 static unsigned long
8185 size_of_aranges (void)
8189 size
= DWARF_ARANGES_HEADER_SIZE
;
8191 /* Count the address/length pair for this compilation unit. */
8192 if (text_section_used
)
8193 size
+= 2 * DWARF2_ADDR_SIZE
;
8194 if (cold_text_section_used
)
8195 size
+= 2 * DWARF2_ADDR_SIZE
;
8196 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
8198 /* Count the two zero words used to terminated the address range table. */
8199 size
+= 2 * DWARF2_ADDR_SIZE
;
8203 /* Select the encoding of an attribute value. */
8205 static enum dwarf_form
8206 value_format (dw_attr_ref a
)
8208 switch (a
->dw_attr_val
.val_class
)
8210 case dw_val_class_addr
:
8211 return DW_FORM_addr
;
8212 case dw_val_class_range_list
:
8213 case dw_val_class_offset
:
8214 case dw_val_class_loc_list
:
8215 switch (DWARF_OFFSET_SIZE
)
8218 return DW_FORM_data4
;
8220 return DW_FORM_data8
;
8224 case dw_val_class_loc
:
8225 switch (constant_size (size_of_locs (AT_loc (a
))))
8228 return DW_FORM_block1
;
8230 return DW_FORM_block2
;
8234 case dw_val_class_const
:
8235 return DW_FORM_sdata
;
8236 case dw_val_class_unsigned_const
:
8237 switch (constant_size (AT_unsigned (a
)))
8240 return DW_FORM_data1
;
8242 return DW_FORM_data2
;
8244 return DW_FORM_data4
;
8246 return DW_FORM_data8
;
8250 case dw_val_class_long_long
:
8251 return DW_FORM_block1
;
8252 case dw_val_class_vec
:
8253 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8254 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8257 return DW_FORM_block1
;
8259 return DW_FORM_block2
;
8261 return DW_FORM_block4
;
8265 case dw_val_class_flag
:
8266 return DW_FORM_flag
;
8267 case dw_val_class_die_ref
:
8268 if (AT_ref_external (a
))
8269 return DW_FORM_ref_addr
;
8272 case dw_val_class_fde_ref
:
8273 return DW_FORM_data
;
8274 case dw_val_class_lbl_id
:
8275 return DW_FORM_addr
;
8276 case dw_val_class_lineptr
:
8277 case dw_val_class_macptr
:
8278 return DW_FORM_data
;
8279 case dw_val_class_str
:
8280 return AT_string_form (a
);
8281 case dw_val_class_file
:
8282 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8285 return DW_FORM_data1
;
8287 return DW_FORM_data2
;
8289 return DW_FORM_data4
;
8299 /* Output the encoding of an attribute value. */
8302 output_value_format (dw_attr_ref a
)
8304 enum dwarf_form form
= value_format (a
);
8306 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8309 /* Output the .debug_abbrev section which defines the DIE abbreviation
8313 output_abbrev_section (void)
8315 unsigned long abbrev_id
;
8317 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8319 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8323 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8324 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8325 dwarf_tag_name (abbrev
->die_tag
));
8327 if (abbrev
->die_child
!= NULL
)
8328 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8330 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8332 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
8335 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8336 dwarf_attr_name (a_attr
->dw_attr
));
8337 output_value_format (a_attr
);
8340 dw2_asm_output_data (1, 0, NULL
);
8341 dw2_asm_output_data (1, 0, NULL
);
8344 /* Terminate the table. */
8345 dw2_asm_output_data (1, 0, NULL
);
8348 /* Output a symbol we can use to refer to this DIE from another CU. */
8351 output_die_symbol (dw_die_ref die
)
8353 char *sym
= die
->die_symbol
;
8358 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8359 /* We make these global, not weak; if the target doesn't support
8360 .linkonce, it doesn't support combining the sections, so debugging
8362 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8364 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8367 /* Return a new location list, given the begin and end range, and the
8368 expression. gensym tells us whether to generate a new internal symbol for
8369 this location list node, which is done for the head of the list only. */
8371 static inline dw_loc_list_ref
8372 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8373 const char *section
, unsigned int gensym
)
8375 dw_loc_list_ref retlist
= GGC_CNEW (dw_loc_list_node
);
8377 retlist
->begin
= begin
;
8379 retlist
->expr
= expr
;
8380 retlist
->section
= section
;
8382 retlist
->ll_symbol
= gen_internal_sym ("LLST");
8387 /* Add a location description expression to a location list. */
8390 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
8391 const char *begin
, const char *end
,
8392 const char *section
)
8396 /* Find the end of the chain. */
8397 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
8400 /* Add a new location list node to the list. */
8401 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
8404 /* Output the location list given to us. */
8407 output_loc_list (dw_loc_list_ref list_head
)
8409 dw_loc_list_ref curr
= list_head
;
8411 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8413 /* Walk the location list, and output each range + expression. */
8414 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8417 /* Don't output an entry that starts and ends at the same address. */
8418 if (strcmp (curr
->begin
, curr
->end
) == 0)
8420 if (!have_multiple_function_sections
)
8422 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8423 "Location list begin address (%s)",
8424 list_head
->ll_symbol
);
8425 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8426 "Location list end address (%s)",
8427 list_head
->ll_symbol
);
8431 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8432 "Location list begin address (%s)",
8433 list_head
->ll_symbol
);
8434 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8435 "Location list end address (%s)",
8436 list_head
->ll_symbol
);
8438 size
= size_of_locs (curr
->expr
);
8440 /* Output the block length for this list of location operations. */
8441 gcc_assert (size
<= 0xffff);
8442 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8444 output_loc_sequence (curr
->expr
);
8447 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8448 "Location list terminator begin (%s)",
8449 list_head
->ll_symbol
);
8450 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8451 "Location list terminator end (%s)",
8452 list_head
->ll_symbol
);
8455 /* Output the DIE and its attributes. Called recursively to generate
8456 the definitions of each child DIE. */
8459 output_die (dw_die_ref die
)
8466 /* If someone in another CU might refer to us, set up a symbol for
8467 them to point to. */
8468 if (die
->die_symbol
)
8469 output_die_symbol (die
);
8471 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
8472 (unsigned long)die
->die_offset
,
8473 dwarf_tag_name (die
->die_tag
));
8475 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
8477 const char *name
= dwarf_attr_name (a
->dw_attr
);
8479 switch (AT_class (a
))
8481 case dw_val_class_addr
:
8482 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8485 case dw_val_class_offset
:
8486 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8490 case dw_val_class_range_list
:
8492 char *p
= strchr (ranges_section_label
, '\0');
8494 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
8495 a
->dw_attr_val
.v
.val_offset
);
8496 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8497 debug_ranges_section
, "%s", name
);
8502 case dw_val_class_loc
:
8503 size
= size_of_locs (AT_loc (a
));
8505 /* Output the block length for this list of location operations. */
8506 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8508 output_loc_sequence (AT_loc (a
));
8511 case dw_val_class_const
:
8512 /* ??? It would be slightly more efficient to use a scheme like is
8513 used for unsigned constants below, but gdb 4.x does not sign
8514 extend. Gdb 5.x does sign extend. */
8515 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8518 case dw_val_class_unsigned_const
:
8519 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
8520 AT_unsigned (a
), "%s", name
);
8523 case dw_val_class_long_long
:
8525 unsigned HOST_WIDE_INT first
, second
;
8527 dw2_asm_output_data (1,
8528 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8531 if (WORDS_BIG_ENDIAN
)
8533 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8534 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
8538 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
8539 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
8542 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8543 first
, "long long constant");
8544 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
8549 case dw_val_class_vec
:
8551 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8552 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8556 dw2_asm_output_data (constant_size (len
* elt_size
),
8557 len
* elt_size
, "%s", name
);
8558 if (elt_size
> sizeof (HOST_WIDE_INT
))
8563 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8566 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8567 "fp or vector constant word %u", i
);
8571 case dw_val_class_flag
:
8572 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8575 case dw_val_class_loc_list
:
8577 char *sym
= AT_loc_list (a
)->ll_symbol
;
8580 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8585 case dw_val_class_die_ref
:
8586 if (AT_ref_external (a
))
8588 char *sym
= AT_ref (a
)->die_symbol
;
8593 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8594 length, whereas in DWARF3 it's always sized as an offset. */
8595 if (dwarf_version
== 2)
8596 size
= DWARF2_ADDR_SIZE
;
8598 size
= DWARF_OFFSET_SIZE
;
8599 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s", name
);
8603 gcc_assert (AT_ref (a
)->die_offset
);
8604 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8609 case dw_val_class_fde_ref
:
8613 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8614 a
->dw_attr_val
.v
.val_fde_index
* 2);
8615 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8620 case dw_val_class_lbl_id
:
8621 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8624 case dw_val_class_lineptr
:
8625 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8626 debug_line_section
, "%s", name
);
8629 case dw_val_class_macptr
:
8630 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8631 debug_macinfo_section
, "%s", name
);
8634 case dw_val_class_str
:
8635 if (AT_string_form (a
) == DW_FORM_strp
)
8636 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8637 a
->dw_attr_val
.v
.val_str
->label
,
8639 "%s: \"%s\"", name
, AT_string (a
));
8641 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8644 case dw_val_class_file
:
8646 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8648 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8649 a
->dw_attr_val
.v
.val_file
->filename
);
8658 FOR_EACH_CHILD (die
, c
, output_die (c
));
8660 /* Add null byte to terminate sibling list. */
8661 if (die
->die_child
!= NULL
)
8662 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8663 (unsigned long) die
->die_offset
);
8666 /* Output the compilation unit that appears at the beginning of the
8667 .debug_info section, and precedes the DIE descriptions. */
8670 output_compilation_unit_header (void)
8672 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8673 dw2_asm_output_data (4, 0xffffffff,
8674 "Initial length escape value indicating 64-bit DWARF extension");
8675 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8676 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8677 "Length of Compilation Unit Info");
8678 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8679 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8680 debug_abbrev_section
,
8681 "Offset Into Abbrev. Section");
8682 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8685 /* Output the compilation unit DIE and its children. */
8688 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8690 const char *secname
;
8693 /* Unless we are outputting main CU, we may throw away empty ones. */
8694 if (!output_if_empty
&& die
->die_child
== NULL
)
8697 /* Even if there are no children of this DIE, we must output the information
8698 about the compilation unit. Otherwise, on an empty translation unit, we
8699 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8700 will then complain when examining the file. First mark all the DIEs in
8701 this CU so we know which get local refs. */
8704 build_abbrev_table (die
);
8706 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8707 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8708 calc_die_sizes (die
);
8710 oldsym
= die
->die_symbol
;
8713 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8715 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8717 die
->die_symbol
= NULL
;
8718 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8721 switch_to_section (debug_info_section
);
8723 /* Output debugging information. */
8724 output_compilation_unit_header ();
8727 /* Leave the marks on the main CU, so we can check them in
8732 die
->die_symbol
= oldsym
;
8736 /* Return the DWARF2/3 pubname associated with a decl. */
8739 dwarf2_name (tree decl
, int scope
)
8741 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8744 /* Add a new entry to .debug_pubnames if appropriate. */
8747 add_pubname_string (const char *str
, dw_die_ref die
)
8752 e
.name
= xstrdup (str
);
8753 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
8757 add_pubname (tree decl
, dw_die_ref die
)
8759 if (TREE_PUBLIC (decl
))
8760 add_pubname_string (dwarf2_name (decl
, 1), die
);
8763 /* Add a new entry to .debug_pubtypes if appropriate. */
8766 add_pubtype (tree decl
, dw_die_ref die
)
8771 if ((TREE_PUBLIC (decl
)
8772 || die
->die_parent
== comp_unit_die
)
8773 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8778 if (TYPE_NAME (decl
))
8780 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
8781 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
8782 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
8783 && DECL_NAME (TYPE_NAME (decl
)))
8784 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
8786 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
8790 e
.name
= xstrdup (dwarf2_name (decl
, 1));
8792 /* If we don't have a name for the type, there's no point in adding
8794 if (e
.name
&& e
.name
[0] != '\0')
8795 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
8799 /* Output the public names table used to speed up access to externally
8800 visible names; or the public types table used to find type definitions. */
8803 output_pubnames (VEC (pubname_entry
, gc
) * names
)
8806 unsigned long pubnames_length
= size_of_pubnames (names
);
8809 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8810 dw2_asm_output_data (4, 0xffffffff,
8811 "Initial length escape value indicating 64-bit DWARF extension");
8812 if (names
== pubname_table
)
8813 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8814 "Length of Public Names Info");
8816 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8817 "Length of Public Type Names Info");
8818 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8819 dw2_asm_output_data (2, 2, "DWARF Version");
8820 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8822 "Offset of Compilation Unit Info");
8823 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8824 "Compilation Unit Length");
8826 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
8828 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8829 if (names
== pubname_table
)
8830 gcc_assert (pub
->die
->die_mark
);
8832 if (names
!= pubtype_table
8833 || pub
->die
->die_offset
!= 0
8834 || !flag_eliminate_unused_debug_types
)
8836 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
8839 dw2_asm_output_nstring (pub
->name
, -1, "external name");
8843 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
8846 /* Add a new entry to .debug_aranges if appropriate. */
8849 add_arange (tree decl
, dw_die_ref die
)
8851 if (! DECL_SECTION_NAME (decl
))
8854 if (arange_table_in_use
== arange_table_allocated
)
8856 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
8857 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
8858 arange_table_allocated
);
8859 memset (arange_table
+ arange_table_in_use
, 0,
8860 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8863 arange_table
[arange_table_in_use
++] = die
;
8866 /* Output the information that goes into the .debug_aranges table.
8867 Namely, define the beginning and ending address range of the
8868 text section generated for this compilation unit. */
8871 output_aranges (void)
8874 unsigned long aranges_length
= size_of_aranges ();
8876 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8877 dw2_asm_output_data (4, 0xffffffff,
8878 "Initial length escape value indicating 64-bit DWARF extension");
8879 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8880 "Length of Address Ranges Info");
8881 /* Version number for aranges is still 2, even in DWARF3. */
8882 dw2_asm_output_data (2, 2, "DWARF Version");
8883 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8885 "Offset of Compilation Unit Info");
8886 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8887 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8889 /* We need to align to twice the pointer size here. */
8890 if (DWARF_ARANGES_PAD_SIZE
)
8892 /* Pad using a 2 byte words so that padding is correct for any
8894 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8895 2 * DWARF2_ADDR_SIZE
);
8896 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8897 dw2_asm_output_data (2, 0, NULL
);
8900 /* It is necessary not to output these entries if the sections were
8901 not used; if the sections were not used, the length will be 0 and
8902 the address may end up as 0 if the section is discarded by ld
8903 --gc-sections, leaving an invalid (0, 0) entry that can be
8904 confused with the terminator. */
8905 if (text_section_used
)
8907 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8908 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8909 text_section_label
, "Length");
8911 if (cold_text_section_used
)
8913 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8915 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8916 cold_text_section_label
, "Length");
8919 for (i
= 0; i
< arange_table_in_use
; i
++)
8921 dw_die_ref die
= arange_table
[i
];
8923 /* We shouldn't see aranges for DIEs outside of the main CU. */
8924 gcc_assert (die
->die_mark
);
8926 if (die
->die_tag
== DW_TAG_subprogram
)
8928 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
8930 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
8931 get_AT_low_pc (die
), "Length");
8935 /* A static variable; extract the symbol from DW_AT_location.
8936 Note that this code isn't currently hit, as we only emit
8937 aranges for functions (jason 9/23/99). */
8938 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
8939 dw_loc_descr_ref loc
;
8941 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
8944 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
8946 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
8947 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
8948 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
8949 get_AT_unsigned (die
, DW_AT_byte_size
),
8954 /* Output the terminator words. */
8955 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8956 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8959 /* Add a new entry to .debug_ranges. Return the offset at which it
8963 add_ranges_num (int num
)
8965 unsigned int in_use
= ranges_table_in_use
;
8967 if (in_use
== ranges_table_allocated
)
8969 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8970 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8971 ranges_table_allocated
);
8972 memset (ranges_table
+ ranges_table_in_use
, 0,
8973 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8976 ranges_table
[in_use
].num
= num
;
8977 ranges_table_in_use
= in_use
+ 1;
8979 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8982 /* Add a new entry to .debug_ranges corresponding to a block, or a
8983 range terminator if BLOCK is NULL. */
8986 add_ranges (const_tree block
)
8988 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8991 /* Add a new entry to .debug_ranges corresponding to a pair of
8995 add_ranges_by_labels (const char *begin
, const char *end
)
8997 unsigned int in_use
= ranges_by_label_in_use
;
8999 if (in_use
== ranges_by_label_allocated
)
9001 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9002 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9004 ranges_by_label_allocated
);
9005 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9006 RANGES_TABLE_INCREMENT
9007 * sizeof (struct dw_ranges_by_label_struct
));
9010 ranges_by_label
[in_use
].begin
= begin
;
9011 ranges_by_label
[in_use
].end
= end
;
9012 ranges_by_label_in_use
= in_use
+ 1;
9014 return add_ranges_num (-(int)in_use
- 1);
9018 output_ranges (void)
9021 static const char *const start_fmt
= "Offset 0x%x";
9022 const char *fmt
= start_fmt
;
9024 for (i
= 0; i
< ranges_table_in_use
; i
++)
9026 int block_num
= ranges_table
[i
].num
;
9030 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9031 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9033 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9034 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9036 /* If all code is in the text section, then the compilation
9037 unit base address defaults to DW_AT_low_pc, which is the
9038 base of the text section. */
9039 if (!have_multiple_function_sections
)
9041 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9043 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9044 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9045 text_section_label
, NULL
);
9048 /* Otherwise, the compilation unit base address is zero,
9049 which allows us to use absolute addresses, and not worry
9050 about whether the target supports cross-section
9054 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9055 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9056 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9062 /* Negative block_num stands for an index into ranges_by_label. */
9063 else if (block_num
< 0)
9065 int lab_idx
= - block_num
- 1;
9067 if (!have_multiple_function_sections
)
9071 /* If we ever use add_ranges_by_labels () for a single
9072 function section, all we have to do is to take out
9074 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9075 ranges_by_label
[lab_idx
].begin
,
9077 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9078 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9079 ranges_by_label
[lab_idx
].end
,
9080 text_section_label
, NULL
);
9085 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9086 ranges_by_label
[lab_idx
].begin
,
9087 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9088 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9089 ranges_by_label
[lab_idx
].end
,
9095 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9096 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9102 /* Data structure containing information about input files. */
9105 const char *path
; /* Complete file name. */
9106 const char *fname
; /* File name part. */
9107 int length
; /* Length of entire string. */
9108 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9109 int dir_idx
; /* Index in directory table. */
9112 /* Data structure containing information about directories with source
9116 const char *path
; /* Path including directory name. */
9117 int length
; /* Path length. */
9118 int prefix
; /* Index of directory entry which is a prefix. */
9119 int count
; /* Number of files in this directory. */
9120 int dir_idx
; /* Index of directory used as base. */
9123 /* Callback function for file_info comparison. We sort by looking at
9124 the directories in the path. */
9127 file_info_cmp (const void *p1
, const void *p2
)
9129 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9130 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9131 const unsigned char *cp1
;
9132 const unsigned char *cp2
;
9134 /* Take care of file names without directories. We need to make sure that
9135 we return consistent values to qsort since some will get confused if
9136 we return the same value when identical operands are passed in opposite
9137 orders. So if neither has a directory, return 0 and otherwise return
9138 1 or -1 depending on which one has the directory. */
9139 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9140 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9142 cp1
= (const unsigned char *) s1
->path
;
9143 cp2
= (const unsigned char *) s2
->path
;
9149 /* Reached the end of the first path? If so, handle like above. */
9150 if ((cp1
== (const unsigned char *) s1
->fname
)
9151 || (cp2
== (const unsigned char *) s2
->fname
))
9152 return ((cp2
== (const unsigned char *) s2
->fname
)
9153 - (cp1
== (const unsigned char *) s1
->fname
));
9155 /* Character of current path component the same? */
9156 else if (*cp1
!= *cp2
)
9161 struct file_name_acquire_data
9163 struct file_info
*files
;
9168 /* Traversal function for the hash table. */
9171 file_name_acquire (void ** slot
, void *data
)
9173 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9174 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9175 struct file_info
*fi
;
9178 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9180 if (! d
->emitted_number
)
9183 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9185 fi
= fnad
->files
+ fnad
->used_files
++;
9187 /* Skip all leading "./". */
9189 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9192 /* Create a new array entry. */
9194 fi
->length
= strlen (f
);
9197 /* Search for the file name part. */
9198 f
= strrchr (f
, DIR_SEPARATOR
);
9199 #if defined (DIR_SEPARATOR_2)
9201 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9205 if (f
== NULL
|| f
< g
)
9211 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9215 /* Output the directory table and the file name table. We try to minimize
9216 the total amount of memory needed. A heuristic is used to avoid large
9217 slowdowns with many input files. */
9220 output_file_names (void)
9222 struct file_name_acquire_data fnad
;
9224 struct file_info
*files
;
9225 struct dir_info
*dirs
;
9234 if (!last_emitted_file
)
9236 dw2_asm_output_data (1, 0, "End directory table");
9237 dw2_asm_output_data (1, 0, "End file name table");
9241 numfiles
= last_emitted_file
->emitted_number
;
9243 /* Allocate the various arrays we need. */
9244 files
= XALLOCAVEC (struct file_info
, numfiles
);
9245 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9248 fnad
.used_files
= 0;
9249 fnad
.max_files
= numfiles
;
9250 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9251 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9253 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9255 /* Find all the different directories used. */
9256 dirs
[0].path
= files
[0].path
;
9257 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9258 dirs
[0].prefix
= -1;
9260 dirs
[0].dir_idx
= 0;
9261 files
[0].dir_idx
= 0;
9264 for (i
= 1; i
< numfiles
; i
++)
9265 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9266 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9267 dirs
[ndirs
- 1].length
) == 0)
9269 /* Same directory as last entry. */
9270 files
[i
].dir_idx
= ndirs
- 1;
9271 ++dirs
[ndirs
- 1].count
;
9277 /* This is a new directory. */
9278 dirs
[ndirs
].path
= files
[i
].path
;
9279 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9280 dirs
[ndirs
].count
= 1;
9281 dirs
[ndirs
].dir_idx
= ndirs
;
9282 files
[i
].dir_idx
= ndirs
;
9284 /* Search for a prefix. */
9285 dirs
[ndirs
].prefix
= -1;
9286 for (j
= 0; j
< ndirs
; j
++)
9287 if (dirs
[j
].length
< dirs
[ndirs
].length
9288 && dirs
[j
].length
> 1
9289 && (dirs
[ndirs
].prefix
== -1
9290 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9291 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9292 dirs
[ndirs
].prefix
= j
;
9297 /* Now to the actual work. We have to find a subset of the directories which
9298 allow expressing the file name using references to the directory table
9299 with the least amount of characters. We do not do an exhaustive search
9300 where we would have to check out every combination of every single
9301 possible prefix. Instead we use a heuristic which provides nearly optimal
9302 results in most cases and never is much off. */
9303 saved
= XALLOCAVEC (int, ndirs
);
9304 savehere
= XALLOCAVEC (int, ndirs
);
9306 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9307 for (i
= 0; i
< ndirs
; i
++)
9312 /* We can always save some space for the current directory. But this
9313 does not mean it will be enough to justify adding the directory. */
9314 savehere
[i
] = dirs
[i
].length
;
9315 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9317 for (j
= i
+ 1; j
< ndirs
; j
++)
9320 if (saved
[j
] < dirs
[i
].length
)
9322 /* Determine whether the dirs[i] path is a prefix of the
9327 while (k
!= -1 && k
!= (int) i
)
9332 /* Yes it is. We can possibly save some memory by
9333 writing the filenames in dirs[j] relative to
9335 savehere
[j
] = dirs
[i
].length
;
9336 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9341 /* Check whether we can save enough to justify adding the dirs[i]
9343 if (total
> dirs
[i
].length
+ 1)
9345 /* It's worthwhile adding. */
9346 for (j
= i
; j
< ndirs
; j
++)
9347 if (savehere
[j
] > 0)
9349 /* Remember how much we saved for this directory so far. */
9350 saved
[j
] = savehere
[j
];
9352 /* Remember the prefix directory. */
9353 dirs
[j
].dir_idx
= i
;
9358 /* Emit the directory name table. */
9360 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9361 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9362 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
9363 "Directory Entry: 0x%x", i
+ idx_offset
);
9365 dw2_asm_output_data (1, 0, "End directory table");
9367 /* We have to emit them in the order of emitted_number since that's
9368 used in the debug info generation. To do this efficiently we
9369 generate a back-mapping of the indices first. */
9370 backmap
= XALLOCAVEC (int, numfiles
);
9371 for (i
= 0; i
< numfiles
; i
++)
9372 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9374 /* Now write all the file names. */
9375 for (i
= 0; i
< numfiles
; i
++)
9377 int file_idx
= backmap
[i
];
9378 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9380 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9381 "File Entry: 0x%x", (unsigned) i
+ 1);
9383 /* Include directory index. */
9384 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9386 /* Modification time. */
9387 dw2_asm_output_data_uleb128 (0, NULL
);
9389 /* File length in bytes. */
9390 dw2_asm_output_data_uleb128 (0, NULL
);
9393 dw2_asm_output_data (1, 0, "End file name table");
9397 /* Output the source line number correspondence information. This
9398 information goes into the .debug_line section. */
9401 output_line_info (void)
9403 char l1
[20], l2
[20], p1
[20], p2
[20];
9404 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9405 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9408 unsigned long lt_index
;
9409 unsigned long current_line
;
9412 unsigned long current_file
;
9413 unsigned long function
;
9415 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9416 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9417 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9418 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9420 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9421 dw2_asm_output_data (4, 0xffffffff,
9422 "Initial length escape value indicating 64-bit DWARF extension");
9423 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9424 "Length of Source Line Info");
9425 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9427 dw2_asm_output_data (2, dwarf_version
, "DWARF Version");
9428 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9429 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9431 /* Define the architecture-dependent minimum instruction length (in
9432 bytes). In this implementation of DWARF, this field is used for
9433 information purposes only. Since GCC generates assembly language,
9434 we have no a priori knowledge of how many instruction bytes are
9435 generated for each source line, and therefore can use only the
9436 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9437 commands. Accordingly, we fix this as `1', which is "correct
9438 enough" for all architectures, and don't let the target override. */
9439 dw2_asm_output_data (1, 1,
9440 "Minimum Instruction Length");
9442 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9443 "Default is_stmt_start flag");
9444 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9445 "Line Base Value (Special Opcodes)");
9446 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9447 "Line Range Value (Special Opcodes)");
9448 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9449 "Special Opcode Base");
9451 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9455 case DW_LNS_advance_pc
:
9456 case DW_LNS_advance_line
:
9457 case DW_LNS_set_file
:
9458 case DW_LNS_set_column
:
9459 case DW_LNS_fixed_advance_pc
:
9467 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
9471 /* Write out the information about the files we use. */
9472 output_file_names ();
9473 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9475 /* We used to set the address register to the first location in the text
9476 section here, but that didn't accomplish anything since we already
9477 have a line note for the opening brace of the first function. */
9479 /* Generate the line number to PC correspondence table, encoded as
9480 a series of state machine operations. */
9484 if (cfun
&& in_cold_section_p
)
9485 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
9487 strcpy (prev_line_label
, text_section_label
);
9488 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
9490 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
9493 /* Disable this optimization for now; GDB wants to see two line notes
9494 at the beginning of a function so it can find the end of the
9497 /* Don't emit anything for redundant notes. Just updating the
9498 address doesn't accomplish anything, because we already assume
9499 that anything after the last address is this line. */
9500 if (line_info
->dw_line_num
== current_line
9501 && line_info
->dw_file_num
== current_file
)
9505 /* Emit debug info for the address of the current line.
9507 Unfortunately, we have little choice here currently, and must always
9508 use the most general form. GCC does not know the address delta
9509 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9510 attributes which will give an upper bound on the address range. We
9511 could perhaps use length attributes to determine when it is safe to
9512 use DW_LNS_fixed_advance_pc. */
9514 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
9517 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9518 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9519 "DW_LNS_fixed_advance_pc");
9520 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9524 /* This can handle any delta. This takes
9525 4+DWARF2_ADDR_SIZE bytes. */
9526 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9527 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9528 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9529 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9532 strcpy (prev_line_label
, line_label
);
9534 /* Emit debug info for the source file of the current line, if
9535 different from the previous line. */
9536 if (line_info
->dw_file_num
!= current_file
)
9538 current_file
= line_info
->dw_file_num
;
9539 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9540 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9543 /* Emit debug info for the current line number, choosing the encoding
9544 that uses the least amount of space. */
9545 if (line_info
->dw_line_num
!= current_line
)
9547 line_offset
= line_info
->dw_line_num
- current_line
;
9548 line_delta
= line_offset
- DWARF_LINE_BASE
;
9549 current_line
= line_info
->dw_line_num
;
9550 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9551 /* This can handle deltas from -10 to 234, using the current
9552 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9554 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9555 "line %lu", current_line
);
9558 /* This can handle any delta. This takes at least 4 bytes,
9559 depending on the value being encoded. */
9560 dw2_asm_output_data (1, DW_LNS_advance_line
,
9561 "advance to line %lu", current_line
);
9562 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9563 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9567 /* We still need to start a new row, so output a copy insn. */
9568 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9571 /* Emit debug info for the address of the end of the function. */
9574 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9575 "DW_LNS_fixed_advance_pc");
9576 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
9580 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9581 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9582 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9583 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
9586 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9587 dw2_asm_output_data_uleb128 (1, NULL
);
9588 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9593 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
9595 dw_separate_line_info_ref line_info
9596 = &separate_line_info_table
[lt_index
];
9599 /* Don't emit anything for redundant notes. */
9600 if (line_info
->dw_line_num
== current_line
9601 && line_info
->dw_file_num
== current_file
9602 && line_info
->function
== function
)
9606 /* Emit debug info for the address of the current line. If this is
9607 a new function, or the first line of a function, then we need
9608 to handle it differently. */
9609 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
9611 if (function
!= line_info
->function
)
9613 function
= line_info
->function
;
9615 /* Set the address register to the first line in the function. */
9616 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9617 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9618 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9619 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9623 /* ??? See the DW_LNS_advance_pc comment above. */
9626 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9627 "DW_LNS_fixed_advance_pc");
9628 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9632 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9633 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9634 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9635 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9639 strcpy (prev_line_label
, line_label
);
9641 /* Emit debug info for the source file of the current line, if
9642 different from the previous line. */
9643 if (line_info
->dw_file_num
!= current_file
)
9645 current_file
= line_info
->dw_file_num
;
9646 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
9647 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
9650 /* Emit debug info for the current line number, choosing the encoding
9651 that uses the least amount of space. */
9652 if (line_info
->dw_line_num
!= current_line
)
9654 line_offset
= line_info
->dw_line_num
- current_line
;
9655 line_delta
= line_offset
- DWARF_LINE_BASE
;
9656 current_line
= line_info
->dw_line_num
;
9657 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9658 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9659 "line %lu", current_line
);
9662 dw2_asm_output_data (1, DW_LNS_advance_line
,
9663 "advance to line %lu", current_line
);
9664 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9665 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9669 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
9677 /* If we're done with a function, end its sequence. */
9678 if (lt_index
== separate_line_info_table_in_use
9679 || separate_line_info_table
[lt_index
].function
!= function
)
9684 /* Emit debug info for the address of the end of the function. */
9685 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
9688 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
9689 "DW_LNS_fixed_advance_pc");
9690 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
9694 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9695 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9696 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9697 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9700 /* Output the marker for the end of this sequence. */
9701 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9702 dw2_asm_output_data_uleb128 (1, NULL
);
9703 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9707 /* Output the marker for the end of the line number info. */
9708 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9711 /* Given a pointer to a tree node for some base type, return a pointer to
9712 a DIE that describes the given type.
9714 This routine must only be called for GCC type nodes that correspond to
9715 Dwarf base (fundamental) types. */
9718 base_type_die (tree type
)
9720 dw_die_ref base_type_result
;
9721 enum dwarf_type encoding
;
9723 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9726 /* If this is a subtype that should not be emitted as a subrange type,
9727 use the base type. See subrange_type_for_debug_p. */
9728 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9729 type
= TREE_TYPE (type
);
9731 switch (TREE_CODE (type
))
9734 if (TYPE_STRING_FLAG (type
))
9736 if (TYPE_UNSIGNED (type
))
9737 encoding
= DW_ATE_unsigned_char
;
9739 encoding
= DW_ATE_signed_char
;
9741 else if (TYPE_UNSIGNED (type
))
9742 encoding
= DW_ATE_unsigned
;
9744 encoding
= DW_ATE_signed
;
9748 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9749 encoding
= DW_ATE_decimal_float
;
9751 encoding
= DW_ATE_float
;
9754 case FIXED_POINT_TYPE
:
9755 if (TYPE_UNSIGNED (type
))
9756 encoding
= DW_ATE_unsigned_fixed
;
9758 encoding
= DW_ATE_signed_fixed
;
9761 /* Dwarf2 doesn't know anything about complex ints, so use
9762 a user defined type for it. */
9764 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9765 encoding
= DW_ATE_complex_float
;
9767 encoding
= DW_ATE_lo_user
;
9771 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9772 encoding
= DW_ATE_boolean
;
9776 /* No other TREE_CODEs are Dwarf fundamental types. */
9780 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
9782 /* This probably indicates a bug. */
9783 if (! TYPE_NAME (type
))
9784 add_name_attribute (base_type_result
, "__unknown__");
9786 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9787 int_size_in_bytes (type
));
9788 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9790 return base_type_result
;
9793 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9794 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9797 is_base_type (tree type
)
9799 switch (TREE_CODE (type
))
9805 case FIXED_POINT_TYPE
:
9813 case QUAL_UNION_TYPE
:
9818 case REFERENCE_TYPE
:
9831 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9832 node, return the size in bits for the type if it is a constant, or else
9833 return the alignment for the type if the type's size is not constant, or
9834 else return BITS_PER_WORD if the type actually turns out to be an
9837 static inline unsigned HOST_WIDE_INT
9838 simple_type_size_in_bits (const_tree type
)
9840 if (TREE_CODE (type
) == ERROR_MARK
)
9841 return BITS_PER_WORD
;
9842 else if (TYPE_SIZE (type
) == NULL_TREE
)
9844 else if (host_integerp (TYPE_SIZE (type
), 1))
9845 return tree_low_cst (TYPE_SIZE (type
), 1);
9847 return TYPE_ALIGN (type
);
9850 /* Given a pointer to a tree node for a subrange type, return a pointer
9851 to a DIE that describes the given type. */
9854 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
9856 dw_die_ref subrange_die
;
9857 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9859 if (context_die
== NULL
)
9860 context_die
= comp_unit_die
;
9862 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9864 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9866 /* The size of the subrange type and its base type do not match,
9867 so we need to generate a size attribute for the subrange type. */
9868 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9872 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
9874 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
9876 return subrange_die
;
9879 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9880 entry that chains various modifiers in front of the given type. */
9883 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9884 dw_die_ref context_die
)
9886 enum tree_code code
= TREE_CODE (type
);
9887 dw_die_ref mod_type_die
;
9888 dw_die_ref sub_die
= NULL
;
9889 tree item_type
= NULL
;
9890 tree qualified_type
;
9891 tree name
, low
, high
;
9893 if (code
== ERROR_MARK
)
9896 /* See if we already have the appropriately qualified variant of
9899 = get_qualified_type (type
,
9900 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9901 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9903 /* If we do, then we can just use its DIE, if it exists. */
9906 mod_type_die
= lookup_type_die (qualified_type
);
9908 return mod_type_die
;
9911 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9913 /* Handle C typedef types. */
9914 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
9916 tree dtype
= TREE_TYPE (name
);
9918 if (qualified_type
== dtype
)
9920 /* For a named type, use the typedef. */
9921 gen_type_die (qualified_type
, context_die
);
9922 return lookup_type_die (qualified_type
);
9924 else if (is_const_type
< TYPE_READONLY (dtype
)
9925 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9926 || (is_const_type
<= TYPE_READONLY (dtype
)
9927 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9928 && DECL_ORIGINAL_TYPE (name
) != type
))
9929 /* cv-unqualified version of named type. Just use the unnamed
9930 type to which it refers. */
9931 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9932 is_const_type
, is_volatile_type
,
9934 /* Else cv-qualified version of named type; fall through. */
9939 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
9940 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9942 else if (is_volatile_type
)
9944 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
9945 sub_die
= modified_type_die (type
, 0, 0, context_die
);
9947 else if (code
== POINTER_TYPE
)
9949 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
9950 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9951 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9952 item_type
= TREE_TYPE (type
);
9954 else if (code
== REFERENCE_TYPE
)
9956 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
9957 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9958 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9959 item_type
= TREE_TYPE (type
);
9961 else if (code
== INTEGER_TYPE
9962 && TREE_TYPE (type
) != NULL_TREE
9963 && subrange_type_for_debug_p (type
, &low
, &high
))
9965 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
9966 item_type
= TREE_TYPE (type
);
9968 else if (is_base_type (type
))
9969 mod_type_die
= base_type_die (type
);
9972 gen_type_die (type
, context_die
);
9974 /* We have to get the type_main_variant here (and pass that to the
9975 `lookup_type_die' routine) because the ..._TYPE node we have
9976 might simply be a *copy* of some original type node (where the
9977 copy was created to help us keep track of typedef names) and
9978 that copy might have a different TYPE_UID from the original
9980 if (TREE_CODE (type
) != VECTOR_TYPE
)
9981 return lookup_type_die (type_main_variant (type
));
9983 /* Vectors have the debugging information in the type,
9984 not the main variant. */
9985 return lookup_type_die (type
);
9988 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9989 don't output a DW_TAG_typedef, since there isn't one in the
9990 user's program; just attach a DW_AT_name to the type. */
9992 && (TREE_CODE (name
) != TYPE_DECL
9993 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
9995 if (TREE_CODE (name
) == TYPE_DECL
)
9996 /* Could just call add_name_and_src_coords_attributes here,
9997 but since this is a builtin type it doesn't have any
9998 useful source coordinates anyway. */
9999 name
= DECL_NAME (name
);
10000 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10003 if (qualified_type
)
10004 equate_type_number_to_die (qualified_type
, mod_type_die
);
10007 /* We must do this after the equate_type_number_to_die call, in case
10008 this is a recursive type. This ensures that the modified_type_die
10009 recursion will terminate even if the type is recursive. Recursive
10010 types are possible in Ada. */
10011 sub_die
= modified_type_die (item_type
,
10012 TYPE_READONLY (item_type
),
10013 TYPE_VOLATILE (item_type
),
10016 if (sub_die
!= NULL
)
10017 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10019 return mod_type_die
;
10022 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10023 an enumerated type. */
10026 type_is_enum (const_tree type
)
10028 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10031 /* Return the DBX register number described by a given RTL node. */
10033 static unsigned int
10034 dbx_reg_number (const_rtx rtl
)
10036 unsigned regno
= REGNO (rtl
);
10038 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10040 #ifdef LEAF_REG_REMAP
10041 if (current_function_uses_only_leaf_regs
)
10043 int leaf_reg
= LEAF_REG_REMAP (regno
);
10044 if (leaf_reg
!= -1)
10045 regno
= (unsigned) leaf_reg
;
10049 return DBX_REGISTER_NUMBER (regno
);
10052 /* Optionally add a DW_OP_piece term to a location description expression.
10053 DW_OP_piece is only added if the location description expression already
10054 doesn't end with DW_OP_piece. */
10057 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10059 dw_loc_descr_ref loc
;
10061 if (*list_head
!= NULL
)
10063 /* Find the end of the chain. */
10064 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10067 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10068 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10072 /* Return a location descriptor that designates a machine register or
10073 zero if there is none. */
10075 static dw_loc_descr_ref
10076 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10080 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10083 regs
= targetm
.dwarf_register_span (rtl
);
10085 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10086 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10088 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
10091 /* Return a location descriptor that designates a machine register for
10092 a given hard register number. */
10094 static dw_loc_descr_ref
10095 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10097 dw_loc_descr_ref reg_loc_descr
;
10101 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10103 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10105 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10106 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10108 return reg_loc_descr
;
10111 /* Given an RTL of a register, return a location descriptor that
10112 designates a value that spans more than one register. */
10114 static dw_loc_descr_ref
10115 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10116 enum var_init_status initialized
)
10118 int nregs
, size
, i
;
10120 dw_loc_descr_ref loc_result
= NULL
;
10123 #ifdef LEAF_REG_REMAP
10124 if (current_function_uses_only_leaf_regs
)
10126 int leaf_reg
= LEAF_REG_REMAP (reg
);
10127 if (leaf_reg
!= -1)
10128 reg
= (unsigned) leaf_reg
;
10131 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10132 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10134 /* Simple, contiguous registers. */
10135 if (regs
== NULL_RTX
)
10137 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10142 dw_loc_descr_ref t
;
10144 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10145 VAR_INIT_STATUS_INITIALIZED
);
10146 add_loc_descr (&loc_result
, t
);
10147 add_loc_descr_op_piece (&loc_result
, size
);
10153 /* Now onto stupid register sets in non contiguous locations. */
10155 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10157 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10160 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10162 dw_loc_descr_ref t
;
10164 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10165 VAR_INIT_STATUS_INITIALIZED
);
10166 add_loc_descr (&loc_result
, t
);
10167 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10168 add_loc_descr_op_piece (&loc_result
, size
);
10171 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10172 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10176 #endif /* DWARF2_DEBUGGING_INFO */
10178 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10180 /* Return a location descriptor that designates a constant. */
10182 static dw_loc_descr_ref
10183 int_loc_descriptor (HOST_WIDE_INT i
)
10185 enum dwarf_location_atom op
;
10187 /* Pick the smallest representation of a constant, rather than just
10188 defaulting to the LEB encoding. */
10192 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10193 else if (i
<= 0xff)
10194 op
= DW_OP_const1u
;
10195 else if (i
<= 0xffff)
10196 op
= DW_OP_const2u
;
10197 else if (HOST_BITS_PER_WIDE_INT
== 32
10198 || i
<= 0xffffffff)
10199 op
= DW_OP_const4u
;
10206 op
= DW_OP_const1s
;
10207 else if (i
>= -0x8000)
10208 op
= DW_OP_const2s
;
10209 else if (HOST_BITS_PER_WIDE_INT
== 32
10210 || i
>= -0x80000000)
10211 op
= DW_OP_const4s
;
10216 return new_loc_descr (op
, i
, 0);
10220 #ifdef DWARF2_DEBUGGING_INFO
10222 /* Return a location descriptor that designates a base+offset location. */
10224 static dw_loc_descr_ref
10225 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10226 enum var_init_status initialized
)
10228 unsigned int regno
;
10229 dw_loc_descr_ref result
;
10230 dw_fde_ref fde
= current_fde ();
10232 /* We only use "frame base" when we're sure we're talking about the
10233 post-prologue local stack frame. We do this by *not* running
10234 register elimination until this point, and recognizing the special
10235 argument pointer and soft frame pointer rtx's. */
10236 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10238 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10242 if (GET_CODE (elim
) == PLUS
)
10244 offset
+= INTVAL (XEXP (elim
, 1));
10245 elim
= XEXP (elim
, 0);
10247 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10248 && (elim
== hard_frame_pointer_rtx
10249 || elim
== stack_pointer_rtx
))
10250 || elim
== (frame_pointer_needed
10251 ? hard_frame_pointer_rtx
10252 : stack_pointer_rtx
));
10254 /* If drap register is used to align stack, use frame
10255 pointer + offset to access stack variables. If stack
10256 is aligned without drap, use stack pointer + offset to
10257 access stack variables. */
10258 if (crtl
->stack_realign_tried
10259 && reg
== frame_pointer_rtx
)
10262 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10263 ? HARD_FRAME_POINTER_REGNUM
10264 : STACK_POINTER_REGNUM
);
10265 return new_reg_loc_descr (base_reg
, offset
);
10268 offset
+= frame_pointer_fb_offset
;
10269 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10273 && fde
->drap_reg
!= INVALID_REGNUM
10274 && (fde
->drap_reg
== REGNO (reg
)
10275 || fde
->vdrap_reg
== REGNO (reg
)))
10277 /* Use cfa+offset to represent the location of arguments passed
10278 on stack when drap is used to align stack. */
10279 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10282 regno
= dbx_reg_number (reg
);
10284 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10287 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10289 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10290 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10295 /* Return true if this RTL expression describes a base+offset calculation. */
10298 is_based_loc (const_rtx rtl
)
10300 return (GET_CODE (rtl
) == PLUS
10301 && ((REG_P (XEXP (rtl
, 0))
10302 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10303 && CONST_INT_P (XEXP (rtl
, 1)))));
10306 /* Return a descriptor that describes the concatenation of N locations
10307 used to form the address of a memory location. */
10309 static dw_loc_descr_ref
10310 concatn_mem_loc_descriptor (rtx concatn
, enum machine_mode mode
,
10311 enum var_init_status initialized
)
10314 dw_loc_descr_ref cc_loc_result
= NULL
;
10315 unsigned int n
= XVECLEN (concatn
, 0);
10317 for (i
= 0; i
< n
; ++i
)
10319 dw_loc_descr_ref ref
;
10320 rtx x
= XVECEXP (concatn
, 0, i
);
10322 ref
= mem_loc_descriptor (x
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10326 add_loc_descr (&cc_loc_result
, ref
);
10327 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
10330 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10331 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10333 return cc_loc_result
;
10336 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10339 static dw_loc_descr_ref
10340 tls_mem_loc_descriptor (rtx mem
)
10343 dw_loc_descr_ref loc_result
;
10345 if (MEM_EXPR (mem
) == NULL_TREE
|| MEM_OFFSET (mem
) == NULL_RTX
)
10348 base
= get_base_address (MEM_EXPR (mem
));
10350 || TREE_CODE (base
) != VAR_DECL
10351 || !DECL_THREAD_LOCAL_P (base
))
10354 loc_result
= loc_descriptor_from_tree_1 (MEM_EXPR (mem
), 2);
10355 if (loc_result
== NULL
)
10358 if (INTVAL (MEM_OFFSET (mem
)))
10359 loc_descr_plus_const (&loc_result
, INTVAL (MEM_OFFSET (mem
)));
10364 /* The following routine converts the RTL for a variable or parameter
10365 (resident in memory) into an equivalent Dwarf representation of a
10366 mechanism for getting the address of that same variable onto the top of a
10367 hypothetical "address evaluation" stack.
10369 When creating memory location descriptors, we are effectively transforming
10370 the RTL for a memory-resident object into its Dwarf postfix expression
10371 equivalent. This routine recursively descends an RTL tree, turning
10372 it into Dwarf postfix code as it goes.
10374 MODE is the mode of the memory reference, needed to handle some
10375 autoincrement addressing modes.
10377 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10378 location list for RTL.
10380 Return 0 if we can't represent the location. */
10382 static dw_loc_descr_ref
10383 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
10384 enum var_init_status initialized
)
10386 dw_loc_descr_ref mem_loc_result
= NULL
;
10387 enum dwarf_location_atom op
;
10389 /* Note that for a dynamically sized array, the location we will generate a
10390 description of here will be the lowest numbered location which is
10391 actually within the array. That's *not* necessarily the same as the
10392 zeroth element of the array. */
10394 rtl
= targetm
.delegitimize_address (rtl
);
10396 switch (GET_CODE (rtl
))
10401 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10402 just fall into the SUBREG code. */
10404 /* ... fall through ... */
10407 /* The case of a subreg may arise when we have a local (register)
10408 variable or a formal (register) parameter which doesn't quite fill
10409 up an entire register. For now, just assume that it is
10410 legitimate to make the Dwarf info refer to the whole register which
10411 contains the given subreg. */
10412 rtl
= XEXP (rtl
, 0);
10414 /* ... fall through ... */
10417 /* Whenever a register number forms a part of the description of the
10418 method for calculating the (dynamic) address of a memory resident
10419 object, DWARF rules require the register number be referred to as
10420 a "base register". This distinction is not based in any way upon
10421 what category of register the hardware believes the given register
10422 belongs to. This is strictly DWARF terminology we're dealing with
10423 here. Note that in cases where the location of a memory-resident
10424 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10425 OP_CONST (0)) the actual DWARF location descriptor that we generate
10426 may just be OP_BASEREG (basereg). This may look deceptively like
10427 the object in question was allocated to a register (rather than in
10428 memory) so DWARF consumers need to be aware of the subtle
10429 distinction between OP_REG and OP_BASEREG. */
10430 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
10431 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
10432 else if (stack_realign_drap
10434 && crtl
->args
.internal_arg_pointer
== rtl
10435 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
10437 /* If RTL is internal_arg_pointer, which has been optimized
10438 out, use DRAP instead. */
10439 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
10440 VAR_INIT_STATUS_INITIALIZED
);
10445 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
10446 VAR_INIT_STATUS_INITIALIZED
);
10447 if (mem_loc_result
== NULL
)
10448 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
10449 if (mem_loc_result
!= 0)
10450 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
10454 rtl
= XEXP (rtl
, 1);
10456 /* ... fall through ... */
10459 /* Some ports can transform a symbol ref into a label ref, because
10460 the symbol ref is too far away and has to be dumped into a constant
10464 /* Alternatively, the symbol in the constant pool might be referenced
10465 by a different symbol. */
10466 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
10469 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
10471 if (GET_CODE (tmp
) == SYMBOL_REF
)
10474 if (CONSTANT_POOL_ADDRESS_P (tmp
))
10475 get_pool_constant_mark (tmp
, &marked
);
10480 /* If all references to this pool constant were optimized away,
10481 it was not output and thus we can't represent it.
10482 FIXME: might try to use DW_OP_const_value here, though
10483 DW_OP_piece complicates it. */
10488 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
10489 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10490 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10491 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
10495 /* Extract the PLUS expression nested inside and fall into
10496 PLUS code below. */
10497 rtl
= XEXP (rtl
, 1);
10502 /* Turn these into a PLUS expression and fall into the PLUS code
10504 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
10505 GEN_INT (GET_CODE (rtl
) == PRE_INC
10506 ? GET_MODE_UNIT_SIZE (mode
)
10507 : -GET_MODE_UNIT_SIZE (mode
)));
10509 /* ... fall through ... */
10513 if (is_based_loc (rtl
))
10514 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
10515 INTVAL (XEXP (rtl
, 1)),
10516 VAR_INIT_STATUS_INITIALIZED
);
10519 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10520 VAR_INIT_STATUS_INITIALIZED
);
10521 if (mem_loc_result
== 0)
10524 if (CONST_INT_P (XEXP (rtl
, 1)))
10525 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
10528 dw_loc_descr_ref mem_loc_result2
10529 = mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10530 VAR_INIT_STATUS_INITIALIZED
);
10531 if (mem_loc_result2
== 0)
10533 add_loc_descr (&mem_loc_result
, mem_loc_result2
);
10534 add_loc_descr (&mem_loc_result
,
10535 new_loc_descr (DW_OP_plus
, 0, 0));
10540 /* If a pseudo-reg is optimized away, it is possible for it to
10541 be replaced with a MEM containing a multiply or shift. */
10560 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
10561 VAR_INIT_STATUS_INITIALIZED
);
10562 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
10563 VAR_INIT_STATUS_INITIALIZED
);
10565 if (op0
== 0 || op1
== 0)
10568 mem_loc_result
= op0
;
10569 add_loc_descr (&mem_loc_result
, op1
);
10570 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
10575 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
10579 mem_loc_result
= concatn_mem_loc_descriptor (rtl
, mode
,
10580 VAR_INIT_STATUS_INITIALIZED
);
10584 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10585 can't express it in the debug info. This can happen e.g. with some
10590 gcc_unreachable ();
10593 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10594 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10596 return mem_loc_result
;
10599 /* Return a descriptor that describes the concatenation of two locations.
10600 This is typically a complex variable. */
10602 static dw_loc_descr_ref
10603 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
10605 dw_loc_descr_ref cc_loc_result
= NULL
;
10606 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, VAR_INIT_STATUS_INITIALIZED
);
10607 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, VAR_INIT_STATUS_INITIALIZED
);
10609 if (x0_ref
== 0 || x1_ref
== 0)
10612 cc_loc_result
= x0_ref
;
10613 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
10615 add_loc_descr (&cc_loc_result
, x1_ref
);
10616 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
10618 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10619 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10621 return cc_loc_result
;
10624 /* Return a descriptor that describes the concatenation of N
10627 static dw_loc_descr_ref
10628 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
10631 dw_loc_descr_ref cc_loc_result
= NULL
;
10632 unsigned int n
= XVECLEN (concatn
, 0);
10634 for (i
= 0; i
< n
; ++i
)
10636 dw_loc_descr_ref ref
;
10637 rtx x
= XVECEXP (concatn
, 0, i
);
10639 ref
= loc_descriptor (x
, VAR_INIT_STATUS_INITIALIZED
);
10643 add_loc_descr (&cc_loc_result
, ref
);
10644 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
10647 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10648 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10650 return cc_loc_result
;
10653 /* Output a proper Dwarf location descriptor for a variable or parameter
10654 which is either allocated in a register or in a memory location. For a
10655 register, we just generate an OP_REG and the register number. For a
10656 memory location we provide a Dwarf postfix expression describing how to
10657 generate the (dynamic) address of the object onto the address stack.
10659 If we don't know how to describe it, return 0. */
10661 static dw_loc_descr_ref
10662 loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10664 dw_loc_descr_ref loc_result
= NULL
;
10666 switch (GET_CODE (rtl
))
10669 /* The case of a subreg may arise when we have a local (register)
10670 variable or a formal (register) parameter which doesn't quite fill
10671 up an entire register. For now, just assume that it is
10672 legitimate to make the Dwarf info refer to the whole register which
10673 contains the given subreg. */
10674 rtl
= SUBREG_REG (rtl
);
10676 /* ... fall through ... */
10679 loc_result
= reg_loc_descriptor (rtl
, initialized
);
10683 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
10685 if (loc_result
== NULL
)
10686 loc_result
= tls_mem_loc_descriptor (rtl
);
10690 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
10695 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
10700 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
10702 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), initialized
);
10706 rtl
= XEXP (rtl
, 1);
10711 rtvec par_elems
= XVEC (rtl
, 0);
10712 int num_elem
= GET_NUM_ELEM (par_elems
);
10713 enum machine_mode mode
;
10716 /* Create the first one, so we have something to add to. */
10717 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
10719 if (loc_result
== NULL
)
10721 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
10722 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10723 for (i
= 1; i
< num_elem
; i
++)
10725 dw_loc_descr_ref temp
;
10727 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
10731 add_loc_descr (&loc_result
, temp
);
10732 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
10733 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
10739 gcc_unreachable ();
10745 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10746 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10747 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10748 top-level invocation, and we require the address of LOC; is 0 if we require
10749 the value of LOC. */
10751 static dw_loc_descr_ref
10752 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
10754 dw_loc_descr_ref ret
, ret1
;
10755 int have_address
= 0;
10756 enum dwarf_location_atom op
;
10758 /* ??? Most of the time we do not take proper care for sign/zero
10759 extending the values properly. Hopefully this won't be a real
10762 switch (TREE_CODE (loc
))
10767 case PLACEHOLDER_EXPR
:
10768 /* This case involves extracting fields from an object to determine the
10769 position of other fields. We don't try to encode this here. The
10770 only user of this is Ada, which encodes the needed information using
10771 the names of types. */
10777 case PREINCREMENT_EXPR
:
10778 case PREDECREMENT_EXPR
:
10779 case POSTINCREMENT_EXPR
:
10780 case POSTDECREMENT_EXPR
:
10781 /* There are no opcodes for these operations. */
10785 /* If we already want an address, there's nothing we can do. */
10789 /* Otherwise, process the argument and look for the address. */
10790 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
10793 if (DECL_THREAD_LOCAL_P (loc
))
10796 enum dwarf_location_atom first_op
;
10797 enum dwarf_location_atom second_op
;
10798 bool dtprel
= false;
10800 if (targetm
.have_tls
)
10802 /* If this is not defined, we have no way to emit the
10804 if (!targetm
.asm_out
.output_dwarf_dtprel
)
10807 /* The way DW_OP_GNU_push_tls_address is specified, we
10808 can only look up addresses of objects in the current
10810 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
10812 first_op
= DW_OP_addr
;
10814 second_op
= DW_OP_GNU_push_tls_address
;
10818 if (!targetm
.emutls
.debug_form_tls_address
)
10820 loc
= emutls_decl (loc
);
10821 first_op
= DW_OP_addr
;
10822 second_op
= DW_OP_form_tls_address
;
10825 rtl
= rtl_for_decl_location (loc
);
10826 if (rtl
== NULL_RTX
)
10831 rtl
= XEXP (rtl
, 0);
10832 if (! CONSTANT_P (rtl
))
10835 ret
= new_loc_descr (first_op
, 0, 0);
10836 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10837 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10838 ret
->dtprel
= dtprel
;
10840 ret1
= new_loc_descr (second_op
, 0, 0);
10841 add_loc_descr (&ret
, ret1
);
10849 if (DECL_HAS_VALUE_EXPR_P (loc
))
10850 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
10855 case FUNCTION_DECL
:
10857 rtx rtl
= rtl_for_decl_location (loc
);
10859 if (rtl
== NULL_RTX
)
10861 else if (CONST_INT_P (rtl
))
10863 HOST_WIDE_INT val
= INTVAL (rtl
);
10864 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
10865 val
&= GET_MODE_MASK (DECL_MODE (loc
));
10866 ret
= int_loc_descriptor (val
);
10868 else if (GET_CODE (rtl
) == CONST_STRING
)
10870 else if (CONSTANT_P (rtl
))
10872 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
10873 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10874 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10878 enum machine_mode mode
;
10880 /* Certain constructs can only be represented at top-level. */
10881 if (want_address
== 2)
10882 return loc_descriptor (rtl
, VAR_INIT_STATUS_INITIALIZED
);
10884 mode
= GET_MODE (rtl
);
10887 rtl
= XEXP (rtl
, 0);
10890 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10896 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10900 case COMPOUND_EXPR
:
10901 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
10904 case VIEW_CONVERT_EXPR
:
10907 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
10909 case COMPONENT_REF
:
10910 case BIT_FIELD_REF
:
10912 case ARRAY_RANGE_REF
:
10915 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
10916 enum machine_mode mode
;
10918 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
10920 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
10921 &unsignedp
, &volatilep
, false);
10926 ret
= loc_descriptor_from_tree_1 (obj
, 1);
10928 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
10931 if (offset
!= NULL_TREE
)
10933 /* Variable offset. */
10934 ret1
= loc_descriptor_from_tree_1 (offset
, 0);
10937 add_loc_descr (&ret
, ret1
);
10938 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10941 bytepos
= bitpos
/ BITS_PER_UNIT
;
10942 loc_descr_plus_const (&ret
, bytepos
);
10949 if (host_integerp (loc
, 0))
10950 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
10957 /* Get an RTL for this, if something has been emitted. */
10958 rtx rtl
= lookup_constant_def (loc
);
10959 enum machine_mode mode
;
10961 if (!rtl
|| !MEM_P (rtl
))
10963 mode
= GET_MODE (rtl
);
10964 rtl
= XEXP (rtl
, 0);
10965 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10970 case TRUTH_AND_EXPR
:
10971 case TRUTH_ANDIF_EXPR
:
10976 case TRUTH_XOR_EXPR
:
10981 case TRUTH_OR_EXPR
:
10982 case TRUTH_ORIF_EXPR
:
10987 case FLOOR_DIV_EXPR
:
10988 case CEIL_DIV_EXPR
:
10989 case ROUND_DIV_EXPR
:
10990 case TRUNC_DIV_EXPR
:
10998 case FLOOR_MOD_EXPR
:
10999 case CEIL_MOD_EXPR
:
11000 case ROUND_MOD_EXPR
:
11001 case TRUNC_MOD_EXPR
:
11014 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
11017 case POINTER_PLUS_EXPR
:
11019 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
11020 && host_integerp (TREE_OPERAND (loc
, 1), 0))
11022 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
11026 loc_descr_plus_const (&ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
11034 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
11041 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
11048 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
11055 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
11070 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
11071 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
11072 if (ret
== 0 || ret1
== 0)
11075 add_loc_descr (&ret
, ret1
);
11076 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11079 case TRUTH_NOT_EXPR
:
11093 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
11097 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11103 const enum tree_code code
=
11104 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
11106 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
11107 build2 (code
, integer_type_node
,
11108 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
11109 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
11112 /* ... fall through ... */
11116 dw_loc_descr_ref lhs
11117 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
11118 dw_loc_descr_ref rhs
11119 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
11120 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
11122 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
11123 if (ret
== 0 || lhs
== 0 || rhs
== 0)
11126 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11127 add_loc_descr (&ret
, bra_node
);
11129 add_loc_descr (&ret
, rhs
);
11130 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
11131 add_loc_descr (&ret
, jump_node
);
11133 add_loc_descr (&ret
, lhs
);
11134 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11135 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
11137 /* ??? Need a node to point the skip at. Use a nop. */
11138 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
11139 add_loc_descr (&ret
, tmp
);
11140 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11141 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
11145 case FIX_TRUNC_EXPR
:
11149 /* Leave front-end specific codes as simply unknown. This comes
11150 up, for instance, with the C STMT_EXPR. */
11151 if ((unsigned int) TREE_CODE (loc
)
11152 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
11155 #ifdef ENABLE_CHECKING
11156 /* Otherwise this is a generic code; we should just lists all of
11157 these explicitly. We forgot one. */
11158 gcc_unreachable ();
11160 /* In a release build, we want to degrade gracefully: better to
11161 generate incomplete debugging information than to crash. */
11166 /* Show if we can't fill the request for an address. */
11167 if (want_address
&& !have_address
)
11170 /* If we've got an address and don't want one, dereference. */
11171 if (!want_address
&& have_address
&& ret
)
11173 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
11175 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
11177 else if (size
== DWARF2_ADDR_SIZE
)
11180 op
= DW_OP_deref_size
;
11182 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
11188 static inline dw_loc_descr_ref
11189 loc_descriptor_from_tree (tree loc
)
11191 return loc_descriptor_from_tree_1 (loc
, 2);
11194 /* Given a value, round it up to the lowest multiple of `boundary'
11195 which is not less than the value itself. */
11197 static inline HOST_WIDE_INT
11198 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
11200 return (((value
+ boundary
- 1) / boundary
) * boundary
);
11203 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
11204 pointer to the declared type for the relevant field variable, or return
11205 `integer_type_node' if the given node turns out to be an
11206 ERROR_MARK node. */
11209 field_type (const_tree decl
)
11213 if (TREE_CODE (decl
) == ERROR_MARK
)
11214 return integer_type_node
;
11216 type
= DECL_BIT_FIELD_TYPE (decl
);
11217 if (type
== NULL_TREE
)
11218 type
= TREE_TYPE (decl
);
11223 /* Given a pointer to a tree node, return the alignment in bits for
11224 it, or else return BITS_PER_WORD if the node actually turns out to
11225 be an ERROR_MARK node. */
11227 static inline unsigned
11228 simple_type_align_in_bits (const_tree type
)
11230 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
11233 static inline unsigned
11234 simple_decl_align_in_bits (const_tree decl
)
11236 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
11239 /* Return the result of rounding T up to ALIGN. */
11241 static inline HOST_WIDE_INT
11242 round_up_to_align (HOST_WIDE_INT t
, unsigned int align
)
11244 /* We must be careful if T is negative because HOST_WIDE_INT can be
11245 either "above" or "below" unsigned int as per the C promotion
11246 rules, depending on the host, thus making the signedness of the
11247 direct multiplication and division unpredictable. */
11248 unsigned HOST_WIDE_INT u
= (unsigned HOST_WIDE_INT
) t
;
11254 return (HOST_WIDE_INT
) u
;
11257 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
11258 lowest addressed byte of the "containing object" for the given FIELD_DECL,
11259 or return 0 if we are unable to determine what that offset is, either
11260 because the argument turns out to be a pointer to an ERROR_MARK node, or
11261 because the offset is actually variable. (We can't handle the latter case
11264 static HOST_WIDE_INT
11265 field_byte_offset (const_tree decl
)
11267 HOST_WIDE_INT object_offset_in_bits
;
11268 HOST_WIDE_INT bitpos_int
;
11270 if (TREE_CODE (decl
) == ERROR_MARK
)
11273 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
11275 /* We cannot yet cope with fields whose positions are variable, so
11276 for now, when we see such things, we simply return 0. Someday, we may
11277 be able to handle such cases, but it will be damn difficult. */
11278 if (! host_integerp (bit_position (decl
), 0))
11281 bitpos_int
= int_bit_position (decl
);
11283 #ifdef PCC_BITFIELD_TYPE_MATTERS
11284 if (PCC_BITFIELD_TYPE_MATTERS
)
11287 tree field_size_tree
;
11288 HOST_WIDE_INT deepest_bitpos
;
11289 unsigned HOST_WIDE_INT field_size_in_bits
;
11290 unsigned int type_align_in_bits
;
11291 unsigned int decl_align_in_bits
;
11292 unsigned HOST_WIDE_INT type_size_in_bits
;
11294 type
= field_type (decl
);
11295 type_size_in_bits
= simple_type_size_in_bits (type
);
11296 type_align_in_bits
= simple_type_align_in_bits (type
);
11298 field_size_tree
= DECL_SIZE (decl
);
11300 /* The size could be unspecified if there was an error, or for
11301 a flexible array member. */
11302 if (!field_size_tree
)
11303 field_size_tree
= bitsize_zero_node
;
11305 /* If the size of the field is not constant, use the type size. */
11306 if (host_integerp (field_size_tree
, 1))
11307 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
11309 field_size_in_bits
= type_size_in_bits
;
11311 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
11313 /* The GCC front-end doesn't make any attempt to keep track of the
11314 starting bit offset (relative to the start of the containing
11315 structure type) of the hypothetical "containing object" for a
11316 bit-field. Thus, when computing the byte offset value for the
11317 start of the "containing object" of a bit-field, we must deduce
11318 this information on our own. This can be rather tricky to do in
11319 some cases. For example, handling the following structure type
11320 definition when compiling for an i386/i486 target (which only
11321 aligns long long's to 32-bit boundaries) can be very tricky:
11323 struct S { int field1; long long field2:31; };
11325 Fortunately, there is a simple rule-of-thumb which can be used
11326 in such cases. When compiling for an i386/i486, GCC will
11327 allocate 8 bytes for the structure shown above. It decides to
11328 do this based upon one simple rule for bit-field allocation.
11329 GCC allocates each "containing object" for each bit-field at
11330 the first (i.e. lowest addressed) legitimate alignment boundary
11331 (based upon the required minimum alignment for the declared
11332 type of the field) which it can possibly use, subject to the
11333 condition that there is still enough available space remaining
11334 in the containing object (when allocated at the selected point)
11335 to fully accommodate all of the bits of the bit-field itself.
11337 This simple rule makes it obvious why GCC allocates 8 bytes for
11338 each object of the structure type shown above. When looking
11339 for a place to allocate the "containing object" for `field2',
11340 the compiler simply tries to allocate a 64-bit "containing
11341 object" at each successive 32-bit boundary (starting at zero)
11342 until it finds a place to allocate that 64- bit field such that
11343 at least 31 contiguous (and previously unallocated) bits remain
11344 within that selected 64 bit field. (As it turns out, for the
11345 example above, the compiler finds it is OK to allocate the
11346 "containing object" 64-bit field at bit-offset zero within the
11349 Here we attempt to work backwards from the limited set of facts
11350 we're given, and we try to deduce from those facts, where GCC
11351 must have believed that the containing object started (within
11352 the structure type). The value we deduce is then used (by the
11353 callers of this routine) to generate DW_AT_location and
11354 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11355 the case of DW_AT_location, regular fields as well). */
11357 /* Figure out the bit-distance from the start of the structure to
11358 the "deepest" bit of the bit-field. */
11359 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
11361 /* This is the tricky part. Use some fancy footwork to deduce
11362 where the lowest addressed bit of the containing object must
11364 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
11366 /* Round up to type_align by default. This works best for
11368 object_offset_in_bits
11369 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
11371 if (object_offset_in_bits
> bitpos_int
)
11373 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
11375 /* Round up to decl_align instead. */
11376 object_offset_in_bits
11377 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
11382 object_offset_in_bits
= bitpos_int
;
11384 return object_offset_in_bits
/ BITS_PER_UNIT
;
11387 /* The following routines define various Dwarf attributes and any data
11388 associated with them. */
11390 /* Add a location description attribute value to a DIE.
11392 This emits location attributes suitable for whole variables and
11393 whole parameters. Note that the location attributes for struct fields are
11394 generated by the routine `data_member_location_attribute' below. */
11397 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
11398 dw_loc_descr_ref descr
)
11401 add_AT_loc (die
, attr_kind
, descr
);
11404 /* Attach the specialized form of location attribute used for data members of
11405 struct and union types. In the special case of a FIELD_DECL node which
11406 represents a bit-field, the "offset" part of this special location
11407 descriptor must indicate the distance in bytes from the lowest-addressed
11408 byte of the containing struct or union type to the lowest-addressed byte of
11409 the "containing object" for the bit-field. (See the `field_byte_offset'
11412 For any given bit-field, the "containing object" is a hypothetical object
11413 (of some integral or enum type) within which the given bit-field lives. The
11414 type of this hypothetical "containing object" is always the same as the
11415 declared type of the individual bit-field itself (for GCC anyway... the
11416 DWARF spec doesn't actually mandate this). Note that it is the size (in
11417 bytes) of the hypothetical "containing object" which will be given in the
11418 DW_AT_byte_size attribute for this bit-field. (See the
11419 `byte_size_attribute' function below.) It is also used when calculating the
11420 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11421 function below.) */
11424 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
11426 HOST_WIDE_INT offset
;
11427 dw_loc_descr_ref loc_descr
= 0;
11429 if (TREE_CODE (decl
) == TREE_BINFO
)
11431 /* We're working on the TAG_inheritance for a base class. */
11432 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
11434 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11435 aren't at a fixed offset from all (sub)objects of the same
11436 type. We need to extract the appropriate offset from our
11437 vtable. The following dwarf expression means
11439 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11441 This is specific to the V3 ABI, of course. */
11443 dw_loc_descr_ref tmp
;
11445 /* Make a copy of the object address. */
11446 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
11447 add_loc_descr (&loc_descr
, tmp
);
11449 /* Extract the vtable address. */
11450 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
11451 add_loc_descr (&loc_descr
, tmp
);
11453 /* Calculate the address of the offset. */
11454 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
11455 gcc_assert (offset
< 0);
11457 tmp
= int_loc_descriptor (-offset
);
11458 add_loc_descr (&loc_descr
, tmp
);
11459 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
11460 add_loc_descr (&loc_descr
, tmp
);
11462 /* Extract the offset. */
11463 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
11464 add_loc_descr (&loc_descr
, tmp
);
11466 /* Add it to the object address. */
11467 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
11468 add_loc_descr (&loc_descr
, tmp
);
11471 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
11474 offset
= field_byte_offset (decl
);
11478 if (dwarf_version
> 2)
11480 /* Don't need to output a location expression, just the constant. */
11481 add_AT_int (die
, DW_AT_data_member_location
, offset
);
11486 enum dwarf_location_atom op
;
11488 /* The DWARF2 standard says that we should assume that the structure
11489 address is already on the stack, so we can specify a structure
11490 field address by using DW_OP_plus_uconst. */
11492 #ifdef MIPS_DEBUGGING_INFO
11493 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11494 operator correctly. It works only if we leave the offset on the
11498 op
= DW_OP_plus_uconst
;
11501 loc_descr
= new_loc_descr (op
, offset
, 0);
11505 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
11508 /* Writes integer values to dw_vec_const array. */
11511 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
11515 *dest
++ = val
& 0xff;
11521 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11523 static HOST_WIDE_INT
11524 extract_int (const unsigned char *src
, unsigned int size
)
11526 HOST_WIDE_INT val
= 0;
11532 val
|= *--src
& 0xff;
11538 /* Writes floating point values to dw_vec_const array. */
11541 insert_float (const_rtx rtl
, unsigned char *array
)
11543 REAL_VALUE_TYPE rv
;
11547 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
11548 real_to_target (val
, &rv
, GET_MODE (rtl
));
11550 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11551 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
11553 insert_int (val
[i
], 4, array
);
11558 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11559 does not have a "location" either in memory or in a register. These
11560 things can arise in GNU C when a constant is passed as an actual parameter
11561 to an inlined function. They can also arise in C++ where declared
11562 constants do not necessarily get memory "homes". */
11565 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
11567 switch (GET_CODE (rtl
))
11571 HOST_WIDE_INT val
= INTVAL (rtl
);
11574 add_AT_int (die
, DW_AT_const_value
, val
);
11576 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
11581 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11582 floating-point constant. A CONST_DOUBLE is used whenever the
11583 constant requires more than one word in order to be adequately
11584 represented. We output CONST_DOUBLEs as blocks. */
11586 enum machine_mode mode
= GET_MODE (rtl
);
11588 if (SCALAR_FLOAT_MODE_P (mode
))
11590 unsigned int length
= GET_MODE_SIZE (mode
);
11591 unsigned char *array
= GGC_NEWVEC (unsigned char, length
);
11593 insert_float (rtl
, array
);
11594 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
11598 /* ??? We really should be using HOST_WIDE_INT throughout. */
11599 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
11601 add_AT_long_long (die
, DW_AT_const_value
,
11602 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
11609 enum machine_mode mode
= GET_MODE (rtl
);
11610 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
11611 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
11612 unsigned char *array
= GGC_NEWVEC (unsigned char, length
* elt_size
);
11616 switch (GET_MODE_CLASS (mode
))
11618 case MODE_VECTOR_INT
:
11619 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11621 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11622 HOST_WIDE_INT lo
, hi
;
11624 switch (GET_CODE (elt
))
11632 lo
= CONST_DOUBLE_LOW (elt
);
11633 hi
= CONST_DOUBLE_HIGH (elt
);
11637 gcc_unreachable ();
11640 if (elt_size
<= sizeof (HOST_WIDE_INT
))
11641 insert_int (lo
, elt_size
, p
);
11644 unsigned char *p0
= p
;
11645 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
11647 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
11648 if (WORDS_BIG_ENDIAN
)
11653 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
11654 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
11659 case MODE_VECTOR_FLOAT
:
11660 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
11662 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
11663 insert_float (elt
, p
);
11668 gcc_unreachable ();
11671 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
11676 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
11682 add_AT_addr (die
, DW_AT_const_value
, rtl
);
11683 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
11687 /* In cases where an inlined instance of an inline function is passed
11688 the address of an `auto' variable (which is local to the caller) we
11689 can get a situation where the DECL_RTL of the artificial local
11690 variable (for the inlining) which acts as a stand-in for the
11691 corresponding formal parameter (of the inline function) will look
11692 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11693 exactly a compile-time constant expression, but it isn't the address
11694 of the (artificial) local variable either. Rather, it represents the
11695 *value* which the artificial local variable always has during its
11696 lifetime. We currently have no way to represent such quasi-constant
11697 values in Dwarf, so for now we just punt and generate nothing. */
11701 /* No other kinds of rtx should be possible here. */
11702 gcc_unreachable ();
11707 /* Determine whether the evaluation of EXPR references any variables
11708 or functions which aren't otherwise used (and therefore may not be
11711 reference_to_unused (tree
* tp
, int * walk_subtrees
,
11712 void * data ATTRIBUTE_UNUSED
)
11714 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
11715 *walk_subtrees
= 0;
11717 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
11718 && ! TREE_ASM_WRITTEN (*tp
))
11720 /* ??? The C++ FE emits debug information for using decls, so
11721 putting gcc_unreachable here falls over. See PR31899. For now
11722 be conservative. */
11723 else if (!cgraph_global_info_ready
11724 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
11726 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
11728 struct varpool_node
*node
= varpool_node (*tp
);
11732 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
11733 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
11735 struct cgraph_node
*node
= cgraph_node (*tp
);
11736 if (node
->process
|| TREE_ASM_WRITTEN (*tp
))
11739 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
11745 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11746 for use in a later add_const_value_attribute call. */
11749 rtl_for_decl_init (tree init
, tree type
)
11751 rtx rtl
= NULL_RTX
;
11753 /* If a variable is initialized with a string constant without embedded
11754 zeros, build CONST_STRING. */
11755 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
11757 tree enttype
= TREE_TYPE (type
);
11758 tree domain
= TYPE_DOMAIN (type
);
11759 enum machine_mode mode
= TYPE_MODE (enttype
);
11761 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
11763 && integer_zerop (TYPE_MIN_VALUE (domain
))
11764 && compare_tree_int (TYPE_MAX_VALUE (domain
),
11765 TREE_STRING_LENGTH (init
) - 1) == 0
11766 && ((size_t) TREE_STRING_LENGTH (init
)
11767 == strlen (TREE_STRING_POINTER (init
)) + 1))
11768 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
11769 ggc_strdup (TREE_STRING_POINTER (init
)));
11771 /* Other aggregates, and complex values, could be represented using
11773 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
11775 /* Vectors only work if their mode is supported by the target.
11776 FIXME: generic vectors ought to work too. */
11777 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
11779 /* If the initializer is something that we know will expand into an
11780 immediate RTL constant, expand it now. We must be careful not to
11781 reference variables which won't be output. */
11782 else if (initializer_constant_valid_p (init
, type
)
11783 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
11785 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11787 if (TREE_CODE (type
) == VECTOR_TYPE
)
11788 switch (TREE_CODE (init
))
11793 if (TREE_CONSTANT (init
))
11795 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
11796 bool constant_p
= true;
11798 unsigned HOST_WIDE_INT ix
;
11800 /* Even when ctor is constant, it might contain non-*_CST
11801 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11802 belong into VECTOR_CST nodes. */
11803 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
11804 if (!CONSTANT_CLASS_P (value
))
11806 constant_p
= false;
11812 init
= build_vector_from_ctor (type
, elts
);
11822 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
11824 /* If expand_expr returns a MEM, it wasn't immediate. */
11825 gcc_assert (!rtl
|| !MEM_P (rtl
));
11831 /* Generate RTL for the variable DECL to represent its location. */
11834 rtl_for_decl_location (tree decl
)
11838 /* Here we have to decide where we are going to say the parameter "lives"
11839 (as far as the debugger is concerned). We only have a couple of
11840 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11842 DECL_RTL normally indicates where the parameter lives during most of the
11843 activation of the function. If optimization is enabled however, this
11844 could be either NULL or else a pseudo-reg. Both of those cases indicate
11845 that the parameter doesn't really live anywhere (as far as the code
11846 generation parts of GCC are concerned) during most of the function's
11847 activation. That will happen (for example) if the parameter is never
11848 referenced within the function.
11850 We could just generate a location descriptor here for all non-NULL
11851 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11852 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11853 where DECL_RTL is NULL or is a pseudo-reg.
11855 Note however that we can only get away with using DECL_INCOMING_RTL as
11856 a backup substitute for DECL_RTL in certain limited cases. In cases
11857 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11858 we can be sure that the parameter was passed using the same type as it is
11859 declared to have within the function, and that its DECL_INCOMING_RTL
11860 points us to a place where a value of that type is passed.
11862 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11863 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11864 because in these cases DECL_INCOMING_RTL points us to a value of some
11865 type which is *different* from the type of the parameter itself. Thus,
11866 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11867 such cases, the debugger would end up (for example) trying to fetch a
11868 `float' from a place which actually contains the first part of a
11869 `double'. That would lead to really incorrect and confusing
11870 output at debug-time.
11872 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11873 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11874 are a couple of exceptions however. On little-endian machines we can
11875 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11876 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11877 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11878 when (on a little-endian machine) a non-prototyped function has a
11879 parameter declared to be of type `short' or `char'. In such cases,
11880 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11881 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11882 passed `int' value. If the debugger then uses that address to fetch
11883 a `short' or a `char' (on a little-endian machine) the result will be
11884 the correct data, so we allow for such exceptional cases below.
11886 Note that our goal here is to describe the place where the given formal
11887 parameter lives during most of the function's activation (i.e. between the
11888 end of the prologue and the start of the epilogue). We'll do that as best
11889 as we can. Note however that if the given formal parameter is modified
11890 sometime during the execution of the function, then a stack backtrace (at
11891 debug-time) will show the function as having been called with the *new*
11892 value rather than the value which was originally passed in. This happens
11893 rarely enough that it is not a major problem, but it *is* a problem, and
11894 I'd like to fix it.
11896 A future version of dwarf2out.c may generate two additional attributes for
11897 any given DW_TAG_formal_parameter DIE which will describe the "passed
11898 type" and the "passed location" for the given formal parameter in addition
11899 to the attributes we now generate to indicate the "declared type" and the
11900 "active location" for each parameter. This additional set of attributes
11901 could be used by debuggers for stack backtraces. Separately, note that
11902 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11903 This happens (for example) for inlined-instances of inline function formal
11904 parameters which are never referenced. This really shouldn't be
11905 happening. All PARM_DECL nodes should get valid non-NULL
11906 DECL_INCOMING_RTL values. FIXME. */
11908 /* Use DECL_RTL as the "location" unless we find something better. */
11909 rtl
= DECL_RTL_IF_SET (decl
);
11911 /* When generating abstract instances, ignore everything except
11912 constants, symbols living in memory, and symbols living in
11913 fixed registers. */
11914 if (! reload_completed
)
11917 && (CONSTANT_P (rtl
)
11919 && CONSTANT_P (XEXP (rtl
, 0)))
11921 && TREE_CODE (decl
) == VAR_DECL
11922 && TREE_STATIC (decl
))))
11924 rtl
= targetm
.delegitimize_address (rtl
);
11929 else if (TREE_CODE (decl
) == PARM_DECL
)
11931 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
11933 tree declared_type
= TREE_TYPE (decl
);
11934 tree passed_type
= DECL_ARG_TYPE (decl
);
11935 enum machine_mode dmode
= TYPE_MODE (declared_type
);
11936 enum machine_mode pmode
= TYPE_MODE (passed_type
);
11938 /* This decl represents a formal parameter which was optimized out.
11939 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11940 all cases where (rtl == NULL_RTX) just below. */
11941 if (dmode
== pmode
)
11942 rtl
= DECL_INCOMING_RTL (decl
);
11943 else if (SCALAR_INT_MODE_P (dmode
)
11944 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
11945 && DECL_INCOMING_RTL (decl
))
11947 rtx inc
= DECL_INCOMING_RTL (decl
);
11950 else if (MEM_P (inc
))
11952 if (BYTES_BIG_ENDIAN
)
11953 rtl
= adjust_address_nv (inc
, dmode
,
11954 GET_MODE_SIZE (pmode
)
11955 - GET_MODE_SIZE (dmode
));
11962 /* If the parm was passed in registers, but lives on the stack, then
11963 make a big endian correction if the mode of the type of the
11964 parameter is not the same as the mode of the rtl. */
11965 /* ??? This is the same series of checks that are made in dbxout.c before
11966 we reach the big endian correction code there. It isn't clear if all
11967 of these checks are necessary here, but keeping them all is the safe
11969 else if (MEM_P (rtl
)
11970 && XEXP (rtl
, 0) != const0_rtx
11971 && ! CONSTANT_P (XEXP (rtl
, 0))
11972 /* Not passed in memory. */
11973 && !MEM_P (DECL_INCOMING_RTL (decl
))
11974 /* Not passed by invisible reference. */
11975 && (!REG_P (XEXP (rtl
, 0))
11976 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
11977 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
11978 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11979 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
11982 /* Big endian correction check. */
11983 && BYTES_BIG_ENDIAN
11984 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
11985 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
11988 int offset
= (UNITS_PER_WORD
11989 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
11991 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11992 plus_constant (XEXP (rtl
, 0), offset
));
11995 else if (TREE_CODE (decl
) == VAR_DECL
11998 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
11999 && BYTES_BIG_ENDIAN
)
12001 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
12002 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
12004 /* If a variable is declared "register" yet is smaller than
12005 a register, then if we store the variable to memory, it
12006 looks like we're storing a register-sized value, when in
12007 fact we are not. We need to adjust the offset of the
12008 storage location to reflect the actual value's bytes,
12009 else gdb will not be able to display it. */
12011 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
12012 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
12015 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
12016 and will have been substituted directly into all expressions that use it.
12017 C does not have such a concept, but C++ and other languages do. */
12018 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
12019 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
12022 rtl
= targetm
.delegitimize_address (rtl
);
12024 /* If we don't look past the constant pool, we risk emitting a
12025 reference to a constant pool entry that isn't referenced from
12026 code, and thus is not emitted. */
12028 rtl
= avoid_constant_pool_reference (rtl
);
12033 /* We need to figure out what section we should use as the base for the
12034 address ranges where a given location is valid.
12035 1. If this particular DECL has a section associated with it, use that.
12036 2. If this function has a section associated with it, use that.
12037 3. Otherwise, use the text section.
12038 XXX: If you split a variable across multiple sections, we won't notice. */
12040 static const char *
12041 secname_for_decl (const_tree decl
)
12043 const char *secname
;
12045 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
12047 tree sectree
= DECL_SECTION_NAME (decl
);
12048 secname
= TREE_STRING_POINTER (sectree
);
12050 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
12052 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
12053 secname
= TREE_STRING_POINTER (sectree
);
12055 else if (cfun
&& in_cold_section_p
)
12056 secname
= crtl
->subsections
.cold_section_label
;
12058 secname
= text_section_label
;
12063 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
12064 returned. If so, the decl for the COMMON block is returned, and the
12065 value is the offset into the common block for the symbol. */
12068 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
12070 tree val_expr
, cvar
;
12071 enum machine_mode mode
;
12072 HOST_WIDE_INT bitsize
, bitpos
;
12074 int volatilep
= 0, unsignedp
= 0;
12076 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
12077 it does not have a value (the offset into the common area), or if it
12078 is thread local (as opposed to global) then it isn't common, and shouldn't
12079 be handled as such. */
12080 if (TREE_CODE (decl
) != VAR_DECL
12081 || !TREE_PUBLIC (decl
)
12082 || !TREE_STATIC (decl
)
12083 || !DECL_HAS_VALUE_EXPR_P (decl
)
12087 val_expr
= DECL_VALUE_EXPR (decl
);
12088 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
12091 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
12092 &mode
, &unsignedp
, &volatilep
, true);
12094 if (cvar
== NULL_TREE
12095 || TREE_CODE (cvar
) != VAR_DECL
12096 || DECL_ARTIFICIAL (cvar
)
12097 || !TREE_PUBLIC (cvar
))
12101 if (offset
!= NULL
)
12103 if (!host_integerp (offset
, 0))
12105 *value
= tree_low_cst (offset
, 0);
12108 *value
+= bitpos
/ BITS_PER_UNIT
;
12113 /* Dereference a location expression LOC if DECL is passed by invisible
12116 static dw_loc_descr_ref
12117 loc_by_reference (dw_loc_descr_ref loc
, tree decl
)
12119 HOST_WIDE_INT size
;
12120 enum dwarf_location_atom op
;
12125 if ((TREE_CODE (decl
) != PARM_DECL
12126 && TREE_CODE (decl
) != RESULT_DECL
12127 && TREE_CODE (decl
) != VAR_DECL
)
12128 || !DECL_BY_REFERENCE (decl
))
12131 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12132 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12133 location expression is considered to be address of a memory location,
12134 rather than the register itself. */
12135 if (((loc
->dw_loc_opc
>= DW_OP_reg0
&& loc
->dw_loc_opc
<= DW_OP_reg31
)
12136 || loc
->dw_loc_opc
== DW_OP_regx
)
12137 && (loc
->dw_loc_next
== NULL
12138 || (loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_uninit
12139 && loc
->dw_loc_next
->dw_loc_next
== NULL
)))
12141 if (loc
->dw_loc_opc
== DW_OP_regx
)
12143 loc
->dw_loc_opc
= DW_OP_bregx
;
12144 loc
->dw_loc_oprnd2
.v
.val_int
= 0;
12149 = (enum dwarf_location_atom
)
12150 (loc
->dw_loc_opc
+ (DW_OP_breg0
- DW_OP_reg0
));
12151 loc
->dw_loc_oprnd1
.v
.val_int
= 0;
12156 size
= int_size_in_bytes (TREE_TYPE (decl
));
12157 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
12159 else if (size
== DWARF2_ADDR_SIZE
)
12162 op
= DW_OP_deref_size
;
12163 add_loc_descr (&loc
, new_loc_descr (op
, size
, 0));
12167 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
12168 data attribute for a variable or a parameter. We generate the
12169 DW_AT_const_value attribute only in those cases where the given variable
12170 or parameter does not have a true "location" either in memory or in a
12171 register. This can happen (for example) when a constant is passed as an
12172 actual argument in a call to an inline function. (It's possible that
12173 these things can crop up in other ways also.) Note that one type of
12174 constant value which can be passed into an inlined function is a constant
12175 pointer. This can happen for example if an actual argument in an inlined
12176 function call evaluates to a compile-time constant address. */
12179 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
12180 enum dwarf_attribute attr
)
12183 dw_loc_descr_ref descr
;
12184 var_loc_list
*loc_list
;
12185 struct var_loc_node
*node
;
12186 if (TREE_CODE (decl
) == ERROR_MARK
)
12189 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
12190 || TREE_CODE (decl
) == RESULT_DECL
);
12192 /* See if we possibly have multiple locations for this variable. */
12193 loc_list
= lookup_decl_loc (decl
);
12195 /* If it truly has multiple locations, the first and last node will
12197 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
12199 const char *endname
, *secname
;
12200 dw_loc_list_ref list
;
12202 enum var_init_status initialized
;
12204 /* Now that we know what section we are using for a base,
12205 actually construct the list of locations.
12206 The first location information is what is passed to the
12207 function that creates the location list, and the remaining
12208 locations just get added on to that list.
12209 Note that we only know the start address for a location
12210 (IE location changes), so to build the range, we use
12211 the range [current location start, next location start].
12212 This means we have to special case the last node, and generate
12213 a range of [last location start, end of function label]. */
12215 node
= loc_list
->first
;
12216 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
12217 secname
= secname_for_decl (decl
);
12219 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
))
12220 initialized
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
12222 initialized
= VAR_INIT_STATUS_INITIALIZED
;
12224 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
), decl
);
12225 list
= new_loc_list (descr
, node
->label
, node
->next
->label
, secname
, 1);
12228 for (; node
->next
; node
= node
->next
)
12229 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
12231 /* The variable has a location between NODE->LABEL and
12232 NODE->NEXT->LABEL. */
12233 enum var_init_status initialized
=
12234 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
12235 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
12236 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
12238 add_loc_descr_to_loc_list (&list
, descr
,
12239 node
->label
, node
->next
->label
, secname
);
12242 /* If the variable has a location at the last label
12243 it keeps its location until the end of function. */
12244 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
12246 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12247 enum var_init_status initialized
=
12248 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
12250 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
12251 if (!current_function_decl
)
12252 endname
= text_end_label
;
12255 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12256 current_function_funcdef_no
);
12257 endname
= ggc_strdup (label_id
);
12259 descr
= loc_by_reference (loc_descriptor (varloc
, initialized
),
12261 add_loc_descr_to_loc_list (&list
, descr
,
12262 node
->label
, endname
, secname
);
12265 /* Finally, add the location list to the DIE, and we are done. */
12266 add_AT_loc_list (die
, attr
, list
);
12270 /* Try to get some constant RTL for this decl, and use that as the value of
12273 rtl
= rtl_for_decl_location (decl
);
12274 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
12276 add_const_value_attribute (die
, rtl
);
12280 /* If we have tried to generate the location otherwise, and it
12281 didn't work out (we wouldn't be here if we did), and we have a one entry
12282 location list, try generating a location from that. */
12283 if (loc_list
&& loc_list
->first
)
12285 enum var_init_status status
;
12286 node
= loc_list
->first
;
12287 status
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
12288 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
), status
);
12291 descr
= loc_by_reference (descr
, decl
);
12292 add_AT_location_description (die
, attr
, descr
);
12297 /* We couldn't get any rtl, so try directly generating the location
12298 description from the tree. */
12299 descr
= loc_descriptor_from_tree (decl
);
12302 descr
= loc_by_reference (descr
, decl
);
12303 add_AT_location_description (die
, attr
, descr
);
12306 /* None of that worked, so it must not really have a location;
12307 try adding a constant value attribute from the DECL_INITIAL. */
12308 tree_add_const_value_attribute (die
, decl
);
12311 /* Add VARIABLE and DIE into deferred locations list. */
12314 defer_location (tree variable
, dw_die_ref die
)
12316 deferred_locations entry
;
12317 entry
.variable
= variable
;
12319 VEC_safe_push (deferred_locations
, gc
, deferred_locations_list
, &entry
);
12322 /* Helper function for tree_add_const_value_attribute. Natively encode
12323 initializer INIT into an array. Return true if successful. */
12326 native_encode_initializer (tree init
, unsigned char *array
, int size
)
12330 if (init
== NULL_TREE
)
12334 switch (TREE_CODE (init
))
12337 type
= TREE_TYPE (init
);
12338 if (TREE_CODE (type
) == ARRAY_TYPE
)
12340 tree enttype
= TREE_TYPE (type
);
12341 enum machine_mode mode
= TYPE_MODE (enttype
);
12343 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
12345 if (int_size_in_bytes (type
) != size
)
12347 if (size
> TREE_STRING_LENGTH (init
))
12349 memcpy (array
, TREE_STRING_POINTER (init
),
12350 TREE_STRING_LENGTH (init
));
12351 memset (array
+ TREE_STRING_LENGTH (init
),
12352 '\0', size
- TREE_STRING_LENGTH (init
));
12355 memcpy (array
, TREE_STRING_POINTER (init
), size
);
12360 type
= TREE_TYPE (init
);
12361 if (int_size_in_bytes (type
) != size
)
12363 if (TREE_CODE (type
) == ARRAY_TYPE
)
12365 HOST_WIDE_INT min_index
;
12366 unsigned HOST_WIDE_INT cnt
;
12367 int curpos
= 0, fieldsize
;
12368 constructor_elt
*ce
;
12370 if (TYPE_DOMAIN (type
) == NULL_TREE
12371 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
12374 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
12375 if (fieldsize
<= 0)
12378 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
12379 memset (array
, '\0', size
);
12381 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
12384 tree val
= ce
->value
;
12385 tree index
= ce
->index
;
12387 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
12388 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
12391 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
12396 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
12399 curpos
= pos
+ fieldsize
;
12400 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
12402 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
12403 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
12407 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
12408 curpos
+= fieldsize
;
12411 gcc_assert (curpos
<= size
);
12415 else if (TREE_CODE (type
) == RECORD_TYPE
12416 || TREE_CODE (type
) == UNION_TYPE
)
12418 tree field
= NULL_TREE
;
12419 unsigned HOST_WIDE_INT cnt
;
12420 constructor_elt
*ce
;
12422 if (int_size_in_bytes (type
) != size
)
12425 if (TREE_CODE (type
) == RECORD_TYPE
)
12426 field
= TYPE_FIELDS (type
);
12429 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (init
), cnt
, ce
);
12430 cnt
++, field
= field
? TREE_CHAIN (field
) : 0)
12432 tree val
= ce
->value
;
12433 int pos
, fieldsize
;
12435 if (ce
->index
!= 0)
12441 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
12444 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
12445 && TYPE_DOMAIN (TREE_TYPE (field
))
12446 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
12448 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
12449 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
12451 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
12452 pos
= int_byte_position (field
);
12453 gcc_assert (pos
+ fieldsize
<= size
);
12455 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
12461 case VIEW_CONVERT_EXPR
:
12462 case NON_LVALUE_EXPR
:
12463 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
12465 return native_encode_expr (init
, array
, size
) == size
;
12469 /* If we don't have a copy of this variable in memory for some reason (such
12470 as a C++ member constant that doesn't have an out-of-line definition),
12471 we should tell the debugger about the constant value. */
12474 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
12477 tree type
= TREE_TYPE (decl
);
12480 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
12483 init
= DECL_INITIAL (decl
);
12484 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
12489 rtl
= rtl_for_decl_init (init
, type
);
12491 add_const_value_attribute (var_die
, rtl
);
12492 /* If the host and target are sane, try harder. */
12493 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
12494 && initializer_constant_valid_p (init
, type
))
12496 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
12497 if (size
> 0 && (int) size
== size
)
12499 unsigned char *array
= GGC_CNEWVEC (unsigned char, size
);
12501 if (native_encode_initializer (init
, array
, size
))
12502 add_AT_vec (var_die
, DW_AT_const_value
, size
, 1, array
);
12507 /* Convert the CFI instructions for the current function into a
12508 location list. This is used for DW_AT_frame_base when we targeting
12509 a dwarf2 consumer that does not support the dwarf3
12510 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12513 static dw_loc_list_ref
12514 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
12517 dw_loc_list_ref list
, *list_tail
;
12519 dw_cfa_location last_cfa
, next_cfa
;
12520 const char *start_label
, *last_label
, *section
;
12521 dw_cfa_location remember
;
12523 fde
= current_fde ();
12524 gcc_assert (fde
!= NULL
);
12526 section
= secname_for_decl (current_function_decl
);
12530 memset (&next_cfa
, 0, sizeof (next_cfa
));
12531 next_cfa
.reg
= INVALID_REGNUM
;
12532 remember
= next_cfa
;
12534 start_label
= fde
->dw_fde_begin
;
12536 /* ??? Bald assumption that the CIE opcode list does not contain
12537 advance opcodes. */
12538 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
12539 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
12541 last_cfa
= next_cfa
;
12542 last_label
= start_label
;
12544 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
12545 switch (cfi
->dw_cfi_opc
)
12547 case DW_CFA_set_loc
:
12548 case DW_CFA_advance_loc1
:
12549 case DW_CFA_advance_loc2
:
12550 case DW_CFA_advance_loc4
:
12551 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12553 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12554 start_label
, last_label
, section
,
12557 list_tail
= &(*list_tail
)->dw_loc_next
;
12558 last_cfa
= next_cfa
;
12559 start_label
= last_label
;
12561 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
12564 case DW_CFA_advance_loc
:
12565 /* The encoding is complex enough that we should never emit this. */
12566 gcc_unreachable ();
12569 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
12573 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
12575 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
12576 start_label
, last_label
, section
,
12578 list_tail
= &(*list_tail
)->dw_loc_next
;
12579 start_label
= last_label
;
12581 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
12582 start_label
, fde
->dw_fde_end
, section
,
12588 /* Compute a displacement from the "steady-state frame pointer" to the
12589 frame base (often the same as the CFA), and store it in
12590 frame_pointer_fb_offset. OFFSET is added to the displacement
12591 before the latter is negated. */
12594 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
12598 #ifdef FRAME_POINTER_CFA_OFFSET
12599 reg
= frame_pointer_rtx
;
12600 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
12602 reg
= arg_pointer_rtx
;
12603 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
12606 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
12607 if (GET_CODE (elim
) == PLUS
)
12609 offset
+= INTVAL (XEXP (elim
, 1));
12610 elim
= XEXP (elim
, 0);
12613 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12614 && (elim
== hard_frame_pointer_rtx
12615 || elim
== stack_pointer_rtx
))
12616 || elim
== (frame_pointer_needed
12617 ? hard_frame_pointer_rtx
12618 : stack_pointer_rtx
));
12620 frame_pointer_fb_offset
= -offset
;
12623 /* Generate a DW_AT_name attribute given some string value to be included as
12624 the value of the attribute. */
12627 add_name_attribute (dw_die_ref die
, const char *name_string
)
12629 if (name_string
!= NULL
&& *name_string
!= 0)
12631 if (demangle_name_func
)
12632 name_string
= (*demangle_name_func
) (name_string
);
12634 add_AT_string (die
, DW_AT_name
, name_string
);
12638 /* Generate a DW_AT_comp_dir attribute for DIE. */
12641 add_comp_dir_attribute (dw_die_ref die
)
12643 const char *wd
= get_src_pwd ();
12645 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
12648 /* Given a tree node describing an array bound (either lower or upper) output
12649 a representation for that bound. */
12652 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
12654 switch (TREE_CODE (bound
))
12659 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12661 if (! host_integerp (bound
, 0)
12662 || (bound_attr
== DW_AT_lower_bound
12663 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
12664 || (is_fortran () && integer_onep (bound
)))))
12665 /* Use the default. */
12668 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
12672 case VIEW_CONVERT_EXPR
:
12673 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
12683 dw_die_ref decl_die
= lookup_decl_die (bound
);
12684 dw_loc_descr_ref loc
;
12686 /* ??? Can this happen, or should the variable have been bound
12687 first? Probably it can, since I imagine that we try to create
12688 the types of parameters in the order in which they exist in
12689 the list, and won't have created a forward reference to a
12690 later parameter. */
12691 if (decl_die
!= NULL
)
12692 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12695 loc
= loc_descriptor_from_tree_1 (bound
, 0);
12696 add_AT_location_description (subrange_die
, bound_attr
, loc
);
12703 /* Otherwise try to create a stack operation procedure to
12704 evaluate the value of the array bound. */
12706 dw_die_ref ctx
, decl_die
;
12707 dw_loc_descr_ref loc
;
12709 loc
= loc_descriptor_from_tree (bound
);
12713 if (current_function_decl
== 0)
12714 ctx
= comp_unit_die
;
12716 ctx
= lookup_decl_die (current_function_decl
);
12718 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
12719 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12720 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
12721 add_AT_loc (decl_die
, DW_AT_location
, loc
);
12723 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
12729 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12730 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12731 Note that the block of subscript information for an array type also
12732 includes information about the element type of the given array type. */
12735 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
12737 unsigned dimension_number
;
12739 dw_die_ref subrange_die
;
12741 for (dimension_number
= 0;
12742 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
12743 type
= TREE_TYPE (type
), dimension_number
++)
12745 tree domain
= TYPE_DOMAIN (type
);
12747 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
12750 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12751 and (in GNU C only) variable bounds. Handle all three forms
12753 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
12756 /* We have an array type with specified bounds. */
12757 lower
= TYPE_MIN_VALUE (domain
);
12758 upper
= TYPE_MAX_VALUE (domain
);
12760 /* Define the index type. */
12761 if (TREE_TYPE (domain
))
12763 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12764 TREE_TYPE field. We can't emit debug info for this
12765 because it is an unnamed integral type. */
12766 if (TREE_CODE (domain
) == INTEGER_TYPE
12767 && TYPE_NAME (domain
) == NULL_TREE
12768 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
12769 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
12772 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
12776 /* ??? If upper is NULL, the array has unspecified length,
12777 but it does have a lower bound. This happens with Fortran
12779 Since the debugger is definitely going to need to know N
12780 to produce useful results, go ahead and output the lower
12781 bound solo, and hope the debugger can cope. */
12783 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
12785 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
12788 /* Otherwise we have an array type with an unspecified length. The
12789 DWARF-2 spec does not say how to handle this; let's just leave out the
12795 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
12799 switch (TREE_CODE (tree_node
))
12804 case ENUMERAL_TYPE
:
12807 case QUAL_UNION_TYPE
:
12808 size
= int_size_in_bytes (tree_node
);
12811 /* For a data member of a struct or union, the DW_AT_byte_size is
12812 generally given as the number of bytes normally allocated for an
12813 object of the *declared* type of the member itself. This is true
12814 even for bit-fields. */
12815 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
12818 gcc_unreachable ();
12821 /* Note that `size' might be -1 when we get to this point. If it is, that
12822 indicates that the byte size of the entity in question is variable. We
12823 have no good way of expressing this fact in Dwarf at the present time,
12824 so just let the -1 pass on through. */
12825 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
12828 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12829 which specifies the distance in bits from the highest order bit of the
12830 "containing object" for the bit-field to the highest order bit of the
12833 For any given bit-field, the "containing object" is a hypothetical object
12834 (of some integral or enum type) within which the given bit-field lives. The
12835 type of this hypothetical "containing object" is always the same as the
12836 declared type of the individual bit-field itself. The determination of the
12837 exact location of the "containing object" for a bit-field is rather
12838 complicated. It's handled by the `field_byte_offset' function (above).
12840 Note that it is the size (in bytes) of the hypothetical "containing object"
12841 which will be given in the DW_AT_byte_size attribute for this bit-field.
12842 (See `byte_size_attribute' above). */
12845 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
12847 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
12848 tree type
= DECL_BIT_FIELD_TYPE (decl
);
12849 HOST_WIDE_INT bitpos_int
;
12850 HOST_WIDE_INT highest_order_object_bit_offset
;
12851 HOST_WIDE_INT highest_order_field_bit_offset
;
12852 HOST_WIDE_INT
unsigned bit_offset
;
12854 /* Must be a field and a bit field. */
12855 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
12857 /* We can't yet handle bit-fields whose offsets are variable, so if we
12858 encounter such things, just return without generating any attribute
12859 whatsoever. Likewise for variable or too large size. */
12860 if (! host_integerp (bit_position (decl
), 0)
12861 || ! host_integerp (DECL_SIZE (decl
), 1))
12864 bitpos_int
= int_bit_position (decl
);
12866 /* Note that the bit offset is always the distance (in bits) from the
12867 highest-order bit of the "containing object" to the highest-order bit of
12868 the bit-field itself. Since the "high-order end" of any object or field
12869 is different on big-endian and little-endian machines, the computation
12870 below must take account of these differences. */
12871 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
12872 highest_order_field_bit_offset
= bitpos_int
;
12874 if (! BYTES_BIG_ENDIAN
)
12876 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
12877 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
12881 = (! BYTES_BIG_ENDIAN
12882 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
12883 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
12885 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
12888 /* For a FIELD_DECL node which represents a bit field, output an attribute
12889 which specifies the length in bits of the given field. */
12892 add_bit_size_attribute (dw_die_ref die
, tree decl
)
12894 /* Must be a field and a bit field. */
12895 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
12896 && DECL_BIT_FIELD_TYPE (decl
));
12898 if (host_integerp (DECL_SIZE (decl
), 1))
12899 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
12902 /* If the compiled language is ANSI C, then add a 'prototyped'
12903 attribute, if arg types are given for the parameters of a function. */
12906 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
12908 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
12909 && TYPE_ARG_TYPES (func_type
) != NULL
)
12910 add_AT_flag (die
, DW_AT_prototyped
, 1);
12913 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12914 by looking in either the type declaration or object declaration
12917 static inline dw_die_ref
12918 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
12920 dw_die_ref origin_die
= NULL
;
12922 if (TREE_CODE (origin
) != FUNCTION_DECL
)
12924 /* We may have gotten separated from the block for the inlined
12925 function, if we're in an exception handler or some such; make
12926 sure that the abstract function has been written out.
12928 Doing this for nested functions is wrong, however; functions are
12929 distinct units, and our context might not even be inline. */
12933 fn
= TYPE_STUB_DECL (fn
);
12935 fn
= decl_function_context (fn
);
12937 dwarf2out_abstract_function (fn
);
12940 if (DECL_P (origin
))
12941 origin_die
= lookup_decl_die (origin
);
12942 else if (TYPE_P (origin
))
12943 origin_die
= lookup_type_die (origin
);
12945 /* XXX: Functions that are never lowered don't always have correct block
12946 trees (in the case of java, they simply have no block tree, in some other
12947 languages). For these functions, there is nothing we can really do to
12948 output correct debug info for inlined functions in all cases. Rather
12949 than die, we'll just produce deficient debug info now, in that we will
12950 have variables without a proper abstract origin. In the future, when all
12951 functions are lowered, we should re-add a gcc_assert (origin_die)
12955 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
12959 /* We do not currently support the pure_virtual attribute. */
12962 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
12964 if (DECL_VINDEX (func_decl
))
12966 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12968 if (host_integerp (DECL_VINDEX (func_decl
), 0))
12969 add_AT_loc (die
, DW_AT_vtable_elem_location
,
12970 new_loc_descr (DW_OP_constu
,
12971 tree_low_cst (DECL_VINDEX (func_decl
), 0),
12974 /* GNU extension: Record what type this method came from originally. */
12975 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12976 add_AT_die_ref (die
, DW_AT_containing_type
,
12977 lookup_type_die (DECL_CONTEXT (func_decl
)));
12981 /* Add source coordinate attributes for the given decl. */
12984 add_src_coords_attributes (dw_die_ref die
, tree decl
)
12986 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12988 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
12989 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
12992 /* Add a DW_AT_name attribute and source coordinate attribute for the
12993 given decl, but only if it actually has a name. */
12996 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
13000 decl_name
= DECL_NAME (decl
);
13001 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
13003 add_name_attribute (die
, dwarf2_name (decl
, 0));
13004 if (! DECL_ARTIFICIAL (decl
))
13005 add_src_coords_attributes (die
, decl
);
13007 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
13008 && TREE_PUBLIC (decl
)
13009 && !DECL_ABSTRACT (decl
)
13010 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
13013 /* Defer until we have an assembler name set. */
13014 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
13016 limbo_die_node
*asm_name
;
13018 asm_name
= GGC_CNEW (limbo_die_node
);
13019 asm_name
->die
= die
;
13020 asm_name
->created_for
= decl
;
13021 asm_name
->next
= deferred_asm_name
;
13022 deferred_asm_name
= asm_name
;
13024 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
13025 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
13026 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
13030 #ifdef VMS_DEBUGGING_INFO
13031 /* Get the function's name, as described by its RTL. This may be different
13032 from the DECL_NAME name used in the source file. */
13033 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
13035 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
13036 XEXP (DECL_RTL (decl
), 0));
13037 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
13042 /* Push a new declaration scope. */
13045 push_decl_scope (tree scope
)
13047 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
13050 /* Pop a declaration scope. */
13053 pop_decl_scope (void)
13055 VEC_pop (tree
, decl_scope_table
);
13058 /* Return the DIE for the scope that immediately contains this type.
13059 Non-named types get global scope. Named types nested in other
13060 types get their containing scope if it's open, or global scope
13061 otherwise. All other types (i.e. function-local named types) get
13062 the current active scope. */
13065 scope_die_for (tree t
, dw_die_ref context_die
)
13067 dw_die_ref scope_die
= NULL
;
13068 tree containing_scope
;
13071 /* Non-types always go in the current scope. */
13072 gcc_assert (TYPE_P (t
));
13074 containing_scope
= TYPE_CONTEXT (t
);
13076 /* Use the containing namespace if it was passed in (for a declaration). */
13077 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
13079 if (context_die
== lookup_decl_die (containing_scope
))
13082 containing_scope
= NULL_TREE
;
13085 /* Ignore function type "scopes" from the C frontend. They mean that
13086 a tagged type is local to a parmlist of a function declarator, but
13087 that isn't useful to DWARF. */
13088 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
13089 containing_scope
= NULL_TREE
;
13091 if (containing_scope
== NULL_TREE
)
13092 scope_die
= comp_unit_die
;
13093 else if (TYPE_P (containing_scope
))
13095 /* For types, we can just look up the appropriate DIE. But
13096 first we check to see if we're in the middle of emitting it
13097 so we know where the new DIE should go. */
13098 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
13099 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
13104 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
13105 || TREE_ASM_WRITTEN (containing_scope
));
13107 /* If none of the current dies are suitable, we get file scope. */
13108 scope_die
= comp_unit_die
;
13111 scope_die
= lookup_type_die (containing_scope
);
13114 scope_die
= context_die
;
13119 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
13122 local_scope_p (dw_die_ref context_die
)
13124 for (; context_die
; context_die
= context_die
->die_parent
)
13125 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
13126 || context_die
->die_tag
== DW_TAG_subprogram
)
13132 /* Returns nonzero if CONTEXT_DIE is a class. */
13135 class_scope_p (dw_die_ref context_die
)
13137 return (context_die
13138 && (context_die
->die_tag
== DW_TAG_structure_type
13139 || context_die
->die_tag
== DW_TAG_class_type
13140 || context_die
->die_tag
== DW_TAG_interface_type
13141 || context_die
->die_tag
== DW_TAG_union_type
));
13144 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
13145 whether or not to treat a DIE in this context as a declaration. */
13148 class_or_namespace_scope_p (dw_die_ref context_die
)
13150 return (class_scope_p (context_die
)
13151 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
13154 /* Many forms of DIEs require a "type description" attribute. This
13155 routine locates the proper "type descriptor" die for the type given
13156 by 'type', and adds a DW_AT_type attribute below the given die. */
13159 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
13160 int decl_volatile
, dw_die_ref context_die
)
13162 enum tree_code code
= TREE_CODE (type
);
13163 dw_die_ref type_die
= NULL
;
13165 /* ??? If this type is an unnamed subrange type of an integral, floating-point
13166 or fixed-point type, use the inner type. This is because we have no
13167 support for unnamed types in base_type_die. This can happen if this is
13168 an Ada subrange type. Correct solution is emit a subrange type die. */
13169 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
13170 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
13171 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
13173 if (code
== ERROR_MARK
13174 /* Handle a special case. For functions whose return type is void, we
13175 generate *no* type attribute. (Note that no object may have type
13176 `void', so this only applies to function return types). */
13177 || code
== VOID_TYPE
)
13180 type_die
= modified_type_die (type
,
13181 decl_const
|| TYPE_READONLY (type
),
13182 decl_volatile
|| TYPE_VOLATILE (type
),
13185 if (type_die
!= NULL
)
13186 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
13189 /* Given an object die, add the calling convention attribute for the
13190 function call type. */
13192 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
13194 enum dwarf_calling_convention value
= DW_CC_normal
;
13196 value
= ((enum dwarf_calling_convention
)
13197 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
13199 /* DWARF doesn't provide a way to identify a program's source-level
13200 entry point. DW_AT_calling_convention attributes are only meant
13201 to describe functions' calling conventions. However, lacking a
13202 better way to signal the Fortran main program, we use this for the
13203 time being, following existing custom. */
13205 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
13206 value
= DW_CC_program
;
13208 /* Only add the attribute if the backend requests it, and
13209 is not DW_CC_normal. */
13210 if (value
&& (value
!= DW_CC_normal
))
13211 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
13214 /* Given a tree pointer to a struct, class, union, or enum type node, return
13215 a pointer to the (string) tag name for the given type, or zero if the type
13216 was declared without a tag. */
13218 static const char *
13219 type_tag (const_tree type
)
13221 const char *name
= 0;
13223 if (TYPE_NAME (type
) != 0)
13227 /* Find the IDENTIFIER_NODE for the type name. */
13228 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
13229 t
= TYPE_NAME (type
);
13231 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
13232 a TYPE_DECL node, regardless of whether or not a `typedef' was
13234 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13235 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
13237 /* We want to be extra verbose. Don't call dwarf_name if
13238 DECL_NAME isn't set. The default hook for decl_printable_name
13239 doesn't like that, and in this context it's correct to return
13240 0, instead of "<anonymous>" or the like. */
13241 if (DECL_NAME (TYPE_NAME (type
)))
13242 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
13245 /* Now get the name as a string, or invent one. */
13246 if (!name
&& t
!= 0)
13247 name
= IDENTIFIER_POINTER (t
);
13250 return (name
== 0 || *name
== '\0') ? 0 : name
;
13253 /* Return the type associated with a data member, make a special check
13254 for bit field types. */
13257 member_declared_type (const_tree member
)
13259 return (DECL_BIT_FIELD_TYPE (member
)
13260 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
13263 /* Get the decl's label, as described by its RTL. This may be different
13264 from the DECL_NAME name used in the source file. */
13267 static const char *
13268 decl_start_label (tree decl
)
13271 const char *fnname
;
13273 x
= DECL_RTL (decl
);
13274 gcc_assert (MEM_P (x
));
13277 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
13279 fnname
= XSTR (x
, 0);
13284 /* These routines generate the internal representation of the DIE's for
13285 the compilation unit. Debugging information is collected by walking
13286 the declaration trees passed in from dwarf2out_decl(). */
13289 gen_array_type_die (tree type
, dw_die_ref context_die
)
13291 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
13292 dw_die_ref array_die
;
13294 /* GNU compilers represent multidimensional array types as sequences of one
13295 dimensional array types whose element types are themselves array types.
13296 We sometimes squish that down to a single array_type DIE with multiple
13297 subscripts in the Dwarf debugging info. The draft Dwarf specification
13298 say that we are allowed to do this kind of compression in C, because
13299 there is no difference between an array of arrays and a multidimensional
13300 array. We don't do this for Ada to remain as close as possible to the
13301 actual representation, which is especially important against the language
13302 flexibilty wrt arrays of variable size. */
13304 bool collapse_nested_arrays
= !is_ada ();
13307 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
13308 DW_TAG_string_type doesn't have DW_AT_type attribute). */
13309 if (TYPE_STRING_FLAG (type
)
13310 && TREE_CODE (type
) == ARRAY_TYPE
13312 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
13314 HOST_WIDE_INT size
;
13316 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
13317 add_name_attribute (array_die
, type_tag (type
));
13318 equate_type_number_to_die (type
, array_die
);
13319 size
= int_size_in_bytes (type
);
13321 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
13322 else if (TYPE_DOMAIN (type
) != NULL_TREE
13323 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
13324 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
13326 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
13327 dw_loc_descr_ref loc
= loc_descriptor_from_tree (szdecl
);
13329 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
13330 if (loc
&& size
> 0)
13332 add_AT_loc (array_die
, DW_AT_string_length
, loc
);
13333 if (size
!= DWARF2_ADDR_SIZE
)
13334 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
13340 /* ??? The SGI dwarf reader fails for array of array of enum types
13341 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
13342 array type comes before the outer array type. We thus call gen_type_die
13343 before we new_die and must prevent nested array types collapsing for this
13346 #ifdef MIPS_DEBUGGING_INFO
13347 gen_type_die (TREE_TYPE (type
), context_die
);
13348 collapse_nested_arrays
= false;
13351 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
13352 add_name_attribute (array_die
, type_tag (type
));
13353 equate_type_number_to_die (type
, array_die
);
13355 if (TREE_CODE (type
) == VECTOR_TYPE
)
13357 /* The frontend feeds us a representation for the vector as a struct
13358 containing an array. Pull out the array type. */
13359 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
13360 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
13363 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13365 && TREE_CODE (type
) == ARRAY_TYPE
13366 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
13367 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
13368 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
13371 /* We default the array ordering. SDB will probably do
13372 the right things even if DW_AT_ordering is not present. It's not even
13373 an issue until we start to get into multidimensional arrays anyway. If
13374 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
13375 then we'll have to put the DW_AT_ordering attribute back in. (But if
13376 and when we find out that we need to put these in, we will only do so
13377 for multidimensional arrays. */
13378 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
13381 #ifdef MIPS_DEBUGGING_INFO
13382 /* The SGI compilers handle arrays of unknown bound by setting
13383 AT_declaration and not emitting any subrange DIEs. */
13384 if (! TYPE_DOMAIN (type
))
13385 add_AT_flag (array_die
, DW_AT_declaration
, 1);
13388 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
13390 /* Add representation of the type of the elements of this array type and
13391 emit the corresponding DIE if we haven't done it already. */
13392 element_type
= TREE_TYPE (type
);
13393 if (collapse_nested_arrays
)
13394 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
13396 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
13398 element_type
= TREE_TYPE (element_type
);
13401 #ifndef MIPS_DEBUGGING_INFO
13402 gen_type_die (element_type
, context_die
);
13405 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
13407 if (get_AT (array_die
, DW_AT_name
))
13408 add_pubtype (type
, array_die
);
13411 static dw_loc_descr_ref
13412 descr_info_loc (tree val
, tree base_decl
)
13414 HOST_WIDE_INT size
;
13415 dw_loc_descr_ref loc
, loc2
;
13416 enum dwarf_location_atom op
;
13418 if (val
== base_decl
)
13419 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
13421 switch (TREE_CODE (val
))
13424 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
13426 return loc_descriptor_from_tree_1 (val
, 0);
13428 if (host_integerp (val
, 0))
13429 return int_loc_descriptor (tree_low_cst (val
, 0));
13432 size
= int_size_in_bytes (TREE_TYPE (val
));
13435 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
13438 if (size
== DWARF2_ADDR_SIZE
)
13439 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
13441 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
13443 case POINTER_PLUS_EXPR
:
13445 if (host_integerp (TREE_OPERAND (val
, 1), 1)
13446 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
13449 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
13452 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
13458 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
13461 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
13464 add_loc_descr (&loc
, loc2
);
13465 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
13487 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
13488 tree val
, tree base_decl
)
13490 dw_loc_descr_ref loc
;
13492 if (host_integerp (val
, 0))
13494 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
13498 loc
= descr_info_loc (val
, base_decl
);
13502 add_AT_loc (die
, attr
, loc
);
13505 /* This routine generates DIE for array with hidden descriptor, details
13506 are filled into *info by a langhook. */
13509 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
13510 dw_die_ref context_die
)
13512 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
13513 dw_die_ref array_die
;
13516 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
13517 add_name_attribute (array_die
, type_tag (type
));
13518 equate_type_number_to_die (type
, array_die
);
13520 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13522 && info
->ndimensions
>= 2)
13523 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
13525 if (info
->data_location
)
13526 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
13528 if (info
->associated
)
13529 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
13531 if (info
->allocated
)
13532 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
13535 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
13537 dw_die_ref subrange_die
13538 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
13540 if (info
->dimen
[dim
].lower_bound
)
13542 /* If it is the default value, omit it. */
13543 if ((is_c_family () || is_java ())
13544 && integer_zerop (info
->dimen
[dim
].lower_bound
))
13546 else if (is_fortran ()
13547 && integer_onep (info
->dimen
[dim
].lower_bound
))
13550 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
13551 info
->dimen
[dim
].lower_bound
,
13554 if (info
->dimen
[dim
].upper_bound
)
13555 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
13556 info
->dimen
[dim
].upper_bound
,
13558 if (info
->dimen
[dim
].stride
)
13559 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
13560 info
->dimen
[dim
].stride
,
13564 gen_type_die (info
->element_type
, context_die
);
13565 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
13567 if (get_AT (array_die
, DW_AT_name
))
13568 add_pubtype (type
, array_die
);
13573 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
13575 tree origin
= decl_ultimate_origin (decl
);
13576 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
13578 if (origin
!= NULL
)
13579 add_abstract_origin_attribute (decl_die
, origin
);
13582 add_name_and_src_coords_attributes (decl_die
, decl
);
13583 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
13584 0, 0, context_die
);
13587 if (DECL_ABSTRACT (decl
))
13588 equate_decl_number_to_die (decl
, decl_die
);
13590 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
13594 /* Walk through the list of incomplete types again, trying once more to
13595 emit full debugging info for them. */
13598 retry_incomplete_types (void)
13602 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
13603 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
13606 /* Determine what tag to use for a record type. */
13608 static enum dwarf_tag
13609 record_type_tag (tree type
)
13611 if (! lang_hooks
.types
.classify_record
)
13612 return DW_TAG_structure_type
;
13614 switch (lang_hooks
.types
.classify_record (type
))
13616 case RECORD_IS_STRUCT
:
13617 return DW_TAG_structure_type
;
13619 case RECORD_IS_CLASS
:
13620 return DW_TAG_class_type
;
13622 case RECORD_IS_INTERFACE
:
13623 return DW_TAG_interface_type
;
13626 gcc_unreachable ();
13630 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13631 include all of the information about the enumeration values also. Each
13632 enumerated type name/value is listed as a child of the enumerated type
13636 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
13638 dw_die_ref type_die
= lookup_type_die (type
);
13640 if (type_die
== NULL
)
13642 type_die
= new_die (DW_TAG_enumeration_type
,
13643 scope_die_for (type
, context_die
), type
);
13644 equate_type_number_to_die (type
, type_die
);
13645 add_name_attribute (type_die
, type_tag (type
));
13647 else if (! TYPE_SIZE (type
))
13650 remove_AT (type_die
, DW_AT_declaration
);
13652 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13653 given enum type is incomplete, do not generate the DW_AT_byte_size
13654 attribute or the DW_AT_element_list attribute. */
13655 if (TYPE_SIZE (type
))
13659 TREE_ASM_WRITTEN (type
) = 1;
13660 add_byte_size_attribute (type_die
, type
);
13661 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
13662 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
13664 /* If the first reference to this type was as the return type of an
13665 inline function, then it may not have a parent. Fix this now. */
13666 if (type_die
->die_parent
== NULL
)
13667 add_child_die (scope_die_for (type
, context_die
), type_die
);
13669 for (link
= TYPE_VALUES (type
);
13670 link
!= NULL
; link
= TREE_CHAIN (link
))
13672 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
13673 tree value
= TREE_VALUE (link
);
13675 add_name_attribute (enum_die
,
13676 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
13678 if (TREE_CODE (value
) == CONST_DECL
)
13679 value
= DECL_INITIAL (value
);
13681 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
13682 /* DWARF2 does not provide a way of indicating whether or
13683 not enumeration constants are signed or unsigned. GDB
13684 always assumes the values are signed, so we output all
13685 values as if they were signed. That means that
13686 enumeration constants with very large unsigned values
13687 will appear to have negative values in the debugger. */
13688 add_AT_int (enum_die
, DW_AT_const_value
,
13689 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
13693 add_AT_flag (type_die
, DW_AT_declaration
, 1);
13695 if (get_AT (type_die
, DW_AT_name
))
13696 add_pubtype (type
, type_die
);
13701 /* Generate a DIE to represent either a real live formal parameter decl or to
13702 represent just the type of some formal parameter position in some function
13705 Note that this routine is a bit unusual because its argument may be a
13706 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13707 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13708 node. If it's the former then this function is being called to output a
13709 DIE to represent a formal parameter object (or some inlining thereof). If
13710 it's the latter, then this function is only being called to output a
13711 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13712 argument type of some subprogram type. */
13715 gen_formal_parameter_die (tree node
, tree origin
, dw_die_ref context_die
)
13717 tree node_or_origin
= node
? node
: origin
;
13718 dw_die_ref parm_die
13719 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
13721 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
13723 case tcc_declaration
:
13725 origin
= decl_ultimate_origin (node
);
13726 if (origin
!= NULL
)
13727 add_abstract_origin_attribute (parm_die
, origin
);
13730 tree type
= TREE_TYPE (node
);
13731 add_name_and_src_coords_attributes (parm_die
, node
);
13732 if (DECL_BY_REFERENCE (node
))
13733 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
13736 add_type_attribute (parm_die
, type
,
13737 TREE_READONLY (node
),
13738 TREE_THIS_VOLATILE (node
),
13740 if (DECL_ARTIFICIAL (node
))
13741 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13744 if (node
&& node
!= origin
)
13745 equate_decl_number_to_die (node
, parm_die
);
13746 if (! DECL_ABSTRACT (node_or_origin
))
13747 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
13753 /* We were called with some kind of a ..._TYPE node. */
13754 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
13758 gcc_unreachable ();
13764 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13765 at the end of an (ANSI prototyped) formal parameters list. */
13768 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
13770 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
13773 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13774 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13775 parameters as specified in some function type specification (except for
13776 those which appear as part of a function *definition*). */
13779 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
13782 tree formal_type
= NULL
;
13783 tree first_parm_type
;
13786 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
13788 arg
= DECL_ARGUMENTS (function_or_method_type
);
13789 function_or_method_type
= TREE_TYPE (function_or_method_type
);
13794 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
13796 /* Make our first pass over the list of formal parameter types and output a
13797 DW_TAG_formal_parameter DIE for each one. */
13798 for (link
= first_parm_type
; link
; )
13800 dw_die_ref parm_die
;
13802 formal_type
= TREE_VALUE (link
);
13803 if (formal_type
== void_type_node
)
13806 /* Output a (nameless) DIE to represent the formal parameter itself. */
13807 parm_die
= gen_formal_parameter_die (formal_type
, NULL
, context_die
);
13808 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
13809 && link
== first_parm_type
)
13810 || (arg
&& DECL_ARTIFICIAL (arg
)))
13811 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
13813 link
= TREE_CHAIN (link
);
13815 arg
= TREE_CHAIN (arg
);
13818 /* If this function type has an ellipsis, add a
13819 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13820 if (formal_type
!= void_type_node
)
13821 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
13823 /* Make our second (and final) pass over the list of formal parameter types
13824 and output DIEs to represent those types (as necessary). */
13825 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
13826 link
&& TREE_VALUE (link
);
13827 link
= TREE_CHAIN (link
))
13828 gen_type_die (TREE_VALUE (link
), context_die
);
13831 /* We want to generate the DIE for TYPE so that we can generate the
13832 die for MEMBER, which has been defined; we will need to refer back
13833 to the member declaration nested within TYPE. If we're trying to
13834 generate minimal debug info for TYPE, processing TYPE won't do the
13835 trick; we need to attach the member declaration by hand. */
13838 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
13840 gen_type_die (type
, context_die
);
13842 /* If we're trying to avoid duplicate debug info, we may not have
13843 emitted the member decl for this function. Emit it now. */
13844 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
13845 && ! lookup_decl_die (member
))
13847 dw_die_ref type_die
;
13848 gcc_assert (!decl_ultimate_origin (member
));
13850 push_decl_scope (type
);
13851 type_die
= lookup_type_die (type
);
13852 if (TREE_CODE (member
) == FUNCTION_DECL
)
13853 gen_subprogram_die (member
, type_die
);
13854 else if (TREE_CODE (member
) == FIELD_DECL
)
13856 /* Ignore the nameless fields that are used to skip bits but handle
13857 C++ anonymous unions and structs. */
13858 if (DECL_NAME (member
) != NULL_TREE
13859 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
13860 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
13862 gen_type_die (member_declared_type (member
), type_die
);
13863 gen_field_die (member
, type_die
);
13867 gen_variable_die (member
, NULL_TREE
, type_die
);
13873 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13874 may later generate inlined and/or out-of-line instances of. */
13877 dwarf2out_abstract_function (tree decl
)
13879 dw_die_ref old_die
;
13882 int was_abstract
= DECL_ABSTRACT (decl
);
13884 /* Make sure we have the actual abstract inline, not a clone. */
13885 decl
= DECL_ORIGIN (decl
);
13886 htab_empty (decl_loc_table
);
13888 old_die
= lookup_decl_die (decl
);
13889 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
13890 /* We've already generated the abstract instance. */
13893 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13894 we don't get confused by DECL_ABSTRACT. */
13895 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13897 context
= decl_class_context (decl
);
13899 gen_type_die_for_member
13900 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
13903 /* Pretend we've just finished compiling this function. */
13904 save_fn
= current_function_decl
;
13905 current_function_decl
= decl
;
13906 push_cfun (DECL_STRUCT_FUNCTION (decl
));
13908 set_decl_abstract_flags (decl
, 1);
13909 dwarf2out_decl (decl
);
13910 if (! was_abstract
)
13911 set_decl_abstract_flags (decl
, 0);
13913 current_function_decl
= save_fn
;
13917 /* Helper function of premark_used_types() which gets called through
13918 htab_traverse_resize().
13920 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13921 marked as unused by prune_unused_types. */
13923 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
13928 type
= (tree
) *slot
;
13929 die
= lookup_type_die (type
);
13931 die
->die_perennial_p
= 1;
13935 /* Mark all members of used_types_hash as perennial. */
13937 premark_used_types (void)
13939 if (cfun
&& cfun
->used_types_hash
)
13940 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
13943 /* Generate a DIE to represent a declared function (either file-scope or
13947 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
13949 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13950 tree origin
= decl_ultimate_origin (decl
);
13951 dw_die_ref subr_die
;
13954 dw_die_ref old_die
= lookup_decl_die (decl
);
13955 int declaration
= (current_function_decl
!= decl
13956 || class_or_namespace_scope_p (context_die
));
13958 premark_used_types ();
13960 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13961 started to generate the abstract instance of an inline, decided to output
13962 its containing class, and proceeded to emit the declaration of the inline
13963 from the member list for the class. If so, DECLARATION takes priority;
13964 we'll get back to the abstract instance when done with the class. */
13966 /* The class-scope declaration DIE must be the primary DIE. */
13967 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
13970 gcc_assert (!old_die
);
13973 /* Now that the C++ front end lazily declares artificial member fns, we
13974 might need to retrofit the declaration into its class. */
13975 if (!declaration
&& !origin
&& !old_die
13976 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
13977 && !class_or_namespace_scope_p (context_die
)
13978 && debug_info_level
> DINFO_LEVEL_TERSE
)
13979 old_die
= force_decl_die (decl
);
13981 if (origin
!= NULL
)
13983 gcc_assert (!declaration
|| local_scope_p (context_die
));
13985 /* Fixup die_parent for the abstract instance of a nested
13986 inline function. */
13987 if (old_die
&& old_die
->die_parent
== NULL
)
13988 add_child_die (context_die
, old_die
);
13990 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
13991 add_abstract_origin_attribute (subr_die
, origin
);
13995 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
13996 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
13998 if (!get_AT_flag (old_die
, DW_AT_declaration
)
13999 /* We can have a normal definition following an inline one in the
14000 case of redefinition of GNU C extern inlines.
14001 It seems reasonable to use AT_specification in this case. */
14002 && !get_AT (old_die
, DW_AT_inline
))
14004 /* Detect and ignore this case, where we are trying to output
14005 something we have already output. */
14009 /* If the definition comes from the same place as the declaration,
14010 maybe use the old DIE. We always want the DIE for this function
14011 that has the *_pc attributes to be under comp_unit_die so the
14012 debugger can find it. We also need to do this for abstract
14013 instances of inlines, since the spec requires the out-of-line copy
14014 to have the same parent. For local class methods, this doesn't
14015 apply; we just use the old DIE. */
14016 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
14017 && (DECL_ARTIFICIAL (decl
)
14018 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
14019 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
14020 == (unsigned) s
.line
))))
14022 subr_die
= old_die
;
14024 /* Clear out the declaration attribute and the formal parameters.
14025 Do not remove all children, because it is possible that this
14026 declaration die was forced using force_decl_die(). In such
14027 cases die that forced declaration die (e.g. TAG_imported_module)
14028 is one of the children that we do not want to remove. */
14029 remove_AT (subr_die
, DW_AT_declaration
);
14030 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
14034 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
14035 add_AT_specification (subr_die
, old_die
);
14036 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
14037 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
14038 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
14039 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
14044 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
14046 if (TREE_PUBLIC (decl
))
14047 add_AT_flag (subr_die
, DW_AT_external
, 1);
14049 add_name_and_src_coords_attributes (subr_die
, decl
);
14050 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14052 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
14053 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
14054 0, 0, context_die
);
14057 add_pure_or_virtual_attribute (subr_die
, decl
);
14058 if (DECL_ARTIFICIAL (decl
))
14059 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
14061 if (TREE_PROTECTED (decl
))
14062 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14063 else if (TREE_PRIVATE (decl
))
14064 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14069 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
14071 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
14073 /* If this is an explicit function declaration then generate
14074 a DW_AT_explicit attribute. */
14075 if (lang_hooks
.decls
.function_decl_explicit_p (decl
))
14076 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
14078 /* The first time we see a member function, it is in the context of
14079 the class to which it belongs. We make sure of this by emitting
14080 the class first. The next time is the definition, which is
14081 handled above. The two may come from the same source text.
14083 Note that force_decl_die() forces function declaration die. It is
14084 later reused to represent definition. */
14085 equate_decl_number_to_die (decl
, subr_die
);
14088 else if (DECL_ABSTRACT (decl
))
14090 if (DECL_DECLARED_INLINE_P (decl
))
14092 if (cgraph_function_possibly_inlined_p (decl
))
14093 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
14095 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
14099 if (cgraph_function_possibly_inlined_p (decl
))
14100 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
14102 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
14105 if (DECL_DECLARED_INLINE_P (decl
)
14106 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
14107 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
14109 equate_decl_number_to_die (decl
, subr_die
);
14111 else if (!DECL_EXTERNAL (decl
))
14113 HOST_WIDE_INT cfa_fb_offset
;
14115 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
14116 equate_decl_number_to_die (decl
, subr_die
);
14118 if (!flag_reorder_blocks_and_partition
)
14120 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
14121 current_function_funcdef_no
);
14122 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
14123 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14124 current_function_funcdef_no
);
14125 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
14127 add_pubname (decl
, subr_die
);
14128 add_arange (decl
, subr_die
);
14131 { /* Do nothing for now; maybe need to duplicate die, one for
14132 hot section and one for cold section, then use the hot/cold
14133 section begin/end labels to generate the aranges... */
14135 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
14136 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
14137 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
14138 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
14140 add_pubname (decl, subr_die);
14141 add_arange (decl, subr_die);
14142 add_arange (decl, subr_die);
14146 #ifdef MIPS_DEBUGGING_INFO
14147 /* Add a reference to the FDE for this routine. */
14148 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
14151 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
14153 /* We define the "frame base" as the function's CFA. This is more
14154 convenient for several reasons: (1) It's stable across the prologue
14155 and epilogue, which makes it better than just a frame pointer,
14156 (2) With dwarf3, there exists a one-byte encoding that allows us
14157 to reference the .debug_frame data by proxy, but failing that,
14158 (3) We can at least reuse the code inspection and interpretation
14159 code that determines the CFA position at various points in the
14161 if (dwarf_version
>= 3)
14163 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
14164 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
14168 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
14169 if (list
->dw_loc_next
)
14170 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
14172 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
14175 /* Compute a displacement from the "steady-state frame pointer" to
14176 the CFA. The former is what all stack slots and argument slots
14177 will reference in the rtl; the later is what we've told the
14178 debugger about. We'll need to adjust all frame_base references
14179 by this displacement. */
14180 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
14182 if (cfun
->static_chain_decl
)
14183 add_AT_location_description (subr_die
, DW_AT_static_link
,
14184 loc_descriptor_from_tree (cfun
->static_chain_decl
));
14187 /* Now output descriptions of the arguments for this function. This gets
14188 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
14189 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
14190 `...' at the end of the formal parameter list. In order to find out if
14191 there was a trailing ellipsis or not, we must instead look at the type
14192 associated with the FUNCTION_DECL. This will be a node of type
14193 FUNCTION_TYPE. If the chain of type nodes hanging off of this
14194 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
14195 an ellipsis at the end. */
14197 /* In the case where we are describing a mere function declaration, all we
14198 need to do here (and all we *can* do here) is to describe the *types* of
14199 its formal parameters. */
14200 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14202 else if (declaration
)
14203 gen_formal_types_die (decl
, subr_die
);
14206 /* Generate DIEs to represent all known formal parameters. */
14207 tree arg_decls
= DECL_ARGUMENTS (decl
);
14210 /* When generating DIEs, generate the unspecified_parameters DIE
14211 instead if we come across the arg "__builtin_va_alist" */
14212 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
14213 if (TREE_CODE (parm
) == PARM_DECL
)
14215 if (DECL_NAME (parm
)
14216 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
14217 "__builtin_va_alist"))
14218 gen_unspecified_parameters_die (parm
, subr_die
);
14220 gen_decl_die (parm
, NULL
, subr_die
);
14223 /* Decide whether we need an unspecified_parameters DIE at the end.
14224 There are 2 more cases to do this for: 1) the ansi ... declaration -
14225 this is detectable when the end of the arg list is not a
14226 void_type_node 2) an unprototyped function declaration (not a
14227 definition). This just means that we have no info about the
14228 parameters at all. */
14229 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
14230 if (fn_arg_types
!= NULL
)
14232 /* This is the prototyped case, check for.... */
14233 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
14234 gen_unspecified_parameters_die (decl
, subr_die
);
14236 else if (DECL_INITIAL (decl
) == NULL_TREE
)
14237 gen_unspecified_parameters_die (decl
, subr_die
);
14240 /* Output Dwarf info for all of the stuff within the body of the function
14241 (if it has one - it may be just a declaration). */
14242 outer_scope
= DECL_INITIAL (decl
);
14244 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
14245 a function. This BLOCK actually represents the outermost binding contour
14246 for the function, i.e. the contour in which the function's formal
14247 parameters and labels get declared. Curiously, it appears that the front
14248 end doesn't actually put the PARM_DECL nodes for the current function onto
14249 the BLOCK_VARS list for this outer scope, but are strung off of the
14250 DECL_ARGUMENTS list for the function instead.
14252 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
14253 the LABEL_DECL nodes for the function however, and we output DWARF info
14254 for those in decls_for_scope. Just within the `outer_scope' there will be
14255 a BLOCK node representing the function's outermost pair of curly braces,
14256 and any blocks used for the base and member initializers of a C++
14257 constructor function. */
14258 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
14260 /* Emit a DW_TAG_variable DIE for a named return value. */
14261 if (DECL_NAME (DECL_RESULT (decl
)))
14262 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
14264 current_function_has_inlines
= 0;
14265 decls_for_scope (outer_scope
, subr_die
, 0);
14267 #if 0 && defined (MIPS_DEBUGGING_INFO)
14268 if (current_function_has_inlines
)
14270 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
14271 if (! comp_unit_has_inlines
)
14273 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
14274 comp_unit_has_inlines
= 1;
14279 /* Add the calling convention attribute if requested. */
14280 add_calling_convention_attribute (subr_die
, decl
);
14284 /* Returns a hash value for X (which really is a die_struct). */
14287 common_block_die_table_hash (const void *x
)
14289 const_dw_die_ref d
= (const_dw_die_ref
) x
;
14290 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
14293 /* Return nonzero if decl_id and die_parent of die_struct X is the same
14294 as decl_id and die_parent of die_struct Y. */
14297 common_block_die_table_eq (const void *x
, const void *y
)
14299 const_dw_die_ref d
= (const_dw_die_ref
) x
;
14300 const_dw_die_ref e
= (const_dw_die_ref
) y
;
14301 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
14304 /* Generate a DIE to represent a declared data object.
14305 Either DECL or ORIGIN must be non-null. */
14308 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
14312 tree decl_or_origin
= decl
? decl
: origin
;
14313 dw_die_ref var_die
;
14314 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
14315 dw_die_ref origin_die
;
14316 int declaration
= (DECL_EXTERNAL (decl_or_origin
)
14317 /* If DECL is COMDAT and has not actually been
14318 emitted, we cannot take its address; there
14319 might end up being no definition anywhere in
14320 the program. For example, consider the C++
14324 struct S { static const int i = 7; };
14329 int f() { return S<int>::i; }
14331 Here, S<int>::i is not DECL_EXTERNAL, but no
14332 definition is required, so the compiler will
14333 not emit a definition. */
14334 || (TREE_CODE (decl_or_origin
) == VAR_DECL
14335 && DECL_COMDAT (decl_or_origin
)
14336 && !TREE_ASM_WRITTEN (decl_or_origin
))
14337 || class_or_namespace_scope_p (context_die
));
14340 origin
= decl_ultimate_origin (decl
);
14342 com_decl
= fortran_common (decl_or_origin
, &off
);
14344 /* Symbol in common gets emitted as a child of the common block, in the form
14345 of a data member. */
14349 dw_die_ref com_die
;
14350 dw_loc_descr_ref loc
;
14351 die_node com_die_arg
;
14353 var_die
= lookup_decl_die (decl_or_origin
);
14356 if (get_AT (var_die
, DW_AT_location
) == NULL
)
14358 loc
= loc_descriptor_from_tree (com_decl
);
14363 /* Optimize the common case. */
14364 if (loc
->dw_loc_opc
== DW_OP_addr
14365 && loc
->dw_loc_next
== NULL
14366 && GET_CODE (loc
->dw_loc_oprnd1
.v
.val_addr
)
14368 loc
->dw_loc_oprnd1
.v
.val_addr
14369 = plus_constant (loc
->dw_loc_oprnd1
.v
.val_addr
, off
);
14371 loc_descr_plus_const (&loc
, off
);
14373 add_AT_loc (var_die
, DW_AT_location
, loc
);
14374 remove_AT (var_die
, DW_AT_declaration
);
14380 if (common_block_die_table
== NULL
)
14381 common_block_die_table
14382 = htab_create_ggc (10, common_block_die_table_hash
,
14383 common_block_die_table_eq
, NULL
);
14385 field
= TREE_OPERAND (DECL_VALUE_EXPR (decl
), 0);
14386 com_die_arg
.decl_id
= DECL_UID (com_decl
);
14387 com_die_arg
.die_parent
= context_die
;
14388 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
14389 loc
= loc_descriptor_from_tree (com_decl
);
14390 if (com_die
== NULL
)
14393 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
14396 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
14397 add_name_and_src_coords_attributes (com_die
, com_decl
);
14400 add_AT_loc (com_die
, DW_AT_location
, loc
);
14401 /* Avoid sharing the same loc descriptor between
14402 DW_TAG_common_block and DW_TAG_variable. */
14403 loc
= loc_descriptor_from_tree (com_decl
);
14405 else if (DECL_EXTERNAL (decl
))
14406 add_AT_flag (com_die
, DW_AT_declaration
, 1);
14407 add_pubname_string (cnam
, com_die
); /* ??? needed? */
14408 com_die
->decl_id
= DECL_UID (com_decl
);
14409 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
14410 *slot
= (void *) com_die
;
14412 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
14414 add_AT_loc (com_die
, DW_AT_location
, loc
);
14415 loc
= loc_descriptor_from_tree (com_decl
);
14416 remove_AT (com_die
, DW_AT_declaration
);
14418 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
14419 add_name_and_src_coords_attributes (var_die
, decl
);
14420 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
14421 TREE_THIS_VOLATILE (decl
), context_die
);
14422 add_AT_flag (var_die
, DW_AT_external
, 1);
14427 /* Optimize the common case. */
14428 if (loc
->dw_loc_opc
== DW_OP_addr
14429 && loc
->dw_loc_next
== NULL
14430 && GET_CODE (loc
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
14431 loc
->dw_loc_oprnd1
.v
.val_addr
14432 = plus_constant (loc
->dw_loc_oprnd1
.v
.val_addr
, off
);
14434 loc_descr_plus_const (&loc
, off
);
14436 add_AT_loc (var_die
, DW_AT_location
, loc
);
14438 else if (DECL_EXTERNAL (decl
))
14439 add_AT_flag (var_die
, DW_AT_declaration
, 1);
14440 equate_decl_number_to_die (decl
, var_die
);
14444 /* If the compiler emitted a definition for the DECL declaration
14445 and if we already emitted a DIE for it, don't emit a second
14446 DIE for it again. */
14449 && old_die
->die_parent
== context_die
)
14452 /* For static data members, the declaration in the class is supposed
14453 to have DW_TAG_member tag; the specification should still be
14454 DW_TAG_variable referencing the DW_TAG_member DIE. */
14455 if (declaration
&& class_scope_p (context_die
))
14456 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
14458 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
14461 if (origin
!= NULL
)
14462 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
14464 /* Loop unrolling can create multiple blocks that refer to the same
14465 static variable, so we must test for the DW_AT_declaration flag.
14467 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14468 copy decls and set the DECL_ABSTRACT flag on them instead of
14471 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14473 ??? The declare_in_namespace support causes us to get two DIEs for one
14474 variable, both of which are declarations. We want to avoid considering
14475 one to be a specification, so we must test that this DIE is not a
14477 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
14478 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
14480 /* This is a definition of a C++ class level static. */
14481 add_AT_specification (var_die
, old_die
);
14482 if (DECL_NAME (decl
))
14484 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
14485 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
14487 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
14488 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
14490 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
14491 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
14496 tree type
= TREE_TYPE (decl
);
14498 add_name_and_src_coords_attributes (var_die
, decl
);
14499 if ((TREE_CODE (decl
) == PARM_DECL
14500 || TREE_CODE (decl
) == RESULT_DECL
14501 || TREE_CODE (decl
) == VAR_DECL
)
14502 && DECL_BY_REFERENCE (decl
))
14503 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
14505 add_type_attribute (var_die
, type
, TREE_READONLY (decl
),
14506 TREE_THIS_VOLATILE (decl
), context_die
);
14508 if (TREE_PUBLIC (decl
))
14509 add_AT_flag (var_die
, DW_AT_external
, 1);
14511 if (DECL_ARTIFICIAL (decl
))
14512 add_AT_flag (var_die
, DW_AT_artificial
, 1);
14514 if (TREE_PROTECTED (decl
))
14515 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14516 else if (TREE_PRIVATE (decl
))
14517 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14521 add_AT_flag (var_die
, DW_AT_declaration
, 1);
14523 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
))
14524 equate_decl_number_to_die (decl
, var_die
);
14527 && (! DECL_ABSTRACT (decl_or_origin
)
14528 /* Local static vars are shared between all clones/inlines,
14529 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14531 || (TREE_CODE (decl_or_origin
) == VAR_DECL
14532 && TREE_STATIC (decl_or_origin
)
14533 && DECL_RTL_SET_P (decl_or_origin
)))
14534 /* When abstract origin already has DW_AT_location attribute, no need
14535 to add it again. */
14536 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
14538 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
14539 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
14540 defer_location (decl_or_origin
, var_die
);
14542 add_location_or_const_value_attribute (var_die
,
14545 add_pubname (decl_or_origin
, var_die
);
14548 tree_add_const_value_attribute (var_die
, decl_or_origin
);
14551 /* Generate a DIE to represent a named constant. */
14554 gen_const_die (tree decl
, dw_die_ref context_die
)
14556 dw_die_ref const_die
;
14557 tree type
= TREE_TYPE (decl
);
14559 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
14560 add_name_and_src_coords_attributes (const_die
, decl
);
14561 add_type_attribute (const_die
, type
, 1, 0, context_die
);
14562 if (TREE_PUBLIC (decl
))
14563 add_AT_flag (const_die
, DW_AT_external
, 1);
14564 if (DECL_ARTIFICIAL (decl
))
14565 add_AT_flag (const_die
, DW_AT_artificial
, 1);
14566 tree_add_const_value_attribute (const_die
, decl
);
14569 /* Generate a DIE to represent a label identifier. */
14572 gen_label_die (tree decl
, dw_die_ref context_die
)
14574 tree origin
= decl_ultimate_origin (decl
);
14575 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
14577 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14579 if (origin
!= NULL
)
14580 add_abstract_origin_attribute (lbl_die
, origin
);
14582 add_name_and_src_coords_attributes (lbl_die
, decl
);
14584 if (DECL_ABSTRACT (decl
))
14585 equate_decl_number_to_die (decl
, lbl_die
);
14588 insn
= DECL_RTL_IF_SET (decl
);
14590 /* Deleted labels are programmer specified labels which have been
14591 eliminated because of various optimizations. We still emit them
14592 here so that it is possible to put breakpoints on them. */
14596 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
14598 /* When optimization is enabled (via -O) some parts of the compiler
14599 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14600 represent source-level labels which were explicitly declared by
14601 the user. This really shouldn't be happening though, so catch
14602 it if it ever does happen. */
14603 gcc_assert (!INSN_DELETED_P (insn
));
14605 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
14606 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
14611 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14612 attributes to the DIE for a block STMT, to describe where the inlined
14613 function was called from. This is similar to add_src_coords_attributes. */
14616 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
14618 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
14620 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
14621 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
14625 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14626 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14629 add_high_low_attributes (tree stmt
, dw_die_ref die
)
14631 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
14633 if (BLOCK_FRAGMENT_CHAIN (stmt
))
14637 if (inlined_function_outer_scope_p (stmt
))
14639 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14640 BLOCK_NUMBER (stmt
));
14641 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
14644 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
14646 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
14649 add_ranges (chain
);
14650 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
14657 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
14658 BLOCK_NUMBER (stmt
));
14659 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
14660 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
14661 BLOCK_NUMBER (stmt
));
14662 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
14666 /* Generate a DIE for a lexical block. */
14669 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14671 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
14673 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
14674 add_high_low_attributes (stmt
, stmt_die
);
14676 decls_for_scope (stmt
, stmt_die
, depth
);
14679 /* Generate a DIE for an inlined subprogram. */
14682 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
14684 tree decl
= block_ultimate_origin (stmt
);
14686 /* Emit info for the abstract instance first, if we haven't yet. We
14687 must emit this even if the block is abstract, otherwise when we
14688 emit the block below (or elsewhere), we may end up trying to emit
14689 a die whose origin die hasn't been emitted, and crashing. */
14690 dwarf2out_abstract_function (decl
);
14692 if (! BLOCK_ABSTRACT (stmt
))
14694 dw_die_ref subr_die
14695 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
14697 add_abstract_origin_attribute (subr_die
, decl
);
14698 if (TREE_ASM_WRITTEN (stmt
))
14699 add_high_low_attributes (stmt
, subr_die
);
14700 add_call_src_coords_attributes (stmt
, subr_die
);
14702 decls_for_scope (stmt
, subr_die
, depth
);
14703 current_function_has_inlines
= 1;
14706 /* We may get here if we're the outer block of function A that was
14707 inlined into function B that was inlined into function C. When
14708 generating debugging info for C, dwarf2out_abstract_function(B)
14709 would mark all inlined blocks as abstract, including this one.
14710 So, we wouldn't (and shouldn't) expect labels to be generated
14711 for this one. Instead, just emit debugging info for
14712 declarations within the block. This is particularly important
14713 in the case of initializers of arguments passed from B to us:
14714 if they're statement expressions containing declarations, we
14715 wouldn't generate dies for their abstract variables, and then,
14716 when generating dies for the real variables, we'd die (pun
14718 gen_lexical_block_die (stmt
, context_die
, depth
);
14721 /* Generate a DIE for a field in a record, or structure. */
14724 gen_field_die (tree decl
, dw_die_ref context_die
)
14726 dw_die_ref decl_die
;
14728 if (TREE_TYPE (decl
) == error_mark_node
)
14731 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
14732 add_name_and_src_coords_attributes (decl_die
, decl
);
14733 add_type_attribute (decl_die
, member_declared_type (decl
),
14734 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
14737 if (DECL_BIT_FIELD_TYPE (decl
))
14739 add_byte_size_attribute (decl_die
, decl
);
14740 add_bit_size_attribute (decl_die
, decl
);
14741 add_bit_offset_attribute (decl_die
, decl
);
14744 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
14745 add_data_member_location_attribute (decl_die
, decl
);
14747 if (DECL_ARTIFICIAL (decl
))
14748 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
14750 if (TREE_PROTECTED (decl
))
14751 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14752 else if (TREE_PRIVATE (decl
))
14753 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
14755 /* Equate decl number to die, so that we can look up this decl later on. */
14756 equate_decl_number_to_die (decl
, decl_die
);
14760 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14761 Use modified_type_die instead.
14762 We keep this code here just in case these types of DIEs may be needed to
14763 represent certain things in other languages (e.g. Pascal) someday. */
14766 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
14769 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
14771 equate_type_number_to_die (type
, ptr_die
);
14772 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14773 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14776 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14777 Use modified_type_die instead.
14778 We keep this code here just in case these types of DIEs may be needed to
14779 represent certain things in other languages (e.g. Pascal) someday. */
14782 gen_reference_type_die (tree type
, dw_die_ref context_die
)
14785 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
14787 equate_type_number_to_die (type
, ref_die
);
14788 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
14789 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
14793 /* Generate a DIE for a pointer to a member type. */
14796 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
14799 = new_die (DW_TAG_ptr_to_member_type
,
14800 scope_die_for (type
, context_die
), type
);
14802 equate_type_number_to_die (type
, ptr_die
);
14803 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
14804 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
14805 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
14808 /* Generate the DIE for the compilation unit. */
14811 gen_compile_unit_die (const char *filename
)
14814 char producer
[250];
14815 const char *language_string
= lang_hooks
.name
;
14818 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
14822 add_name_attribute (die
, filename
);
14823 /* Don't add cwd for <built-in>. */
14824 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
14825 add_comp_dir_attribute (die
);
14828 sprintf (producer
, "%s %s", language_string
, version_string
);
14830 #ifdef MIPS_DEBUGGING_INFO
14831 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14832 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14833 not appear in the producer string, the debugger reaches the conclusion
14834 that the object file is stripped and has no debugging information.
14835 To get the MIPS/SGI debugger to believe that there is debugging
14836 information in the object file, we add a -g to the producer string. */
14837 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14838 strcat (producer
, " -g");
14841 add_AT_string (die
, DW_AT_producer
, producer
);
14843 if (strcmp (language_string
, "GNU C++") == 0)
14844 language
= DW_LANG_C_plus_plus
;
14845 else if (strcmp (language_string
, "GNU Ada") == 0)
14846 language
= DW_LANG_Ada95
;
14847 else if (strcmp (language_string
, "GNU F77") == 0)
14848 language
= DW_LANG_Fortran77
;
14849 else if (strcmp (language_string
, "GNU Fortran") == 0)
14850 language
= DW_LANG_Fortran95
;
14851 else if (strcmp (language_string
, "GNU Pascal") == 0)
14852 language
= DW_LANG_Pascal83
;
14853 else if (strcmp (language_string
, "GNU Java") == 0)
14854 language
= DW_LANG_Java
;
14855 else if (strcmp (language_string
, "GNU Objective-C") == 0)
14856 language
= DW_LANG_ObjC
;
14857 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
14858 language
= DW_LANG_ObjC_plus_plus
;
14860 language
= DW_LANG_C89
;
14862 add_AT_unsigned (die
, DW_AT_language
, language
);
14866 /* Generate the DIE for a base class. */
14869 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
14871 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
14873 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
14874 add_data_member_location_attribute (die
, binfo
);
14876 if (BINFO_VIRTUAL_P (binfo
))
14877 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
14879 if (access
== access_public_node
)
14880 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14881 else if (access
== access_protected_node
)
14882 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14885 /* Generate a DIE for a class member. */
14888 gen_member_die (tree type
, dw_die_ref context_die
)
14891 tree binfo
= TYPE_BINFO (type
);
14894 /* If this is not an incomplete type, output descriptions of each of its
14895 members. Note that as we output the DIEs necessary to represent the
14896 members of this record or union type, we will also be trying to output
14897 DIEs to represent the *types* of those members. However the `type'
14898 function (above) will specifically avoid generating type DIEs for member
14899 types *within* the list of member DIEs for this (containing) type except
14900 for those types (of members) which are explicitly marked as also being
14901 members of this (containing) type themselves. The g++ front- end can
14902 force any given type to be treated as a member of some other (containing)
14903 type by setting the TYPE_CONTEXT of the given (member) type to point to
14904 the TREE node representing the appropriate (containing) type. */
14906 /* First output info about the base classes. */
14909 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
14913 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
14914 gen_inheritance_die (base
,
14915 (accesses
? VEC_index (tree
, accesses
, i
)
14916 : access_public_node
), context_die
);
14919 /* Now output info about the data members and type members. */
14920 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
14922 /* If we thought we were generating minimal debug info for TYPE
14923 and then changed our minds, some of the member declarations
14924 may have already been defined. Don't define them again, but
14925 do put them in the right order. */
14927 child
= lookup_decl_die (member
);
14929 splice_child_die (context_die
, child
);
14931 gen_decl_die (member
, NULL
, context_die
);
14934 /* Now output info about the function members (if any). */
14935 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
14937 /* Don't include clones in the member list. */
14938 if (DECL_ABSTRACT_ORIGIN (member
))
14941 child
= lookup_decl_die (member
);
14943 splice_child_die (context_die
, child
);
14945 gen_decl_die (member
, NULL
, context_die
);
14949 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14950 is set, we pretend that the type was never defined, so we only get the
14951 member DIEs needed by later specification DIEs. */
14954 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
14955 enum debug_info_usage usage
)
14957 dw_die_ref type_die
= lookup_type_die (type
);
14958 dw_die_ref scope_die
= 0;
14960 int complete
= (TYPE_SIZE (type
)
14961 && (! TYPE_STUB_DECL (type
)
14962 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
14963 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
14964 complete
= complete
&& should_emit_struct_debug (type
, usage
);
14966 if (type_die
&& ! complete
)
14969 if (TYPE_CONTEXT (type
) != NULL_TREE
14970 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
14971 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
14974 scope_die
= scope_die_for (type
, context_die
);
14976 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
14977 /* First occurrence of type or toplevel definition of nested class. */
14979 dw_die_ref old_die
= type_die
;
14981 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
14982 ? record_type_tag (type
) : DW_TAG_union_type
,
14984 equate_type_number_to_die (type
, type_die
);
14986 add_AT_specification (type_die
, old_die
);
14988 add_name_attribute (type_die
, type_tag (type
));
14991 remove_AT (type_die
, DW_AT_declaration
);
14993 /* If this type has been completed, then give it a byte_size attribute and
14994 then give a list of members. */
14995 if (complete
&& !ns_decl
)
14997 /* Prevent infinite recursion in cases where the type of some member of
14998 this type is expressed in terms of this type itself. */
14999 TREE_ASM_WRITTEN (type
) = 1;
15000 add_byte_size_attribute (type_die
, type
);
15001 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
15002 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
15004 /* If the first reference to this type was as the return type of an
15005 inline function, then it may not have a parent. Fix this now. */
15006 if (type_die
->die_parent
== NULL
)
15007 add_child_die (scope_die
, type_die
);
15009 push_decl_scope (type
);
15010 gen_member_die (type
, type_die
);
15013 /* GNU extension: Record what type our vtable lives in. */
15014 if (TYPE_VFIELD (type
))
15016 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
15018 gen_type_die (vtype
, context_die
);
15019 add_AT_die_ref (type_die
, DW_AT_containing_type
,
15020 lookup_type_die (vtype
));
15025 add_AT_flag (type_die
, DW_AT_declaration
, 1);
15027 /* We don't need to do this for function-local types. */
15028 if (TYPE_STUB_DECL (type
)
15029 && ! decl_function_context (TYPE_STUB_DECL (type
)))
15030 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
15033 if (get_AT (type_die
, DW_AT_name
))
15034 add_pubtype (type
, type_die
);
15037 /* Generate a DIE for a subroutine _type_. */
15040 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
15042 tree return_type
= TREE_TYPE (type
);
15043 dw_die_ref subr_die
15044 = new_die (DW_TAG_subroutine_type
,
15045 scope_die_for (type
, context_die
), type
);
15047 equate_type_number_to_die (type
, subr_die
);
15048 add_prototyped_attribute (subr_die
, type
);
15049 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
15050 gen_formal_types_die (type
, subr_die
);
15052 if (get_AT (subr_die
, DW_AT_name
))
15053 add_pubtype (type
, subr_die
);
15056 /* Generate a DIE for a type definition. */
15059 gen_typedef_die (tree decl
, dw_die_ref context_die
)
15061 dw_die_ref type_die
;
15064 if (TREE_ASM_WRITTEN (decl
))
15067 TREE_ASM_WRITTEN (decl
) = 1;
15068 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
15069 origin
= decl_ultimate_origin (decl
);
15070 if (origin
!= NULL
)
15071 add_abstract_origin_attribute (type_die
, origin
);
15076 add_name_and_src_coords_attributes (type_die
, decl
);
15077 if (DECL_ORIGINAL_TYPE (decl
))
15079 type
= DECL_ORIGINAL_TYPE (decl
);
15081 gcc_assert (type
!= TREE_TYPE (decl
));
15082 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
15085 type
= TREE_TYPE (decl
);
15087 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
15088 TREE_THIS_VOLATILE (decl
), context_die
);
15091 if (DECL_ABSTRACT (decl
))
15092 equate_decl_number_to_die (decl
, type_die
);
15094 if (get_AT (type_die
, DW_AT_name
))
15095 add_pubtype (decl
, type_die
);
15098 /* Generate a type description DIE. */
15101 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
15102 enum debug_info_usage usage
)
15105 struct array_descr_info info
;
15107 if (type
== NULL_TREE
|| type
== error_mark_node
)
15110 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
15111 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
15113 if (TREE_ASM_WRITTEN (type
))
15116 /* Prevent broken recursion; we can't hand off to the same type. */
15117 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
15119 /* Use the DIE of the containing namespace as the parent DIE of
15120 the type description DIE we want to generate. */
15121 if (DECL_CONTEXT (TYPE_NAME (type
))
15122 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
15123 context_die
= lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type
)));
15125 TREE_ASM_WRITTEN (type
) = 1;
15126 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
15130 /* If this is an array type with hidden descriptor, handle it first. */
15131 if (!TREE_ASM_WRITTEN (type
)
15132 && lang_hooks
.types
.get_array_descr_info
15133 && lang_hooks
.types
.get_array_descr_info (type
, &info
))
15135 gen_descr_array_type_die (type
, &info
, context_die
);
15136 TREE_ASM_WRITTEN (type
) = 1;
15140 /* We are going to output a DIE to represent the unqualified version
15141 of this type (i.e. without any const or volatile qualifiers) so
15142 get the main variant (i.e. the unqualified version) of this type
15143 now. (Vectors are special because the debugging info is in the
15144 cloned type itself). */
15145 if (TREE_CODE (type
) != VECTOR_TYPE
)
15146 type
= type_main_variant (type
);
15148 if (TREE_ASM_WRITTEN (type
))
15151 switch (TREE_CODE (type
))
15157 case REFERENCE_TYPE
:
15158 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
15159 ensures that the gen_type_die recursion will terminate even if the
15160 type is recursive. Recursive types are possible in Ada. */
15161 /* ??? We could perhaps do this for all types before the switch
15163 TREE_ASM_WRITTEN (type
) = 1;
15165 /* For these types, all that is required is that we output a DIE (or a
15166 set of DIEs) to represent the "basis" type. */
15167 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
15168 DINFO_USAGE_IND_USE
);
15172 /* This code is used for C++ pointer-to-data-member types.
15173 Output a description of the relevant class type. */
15174 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
15175 DINFO_USAGE_IND_USE
);
15177 /* Output a description of the type of the object pointed to. */
15178 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
15179 DINFO_USAGE_IND_USE
);
15181 /* Now output a DIE to represent this pointer-to-data-member type
15183 gen_ptr_to_mbr_type_die (type
, context_die
);
15186 case FUNCTION_TYPE
:
15187 /* Force out return type (in case it wasn't forced out already). */
15188 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
15189 DINFO_USAGE_DIR_USE
);
15190 gen_subroutine_type_die (type
, context_die
);
15194 /* Force out return type (in case it wasn't forced out already). */
15195 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
15196 DINFO_USAGE_DIR_USE
);
15197 gen_subroutine_type_die (type
, context_die
);
15201 gen_array_type_die (type
, context_die
);
15205 gen_array_type_die (type
, context_die
);
15208 case ENUMERAL_TYPE
:
15211 case QUAL_UNION_TYPE
:
15212 /* If this is a nested type whose containing class hasn't been written
15213 out yet, writing it out will cover this one, too. This does not apply
15214 to instantiations of member class templates; they need to be added to
15215 the containing class as they are generated. FIXME: This hurts the
15216 idea of combining type decls from multiple TUs, since we can't predict
15217 what set of template instantiations we'll get. */
15218 if (TYPE_CONTEXT (type
)
15219 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
15220 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
15222 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
15224 if (TREE_ASM_WRITTEN (type
))
15227 /* If that failed, attach ourselves to the stub. */
15228 push_decl_scope (TYPE_CONTEXT (type
));
15229 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
15234 context_die
= declare_in_namespace (type
, context_die
);
15238 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
15240 /* This might have been written out by the call to
15241 declare_in_namespace. */
15242 if (!TREE_ASM_WRITTEN (type
))
15243 gen_enumeration_type_die (type
, context_die
);
15246 gen_struct_or_union_type_die (type
, context_die
, usage
);
15251 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
15252 it up if it is ever completed. gen_*_type_die will set it for us
15253 when appropriate. */
15259 case FIXED_POINT_TYPE
:
15262 /* No DIEs needed for fundamental types. */
15266 /* No Dwarf representation currently defined. */
15270 gcc_unreachable ();
15273 TREE_ASM_WRITTEN (type
) = 1;
15277 gen_type_die (tree type
, dw_die_ref context_die
)
15279 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
15282 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
15283 things which are local to the given block. */
15286 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
15288 int must_output_die
= 0;
15291 /* Ignore blocks that are NULL. */
15292 if (stmt
== NULL_TREE
)
15295 inlined_func
= inlined_function_outer_scope_p (stmt
);
15297 /* If the block is one fragment of a non-contiguous block, do not
15298 process the variables, since they will have been done by the
15299 origin block. Do process subblocks. */
15300 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
15304 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
15305 gen_block_die (sub
, context_die
, depth
+ 1);
15310 /* Determine if we need to output any Dwarf DIEs at all to represent this
15313 /* The outer scopes for inlinings *must* always be represented. We
15314 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
15315 must_output_die
= 1;
15318 /* Determine if this block directly contains any "significant"
15319 local declarations which we will need to output DIEs for. */
15320 if (debug_info_level
> DINFO_LEVEL_TERSE
)
15321 /* We are not in terse mode so *any* local declaration counts
15322 as being a "significant" one. */
15323 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
15324 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
15325 && (TREE_USED (stmt
)
15326 || TREE_ASM_WRITTEN (stmt
)
15327 || BLOCK_ABSTRACT (stmt
)));
15328 else if ((TREE_USED (stmt
)
15329 || TREE_ASM_WRITTEN (stmt
)
15330 || BLOCK_ABSTRACT (stmt
))
15331 && !dwarf2out_ignore_block (stmt
))
15332 must_output_die
= 1;
15335 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
15336 DIE for any block which contains no significant local declarations at
15337 all. Rather, in such cases we just call `decls_for_scope' so that any
15338 needed Dwarf info for any sub-blocks will get properly generated. Note
15339 that in terse mode, our definition of what constitutes a "significant"
15340 local declaration gets restricted to include only inlined function
15341 instances and local (nested) function definitions. */
15342 if (must_output_die
)
15345 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
15347 gen_lexical_block_die (stmt
, context_die
, depth
);
15350 decls_for_scope (stmt
, context_die
, depth
);
15353 /* Process variable DECL (or variable with origin ORIGIN) within
15354 block STMT and add it to CONTEXT_DIE. */
15356 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
15359 tree decl_or_origin
= decl
? decl
: origin
;
15360 tree ultimate_origin
= origin
? decl_ultimate_origin (origin
) : NULL
;
15362 if (ultimate_origin
)
15363 origin
= ultimate_origin
;
15365 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
15366 die
= lookup_decl_die (decl_or_origin
);
15367 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
15368 && TYPE_DECL_IS_STUB (decl_or_origin
))
15369 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
15373 if (die
!= NULL
&& die
->die_parent
== NULL
)
15374 add_child_die (context_die
, die
);
15375 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
15376 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
15377 stmt
, context_die
);
15379 gen_decl_die (decl
, origin
, context_die
);
15382 /* Generate all of the decls declared within a given scope and (recursively)
15383 all of its sub-blocks. */
15386 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
15392 /* Ignore NULL blocks. */
15393 if (stmt
== NULL_TREE
)
15396 /* Output the DIEs to represent all of the data objects and typedefs
15397 declared directly within this block but not within any nested
15398 sub-blocks. Also, nested function and tag DIEs have been
15399 generated with a parent of NULL; fix that up now. */
15400 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
15401 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
15402 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
15403 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
15406 /* If we're at -g1, we're not interested in subblocks. */
15407 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15410 /* Output the DIEs to represent all sub-blocks (and the items declared
15411 therein) of this block. */
15412 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
15414 subblocks
= BLOCK_CHAIN (subblocks
))
15415 gen_block_die (subblocks
, context_die
, depth
+ 1);
15418 /* Is this a typedef we can avoid emitting? */
15421 is_redundant_typedef (const_tree decl
)
15423 if (TYPE_DECL_IS_STUB (decl
))
15426 if (DECL_ARTIFICIAL (decl
)
15427 && DECL_CONTEXT (decl
)
15428 && is_tagged_type (DECL_CONTEXT (decl
))
15429 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
15430 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
15431 /* Also ignore the artificial member typedef for the class name. */
15437 /* Returns the DIE for a context. */
15439 static inline dw_die_ref
15440 get_context_die (tree context
)
15444 /* Find die that represents this context. */
15445 if (TYPE_P (context
))
15446 return force_type_die (context
);
15448 return force_decl_die (context
);
15450 return comp_unit_die
;
15453 /* Returns the DIE for decl. A DIE will always be returned. */
15456 force_decl_die (tree decl
)
15458 dw_die_ref decl_die
;
15459 unsigned saved_external_flag
;
15460 tree save_fn
= NULL_TREE
;
15461 decl_die
= lookup_decl_die (decl
);
15464 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
15466 decl_die
= lookup_decl_die (decl
);
15470 switch (TREE_CODE (decl
))
15472 case FUNCTION_DECL
:
15473 /* Clear current_function_decl, so that gen_subprogram_die thinks
15474 that this is a declaration. At this point, we just want to force
15475 declaration die. */
15476 save_fn
= current_function_decl
;
15477 current_function_decl
= NULL_TREE
;
15478 gen_subprogram_die (decl
, context_die
);
15479 current_function_decl
= save_fn
;
15483 /* Set external flag to force declaration die. Restore it after
15484 gen_decl_die() call. */
15485 saved_external_flag
= DECL_EXTERNAL (decl
);
15486 DECL_EXTERNAL (decl
) = 1;
15487 gen_decl_die (decl
, NULL
, context_die
);
15488 DECL_EXTERNAL (decl
) = saved_external_flag
;
15491 case NAMESPACE_DECL
:
15492 dwarf2out_decl (decl
);
15496 gcc_unreachable ();
15499 /* We should be able to find the DIE now. */
15501 decl_die
= lookup_decl_die (decl
);
15502 gcc_assert (decl_die
);
15508 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15509 always returned. */
15512 force_type_die (tree type
)
15514 dw_die_ref type_die
;
15516 type_die
= lookup_type_die (type
);
15519 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
15521 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
15522 TYPE_VOLATILE (type
), context_die
);
15523 gcc_assert (type_die
);
15528 /* Force out any required namespaces to be able to output DECL,
15529 and return the new context_die for it, if it's changed. */
15532 setup_namespace_context (tree thing
, dw_die_ref context_die
)
15534 tree context
= (DECL_P (thing
)
15535 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
15536 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
15537 /* Force out the namespace. */
15538 context_die
= force_decl_die (context
);
15540 return context_die
;
15543 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15544 type) within its namespace, if appropriate.
15546 For compatibility with older debuggers, namespace DIEs only contain
15547 declarations; all definitions are emitted at CU scope. */
15550 declare_in_namespace (tree thing
, dw_die_ref context_die
)
15552 dw_die_ref ns_context
;
15554 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15555 return context_die
;
15557 /* If this decl is from an inlined function, then don't try to emit it in its
15558 namespace, as we will get confused. It would have already been emitted
15559 when the abstract instance of the inline function was emitted anyways. */
15560 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
15561 return context_die
;
15563 ns_context
= setup_namespace_context (thing
, context_die
);
15565 if (ns_context
!= context_die
)
15569 if (DECL_P (thing
))
15570 gen_decl_die (thing
, NULL
, ns_context
);
15572 gen_type_die (thing
, ns_context
);
15574 return context_die
;
15577 /* Generate a DIE for a namespace or namespace alias. */
15580 gen_namespace_die (tree decl
, dw_die_ref context_die
)
15582 dw_die_ref namespace_die
;
15584 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15585 they are an alias of. */
15586 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
15588 /* Output a real namespace or module. */
15589 context_die
= setup_namespace_context (decl
, comp_unit_die
);
15590 namespace_die
= new_die (is_fortran ()
15591 ? DW_TAG_module
: DW_TAG_namespace
,
15592 context_die
, decl
);
15593 /* For Fortran modules defined in different CU don't add src coords. */
15594 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
15595 add_name_attribute (namespace_die
, dwarf2_name (decl
, 0));
15597 add_name_and_src_coords_attributes (namespace_die
, decl
);
15598 if (DECL_EXTERNAL (decl
))
15599 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
15600 equate_decl_number_to_die (decl
, namespace_die
);
15604 /* Output a namespace alias. */
15606 /* Force out the namespace we are an alias of, if necessary. */
15607 dw_die_ref origin_die
15608 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
15610 if (DECL_CONTEXT (decl
) == NULL_TREE
15611 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
15612 context_die
= setup_namespace_context (decl
, comp_unit_die
);
15613 /* Now create the namespace alias DIE. */
15614 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
15615 add_name_and_src_coords_attributes (namespace_die
, decl
);
15616 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
15617 equate_decl_number_to_die (decl
, namespace_die
);
15621 /* Generate Dwarf debug information for a decl described by DECL. */
15624 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
15626 tree decl_or_origin
= decl
? decl
: origin
;
15627 tree class_origin
= NULL
;
15629 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
15632 switch (TREE_CODE (decl_or_origin
))
15638 if (!is_fortran ())
15640 /* The individual enumerators of an enum type get output when we output
15641 the Dwarf representation of the relevant enum type itself. */
15645 /* Emit its type. */
15646 gen_type_die (TREE_TYPE (decl
), context_die
);
15648 /* And its containing namespace. */
15649 context_die
= declare_in_namespace (decl
, context_die
);
15651 gen_const_die (decl
, context_die
);
15654 case FUNCTION_DECL
:
15655 /* Don't output any DIEs to represent mere function declarations,
15656 unless they are class members or explicit block externs. */
15657 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
15658 && DECL_CONTEXT (decl_or_origin
) == NULL_TREE
15659 && (current_function_decl
== NULL_TREE
15660 || DECL_ARTIFICIAL (decl_or_origin
)))
15665 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15666 on local redeclarations of global functions. That seems broken. */
15667 if (current_function_decl
!= decl
)
15668 /* This is only a declaration. */;
15671 /* If we're emitting a clone, emit info for the abstract instance. */
15672 if (origin
|| DECL_ORIGIN (decl
) != decl
)
15673 dwarf2out_abstract_function (origin
? origin
: DECL_ABSTRACT_ORIGIN (decl
));
15675 /* If we're emitting an out-of-line copy of an inline function,
15676 emit info for the abstract instance and set up to refer to it. */
15677 else if (cgraph_function_possibly_inlined_p (decl
)
15678 && ! DECL_ABSTRACT (decl
)
15679 && ! class_or_namespace_scope_p (context_die
)
15680 /* dwarf2out_abstract_function won't emit a die if this is just
15681 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15682 that case, because that works only if we have a die. */
15683 && DECL_INITIAL (decl
) != NULL_TREE
)
15685 dwarf2out_abstract_function (decl
);
15686 set_decl_origin_self (decl
);
15689 /* Otherwise we're emitting the primary DIE for this decl. */
15690 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
15692 /* Before we describe the FUNCTION_DECL itself, make sure that we
15693 have described its return type. */
15694 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
15696 /* And its virtual context. */
15697 if (DECL_VINDEX (decl
) != NULL_TREE
)
15698 gen_type_die (DECL_CONTEXT (decl
), context_die
);
15700 /* And its containing type. */
15702 origin
= decl_class_context (decl
);
15703 if (origin
!= NULL_TREE
)
15704 gen_type_die_for_member (origin
, decl
, context_die
);
15706 /* And its containing namespace. */
15707 context_die
= declare_in_namespace (decl
, context_die
);
15710 /* Now output a DIE to represent the function itself. */
15712 gen_subprogram_die (decl
, context_die
);
15716 /* If we are in terse mode, don't generate any DIEs to represent any
15717 actual typedefs. */
15718 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15721 /* In the special case of a TYPE_DECL node representing the declaration
15722 of some type tag, if the given TYPE_DECL is marked as having been
15723 instantiated from some other (original) TYPE_DECL node (e.g. one which
15724 was generated within the original definition of an inline function) we
15725 used to generate a special (abbreviated) DW_TAG_structure_type,
15726 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15727 should be actually referencing those DIEs, as variable DIEs with that
15728 type would be emitted already in the abstract origin, so it was always
15729 removed during unused type prunning. Don't add anything in this
15731 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
15734 if (is_redundant_typedef (decl
))
15735 gen_type_die (TREE_TYPE (decl
), context_die
);
15737 /* Output a DIE to represent the typedef itself. */
15738 gen_typedef_die (decl
, context_die
);
15742 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
15743 gen_label_die (decl
, context_die
);
15748 /* If we are in terse mode, don't generate any DIEs to represent any
15749 variable declarations or definitions. */
15750 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15753 /* Output any DIEs that are needed to specify the type of this data
15755 if ((TREE_CODE (decl_or_origin
) == RESULT_DECL
15756 || TREE_CODE (decl_or_origin
) == VAR_DECL
)
15757 && DECL_BY_REFERENCE (decl_or_origin
))
15758 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
15760 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
15762 /* And its containing type. */
15763 class_origin
= decl_class_context (decl_or_origin
);
15764 if (class_origin
!= NULL_TREE
)
15765 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
15767 /* And its containing namespace. */
15768 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
15770 /* Now output the DIE to represent the data object itself. This gets
15771 complicated because of the possibility that the VAR_DECL really
15772 represents an inlined instance of a formal parameter for an inline
15775 origin
= decl_ultimate_origin (decl
);
15776 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
15777 gen_formal_parameter_die (decl
, origin
, context_die
);
15779 gen_variable_die (decl
, origin
, context_die
);
15783 /* Ignore the nameless fields that are used to skip bits but handle C++
15784 anonymous unions and structs. */
15785 if (DECL_NAME (decl
) != NULL_TREE
15786 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
15787 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
15789 gen_type_die (member_declared_type (decl
), context_die
);
15790 gen_field_die (decl
, context_die
);
15795 if (DECL_BY_REFERENCE (decl_or_origin
))
15796 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
15798 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
15799 gen_formal_parameter_die (decl
, origin
, context_die
);
15802 case NAMESPACE_DECL
:
15803 case IMPORTED_DECL
:
15804 gen_namespace_die (decl
, context_die
);
15808 /* Probably some frontend-internal decl. Assume we don't care. */
15809 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
15814 /* Output debug information for global decl DECL. Called from toplev.c after
15815 compilation proper has finished. */
15818 dwarf2out_global_decl (tree decl
)
15820 /* Output DWARF2 information for file-scope tentative data object
15821 declarations, file-scope (extern) function declarations (which
15822 had no corresponding body) and file-scope tagged type declarations
15823 and definitions which have not yet been forced out. */
15824 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
15825 dwarf2out_decl (decl
);
15828 /* Output debug information for type decl DECL. Called from toplev.c
15829 and from language front ends (to record built-in types). */
15831 dwarf2out_type_decl (tree decl
, int local
)
15834 dwarf2out_decl (decl
);
15837 /* Output debug information for imported module or decl DECL.
15838 NAME is non-NULL name in the lexical block if the decl has been renamed.
15839 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15840 that DECL belongs to.
15841 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15843 dwarf2out_imported_module_or_decl_1 (tree decl
,
15845 tree lexical_block
,
15846 dw_die_ref lexical_block_die
)
15848 expanded_location xloc
;
15849 dw_die_ref imported_die
= NULL
;
15850 dw_die_ref at_import_die
;
15852 if (TREE_CODE (decl
) == IMPORTED_DECL
)
15854 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
15855 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
15859 xloc
= expand_location (input_location
);
15861 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
15863 if (is_base_type (TREE_TYPE (decl
)))
15864 at_import_die
= base_type_die (TREE_TYPE (decl
));
15866 at_import_die
= force_type_die (TREE_TYPE (decl
));
15867 /* For namespace N { typedef void T; } using N::T; base_type_die
15868 returns NULL, but DW_TAG_imported_declaration requires
15869 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15870 if (!at_import_die
)
15872 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
15873 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
15874 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
15875 gcc_assert (at_import_die
);
15880 at_import_die
= lookup_decl_die (decl
);
15881 if (!at_import_die
)
15883 /* If we're trying to avoid duplicate debug info, we may not have
15884 emitted the member decl for this field. Emit it now. */
15885 if (TREE_CODE (decl
) == FIELD_DECL
)
15887 tree type
= DECL_CONTEXT (decl
);
15889 if (TYPE_CONTEXT (type
)
15890 && TYPE_P (TYPE_CONTEXT (type
))
15891 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
15892 DINFO_USAGE_DIR_USE
))
15894 gen_type_die_for_member (type
, decl
,
15895 get_context_die (TYPE_CONTEXT (type
)));
15897 at_import_die
= force_decl_die (decl
);
15901 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
15902 imported_die
= new_die (DW_TAG_imported_module
,
15906 imported_die
= new_die (DW_TAG_imported_declaration
,
15910 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
15911 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
15913 add_AT_string (imported_die
, DW_AT_name
,
15914 IDENTIFIER_POINTER (name
));
15915 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
15918 /* Output debug information for imported module or decl DECL.
15919 NAME is non-NULL name in context if the decl has been renamed.
15920 CHILD is true if decl is one of the renamed decls as part of
15921 importing whole module. */
15924 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
15927 /* dw_die_ref at_import_die; */
15928 dw_die_ref scope_die
;
15930 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
15935 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15936 We need decl DIE for reference and scope die. First, get DIE for the decl
15939 /* Get the scope die for decl context. Use comp_unit_die for global module
15940 or decl. If die is not found for non globals, force new die. */
15942 && TYPE_P (context
)
15943 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
15945 scope_die
= get_context_die (context
);
15949 gcc_assert (scope_die
->die_child
);
15950 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
15951 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
15952 scope_die
= scope_die
->die_child
;
15955 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15956 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
15960 /* Write the debugging output for DECL. */
15963 dwarf2out_decl (tree decl
)
15965 dw_die_ref context_die
= comp_unit_die
;
15967 switch (TREE_CODE (decl
))
15972 case FUNCTION_DECL
:
15973 /* What we would really like to do here is to filter out all mere
15974 file-scope declarations of file-scope functions which are never
15975 referenced later within this translation unit (and keep all of ones
15976 that *are* referenced later on) but we aren't clairvoyant, so we have
15977 no idea which functions will be referenced in the future (i.e. later
15978 on within the current translation unit). So here we just ignore all
15979 file-scope function declarations which are not also definitions. If
15980 and when the debugger needs to know something about these functions,
15981 it will have to hunt around and find the DWARF information associated
15982 with the definition of the function.
15984 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15985 nodes represent definitions and which ones represent mere
15986 declarations. We have to check DECL_INITIAL instead. That's because
15987 the C front-end supports some weird semantics for "extern inline"
15988 function definitions. These can get inlined within the current
15989 translation unit (and thus, we need to generate Dwarf info for their
15990 abstract instances so that the Dwarf info for the concrete inlined
15991 instances can have something to refer to) but the compiler never
15992 generates any out-of-lines instances of such things (despite the fact
15993 that they *are* definitions).
15995 The important point is that the C front-end marks these "extern
15996 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15997 them anyway. Note that the C++ front-end also plays some similar games
15998 for inline function definitions appearing within include files which
15999 also contain `#pragma interface' pragmas. */
16000 if (DECL_INITIAL (decl
) == NULL_TREE
)
16003 /* If we're a nested function, initially use a parent of NULL; if we're
16004 a plain function, this will be fixed up in decls_for_scope. If
16005 we're a method, it will be ignored, since we already have a DIE. */
16006 if (decl_function_context (decl
)
16007 /* But if we're in terse mode, we don't care about scope. */
16008 && debug_info_level
> DINFO_LEVEL_TERSE
)
16009 context_die
= NULL
;
16013 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
16014 declaration and if the declaration was never even referenced from
16015 within this entire compilation unit. We suppress these DIEs in
16016 order to save space in the .debug section (by eliminating entries
16017 which are probably useless). Note that we must not suppress
16018 block-local extern declarations (whether used or not) because that
16019 would screw-up the debugger's name lookup mechanism and cause it to
16020 miss things which really ought to be in scope at a given point. */
16021 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
16024 /* For local statics lookup proper context die. */
16025 if (TREE_STATIC (decl
) && decl_function_context (decl
))
16026 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
16028 /* If we are in terse mode, don't generate any DIEs to represent any
16029 variable declarations or definitions. */
16030 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
16035 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
16037 if (!is_fortran ())
16039 if (TREE_STATIC (decl
) && decl_function_context (decl
))
16040 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
16043 case NAMESPACE_DECL
:
16044 case IMPORTED_DECL
:
16045 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
16047 if (lookup_decl_die (decl
) != NULL
)
16052 /* Don't emit stubs for types unless they are needed by other DIEs. */
16053 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
16056 /* Don't bother trying to generate any DIEs to represent any of the
16057 normal built-in types for the language we are compiling. */
16058 if (DECL_IS_BUILTIN (decl
))
16060 /* OK, we need to generate one for `bool' so GDB knows what type
16061 comparisons have. */
16063 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
16064 && ! DECL_IGNORED_P (decl
))
16065 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
16070 /* If we are in terse mode, don't generate any DIEs for types. */
16071 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
16074 /* If we're a function-scope tag, initially use a parent of NULL;
16075 this will be fixed up in decls_for_scope. */
16076 if (decl_function_context (decl
))
16077 context_die
= NULL
;
16085 gen_decl_die (decl
, NULL
, context_die
);
16088 /* Output a marker (i.e. a label) for the beginning of the generated code for
16089 a lexical block. */
16092 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
16093 unsigned int blocknum
)
16095 switch_to_section (current_function_section ());
16096 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
16099 /* Output a marker (i.e. a label) for the end of the generated code for a
16103 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
16105 switch_to_section (current_function_section ());
16106 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
16109 /* Returns nonzero if it is appropriate not to emit any debugging
16110 information for BLOCK, because it doesn't contain any instructions.
16112 Don't allow this for blocks with nested functions or local classes
16113 as we would end up with orphans, and in the presence of scheduling
16114 we may end up calling them anyway. */
16117 dwarf2out_ignore_block (const_tree block
)
16122 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
16123 if (TREE_CODE (decl
) == FUNCTION_DECL
16124 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
16126 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
16128 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
16129 if (TREE_CODE (decl
) == FUNCTION_DECL
16130 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
16137 /* Hash table routines for file_hash. */
16140 file_table_eq (const void *p1_p
, const void *p2_p
)
16142 const struct dwarf_file_data
*const p1
=
16143 (const struct dwarf_file_data
*) p1_p
;
16144 const char *const p2
= (const char *) p2_p
;
16145 return strcmp (p1
->filename
, p2
) == 0;
16149 file_table_hash (const void *p_p
)
16151 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
16152 return htab_hash_string (p
->filename
);
16155 /* Lookup FILE_NAME (in the list of filenames that we know about here in
16156 dwarf2out.c) and return its "index". The index of each (known) filename is
16157 just a unique number which is associated with only that one filename. We
16158 need such numbers for the sake of generating labels (in the .debug_sfnames
16159 section) and references to those files numbers (in the .debug_srcinfo
16160 and.debug_macinfo sections). If the filename given as an argument is not
16161 found in our current list, add it to the list and assign it the next
16162 available unique index number. In order to speed up searches, we remember
16163 the index of the filename was looked up last. This handles the majority of
16166 static struct dwarf_file_data
*
16167 lookup_filename (const char *file_name
)
16170 struct dwarf_file_data
* created
;
16172 /* Check to see if the file name that was searched on the previous
16173 call matches this file name. If so, return the index. */
16174 if (file_table_last_lookup
16175 && (file_name
== file_table_last_lookup
->filename
16176 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
16177 return file_table_last_lookup
;
16179 /* Didn't match the previous lookup, search the table. */
16180 slot
= htab_find_slot_with_hash (file_table
, file_name
,
16181 htab_hash_string (file_name
), INSERT
);
16183 return (struct dwarf_file_data
*) *slot
;
16185 created
= GGC_NEW (struct dwarf_file_data
);
16186 created
->filename
= file_name
;
16187 created
->emitted_number
= 0;
16192 /* If the assembler will construct the file table, then translate the compiler
16193 internal file table number into the assembler file table number, and emit
16194 a .file directive if we haven't already emitted one yet. The file table
16195 numbers are different because we prune debug info for unused variables and
16196 types, which may include filenames. */
16199 maybe_emit_file (struct dwarf_file_data
* fd
)
16201 if (! fd
->emitted_number
)
16203 if (last_emitted_file
)
16204 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
16206 fd
->emitted_number
= 1;
16207 last_emitted_file
= fd
;
16209 if (DWARF2_ASM_LINE_DEBUG_INFO
)
16211 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
16212 output_quoted_string (asm_out_file
,
16213 remap_debug_filename (fd
->filename
));
16214 fputc ('\n', asm_out_file
);
16218 return fd
->emitted_number
;
16221 /* Replace DW_AT_name for the decl with name. */
16224 dwarf2out_set_name (tree decl
, tree name
)
16229 die
= TYPE_SYMTAB_DIE (decl
);
16233 attr
= get_AT (die
, DW_AT_name
);
16236 struct indirect_string_node
*node
;
16238 node
= find_AT_string (dwarf2_name (name
, 0));
16239 /* replace the string. */
16240 attr
->dw_attr_val
.v
.val_str
= node
;
16244 add_name_attribute (die
, dwarf2_name (name
, 0));
16247 /* Called by the final INSN scan whenever we see a var location. We
16248 use it to drop labels in the right places, and throw the location in
16249 our lookup table. */
16252 dwarf2out_var_location (rtx loc_note
)
16254 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
16255 struct var_loc_node
*newloc
;
16257 static const char *last_label
;
16258 static bool last_in_cold_section_p
;
16261 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
16264 next_real
= next_real_insn (loc_note
);
16265 /* If there are no instructions which would be affected by this note,
16266 don't do anything. */
16267 if (next_real
== NULL_RTX
)
16270 newloc
= GGC_CNEW (struct var_loc_node
);
16271 /* If there were no real insns between note we processed last time
16272 and this note, use the label we emitted last time. */
16273 if (last_var_location_insn
!= NULL_RTX
16274 && last_var_location_insn
== next_real
16275 && last_in_cold_section_p
== in_cold_section_p
)
16276 newloc
->label
= last_label
;
16279 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
16280 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
16282 newloc
->label
= ggc_strdup (loclabel
);
16284 newloc
->var_loc_note
= loc_note
;
16285 newloc
->next
= NULL
;
16287 if (cfun
&& in_cold_section_p
)
16288 newloc
->section_label
= crtl
->subsections
.cold_section_label
;
16290 newloc
->section_label
= text_section_label
;
16292 last_var_location_insn
= next_real
;
16293 last_label
= newloc
->label
;
16294 last_in_cold_section_p
= in_cold_section_p
;
16295 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
16296 add_var_loc_to_decl (decl
, newloc
);
16299 /* We need to reset the locations at the beginning of each
16300 function. We can't do this in the end_function hook, because the
16301 declarations that use the locations won't have been output when
16302 that hook is called. Also compute have_multiple_function_sections here. */
16305 dwarf2out_begin_function (tree fun
)
16307 htab_empty (decl_loc_table
);
16309 if (function_section (fun
) != text_section
)
16310 have_multiple_function_sections
= true;
16312 dwarf2out_note_section_used ();
16315 /* Output a label to mark the beginning of a source code line entry
16316 and record information relating to this source line, in
16317 'line_info_table' for later output of the .debug_line section. */
16320 dwarf2out_source_line (unsigned int line
, const char *filename
,
16321 int discriminator
, bool is_stmt
)
16323 static bool last_is_stmt
= true;
16325 if (debug_info_level
>= DINFO_LEVEL_NORMAL
16328 int file_num
= maybe_emit_file (lookup_filename (filename
));
16330 switch_to_section (current_function_section ());
16332 /* If requested, emit something human-readable. */
16333 if (flag_debug_asm
)
16334 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
16337 if (DWARF2_ASM_LINE_DEBUG_INFO
)
16339 /* Emit the .loc directive understood by GNU as. */
16340 fprintf (asm_out_file
, "\t.loc %d %d 0", file_num
, line
);
16341 if (is_stmt
!= last_is_stmt
)
16343 fprintf (asm_out_file
, " is_stmt %d", is_stmt
? 1 : 0);
16344 last_is_stmt
= is_stmt
;
16346 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
16347 fprintf (asm_out_file
, " discriminator %d", discriminator
);
16348 fputc ('\n', asm_out_file
);
16350 /* Indicate that line number info exists. */
16351 line_info_table_in_use
++;
16353 else if (function_section (current_function_decl
) != text_section
)
16355 dw_separate_line_info_ref line_info
;
16356 targetm
.asm_out
.internal_label (asm_out_file
,
16357 SEPARATE_LINE_CODE_LABEL
,
16358 separate_line_info_table_in_use
);
16360 /* Expand the line info table if necessary. */
16361 if (separate_line_info_table_in_use
16362 == separate_line_info_table_allocated
)
16364 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
16365 separate_line_info_table
16366 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
16367 separate_line_info_table
,
16368 separate_line_info_table_allocated
);
16369 memset (separate_line_info_table
16370 + separate_line_info_table_in_use
,
16372 (LINE_INFO_TABLE_INCREMENT
16373 * sizeof (dw_separate_line_info_entry
)));
16376 /* Add the new entry at the end of the line_info_table. */
16378 = &separate_line_info_table
[separate_line_info_table_in_use
++];
16379 line_info
->dw_file_num
= file_num
;
16380 line_info
->dw_line_num
= line
;
16381 line_info
->function
= current_function_funcdef_no
;
16385 dw_line_info_ref line_info
;
16387 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
16388 line_info_table_in_use
);
16390 /* Expand the line info table if necessary. */
16391 if (line_info_table_in_use
== line_info_table_allocated
)
16393 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
16395 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
16396 line_info_table_allocated
);
16397 memset (line_info_table
+ line_info_table_in_use
, 0,
16398 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
16401 /* Add the new entry at the end of the line_info_table. */
16402 line_info
= &line_info_table
[line_info_table_in_use
++];
16403 line_info
->dw_file_num
= file_num
;
16404 line_info
->dw_line_num
= line
;
16409 /* Record the beginning of a new source file. */
16412 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
16414 if (flag_eliminate_dwarf2_dups
)
16416 /* Record the beginning of the file for break_out_includes. */
16417 dw_die_ref bincl_die
;
16419 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
16420 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
16423 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16425 int file_num
= maybe_emit_file (lookup_filename (filename
));
16427 switch_to_section (debug_macinfo_section
);
16428 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
16429 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
16432 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
16436 /* Record the end of a source file. */
16439 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
16441 if (flag_eliminate_dwarf2_dups
)
16442 /* Record the end of the file for break_out_includes. */
16443 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
16445 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16447 switch_to_section (debug_macinfo_section
);
16448 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
16452 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16453 the tail part of the directive line, i.e. the part which is past the
16454 initial whitespace, #, whitespace, directive-name, whitespace part. */
16457 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
16458 const char *buffer ATTRIBUTE_UNUSED
)
16460 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16462 switch_to_section (debug_macinfo_section
);
16463 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
16464 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
16465 dw2_asm_output_nstring (buffer
, -1, "The macro");
16469 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16470 the tail part of the directive line, i.e. the part which is past the
16471 initial whitespace, #, whitespace, directive-name, whitespace part. */
16474 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
16475 const char *buffer ATTRIBUTE_UNUSED
)
16477 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16479 switch_to_section (debug_macinfo_section
);
16480 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
16481 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
16482 dw2_asm_output_nstring (buffer
, -1, "The macro");
16486 /* Set up for Dwarf output at the start of compilation. */
16489 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
16491 /* Allocate the file_table. */
16492 file_table
= htab_create_ggc (50, file_table_hash
,
16493 file_table_eq
, NULL
);
16495 /* Allocate the decl_die_table. */
16496 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
16497 decl_die_table_eq
, NULL
);
16499 /* Allocate the decl_loc_table. */
16500 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
16501 decl_loc_table_eq
, NULL
);
16503 /* Allocate the initial hunk of the decl_scope_table. */
16504 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
16506 /* Allocate the initial hunk of the abbrev_die_table. */
16507 abbrev_die_table
= GGC_CNEWVEC (dw_die_ref
, ABBREV_DIE_TABLE_INCREMENT
);
16508 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
16509 /* Zero-th entry is allocated, but unused. */
16510 abbrev_die_table_in_use
= 1;
16512 /* Allocate the initial hunk of the line_info_table. */
16513 line_info_table
= GGC_CNEWVEC (dw_line_info_entry
, LINE_INFO_TABLE_INCREMENT
);
16514 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
16516 /* Zero-th entry is allocated, but unused. */
16517 line_info_table_in_use
= 1;
16519 /* Allocate the pubtypes and pubnames vectors. */
16520 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
16521 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
16523 /* Generate the initial DIE for the .debug section. Note that the (string)
16524 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16525 will (typically) be a relative pathname and that this pathname should be
16526 taken as being relative to the directory from which the compiler was
16527 invoked when the given (base) source file was compiled. We will fill
16528 in this value in dwarf2out_finish. */
16529 comp_unit_die
= gen_compile_unit_die (NULL
);
16531 incomplete_types
= VEC_alloc (tree
, gc
, 64);
16533 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
16535 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
16536 SECTION_DEBUG
, NULL
);
16537 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
16538 SECTION_DEBUG
, NULL
);
16539 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
16540 SECTION_DEBUG
, NULL
);
16541 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
16542 SECTION_DEBUG
, NULL
);
16543 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
16544 SECTION_DEBUG
, NULL
);
16545 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
16546 SECTION_DEBUG
, NULL
);
16547 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
16548 SECTION_DEBUG
, NULL
);
16549 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
16550 SECTION_DEBUG
, NULL
);
16551 debug_str_section
= get_section (DEBUG_STR_SECTION
,
16552 DEBUG_STR_SECTION_FLAGS
, NULL
);
16553 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
16554 SECTION_DEBUG
, NULL
);
16555 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
16556 SECTION_DEBUG
, NULL
);
16558 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
16559 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
16560 DEBUG_ABBREV_SECTION_LABEL
, 0);
16561 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
16562 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
16563 COLD_TEXT_SECTION_LABEL
, 0);
16564 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
16566 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
16567 DEBUG_INFO_SECTION_LABEL
, 0);
16568 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
16569 DEBUG_LINE_SECTION_LABEL
, 0);
16570 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
16571 DEBUG_RANGES_SECTION_LABEL
, 0);
16572 switch_to_section (debug_abbrev_section
);
16573 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
16574 switch_to_section (debug_info_section
);
16575 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
16576 switch_to_section (debug_line_section
);
16577 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
16579 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
16581 switch_to_section (debug_macinfo_section
);
16582 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
16583 DEBUG_MACINFO_SECTION_LABEL
, 0);
16584 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
16587 switch_to_section (text_section
);
16588 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
16589 if (flag_reorder_blocks_and_partition
)
16591 cold_text_section
= unlikely_text_section ();
16592 switch_to_section (cold_text_section
);
16593 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
16597 /* A helper function for dwarf2out_finish called through
16598 ht_forall. Emit one queued .debug_str string. */
16601 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
16603 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
16605 if (node
->form
== DW_FORM_strp
)
16607 switch_to_section (debug_str_section
);
16608 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
16609 assemble_string (node
->str
, strlen (node
->str
) + 1);
16615 #if ENABLE_ASSERT_CHECKING
16616 /* Verify that all marks are clear. */
16619 verify_marks_clear (dw_die_ref die
)
16623 gcc_assert (! die
->die_mark
);
16624 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
16626 #endif /* ENABLE_ASSERT_CHECKING */
16628 /* Clear the marks for a die and its children.
16629 Be cool if the mark isn't set. */
16632 prune_unmark_dies (dw_die_ref die
)
16638 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
16641 /* Given DIE that we're marking as used, find any other dies
16642 it references as attributes and mark them as used. */
16645 prune_unused_types_walk_attribs (dw_die_ref die
)
16650 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16652 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
16654 /* A reference to another DIE.
16655 Make sure that it will get emitted. */
16656 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
16658 /* Set the string's refcount to 0 so that prune_unused_types_mark
16659 accounts properly for it. */
16660 if (AT_class (a
) == dw_val_class_str
)
16661 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
16666 /* Mark DIE as being used. If DOKIDS is true, then walk down
16667 to DIE's children. */
16670 prune_unused_types_mark (dw_die_ref die
, int dokids
)
16674 if (die
->die_mark
== 0)
16676 /* We haven't done this node yet. Mark it as used. */
16679 /* We also have to mark its parents as used.
16680 (But we don't want to mark our parents' kids due to this.) */
16681 if (die
->die_parent
)
16682 prune_unused_types_mark (die
->die_parent
, 0);
16684 /* Mark any referenced nodes. */
16685 prune_unused_types_walk_attribs (die
);
16687 /* If this node is a specification,
16688 also mark the definition, if it exists. */
16689 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
16690 prune_unused_types_mark (die
->die_definition
, 1);
16693 if (dokids
&& die
->die_mark
!= 2)
16695 /* We need to walk the children, but haven't done so yet.
16696 Remember that we've walked the kids. */
16699 /* If this is an array type, we need to make sure our
16700 kids get marked, even if they're types. */
16701 if (die
->die_tag
== DW_TAG_array_type
)
16702 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
16704 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16708 /* For local classes, look if any static member functions were emitted
16709 and if so, mark them. */
16712 prune_unused_types_walk_local_classes (dw_die_ref die
)
16716 if (die
->die_mark
== 2)
16719 switch (die
->die_tag
)
16721 case DW_TAG_structure_type
:
16722 case DW_TAG_union_type
:
16723 case DW_TAG_class_type
:
16726 case DW_TAG_subprogram
:
16727 if (!get_AT_flag (die
, DW_AT_declaration
)
16728 || die
->die_definition
!= NULL
)
16729 prune_unused_types_mark (die
, 1);
16736 /* Mark children. */
16737 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
16740 /* Walk the tree DIE and mark types that we actually use. */
16743 prune_unused_types_walk (dw_die_ref die
)
16747 /* Don't do anything if this node is already marked and
16748 children have been marked as well. */
16749 if (die
->die_mark
== 2)
16752 switch (die
->die_tag
)
16754 case DW_TAG_structure_type
:
16755 case DW_TAG_union_type
:
16756 case DW_TAG_class_type
:
16757 if (die
->die_perennial_p
)
16760 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
16761 if (c
->die_tag
== DW_TAG_subprogram
)
16764 /* Finding used static member functions inside of classes
16765 is needed just for local classes, because for other classes
16766 static member function DIEs with DW_AT_specification
16767 are emitted outside of the DW_TAG_*_type. If we ever change
16768 it, we'd need to call this even for non-local classes. */
16770 prune_unused_types_walk_local_classes (die
);
16772 /* It's a type node --- don't mark it. */
16775 case DW_TAG_const_type
:
16776 case DW_TAG_packed_type
:
16777 case DW_TAG_pointer_type
:
16778 case DW_TAG_reference_type
:
16779 case DW_TAG_volatile_type
:
16780 case DW_TAG_typedef
:
16781 case DW_TAG_array_type
:
16782 case DW_TAG_interface_type
:
16783 case DW_TAG_friend
:
16784 case DW_TAG_variant_part
:
16785 case DW_TAG_enumeration_type
:
16786 case DW_TAG_subroutine_type
:
16787 case DW_TAG_string_type
:
16788 case DW_TAG_set_type
:
16789 case DW_TAG_subrange_type
:
16790 case DW_TAG_ptr_to_member_type
:
16791 case DW_TAG_file_type
:
16792 if (die
->die_perennial_p
)
16795 /* It's a type node --- don't mark it. */
16799 /* Mark everything else. */
16803 if (die
->die_mark
== 0)
16807 /* Now, mark any dies referenced from here. */
16808 prune_unused_types_walk_attribs (die
);
16813 /* Mark children. */
16814 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
16817 /* Increment the string counts on strings referred to from DIE's
16821 prune_unused_types_update_strings (dw_die_ref die
)
16826 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
16827 if (AT_class (a
) == dw_val_class_str
)
16829 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
16831 /* Avoid unnecessarily putting strings that are used less than
16832 twice in the hash table. */
16834 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
16837 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
16838 htab_hash_string (s
->str
),
16840 gcc_assert (*slot
== NULL
);
16846 /* Remove from the tree DIE any dies that aren't marked. */
16849 prune_unused_types_prune (dw_die_ref die
)
16853 gcc_assert (die
->die_mark
);
16854 prune_unused_types_update_strings (die
);
16856 if (! die
->die_child
)
16859 c
= die
->die_child
;
16861 dw_die_ref prev
= c
;
16862 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
16863 if (c
== die
->die_child
)
16865 /* No marked children between 'prev' and the end of the list. */
16867 /* No marked children at all. */
16868 die
->die_child
= NULL
;
16871 prev
->die_sib
= c
->die_sib
;
16872 die
->die_child
= prev
;
16877 if (c
!= prev
->die_sib
)
16879 prune_unused_types_prune (c
);
16880 } while (c
!= die
->die_child
);
16884 /* Remove dies representing declarations that we never use. */
16887 prune_unused_types (void)
16890 limbo_die_node
*node
;
16893 #if ENABLE_ASSERT_CHECKING
16894 /* All the marks should already be clear. */
16895 verify_marks_clear (comp_unit_die
);
16896 for (node
= limbo_die_list
; node
; node
= node
->next
)
16897 verify_marks_clear (node
->die
);
16898 #endif /* ENABLE_ASSERT_CHECKING */
16900 /* Set the mark on nodes that are actually used. */
16901 prune_unused_types_walk (comp_unit_die
);
16902 for (node
= limbo_die_list
; node
; node
= node
->next
)
16903 prune_unused_types_walk (node
->die
);
16905 /* Also set the mark on nodes referenced from the
16906 pubname_table or arange_table. */
16907 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
16908 prune_unused_types_mark (pub
->die
, 1);
16909 for (i
= 0; i
< arange_table_in_use
; i
++)
16910 prune_unused_types_mark (arange_table
[i
], 1);
16912 /* Get rid of nodes that aren't marked; and update the string counts. */
16913 if (debug_str_hash
)
16914 htab_empty (debug_str_hash
);
16915 prune_unused_types_prune (comp_unit_die
);
16916 for (node
= limbo_die_list
; node
; node
= node
->next
)
16917 prune_unused_types_prune (node
->die
);
16919 /* Leave the marks clear. */
16920 prune_unmark_dies (comp_unit_die
);
16921 for (node
= limbo_die_list
; node
; node
= node
->next
)
16922 prune_unmark_dies (node
->die
);
16925 /* Set the parameter to true if there are any relative pathnames in
16928 file_table_relative_p (void ** slot
, void *param
)
16930 bool *p
= (bool *) param
;
16931 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
16932 if (!IS_ABSOLUTE_PATH (d
->filename
))
16940 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
16941 to the location it would have been added, should we know its
16942 DECL_ASSEMBLER_NAME when we added other attributes. This will
16943 probably improve compactness of debug info, removing equivalent
16944 abbrevs, and hide any differences caused by deferring the
16945 computation of the assembler name, triggered by e.g. PCH. */
16948 move_linkage_attr (dw_die_ref die
)
16950 unsigned ix
= VEC_length (dw_attr_node
, die
->die_attr
);
16951 dw_attr_node linkage
= *VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
16953 gcc_assert (linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
16957 dw_attr_node
*prev
= VEC_index (dw_attr_node
, die
->die_attr
, ix
- 1);
16959 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
16963 if (ix
!= VEC_length (dw_attr_node
, die
->die_attr
) - 1)
16965 VEC_pop (dw_attr_node
, die
->die_attr
);
16966 VEC_quick_insert (dw_attr_node
, die
->die_attr
, ix
, &linkage
);
16970 /* Output stuff that dwarf requires at the end of every file,
16971 and generate the DWARF-2 debugging info. */
16974 dwarf2out_finish (const char *filename
)
16976 limbo_die_node
*node
, *next_node
;
16977 dw_die_ref die
= 0;
16980 /* Add the name for the main input file now. We delayed this from
16981 dwarf2out_init to avoid complications with PCH. */
16982 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
16983 if (!IS_ABSOLUTE_PATH (filename
))
16984 add_comp_dir_attribute (comp_unit_die
);
16985 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
16988 htab_traverse (file_table
, file_table_relative_p
, &p
);
16990 add_comp_dir_attribute (comp_unit_die
);
16993 for (i
= 0; i
< VEC_length (deferred_locations
, deferred_locations_list
); i
++)
16995 add_location_or_const_value_attribute (
16996 VEC_index (deferred_locations
, deferred_locations_list
, i
)->die
,
16997 VEC_index (deferred_locations
, deferred_locations_list
, i
)->variable
,
17001 /* Traverse the limbo die list, and add parent/child links. The only
17002 dies without parents that should be here are concrete instances of
17003 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
17004 For concrete instances, we can get the parent die from the abstract
17006 for (node
= limbo_die_list
; node
; node
= next_node
)
17008 next_node
= node
->next
;
17011 if (die
->die_parent
== NULL
)
17013 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
17016 add_child_die (origin
->die_parent
, die
);
17017 else if (die
== comp_unit_die
)
17019 else if (errorcount
> 0 || sorrycount
> 0)
17020 /* It's OK to be confused by errors in the input. */
17021 add_child_die (comp_unit_die
, die
);
17024 /* In certain situations, the lexical block containing a
17025 nested function can be optimized away, which results
17026 in the nested function die being orphaned. Likewise
17027 with the return type of that nested function. Force
17028 this to be a child of the containing function.
17030 It may happen that even the containing function got fully
17031 inlined and optimized out. In that case we are lost and
17032 assign the empty child. This should not be big issue as
17033 the function is likely unreachable too. */
17034 tree context
= NULL_TREE
;
17036 gcc_assert (node
->created_for
);
17038 if (DECL_P (node
->created_for
))
17039 context
= DECL_CONTEXT (node
->created_for
);
17040 else if (TYPE_P (node
->created_for
))
17041 context
= TYPE_CONTEXT (node
->created_for
);
17043 gcc_assert (context
17044 && (TREE_CODE (context
) == FUNCTION_DECL
17045 || TREE_CODE (context
) == NAMESPACE_DECL
));
17047 origin
= lookup_decl_die (context
);
17049 add_child_die (origin
, die
);
17051 add_child_die (comp_unit_die
, die
);
17056 limbo_die_list
= NULL
;
17058 for (node
= deferred_asm_name
; node
; node
= node
->next
)
17060 tree decl
= node
->created_for
;
17061 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17063 add_AT_string (node
->die
, DW_AT_MIPS_linkage_name
,
17064 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
17065 move_linkage_attr (node
->die
);
17069 deferred_asm_name
= NULL
;
17071 /* Walk through the list of incomplete types again, trying once more to
17072 emit full debugging info for them. */
17073 retry_incomplete_types ();
17075 if (flag_eliminate_unused_debug_types
)
17076 prune_unused_types ();
17078 /* Generate separate CUs for each of the include files we've seen.
17079 They will go into limbo_die_list. */
17080 if (flag_eliminate_dwarf2_dups
)
17081 break_out_includes (comp_unit_die
);
17083 /* Traverse the DIE's and add add sibling attributes to those DIE's
17084 that have children. */
17085 add_sibling_attributes (comp_unit_die
);
17086 for (node
= limbo_die_list
; node
; node
= node
->next
)
17087 add_sibling_attributes (node
->die
);
17089 /* Output a terminator label for the .text section. */
17090 switch_to_section (text_section
);
17091 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
17092 if (flag_reorder_blocks_and_partition
)
17094 switch_to_section (unlikely_text_section ());
17095 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
17098 /* We can only use the low/high_pc attributes if all of the code was
17100 if (!have_multiple_function_sections
)
17102 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
17103 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
17108 unsigned fde_idx
= 0;
17110 /* We need to give .debug_loc and .debug_ranges an appropriate
17111 "base address". Use zero so that these addresses become
17112 absolute. Historically, we've emitted the unexpected
17113 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
17114 Emit both to give time for other tools to adapt. */
17115 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
17116 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
17118 add_AT_range_list (comp_unit_die
, DW_AT_ranges
,
17119 add_ranges_by_labels (text_section_label
,
17121 if (flag_reorder_blocks_and_partition
)
17122 add_ranges_by_labels (cold_text_section_label
,
17125 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
17127 dw_fde_ref fde
= &fde_table
[fde_idx
];
17129 if (fde
->dw_fde_switched_sections
)
17131 add_ranges_by_labels (fde
->dw_fde_hot_section_label
,
17132 fde
->dw_fde_hot_section_end_label
);
17133 add_ranges_by_labels (fde
->dw_fde_unlikely_section_label
,
17134 fde
->dw_fde_unlikely_section_end_label
);
17137 add_ranges_by_labels (fde
->dw_fde_begin
,
17144 /* Output location list section if necessary. */
17145 if (have_location_lists
)
17147 /* Output the location lists info. */
17148 switch_to_section (debug_loc_section
);
17149 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
17150 DEBUG_LOC_SECTION_LABEL
, 0);
17151 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
17152 output_location_lists (die
);
17155 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
17156 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
17157 debug_line_section_label
);
17159 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
17160 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
17162 /* Output all of the compilation units. We put the main one last so that
17163 the offsets are available to output_pubnames. */
17164 for (node
= limbo_die_list
; node
; node
= node
->next
)
17165 output_comp_unit (node
->die
, 0);
17167 /* Output the main compilation unit if non-empty or if .debug_macinfo
17168 has been emitted. */
17169 output_comp_unit (comp_unit_die
, debug_info_level
>= DINFO_LEVEL_VERBOSE
);
17171 /* Output the abbreviation table. */
17172 switch_to_section (debug_abbrev_section
);
17173 output_abbrev_section ();
17175 /* Output public names table if necessary. */
17176 if (!VEC_empty (pubname_entry
, pubname_table
))
17178 switch_to_section (debug_pubnames_section
);
17179 output_pubnames (pubname_table
);
17182 /* Output public types table if necessary. */
17183 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
17184 It shouldn't hurt to emit it always, since pure DWARF2 consumers
17185 simply won't look for the section. */
17186 if (!VEC_empty (pubname_entry
, pubtype_table
))
17188 switch_to_section (debug_pubtypes_section
);
17189 output_pubnames (pubtype_table
);
17192 /* Output the address range information. We only put functions in the arange
17193 table, so don't write it out if we don't have any. */
17194 if (fde_table_in_use
)
17196 switch_to_section (debug_aranges_section
);
17200 /* Output ranges section if necessary. */
17201 if (ranges_table_in_use
)
17203 switch_to_section (debug_ranges_section
);
17204 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
17208 /* Output the source line correspondence table. We must do this
17209 even if there is no line information. Otherwise, on an empty
17210 translation unit, we will generate a present, but empty,
17211 .debug_info section. IRIX 6.5 `nm' will then complain when
17212 examining the file. This is done late so that any filenames
17213 used by the debug_info section are marked as 'used'. */
17214 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
17216 switch_to_section (debug_line_section
);
17217 output_line_info ();
17220 /* Have to end the macro section. */
17221 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
17223 switch_to_section (debug_macinfo_section
);
17224 dw2_asm_output_data (1, 0, "End compilation unit");
17227 /* If we emitted any DW_FORM_strp form attribute, output the string
17229 if (debug_str_hash
)
17230 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
17234 /* This should never be used, but its address is needed for comparisons. */
17235 const struct gcc_debug_hooks dwarf2_debug_hooks
=
17241 0, /* start_source_file */
17242 0, /* end_source_file */
17243 0, /* begin_block */
17245 0, /* ignore_block */
17246 0, /* source_line */
17247 0, /* begin_prologue */
17248 0, /* end_prologue */
17249 0, /* end_epilogue */
17250 0, /* begin_function */
17251 0, /* end_function */
17252 0, /* function_decl */
17253 0, /* global_decl */
17255 0, /* imported_module_or_decl */
17256 0, /* deferred_inline_function */
17257 0, /* outlining_inline_function */
17259 0, /* handle_pch */
17260 0, /* var_location */
17261 0, /* switch_text_section */
17263 0 /* start_end_main_source_file */
17266 #endif /* DWARF2_DEBUGGING_INFO */
17268 #include "gt-dwarf2out.h"