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, 2010
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 #ifndef DWARF2_UNWIND_INFO
116 #define DWARF2_UNWIND_INFO 0
119 #ifndef INCOMING_RETURN_ADDR_RTX
120 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
123 #ifndef DWARF2_FRAME_INFO
124 # ifdef DWARF2_DEBUGGING_INFO
125 # define DWARF2_FRAME_INFO \
126 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
128 # define DWARF2_FRAME_INFO 0
132 /* Map register numbers held in the call frame info that gcc has
133 collected using DWARF_FRAME_REGNUM to those that should be output in
134 .debug_frame and .eh_frame. */
135 #ifndef DWARF2_FRAME_REG_OUT
136 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
139 /* Save the result of dwarf2out_do_frame across PCH. */
140 static GTY(()) bool saved_do_cfi_asm = 0;
142 /* Decide whether we want to emit frame unwind information for the current
146 dwarf2out_do_frame (void)
148 /* We want to emit correct CFA location expressions or lists, so we
149 have to return true if we're going to output debug info, even if
150 we're not going to output frame or unwind info. */
151 return (write_symbols == DWARF2_DEBUG
152 || write_symbols == VMS_AND_DWARF2_DEBUG
153 || DWARF2_FRAME_INFO || saved_do_cfi_asm
154 || (DWARF2_UNWIND_INFO
155 && (flag_unwind_tables
156 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
160 /* Decide whether to emit frame unwind via assembler directives. */
163 dwarf2out_do_cfi_asm (void)
167 #ifdef MIPS_DEBUGGING_INFO
170 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
172 if (saved_do_cfi_asm)
174 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
177 /* Make sure the personality encoding is one the assembler can support.
178 In particular, aligned addresses can't be handled. */
179 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
180 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
186 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
188 #ifdef TARGET_UNWIND_INFO
191 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
196 saved_do_cfi_asm = true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_dcall_section;
232 static GTY(()) section *debug_vcall_section;
233 static GTY(()) section *debug_str_section;
234 static GTY(()) section *debug_ranges_section;
235 static GTY(()) section *debug_frame_section;
237 /* Personality decl of current unit. Used only when assembler does not support
239 static GTY(()) rtx current_unit_personality;
241 /* How to start an assembler comment. */
242 #ifndef ASM_COMMENT_START
243 #define ASM_COMMENT_START ";#"
246 typedef struct dw_cfi_struct *dw_cfi_ref;
247 typedef struct dw_fde_struct *dw_fde_ref;
248 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
250 /* Call frames are described using a sequence of Call Frame
251 Information instructions. The register number, offset
252 and address fields are provided as possible operands;
253 their use is selected by the opcode field. */
255 enum dw_cfi_oprnd_type {
257 dw_cfi_oprnd_reg_num,
263 typedef union GTY(()) dw_cfi_oprnd_struct {
264 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
265 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
266 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
267 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
271 typedef struct GTY(()) dw_cfi_struct {
272 dw_cfi_ref dw_cfi_next;
273 enum dwarf_call_frame_info dw_cfi_opc;
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
276 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
281 /* This is how we define the location of the CFA. We use to handle it
282 as REG + OFFSET all the time, but now it can be more complex.
283 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
284 Instead of passing around REG and OFFSET, we pass a copy
285 of this structure. */
286 typedef struct GTY(()) cfa_loc {
287 HOST_WIDE_INT offset;
288 HOST_WIDE_INT base_offset;
290 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
291 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
294 /* All call frame descriptions (FDE's) in the GCC generated DWARF
295 refer to a single Common Information Entry (CIE), defined at
296 the beginning of the .debug_frame section. This use of a single
297 CIE obviates the need to keep track of multiple CIE's
298 in the DWARF generation routines below. */
300 typedef struct GTY(()) dw_fde_struct {
302 const char *dw_fde_begin;
303 const char *dw_fde_current_label;
304 const char *dw_fde_end;
305 const char *dw_fde_vms_end_prologue;
306 const char *dw_fde_vms_begin_epilogue;
307 const char *dw_fde_hot_section_label;
308 const char *dw_fde_hot_section_end_label;
309 const char *dw_fde_unlikely_section_label;
310 const char *dw_fde_unlikely_section_end_label;
311 dw_cfi_ref dw_fde_cfi;
312 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
313 HOST_WIDE_INT stack_realignment;
314 unsigned funcdef_number;
315 /* Dynamic realign argument pointer register. */
316 unsigned int drap_reg;
317 /* Virtual dynamic realign argument pointer register. */
318 unsigned int vdrap_reg;
319 /* These 3 flags are copied from rtl_data in function.h. */
320 unsigned all_throwers_are_sibcalls : 1;
321 unsigned uses_eh_lsda : 1;
322 unsigned nothrow : 1;
323 /* Whether we did stack realign in this call frame. */
324 unsigned stack_realign : 1;
325 /* Whether dynamic realign argument pointer register has been saved. */
326 unsigned drap_reg_saved: 1;
327 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
328 unsigned in_std_section : 1;
329 /* True iff dw_fde_unlikely_section_label is in text_section or
330 cold_text_section. */
331 unsigned cold_in_std_section : 1;
332 /* True iff switched sections. */
333 unsigned dw_fde_switched_sections : 1;
334 /* True iff switching from cold to hot section. */
335 unsigned dw_fde_switched_cold_to_hot : 1;
339 /* Maximum size (in bytes) of an artificially generated label. */
340 #define MAX_ARTIFICIAL_LABEL_BYTES 30
342 /* The size of addresses as they appear in the Dwarf 2 data.
343 Some architectures use word addresses to refer to code locations,
344 but Dwarf 2 info always uses byte addresses. On such machines,
345 Dwarf 2 addresses need to be larger than the architecture's
347 #ifndef DWARF2_ADDR_SIZE
348 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
351 /* The size in bytes of a DWARF field indicating an offset or length
352 relative to a debug info section, specified to be 4 bytes in the
353 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
356 #ifndef DWARF_OFFSET_SIZE
357 #define DWARF_OFFSET_SIZE 4
360 /* The size in bytes of a DWARF 4 type signature. */
362 #ifndef DWARF_TYPE_SIGNATURE_SIZE
363 #define DWARF_TYPE_SIGNATURE_SIZE 8
366 /* According to the (draft) DWARF 3 specification, the initial length
367 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
368 bytes are 0xffffffff, followed by the length stored in the next 8
371 However, the SGI/MIPS ABI uses an initial length which is equal to
372 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
374 #ifndef DWARF_INITIAL_LENGTH_SIZE
375 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
378 /* Round SIZE up to the nearest BOUNDARY. */
379 #define DWARF_ROUND(SIZE,BOUNDARY) \
380 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
382 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
383 #ifndef DWARF_CIE_DATA_ALIGNMENT
384 #ifdef STACK_GROWS_DOWNWARD
385 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
387 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
391 /* CIE identifier. */
392 #if HOST_BITS_PER_WIDE_INT >= 64
393 #define DWARF_CIE_ID \
394 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
396 #define DWARF_CIE_ID DW_CIE_ID
399 /* A pointer to the base of a table that contains frame description
400 information for each routine. */
401 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
403 /* Number of elements currently allocated for fde_table. */
404 static GTY(()) unsigned fde_table_allocated;
406 /* Number of elements in fde_table currently in use. */
407 static GTY(()) unsigned fde_table_in_use;
409 /* Size (in elements) of increments by which we may expand the
411 #define FDE_TABLE_INCREMENT 256
413 /* Get the current fde_table entry we should use. */
415 static inline dw_fde_ref
418 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
421 /* A list of call frame insns for the CIE. */
422 static GTY(()) dw_cfi_ref cie_cfi_head;
424 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
425 attribute that accelerates the lookup of the FDE associated
426 with the subprogram. This variable holds the table index of the FDE
427 associated with the current function (body) definition. */
428 static unsigned current_funcdef_fde;
430 struct GTY(()) indirect_string_node {
432 unsigned int refcount;
433 enum dwarf_form form;
437 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
439 /* True if the compilation unit has location entries that reference
441 static GTY(()) bool debug_str_hash_forced = false;
443 static GTY(()) int dw2_string_counter;
444 static GTY(()) unsigned long dwarf2out_cfi_label_num;
446 /* True if the compilation unit places functions in more than one section. */
447 static GTY(()) bool have_multiple_function_sections = false;
449 /* Whether the default text and cold text sections have been used at all. */
451 static GTY(()) bool text_section_used = false;
452 static GTY(()) bool cold_text_section_used = false;
454 /* The default cold text section. */
455 static GTY(()) section *cold_text_section;
457 /* Forward declarations for functions defined in this file. */
459 static char *stripattributes (const char *);
460 static const char *dwarf_cfi_name (unsigned);
461 static dw_cfi_ref new_cfi (void);
462 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
463 static void add_fde_cfi (const char *, dw_cfi_ref);
464 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
465 static void lookup_cfa (dw_cfa_location *);
466 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
467 static void initial_return_save (rtx);
468 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
470 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
471 static void output_cfi_directive (dw_cfi_ref);
472 static void output_call_frame_info (int);
473 static void dwarf2out_note_section_used (void);
474 static bool clobbers_queued_reg_save (const_rtx);
475 static void dwarf2out_frame_debug_expr (rtx, const char *);
477 /* Support for complex CFA locations. */
478 static void output_cfa_loc (dw_cfi_ref);
479 static void output_cfa_loc_raw (dw_cfi_ref);
480 static void get_cfa_from_loc_descr (dw_cfa_location *,
481 struct dw_loc_descr_struct *);
482 static struct dw_loc_descr_struct *build_cfa_loc
483 (dw_cfa_location *, HOST_WIDE_INT);
484 static struct dw_loc_descr_struct *build_cfa_aligned_loc
485 (HOST_WIDE_INT, HOST_WIDE_INT);
486 static void def_cfa_1 (const char *, dw_cfa_location *);
487 static struct dw_loc_descr_struct *mem_loc_descriptor
488 (rtx, enum machine_mode mode, enum var_init_status);
490 /* How to start an assembler comment. */
491 #ifndef ASM_COMMENT_START
492 #define ASM_COMMENT_START ";#"
495 /* Data and reference forms for relocatable data. */
496 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
497 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
499 #ifndef DEBUG_FRAME_SECTION
500 #define DEBUG_FRAME_SECTION ".debug_frame"
503 #ifndef FUNC_BEGIN_LABEL
504 #define FUNC_BEGIN_LABEL "LFB"
507 #ifndef FUNC_END_LABEL
508 #define FUNC_END_LABEL "LFE"
511 #ifndef PROLOGUE_END_LABEL
512 #define PROLOGUE_END_LABEL "LPE"
515 #ifndef EPILOGUE_BEGIN_LABEL
516 #define EPILOGUE_BEGIN_LABEL "LEB"
519 #ifndef FRAME_BEGIN_LABEL
520 #define FRAME_BEGIN_LABEL "Lframe"
522 #define CIE_AFTER_SIZE_LABEL "LSCIE"
523 #define CIE_END_LABEL "LECIE"
524 #define FDE_LABEL "LSFDE"
525 #define FDE_AFTER_SIZE_LABEL "LASFDE"
526 #define FDE_END_LABEL "LEFDE"
527 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
528 #define LINE_NUMBER_END_LABEL "LELT"
529 #define LN_PROLOG_AS_LABEL "LASLTP"
530 #define LN_PROLOG_END_LABEL "LELTP"
531 #define DIE_LABEL_PREFIX "DW"
533 /* The DWARF 2 CFA column which tracks the return address. Normally this
534 is the column for PC, or the first column after all of the hard
536 #ifndef DWARF_FRAME_RETURN_COLUMN
538 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
540 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
544 /* The mapping from gcc register number to DWARF 2 CFA column number. By
545 default, we just provide columns for all registers. */
546 #ifndef DWARF_FRAME_REGNUM
547 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
550 /* Hook used by __throw. */
553 expand_builtin_dwarf_sp_column (void)
555 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
556 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
559 /* Return a pointer to a copy of the section string name S with all
560 attributes stripped off, and an asterisk prepended (for assemble_name). */
563 stripattributes (const char *s)
565 char *stripped = XNEWVEC (char, strlen (s) + 2);
570 while (*s && *s != ',')
577 /* MEM is a memory reference for the register size table, each element of
578 which has mode MODE. Initialize column C as a return address column. */
581 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
583 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
584 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
585 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
588 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
590 static inline HOST_WIDE_INT
591 div_data_align (HOST_WIDE_INT off)
593 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
594 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
598 /* Return true if we need a signed version of a given opcode
599 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
602 need_data_align_sf_opcode (HOST_WIDE_INT off)
604 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
607 /* Generate code to initialize the register size table. */
610 expand_builtin_init_dwarf_reg_sizes (tree address)
613 enum machine_mode mode = TYPE_MODE (char_type_node);
614 rtx addr = expand_normal (address);
615 rtx mem = gen_rtx_MEM (BLKmode, addr);
616 bool wrote_return_column = false;
618 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
620 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
622 if (rnum < DWARF_FRAME_REGISTERS)
624 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
625 enum machine_mode save_mode = reg_raw_mode[i];
628 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
629 save_mode = choose_hard_reg_mode (i, 1, true);
630 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
632 if (save_mode == VOIDmode)
634 wrote_return_column = true;
636 size = GET_MODE_SIZE (save_mode);
640 emit_move_insn (adjust_address (mem, mode, offset),
641 gen_int_mode (size, mode));
645 if (!wrote_return_column)
646 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
648 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
649 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
652 targetm.init_dwarf_reg_sizes_extra (address);
655 /* Convert a DWARF call frame info. operation to its string name */
658 dwarf_cfi_name (unsigned int cfi_opc)
662 case DW_CFA_advance_loc:
663 return "DW_CFA_advance_loc";
665 return "DW_CFA_offset";
667 return "DW_CFA_restore";
671 return "DW_CFA_set_loc";
672 case DW_CFA_advance_loc1:
673 return "DW_CFA_advance_loc1";
674 case DW_CFA_advance_loc2:
675 return "DW_CFA_advance_loc2";
676 case DW_CFA_advance_loc4:
677 return "DW_CFA_advance_loc4";
678 case DW_CFA_offset_extended:
679 return "DW_CFA_offset_extended";
680 case DW_CFA_restore_extended:
681 return "DW_CFA_restore_extended";
682 case DW_CFA_undefined:
683 return "DW_CFA_undefined";
684 case DW_CFA_same_value:
685 return "DW_CFA_same_value";
686 case DW_CFA_register:
687 return "DW_CFA_register";
688 case DW_CFA_remember_state:
689 return "DW_CFA_remember_state";
690 case DW_CFA_restore_state:
691 return "DW_CFA_restore_state";
693 return "DW_CFA_def_cfa";
694 case DW_CFA_def_cfa_register:
695 return "DW_CFA_def_cfa_register";
696 case DW_CFA_def_cfa_offset:
697 return "DW_CFA_def_cfa_offset";
700 case DW_CFA_def_cfa_expression:
701 return "DW_CFA_def_cfa_expression";
702 case DW_CFA_expression:
703 return "DW_CFA_expression";
704 case DW_CFA_offset_extended_sf:
705 return "DW_CFA_offset_extended_sf";
706 case DW_CFA_def_cfa_sf:
707 return "DW_CFA_def_cfa_sf";
708 case DW_CFA_def_cfa_offset_sf:
709 return "DW_CFA_def_cfa_offset_sf";
711 /* SGI/MIPS specific */
712 case DW_CFA_MIPS_advance_loc8:
713 return "DW_CFA_MIPS_advance_loc8";
716 case DW_CFA_GNU_window_save:
717 return "DW_CFA_GNU_window_save";
718 case DW_CFA_GNU_args_size:
719 return "DW_CFA_GNU_args_size";
720 case DW_CFA_GNU_negative_offset_extended:
721 return "DW_CFA_GNU_negative_offset_extended";
724 return "DW_CFA_<unknown>";
728 /* Return a pointer to a newly allocated Call Frame Instruction. */
730 static inline dw_cfi_ref
733 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
735 cfi->dw_cfi_next = NULL;
736 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
737 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
742 /* Add a Call Frame Instruction to list of instructions. */
745 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
748 dw_fde_ref fde = current_fde ();
750 /* When DRAP is used, CFA is defined with an expression. Redefine
751 CFA may lead to a different CFA value. */
752 /* ??? Of course, this heuristic fails when we're annotating epilogues,
753 because of course we'll always want to redefine the CFA back to the
754 stack pointer on the way out. Where should we move this check? */
755 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
756 switch (cfi->dw_cfi_opc)
758 case DW_CFA_def_cfa_register:
759 case DW_CFA_def_cfa_offset:
760 case DW_CFA_def_cfa_offset_sf:
762 case DW_CFA_def_cfa_sf:
769 /* Find the end of the chain. */
770 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
776 /* Generate a new label for the CFI info to refer to. FORCE is true
777 if a label needs to be output even when using .cfi_* directives. */
780 dwarf2out_cfi_label (bool force)
782 static char label[20];
784 if (!force && dwarf2out_do_cfi_asm ())
786 /* In this case, we will be emitting the asm directive instead of
787 the label, so just return a placeholder to keep the rest of the
789 strcpy (label, "<do not output>");
793 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
794 ASM_OUTPUT_LABEL (asm_out_file, label);
800 /* True if remember_state should be emitted before following CFI directive. */
801 static bool emit_cfa_remember;
803 /* True if any CFI directives were emitted at the current insn. */
804 static bool any_cfis_emitted;
806 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
807 or to the CIE if LABEL is NULL. */
810 add_fde_cfi (const char *label, dw_cfi_ref cfi)
812 dw_cfi_ref *list_head;
814 if (emit_cfa_remember)
816 dw_cfi_ref cfi_remember;
818 /* Emit the state save. */
819 emit_cfa_remember = false;
820 cfi_remember = new_cfi ();
821 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
822 add_fde_cfi (label, cfi_remember);
825 list_head = &cie_cfi_head;
827 if (dwarf2out_do_cfi_asm ())
831 dw_fde_ref fde = current_fde ();
833 gcc_assert (fde != NULL);
835 /* We still have to add the cfi to the list so that lookup_cfa
836 works later on. When -g2 and above we even need to force
837 emitting of CFI labels and add to list a DW_CFA_set_loc for
838 convert_cfa_to_fb_loc_list purposes. If we're generating
839 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
840 convert_cfa_to_fb_loc_list. */
841 if (dwarf_version == 2
842 && debug_info_level > DINFO_LEVEL_TERSE
843 && (write_symbols == DWARF2_DEBUG
844 || write_symbols == VMS_AND_DWARF2_DEBUG))
846 switch (cfi->dw_cfi_opc)
848 case DW_CFA_def_cfa_offset:
849 case DW_CFA_def_cfa_offset_sf:
850 case DW_CFA_def_cfa_register:
852 case DW_CFA_def_cfa_sf:
853 case DW_CFA_def_cfa_expression:
854 case DW_CFA_restore_state:
855 if (*label == 0 || strcmp (label, "<do not output>") == 0)
856 label = dwarf2out_cfi_label (true);
858 if (fde->dw_fde_current_label == NULL
859 || strcmp (label, fde->dw_fde_current_label) != 0)
863 label = xstrdup (label);
865 /* Set the location counter to the new label. */
867 /* It doesn't metter whether DW_CFA_set_loc
868 or DW_CFA_advance_loc4 is added here, those aren't
869 emitted into assembly, only looked up by
870 convert_cfa_to_fb_loc_list. */
871 xcfi->dw_cfi_opc = DW_CFA_set_loc;
872 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
873 add_cfi (&fde->dw_fde_cfi, xcfi);
874 fde->dw_fde_current_label = label;
882 output_cfi_directive (cfi);
884 list_head = &fde->dw_fde_cfi;
885 any_cfis_emitted = true;
887 /* ??? If this is a CFI for the CIE, we don't emit. This
888 assumes that the standard CIE contents that the assembler
889 uses matches the standard CIE contents that the compiler
890 uses. This is probably a bad assumption. I'm not quite
891 sure how to address this for now. */
895 dw_fde_ref fde = current_fde ();
897 gcc_assert (fde != NULL);
900 label = dwarf2out_cfi_label (false);
902 if (fde->dw_fde_current_label == NULL
903 || strcmp (label, fde->dw_fde_current_label) != 0)
907 label = xstrdup (label);
909 /* Set the location counter to the new label. */
911 /* If we have a current label, advance from there, otherwise
912 set the location directly using set_loc. */
913 xcfi->dw_cfi_opc = fde->dw_fde_current_label
914 ? DW_CFA_advance_loc4
916 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
917 add_cfi (&fde->dw_fde_cfi, xcfi);
919 fde->dw_fde_current_label = label;
922 list_head = &fde->dw_fde_cfi;
923 any_cfis_emitted = true;
926 add_cfi (list_head, cfi);
929 /* Subroutine of lookup_cfa. */
932 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
934 switch (cfi->dw_cfi_opc)
936 case DW_CFA_def_cfa_offset:
937 case DW_CFA_def_cfa_offset_sf:
938 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
940 case DW_CFA_def_cfa_register:
941 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
944 case DW_CFA_def_cfa_sf:
945 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
946 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
948 case DW_CFA_def_cfa_expression:
949 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
952 case DW_CFA_remember_state:
953 gcc_assert (!remember->in_use);
955 remember->in_use = 1;
957 case DW_CFA_restore_state:
958 gcc_assert (remember->in_use);
960 remember->in_use = 0;
968 /* Find the previous value for the CFA. */
971 lookup_cfa (dw_cfa_location *loc)
975 dw_cfa_location remember;
977 memset (loc, 0, sizeof (*loc));
978 loc->reg = INVALID_REGNUM;
981 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
982 lookup_cfa_1 (cfi, loc, &remember);
984 fde = current_fde ();
986 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
987 lookup_cfa_1 (cfi, loc, &remember);
990 /* The current rule for calculating the DWARF2 canonical frame address. */
991 static dw_cfa_location cfa;
993 /* The register used for saving registers to the stack, and its offset
995 static dw_cfa_location cfa_store;
997 /* The current save location around an epilogue. */
998 static dw_cfa_location cfa_remember;
1000 /* The running total of the size of arguments pushed onto the stack. */
1001 static HOST_WIDE_INT args_size;
1003 /* The last args_size we actually output. */
1004 static HOST_WIDE_INT old_args_size;
1006 /* Entry point to update the canonical frame address (CFA).
1007 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1008 calculated from REG+OFFSET. */
1011 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1013 dw_cfa_location loc;
1015 loc.base_offset = 0;
1017 loc.offset = offset;
1018 def_cfa_1 (label, &loc);
1021 /* Determine if two dw_cfa_location structures define the same data. */
1024 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1026 return (loc1->reg == loc2->reg
1027 && loc1->offset == loc2->offset
1028 && loc1->indirect == loc2->indirect
1029 && (loc1->indirect == 0
1030 || loc1->base_offset == loc2->base_offset));
1033 /* This routine does the actual work. The CFA is now calculated from
1034 the dw_cfa_location structure. */
1037 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1040 dw_cfa_location old_cfa, loc;
1045 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1046 cfa_store.offset = loc.offset;
1048 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1049 lookup_cfa (&old_cfa);
1051 /* If nothing changed, no need to issue any call frame instructions. */
1052 if (cfa_equal_p (&loc, &old_cfa))
1057 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1059 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1060 the CFA register did not change but the offset did. The data
1061 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1062 in the assembler via the .cfi_def_cfa_offset directive. */
1064 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1066 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1067 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1070 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1071 else if (loc.offset == old_cfa.offset
1072 && old_cfa.reg != INVALID_REGNUM
1074 && !old_cfa.indirect)
1076 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1077 indicating the CFA register has changed to <register> but the
1078 offset has not changed. */
1079 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1080 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1084 else if (loc.indirect == 0)
1086 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1087 indicating the CFA register has changed to <register> with
1088 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1089 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1092 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1094 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1095 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1096 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1100 /* Construct a DW_CFA_def_cfa_expression instruction to
1101 calculate the CFA using a full location expression since no
1102 register-offset pair is available. */
1103 struct dw_loc_descr_struct *loc_list;
1105 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1106 loc_list = build_cfa_loc (&loc, 0);
1107 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1110 add_fde_cfi (label, cfi);
1113 /* Add the CFI for saving a register. REG is the CFA column number.
1114 LABEL is passed to add_fde_cfi.
1115 If SREG is -1, the register is saved at OFFSET from the CFA;
1116 otherwise it is saved in SREG. */
1119 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1121 dw_cfi_ref cfi = new_cfi ();
1122 dw_fde_ref fde = current_fde ();
1124 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1126 /* When stack is aligned, store REG using DW_CFA_expression with
1129 && fde->stack_realign
1130 && sreg == INVALID_REGNUM)
1132 cfi->dw_cfi_opc = DW_CFA_expression;
1133 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1134 cfi->dw_cfi_oprnd2.dw_cfi_loc
1135 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1137 else if (sreg == INVALID_REGNUM)
1139 if (need_data_align_sf_opcode (offset))
1140 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1141 else if (reg & ~0x3f)
1142 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1144 cfi->dw_cfi_opc = DW_CFA_offset;
1145 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1147 else if (sreg == reg)
1148 cfi->dw_cfi_opc = DW_CFA_same_value;
1151 cfi->dw_cfi_opc = DW_CFA_register;
1152 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1155 add_fde_cfi (label, cfi);
1158 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1159 This CFI tells the unwinder that it needs to restore the window registers
1160 from the previous frame's window save area.
1162 ??? Perhaps we should note in the CIE where windows are saved (instead of
1163 assuming 0(cfa)) and what registers are in the window. */
1166 dwarf2out_window_save (const char *label)
1168 dw_cfi_ref cfi = new_cfi ();
1170 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1171 add_fde_cfi (label, cfi);
1174 /* Entry point for saving a register to the stack. REG is the GCC register
1175 number. LABEL and OFFSET are passed to reg_save. */
1178 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1180 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1183 /* Entry point for saving the return address in the stack.
1184 LABEL and OFFSET are passed to reg_save. */
1187 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1189 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1192 /* Entry point for saving the return address in a register.
1193 LABEL and SREG are passed to reg_save. */
1196 dwarf2out_return_reg (const char *label, unsigned int sreg)
1198 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1201 /* Record the initial position of the return address. RTL is
1202 INCOMING_RETURN_ADDR_RTX. */
1205 initial_return_save (rtx rtl)
1207 unsigned int reg = INVALID_REGNUM;
1208 HOST_WIDE_INT offset = 0;
1210 switch (GET_CODE (rtl))
1213 /* RA is in a register. */
1214 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1218 /* RA is on the stack. */
1219 rtl = XEXP (rtl, 0);
1220 switch (GET_CODE (rtl))
1223 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1228 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1229 offset = INTVAL (XEXP (rtl, 1));
1233 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1234 offset = -INTVAL (XEXP (rtl, 1));
1244 /* The return address is at some offset from any value we can
1245 actually load. For instance, on the SPARC it is in %i7+8. Just
1246 ignore the offset for now; it doesn't matter for unwinding frames. */
1247 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1248 initial_return_save (XEXP (rtl, 0));
1255 if (reg != DWARF_FRAME_RETURN_COLUMN)
1256 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1259 /* Given a SET, calculate the amount of stack adjustment it
1262 static HOST_WIDE_INT
1263 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1264 HOST_WIDE_INT cur_offset)
1266 const_rtx src = SET_SRC (pattern);
1267 const_rtx dest = SET_DEST (pattern);
1268 HOST_WIDE_INT offset = 0;
1271 if (dest == stack_pointer_rtx)
1273 code = GET_CODE (src);
1275 /* Assume (set (reg sp) (reg whatever)) sets args_size
1277 if (code == REG && src != stack_pointer_rtx)
1279 offset = -cur_args_size;
1280 #ifndef STACK_GROWS_DOWNWARD
1283 return offset - cur_offset;
1286 if (! (code == PLUS || code == MINUS)
1287 || XEXP (src, 0) != stack_pointer_rtx
1288 || !CONST_INT_P (XEXP (src, 1)))
1291 /* (set (reg sp) (plus (reg sp) (const_int))) */
1292 offset = INTVAL (XEXP (src, 1));
1298 if (MEM_P (src) && !MEM_P (dest))
1302 /* (set (mem (pre_dec (reg sp))) (foo)) */
1303 src = XEXP (dest, 0);
1304 code = GET_CODE (src);
1310 if (XEXP (src, 0) == stack_pointer_rtx)
1312 rtx val = XEXP (XEXP (src, 1), 1);
1313 /* We handle only adjustments by constant amount. */
1314 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1315 && CONST_INT_P (val));
1316 offset = -INTVAL (val);
1323 if (XEXP (src, 0) == stack_pointer_rtx)
1325 offset = GET_MODE_SIZE (GET_MODE (dest));
1332 if (XEXP (src, 0) == stack_pointer_rtx)
1334 offset = -GET_MODE_SIZE (GET_MODE (dest));
1349 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1350 indexed by INSN_UID. */
1352 static HOST_WIDE_INT *barrier_args_size;
1354 /* Helper function for compute_barrier_args_size. Handle one insn. */
1356 static HOST_WIDE_INT
1357 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1358 VEC (rtx, heap) **next)
1360 HOST_WIDE_INT offset = 0;
1363 if (! RTX_FRAME_RELATED_P (insn))
1365 if (prologue_epilogue_contains (insn))
1367 else if (GET_CODE (PATTERN (insn)) == SET)
1368 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1369 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1370 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1372 /* There may be stack adjustments inside compound insns. Search
1374 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1375 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1376 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1377 cur_args_size, offset);
1382 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1386 expr = XEXP (expr, 0);
1387 if (GET_CODE (expr) == PARALLEL
1388 || GET_CODE (expr) == SEQUENCE)
1389 for (i = 1; i < XVECLEN (expr, 0); i++)
1391 rtx elem = XVECEXP (expr, 0, i);
1393 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1394 offset += stack_adjust_offset (elem, cur_args_size, offset);
1399 #ifndef STACK_GROWS_DOWNWARD
1403 cur_args_size += offset;
1404 if (cur_args_size < 0)
1409 rtx dest = JUMP_LABEL (insn);
1413 if (barrier_args_size [INSN_UID (dest)] < 0)
1415 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1416 VEC_safe_push (rtx, heap, *next, dest);
1421 return cur_args_size;
1424 /* Walk the whole function and compute args_size on BARRIERs. */
1427 compute_barrier_args_size (void)
1429 int max_uid = get_max_uid (), i;
1431 VEC (rtx, heap) *worklist, *next, *tmp;
1433 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1434 for (i = 0; i < max_uid; i++)
1435 barrier_args_size[i] = -1;
1437 worklist = VEC_alloc (rtx, heap, 20);
1438 next = VEC_alloc (rtx, heap, 20);
1439 insn = get_insns ();
1440 barrier_args_size[INSN_UID (insn)] = 0;
1441 VEC_quick_push (rtx, worklist, insn);
1444 while (!VEC_empty (rtx, worklist))
1446 rtx prev, body, first_insn;
1447 HOST_WIDE_INT cur_args_size;
1449 first_insn = insn = VEC_pop (rtx, worklist);
1450 cur_args_size = barrier_args_size[INSN_UID (insn)];
1451 prev = prev_nonnote_insn (insn);
1452 if (prev && BARRIER_P (prev))
1453 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1455 for (; insn; insn = NEXT_INSN (insn))
1457 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1459 if (BARRIER_P (insn))
1464 if (insn == first_insn)
1466 else if (barrier_args_size[INSN_UID (insn)] < 0)
1468 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1473 /* The insns starting with this label have been
1474 already scanned or are in the worklist. */
1479 body = PATTERN (insn);
1480 if (GET_CODE (body) == SEQUENCE)
1482 HOST_WIDE_INT dest_args_size = cur_args_size;
1483 for (i = 1; i < XVECLEN (body, 0); i++)
1484 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1485 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1487 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1488 dest_args_size, &next);
1491 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1492 cur_args_size, &next);
1494 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1495 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1496 dest_args_size, &next);
1499 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1500 cur_args_size, &next);
1504 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1508 if (VEC_empty (rtx, next))
1511 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1515 VEC_truncate (rtx, next, 0);
1518 VEC_free (rtx, heap, worklist);
1519 VEC_free (rtx, heap, next);
1522 /* Add a CFI to update the running total of the size of arguments
1523 pushed onto the stack. */
1526 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1530 if (size == old_args_size)
1533 old_args_size = size;
1536 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1537 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1538 add_fde_cfi (label, cfi);
1541 /* Record a stack adjustment of OFFSET bytes. */
1544 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1546 if (cfa.reg == STACK_POINTER_REGNUM)
1547 cfa.offset += offset;
1549 if (cfa_store.reg == STACK_POINTER_REGNUM)
1550 cfa_store.offset += offset;
1552 if (ACCUMULATE_OUTGOING_ARGS)
1555 #ifndef STACK_GROWS_DOWNWARD
1559 args_size += offset;
1563 def_cfa_1 (label, &cfa);
1564 if (flag_asynchronous_unwind_tables)
1565 dwarf2out_args_size (label, args_size);
1568 /* Check INSN to see if it looks like a push or a stack adjustment, and
1569 make a note of it if it does. EH uses this information to find out
1570 how much extra space it needs to pop off the stack. */
1573 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1575 HOST_WIDE_INT offset;
1579 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1580 with this function. Proper support would require all frame-related
1581 insns to be marked, and to be able to handle saving state around
1582 epilogues textually in the middle of the function. */
1583 if (prologue_epilogue_contains (insn))
1586 /* If INSN is an instruction from target of an annulled branch, the
1587 effects are for the target only and so current argument size
1588 shouldn't change at all. */
1590 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1591 && INSN_FROM_TARGET_P (insn))
1594 /* If only calls can throw, and we have a frame pointer,
1595 save up adjustments until we see the CALL_INSN. */
1596 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1598 if (CALL_P (insn) && !after_p)
1600 /* Extract the size of the args from the CALL rtx itself. */
1601 insn = PATTERN (insn);
1602 if (GET_CODE (insn) == PARALLEL)
1603 insn = XVECEXP (insn, 0, 0);
1604 if (GET_CODE (insn) == SET)
1605 insn = SET_SRC (insn);
1606 gcc_assert (GET_CODE (insn) == CALL);
1607 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1612 if (CALL_P (insn) && !after_p)
1614 if (!flag_asynchronous_unwind_tables)
1615 dwarf2out_args_size ("", args_size);
1618 else if (BARRIER_P (insn))
1620 /* Don't call compute_barrier_args_size () if the only
1621 BARRIER is at the end of function. */
1622 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1623 compute_barrier_args_size ();
1624 if (barrier_args_size == NULL)
1628 offset = barrier_args_size[INSN_UID (insn)];
1633 offset -= args_size;
1634 #ifndef STACK_GROWS_DOWNWARD
1638 else if (GET_CODE (PATTERN (insn)) == SET)
1639 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1640 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1641 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1643 /* There may be stack adjustments inside compound insns. Search
1645 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1646 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1647 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1656 label = dwarf2out_cfi_label (false);
1657 dwarf2out_stack_adjust (offset, label);
1660 /* We delay emitting a register save until either (a) we reach the end
1661 of the prologue or (b) the register is clobbered. This clusters
1662 register saves so that there are fewer pc advances. */
1664 struct GTY(()) queued_reg_save {
1665 struct queued_reg_save *next;
1667 HOST_WIDE_INT cfa_offset;
1671 static GTY(()) struct queued_reg_save *queued_reg_saves;
1673 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1674 struct GTY(()) reg_saved_in_data {
1679 /* A list of registers saved in other registers.
1680 The list intentionally has a small maximum capacity of 4; if your
1681 port needs more than that, you might consider implementing a
1682 more efficient data structure. */
1683 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1684 static GTY(()) size_t num_regs_saved_in_regs;
1686 static const char *last_reg_save_label;
1688 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1689 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1692 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1694 struct queued_reg_save *q;
1696 /* Duplicates waste space, but it's also necessary to remove them
1697 for correctness, since the queue gets output in reverse
1699 for (q = queued_reg_saves; q != NULL; q = q->next)
1700 if (REGNO (q->reg) == REGNO (reg))
1705 q = ggc_alloc_queued_reg_save ();
1706 q->next = queued_reg_saves;
1707 queued_reg_saves = q;
1711 q->cfa_offset = offset;
1712 q->saved_reg = sreg;
1714 last_reg_save_label = label;
1717 /* Output all the entries in QUEUED_REG_SAVES. */
1720 dwarf2out_flush_queued_reg_saves (void)
1722 struct queued_reg_save *q;
1724 for (q = queued_reg_saves; q; q = q->next)
1727 unsigned int reg, sreg;
1729 for (i = 0; i < num_regs_saved_in_regs; i++)
1730 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1732 if (q->saved_reg && i == num_regs_saved_in_regs)
1734 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1735 num_regs_saved_in_regs++;
1737 if (i != num_regs_saved_in_regs)
1739 regs_saved_in_regs[i].orig_reg = q->reg;
1740 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1743 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1745 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1747 sreg = INVALID_REGNUM;
1748 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1751 queued_reg_saves = NULL;
1752 last_reg_save_label = NULL;
1755 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1756 location for? Or, does it clobber a register which we've previously
1757 said that some other register is saved in, and for which we now
1758 have a new location for? */
1761 clobbers_queued_reg_save (const_rtx insn)
1763 struct queued_reg_save *q;
1765 for (q = queued_reg_saves; q; q = q->next)
1768 if (modified_in_p (q->reg, insn))
1770 for (i = 0; i < num_regs_saved_in_regs; i++)
1771 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1772 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1779 /* Entry point for saving the first register into the second. */
1782 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1785 unsigned int regno, sregno;
1787 for (i = 0; i < num_regs_saved_in_regs; i++)
1788 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1790 if (i == num_regs_saved_in_regs)
1792 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1793 num_regs_saved_in_regs++;
1795 regs_saved_in_regs[i].orig_reg = reg;
1796 regs_saved_in_regs[i].saved_in_reg = sreg;
1798 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1799 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1800 reg_save (label, regno, sregno, 0);
1803 /* What register, if any, is currently saved in REG? */
1806 reg_saved_in (rtx reg)
1808 unsigned int regn = REGNO (reg);
1810 struct queued_reg_save *q;
1812 for (q = queued_reg_saves; q; q = q->next)
1813 if (q->saved_reg && regn == REGNO (q->saved_reg))
1816 for (i = 0; i < num_regs_saved_in_regs; i++)
1817 if (regs_saved_in_regs[i].saved_in_reg
1818 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1819 return regs_saved_in_regs[i].orig_reg;
1825 /* A temporary register holding an integral value used in adjusting SP
1826 or setting up the store_reg. The "offset" field holds the integer
1827 value, not an offset. */
1828 static dw_cfa_location cfa_temp;
1830 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1833 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1835 memset (&cfa, 0, sizeof (cfa));
1837 switch (GET_CODE (pat))
1840 cfa.reg = REGNO (XEXP (pat, 0));
1841 cfa.offset = INTVAL (XEXP (pat, 1));
1845 cfa.reg = REGNO (pat);
1850 pat = XEXP (pat, 0);
1851 if (GET_CODE (pat) == PLUS)
1853 cfa.base_offset = INTVAL (XEXP (pat, 1));
1854 pat = XEXP (pat, 0);
1856 cfa.reg = REGNO (pat);
1860 /* Recurse and define an expression. */
1864 def_cfa_1 (label, &cfa);
1867 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1870 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1874 gcc_assert (GET_CODE (pat) == SET);
1875 dest = XEXP (pat, 0);
1876 src = XEXP (pat, 1);
1878 switch (GET_CODE (src))
1881 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1882 cfa.offset -= INTVAL (XEXP (src, 1));
1892 cfa.reg = REGNO (dest);
1893 gcc_assert (cfa.indirect == 0);
1895 def_cfa_1 (label, &cfa);
1898 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1901 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1903 HOST_WIDE_INT offset;
1904 rtx src, addr, span;
1906 src = XEXP (set, 1);
1907 addr = XEXP (set, 0);
1908 gcc_assert (MEM_P (addr));
1909 addr = XEXP (addr, 0);
1911 /* As documented, only consider extremely simple addresses. */
1912 switch (GET_CODE (addr))
1915 gcc_assert (REGNO (addr) == cfa.reg);
1916 offset = -cfa.offset;
1919 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1920 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1926 span = targetm.dwarf_register_span (src);
1928 /* ??? We'd like to use queue_reg_save, but we need to come up with
1929 a different flushing heuristic for epilogues. */
1931 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1934 /* We have a PARALLEL describing where the contents of SRC live.
1935 Queue register saves for each piece of the PARALLEL. */
1938 HOST_WIDE_INT span_offset = offset;
1940 gcc_assert (GET_CODE (span) == PARALLEL);
1942 limit = XVECLEN (span, 0);
1943 for (par_index = 0; par_index < limit; par_index++)
1945 rtx elem = XVECEXP (span, 0, par_index);
1947 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1948 INVALID_REGNUM, span_offset);
1949 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1954 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1957 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1960 unsigned sregno, dregno;
1962 src = XEXP (set, 1);
1963 dest = XEXP (set, 0);
1966 sregno = DWARF_FRAME_RETURN_COLUMN;
1968 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1970 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1972 /* ??? We'd like to use queue_reg_save, but we need to come up with
1973 a different flushing heuristic for epilogues. */
1974 reg_save (label, sregno, dregno, 0);
1977 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1980 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
1982 rtx src, dest, span;
1983 dw_cfi_ref cfi = new_cfi ();
1985 dest = SET_DEST (set);
1986 src = SET_SRC (set);
1988 gcc_assert (REG_P (src));
1989 gcc_assert (MEM_P (dest));
1991 span = targetm.dwarf_register_span (src);
1994 cfi->dw_cfi_opc = DW_CFA_expression;
1995 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
1996 cfi->dw_cfi_oprnd2.dw_cfi_loc
1997 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
1998 VAR_INIT_STATUS_INITIALIZED);
2000 /* ??? We'd like to use queue_reg_save, were the interface different,
2001 and, as above, we could manage flushing for epilogues. */
2002 add_fde_cfi (label, cfi);
2005 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2008 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2010 dw_cfi_ref cfi = new_cfi ();
2011 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2013 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2014 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2016 add_fde_cfi (label, cfi);
2019 /* Record call frame debugging information for an expression EXPR,
2020 which either sets SP or FP (adjusting how we calculate the frame
2021 address) or saves a register to the stack or another register.
2022 LABEL indicates the address of EXPR.
2024 This function encodes a state machine mapping rtxes to actions on
2025 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2026 users need not read the source code.
2028 The High-Level Picture
2030 Changes in the register we use to calculate the CFA: Currently we
2031 assume that if you copy the CFA register into another register, we
2032 should take the other one as the new CFA register; this seems to
2033 work pretty well. If it's wrong for some target, it's simple
2034 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2036 Changes in the register we use for saving registers to the stack:
2037 This is usually SP, but not always. Again, we deduce that if you
2038 copy SP into another register (and SP is not the CFA register),
2039 then the new register is the one we will be using for register
2040 saves. This also seems to work.
2042 Register saves: There's not much guesswork about this one; if
2043 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2044 register save, and the register used to calculate the destination
2045 had better be the one we think we're using for this purpose.
2046 It's also assumed that a copy from a call-saved register to another
2047 register is saving that register if RTX_FRAME_RELATED_P is set on
2048 that instruction. If the copy is from a call-saved register to
2049 the *same* register, that means that the register is now the same
2050 value as in the caller.
2052 Except: If the register being saved is the CFA register, and the
2053 offset is nonzero, we are saving the CFA, so we assume we have to
2054 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2055 the intent is to save the value of SP from the previous frame.
2057 In addition, if a register has previously been saved to a different
2060 Invariants / Summaries of Rules
2062 cfa current rule for calculating the CFA. It usually
2063 consists of a register and an offset.
2064 cfa_store register used by prologue code to save things to the stack
2065 cfa_store.offset is the offset from the value of
2066 cfa_store.reg to the actual CFA
2067 cfa_temp register holding an integral value. cfa_temp.offset
2068 stores the value, which will be used to adjust the
2069 stack pointer. cfa_temp is also used like cfa_store,
2070 to track stores to the stack via fp or a temp reg.
2072 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2073 with cfa.reg as the first operand changes the cfa.reg and its
2074 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2077 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2078 expression yielding a constant. This sets cfa_temp.reg
2079 and cfa_temp.offset.
2081 Rule 5: Create a new register cfa_store used to save items to the
2084 Rules 10-14: Save a register to the stack. Define offset as the
2085 difference of the original location and cfa_store's
2086 location (or cfa_temp's location if cfa_temp is used).
2088 Rules 16-20: If AND operation happens on sp in prologue, we assume
2089 stack is realigned. We will use a group of DW_OP_XXX
2090 expressions to represent the location of the stored
2091 register instead of CFA+offset.
2095 "{a,b}" indicates a choice of a xor b.
2096 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2099 (set <reg1> <reg2>:cfa.reg)
2100 effects: cfa.reg = <reg1>
2101 cfa.offset unchanged
2102 cfa_temp.reg = <reg1>
2103 cfa_temp.offset = cfa.offset
2106 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2107 {<const_int>,<reg>:cfa_temp.reg}))
2108 effects: cfa.reg = sp if fp used
2109 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2110 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2111 if cfa_store.reg==sp
2114 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2115 effects: cfa.reg = fp
2116 cfa_offset += +/- <const_int>
2119 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2120 constraints: <reg1> != fp
2122 effects: cfa.reg = <reg1>
2123 cfa_temp.reg = <reg1>
2124 cfa_temp.offset = cfa.offset
2127 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2128 constraints: <reg1> != fp
2130 effects: cfa_store.reg = <reg1>
2131 cfa_store.offset = cfa.offset - cfa_temp.offset
2134 (set <reg> <const_int>)
2135 effects: cfa_temp.reg = <reg>
2136 cfa_temp.offset = <const_int>
2139 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2140 effects: cfa_temp.reg = <reg1>
2141 cfa_temp.offset |= <const_int>
2144 (set <reg> (high <exp>))
2148 (set <reg> (lo_sum <exp> <const_int>))
2149 effects: cfa_temp.reg = <reg>
2150 cfa_temp.offset = <const_int>
2153 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2154 effects: cfa_store.offset -= <const_int>
2155 cfa.offset = cfa_store.offset if cfa.reg == sp
2157 cfa.base_offset = -cfa_store.offset
2160 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2161 effects: cfa_store.offset += -/+ mode_size(mem)
2162 cfa.offset = cfa_store.offset if cfa.reg == sp
2164 cfa.base_offset = -cfa_store.offset
2167 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2170 effects: cfa.reg = <reg1>
2171 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2174 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2175 effects: cfa.reg = <reg1>
2176 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2179 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2180 effects: cfa.reg = <reg1>
2181 cfa.base_offset = -cfa_temp.offset
2182 cfa_temp.offset -= mode_size(mem)
2185 (set <reg> {unspec, unspec_volatile})
2186 effects: target-dependent
2189 (set sp (and: sp <const_int>))
2190 constraints: cfa_store.reg == sp
2191 effects: current_fde.stack_realign = 1
2192 cfa_store.offset = 0
2193 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2196 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2197 effects: cfa_store.offset += -/+ mode_size(mem)
2200 (set (mem ({pre_inc, pre_dec} sp)) fp)
2201 constraints: fde->stack_realign == 1
2202 effects: cfa_store.offset = 0
2203 cfa.reg != HARD_FRAME_POINTER_REGNUM
2206 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2207 constraints: fde->stack_realign == 1
2209 && cfa.indirect == 0
2210 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2211 effects: Use DW_CFA_def_cfa_expression to define cfa
2212 cfa.reg == fde->drap_reg */
2215 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2217 rtx src, dest, span;
2218 HOST_WIDE_INT offset;
2221 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2222 the PARALLEL independently. The first element is always processed if
2223 it is a SET. This is for backward compatibility. Other elements
2224 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2225 flag is set in them. */
2226 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2229 int limit = XVECLEN (expr, 0);
2232 /* PARALLELs have strict read-modify-write semantics, so we
2233 ought to evaluate every rvalue before changing any lvalue.
2234 It's cumbersome to do that in general, but there's an
2235 easy approximation that is enough for all current users:
2236 handle register saves before register assignments. */
2237 if (GET_CODE (expr) == PARALLEL)
2238 for (par_index = 0; par_index < limit; par_index++)
2240 elem = XVECEXP (expr, 0, par_index);
2241 if (GET_CODE (elem) == SET
2242 && MEM_P (SET_DEST (elem))
2243 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2244 dwarf2out_frame_debug_expr (elem, label);
2247 for (par_index = 0; par_index < limit; par_index++)
2249 elem = XVECEXP (expr, 0, par_index);
2250 if (GET_CODE (elem) == SET
2251 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2252 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2253 dwarf2out_frame_debug_expr (elem, label);
2254 else if (GET_CODE (elem) == SET
2256 && !RTX_FRAME_RELATED_P (elem))
2258 /* Stack adjustment combining might combine some post-prologue
2259 stack adjustment into a prologue stack adjustment. */
2260 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2263 dwarf2out_stack_adjust (offset, label);
2269 gcc_assert (GET_CODE (expr) == SET);
2271 src = SET_SRC (expr);
2272 dest = SET_DEST (expr);
2276 rtx rsi = reg_saved_in (src);
2281 fde = current_fde ();
2283 switch (GET_CODE (dest))
2286 switch (GET_CODE (src))
2288 /* Setting FP from SP. */
2290 if (cfa.reg == (unsigned) REGNO (src))
2293 /* Update the CFA rule wrt SP or FP. Make sure src is
2294 relative to the current CFA register.
2296 We used to require that dest be either SP or FP, but the
2297 ARM copies SP to a temporary register, and from there to
2298 FP. So we just rely on the backends to only set
2299 RTX_FRAME_RELATED_P on appropriate insns. */
2300 cfa.reg = REGNO (dest);
2301 cfa_temp.reg = cfa.reg;
2302 cfa_temp.offset = cfa.offset;
2306 /* Saving a register in a register. */
2307 gcc_assert (!fixed_regs [REGNO (dest)]
2308 /* For the SPARC and its register window. */
2309 || (DWARF_FRAME_REGNUM (REGNO (src))
2310 == DWARF_FRAME_RETURN_COLUMN));
2312 /* After stack is aligned, we can only save SP in FP
2313 if drap register is used. In this case, we have
2314 to restore stack pointer with the CFA value and we
2315 don't generate this DWARF information. */
2317 && fde->stack_realign
2318 && REGNO (src) == STACK_POINTER_REGNUM)
2319 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2320 && fde->drap_reg != INVALID_REGNUM
2321 && cfa.reg != REGNO (src));
2323 queue_reg_save (label, src, dest, 0);
2330 if (dest == stack_pointer_rtx)
2334 switch (GET_CODE (XEXP (src, 1)))
2337 offset = INTVAL (XEXP (src, 1));
2340 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2342 offset = cfa_temp.offset;
2348 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2350 /* Restoring SP from FP in the epilogue. */
2351 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2352 cfa.reg = STACK_POINTER_REGNUM;
2354 else if (GET_CODE (src) == LO_SUM)
2355 /* Assume we've set the source reg of the LO_SUM from sp. */
2358 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2360 if (GET_CODE (src) != MINUS)
2362 if (cfa.reg == STACK_POINTER_REGNUM)
2363 cfa.offset += offset;
2364 if (cfa_store.reg == STACK_POINTER_REGNUM)
2365 cfa_store.offset += offset;
2367 else if (dest == hard_frame_pointer_rtx)
2370 /* Either setting the FP from an offset of the SP,
2371 or adjusting the FP */
2372 gcc_assert (frame_pointer_needed);
2374 gcc_assert (REG_P (XEXP (src, 0))
2375 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2376 && CONST_INT_P (XEXP (src, 1)));
2377 offset = INTVAL (XEXP (src, 1));
2378 if (GET_CODE (src) != MINUS)
2380 cfa.offset += offset;
2381 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2385 gcc_assert (GET_CODE (src) != MINUS);
2388 if (REG_P (XEXP (src, 0))
2389 && REGNO (XEXP (src, 0)) == cfa.reg
2390 && CONST_INT_P (XEXP (src, 1)))
2392 /* Setting a temporary CFA register that will be copied
2393 into the FP later on. */
2394 offset = - INTVAL (XEXP (src, 1));
2395 cfa.offset += offset;
2396 cfa.reg = REGNO (dest);
2397 /* Or used to save regs to the stack. */
2398 cfa_temp.reg = cfa.reg;
2399 cfa_temp.offset = cfa.offset;
2403 else if (REG_P (XEXP (src, 0))
2404 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2405 && XEXP (src, 1) == stack_pointer_rtx)
2407 /* Setting a scratch register that we will use instead
2408 of SP for saving registers to the stack. */
2409 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2410 cfa_store.reg = REGNO (dest);
2411 cfa_store.offset = cfa.offset - cfa_temp.offset;
2415 else if (GET_CODE (src) == LO_SUM
2416 && CONST_INT_P (XEXP (src, 1)))
2418 cfa_temp.reg = REGNO (dest);
2419 cfa_temp.offset = INTVAL (XEXP (src, 1));
2428 cfa_temp.reg = REGNO (dest);
2429 cfa_temp.offset = INTVAL (src);
2434 gcc_assert (REG_P (XEXP (src, 0))
2435 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2436 && CONST_INT_P (XEXP (src, 1)));
2438 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2439 cfa_temp.reg = REGNO (dest);
2440 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2443 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2444 which will fill in all of the bits. */
2451 case UNSPEC_VOLATILE:
2452 gcc_assert (targetm.dwarf_handle_frame_unspec);
2453 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2458 /* If this AND operation happens on stack pointer in prologue,
2459 we assume the stack is realigned and we extract the
2461 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2463 /* We interpret reg_save differently with stack_realign set.
2464 Thus we must flush whatever we have queued first. */
2465 dwarf2out_flush_queued_reg_saves ();
2467 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2468 fde->stack_realign = 1;
2469 fde->stack_realignment = INTVAL (XEXP (src, 1));
2470 cfa_store.offset = 0;
2472 if (cfa.reg != STACK_POINTER_REGNUM
2473 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2474 fde->drap_reg = cfa.reg;
2482 def_cfa_1 (label, &cfa);
2487 /* Saving a register to the stack. Make sure dest is relative to the
2489 switch (GET_CODE (XEXP (dest, 0)))
2494 /* We can't handle variable size modifications. */
2495 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2497 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2499 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2500 && cfa_store.reg == STACK_POINTER_REGNUM);
2502 cfa_store.offset += offset;
2503 if (cfa.reg == STACK_POINTER_REGNUM)
2504 cfa.offset = cfa_store.offset;
2506 offset = -cfa_store.offset;
2512 offset = GET_MODE_SIZE (GET_MODE (dest));
2513 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2516 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2517 == STACK_POINTER_REGNUM)
2518 && cfa_store.reg == STACK_POINTER_REGNUM);
2520 cfa_store.offset += offset;
2522 /* Rule 18: If stack is aligned, we will use FP as a
2523 reference to represent the address of the stored
2526 && fde->stack_realign
2527 && src == hard_frame_pointer_rtx)
2529 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2530 cfa_store.offset = 0;
2533 if (cfa.reg == STACK_POINTER_REGNUM)
2534 cfa.offset = cfa_store.offset;
2536 offset = -cfa_store.offset;
2540 /* With an offset. */
2547 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2548 && REG_P (XEXP (XEXP (dest, 0), 0)));
2549 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2550 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2553 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2555 if (cfa_store.reg == (unsigned) regno)
2556 offset -= cfa_store.offset;
2559 gcc_assert (cfa_temp.reg == (unsigned) regno);
2560 offset -= cfa_temp.offset;
2566 /* Without an offset. */
2569 int regno = REGNO (XEXP (dest, 0));
2571 if (cfa_store.reg == (unsigned) regno)
2572 offset = -cfa_store.offset;
2575 gcc_assert (cfa_temp.reg == (unsigned) regno);
2576 offset = -cfa_temp.offset;
2583 gcc_assert (cfa_temp.reg
2584 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2585 offset = -cfa_temp.offset;
2586 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2594 /* If the source operand of this MEM operation is not a
2595 register, basically the source is return address. Here
2596 we only care how much stack grew and we don't save it. */
2600 if (REGNO (src) != STACK_POINTER_REGNUM
2601 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2602 && (unsigned) REGNO (src) == cfa.reg)
2604 /* We're storing the current CFA reg into the stack. */
2606 if (cfa.offset == 0)
2609 /* If stack is aligned, putting CFA reg into stack means
2610 we can no longer use reg + offset to represent CFA.
2611 Here we use DW_CFA_def_cfa_expression instead. The
2612 result of this expression equals to the original CFA
2615 && fde->stack_realign
2616 && cfa.indirect == 0
2617 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2619 dw_cfa_location cfa_exp;
2621 gcc_assert (fde->drap_reg == cfa.reg);
2623 cfa_exp.indirect = 1;
2624 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2625 cfa_exp.base_offset = offset;
2628 fde->drap_reg_saved = 1;
2630 def_cfa_1 (label, &cfa_exp);
2634 /* If the source register is exactly the CFA, assume
2635 we're saving SP like any other register; this happens
2637 def_cfa_1 (label, &cfa);
2638 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2643 /* Otherwise, we'll need to look in the stack to
2644 calculate the CFA. */
2645 rtx x = XEXP (dest, 0);
2649 gcc_assert (REG_P (x));
2651 cfa.reg = REGNO (x);
2652 cfa.base_offset = offset;
2654 def_cfa_1 (label, &cfa);
2659 def_cfa_1 (label, &cfa);
2661 span = targetm.dwarf_register_span (src);
2664 queue_reg_save (label, src, NULL_RTX, offset);
2667 /* We have a PARALLEL describing where the contents of SRC
2668 live. Queue register saves for each piece of the
2672 HOST_WIDE_INT span_offset = offset;
2674 gcc_assert (GET_CODE (span) == PARALLEL);
2676 limit = XVECLEN (span, 0);
2677 for (par_index = 0; par_index < limit; par_index++)
2679 rtx elem = XVECEXP (span, 0, par_index);
2681 queue_reg_save (label, elem, NULL_RTX, span_offset);
2682 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2693 /* Record call frame debugging information for INSN, which either
2694 sets SP or FP (adjusting how we calculate the frame address) or saves a
2695 register to the stack. If INSN is NULL_RTX, initialize our state.
2697 If AFTER_P is false, we're being called before the insn is emitted,
2698 otherwise after. Call instructions get invoked twice. */
2701 dwarf2out_frame_debug (rtx insn, bool after_p)
2705 bool handled_one = false;
2707 if (insn == NULL_RTX)
2711 /* Flush any queued register saves. */
2712 dwarf2out_flush_queued_reg_saves ();
2714 /* Set up state for generating call frame debug info. */
2717 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2719 cfa.reg = STACK_POINTER_REGNUM;
2722 cfa_temp.offset = 0;
2724 for (i = 0; i < num_regs_saved_in_regs; i++)
2726 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2727 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2729 num_regs_saved_in_regs = 0;
2731 if (barrier_args_size)
2733 XDELETEVEC (barrier_args_size);
2734 barrier_args_size = NULL;
2739 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2740 dwarf2out_flush_queued_reg_saves ();
2742 if (!RTX_FRAME_RELATED_P (insn))
2744 /* ??? This should be done unconditionally since stack adjustments
2745 matter if the stack pointer is not the CFA register anymore but
2746 is still used to save registers. */
2747 if (!ACCUMULATE_OUTGOING_ARGS)
2748 dwarf2out_notice_stack_adjust (insn, after_p);
2752 label = dwarf2out_cfi_label (false);
2753 any_cfis_emitted = false;
2755 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2756 switch (REG_NOTE_KIND (note))
2758 case REG_FRAME_RELATED_EXPR:
2759 insn = XEXP (note, 0);
2762 case REG_CFA_DEF_CFA:
2763 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2767 case REG_CFA_ADJUST_CFA:
2772 if (GET_CODE (n) == PARALLEL)
2773 n = XVECEXP (n, 0, 0);
2775 dwarf2out_frame_debug_adjust_cfa (n, label);
2779 case REG_CFA_OFFSET:
2782 n = single_set (insn);
2783 dwarf2out_frame_debug_cfa_offset (n, label);
2787 case REG_CFA_REGISTER:
2792 if (GET_CODE (n) == PARALLEL)
2793 n = XVECEXP (n, 0, 0);
2795 dwarf2out_frame_debug_cfa_register (n, label);
2799 case REG_CFA_EXPRESSION:
2802 n = single_set (insn);
2803 dwarf2out_frame_debug_cfa_expression (n, label);
2807 case REG_CFA_RESTORE:
2812 if (GET_CODE (n) == PARALLEL)
2813 n = XVECEXP (n, 0, 0);
2816 dwarf2out_frame_debug_cfa_restore (n, label);
2820 case REG_CFA_SET_VDRAP:
2824 dw_fde_ref fde = current_fde ();
2827 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2829 fde->vdrap_reg = REGNO (n);
2840 if (any_cfis_emitted)
2841 dwarf2out_flush_queued_reg_saves ();
2845 insn = PATTERN (insn);
2847 dwarf2out_frame_debug_expr (insn, label);
2849 /* Check again. A parallel can save and update the same register.
2850 We could probably check just once, here, but this is safer than
2851 removing the check above. */
2852 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2853 dwarf2out_flush_queued_reg_saves ();
2856 /* Determine if we need to save and restore CFI information around this
2857 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2858 we do need to save/restore, then emit the save now, and insert a
2859 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2862 dwarf2out_cfi_begin_epilogue (rtx insn)
2864 bool saw_frp = false;
2867 /* Scan forward to the return insn, noticing if there are possible
2868 frame related insns. */
2869 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2874 /* Look for both regular and sibcalls to end the block. */
2875 if (returnjump_p (i))
2877 if (CALL_P (i) && SIBLING_CALL_P (i))
2880 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2883 rtx seq = PATTERN (i);
2885 if (returnjump_p (XVECEXP (seq, 0, 0)))
2887 if (CALL_P (XVECEXP (seq, 0, 0))
2888 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2891 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2892 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2896 if (RTX_FRAME_RELATED_P (i))
2900 /* If the port doesn't emit epilogue unwind info, we don't need a
2901 save/restore pair. */
2905 /* Otherwise, search forward to see if the return insn was the last
2906 basic block of the function. If so, we don't need save/restore. */
2907 gcc_assert (i != NULL);
2908 i = next_real_insn (i);
2912 /* Insert the restore before that next real insn in the stream, and before
2913 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2914 properly nested. This should be after any label or alignment. This
2915 will be pushed into the CFI stream by the function below. */
2918 rtx p = PREV_INSN (i);
2921 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2925 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2927 emit_cfa_remember = true;
2929 /* And emulate the state save. */
2930 gcc_assert (!cfa_remember.in_use);
2932 cfa_remember.in_use = 1;
2935 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
2939 dwarf2out_frame_debug_restore_state (void)
2941 dw_cfi_ref cfi = new_cfi ();
2942 const char *label = dwarf2out_cfi_label (false);
2944 cfi->dw_cfi_opc = DW_CFA_restore_state;
2945 add_fde_cfi (label, cfi);
2947 gcc_assert (cfa_remember.in_use);
2949 cfa_remember.in_use = 0;
2952 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2953 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2954 (enum dwarf_call_frame_info cfi);
2956 static enum dw_cfi_oprnd_type
2957 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2962 case DW_CFA_GNU_window_save:
2963 case DW_CFA_remember_state:
2964 case DW_CFA_restore_state:
2965 return dw_cfi_oprnd_unused;
2967 case DW_CFA_set_loc:
2968 case DW_CFA_advance_loc1:
2969 case DW_CFA_advance_loc2:
2970 case DW_CFA_advance_loc4:
2971 case DW_CFA_MIPS_advance_loc8:
2972 return dw_cfi_oprnd_addr;
2975 case DW_CFA_offset_extended:
2976 case DW_CFA_def_cfa:
2977 case DW_CFA_offset_extended_sf:
2978 case DW_CFA_def_cfa_sf:
2979 case DW_CFA_restore:
2980 case DW_CFA_restore_extended:
2981 case DW_CFA_undefined:
2982 case DW_CFA_same_value:
2983 case DW_CFA_def_cfa_register:
2984 case DW_CFA_register:
2985 case DW_CFA_expression:
2986 return dw_cfi_oprnd_reg_num;
2988 case DW_CFA_def_cfa_offset:
2989 case DW_CFA_GNU_args_size:
2990 case DW_CFA_def_cfa_offset_sf:
2991 return dw_cfi_oprnd_offset;
2993 case DW_CFA_def_cfa_expression:
2994 return dw_cfi_oprnd_loc;
3001 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3002 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3003 (enum dwarf_call_frame_info cfi);
3005 static enum dw_cfi_oprnd_type
3006 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3010 case DW_CFA_def_cfa:
3011 case DW_CFA_def_cfa_sf:
3013 case DW_CFA_offset_extended_sf:
3014 case DW_CFA_offset_extended:
3015 return dw_cfi_oprnd_offset;
3017 case DW_CFA_register:
3018 return dw_cfi_oprnd_reg_num;
3020 case DW_CFA_expression:
3021 return dw_cfi_oprnd_loc;
3024 return dw_cfi_oprnd_unused;
3028 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3029 switch to the data section instead, and write out a synthetic start label
3030 for collect2 the first time around. */
3033 switch_to_eh_frame_section (bool back)
3037 #ifdef EH_FRAME_SECTION_NAME
3038 if (eh_frame_section == 0)
3042 if (EH_TABLES_CAN_BE_READ_ONLY)
3048 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3050 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3052 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3054 flags = ((! flag_pic
3055 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3056 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3057 && (per_encoding & 0x70) != DW_EH_PE_absptr
3058 && (per_encoding & 0x70) != DW_EH_PE_aligned
3059 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3060 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3061 ? 0 : SECTION_WRITE);
3064 flags = SECTION_WRITE;
3065 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3067 #endif /* EH_FRAME_SECTION_NAME */
3069 if (eh_frame_section)
3070 switch_to_section (eh_frame_section);
3073 /* We have no special eh_frame section. Put the information in
3074 the data section and emit special labels to guide collect2. */
3075 switch_to_section (data_section);
3079 label = get_file_function_name ("F");
3080 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3081 targetm.asm_out.globalize_label (asm_out_file,
3082 IDENTIFIER_POINTER (label));
3083 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3088 /* Switch [BACK] to the eh or debug frame table section, depending on
3092 switch_to_frame_table_section (int for_eh, bool back)
3095 switch_to_eh_frame_section (back);
3098 if (!debug_frame_section)
3099 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3100 SECTION_DEBUG, NULL);
3101 switch_to_section (debug_frame_section);
3105 /* Output a Call Frame Information opcode and its operand(s). */
3108 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3113 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3114 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3115 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3116 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3117 ((unsigned HOST_WIDE_INT)
3118 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3119 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3121 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3122 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3123 "DW_CFA_offset, column %#lx", r);
3124 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3125 dw2_asm_output_data_uleb128 (off, NULL);
3127 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3129 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3130 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3131 "DW_CFA_restore, column %#lx", r);
3135 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3136 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3138 switch (cfi->dw_cfi_opc)
3140 case DW_CFA_set_loc:
3142 dw2_asm_output_encoded_addr_rtx (
3143 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3144 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3147 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3148 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3149 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3152 case DW_CFA_advance_loc1:
3153 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3154 fde->dw_fde_current_label, NULL);
3155 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3158 case DW_CFA_advance_loc2:
3159 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3160 fde->dw_fde_current_label, NULL);
3161 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3164 case DW_CFA_advance_loc4:
3165 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3166 fde->dw_fde_current_label, NULL);
3167 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3170 case DW_CFA_MIPS_advance_loc8:
3171 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3172 fde->dw_fde_current_label, NULL);
3173 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3176 case DW_CFA_offset_extended:
3177 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3178 dw2_asm_output_data_uleb128 (r, NULL);
3179 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3180 dw2_asm_output_data_uleb128 (off, NULL);
3183 case DW_CFA_def_cfa:
3184 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3185 dw2_asm_output_data_uleb128 (r, NULL);
3186 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3189 case DW_CFA_offset_extended_sf:
3190 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3191 dw2_asm_output_data_uleb128 (r, NULL);
3192 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3193 dw2_asm_output_data_sleb128 (off, NULL);
3196 case DW_CFA_def_cfa_sf:
3197 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3198 dw2_asm_output_data_uleb128 (r, NULL);
3199 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3200 dw2_asm_output_data_sleb128 (off, NULL);
3203 case DW_CFA_restore_extended:
3204 case DW_CFA_undefined:
3205 case DW_CFA_same_value:
3206 case DW_CFA_def_cfa_register:
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3208 dw2_asm_output_data_uleb128 (r, NULL);
3211 case DW_CFA_register:
3212 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3213 dw2_asm_output_data_uleb128 (r, NULL);
3214 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3215 dw2_asm_output_data_uleb128 (r, NULL);
3218 case DW_CFA_def_cfa_offset:
3219 case DW_CFA_GNU_args_size:
3220 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3223 case DW_CFA_def_cfa_offset_sf:
3224 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3225 dw2_asm_output_data_sleb128 (off, NULL);
3228 case DW_CFA_GNU_window_save:
3231 case DW_CFA_def_cfa_expression:
3232 case DW_CFA_expression:
3233 output_cfa_loc (cfi);
3236 case DW_CFA_GNU_negative_offset_extended:
3237 /* Obsoleted by DW_CFA_offset_extended_sf. */
3246 /* Similar, but do it via assembler directives instead. */
3249 output_cfi_directive (dw_cfi_ref cfi)
3251 unsigned long r, r2;
3253 switch (cfi->dw_cfi_opc)
3255 case DW_CFA_advance_loc:
3256 case DW_CFA_advance_loc1:
3257 case DW_CFA_advance_loc2:
3258 case DW_CFA_advance_loc4:
3259 case DW_CFA_MIPS_advance_loc8:
3260 case DW_CFA_set_loc:
3261 /* Should only be created by add_fde_cfi in a code path not
3262 followed when emitting via directives. The assembler is
3263 going to take care of this for us. */
3267 case DW_CFA_offset_extended:
3268 case DW_CFA_offset_extended_sf:
3269 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3270 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3271 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3274 case DW_CFA_restore:
3275 case DW_CFA_restore_extended:
3276 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3277 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3280 case DW_CFA_undefined:
3281 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3282 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3285 case DW_CFA_same_value:
3286 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3287 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3290 case DW_CFA_def_cfa:
3291 case DW_CFA_def_cfa_sf:
3292 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3293 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3294 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3297 case DW_CFA_def_cfa_register:
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3299 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3302 case DW_CFA_register:
3303 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3304 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3305 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3308 case DW_CFA_def_cfa_offset:
3309 case DW_CFA_def_cfa_offset_sf:
3310 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3311 HOST_WIDE_INT_PRINT_DEC"\n",
3312 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3315 case DW_CFA_remember_state:
3316 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3318 case DW_CFA_restore_state:
3319 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3322 case DW_CFA_GNU_args_size:
3323 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3324 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3326 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3327 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3328 fputc ('\n', asm_out_file);
3331 case DW_CFA_GNU_window_save:
3332 fprintf (asm_out_file, "\t.cfi_window_save\n");
3335 case DW_CFA_def_cfa_expression:
3336 case DW_CFA_expression:
3337 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3338 output_cfa_loc_raw (cfi);
3339 fputc ('\n', asm_out_file);
3347 DEF_VEC_P (dw_cfi_ref);
3348 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3350 /* Output CFIs to bring current FDE to the same state as after executing
3351 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3352 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3353 other arguments to pass to output_cfi. */
3356 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3358 struct dw_cfi_struct cfi_buf;
3360 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3361 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3362 unsigned int len, idx;
3364 for (;; cfi = cfi->dw_cfi_next)
3365 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3367 case DW_CFA_advance_loc:
3368 case DW_CFA_advance_loc1:
3369 case DW_CFA_advance_loc2:
3370 case DW_CFA_advance_loc4:
3371 case DW_CFA_MIPS_advance_loc8:
3372 case DW_CFA_set_loc:
3373 /* All advances should be ignored. */
3375 case DW_CFA_remember_state:
3377 dw_cfi_ref args_size = cfi_args_size;
3379 /* Skip everything between .cfi_remember_state and
3380 .cfi_restore_state. */
3381 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3382 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3384 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3387 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3394 cfi_args_size = args_size;
3398 case DW_CFA_GNU_args_size:
3399 cfi_args_size = cfi;
3401 case DW_CFA_GNU_window_save:
3404 case DW_CFA_offset_extended:
3405 case DW_CFA_offset_extended_sf:
3406 case DW_CFA_restore:
3407 case DW_CFA_restore_extended:
3408 case DW_CFA_undefined:
3409 case DW_CFA_same_value:
3410 case DW_CFA_register:
3411 case DW_CFA_val_offset:
3412 case DW_CFA_val_offset_sf:
3413 case DW_CFA_expression:
3414 case DW_CFA_val_expression:
3415 case DW_CFA_GNU_negative_offset_extended:
3416 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3417 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3418 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3419 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3421 case DW_CFA_def_cfa:
3422 case DW_CFA_def_cfa_sf:
3423 case DW_CFA_def_cfa_expression:
3425 cfi_cfa_offset = cfi;
3427 case DW_CFA_def_cfa_register:
3430 case DW_CFA_def_cfa_offset:
3431 case DW_CFA_def_cfa_offset_sf:
3432 cfi_cfa_offset = cfi;
3435 gcc_assert (cfi == NULL);
3437 len = VEC_length (dw_cfi_ref, regs);
3438 for (idx = 0; idx < len; idx++)
3440 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3442 && cfi2->dw_cfi_opc != DW_CFA_restore
3443 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3446 output_cfi_directive (cfi2);
3448 output_cfi (cfi2, fde, for_eh);
3451 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3453 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3455 switch (cfi_cfa_offset->dw_cfi_opc)
3457 case DW_CFA_def_cfa_offset:
3458 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3459 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3461 case DW_CFA_def_cfa_offset_sf:
3462 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3463 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3465 case DW_CFA_def_cfa:
3466 case DW_CFA_def_cfa_sf:
3467 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3468 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3475 else if (cfi_cfa_offset)
3476 cfi_cfa = cfi_cfa_offset;
3480 output_cfi_directive (cfi_cfa);
3482 output_cfi (cfi_cfa, fde, for_eh);
3485 cfi_cfa_offset = NULL;
3487 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3490 output_cfi_directive (cfi_args_size);
3492 output_cfi (cfi_args_size, fde, for_eh);
3494 cfi_args_size = NULL;
3497 VEC_free (dw_cfi_ref, heap, regs);
3500 else if (do_cfi_asm)
3501 output_cfi_directive (cfi);
3503 output_cfi (cfi, fde, for_eh);
3510 /* Output one FDE. */
3513 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3514 char *section_start_label, int fde_encoding, char *augmentation,
3515 bool any_lsda_needed, int lsda_encoding)
3517 const char *begin, *end;
3518 static unsigned int j;
3519 char l1[20], l2[20];
3522 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3524 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3526 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3527 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3528 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3529 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3530 " indicating 64-bit DWARF extension");
3531 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3533 ASM_OUTPUT_LABEL (asm_out_file, l1);
3536 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3538 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3539 debug_frame_section, "FDE CIE offset");
3541 if (!fde->dw_fde_switched_sections)
3543 begin = fde->dw_fde_begin;
3544 end = fde->dw_fde_end;
3548 /* For the first section, prefer dw_fde_begin over
3549 dw_fde_{hot,cold}_section_label, as the latter
3550 might be separated from the real start of the
3551 function by alignment padding. */
3553 begin = fde->dw_fde_begin;
3554 else if (fde->dw_fde_switched_cold_to_hot)
3555 begin = fde->dw_fde_hot_section_label;
3557 begin = fde->dw_fde_unlikely_section_label;
3558 if (second ^ fde->dw_fde_switched_cold_to_hot)
3559 end = fde->dw_fde_unlikely_section_end_label;
3561 end = fde->dw_fde_hot_section_end_label;
3566 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3567 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3568 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3569 "FDE initial location");
3570 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3571 end, begin, "FDE address range");
3575 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3576 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3579 if (augmentation[0])
3581 if (any_lsda_needed)
3583 int size = size_of_encoded_value (lsda_encoding);
3585 if (lsda_encoding == DW_EH_PE_aligned)
3587 int offset = ( 4 /* Length */
3588 + 4 /* CIE offset */
3589 + 2 * size_of_encoded_value (fde_encoding)
3590 + 1 /* Augmentation size */ );
3591 int pad = -offset & (PTR_SIZE - 1);
3594 gcc_assert (size_of_uleb128 (size) == 1);
3597 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3599 if (fde->uses_eh_lsda)
3601 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3602 fde->funcdef_number);
3603 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3604 gen_rtx_SYMBOL_REF (Pmode, l1),
3606 "Language Specific Data Area");
3610 if (lsda_encoding == DW_EH_PE_aligned)
3611 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3612 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3613 "Language Specific Data Area (none)");
3617 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3620 /* Loop through the Call Frame Instructions associated with
3622 fde->dw_fde_current_label = begin;
3623 if (!fde->dw_fde_switched_sections)
3624 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3625 output_cfi (cfi, fde, for_eh);
3628 if (fde->dw_fde_switch_cfi)
3629 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3631 output_cfi (cfi, fde, for_eh);
3632 if (cfi == fde->dw_fde_switch_cfi)
3638 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3640 if (fde->dw_fde_switch_cfi)
3642 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3643 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3644 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3645 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3647 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3648 output_cfi (cfi, fde, for_eh);
3651 /* If we are to emit a ref/link from function bodies to their frame tables,
3652 do it now. This is typically performed to make sure that tables
3653 associated with functions are dragged with them and not discarded in
3654 garbage collecting links. We need to do this on a per function basis to
3655 cope with -ffunction-sections. */
3657 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3658 /* Switch to the function section, emit the ref to the tables, and
3659 switch *back* into the table section. */
3660 switch_to_section (function_section (fde->decl));
3661 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3662 switch_to_frame_table_section (for_eh, true);
3665 /* Pad the FDE out to an address sized boundary. */
3666 ASM_OUTPUT_ALIGN (asm_out_file,
3667 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3668 ASM_OUTPUT_LABEL (asm_out_file, l2);
3673 /* Return true if frame description entry FDE is needed for EH. */
3676 fde_needed_for_eh_p (dw_fde_ref fde)
3678 if (flag_asynchronous_unwind_tables)
3681 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3684 if (fde->uses_eh_lsda)
3687 /* If exceptions are enabled, we have collected nothrow info. */
3688 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3694 /* Output the call frame information used to record information
3695 that relates to calculating the frame pointer, and records the
3696 location of saved registers. */
3699 output_call_frame_info (int for_eh)
3704 char l1[20], l2[20], section_start_label[20];
3705 bool any_lsda_needed = false;
3706 char augmentation[6];
3707 int augmentation_size;
3708 int fde_encoding = DW_EH_PE_absptr;
3709 int per_encoding = DW_EH_PE_absptr;
3710 int lsda_encoding = DW_EH_PE_absptr;
3712 rtx personality = NULL;
3715 /* Don't emit a CIE if there won't be any FDEs. */
3716 if (fde_table_in_use == 0)
3719 /* Nothing to do if the assembler's doing it all. */
3720 if (dwarf2out_do_cfi_asm ())
3723 /* If we don't have any functions we'll want to unwind out of, don't emit
3724 any EH unwind information. If we make FDEs linkonce, we may have to
3725 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3726 want to avoid having an FDE kept around when the function it refers to
3727 is discarded. Example where this matters: a primary function template
3728 in C++ requires EH information, an explicit specialization doesn't. */
3731 bool any_eh_needed = false;
3733 for (i = 0; i < fde_table_in_use; i++)
3734 if (fde_table[i].uses_eh_lsda)
3735 any_eh_needed = any_lsda_needed = true;
3736 else if (fde_needed_for_eh_p (&fde_table[i]))
3737 any_eh_needed = true;
3738 else if (TARGET_USES_WEAK_UNWIND_INFO)
3739 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3746 /* We're going to be generating comments, so turn on app. */
3750 /* Switch to the proper frame section, first time. */
3751 switch_to_frame_table_section (for_eh, false);
3753 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3754 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3756 /* Output the CIE. */
3757 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3758 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3759 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3760 dw2_asm_output_data (4, 0xffffffff,
3761 "Initial length escape value indicating 64-bit DWARF extension");
3762 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3763 "Length of Common Information Entry");
3764 ASM_OUTPUT_LABEL (asm_out_file, l1);
3766 /* Now that the CIE pointer is PC-relative for EH,
3767 use 0 to identify the CIE. */
3768 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3769 (for_eh ? 0 : DWARF_CIE_ID),
3770 "CIE Identifier Tag");
3772 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3773 use CIE version 1, unless that would produce incorrect results
3774 due to overflowing the return register column. */
3775 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3777 if (return_reg >= 256 || dwarf_version > 2)
3779 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3781 augmentation[0] = 0;
3782 augmentation_size = 0;
3784 personality = current_unit_personality;
3790 z Indicates that a uleb128 is present to size the
3791 augmentation section.
3792 L Indicates the encoding (and thus presence) of
3793 an LSDA pointer in the FDE augmentation.
3794 R Indicates a non-default pointer encoding for
3796 P Indicates the presence of an encoding + language
3797 personality routine in the CIE augmentation. */
3799 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3800 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3801 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3803 p = augmentation + 1;
3807 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3808 assemble_external_libcall (personality);
3810 if (any_lsda_needed)
3813 augmentation_size += 1;
3815 if (fde_encoding != DW_EH_PE_absptr)
3818 augmentation_size += 1;
3820 if (p > augmentation + 1)
3822 augmentation[0] = 'z';
3826 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3827 if (personality && per_encoding == DW_EH_PE_aligned)
3829 int offset = ( 4 /* Length */
3831 + 1 /* CIE version */
3832 + strlen (augmentation) + 1 /* Augmentation */
3833 + size_of_uleb128 (1) /* Code alignment */
3834 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3836 + 1 /* Augmentation size */
3837 + 1 /* Personality encoding */ );
3838 int pad = -offset & (PTR_SIZE - 1);
3840 augmentation_size += pad;
3842 /* Augmentations should be small, so there's scarce need to
3843 iterate for a solution. Die if we exceed one uleb128 byte. */
3844 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3848 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3849 if (dw_cie_version >= 4)
3851 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3852 dw2_asm_output_data (1, 0, "CIE Segment Size");
3854 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3855 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3856 "CIE Data Alignment Factor");
3858 if (dw_cie_version == 1)
3859 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3861 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3863 if (augmentation[0])
3865 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3868 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3869 eh_data_format_name (per_encoding));
3870 dw2_asm_output_encoded_addr_rtx (per_encoding,
3875 if (any_lsda_needed)
3876 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3877 eh_data_format_name (lsda_encoding));
3879 if (fde_encoding != DW_EH_PE_absptr)
3880 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3881 eh_data_format_name (fde_encoding));
3884 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3885 output_cfi (cfi, NULL, for_eh);
3887 /* Pad the CIE out to an address sized boundary. */
3888 ASM_OUTPUT_ALIGN (asm_out_file,
3889 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3890 ASM_OUTPUT_LABEL (asm_out_file, l2);
3892 /* Loop through all of the FDE's. */
3893 for (i = 0; i < fde_table_in_use; i++)
3896 fde = &fde_table[i];
3898 /* Don't emit EH unwind info for leaf functions that don't need it. */
3899 if (for_eh && !fde_needed_for_eh_p (fde))
3902 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3903 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3904 augmentation, any_lsda_needed, lsda_encoding);
3907 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3908 dw2_asm_output_data (4, 0, "End of Table");
3909 #ifdef MIPS_DEBUGGING_INFO
3910 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3911 get a value of 0. Putting .align 0 after the label fixes it. */
3912 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3915 /* Turn off app to make assembly quicker. */
3920 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3923 dwarf2out_do_cfi_startproc (bool second)
3927 rtx personality = get_personality_function (current_function_decl);
3929 fprintf (asm_out_file, "\t.cfi_startproc\n");
3933 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3936 /* ??? The GAS support isn't entirely consistent. We have to
3937 handle indirect support ourselves, but PC-relative is done
3938 in the assembler. Further, the assembler can't handle any
3939 of the weirder relocation types. */
3940 if (enc & DW_EH_PE_indirect)
3941 ref = dw2_force_const_mem (ref, true);
3943 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
3944 output_addr_const (asm_out_file, ref);
3945 fputc ('\n', asm_out_file);
3948 if (crtl->uses_eh_lsda)
3952 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3953 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3954 current_function_funcdef_no);
3955 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3956 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3958 if (enc & DW_EH_PE_indirect)
3959 ref = dw2_force_const_mem (ref, true);
3961 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
3962 output_addr_const (asm_out_file, ref);
3963 fputc ('\n', asm_out_file);
3967 /* Output a marker (i.e. a label) for the beginning of a function, before
3971 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3972 const char *file ATTRIBUTE_UNUSED)
3974 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3979 current_function_func_begin_label = NULL;
3981 #ifdef TARGET_UNWIND_INFO
3982 /* ??? current_function_func_begin_label is also used by except.c
3983 for call-site information. We must emit this label if it might
3985 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3986 && ! dwarf2out_do_frame ())
3989 if (! dwarf2out_do_frame ())
3993 fnsec = function_section (current_function_decl);
3994 switch_to_section (fnsec);
3995 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3996 current_function_funcdef_no);
3997 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3998 current_function_funcdef_no);
3999 dup_label = xstrdup (label);
4000 current_function_func_begin_label = dup_label;
4002 #ifdef TARGET_UNWIND_INFO
4003 /* We can elide the fde allocation if we're not emitting debug info. */
4004 if (! dwarf2out_do_frame ())
4008 /* Expand the fde table if necessary. */
4009 if (fde_table_in_use == fde_table_allocated)
4011 fde_table_allocated += FDE_TABLE_INCREMENT;
4012 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4013 memset (fde_table + fde_table_in_use, 0,
4014 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4017 /* Record the FDE associated with this function. */
4018 current_funcdef_fde = fde_table_in_use;
4020 /* Add the new FDE at the end of the fde_table. */
4021 fde = &fde_table[fde_table_in_use++];
4022 fde->decl = current_function_decl;
4023 fde->dw_fde_begin = dup_label;
4024 fde->dw_fde_current_label = dup_label;
4025 fde->dw_fde_hot_section_label = NULL;
4026 fde->dw_fde_hot_section_end_label = NULL;
4027 fde->dw_fde_unlikely_section_label = NULL;
4028 fde->dw_fde_unlikely_section_end_label = NULL;
4029 fde->dw_fde_switched_sections = 0;
4030 fde->dw_fde_switched_cold_to_hot = 0;
4031 fde->dw_fde_end = NULL;
4032 fde->dw_fde_vms_end_prologue = NULL;
4033 fde->dw_fde_vms_begin_epilogue = NULL;
4034 fde->dw_fde_cfi = NULL;
4035 fde->dw_fde_switch_cfi = NULL;
4036 fde->funcdef_number = current_function_funcdef_no;
4037 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4038 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4039 fde->nothrow = crtl->nothrow;
4040 fde->drap_reg = INVALID_REGNUM;
4041 fde->vdrap_reg = INVALID_REGNUM;
4042 if (flag_reorder_blocks_and_partition)
4044 section *unlikelysec;
4045 if (first_function_block_is_cold)
4046 fde->in_std_section = 1;
4049 = (fnsec == text_section
4050 || (cold_text_section && fnsec == cold_text_section));
4051 unlikelysec = unlikely_text_section ();
4052 fde->cold_in_std_section
4053 = (unlikelysec == text_section
4054 || (cold_text_section && unlikelysec == cold_text_section));
4059 = (fnsec == text_section
4060 || (cold_text_section && fnsec == cold_text_section));
4061 fde->cold_in_std_section = 0;
4064 args_size = old_args_size = 0;
4066 /* We only want to output line number information for the genuine dwarf2
4067 prologue case, not the eh frame case. */
4068 #ifdef DWARF2_DEBUGGING_INFO
4070 dwarf2out_source_line (line, file, 0, true);
4073 if (dwarf2out_do_cfi_asm ())
4074 dwarf2out_do_cfi_startproc (false);
4077 rtx personality = get_personality_function (current_function_decl);
4078 if (!current_unit_personality)
4079 current_unit_personality = personality;
4081 /* We cannot keep a current personality per function as without CFI
4082 asm, at the point where we emit the CFI data, there is no current
4083 function anymore. */
4084 if (personality && current_unit_personality != personality)
4085 sorry ("multiple EH personalities are supported only with assemblers "
4086 "supporting .cfi_personality directive");
4090 /* Output a marker (i.e. a label) for the end of the generated code
4091 for a function prologue. This gets called *after* the prologue code has
4095 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4096 const char *file ATTRIBUTE_UNUSED)
4099 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4101 /* Output a label to mark the endpoint of the code generated for this
4103 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4104 current_function_funcdef_no);
4105 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4106 current_function_funcdef_no);
4107 fde = &fde_table[fde_table_in_use - 1];
4108 fde->dw_fde_vms_end_prologue = xstrdup (label);
4111 /* Output a marker (i.e. a label) for the beginning of the generated code
4112 for a function epilogue. This gets called *before* the prologue code has
4116 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4117 const char *file ATTRIBUTE_UNUSED)
4120 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4122 fde = &fde_table[fde_table_in_use - 1];
4123 if (fde->dw_fde_vms_begin_epilogue)
4126 /* Output a label to mark the endpoint of the code generated for this
4128 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4129 current_function_funcdef_no);
4130 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4131 current_function_funcdef_no);
4132 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4135 /* Output a marker (i.e. a label) for the absolute end of the generated code
4136 for a function definition. This gets called *after* the epilogue code has
4140 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4141 const char *file ATTRIBUTE_UNUSED)
4144 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4146 last_var_location_insn = NULL_RTX;
4148 if (dwarf2out_do_cfi_asm ())
4149 fprintf (asm_out_file, "\t.cfi_endproc\n");
4151 /* Output a label to mark the endpoint of the code generated for this
4153 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4154 current_function_funcdef_no);
4155 ASM_OUTPUT_LABEL (asm_out_file, label);
4156 fde = current_fde ();
4157 gcc_assert (fde != NULL);
4158 fde->dw_fde_end = xstrdup (label);
4162 dwarf2out_frame_init (void)
4164 /* Allocate the initial hunk of the fde_table. */
4165 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4166 fde_table_allocated = FDE_TABLE_INCREMENT;
4167 fde_table_in_use = 0;
4169 /* Generate the CFA instructions common to all FDE's. Do it now for the
4170 sake of lookup_cfa. */
4172 /* On entry, the Canonical Frame Address is at SP. */
4173 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4175 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4176 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4180 dwarf2out_frame_finish (void)
4182 /* Output call frame information. */
4183 if (DWARF2_FRAME_INFO)
4184 output_call_frame_info (0);
4186 #ifndef TARGET_UNWIND_INFO
4187 /* Output another copy for the unwinder. */
4188 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4189 output_call_frame_info (1);
4193 /* Note that the current function section is being used for code. */
4196 dwarf2out_note_section_used (void)
4198 section *sec = current_function_section ();
4199 if (sec == text_section)
4200 text_section_used = true;
4201 else if (sec == cold_text_section)
4202 cold_text_section_used = true;
4206 dwarf2out_switch_text_section (void)
4208 dw_fde_ref fde = current_fde ();
4210 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4212 fde->dw_fde_switched_sections = 1;
4213 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4215 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4216 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4217 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4218 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4219 have_multiple_function_sections = true;
4221 /* Reset the current label on switching text sections, so that we
4222 don't attempt to advance_loc4 between labels in different sections. */
4223 fde->dw_fde_current_label = NULL;
4225 /* There is no need to mark used sections when not debugging. */
4226 if (cold_text_section != NULL)
4227 dwarf2out_note_section_used ();
4229 if (dwarf2out_do_cfi_asm ())
4230 fprintf (asm_out_file, "\t.cfi_endproc\n");
4232 /* Now do the real section switch. */
4233 switch_to_section (current_function_section ());
4235 if (dwarf2out_do_cfi_asm ())
4237 dwarf2out_do_cfi_startproc (true);
4238 /* As this is a different FDE, insert all current CFI instructions
4240 output_cfis (fde->dw_fde_cfi, true, fde, true);
4244 dw_cfi_ref cfi = fde->dw_fde_cfi;
4246 cfi = fde->dw_fde_cfi;
4248 while (cfi->dw_cfi_next != NULL)
4249 cfi = cfi->dw_cfi_next;
4250 fde->dw_fde_switch_cfi = cfi;
4254 /* And now, the subset of the debugging information support code necessary
4255 for emitting location expressions. */
4257 /* Data about a single source file. */
4258 struct GTY(()) dwarf_file_data {
4259 const char * filename;
4263 typedef struct dw_val_struct *dw_val_ref;
4264 typedef struct die_struct *dw_die_ref;
4265 typedef const struct die_struct *const_dw_die_ref;
4266 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4267 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4269 typedef struct GTY(()) deferred_locations_struct
4273 } deferred_locations;
4275 DEF_VEC_O(deferred_locations);
4276 DEF_VEC_ALLOC_O(deferred_locations,gc);
4278 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4280 DEF_VEC_P(dw_die_ref);
4281 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4283 /* Each DIE may have a series of attribute/value pairs. Values
4284 can take on several forms. The forms that are used in this
4285 implementation are listed below. */
4290 dw_val_class_offset,
4292 dw_val_class_loc_list,
4293 dw_val_class_range_list,
4295 dw_val_class_unsigned_const,
4296 dw_val_class_const_double,
4299 dw_val_class_die_ref,
4300 dw_val_class_fde_ref,
4301 dw_val_class_lbl_id,
4302 dw_val_class_lineptr,
4304 dw_val_class_macptr,
4307 dw_val_class_decl_ref,
4308 dw_val_class_vms_delta
4311 /* Describe a floating point constant value, or a vector constant value. */
4313 typedef struct GTY(()) dw_vec_struct {
4314 unsigned char * GTY((length ("%h.length"))) array;
4320 /* The dw_val_node describes an attribute's value, as it is
4321 represented internally. */
4323 typedef struct GTY(()) dw_val_struct {
4324 enum dw_val_class val_class;
4325 union dw_val_struct_union
4327 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4328 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4329 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4330 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4331 HOST_WIDE_INT GTY ((default)) val_int;
4332 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4333 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4334 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4335 struct dw_val_die_union
4339 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4340 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4341 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4342 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4343 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4344 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4345 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4346 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4347 struct dw_val_vms_delta_union
4351 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4353 GTY ((desc ("%1.val_class"))) v;
4357 /* Locations in memory are described using a sequence of stack machine
4360 typedef struct GTY(()) dw_loc_descr_struct {
4361 dw_loc_descr_ref dw_loc_next;
4362 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4363 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4364 from DW_OP_addr with a dtp-relative symbol relocation. */
4365 unsigned int dtprel : 1;
4367 dw_val_node dw_loc_oprnd1;
4368 dw_val_node dw_loc_oprnd2;
4372 /* Location lists are ranges + location descriptions for that range,
4373 so you can track variables that are in different places over
4374 their entire life. */
4375 typedef struct GTY(()) dw_loc_list_struct {
4376 dw_loc_list_ref dw_loc_next;
4377 const char *begin; /* Label for begin address of range */
4378 const char *end; /* Label for end address of range */
4379 char *ll_symbol; /* Label for beginning of location list.
4380 Only on head of list */
4381 const char *section; /* Section this loclist is relative to */
4382 dw_loc_descr_ref expr;
4385 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4387 /* Convert a DWARF stack opcode into its string name. */
4390 dwarf_stack_op_name (unsigned int op)
4395 return "DW_OP_addr";
4397 return "DW_OP_deref";
4399 return "DW_OP_const1u";
4401 return "DW_OP_const1s";
4403 return "DW_OP_const2u";
4405 return "DW_OP_const2s";
4407 return "DW_OP_const4u";
4409 return "DW_OP_const4s";
4411 return "DW_OP_const8u";
4413 return "DW_OP_const8s";
4415 return "DW_OP_constu";
4417 return "DW_OP_consts";
4421 return "DW_OP_drop";
4423 return "DW_OP_over";
4425 return "DW_OP_pick";
4427 return "DW_OP_swap";
4431 return "DW_OP_xderef";
4439 return "DW_OP_minus";
4451 return "DW_OP_plus";
4452 case DW_OP_plus_uconst:
4453 return "DW_OP_plus_uconst";
4459 return "DW_OP_shra";
4477 return "DW_OP_skip";
4479 return "DW_OP_lit0";
4481 return "DW_OP_lit1";
4483 return "DW_OP_lit2";
4485 return "DW_OP_lit3";
4487 return "DW_OP_lit4";
4489 return "DW_OP_lit5";
4491 return "DW_OP_lit6";
4493 return "DW_OP_lit7";
4495 return "DW_OP_lit8";
4497 return "DW_OP_lit9";
4499 return "DW_OP_lit10";
4501 return "DW_OP_lit11";
4503 return "DW_OP_lit12";
4505 return "DW_OP_lit13";
4507 return "DW_OP_lit14";
4509 return "DW_OP_lit15";
4511 return "DW_OP_lit16";
4513 return "DW_OP_lit17";
4515 return "DW_OP_lit18";
4517 return "DW_OP_lit19";
4519 return "DW_OP_lit20";
4521 return "DW_OP_lit21";
4523 return "DW_OP_lit22";
4525 return "DW_OP_lit23";
4527 return "DW_OP_lit24";
4529 return "DW_OP_lit25";
4531 return "DW_OP_lit26";
4533 return "DW_OP_lit27";
4535 return "DW_OP_lit28";
4537 return "DW_OP_lit29";
4539 return "DW_OP_lit30";
4541 return "DW_OP_lit31";
4543 return "DW_OP_reg0";
4545 return "DW_OP_reg1";
4547 return "DW_OP_reg2";
4549 return "DW_OP_reg3";
4551 return "DW_OP_reg4";
4553 return "DW_OP_reg5";
4555 return "DW_OP_reg6";
4557 return "DW_OP_reg7";
4559 return "DW_OP_reg8";
4561 return "DW_OP_reg9";
4563 return "DW_OP_reg10";
4565 return "DW_OP_reg11";
4567 return "DW_OP_reg12";
4569 return "DW_OP_reg13";
4571 return "DW_OP_reg14";
4573 return "DW_OP_reg15";
4575 return "DW_OP_reg16";
4577 return "DW_OP_reg17";
4579 return "DW_OP_reg18";
4581 return "DW_OP_reg19";
4583 return "DW_OP_reg20";
4585 return "DW_OP_reg21";
4587 return "DW_OP_reg22";
4589 return "DW_OP_reg23";
4591 return "DW_OP_reg24";
4593 return "DW_OP_reg25";
4595 return "DW_OP_reg26";
4597 return "DW_OP_reg27";
4599 return "DW_OP_reg28";
4601 return "DW_OP_reg29";
4603 return "DW_OP_reg30";
4605 return "DW_OP_reg31";
4607 return "DW_OP_breg0";
4609 return "DW_OP_breg1";
4611 return "DW_OP_breg2";
4613 return "DW_OP_breg3";
4615 return "DW_OP_breg4";
4617 return "DW_OP_breg5";
4619 return "DW_OP_breg6";
4621 return "DW_OP_breg7";
4623 return "DW_OP_breg8";
4625 return "DW_OP_breg9";
4627 return "DW_OP_breg10";
4629 return "DW_OP_breg11";
4631 return "DW_OP_breg12";
4633 return "DW_OP_breg13";
4635 return "DW_OP_breg14";
4637 return "DW_OP_breg15";
4639 return "DW_OP_breg16";
4641 return "DW_OP_breg17";
4643 return "DW_OP_breg18";
4645 return "DW_OP_breg19";
4647 return "DW_OP_breg20";
4649 return "DW_OP_breg21";
4651 return "DW_OP_breg22";
4653 return "DW_OP_breg23";
4655 return "DW_OP_breg24";
4657 return "DW_OP_breg25";
4659 return "DW_OP_breg26";
4661 return "DW_OP_breg27";
4663 return "DW_OP_breg28";
4665 return "DW_OP_breg29";
4667 return "DW_OP_breg30";
4669 return "DW_OP_breg31";
4671 return "DW_OP_regx";
4673 return "DW_OP_fbreg";
4675 return "DW_OP_bregx";
4677 return "DW_OP_piece";
4678 case DW_OP_deref_size:
4679 return "DW_OP_deref_size";
4680 case DW_OP_xderef_size:
4681 return "DW_OP_xderef_size";
4685 case DW_OP_push_object_address:
4686 return "DW_OP_push_object_address";
4688 return "DW_OP_call2";
4690 return "DW_OP_call4";
4691 case DW_OP_call_ref:
4692 return "DW_OP_call_ref";
4693 case DW_OP_implicit_value:
4694 return "DW_OP_implicit_value";
4695 case DW_OP_stack_value:
4696 return "DW_OP_stack_value";
4697 case DW_OP_form_tls_address:
4698 return "DW_OP_form_tls_address";
4699 case DW_OP_call_frame_cfa:
4700 return "DW_OP_call_frame_cfa";
4701 case DW_OP_bit_piece:
4702 return "DW_OP_bit_piece";
4704 case DW_OP_GNU_push_tls_address:
4705 return "DW_OP_GNU_push_tls_address";
4706 case DW_OP_GNU_uninit:
4707 return "DW_OP_GNU_uninit";
4708 case DW_OP_GNU_encoded_addr:
4709 return "DW_OP_GNU_encoded_addr";
4710 case DW_OP_GNU_implicit_pointer:
4711 return "DW_OP_GNU_implicit_pointer";
4714 return "OP_<unknown>";
4718 /* Return a pointer to a newly allocated location description. Location
4719 descriptions are simple expression terms that can be strung
4720 together to form more complicated location (address) descriptions. */
4722 static inline dw_loc_descr_ref
4723 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4724 unsigned HOST_WIDE_INT oprnd2)
4726 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4728 descr->dw_loc_opc = op;
4729 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4730 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4731 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4732 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4737 /* Return a pointer to a newly allocated location description for
4740 static inline dw_loc_descr_ref
4741 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4744 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4747 return new_loc_descr (DW_OP_bregx, reg, offset);
4750 /* Add a location description term to a location description expression. */
4753 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4755 dw_loc_descr_ref *d;
4757 /* Find the end of the chain. */
4758 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4764 /* Add a constant OFFSET to a location expression. */
4767 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4769 dw_loc_descr_ref loc;
4772 gcc_assert (*list_head != NULL);
4777 /* Find the end of the chain. */
4778 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4782 if (loc->dw_loc_opc == DW_OP_fbreg
4783 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4784 p = &loc->dw_loc_oprnd1.v.val_int;
4785 else if (loc->dw_loc_opc == DW_OP_bregx)
4786 p = &loc->dw_loc_oprnd2.v.val_int;
4788 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4789 offset. Don't optimize if an signed integer overflow would happen. */
4791 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4792 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4795 else if (offset > 0)
4796 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4800 loc->dw_loc_next = int_loc_descriptor (-offset);
4801 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4805 /* Add a constant OFFSET to a location list. */
4808 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4811 for (d = list_head; d != NULL; d = d->dw_loc_next)
4812 loc_descr_plus_const (&d->expr, offset);
4815 #define DWARF_REF_SIZE \
4816 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4818 /* Return the size of a location descriptor. */
4820 static unsigned long
4821 size_of_loc_descr (dw_loc_descr_ref loc)
4823 unsigned long size = 1;
4825 switch (loc->dw_loc_opc)
4828 size += DWARF2_ADDR_SIZE;
4847 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4850 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4855 case DW_OP_plus_uconst:
4856 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4894 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4897 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4900 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4903 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4904 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4907 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4909 case DW_OP_bit_piece:
4910 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4911 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4913 case DW_OP_deref_size:
4914 case DW_OP_xderef_size:
4923 case DW_OP_call_ref:
4924 size += DWARF_REF_SIZE;
4926 case DW_OP_implicit_value:
4927 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4928 + loc->dw_loc_oprnd1.v.val_unsigned;
4930 case DW_OP_GNU_implicit_pointer:
4931 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4940 /* Return the size of a series of location descriptors. */
4942 static unsigned long
4943 size_of_locs (dw_loc_descr_ref loc)
4948 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4949 field, to avoid writing to a PCH file. */
4950 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4952 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4954 size += size_of_loc_descr (l);
4959 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4961 l->dw_loc_addr = size;
4962 size += size_of_loc_descr (l);
4968 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4969 static void get_ref_die_offset_label (char *, dw_die_ref);
4971 /* Output location description stack opcode's operands (if any). */
4974 output_loc_operands (dw_loc_descr_ref loc)
4976 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4977 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4979 switch (loc->dw_loc_opc)
4981 #ifdef DWARF2_DEBUGGING_INFO
4984 dw2_asm_output_data (2, val1->v.val_int, NULL);
4989 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
4990 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
4992 fputc ('\n', asm_out_file);
4997 dw2_asm_output_data (4, val1->v.val_int, NULL);
5002 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5003 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5005 fputc ('\n', asm_out_file);
5010 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5011 dw2_asm_output_data (8, val1->v.val_int, NULL);
5018 gcc_assert (val1->val_class == dw_val_class_loc);
5019 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5021 dw2_asm_output_data (2, offset, NULL);
5024 case DW_OP_implicit_value:
5025 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5026 switch (val2->val_class)
5028 case dw_val_class_const:
5029 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5031 case dw_val_class_vec:
5033 unsigned int elt_size = val2->v.val_vec.elt_size;
5034 unsigned int len = val2->v.val_vec.length;
5038 if (elt_size > sizeof (HOST_WIDE_INT))
5043 for (i = 0, p = val2->v.val_vec.array;
5046 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5047 "fp or vector constant word %u", i);
5050 case dw_val_class_const_double:
5052 unsigned HOST_WIDE_INT first, second;
5054 if (WORDS_BIG_ENDIAN)
5056 first = val2->v.val_double.high;
5057 second = val2->v.val_double.low;
5061 first = val2->v.val_double.low;
5062 second = val2->v.val_double.high;
5064 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5066 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5070 case dw_val_class_addr:
5071 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5072 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5087 case DW_OP_implicit_value:
5088 /* We currently don't make any attempt to make sure these are
5089 aligned properly like we do for the main unwind info, so
5090 don't support emitting things larger than a byte if we're
5091 only doing unwinding. */
5096 dw2_asm_output_data (1, val1->v.val_int, NULL);
5099 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5102 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5105 dw2_asm_output_data (1, val1->v.val_int, NULL);
5107 case DW_OP_plus_uconst:
5108 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5142 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5145 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5148 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5151 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5152 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5155 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5157 case DW_OP_bit_piece:
5158 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5159 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5161 case DW_OP_deref_size:
5162 case DW_OP_xderef_size:
5163 dw2_asm_output_data (1, val1->v.val_int, NULL);
5169 if (targetm.asm_out.output_dwarf_dtprel)
5171 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5174 fputc ('\n', asm_out_file);
5181 #ifdef DWARF2_DEBUGGING_INFO
5182 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5189 case DW_OP_GNU_implicit_pointer:
5191 char label[MAX_ARTIFICIAL_LABEL_BYTES
5192 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5193 gcc_assert (val1->val_class == dw_val_class_die_ref);
5194 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5195 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5196 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5201 /* Other codes have no operands. */
5206 /* Output a sequence of location operations. */
5209 output_loc_sequence (dw_loc_descr_ref loc)
5211 for (; loc != NULL; loc = loc->dw_loc_next)
5213 /* Output the opcode. */
5214 dw2_asm_output_data (1, loc->dw_loc_opc,
5215 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5217 /* Output the operand(s) (if any). */
5218 output_loc_operands (loc);
5222 /* Output location description stack opcode's operands (if any).
5223 The output is single bytes on a line, suitable for .cfi_escape. */
5226 output_loc_operands_raw (dw_loc_descr_ref loc)
5228 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5229 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5231 switch (loc->dw_loc_opc)
5234 case DW_OP_implicit_value:
5235 /* We cannot output addresses in .cfi_escape, only bytes. */
5241 case DW_OP_deref_size:
5242 case DW_OP_xderef_size:
5243 fputc (',', asm_out_file);
5244 dw2_asm_output_data_raw (1, val1->v.val_int);
5249 fputc (',', asm_out_file);
5250 dw2_asm_output_data_raw (2, val1->v.val_int);
5255 fputc (',', asm_out_file);
5256 dw2_asm_output_data_raw (4, val1->v.val_int);
5261 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5262 fputc (',', asm_out_file);
5263 dw2_asm_output_data_raw (8, val1->v.val_int);
5271 gcc_assert (val1->val_class == dw_val_class_loc);
5272 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5274 fputc (',', asm_out_file);
5275 dw2_asm_output_data_raw (2, offset);
5280 case DW_OP_plus_uconst:
5283 fputc (',', asm_out_file);
5284 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5287 case DW_OP_bit_piece:
5288 fputc (',', asm_out_file);
5289 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5290 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5327 fputc (',', asm_out_file);
5328 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5332 fputc (',', asm_out_file);
5333 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5334 fputc (',', asm_out_file);
5335 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5338 case DW_OP_GNU_implicit_pointer:
5343 /* Other codes have no operands. */
5349 output_loc_sequence_raw (dw_loc_descr_ref loc)
5353 /* Output the opcode. */
5354 fprintf (asm_out_file, "%#x", loc->dw_loc_opc);
5355 output_loc_operands_raw (loc);
5357 if (!loc->dw_loc_next)
5359 loc = loc->dw_loc_next;
5361 fputc (',', asm_out_file);
5365 /* This routine will generate the correct assembly data for a location
5366 description based on a cfi entry with a complex address. */
5369 output_cfa_loc (dw_cfi_ref cfi)
5371 dw_loc_descr_ref loc;
5374 if (cfi->dw_cfi_opc == DW_CFA_expression)
5376 dw2_asm_output_data (1, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
5377 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5380 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5382 /* Output the size of the block. */
5383 size = size_of_locs (loc);
5384 dw2_asm_output_data_uleb128 (size, NULL);
5386 /* Now output the operations themselves. */
5387 output_loc_sequence (loc);
5390 /* Similar, but used for .cfi_escape. */
5393 output_cfa_loc_raw (dw_cfi_ref cfi)
5395 dw_loc_descr_ref loc;
5398 if (cfi->dw_cfi_opc == DW_CFA_expression)
5400 fprintf (asm_out_file, "%#x,", cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
5401 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5404 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5406 /* Output the size of the block. */
5407 size = size_of_locs (loc);
5408 dw2_asm_output_data_uleb128_raw (size);
5409 fputc (',', asm_out_file);
5411 /* Now output the operations themselves. */
5412 output_loc_sequence_raw (loc);
5415 /* This function builds a dwarf location descriptor sequence from a
5416 dw_cfa_location, adding the given OFFSET to the result of the
5419 static struct dw_loc_descr_struct *
5420 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5422 struct dw_loc_descr_struct *head, *tmp;
5424 offset += cfa->offset;
5428 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5429 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5430 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5431 add_loc_descr (&head, tmp);
5434 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5435 add_loc_descr (&head, tmp);
5439 head = new_reg_loc_descr (cfa->reg, offset);
5444 /* This function builds a dwarf location descriptor sequence for
5445 the address at OFFSET from the CFA when stack is aligned to
5448 static struct dw_loc_descr_struct *
5449 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5451 struct dw_loc_descr_struct *head;
5452 unsigned int dwarf_fp
5453 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5455 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5456 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5458 head = new_reg_loc_descr (dwarf_fp, 0);
5459 add_loc_descr (&head, int_loc_descriptor (alignment));
5460 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5461 loc_descr_plus_const (&head, offset);
5464 head = new_reg_loc_descr (dwarf_fp, offset);
5468 /* This function fills in aa dw_cfa_location structure from a dwarf location
5469 descriptor sequence. */
5472 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5474 struct dw_loc_descr_struct *ptr;
5476 cfa->base_offset = 0;
5480 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5482 enum dwarf_location_atom op = ptr->dw_loc_opc;
5518 cfa->reg = op - DW_OP_reg0;
5521 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5555 cfa->reg = op - DW_OP_breg0;
5556 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5559 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5560 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5565 case DW_OP_plus_uconst:
5566 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5569 internal_error ("DW_LOC_OP %s not implemented",
5570 dwarf_stack_op_name (ptr->dw_loc_opc));
5575 /* And now, the support for symbolic debugging information. */
5577 /* .debug_str support. */
5578 static int output_indirect_string (void **, void *);
5580 static void dwarf2out_init (const char *);
5581 static void dwarf2out_finish (const char *);
5582 static void dwarf2out_assembly_start (void);
5583 static void dwarf2out_define (unsigned int, const char *);
5584 static void dwarf2out_undef (unsigned int, const char *);
5585 static void dwarf2out_start_source_file (unsigned, const char *);
5586 static void dwarf2out_end_source_file (unsigned);
5587 static void dwarf2out_function_decl (tree);
5588 static void dwarf2out_begin_block (unsigned, unsigned);
5589 static void dwarf2out_end_block (unsigned, unsigned);
5590 static bool dwarf2out_ignore_block (const_tree);
5591 static void dwarf2out_global_decl (tree);
5592 static void dwarf2out_type_decl (tree, int);
5593 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5594 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5596 static void dwarf2out_abstract_function (tree);
5597 static void dwarf2out_var_location (rtx);
5598 static void dwarf2out_direct_call (tree);
5599 static void dwarf2out_virtual_call_token (tree, int);
5600 static void dwarf2out_copy_call_info (rtx, rtx);
5601 static void dwarf2out_virtual_call (int);
5602 static void dwarf2out_begin_function (tree);
5603 static void dwarf2out_set_name (tree, tree);
5605 /* The debug hooks structure. */
5607 const struct gcc_debug_hooks dwarf2_debug_hooks =
5611 dwarf2out_assembly_start,
5614 dwarf2out_start_source_file,
5615 dwarf2out_end_source_file,
5616 dwarf2out_begin_block,
5617 dwarf2out_end_block,
5618 dwarf2out_ignore_block,
5619 dwarf2out_source_line,
5620 dwarf2out_begin_prologue,
5621 #if VMS_DEBUGGING_INFO
5622 dwarf2out_vms_end_prologue,
5623 dwarf2out_vms_begin_epilogue,
5625 debug_nothing_int_charstar,
5626 debug_nothing_int_charstar,
5628 dwarf2out_end_epilogue,
5629 dwarf2out_begin_function,
5630 debug_nothing_int, /* end_function */
5631 dwarf2out_function_decl, /* function_decl */
5632 dwarf2out_global_decl,
5633 dwarf2out_type_decl, /* type_decl */
5634 dwarf2out_imported_module_or_decl,
5635 debug_nothing_tree, /* deferred_inline_function */
5636 /* The DWARF 2 backend tries to reduce debugging bloat by not
5637 emitting the abstract description of inline functions until
5638 something tries to reference them. */
5639 dwarf2out_abstract_function, /* outlining_inline_function */
5640 debug_nothing_rtx, /* label */
5641 debug_nothing_int, /* handle_pch */
5642 dwarf2out_var_location,
5643 dwarf2out_switch_text_section,
5644 dwarf2out_direct_call,
5645 dwarf2out_virtual_call_token,
5646 dwarf2out_copy_call_info,
5647 dwarf2out_virtual_call,
5649 1 /* start_end_main_source_file */
5652 /* NOTE: In the comments in this file, many references are made to
5653 "Debugging Information Entries". This term is abbreviated as `DIE'
5654 throughout the remainder of this file. */
5656 /* An internal representation of the DWARF output is built, and then
5657 walked to generate the DWARF debugging info. The walk of the internal
5658 representation is done after the entire program has been compiled.
5659 The types below are used to describe the internal representation. */
5661 /* Various DIE's use offsets relative to the beginning of the
5662 .debug_info section to refer to each other. */
5664 typedef long int dw_offset;
5666 /* Define typedefs here to avoid circular dependencies. */
5668 typedef struct dw_attr_struct *dw_attr_ref;
5669 typedef struct dw_line_info_struct *dw_line_info_ref;
5670 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5671 typedef struct pubname_struct *pubname_ref;
5672 typedef struct dw_ranges_struct *dw_ranges_ref;
5673 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5674 typedef struct comdat_type_struct *comdat_type_node_ref;
5676 /* Each entry in the line_info_table maintains the file and
5677 line number associated with the label generated for that
5678 entry. The label gives the PC value associated with
5679 the line number entry. */
5681 typedef struct GTY(()) dw_line_info_struct {
5682 unsigned long dw_file_num;
5683 unsigned long dw_line_num;
5687 /* Line information for functions in separate sections; each one gets its
5689 typedef struct GTY(()) dw_separate_line_info_struct {
5690 unsigned long dw_file_num;
5691 unsigned long dw_line_num;
5692 unsigned long function;
5694 dw_separate_line_info_entry;
5696 /* Each DIE attribute has a field specifying the attribute kind,
5697 a link to the next attribute in the chain, and an attribute value.
5698 Attributes are typically linked below the DIE they modify. */
5700 typedef struct GTY(()) dw_attr_struct {
5701 enum dwarf_attribute dw_attr;
5702 dw_val_node dw_attr_val;
5706 DEF_VEC_O(dw_attr_node);
5707 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5709 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5710 The children of each node form a circular list linked by
5711 die_sib. die_child points to the node *before* the "first" child node. */
5713 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5714 union die_symbol_or_type_node
5716 char * GTY ((tag ("0"))) die_symbol;
5717 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5719 GTY ((desc ("dwarf_version >= 4"))) die_id;
5720 VEC(dw_attr_node,gc) * die_attr;
5721 dw_die_ref die_parent;
5722 dw_die_ref die_child;
5724 dw_die_ref die_definition; /* ref from a specification to its definition */
5725 dw_offset die_offset;
5726 unsigned long die_abbrev;
5728 /* Die is used and must not be pruned as unused. */
5729 int die_perennial_p;
5730 unsigned int decl_id;
5731 enum dwarf_tag die_tag;
5735 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5736 #define FOR_EACH_CHILD(die, c, expr) do { \
5737 c = die->die_child; \
5741 } while (c != die->die_child); \
5744 /* The pubname structure */
5746 typedef struct GTY(()) pubname_struct {
5752 DEF_VEC_O(pubname_entry);
5753 DEF_VEC_ALLOC_O(pubname_entry, gc);
5755 struct GTY(()) dw_ranges_struct {
5756 /* If this is positive, it's a block number, otherwise it's a
5757 bitwise-negated index into dw_ranges_by_label. */
5761 struct GTY(()) dw_ranges_by_label_struct {
5766 /* The comdat type node structure. */
5767 typedef struct GTY(()) comdat_type_struct
5769 dw_die_ref root_die;
5770 dw_die_ref type_die;
5771 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5772 struct comdat_type_struct *next;
5776 /* The limbo die list structure. */
5777 typedef struct GTY(()) limbo_die_struct {
5780 struct limbo_die_struct *next;
5784 typedef struct GTY(()) skeleton_chain_struct
5788 struct skeleton_chain_struct *parent;
5790 skeleton_chain_node;
5792 /* How to start an assembler comment. */
5793 #ifndef ASM_COMMENT_START
5794 #define ASM_COMMENT_START ";#"
5797 /* Define a macro which returns nonzero for a TYPE_DECL which was
5798 implicitly generated for a tagged type.
5800 Note that unlike the gcc front end (which generates a NULL named
5801 TYPE_DECL node for each complete tagged type, each array type, and
5802 each function type node created) the g++ front end generates a
5803 _named_ TYPE_DECL node for each tagged type node created.
5804 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5805 generate a DW_TAG_typedef DIE for them. */
5807 #define TYPE_DECL_IS_STUB(decl) \
5808 (DECL_NAME (decl) == NULL_TREE \
5809 || (DECL_ARTIFICIAL (decl) \
5810 && is_tagged_type (TREE_TYPE (decl)) \
5811 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5812 /* This is necessary for stub decls that \
5813 appear in nested inline functions. */ \
5814 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5815 && (decl_ultimate_origin (decl) \
5816 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5818 /* Information concerning the compilation unit's programming
5819 language, and compiler version. */
5821 /* Fixed size portion of the DWARF compilation unit header. */
5822 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5823 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5825 /* Fixed size portion of the DWARF comdat type unit header. */
5826 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5827 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5828 + DWARF_OFFSET_SIZE)
5830 /* Fixed size portion of public names info. */
5831 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5833 /* Fixed size portion of the address range info. */
5834 #define DWARF_ARANGES_HEADER_SIZE \
5835 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5836 DWARF2_ADDR_SIZE * 2) \
5837 - DWARF_INITIAL_LENGTH_SIZE)
5839 /* Size of padding portion in the address range info. It must be
5840 aligned to twice the pointer size. */
5841 #define DWARF_ARANGES_PAD_SIZE \
5842 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5843 DWARF2_ADDR_SIZE * 2) \
5844 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5846 /* Use assembler line directives if available. */
5847 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5848 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5849 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5851 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5855 /* Minimum line offset in a special line info. opcode.
5856 This value was chosen to give a reasonable range of values. */
5857 #define DWARF_LINE_BASE -10
5859 /* First special line opcode - leave room for the standard opcodes. */
5860 #define DWARF_LINE_OPCODE_BASE 10
5862 /* Range of line offsets in a special line info. opcode. */
5863 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5865 /* Flag that indicates the initial value of the is_stmt_start flag.
5866 In the present implementation, we do not mark any lines as
5867 the beginning of a source statement, because that information
5868 is not made available by the GCC front-end. */
5869 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5871 /* Maximum number of operations per instruction bundle. */
5872 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5873 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5876 /* This location is used by calc_die_sizes() to keep track
5877 the offset of each DIE within the .debug_info section. */
5878 static unsigned long next_die_offset;
5880 /* Record the root of the DIE's built for the current compilation unit. */
5881 static GTY(()) dw_die_ref comp_unit_die;
5883 /* A list of type DIEs that have been separated into comdat sections. */
5884 static GTY(()) comdat_type_node *comdat_type_list;
5886 /* A list of DIEs with a NULL parent waiting to be relocated. */
5887 static GTY(()) limbo_die_node *limbo_die_list;
5889 /* A list of DIEs for which we may have to generate
5890 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5891 static GTY(()) limbo_die_node *deferred_asm_name;
5893 /* Filenames referenced by this compilation unit. */
5894 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5896 /* A hash table of references to DIE's that describe declarations.
5897 The key is a DECL_UID() which is a unique number identifying each decl. */
5898 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5900 /* A hash table of references to DIE's that describe COMMON blocks.
5901 The key is DECL_UID() ^ die_parent. */
5902 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5904 typedef struct GTY(()) die_arg_entry_struct {
5909 DEF_VEC_O(die_arg_entry);
5910 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5912 /* Node of the variable location list. */
5913 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5914 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
5915 EXPR_LIST chain. For small bitsizes, bitsize is encoded
5916 in mode of the EXPR_LIST node and first EXPR_LIST operand
5917 is either NOTE_INSN_VAR_LOCATION for a piece with a known
5918 location or NULL for padding. For larger bitsizes,
5919 mode is 0 and first operand is a CONCAT with bitsize
5920 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
5921 NULL as second operand. */
5923 const char * GTY (()) label;
5924 struct var_loc_node * GTY (()) next;
5927 /* Variable location list. */
5928 struct GTY (()) var_loc_list_def {
5929 struct var_loc_node * GTY (()) first;
5931 /* Pointer to the last but one or last element of the
5932 chained list. If the list is empty, both first and
5933 last are NULL, if the list contains just one node
5934 or the last node certainly is not redundant, it points
5935 to the last node, otherwise points to the last but one.
5936 Do not mark it for GC because it is marked through the chain. */
5937 struct var_loc_node * GTY ((skip ("%h"))) last;
5939 /* DECL_UID of the variable decl. */
5940 unsigned int decl_id;
5942 typedef struct var_loc_list_def var_loc_list;
5945 /* Table of decl location linked lists. */
5946 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5948 /* A pointer to the base of a list of references to DIE's that
5949 are uniquely identified by their tag, presence/absence of
5950 children DIE's, and list of attribute/value pairs. */
5951 static GTY((length ("abbrev_die_table_allocated")))
5952 dw_die_ref *abbrev_die_table;
5954 /* Number of elements currently allocated for abbrev_die_table. */
5955 static GTY(()) unsigned abbrev_die_table_allocated;
5957 /* Number of elements in type_die_table currently in use. */
5958 static GTY(()) unsigned abbrev_die_table_in_use;
5960 /* Size (in elements) of increments by which we may expand the
5961 abbrev_die_table. */
5962 #define ABBREV_DIE_TABLE_INCREMENT 256
5964 /* A pointer to the base of a table that contains line information
5965 for each source code line in .text in the compilation unit. */
5966 static GTY((length ("line_info_table_allocated")))
5967 dw_line_info_ref line_info_table;
5969 /* Number of elements currently allocated for line_info_table. */
5970 static GTY(()) unsigned line_info_table_allocated;
5972 /* Number of elements in line_info_table currently in use. */
5973 static GTY(()) unsigned line_info_table_in_use;
5975 /* A pointer to the base of a table that contains line information
5976 for each source code line outside of .text in the compilation unit. */
5977 static GTY ((length ("separate_line_info_table_allocated")))
5978 dw_separate_line_info_ref separate_line_info_table;
5980 /* Number of elements currently allocated for separate_line_info_table. */
5981 static GTY(()) unsigned separate_line_info_table_allocated;
5983 /* Number of elements in separate_line_info_table currently in use. */
5984 static GTY(()) unsigned separate_line_info_table_in_use;
5986 /* Size (in elements) of increments by which we may expand the
5988 #define LINE_INFO_TABLE_INCREMENT 1024
5990 /* A pointer to the base of a table that contains a list of publicly
5991 accessible names. */
5992 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5994 /* A pointer to the base of a table that contains a list of publicly
5995 accessible types. */
5996 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5998 /* Array of dies for which we should generate .debug_arange info. */
5999 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
6001 /* Number of elements currently allocated for arange_table. */
6002 static GTY(()) unsigned arange_table_allocated;
6004 /* Number of elements in arange_table currently in use. */
6005 static GTY(()) unsigned arange_table_in_use;
6007 /* Size (in elements) of increments by which we may expand the
6009 #define ARANGE_TABLE_INCREMENT 64
6011 /* Array of dies for which we should generate .debug_ranges info. */
6012 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6014 /* Number of elements currently allocated for ranges_table. */
6015 static GTY(()) unsigned ranges_table_allocated;
6017 /* Number of elements in ranges_table currently in use. */
6018 static GTY(()) unsigned ranges_table_in_use;
6020 /* Array of pairs of labels referenced in ranges_table. */
6021 static GTY ((length ("ranges_by_label_allocated")))
6022 dw_ranges_by_label_ref ranges_by_label;
6024 /* Number of elements currently allocated for ranges_by_label. */
6025 static GTY(()) unsigned ranges_by_label_allocated;
6027 /* Number of elements in ranges_by_label currently in use. */
6028 static GTY(()) unsigned ranges_by_label_in_use;
6030 /* Size (in elements) of increments by which we may expand the
6032 #define RANGES_TABLE_INCREMENT 64
6034 /* Whether we have location lists that need outputting */
6035 static GTY(()) bool have_location_lists;
6037 /* Unique label counter. */
6038 static GTY(()) unsigned int loclabel_num;
6040 /* Unique label counter for point-of-call tables. */
6041 static GTY(()) unsigned int poc_label_num;
6043 /* The direct call table structure. */
6045 typedef struct GTY(()) dcall_struct {
6046 unsigned int poc_label_num;
6048 dw_die_ref targ_die;
6052 DEF_VEC_O(dcall_entry);
6053 DEF_VEC_ALLOC_O(dcall_entry, gc);
6055 /* The virtual call table structure. */
6057 typedef struct GTY(()) vcall_struct {
6058 unsigned int poc_label_num;
6059 unsigned int vtable_slot;
6063 DEF_VEC_O(vcall_entry);
6064 DEF_VEC_ALLOC_O(vcall_entry, gc);
6066 /* Pointers to the direct and virtual call tables. */
6067 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6068 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6070 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6072 struct GTY (()) vcall_insn {
6074 unsigned int vtable_slot;
6077 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6079 /* Record whether the function being analyzed contains inlined functions. */
6080 static int current_function_has_inlines;
6082 /* The last file entry emitted by maybe_emit_file(). */
6083 static GTY(()) struct dwarf_file_data * last_emitted_file;
6085 /* Number of internal labels generated by gen_internal_sym(). */
6086 static GTY(()) int label_num;
6088 /* Cached result of previous call to lookup_filename. */
6089 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6091 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6093 /* Offset from the "steady-state frame pointer" to the frame base,
6094 within the current function. */
6095 static HOST_WIDE_INT frame_pointer_fb_offset;
6097 /* Forward declarations for functions defined in this file. */
6099 static int is_pseudo_reg (const_rtx);
6100 static tree type_main_variant (tree);
6101 static int is_tagged_type (const_tree);
6102 static const char *dwarf_tag_name (unsigned);
6103 static const char *dwarf_attr_name (unsigned);
6104 static const char *dwarf_form_name (unsigned);
6105 static tree decl_ultimate_origin (const_tree);
6106 static tree decl_class_context (tree);
6107 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6108 static inline enum dw_val_class AT_class (dw_attr_ref);
6109 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6110 static inline unsigned AT_flag (dw_attr_ref);
6111 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6112 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6113 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6114 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6115 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6116 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6117 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6118 unsigned int, unsigned char *);
6119 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6120 static hashval_t debug_str_do_hash (const void *);
6121 static int debug_str_eq (const void *, const void *);
6122 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6123 static inline const char *AT_string (dw_attr_ref);
6124 static enum dwarf_form AT_string_form (dw_attr_ref);
6125 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6126 static void add_AT_specification (dw_die_ref, dw_die_ref);
6127 static inline dw_die_ref AT_ref (dw_attr_ref);
6128 static inline int AT_ref_external (dw_attr_ref);
6129 static inline void set_AT_ref_external (dw_attr_ref, int);
6130 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6131 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6132 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6133 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6135 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6136 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6137 static inline rtx AT_addr (dw_attr_ref);
6138 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6139 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6140 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6141 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6142 unsigned HOST_WIDE_INT);
6143 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6145 static inline const char *AT_lbl (dw_attr_ref);
6146 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6147 static const char *get_AT_low_pc (dw_die_ref);
6148 static const char *get_AT_hi_pc (dw_die_ref);
6149 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6150 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6151 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6152 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6153 static bool is_cxx (void);
6154 static bool is_fortran (void);
6155 static bool is_ada (void);
6156 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6157 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6158 static void add_child_die (dw_die_ref, dw_die_ref);
6159 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6160 static dw_die_ref lookup_type_die (tree);
6161 static void equate_type_number_to_die (tree, dw_die_ref);
6162 static hashval_t decl_die_table_hash (const void *);
6163 static int decl_die_table_eq (const void *, const void *);
6164 static dw_die_ref lookup_decl_die (tree);
6165 static hashval_t common_block_die_table_hash (const void *);
6166 static int common_block_die_table_eq (const void *, const void *);
6167 static hashval_t decl_loc_table_hash (const void *);
6168 static int decl_loc_table_eq (const void *, const void *);
6169 static var_loc_list *lookup_decl_loc (const_tree);
6170 static void equate_decl_number_to_die (tree, dw_die_ref);
6171 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6172 static void print_spaces (FILE *);
6173 static void print_die (dw_die_ref, FILE *);
6174 static void print_dwarf_line_table (FILE *);
6175 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6176 static dw_die_ref pop_compile_unit (dw_die_ref);
6177 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6178 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6179 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6180 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6181 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6182 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6183 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6184 struct md5_ctx *, int *);
6185 struct checksum_attributes;
6186 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6187 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6188 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6189 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6190 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6191 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6192 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6193 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6194 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6195 static void compute_section_prefix (dw_die_ref);
6196 static int is_type_die (dw_die_ref);
6197 static int is_comdat_die (dw_die_ref);
6198 static int is_symbol_die (dw_die_ref);
6199 static void assign_symbol_names (dw_die_ref);
6200 static void break_out_includes (dw_die_ref);
6201 static int is_declaration_die (dw_die_ref);
6202 static int should_move_die_to_comdat (dw_die_ref);
6203 static dw_die_ref clone_as_declaration (dw_die_ref);
6204 static dw_die_ref clone_die (dw_die_ref);
6205 static dw_die_ref clone_tree (dw_die_ref);
6206 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6207 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6208 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6209 static dw_die_ref generate_skeleton (dw_die_ref);
6210 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6212 static void break_out_comdat_types (dw_die_ref);
6213 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6214 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6215 static void copy_decls_for_unworthy_types (dw_die_ref);
6217 static hashval_t htab_cu_hash (const void *);
6218 static int htab_cu_eq (const void *, const void *);
6219 static void htab_cu_del (void *);
6220 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6221 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6222 static void add_sibling_attributes (dw_die_ref);
6223 static void build_abbrev_table (dw_die_ref);
6224 static void output_location_lists (dw_die_ref);
6225 static int constant_size (unsigned HOST_WIDE_INT);
6226 static unsigned long size_of_die (dw_die_ref);
6227 static void calc_die_sizes (dw_die_ref);
6228 static void mark_dies (dw_die_ref);
6229 static void unmark_dies (dw_die_ref);
6230 static void unmark_all_dies (dw_die_ref);
6231 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6232 static unsigned long size_of_aranges (void);
6233 static enum dwarf_form value_format (dw_attr_ref);
6234 static void output_value_format (dw_attr_ref);
6235 static void output_abbrev_section (void);
6236 static void output_die_symbol (dw_die_ref);
6237 static void output_die (dw_die_ref);
6238 static void output_compilation_unit_header (void);
6239 static void output_comp_unit (dw_die_ref, int);
6240 static void output_comdat_type_unit (comdat_type_node *);
6241 static const char *dwarf2_name (tree, int);
6242 static void add_pubname (tree, dw_die_ref);
6243 static void add_pubname_string (const char *, dw_die_ref);
6244 static void add_pubtype (tree, dw_die_ref);
6245 static void output_pubnames (VEC (pubname_entry,gc) *);
6246 static void add_arange (tree, dw_die_ref);
6247 static void output_aranges (void);
6248 static unsigned int add_ranges_num (int);
6249 static unsigned int add_ranges (const_tree);
6250 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6252 static void output_ranges (void);
6253 static void output_line_info (void);
6254 static void output_file_names (void);
6255 static dw_die_ref base_type_die (tree);
6256 static int is_base_type (tree);
6257 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6258 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6259 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6260 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6261 static int type_is_enum (const_tree);
6262 static unsigned int dbx_reg_number (const_rtx);
6263 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6264 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6265 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6266 enum var_init_status);
6267 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6268 enum var_init_status);
6269 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6270 enum var_init_status);
6271 static int is_based_loc (const_rtx);
6272 static int resolve_one_addr (rtx *, void *);
6273 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6274 enum var_init_status);
6275 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6276 enum var_init_status);
6277 static dw_loc_list_ref loc_list_from_tree (tree, int);
6278 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6279 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6280 static tree field_type (const_tree);
6281 static unsigned int simple_type_align_in_bits (const_tree);
6282 static unsigned int simple_decl_align_in_bits (const_tree);
6283 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6284 static HOST_WIDE_INT field_byte_offset (const_tree);
6285 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6287 static void add_data_member_location_attribute (dw_die_ref, tree);
6288 static bool add_const_value_attribute (dw_die_ref, rtx);
6289 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6290 static void insert_double (double_int, unsigned char *);
6291 static void insert_float (const_rtx, unsigned char *);
6292 static rtx rtl_for_decl_location (tree);
6293 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6294 enum dwarf_attribute);
6295 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6296 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6297 static void add_name_attribute (dw_die_ref, const char *);
6298 static void add_comp_dir_attribute (dw_die_ref);
6299 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6300 static void add_subscript_info (dw_die_ref, tree, bool);
6301 static void add_byte_size_attribute (dw_die_ref, tree);
6302 static void add_bit_offset_attribute (dw_die_ref, tree);
6303 static void add_bit_size_attribute (dw_die_ref, tree);
6304 static void add_prototyped_attribute (dw_die_ref, tree);
6305 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6306 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6307 static void add_src_coords_attributes (dw_die_ref, tree);
6308 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6309 static void push_decl_scope (tree);
6310 static void pop_decl_scope (void);
6311 static dw_die_ref scope_die_for (tree, dw_die_ref);
6312 static inline int local_scope_p (dw_die_ref);
6313 static inline int class_scope_p (dw_die_ref);
6314 static inline int class_or_namespace_scope_p (dw_die_ref);
6315 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6316 static void add_calling_convention_attribute (dw_die_ref, tree);
6317 static const char *type_tag (const_tree);
6318 static tree member_declared_type (const_tree);
6320 static const char *decl_start_label (tree);
6322 static void gen_array_type_die (tree, dw_die_ref);
6323 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6325 static void gen_entry_point_die (tree, dw_die_ref);
6327 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6328 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6329 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6330 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6331 static void gen_formal_types_die (tree, dw_die_ref);
6332 static void gen_subprogram_die (tree, dw_die_ref);
6333 static void gen_variable_die (tree, tree, dw_die_ref);
6334 static void gen_const_die (tree, dw_die_ref);
6335 static void gen_label_die (tree, dw_die_ref);
6336 static void gen_lexical_block_die (tree, dw_die_ref, int);
6337 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6338 static void gen_field_die (tree, dw_die_ref);
6339 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6340 static dw_die_ref gen_compile_unit_die (const char *);
6341 static void gen_inheritance_die (tree, tree, dw_die_ref);
6342 static void gen_member_die (tree, dw_die_ref);
6343 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6344 enum debug_info_usage);
6345 static void gen_subroutine_type_die (tree, dw_die_ref);
6346 static void gen_typedef_die (tree, dw_die_ref);
6347 static void gen_type_die (tree, dw_die_ref);
6348 static void gen_block_die (tree, dw_die_ref, int);
6349 static void decls_for_scope (tree, dw_die_ref, int);
6350 static int is_redundant_typedef (const_tree);
6351 static bool is_naming_typedef_decl (const_tree);
6352 static inline dw_die_ref get_context_die (tree);
6353 static void gen_namespace_die (tree, dw_die_ref);
6354 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6355 static dw_die_ref force_decl_die (tree);
6356 static dw_die_ref force_type_die (tree);
6357 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6358 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6359 static struct dwarf_file_data * lookup_filename (const char *);
6360 static void retry_incomplete_types (void);
6361 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6362 static void gen_generic_params_dies (tree);
6363 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6364 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6365 static void splice_child_die (dw_die_ref, dw_die_ref);
6366 static int file_info_cmp (const void *, const void *);
6367 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6368 const char *, const char *);
6369 static void output_loc_list (dw_loc_list_ref);
6370 static char *gen_internal_sym (const char *);
6372 static void prune_unmark_dies (dw_die_ref);
6373 static void prune_unused_types_mark (dw_die_ref, int);
6374 static void prune_unused_types_walk (dw_die_ref);
6375 static void prune_unused_types_walk_attribs (dw_die_ref);
6376 static void prune_unused_types_prune (dw_die_ref);
6377 static void prune_unused_types (void);
6378 static int maybe_emit_file (struct dwarf_file_data *fd);
6379 static inline const char *AT_vms_delta1 (dw_attr_ref);
6380 static inline const char *AT_vms_delta2 (dw_attr_ref);
6381 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6382 const char *, const char *);
6383 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6384 static void gen_remaining_tmpl_value_param_die_attribute (void);
6386 /* Section names used to hold DWARF debugging information. */
6387 #ifndef DEBUG_INFO_SECTION
6388 #define DEBUG_INFO_SECTION ".debug_info"
6390 #ifndef DEBUG_ABBREV_SECTION
6391 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6393 #ifndef DEBUG_ARANGES_SECTION
6394 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6396 #ifndef DEBUG_MACINFO_SECTION
6397 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6399 #ifndef DEBUG_LINE_SECTION
6400 #define DEBUG_LINE_SECTION ".debug_line"
6402 #ifndef DEBUG_LOC_SECTION
6403 #define DEBUG_LOC_SECTION ".debug_loc"
6405 #ifndef DEBUG_PUBNAMES_SECTION
6406 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6408 #ifndef DEBUG_PUBTYPES_SECTION
6409 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6411 #ifndef DEBUG_DCALL_SECTION
6412 #define DEBUG_DCALL_SECTION ".debug_dcall"
6414 #ifndef DEBUG_VCALL_SECTION
6415 #define DEBUG_VCALL_SECTION ".debug_vcall"
6417 #ifndef DEBUG_STR_SECTION
6418 #define DEBUG_STR_SECTION ".debug_str"
6420 #ifndef DEBUG_RANGES_SECTION
6421 #define DEBUG_RANGES_SECTION ".debug_ranges"
6424 /* Standard ELF section names for compiled code and data. */
6425 #ifndef TEXT_SECTION_NAME
6426 #define TEXT_SECTION_NAME ".text"
6429 /* Section flags for .debug_str section. */
6430 #define DEBUG_STR_SECTION_FLAGS \
6431 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6432 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6435 /* Labels we insert at beginning sections we can reference instead of
6436 the section names themselves. */
6438 #ifndef TEXT_SECTION_LABEL
6439 #define TEXT_SECTION_LABEL "Ltext"
6441 #ifndef COLD_TEXT_SECTION_LABEL
6442 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6444 #ifndef DEBUG_LINE_SECTION_LABEL
6445 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6447 #ifndef DEBUG_INFO_SECTION_LABEL
6448 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6450 #ifndef DEBUG_ABBREV_SECTION_LABEL
6451 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6453 #ifndef DEBUG_LOC_SECTION_LABEL
6454 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6456 #ifndef DEBUG_RANGES_SECTION_LABEL
6457 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6459 #ifndef DEBUG_MACINFO_SECTION_LABEL
6460 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6464 /* Definitions of defaults for formats and names of various special
6465 (artificial) labels which may be generated within this file (when the -g
6466 options is used and DWARF2_DEBUGGING_INFO is in effect.
6467 If necessary, these may be overridden from within the tm.h file, but
6468 typically, overriding these defaults is unnecessary. */
6470 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6471 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6472 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6473 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6474 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6475 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6476 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6477 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6478 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6479 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6481 #ifndef TEXT_END_LABEL
6482 #define TEXT_END_LABEL "Letext"
6484 #ifndef COLD_END_LABEL
6485 #define COLD_END_LABEL "Letext_cold"
6487 #ifndef BLOCK_BEGIN_LABEL
6488 #define BLOCK_BEGIN_LABEL "LBB"
6490 #ifndef BLOCK_END_LABEL
6491 #define BLOCK_END_LABEL "LBE"
6493 #ifndef LINE_CODE_LABEL
6494 #define LINE_CODE_LABEL "LM"
6496 #ifndef SEPARATE_LINE_CODE_LABEL
6497 #define SEPARATE_LINE_CODE_LABEL "LSM"
6501 /* We allow a language front-end to designate a function that is to be
6502 called to "demangle" any name before it is put into a DIE. */
6504 static const char *(*demangle_name_func) (const char *);
6507 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6509 demangle_name_func = func;
6512 /* Test if rtl node points to a pseudo register. */
6515 is_pseudo_reg (const_rtx rtl)
6517 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6518 || (GET_CODE (rtl) == SUBREG
6519 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6522 /* Return a reference to a type, with its const and volatile qualifiers
6526 type_main_variant (tree type)
6528 type = TYPE_MAIN_VARIANT (type);
6530 /* ??? There really should be only one main variant among any group of
6531 variants of a given type (and all of the MAIN_VARIANT values for all
6532 members of the group should point to that one type) but sometimes the C
6533 front-end messes this up for array types, so we work around that bug
6535 if (TREE_CODE (type) == ARRAY_TYPE)
6536 while (type != TYPE_MAIN_VARIANT (type))
6537 type = TYPE_MAIN_VARIANT (type);
6542 /* Return nonzero if the given type node represents a tagged type. */
6545 is_tagged_type (const_tree type)
6547 enum tree_code code = TREE_CODE (type);
6549 return (code == RECORD_TYPE || code == UNION_TYPE
6550 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6553 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6556 get_ref_die_offset_label (char *label, dw_die_ref ref)
6558 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6561 /* Convert a DIE tag into its string name. */
6564 dwarf_tag_name (unsigned int tag)
6568 case DW_TAG_padding:
6569 return "DW_TAG_padding";
6570 case DW_TAG_array_type:
6571 return "DW_TAG_array_type";
6572 case DW_TAG_class_type:
6573 return "DW_TAG_class_type";
6574 case DW_TAG_entry_point:
6575 return "DW_TAG_entry_point";
6576 case DW_TAG_enumeration_type:
6577 return "DW_TAG_enumeration_type";
6578 case DW_TAG_formal_parameter:
6579 return "DW_TAG_formal_parameter";
6580 case DW_TAG_imported_declaration:
6581 return "DW_TAG_imported_declaration";
6583 return "DW_TAG_label";
6584 case DW_TAG_lexical_block:
6585 return "DW_TAG_lexical_block";
6587 return "DW_TAG_member";
6588 case DW_TAG_pointer_type:
6589 return "DW_TAG_pointer_type";
6590 case DW_TAG_reference_type:
6591 return "DW_TAG_reference_type";
6592 case DW_TAG_compile_unit:
6593 return "DW_TAG_compile_unit";
6594 case DW_TAG_string_type:
6595 return "DW_TAG_string_type";
6596 case DW_TAG_structure_type:
6597 return "DW_TAG_structure_type";
6598 case DW_TAG_subroutine_type:
6599 return "DW_TAG_subroutine_type";
6600 case DW_TAG_typedef:
6601 return "DW_TAG_typedef";
6602 case DW_TAG_union_type:
6603 return "DW_TAG_union_type";
6604 case DW_TAG_unspecified_parameters:
6605 return "DW_TAG_unspecified_parameters";
6606 case DW_TAG_variant:
6607 return "DW_TAG_variant";
6608 case DW_TAG_common_block:
6609 return "DW_TAG_common_block";
6610 case DW_TAG_common_inclusion:
6611 return "DW_TAG_common_inclusion";
6612 case DW_TAG_inheritance:
6613 return "DW_TAG_inheritance";
6614 case DW_TAG_inlined_subroutine:
6615 return "DW_TAG_inlined_subroutine";
6617 return "DW_TAG_module";
6618 case DW_TAG_ptr_to_member_type:
6619 return "DW_TAG_ptr_to_member_type";
6620 case DW_TAG_set_type:
6621 return "DW_TAG_set_type";
6622 case DW_TAG_subrange_type:
6623 return "DW_TAG_subrange_type";
6624 case DW_TAG_with_stmt:
6625 return "DW_TAG_with_stmt";
6626 case DW_TAG_access_declaration:
6627 return "DW_TAG_access_declaration";
6628 case DW_TAG_base_type:
6629 return "DW_TAG_base_type";
6630 case DW_TAG_catch_block:
6631 return "DW_TAG_catch_block";
6632 case DW_TAG_const_type:
6633 return "DW_TAG_const_type";
6634 case DW_TAG_constant:
6635 return "DW_TAG_constant";
6636 case DW_TAG_enumerator:
6637 return "DW_TAG_enumerator";
6638 case DW_TAG_file_type:
6639 return "DW_TAG_file_type";
6641 return "DW_TAG_friend";
6642 case DW_TAG_namelist:
6643 return "DW_TAG_namelist";
6644 case DW_TAG_namelist_item:
6645 return "DW_TAG_namelist_item";
6646 case DW_TAG_packed_type:
6647 return "DW_TAG_packed_type";
6648 case DW_TAG_subprogram:
6649 return "DW_TAG_subprogram";
6650 case DW_TAG_template_type_param:
6651 return "DW_TAG_template_type_param";
6652 case DW_TAG_template_value_param:
6653 return "DW_TAG_template_value_param";
6654 case DW_TAG_thrown_type:
6655 return "DW_TAG_thrown_type";
6656 case DW_TAG_try_block:
6657 return "DW_TAG_try_block";
6658 case DW_TAG_variant_part:
6659 return "DW_TAG_variant_part";
6660 case DW_TAG_variable:
6661 return "DW_TAG_variable";
6662 case DW_TAG_volatile_type:
6663 return "DW_TAG_volatile_type";
6664 case DW_TAG_dwarf_procedure:
6665 return "DW_TAG_dwarf_procedure";
6666 case DW_TAG_restrict_type:
6667 return "DW_TAG_restrict_type";
6668 case DW_TAG_interface_type:
6669 return "DW_TAG_interface_type";
6670 case DW_TAG_namespace:
6671 return "DW_TAG_namespace";
6672 case DW_TAG_imported_module:
6673 return "DW_TAG_imported_module";
6674 case DW_TAG_unspecified_type:
6675 return "DW_TAG_unspecified_type";
6676 case DW_TAG_partial_unit:
6677 return "DW_TAG_partial_unit";
6678 case DW_TAG_imported_unit:
6679 return "DW_TAG_imported_unit";
6680 case DW_TAG_condition:
6681 return "DW_TAG_condition";
6682 case DW_TAG_shared_type:
6683 return "DW_TAG_shared_type";
6684 case DW_TAG_type_unit:
6685 return "DW_TAG_type_unit";
6686 case DW_TAG_rvalue_reference_type:
6687 return "DW_TAG_rvalue_reference_type";
6688 case DW_TAG_template_alias:
6689 return "DW_TAG_template_alias";
6690 case DW_TAG_GNU_template_parameter_pack:
6691 return "DW_TAG_GNU_template_parameter_pack";
6692 case DW_TAG_GNU_formal_parameter_pack:
6693 return "DW_TAG_GNU_formal_parameter_pack";
6694 case DW_TAG_MIPS_loop:
6695 return "DW_TAG_MIPS_loop";
6696 case DW_TAG_format_label:
6697 return "DW_TAG_format_label";
6698 case DW_TAG_function_template:
6699 return "DW_TAG_function_template";
6700 case DW_TAG_class_template:
6701 return "DW_TAG_class_template";
6702 case DW_TAG_GNU_BINCL:
6703 return "DW_TAG_GNU_BINCL";
6704 case DW_TAG_GNU_EINCL:
6705 return "DW_TAG_GNU_EINCL";
6706 case DW_TAG_GNU_template_template_param:
6707 return "DW_TAG_GNU_template_template_param";
6709 return "DW_TAG_<unknown>";
6713 /* Convert a DWARF attribute code into its string name. */
6716 dwarf_attr_name (unsigned int attr)
6721 return "DW_AT_sibling";
6722 case DW_AT_location:
6723 return "DW_AT_location";
6725 return "DW_AT_name";
6726 case DW_AT_ordering:
6727 return "DW_AT_ordering";
6728 case DW_AT_subscr_data:
6729 return "DW_AT_subscr_data";
6730 case DW_AT_byte_size:
6731 return "DW_AT_byte_size";
6732 case DW_AT_bit_offset:
6733 return "DW_AT_bit_offset";
6734 case DW_AT_bit_size:
6735 return "DW_AT_bit_size";
6736 case DW_AT_element_list:
6737 return "DW_AT_element_list";
6738 case DW_AT_stmt_list:
6739 return "DW_AT_stmt_list";
6741 return "DW_AT_low_pc";
6743 return "DW_AT_high_pc";
6744 case DW_AT_language:
6745 return "DW_AT_language";
6747 return "DW_AT_member";
6749 return "DW_AT_discr";
6750 case DW_AT_discr_value:
6751 return "DW_AT_discr_value";
6752 case DW_AT_visibility:
6753 return "DW_AT_visibility";
6755 return "DW_AT_import";
6756 case DW_AT_string_length:
6757 return "DW_AT_string_length";
6758 case DW_AT_common_reference:
6759 return "DW_AT_common_reference";
6760 case DW_AT_comp_dir:
6761 return "DW_AT_comp_dir";
6762 case DW_AT_const_value:
6763 return "DW_AT_const_value";
6764 case DW_AT_containing_type:
6765 return "DW_AT_containing_type";
6766 case DW_AT_default_value:
6767 return "DW_AT_default_value";
6769 return "DW_AT_inline";
6770 case DW_AT_is_optional:
6771 return "DW_AT_is_optional";
6772 case DW_AT_lower_bound:
6773 return "DW_AT_lower_bound";
6774 case DW_AT_producer:
6775 return "DW_AT_producer";
6776 case DW_AT_prototyped:
6777 return "DW_AT_prototyped";
6778 case DW_AT_return_addr:
6779 return "DW_AT_return_addr";
6780 case DW_AT_start_scope:
6781 return "DW_AT_start_scope";
6782 case DW_AT_bit_stride:
6783 return "DW_AT_bit_stride";
6784 case DW_AT_upper_bound:
6785 return "DW_AT_upper_bound";
6786 case DW_AT_abstract_origin:
6787 return "DW_AT_abstract_origin";
6788 case DW_AT_accessibility:
6789 return "DW_AT_accessibility";
6790 case DW_AT_address_class:
6791 return "DW_AT_address_class";
6792 case DW_AT_artificial:
6793 return "DW_AT_artificial";
6794 case DW_AT_base_types:
6795 return "DW_AT_base_types";
6796 case DW_AT_calling_convention:
6797 return "DW_AT_calling_convention";
6799 return "DW_AT_count";
6800 case DW_AT_data_member_location:
6801 return "DW_AT_data_member_location";
6802 case DW_AT_decl_column:
6803 return "DW_AT_decl_column";
6804 case DW_AT_decl_file:
6805 return "DW_AT_decl_file";
6806 case DW_AT_decl_line:
6807 return "DW_AT_decl_line";
6808 case DW_AT_declaration:
6809 return "DW_AT_declaration";
6810 case DW_AT_discr_list:
6811 return "DW_AT_discr_list";
6812 case DW_AT_encoding:
6813 return "DW_AT_encoding";
6814 case DW_AT_external:
6815 return "DW_AT_external";
6816 case DW_AT_explicit:
6817 return "DW_AT_explicit";
6818 case DW_AT_frame_base:
6819 return "DW_AT_frame_base";
6821 return "DW_AT_friend";
6822 case DW_AT_identifier_case:
6823 return "DW_AT_identifier_case";
6824 case DW_AT_macro_info:
6825 return "DW_AT_macro_info";
6826 case DW_AT_namelist_items:
6827 return "DW_AT_namelist_items";
6828 case DW_AT_priority:
6829 return "DW_AT_priority";
6831 return "DW_AT_segment";
6832 case DW_AT_specification:
6833 return "DW_AT_specification";
6834 case DW_AT_static_link:
6835 return "DW_AT_static_link";
6837 return "DW_AT_type";
6838 case DW_AT_use_location:
6839 return "DW_AT_use_location";
6840 case DW_AT_variable_parameter:
6841 return "DW_AT_variable_parameter";
6842 case DW_AT_virtuality:
6843 return "DW_AT_virtuality";
6844 case DW_AT_vtable_elem_location:
6845 return "DW_AT_vtable_elem_location";
6847 case DW_AT_allocated:
6848 return "DW_AT_allocated";
6849 case DW_AT_associated:
6850 return "DW_AT_associated";
6851 case DW_AT_data_location:
6852 return "DW_AT_data_location";
6853 case DW_AT_byte_stride:
6854 return "DW_AT_byte_stride";
6855 case DW_AT_entry_pc:
6856 return "DW_AT_entry_pc";
6857 case DW_AT_use_UTF8:
6858 return "DW_AT_use_UTF8";
6859 case DW_AT_extension:
6860 return "DW_AT_extension";
6862 return "DW_AT_ranges";
6863 case DW_AT_trampoline:
6864 return "DW_AT_trampoline";
6865 case DW_AT_call_column:
6866 return "DW_AT_call_column";
6867 case DW_AT_call_file:
6868 return "DW_AT_call_file";
6869 case DW_AT_call_line:
6870 return "DW_AT_call_line";
6871 case DW_AT_object_pointer:
6872 return "DW_AT_object_pointer";
6874 case DW_AT_signature:
6875 return "DW_AT_signature";
6876 case DW_AT_main_subprogram:
6877 return "DW_AT_main_subprogram";
6878 case DW_AT_data_bit_offset:
6879 return "DW_AT_data_bit_offset";
6880 case DW_AT_const_expr:
6881 return "DW_AT_const_expr";
6882 case DW_AT_enum_class:
6883 return "DW_AT_enum_class";
6884 case DW_AT_linkage_name:
6885 return "DW_AT_linkage_name";
6887 case DW_AT_MIPS_fde:
6888 return "DW_AT_MIPS_fde";
6889 case DW_AT_MIPS_loop_begin:
6890 return "DW_AT_MIPS_loop_begin";
6891 case DW_AT_MIPS_tail_loop_begin:
6892 return "DW_AT_MIPS_tail_loop_begin";
6893 case DW_AT_MIPS_epilog_begin:
6894 return "DW_AT_MIPS_epilog_begin";
6895 #if VMS_DEBUGGING_INFO
6896 case DW_AT_HP_prologue:
6897 return "DW_AT_HP_prologue";
6899 case DW_AT_MIPS_loop_unroll_factor:
6900 return "DW_AT_MIPS_loop_unroll_factor";
6902 case DW_AT_MIPS_software_pipeline_depth:
6903 return "DW_AT_MIPS_software_pipeline_depth";
6904 case DW_AT_MIPS_linkage_name:
6905 return "DW_AT_MIPS_linkage_name";
6906 #if VMS_DEBUGGING_INFO
6907 case DW_AT_HP_epilogue:
6908 return "DW_AT_HP_epilogue";
6910 case DW_AT_MIPS_stride:
6911 return "DW_AT_MIPS_stride";
6913 case DW_AT_MIPS_abstract_name:
6914 return "DW_AT_MIPS_abstract_name";
6915 case DW_AT_MIPS_clone_origin:
6916 return "DW_AT_MIPS_clone_origin";
6917 case DW_AT_MIPS_has_inlines:
6918 return "DW_AT_MIPS_has_inlines";
6920 case DW_AT_sf_names:
6921 return "DW_AT_sf_names";
6922 case DW_AT_src_info:
6923 return "DW_AT_src_info";
6924 case DW_AT_mac_info:
6925 return "DW_AT_mac_info";
6926 case DW_AT_src_coords:
6927 return "DW_AT_src_coords";
6928 case DW_AT_body_begin:
6929 return "DW_AT_body_begin";
6930 case DW_AT_body_end:
6931 return "DW_AT_body_end";
6932 case DW_AT_GNU_vector:
6933 return "DW_AT_GNU_vector";
6934 case DW_AT_GNU_guarded_by:
6935 return "DW_AT_GNU_guarded_by";
6936 case DW_AT_GNU_pt_guarded_by:
6937 return "DW_AT_GNU_pt_guarded_by";
6938 case DW_AT_GNU_guarded:
6939 return "DW_AT_GNU_guarded";
6940 case DW_AT_GNU_pt_guarded:
6941 return "DW_AT_GNU_pt_guarded";
6942 case DW_AT_GNU_locks_excluded:
6943 return "DW_AT_GNU_locks_excluded";
6944 case DW_AT_GNU_exclusive_locks_required:
6945 return "DW_AT_GNU_exclusive_locks_required";
6946 case DW_AT_GNU_shared_locks_required:
6947 return "DW_AT_GNU_shared_locks_required";
6948 case DW_AT_GNU_odr_signature:
6949 return "DW_AT_GNU_odr_signature";
6950 case DW_AT_GNU_template_name:
6951 return "DW_AT_GNU_template_name";
6953 case DW_AT_VMS_rtnbeg_pd_address:
6954 return "DW_AT_VMS_rtnbeg_pd_address";
6957 return "DW_AT_<unknown>";
6961 /* Convert a DWARF value form code into its string name. */
6964 dwarf_form_name (unsigned int form)
6969 return "DW_FORM_addr";
6970 case DW_FORM_block2:
6971 return "DW_FORM_block2";
6972 case DW_FORM_block4:
6973 return "DW_FORM_block4";
6975 return "DW_FORM_data2";
6977 return "DW_FORM_data4";
6979 return "DW_FORM_data8";
6980 case DW_FORM_string:
6981 return "DW_FORM_string";
6983 return "DW_FORM_block";
6984 case DW_FORM_block1:
6985 return "DW_FORM_block1";
6987 return "DW_FORM_data1";
6989 return "DW_FORM_flag";
6991 return "DW_FORM_sdata";
6993 return "DW_FORM_strp";
6995 return "DW_FORM_udata";
6996 case DW_FORM_ref_addr:
6997 return "DW_FORM_ref_addr";
6999 return "DW_FORM_ref1";
7001 return "DW_FORM_ref2";
7003 return "DW_FORM_ref4";
7005 return "DW_FORM_ref8";
7006 case DW_FORM_ref_udata:
7007 return "DW_FORM_ref_udata";
7008 case DW_FORM_indirect:
7009 return "DW_FORM_indirect";
7010 case DW_FORM_sec_offset:
7011 return "DW_FORM_sec_offset";
7012 case DW_FORM_exprloc:
7013 return "DW_FORM_exprloc";
7014 case DW_FORM_flag_present:
7015 return "DW_FORM_flag_present";
7016 case DW_FORM_ref_sig8:
7017 return "DW_FORM_ref_sig8";
7019 return "DW_FORM_<unknown>";
7023 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7024 instance of an inlined instance of a decl which is local to an inline
7025 function, so we have to trace all of the way back through the origin chain
7026 to find out what sort of node actually served as the original seed for the
7030 decl_ultimate_origin (const_tree decl)
7032 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7035 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7036 nodes in the function to point to themselves; ignore that if
7037 we're trying to output the abstract instance of this function. */
7038 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7041 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7042 most distant ancestor, this should never happen. */
7043 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7045 return DECL_ABSTRACT_ORIGIN (decl);
7048 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7049 of a virtual function may refer to a base class, so we check the 'this'
7053 decl_class_context (tree decl)
7055 tree context = NULL_TREE;
7057 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7058 context = DECL_CONTEXT (decl);
7060 context = TYPE_MAIN_VARIANT
7061 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7063 if (context && !TYPE_P (context))
7064 context = NULL_TREE;
7069 /* Add an attribute/value pair to a DIE. */
7072 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7074 /* Maybe this should be an assert? */
7078 if (die->die_attr == NULL)
7079 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7080 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7083 static inline enum dw_val_class
7084 AT_class (dw_attr_ref a)
7086 return a->dw_attr_val.val_class;
7089 /* Add a flag value attribute to a DIE. */
7092 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7096 attr.dw_attr = attr_kind;
7097 attr.dw_attr_val.val_class = dw_val_class_flag;
7098 attr.dw_attr_val.v.val_flag = flag;
7099 add_dwarf_attr (die, &attr);
7102 static inline unsigned
7103 AT_flag (dw_attr_ref a)
7105 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7106 return a->dw_attr_val.v.val_flag;
7109 /* Add a signed integer attribute value to a DIE. */
7112 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7116 attr.dw_attr = attr_kind;
7117 attr.dw_attr_val.val_class = dw_val_class_const;
7118 attr.dw_attr_val.v.val_int = int_val;
7119 add_dwarf_attr (die, &attr);
7122 static inline HOST_WIDE_INT
7123 AT_int (dw_attr_ref a)
7125 gcc_assert (a && AT_class (a) == dw_val_class_const);
7126 return a->dw_attr_val.v.val_int;
7129 /* Add an unsigned integer attribute value to a DIE. */
7132 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7133 unsigned HOST_WIDE_INT unsigned_val)
7137 attr.dw_attr = attr_kind;
7138 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7139 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7140 add_dwarf_attr (die, &attr);
7143 static inline unsigned HOST_WIDE_INT
7144 AT_unsigned (dw_attr_ref a)
7146 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7147 return a->dw_attr_val.v.val_unsigned;
7150 /* Add an unsigned double integer attribute value to a DIE. */
7153 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7154 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7158 attr.dw_attr = attr_kind;
7159 attr.dw_attr_val.val_class = dw_val_class_const_double;
7160 attr.dw_attr_val.v.val_double.high = high;
7161 attr.dw_attr_val.v.val_double.low = low;
7162 add_dwarf_attr (die, &attr);
7165 /* Add a floating point attribute value to a DIE and return it. */
7168 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7169 unsigned int length, unsigned int elt_size, unsigned char *array)
7173 attr.dw_attr = attr_kind;
7174 attr.dw_attr_val.val_class = dw_val_class_vec;
7175 attr.dw_attr_val.v.val_vec.length = length;
7176 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7177 attr.dw_attr_val.v.val_vec.array = array;
7178 add_dwarf_attr (die, &attr);
7181 /* Add an 8-byte data attribute value to a DIE. */
7184 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7185 unsigned char data8[8])
7189 attr.dw_attr = attr_kind;
7190 attr.dw_attr_val.val_class = dw_val_class_data8;
7191 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7192 add_dwarf_attr (die, &attr);
7195 /* Hash and equality functions for debug_str_hash. */
7198 debug_str_do_hash (const void *x)
7200 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7204 debug_str_eq (const void *x1, const void *x2)
7206 return strcmp ((((const struct indirect_string_node *)x1)->str),
7207 (const char *)x2) == 0;
7210 /* Add STR to the indirect string hash table. */
7212 static struct indirect_string_node *
7213 find_AT_string (const char *str)
7215 struct indirect_string_node *node;
7218 if (! debug_str_hash)
7219 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7220 debug_str_eq, NULL);
7222 slot = htab_find_slot_with_hash (debug_str_hash, str,
7223 htab_hash_string (str), INSERT);
7226 node = ggc_alloc_cleared_indirect_string_node ();
7227 node->str = ggc_strdup (str);
7231 node = (struct indirect_string_node *) *slot;
7237 /* Add a string attribute value to a DIE. */
7240 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7243 struct indirect_string_node *node;
7245 node = find_AT_string (str);
7247 attr.dw_attr = attr_kind;
7248 attr.dw_attr_val.val_class = dw_val_class_str;
7249 attr.dw_attr_val.v.val_str = node;
7250 add_dwarf_attr (die, &attr);
7253 /* Create a label for an indirect string node, ensuring it is going to
7254 be output, unless its reference count goes down to zero. */
7257 gen_label_for_indirect_string (struct indirect_string_node *node)
7264 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7265 ++dw2_string_counter;
7266 node->label = xstrdup (label);
7269 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7270 debug string STR. */
7273 get_debug_string_label (const char *str)
7275 struct indirect_string_node *node = find_AT_string (str);
7277 debug_str_hash_forced = true;
7279 gen_label_for_indirect_string (node);
7281 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7284 static inline const char *
7285 AT_string (dw_attr_ref a)
7287 gcc_assert (a && AT_class (a) == dw_val_class_str);
7288 return a->dw_attr_val.v.val_str->str;
7291 /* Find out whether a string should be output inline in DIE
7292 or out-of-line in .debug_str section. */
7294 static enum dwarf_form
7295 AT_string_form (dw_attr_ref a)
7297 struct indirect_string_node *node;
7300 gcc_assert (a && AT_class (a) == dw_val_class_str);
7302 node = a->dw_attr_val.v.val_str;
7306 len = strlen (node->str) + 1;
7308 /* If the string is shorter or equal to the size of the reference, it is
7309 always better to put it inline. */
7310 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7311 return node->form = DW_FORM_string;
7313 /* If we cannot expect the linker to merge strings in .debug_str
7314 section, only put it into .debug_str if it is worth even in this
7316 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7317 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7318 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7319 return node->form = DW_FORM_string;
7321 gen_label_for_indirect_string (node);
7323 return node->form = DW_FORM_strp;
7326 /* Add a DIE reference attribute value to a DIE. */
7329 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7333 attr.dw_attr = attr_kind;
7334 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7335 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7336 attr.dw_attr_val.v.val_die_ref.external = 0;
7337 add_dwarf_attr (die, &attr);
7340 /* Add an AT_specification attribute to a DIE, and also make the back
7341 pointer from the specification to the definition. */
7344 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7346 add_AT_die_ref (die, DW_AT_specification, targ_die);
7347 gcc_assert (!targ_die->die_definition);
7348 targ_die->die_definition = die;
7351 static inline dw_die_ref
7352 AT_ref (dw_attr_ref a)
7354 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7355 return a->dw_attr_val.v.val_die_ref.die;
7359 AT_ref_external (dw_attr_ref a)
7361 if (a && AT_class (a) == dw_val_class_die_ref)
7362 return a->dw_attr_val.v.val_die_ref.external;
7368 set_AT_ref_external (dw_attr_ref a, int i)
7370 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7371 a->dw_attr_val.v.val_die_ref.external = i;
7374 /* Add an FDE reference attribute value to a DIE. */
7377 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7381 attr.dw_attr = attr_kind;
7382 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7383 attr.dw_attr_val.v.val_fde_index = targ_fde;
7384 add_dwarf_attr (die, &attr);
7387 /* Add a location description attribute value to a DIE. */
7390 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7394 attr.dw_attr = attr_kind;
7395 attr.dw_attr_val.val_class = dw_val_class_loc;
7396 attr.dw_attr_val.v.val_loc = loc;
7397 add_dwarf_attr (die, &attr);
7400 static inline dw_loc_descr_ref
7401 AT_loc (dw_attr_ref a)
7403 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7404 return a->dw_attr_val.v.val_loc;
7408 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7412 attr.dw_attr = attr_kind;
7413 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7414 attr.dw_attr_val.v.val_loc_list = loc_list;
7415 add_dwarf_attr (die, &attr);
7416 have_location_lists = true;
7419 static inline dw_loc_list_ref
7420 AT_loc_list (dw_attr_ref a)
7422 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7423 return a->dw_attr_val.v.val_loc_list;
7426 static inline dw_loc_list_ref *
7427 AT_loc_list_ptr (dw_attr_ref a)
7429 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7430 return &a->dw_attr_val.v.val_loc_list;
7433 /* Add an address constant attribute value to a DIE. */
7436 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7440 attr.dw_attr = attr_kind;
7441 attr.dw_attr_val.val_class = dw_val_class_addr;
7442 attr.dw_attr_val.v.val_addr = addr;
7443 add_dwarf_attr (die, &attr);
7446 /* Get the RTX from to an address DIE attribute. */
7449 AT_addr (dw_attr_ref a)
7451 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7452 return a->dw_attr_val.v.val_addr;
7455 /* Add a file attribute value to a DIE. */
7458 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7459 struct dwarf_file_data *fd)
7463 attr.dw_attr = attr_kind;
7464 attr.dw_attr_val.val_class = dw_val_class_file;
7465 attr.dw_attr_val.v.val_file = fd;
7466 add_dwarf_attr (die, &attr);
7469 /* Get the dwarf_file_data from a file DIE attribute. */
7471 static inline struct dwarf_file_data *
7472 AT_file (dw_attr_ref a)
7474 gcc_assert (a && AT_class (a) == dw_val_class_file);
7475 return a->dw_attr_val.v.val_file;
7478 /* Add a vms delta attribute value to a DIE. */
7481 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7482 const char *lbl1, const char *lbl2)
7486 attr.dw_attr = attr_kind;
7487 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7488 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7489 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7490 add_dwarf_attr (die, &attr);
7493 /* Add a label identifier attribute value to a DIE. */
7496 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7500 attr.dw_attr = attr_kind;
7501 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7502 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7503 add_dwarf_attr (die, &attr);
7506 /* Add a section offset attribute value to a DIE, an offset into the
7507 debug_line section. */
7510 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7515 attr.dw_attr = attr_kind;
7516 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7517 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7518 add_dwarf_attr (die, &attr);
7521 /* Add a section offset attribute value to a DIE, an offset into the
7522 debug_macinfo section. */
7525 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7530 attr.dw_attr = attr_kind;
7531 attr.dw_attr_val.val_class = dw_val_class_macptr;
7532 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7533 add_dwarf_attr (die, &attr);
7536 /* Add an offset attribute value to a DIE. */
7539 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7540 unsigned HOST_WIDE_INT offset)
7544 attr.dw_attr = attr_kind;
7545 attr.dw_attr_val.val_class = dw_val_class_offset;
7546 attr.dw_attr_val.v.val_offset = offset;
7547 add_dwarf_attr (die, &attr);
7550 /* Add an range_list attribute value to a DIE. */
7553 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7554 long unsigned int offset)
7558 attr.dw_attr = attr_kind;
7559 attr.dw_attr_val.val_class = dw_val_class_range_list;
7560 attr.dw_attr_val.v.val_offset = offset;
7561 add_dwarf_attr (die, &attr);
7564 /* Return the start label of a delta attribute. */
7566 static inline const char *
7567 AT_vms_delta1 (dw_attr_ref a)
7569 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7570 return a->dw_attr_val.v.val_vms_delta.lbl1;
7573 /* Return the end label of a delta attribute. */
7575 static inline const char *
7576 AT_vms_delta2 (dw_attr_ref a)
7578 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7579 return a->dw_attr_val.v.val_vms_delta.lbl2;
7582 static inline const char *
7583 AT_lbl (dw_attr_ref a)
7585 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7586 || AT_class (a) == dw_val_class_lineptr
7587 || AT_class (a) == dw_val_class_macptr));
7588 return a->dw_attr_val.v.val_lbl_id;
7591 /* Get the attribute of type attr_kind. */
7594 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7598 dw_die_ref spec = NULL;
7603 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7604 if (a->dw_attr == attr_kind)
7606 else if (a->dw_attr == DW_AT_specification
7607 || a->dw_attr == DW_AT_abstract_origin)
7611 return get_AT (spec, attr_kind);
7616 /* Return the "low pc" attribute value, typically associated with a subprogram
7617 DIE. Return null if the "low pc" attribute is either not present, or if it
7618 cannot be represented as an assembler label identifier. */
7620 static inline const char *
7621 get_AT_low_pc (dw_die_ref die)
7623 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7625 return a ? AT_lbl (a) : NULL;
7628 /* Return the "high pc" attribute value, typically associated with a subprogram
7629 DIE. Return null if the "high pc" attribute is either not present, or if it
7630 cannot be represented as an assembler label identifier. */
7632 static inline const char *
7633 get_AT_hi_pc (dw_die_ref die)
7635 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7637 return a ? AT_lbl (a) : NULL;
7640 /* Return the value of the string attribute designated by ATTR_KIND, or
7641 NULL if it is not present. */
7643 static inline const char *
7644 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7646 dw_attr_ref a = get_AT (die, attr_kind);
7648 return a ? AT_string (a) : NULL;
7651 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7652 if it is not present. */
7655 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7657 dw_attr_ref a = get_AT (die, attr_kind);
7659 return a ? AT_flag (a) : 0;
7662 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7663 if it is not present. */
7665 static inline unsigned
7666 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7668 dw_attr_ref a = get_AT (die, attr_kind);
7670 return a ? AT_unsigned (a) : 0;
7673 static inline dw_die_ref
7674 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7676 dw_attr_ref a = get_AT (die, attr_kind);
7678 return a ? AT_ref (a) : NULL;
7681 static inline struct dwarf_file_data *
7682 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7684 dw_attr_ref a = get_AT (die, attr_kind);
7686 return a ? AT_file (a) : NULL;
7689 /* Return TRUE if the language is C++. */
7694 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7696 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7699 /* Return TRUE if the language is Fortran. */
7704 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7706 return (lang == DW_LANG_Fortran77
7707 || lang == DW_LANG_Fortran90
7708 || lang == DW_LANG_Fortran95);
7711 /* Return TRUE if the language is Ada. */
7716 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7718 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7721 /* Remove the specified attribute if present. */
7724 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7732 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7733 if (a->dw_attr == attr_kind)
7735 if (AT_class (a) == dw_val_class_str)
7736 if (a->dw_attr_val.v.val_str->refcount)
7737 a->dw_attr_val.v.val_str->refcount--;
7739 /* VEC_ordered_remove should help reduce the number of abbrevs
7741 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7746 /* Remove CHILD from its parent. PREV must have the property that
7747 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7750 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7752 gcc_assert (child->die_parent == prev->die_parent);
7753 gcc_assert (prev->die_sib == child);
7756 gcc_assert (child->die_parent->die_child == child);
7760 prev->die_sib = child->die_sib;
7761 if (child->die_parent->die_child == child)
7762 child->die_parent->die_child = prev;
7765 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7766 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7769 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7771 dw_die_ref parent = old_child->die_parent;
7773 gcc_assert (parent == prev->die_parent);
7774 gcc_assert (prev->die_sib == old_child);
7776 new_child->die_parent = parent;
7777 if (prev == old_child)
7779 gcc_assert (parent->die_child == old_child);
7780 new_child->die_sib = new_child;
7784 prev->die_sib = new_child;
7785 new_child->die_sib = old_child->die_sib;
7787 if (old_child->die_parent->die_child == old_child)
7788 old_child->die_parent->die_child = new_child;
7791 /* Move all children from OLD_PARENT to NEW_PARENT. */
7794 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7797 new_parent->die_child = old_parent->die_child;
7798 old_parent->die_child = NULL;
7799 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7802 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7806 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7812 dw_die_ref prev = c;
7814 while (c->die_tag == tag)
7816 remove_child_with_prev (c, prev);
7817 /* Might have removed every child. */
7818 if (c == c->die_sib)
7822 } while (c != die->die_child);
7825 /* Add a CHILD_DIE as the last child of DIE. */
7828 add_child_die (dw_die_ref die, dw_die_ref child_die)
7830 /* FIXME this should probably be an assert. */
7831 if (! die || ! child_die)
7833 gcc_assert (die != child_die);
7835 child_die->die_parent = die;
7838 child_die->die_sib = die->die_child->die_sib;
7839 die->die_child->die_sib = child_die;
7842 child_die->die_sib = child_die;
7843 die->die_child = child_die;
7846 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7847 is the specification, to the end of PARENT's list of children.
7848 This is done by removing and re-adding it. */
7851 splice_child_die (dw_die_ref parent, dw_die_ref child)
7855 /* We want the declaration DIE from inside the class, not the
7856 specification DIE at toplevel. */
7857 if (child->die_parent != parent)
7859 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7865 gcc_assert (child->die_parent == parent
7866 || (child->die_parent
7867 == get_AT_ref (parent, DW_AT_specification)));
7869 for (p = child->die_parent->die_child; ; p = p->die_sib)
7870 if (p->die_sib == child)
7872 remove_child_with_prev (child, p);
7876 add_child_die (parent, child);
7879 /* Return a pointer to a newly created DIE node. */
7881 static inline dw_die_ref
7882 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7884 dw_die_ref die = ggc_alloc_cleared_die_node ();
7886 die->die_tag = tag_value;
7888 if (parent_die != NULL)
7889 add_child_die (parent_die, die);
7892 limbo_die_node *limbo_node;
7894 limbo_node = ggc_alloc_cleared_limbo_die_node ();
7895 limbo_node->die = die;
7896 limbo_node->created_for = t;
7897 limbo_node->next = limbo_die_list;
7898 limbo_die_list = limbo_node;
7904 /* Return the DIE associated with the given type specifier. */
7906 static inline dw_die_ref
7907 lookup_type_die (tree type)
7909 return TYPE_SYMTAB_DIE (type);
7912 /* Equate a DIE to a given type specifier. */
7915 equate_type_number_to_die (tree type, dw_die_ref type_die)
7917 TYPE_SYMTAB_DIE (type) = type_die;
7920 /* Returns a hash value for X (which really is a die_struct). */
7923 decl_die_table_hash (const void *x)
7925 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7928 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7931 decl_die_table_eq (const void *x, const void *y)
7933 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7936 /* Return the DIE associated with a given declaration. */
7938 static inline dw_die_ref
7939 lookup_decl_die (tree decl)
7941 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7944 /* Returns a hash value for X (which really is a var_loc_list). */
7947 decl_loc_table_hash (const void *x)
7949 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7952 /* Return nonzero if decl_id of var_loc_list X is the same as
7956 decl_loc_table_eq (const void *x, const void *y)
7958 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7961 /* Return the var_loc list associated with a given declaration. */
7963 static inline var_loc_list *
7964 lookup_decl_loc (const_tree decl)
7966 if (!decl_loc_table)
7968 return (var_loc_list *)
7969 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7972 /* Equate a DIE to a particular declaration. */
7975 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7977 unsigned int decl_id = DECL_UID (decl);
7980 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7982 decl_die->decl_id = decl_id;
7985 /* Return how many bits covers PIECE EXPR_LIST. */
7988 decl_piece_bitsize (rtx piece)
7990 int ret = (int) GET_MODE (piece);
7993 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
7994 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
7995 return INTVAL (XEXP (XEXP (piece, 0), 0));
7998 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8001 decl_piece_varloc_ptr (rtx piece)
8003 if ((int) GET_MODE (piece))
8004 return &XEXP (piece, 0);
8006 return &XEXP (XEXP (piece, 0), 1);
8009 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8010 Next is the chain of following piece nodes. */
8013 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8015 if (bitsize <= (int) MAX_MACHINE_MODE)
8016 return alloc_EXPR_LIST (bitsize, loc_note, next);
8018 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8023 /* Return rtx that should be stored into loc field for
8024 LOC_NOTE and BITPOS/BITSIZE. */
8027 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8028 HOST_WIDE_INT bitsize)
8032 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8034 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8039 /* This function either modifies location piece list *DEST in
8040 place (if SRC and INNER is NULL), or copies location piece list
8041 *SRC to *DEST while modifying it. Location BITPOS is modified
8042 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8043 not copied and if needed some padding around it is added.
8044 When modifying in place, DEST should point to EXPR_LIST where
8045 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8046 to the start of the whole list and INNER points to the EXPR_LIST
8047 where earlier pieces cover PIECE_BITPOS bits. */
8050 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8051 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8052 HOST_WIDE_INT bitsize, rtx loc_note)
8055 bool copy = inner != NULL;
8059 /* First copy all nodes preceeding the current bitpos. */
8060 while (src != inner)
8062 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8063 decl_piece_bitsize (*src), NULL_RTX);
8064 dest = &XEXP (*dest, 1);
8065 src = &XEXP (*src, 1);
8068 /* Add padding if needed. */
8069 if (bitpos != piece_bitpos)
8071 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8072 copy ? NULL_RTX : *dest);
8073 dest = &XEXP (*dest, 1);
8075 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8078 /* A piece with correct bitpos and bitsize already exist,
8079 just update the location for it and return. */
8080 *decl_piece_varloc_ptr (*dest) = loc_note;
8083 /* Add the piece that changed. */
8084 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8085 dest = &XEXP (*dest, 1);
8086 /* Skip over pieces that overlap it. */
8087 diff = bitpos - piece_bitpos + bitsize;
8090 while (diff > 0 && *src)
8093 diff -= decl_piece_bitsize (piece);
8095 src = &XEXP (piece, 1);
8098 *src = XEXP (piece, 1);
8099 free_EXPR_LIST_node (piece);
8102 /* Add padding if needed. */
8103 if (diff < 0 && *src)
8107 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8108 dest = &XEXP (*dest, 1);
8112 /* Finally copy all nodes following it. */
8115 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8116 decl_piece_bitsize (*src), NULL_RTX);
8117 dest = &XEXP (*dest, 1);
8118 src = &XEXP (*src, 1);
8122 /* Add a variable location node to the linked list for DECL. */
8124 static struct var_loc_node *
8125 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8127 unsigned int decl_id;
8130 struct var_loc_node *loc = NULL;
8131 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8133 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8135 tree realdecl = DECL_DEBUG_EXPR (decl);
8136 if (realdecl && handled_component_p (realdecl))
8138 HOST_WIDE_INT maxsize;
8141 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8142 if (!DECL_P (innerdecl)
8143 || DECL_IGNORED_P (innerdecl)
8144 || TREE_STATIC (innerdecl)
8146 || bitpos + bitsize > 256
8147 || bitsize != maxsize)
8153 decl_id = DECL_UID (decl);
8154 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8157 temp = ggc_alloc_cleared_var_loc_list ();
8158 temp->decl_id = decl_id;
8162 temp = (var_loc_list *) *slot;
8166 struct var_loc_node *last = temp->last, *unused = NULL;
8167 rtx *piece_loc = NULL, last_loc_note;
8168 int piece_bitpos = 0;
8172 gcc_assert (last->next == NULL);
8174 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8176 piece_loc = &last->loc;
8179 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8180 if (piece_bitpos + cur_bitsize > bitpos)
8182 piece_bitpos += cur_bitsize;
8183 piece_loc = &XEXP (*piece_loc, 1);
8187 /* TEMP->LAST here is either pointer to the last but one or
8188 last element in the chained list, LAST is pointer to the
8190 if (label && strcmp (last->label, label) == 0)
8192 /* For SRA optimized variables if there weren't any real
8193 insns since last note, just modify the last node. */
8194 if (piece_loc != NULL)
8196 adjust_piece_list (piece_loc, NULL, NULL,
8197 bitpos, piece_bitpos, bitsize, loc_note);
8200 /* If the last note doesn't cover any instructions, remove it. */
8201 if (temp->last != last)
8203 temp->last->next = NULL;
8206 gcc_assert (strcmp (last->label, label) != 0);
8210 gcc_assert (temp->first == temp->last);
8211 memset (temp->last, '\0', sizeof (*temp->last));
8212 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8216 if (bitsize == -1 && NOTE_P (last->loc))
8217 last_loc_note = last->loc;
8218 else if (piece_loc != NULL
8219 && *piece_loc != NULL_RTX
8220 && piece_bitpos == bitpos
8221 && decl_piece_bitsize (*piece_loc) == bitsize)
8222 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8224 last_loc_note = NULL_RTX;
8225 /* If the current location is the same as the end of the list,
8226 and either both or neither of the locations is uninitialized,
8227 we have nothing to do. */
8228 if (last_loc_note == NULL_RTX
8229 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8230 NOTE_VAR_LOCATION_LOC (loc_note)))
8231 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8232 != NOTE_VAR_LOCATION_STATUS (loc_note))
8233 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8234 == VAR_INIT_STATUS_UNINITIALIZED)
8235 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8236 == VAR_INIT_STATUS_UNINITIALIZED))))
8238 /* Add LOC to the end of list and update LAST. If the last
8239 element of the list has been removed above, reuse its
8240 memory for the new node, otherwise allocate a new one. */
8244 memset (loc, '\0', sizeof (*loc));
8247 loc = ggc_alloc_cleared_var_loc_node ();
8248 if (bitsize == -1 || piece_loc == NULL)
8249 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8251 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8252 bitpos, piece_bitpos, bitsize, loc_note);
8254 /* Ensure TEMP->LAST will point either to the new last but one
8255 element of the chain, or to the last element in it. */
8256 if (last != temp->last)
8264 loc = ggc_alloc_cleared_var_loc_node ();
8267 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8272 /* Keep track of the number of spaces used to indent the
8273 output of the debugging routines that print the structure of
8274 the DIE internal representation. */
8275 static int print_indent;
8277 /* Indent the line the number of spaces given by print_indent. */
8280 print_spaces (FILE *outfile)
8282 fprintf (outfile, "%*s", print_indent, "");
8285 /* Print a type signature in hex. */
8288 print_signature (FILE *outfile, char *sig)
8292 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8293 fprintf (outfile, "%02x", sig[i] & 0xff);
8296 /* Print the information associated with a given DIE, and its children.
8297 This routine is a debugging aid only. */
8300 print_die (dw_die_ref die, FILE *outfile)
8306 print_spaces (outfile);
8307 fprintf (outfile, "DIE %4ld: %s\n",
8308 die->die_offset, dwarf_tag_name (die->die_tag));
8309 print_spaces (outfile);
8310 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8311 fprintf (outfile, " offset: %ld\n", die->die_offset);
8312 if (dwarf_version >= 4 && die->die_id.die_type_node)
8314 print_spaces (outfile);
8315 fprintf (outfile, " signature: ");
8316 print_signature (outfile, die->die_id.die_type_node->signature);
8317 fprintf (outfile, "\n");
8320 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8322 print_spaces (outfile);
8323 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8325 switch (AT_class (a))
8327 case dw_val_class_addr:
8328 fprintf (outfile, "address");
8330 case dw_val_class_offset:
8331 fprintf (outfile, "offset");
8333 case dw_val_class_loc:
8334 fprintf (outfile, "location descriptor");
8336 case dw_val_class_loc_list:
8337 fprintf (outfile, "location list -> label:%s",
8338 AT_loc_list (a)->ll_symbol);
8340 case dw_val_class_range_list:
8341 fprintf (outfile, "range list");
8343 case dw_val_class_const:
8344 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8346 case dw_val_class_unsigned_const:
8347 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8349 case dw_val_class_const_double:
8350 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8351 HOST_WIDE_INT_PRINT_UNSIGNED")",
8352 a->dw_attr_val.v.val_double.high,
8353 a->dw_attr_val.v.val_double.low);
8355 case dw_val_class_vec:
8356 fprintf (outfile, "floating-point or vector constant");
8358 case dw_val_class_flag:
8359 fprintf (outfile, "%u", AT_flag (a));
8361 case dw_val_class_die_ref:
8362 if (AT_ref (a) != NULL)
8364 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8366 fprintf (outfile, "die -> signature: ");
8367 print_signature (outfile,
8368 AT_ref (a)->die_id.die_type_node->signature);
8370 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8371 fprintf (outfile, "die -> label: %s",
8372 AT_ref (a)->die_id.die_symbol);
8374 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8377 fprintf (outfile, "die -> <null>");
8379 case dw_val_class_vms_delta:
8380 fprintf (outfile, "delta: @slotcount(%s-%s)",
8381 AT_vms_delta2 (a), AT_vms_delta1 (a));
8383 case dw_val_class_lbl_id:
8384 case dw_val_class_lineptr:
8385 case dw_val_class_macptr:
8386 fprintf (outfile, "label: %s", AT_lbl (a));
8388 case dw_val_class_str:
8389 if (AT_string (a) != NULL)
8390 fprintf (outfile, "\"%s\"", AT_string (a));
8392 fprintf (outfile, "<null>");
8394 case dw_val_class_file:
8395 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8396 AT_file (a)->emitted_number);
8398 case dw_val_class_data8:
8402 for (i = 0; i < 8; i++)
8403 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8410 fprintf (outfile, "\n");
8413 if (die->die_child != NULL)
8416 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8419 if (print_indent == 0)
8420 fprintf (outfile, "\n");
8423 /* Print the contents of the source code line number correspondence table.
8424 This routine is a debugging aid only. */
8427 print_dwarf_line_table (FILE *outfile)
8430 dw_line_info_ref line_info;
8432 fprintf (outfile, "\n\nDWARF source line information\n");
8433 for (i = 1; i < line_info_table_in_use; i++)
8435 line_info = &line_info_table[i];
8436 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8437 line_info->dw_file_num,
8438 line_info->dw_line_num);
8441 fprintf (outfile, "\n\n");
8444 /* Print the information collected for a given DIE. */
8447 debug_dwarf_die (dw_die_ref die)
8449 print_die (die, stderr);
8452 /* Print all DWARF information collected for the compilation unit.
8453 This routine is a debugging aid only. */
8459 print_die (comp_unit_die, stderr);
8460 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8461 print_dwarf_line_table (stderr);
8464 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8465 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8466 DIE that marks the start of the DIEs for this include file. */
8469 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8471 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8472 dw_die_ref new_unit = gen_compile_unit_die (filename);
8474 new_unit->die_sib = old_unit;
8478 /* Close an include-file CU and reopen the enclosing one. */
8481 pop_compile_unit (dw_die_ref old_unit)
8483 dw_die_ref new_unit = old_unit->die_sib;
8485 old_unit->die_sib = NULL;
8489 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8490 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8492 /* Calculate the checksum of a location expression. */
8495 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8499 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8501 CHECKSUM (loc->dw_loc_oprnd1);
8502 CHECKSUM (loc->dw_loc_oprnd2);
8505 /* Calculate the checksum of an attribute. */
8508 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8510 dw_loc_descr_ref loc;
8513 CHECKSUM (at->dw_attr);
8515 /* We don't care that this was compiled with a different compiler
8516 snapshot; if the output is the same, that's what matters. */
8517 if (at->dw_attr == DW_AT_producer)
8520 switch (AT_class (at))
8522 case dw_val_class_const:
8523 CHECKSUM (at->dw_attr_val.v.val_int);
8525 case dw_val_class_unsigned_const:
8526 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8528 case dw_val_class_const_double:
8529 CHECKSUM (at->dw_attr_val.v.val_double);
8531 case dw_val_class_vec:
8532 CHECKSUM (at->dw_attr_val.v.val_vec);
8534 case dw_val_class_flag:
8535 CHECKSUM (at->dw_attr_val.v.val_flag);
8537 case dw_val_class_str:
8538 CHECKSUM_STRING (AT_string (at));
8541 case dw_val_class_addr:
8543 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8544 CHECKSUM_STRING (XSTR (r, 0));
8547 case dw_val_class_offset:
8548 CHECKSUM (at->dw_attr_val.v.val_offset);
8551 case dw_val_class_loc:
8552 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8553 loc_checksum (loc, ctx);
8556 case dw_val_class_die_ref:
8557 die_checksum (AT_ref (at), ctx, mark);
8560 case dw_val_class_fde_ref:
8561 case dw_val_class_vms_delta:
8562 case dw_val_class_lbl_id:
8563 case dw_val_class_lineptr:
8564 case dw_val_class_macptr:
8567 case dw_val_class_file:
8568 CHECKSUM_STRING (AT_file (at)->filename);
8571 case dw_val_class_data8:
8572 CHECKSUM (at->dw_attr_val.v.val_data8);
8580 /* Calculate the checksum of a DIE. */
8583 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8589 /* To avoid infinite recursion. */
8592 CHECKSUM (die->die_mark);
8595 die->die_mark = ++(*mark);
8597 CHECKSUM (die->die_tag);
8599 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8600 attr_checksum (a, ctx, mark);
8602 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8606 #undef CHECKSUM_STRING
8608 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8609 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8610 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8611 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8612 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8613 #define CHECKSUM_ATTR(FOO) \
8614 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8616 /* Calculate the checksum of a number in signed LEB128 format. */
8619 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8626 byte = (value & 0x7f);
8628 more = !((value == 0 && (byte & 0x40) == 0)
8629 || (value == -1 && (byte & 0x40) != 0));
8638 /* Calculate the checksum of a number in unsigned LEB128 format. */
8641 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8645 unsigned char byte = (value & 0x7f);
8648 /* More bytes to follow. */
8656 /* Checksum the context of the DIE. This adds the names of any
8657 surrounding namespaces or structures to the checksum. */
8660 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8664 int tag = die->die_tag;
8666 if (tag != DW_TAG_namespace
8667 && tag != DW_TAG_structure_type
8668 && tag != DW_TAG_class_type)
8671 name = get_AT_string (die, DW_AT_name);
8673 spec = get_AT_ref (die, DW_AT_specification);
8677 if (die->die_parent != NULL)
8678 checksum_die_context (die->die_parent, ctx);
8680 CHECKSUM_ULEB128 ('C');
8681 CHECKSUM_ULEB128 (tag);
8683 CHECKSUM_STRING (name);
8686 /* Calculate the checksum of a location expression. */
8689 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8691 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8692 were emitted as a DW_FORM_sdata instead of a location expression. */
8693 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8695 CHECKSUM_ULEB128 (DW_FORM_sdata);
8696 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8700 /* Otherwise, just checksum the raw location expression. */
8703 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8704 CHECKSUM (loc->dw_loc_oprnd1);
8705 CHECKSUM (loc->dw_loc_oprnd2);
8706 loc = loc->dw_loc_next;
8710 /* Calculate the checksum of an attribute. */
8713 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8714 struct md5_ctx *ctx, int *mark)
8716 dw_loc_descr_ref loc;
8719 if (AT_class (at) == dw_val_class_die_ref)
8721 dw_die_ref target_die = AT_ref (at);
8723 /* For pointer and reference types, we checksum only the (qualified)
8724 name of the target type (if there is a name). For friend entries,
8725 we checksum only the (qualified) name of the target type or function.
8726 This allows the checksum to remain the same whether the target type
8727 is complete or not. */
8728 if ((at->dw_attr == DW_AT_type
8729 && (tag == DW_TAG_pointer_type
8730 || tag == DW_TAG_reference_type
8731 || tag == DW_TAG_rvalue_reference_type
8732 || tag == DW_TAG_ptr_to_member_type))
8733 || (at->dw_attr == DW_AT_friend
8734 && tag == DW_TAG_friend))
8736 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8738 if (name_attr != NULL)
8740 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8744 CHECKSUM_ULEB128 ('N');
8745 CHECKSUM_ULEB128 (at->dw_attr);
8746 if (decl->die_parent != NULL)
8747 checksum_die_context (decl->die_parent, ctx);
8748 CHECKSUM_ULEB128 ('E');
8749 CHECKSUM_STRING (AT_string (name_attr));
8754 /* For all other references to another DIE, we check to see if the
8755 target DIE has already been visited. If it has, we emit a
8756 backward reference; if not, we descend recursively. */
8757 if (target_die->die_mark > 0)
8759 CHECKSUM_ULEB128 ('R');
8760 CHECKSUM_ULEB128 (at->dw_attr);
8761 CHECKSUM_ULEB128 (target_die->die_mark);
8765 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8769 target_die->die_mark = ++(*mark);
8770 CHECKSUM_ULEB128 ('T');
8771 CHECKSUM_ULEB128 (at->dw_attr);
8772 if (decl->die_parent != NULL)
8773 checksum_die_context (decl->die_parent, ctx);
8774 die_checksum_ordered (target_die, ctx, mark);
8779 CHECKSUM_ULEB128 ('A');
8780 CHECKSUM_ULEB128 (at->dw_attr);
8782 switch (AT_class (at))
8784 case dw_val_class_const:
8785 CHECKSUM_ULEB128 (DW_FORM_sdata);
8786 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
8789 case dw_val_class_unsigned_const:
8790 CHECKSUM_ULEB128 (DW_FORM_sdata);
8791 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
8794 case dw_val_class_const_double:
8795 CHECKSUM_ULEB128 (DW_FORM_block);
8796 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
8797 CHECKSUM (at->dw_attr_val.v.val_double);
8800 case dw_val_class_vec:
8801 CHECKSUM_ULEB128 (DW_FORM_block);
8802 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
8803 CHECKSUM (at->dw_attr_val.v.val_vec);
8806 case dw_val_class_flag:
8807 CHECKSUM_ULEB128 (DW_FORM_flag);
8808 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
8811 case dw_val_class_str:
8812 CHECKSUM_ULEB128 (DW_FORM_string);
8813 CHECKSUM_STRING (AT_string (at));
8816 case dw_val_class_addr:
8818 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8819 CHECKSUM_ULEB128 (DW_FORM_string);
8820 CHECKSUM_STRING (XSTR (r, 0));
8823 case dw_val_class_offset:
8824 CHECKSUM_ULEB128 (DW_FORM_sdata);
8825 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
8828 case dw_val_class_loc:
8829 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8830 loc_checksum_ordered (loc, ctx);
8833 case dw_val_class_fde_ref:
8834 case dw_val_class_lbl_id:
8835 case dw_val_class_lineptr:
8836 case dw_val_class_macptr:
8839 case dw_val_class_file:
8840 CHECKSUM_ULEB128 (DW_FORM_string);
8841 CHECKSUM_STRING (AT_file (at)->filename);
8844 case dw_val_class_data8:
8845 CHECKSUM (at->dw_attr_val.v.val_data8);
8853 struct checksum_attributes
8855 dw_attr_ref at_name;
8856 dw_attr_ref at_type;
8857 dw_attr_ref at_friend;
8858 dw_attr_ref at_accessibility;
8859 dw_attr_ref at_address_class;
8860 dw_attr_ref at_allocated;
8861 dw_attr_ref at_artificial;
8862 dw_attr_ref at_associated;
8863 dw_attr_ref at_binary_scale;
8864 dw_attr_ref at_bit_offset;
8865 dw_attr_ref at_bit_size;
8866 dw_attr_ref at_bit_stride;
8867 dw_attr_ref at_byte_size;
8868 dw_attr_ref at_byte_stride;
8869 dw_attr_ref at_const_value;
8870 dw_attr_ref at_containing_type;
8871 dw_attr_ref at_count;
8872 dw_attr_ref at_data_location;
8873 dw_attr_ref at_data_member_location;
8874 dw_attr_ref at_decimal_scale;
8875 dw_attr_ref at_decimal_sign;
8876 dw_attr_ref at_default_value;
8877 dw_attr_ref at_digit_count;
8878 dw_attr_ref at_discr;
8879 dw_attr_ref at_discr_list;
8880 dw_attr_ref at_discr_value;
8881 dw_attr_ref at_encoding;
8882 dw_attr_ref at_endianity;
8883 dw_attr_ref at_explicit;
8884 dw_attr_ref at_is_optional;
8885 dw_attr_ref at_location;
8886 dw_attr_ref at_lower_bound;
8887 dw_attr_ref at_mutable;
8888 dw_attr_ref at_ordering;
8889 dw_attr_ref at_picture_string;
8890 dw_attr_ref at_prototyped;
8891 dw_attr_ref at_small;
8892 dw_attr_ref at_segment;
8893 dw_attr_ref at_string_length;
8894 dw_attr_ref at_threads_scaled;
8895 dw_attr_ref at_upper_bound;
8896 dw_attr_ref at_use_location;
8897 dw_attr_ref at_use_UTF8;
8898 dw_attr_ref at_variable_parameter;
8899 dw_attr_ref at_virtuality;
8900 dw_attr_ref at_visibility;
8901 dw_attr_ref at_vtable_elem_location;
8904 /* Collect the attributes that we will want to use for the checksum. */
8907 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
8912 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8923 attrs->at_friend = a;
8925 case DW_AT_accessibility:
8926 attrs->at_accessibility = a;
8928 case DW_AT_address_class:
8929 attrs->at_address_class = a;
8931 case DW_AT_allocated:
8932 attrs->at_allocated = a;
8934 case DW_AT_artificial:
8935 attrs->at_artificial = a;
8937 case DW_AT_associated:
8938 attrs->at_associated = a;
8940 case DW_AT_binary_scale:
8941 attrs->at_binary_scale = a;
8943 case DW_AT_bit_offset:
8944 attrs->at_bit_offset = a;
8946 case DW_AT_bit_size:
8947 attrs->at_bit_size = a;
8949 case DW_AT_bit_stride:
8950 attrs->at_bit_stride = a;
8952 case DW_AT_byte_size:
8953 attrs->at_byte_size = a;
8955 case DW_AT_byte_stride:
8956 attrs->at_byte_stride = a;
8958 case DW_AT_const_value:
8959 attrs->at_const_value = a;
8961 case DW_AT_containing_type:
8962 attrs->at_containing_type = a;
8965 attrs->at_count = a;
8967 case DW_AT_data_location:
8968 attrs->at_data_location = a;
8970 case DW_AT_data_member_location:
8971 attrs->at_data_member_location = a;
8973 case DW_AT_decimal_scale:
8974 attrs->at_decimal_scale = a;
8976 case DW_AT_decimal_sign:
8977 attrs->at_decimal_sign = a;
8979 case DW_AT_default_value:
8980 attrs->at_default_value = a;
8982 case DW_AT_digit_count:
8983 attrs->at_digit_count = a;
8986 attrs->at_discr = a;
8988 case DW_AT_discr_list:
8989 attrs->at_discr_list = a;
8991 case DW_AT_discr_value:
8992 attrs->at_discr_value = a;
8994 case DW_AT_encoding:
8995 attrs->at_encoding = a;
8997 case DW_AT_endianity:
8998 attrs->at_endianity = a;
9000 case DW_AT_explicit:
9001 attrs->at_explicit = a;
9003 case DW_AT_is_optional:
9004 attrs->at_is_optional = a;
9006 case DW_AT_location:
9007 attrs->at_location = a;
9009 case DW_AT_lower_bound:
9010 attrs->at_lower_bound = a;
9013 attrs->at_mutable = a;
9015 case DW_AT_ordering:
9016 attrs->at_ordering = a;
9018 case DW_AT_picture_string:
9019 attrs->at_picture_string = a;
9021 case DW_AT_prototyped:
9022 attrs->at_prototyped = a;
9025 attrs->at_small = a;
9028 attrs->at_segment = a;
9030 case DW_AT_string_length:
9031 attrs->at_string_length = a;
9033 case DW_AT_threads_scaled:
9034 attrs->at_threads_scaled = a;
9036 case DW_AT_upper_bound:
9037 attrs->at_upper_bound = a;
9039 case DW_AT_use_location:
9040 attrs->at_use_location = a;
9042 case DW_AT_use_UTF8:
9043 attrs->at_use_UTF8 = a;
9045 case DW_AT_variable_parameter:
9046 attrs->at_variable_parameter = a;
9048 case DW_AT_virtuality:
9049 attrs->at_virtuality = a;
9051 case DW_AT_visibility:
9052 attrs->at_visibility = a;
9054 case DW_AT_vtable_elem_location:
9055 attrs->at_vtable_elem_location = a;
9063 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9066 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9070 struct checksum_attributes attrs;
9072 CHECKSUM_ULEB128 ('D');
9073 CHECKSUM_ULEB128 (die->die_tag);
9075 memset (&attrs, 0, sizeof (attrs));
9077 decl = get_AT_ref (die, DW_AT_specification);
9079 collect_checksum_attributes (&attrs, decl);
9080 collect_checksum_attributes (&attrs, die);
9082 CHECKSUM_ATTR (attrs.at_name);
9083 CHECKSUM_ATTR (attrs.at_accessibility);
9084 CHECKSUM_ATTR (attrs.at_address_class);
9085 CHECKSUM_ATTR (attrs.at_allocated);
9086 CHECKSUM_ATTR (attrs.at_artificial);
9087 CHECKSUM_ATTR (attrs.at_associated);
9088 CHECKSUM_ATTR (attrs.at_binary_scale);
9089 CHECKSUM_ATTR (attrs.at_bit_offset);
9090 CHECKSUM_ATTR (attrs.at_bit_size);
9091 CHECKSUM_ATTR (attrs.at_bit_stride);
9092 CHECKSUM_ATTR (attrs.at_byte_size);
9093 CHECKSUM_ATTR (attrs.at_byte_stride);
9094 CHECKSUM_ATTR (attrs.at_const_value);
9095 CHECKSUM_ATTR (attrs.at_containing_type);
9096 CHECKSUM_ATTR (attrs.at_count);
9097 CHECKSUM_ATTR (attrs.at_data_location);
9098 CHECKSUM_ATTR (attrs.at_data_member_location);
9099 CHECKSUM_ATTR (attrs.at_decimal_scale);
9100 CHECKSUM_ATTR (attrs.at_decimal_sign);
9101 CHECKSUM_ATTR (attrs.at_default_value);
9102 CHECKSUM_ATTR (attrs.at_digit_count);
9103 CHECKSUM_ATTR (attrs.at_discr);
9104 CHECKSUM_ATTR (attrs.at_discr_list);
9105 CHECKSUM_ATTR (attrs.at_discr_value);
9106 CHECKSUM_ATTR (attrs.at_encoding);
9107 CHECKSUM_ATTR (attrs.at_endianity);
9108 CHECKSUM_ATTR (attrs.at_explicit);
9109 CHECKSUM_ATTR (attrs.at_is_optional);
9110 CHECKSUM_ATTR (attrs.at_location);
9111 CHECKSUM_ATTR (attrs.at_lower_bound);
9112 CHECKSUM_ATTR (attrs.at_mutable);
9113 CHECKSUM_ATTR (attrs.at_ordering);
9114 CHECKSUM_ATTR (attrs.at_picture_string);
9115 CHECKSUM_ATTR (attrs.at_prototyped);
9116 CHECKSUM_ATTR (attrs.at_small);
9117 CHECKSUM_ATTR (attrs.at_segment);
9118 CHECKSUM_ATTR (attrs.at_string_length);
9119 CHECKSUM_ATTR (attrs.at_threads_scaled);
9120 CHECKSUM_ATTR (attrs.at_upper_bound);
9121 CHECKSUM_ATTR (attrs.at_use_location);
9122 CHECKSUM_ATTR (attrs.at_use_UTF8);
9123 CHECKSUM_ATTR (attrs.at_variable_parameter);
9124 CHECKSUM_ATTR (attrs.at_virtuality);
9125 CHECKSUM_ATTR (attrs.at_visibility);
9126 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9127 CHECKSUM_ATTR (attrs.at_type);
9128 CHECKSUM_ATTR (attrs.at_friend);
9130 /* Checksum the child DIEs, except for nested types and member functions. */
9133 dw_attr_ref name_attr;
9136 name_attr = get_AT (c, DW_AT_name);
9137 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9138 && name_attr != NULL)
9140 CHECKSUM_ULEB128 ('S');
9141 CHECKSUM_ULEB128 (c->die_tag);
9142 CHECKSUM_STRING (AT_string (name_attr));
9146 /* Mark this DIE so it gets processed when unmarking. */
9147 if (c->die_mark == 0)
9149 die_checksum_ordered (c, ctx, mark);
9151 } while (c != die->die_child);
9153 CHECKSUM_ULEB128 (0);
9157 #undef CHECKSUM_STRING
9158 #undef CHECKSUM_ATTR
9159 #undef CHECKSUM_LEB128
9160 #undef CHECKSUM_ULEB128
9162 /* Generate the type signature for DIE. This is computed by generating an
9163 MD5 checksum over the DIE's tag, its relevant attributes, and its
9164 children. Attributes that are references to other DIEs are processed
9165 by recursion, using the MARK field to prevent infinite recursion.
9166 If the DIE is nested inside a namespace or another type, we also
9167 need to include that context in the signature. The lower 64 bits
9168 of the resulting MD5 checksum comprise the signature. */
9171 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9175 unsigned char checksum[16];
9179 name = get_AT_string (die, DW_AT_name);
9180 decl = get_AT_ref (die, DW_AT_specification);
9182 /* First, compute a signature for just the type name (and its surrounding
9183 context, if any. This is stored in the type unit DIE for link-time
9184 ODR (one-definition rule) checking. */
9186 if (is_cxx() && name != NULL)
9188 md5_init_ctx (&ctx);
9190 /* Checksum the names of surrounding namespaces and structures. */
9191 if (decl != NULL && decl->die_parent != NULL)
9192 checksum_die_context (decl->die_parent, &ctx);
9194 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9195 md5_process_bytes (name, strlen (name) + 1, &ctx);
9196 md5_finish_ctx (&ctx, checksum);
9198 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9201 /* Next, compute the complete type signature. */
9203 md5_init_ctx (&ctx);
9205 die->die_mark = mark;
9207 /* Checksum the names of surrounding namespaces and structures. */
9208 if (decl != NULL && decl->die_parent != NULL)
9209 checksum_die_context (decl->die_parent, &ctx);
9211 /* Checksum the DIE and its children. */
9212 die_checksum_ordered (die, &ctx, &mark);
9213 unmark_all_dies (die);
9214 md5_finish_ctx (&ctx, checksum);
9216 /* Store the signature in the type node and link the type DIE and the
9217 type node together. */
9218 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9219 DWARF_TYPE_SIGNATURE_SIZE);
9220 die->die_id.die_type_node = type_node;
9221 type_node->type_die = die;
9223 /* If the DIE is a specification, link its declaration to the type node
9226 decl->die_id.die_type_node = type_node;
9229 /* Do the location expressions look same? */
9231 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9233 return loc1->dw_loc_opc == loc2->dw_loc_opc
9234 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9235 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9238 /* Do the values look the same? */
9240 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9242 dw_loc_descr_ref loc1, loc2;
9245 if (v1->val_class != v2->val_class)
9248 switch (v1->val_class)
9250 case dw_val_class_const:
9251 return v1->v.val_int == v2->v.val_int;
9252 case dw_val_class_unsigned_const:
9253 return v1->v.val_unsigned == v2->v.val_unsigned;
9254 case dw_val_class_const_double:
9255 return v1->v.val_double.high == v2->v.val_double.high
9256 && v1->v.val_double.low == v2->v.val_double.low;
9257 case dw_val_class_vec:
9258 if (v1->v.val_vec.length != v2->v.val_vec.length
9259 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9261 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9262 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9265 case dw_val_class_flag:
9266 return v1->v.val_flag == v2->v.val_flag;
9267 case dw_val_class_str:
9268 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9270 case dw_val_class_addr:
9271 r1 = v1->v.val_addr;
9272 r2 = v2->v.val_addr;
9273 if (GET_CODE (r1) != GET_CODE (r2))
9275 return !rtx_equal_p (r1, r2);
9277 case dw_val_class_offset:
9278 return v1->v.val_offset == v2->v.val_offset;
9280 case dw_val_class_loc:
9281 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9283 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9284 if (!same_loc_p (loc1, loc2, mark))
9286 return !loc1 && !loc2;
9288 case dw_val_class_die_ref:
9289 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9291 case dw_val_class_fde_ref:
9292 case dw_val_class_vms_delta:
9293 case dw_val_class_lbl_id:
9294 case dw_val_class_lineptr:
9295 case dw_val_class_macptr:
9298 case dw_val_class_file:
9299 return v1->v.val_file == v2->v.val_file;
9301 case dw_val_class_data8:
9302 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9309 /* Do the attributes look the same? */
9312 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9314 if (at1->dw_attr != at2->dw_attr)
9317 /* We don't care that this was compiled with a different compiler
9318 snapshot; if the output is the same, that's what matters. */
9319 if (at1->dw_attr == DW_AT_producer)
9322 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9325 /* Do the dies look the same? */
9328 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9334 /* To avoid infinite recursion. */
9336 return die1->die_mark == die2->die_mark;
9337 die1->die_mark = die2->die_mark = ++(*mark);
9339 if (die1->die_tag != die2->die_tag)
9342 if (VEC_length (dw_attr_node, die1->die_attr)
9343 != VEC_length (dw_attr_node, die2->die_attr))
9346 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9347 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9350 c1 = die1->die_child;
9351 c2 = die2->die_child;
9360 if (!same_die_p (c1, c2, mark))
9364 if (c1 == die1->die_child)
9366 if (c2 == die2->die_child)
9376 /* Do the dies look the same? Wrapper around same_die_p. */
9379 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9382 int ret = same_die_p (die1, die2, &mark);
9384 unmark_all_dies (die1);
9385 unmark_all_dies (die2);
9390 /* The prefix to attach to symbols on DIEs in the current comdat debug
9392 static char *comdat_symbol_id;
9394 /* The index of the current symbol within the current comdat CU. */
9395 static unsigned int comdat_symbol_number;
9397 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9398 children, and set comdat_symbol_id accordingly. */
9401 compute_section_prefix (dw_die_ref unit_die)
9403 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9404 const char *base = die_name ? lbasename (die_name) : "anonymous";
9405 char *name = XALLOCAVEC (char, strlen (base) + 64);
9408 unsigned char checksum[16];
9411 /* Compute the checksum of the DIE, then append part of it as hex digits to
9412 the name filename of the unit. */
9414 md5_init_ctx (&ctx);
9416 die_checksum (unit_die, &ctx, &mark);
9417 unmark_all_dies (unit_die);
9418 md5_finish_ctx (&ctx, checksum);
9420 sprintf (name, "%s.", base);
9421 clean_symbol_name (name);
9423 p = name + strlen (name);
9424 for (i = 0; i < 4; i++)
9426 sprintf (p, "%.2x", checksum[i]);
9430 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9431 comdat_symbol_number = 0;
9434 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9437 is_type_die (dw_die_ref die)
9439 switch (die->die_tag)
9441 case DW_TAG_array_type:
9442 case DW_TAG_class_type:
9443 case DW_TAG_interface_type:
9444 case DW_TAG_enumeration_type:
9445 case DW_TAG_pointer_type:
9446 case DW_TAG_reference_type:
9447 case DW_TAG_rvalue_reference_type:
9448 case DW_TAG_string_type:
9449 case DW_TAG_structure_type:
9450 case DW_TAG_subroutine_type:
9451 case DW_TAG_union_type:
9452 case DW_TAG_ptr_to_member_type:
9453 case DW_TAG_set_type:
9454 case DW_TAG_subrange_type:
9455 case DW_TAG_base_type:
9456 case DW_TAG_const_type:
9457 case DW_TAG_file_type:
9458 case DW_TAG_packed_type:
9459 case DW_TAG_volatile_type:
9460 case DW_TAG_typedef:
9467 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9468 Basically, we want to choose the bits that are likely to be shared between
9469 compilations (types) and leave out the bits that are specific to individual
9470 compilations (functions). */
9473 is_comdat_die (dw_die_ref c)
9475 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9476 we do for stabs. The advantage is a greater likelihood of sharing between
9477 objects that don't include headers in the same order (and therefore would
9478 put the base types in a different comdat). jason 8/28/00 */
9480 if (c->die_tag == DW_TAG_base_type)
9483 if (c->die_tag == DW_TAG_pointer_type
9484 || c->die_tag == DW_TAG_reference_type
9485 || c->die_tag == DW_TAG_rvalue_reference_type
9486 || c->die_tag == DW_TAG_const_type
9487 || c->die_tag == DW_TAG_volatile_type)
9489 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9491 return t ? is_comdat_die (t) : 0;
9494 return is_type_die (c);
9497 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9498 compilation unit. */
9501 is_symbol_die (dw_die_ref c)
9503 return (is_type_die (c)
9504 || is_declaration_die (c)
9505 || c->die_tag == DW_TAG_namespace
9506 || c->die_tag == DW_TAG_module);
9510 gen_internal_sym (const char *prefix)
9514 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9515 return xstrdup (buf);
9518 /* Assign symbols to all worthy DIEs under DIE. */
9521 assign_symbol_names (dw_die_ref die)
9525 if (is_symbol_die (die))
9527 if (comdat_symbol_id)
9529 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9531 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9532 comdat_symbol_id, comdat_symbol_number++);
9533 die->die_id.die_symbol = xstrdup (p);
9536 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9539 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9542 struct cu_hash_table_entry
9545 unsigned min_comdat_num, max_comdat_num;
9546 struct cu_hash_table_entry *next;
9549 /* Routines to manipulate hash table of CUs. */
9551 htab_cu_hash (const void *of)
9553 const struct cu_hash_table_entry *const entry =
9554 (const struct cu_hash_table_entry *) of;
9556 return htab_hash_string (entry->cu->die_id.die_symbol);
9560 htab_cu_eq (const void *of1, const void *of2)
9562 const struct cu_hash_table_entry *const entry1 =
9563 (const struct cu_hash_table_entry *) of1;
9564 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9566 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9570 htab_cu_del (void *what)
9572 struct cu_hash_table_entry *next,
9573 *entry = (struct cu_hash_table_entry *) what;
9583 /* Check whether we have already seen this CU and set up SYM_NUM
9586 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9588 struct cu_hash_table_entry dummy;
9589 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9591 dummy.max_comdat_num = 0;
9593 slot = (struct cu_hash_table_entry **)
9594 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9598 for (; entry; last = entry, entry = entry->next)
9600 if (same_die_p_wrap (cu, entry->cu))
9606 *sym_num = entry->min_comdat_num;
9610 entry = XCNEW (struct cu_hash_table_entry);
9612 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9613 entry->next = *slot;
9619 /* Record SYM_NUM to record of CU in HTABLE. */
9621 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9623 struct cu_hash_table_entry **slot, *entry;
9625 slot = (struct cu_hash_table_entry **)
9626 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9630 entry->max_comdat_num = sym_num;
9633 /* Traverse the DIE (which is always comp_unit_die), and set up
9634 additional compilation units for each of the include files we see
9635 bracketed by BINCL/EINCL. */
9638 break_out_includes (dw_die_ref die)
9641 dw_die_ref unit = NULL;
9642 limbo_die_node *node, **pnode;
9643 htab_t cu_hash_table;
9647 dw_die_ref prev = c;
9649 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9650 || (unit && is_comdat_die (c)))
9652 dw_die_ref next = c->die_sib;
9654 /* This DIE is for a secondary CU; remove it from the main one. */
9655 remove_child_with_prev (c, prev);
9657 if (c->die_tag == DW_TAG_GNU_BINCL)
9658 unit = push_new_compile_unit (unit, c);
9659 else if (c->die_tag == DW_TAG_GNU_EINCL)
9660 unit = pop_compile_unit (unit);
9662 add_child_die (unit, c);
9664 if (c == die->die_child)
9667 } while (c != die->die_child);
9670 /* We can only use this in debugging, since the frontend doesn't check
9671 to make sure that we leave every include file we enter. */
9675 assign_symbol_names (die);
9676 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9677 for (node = limbo_die_list, pnode = &limbo_die_list;
9683 compute_section_prefix (node->die);
9684 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9685 &comdat_symbol_number);
9686 assign_symbol_names (node->die);
9688 *pnode = node->next;
9691 pnode = &node->next;
9692 record_comdat_symbol_number (node->die, cu_hash_table,
9693 comdat_symbol_number);
9696 htab_delete (cu_hash_table);
9699 /* Return non-zero if this DIE is a declaration. */
9702 is_declaration_die (dw_die_ref die)
9707 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9708 if (a->dw_attr == DW_AT_declaration)
9714 /* Return non-zero if this DIE is nested inside a subprogram. */
9717 is_nested_in_subprogram (dw_die_ref die)
9719 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9723 return local_scope_p (decl);
9726 /* Return non-zero if this is a type DIE that should be moved to a
9727 COMDAT .debug_types section. */
9730 should_move_die_to_comdat (dw_die_ref die)
9732 switch (die->die_tag)
9734 case DW_TAG_class_type:
9735 case DW_TAG_structure_type:
9736 case DW_TAG_enumeration_type:
9737 case DW_TAG_union_type:
9738 /* Don't move declarations, inlined instances, or types nested in a
9740 if (is_declaration_die (die)
9741 || get_AT (die, DW_AT_abstract_origin)
9742 || is_nested_in_subprogram (die))
9745 case DW_TAG_array_type:
9746 case DW_TAG_interface_type:
9747 case DW_TAG_pointer_type:
9748 case DW_TAG_reference_type:
9749 case DW_TAG_rvalue_reference_type:
9750 case DW_TAG_string_type:
9751 case DW_TAG_subroutine_type:
9752 case DW_TAG_ptr_to_member_type:
9753 case DW_TAG_set_type:
9754 case DW_TAG_subrange_type:
9755 case DW_TAG_base_type:
9756 case DW_TAG_const_type:
9757 case DW_TAG_file_type:
9758 case DW_TAG_packed_type:
9759 case DW_TAG_volatile_type:
9760 case DW_TAG_typedef:
9766 /* Make a clone of DIE. */
9769 clone_die (dw_die_ref die)
9775 clone = ggc_alloc_cleared_die_node ();
9776 clone->die_tag = die->die_tag;
9778 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9779 add_dwarf_attr (clone, a);
9784 /* Make a clone of the tree rooted at DIE. */
9787 clone_tree (dw_die_ref die)
9790 dw_die_ref clone = clone_die (die);
9792 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
9797 /* Make a clone of DIE as a declaration. */
9800 clone_as_declaration (dw_die_ref die)
9807 /* If the DIE is already a declaration, just clone it. */
9808 if (is_declaration_die (die))
9809 return clone_die (die);
9811 /* If the DIE is a specification, just clone its declaration DIE. */
9812 decl = get_AT_ref (die, DW_AT_specification);
9814 return clone_die (decl);
9816 clone = ggc_alloc_cleared_die_node ();
9817 clone->die_tag = die->die_tag;
9819 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9821 /* We don't want to copy over all attributes.
9822 For example we don't want DW_AT_byte_size because otherwise we will no
9823 longer have a declaration and GDB will treat it as a definition. */
9827 case DW_AT_artificial:
9828 case DW_AT_containing_type:
9829 case DW_AT_external:
9832 case DW_AT_virtuality:
9833 case DW_AT_linkage_name:
9834 case DW_AT_MIPS_linkage_name:
9835 add_dwarf_attr (clone, a);
9837 case DW_AT_byte_size:
9843 if (die->die_id.die_type_node)
9844 add_AT_die_ref (clone, DW_AT_signature, die);
9846 add_AT_flag (clone, DW_AT_declaration, 1);
9850 /* Copy the declaration context to the new compile unit DIE. This includes
9851 any surrounding namespace or type declarations. If the DIE has an
9852 AT_specification attribute, it also includes attributes and children
9853 attached to the specification. */
9856 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
9859 dw_die_ref new_decl;
9861 decl = get_AT_ref (die, DW_AT_specification);
9870 /* Copy the type node pointer from the new DIE to the original
9871 declaration DIE so we can forward references later. */
9872 decl->die_id.die_type_node = die->die_id.die_type_node;
9874 remove_AT (die, DW_AT_specification);
9876 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
9878 if (a->dw_attr != DW_AT_name
9879 && a->dw_attr != DW_AT_declaration
9880 && a->dw_attr != DW_AT_external)
9881 add_dwarf_attr (die, a);
9884 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
9887 if (decl->die_parent != NULL
9888 && decl->die_parent->die_tag != DW_TAG_compile_unit
9889 && decl->die_parent->die_tag != DW_TAG_type_unit)
9891 new_decl = copy_ancestor_tree (unit, decl, NULL);
9892 if (new_decl != NULL)
9894 remove_AT (new_decl, DW_AT_signature);
9895 add_AT_specification (die, new_decl);
9900 /* Generate the skeleton ancestor tree for the given NODE, then clone
9901 the DIE and add the clone into the tree. */
9904 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
9906 if (node->new_die != NULL)
9909 node->new_die = clone_as_declaration (node->old_die);
9911 if (node->parent != NULL)
9913 generate_skeleton_ancestor_tree (node->parent);
9914 add_child_die (node->parent->new_die, node->new_die);
9918 /* Generate a skeleton tree of DIEs containing any declarations that are
9919 found in the original tree. We traverse the tree looking for declaration
9920 DIEs, and construct the skeleton from the bottom up whenever we find one. */
9923 generate_skeleton_bottom_up (skeleton_chain_node *parent)
9925 skeleton_chain_node node;
9928 dw_die_ref prev = NULL;
9929 dw_die_ref next = NULL;
9931 node.parent = parent;
9933 first = c = parent->old_die->die_child;
9937 if (prev == NULL || prev->die_sib == c)
9940 next = (c == first ? NULL : c->die_sib);
9942 node.new_die = NULL;
9943 if (is_declaration_die (c))
9945 /* Clone the existing DIE, move the original to the skeleton
9946 tree (which is in the main CU), and put the clone, with
9947 all the original's children, where the original came from. */
9948 dw_die_ref clone = clone_die (c);
9949 move_all_children (c, clone);
9951 replace_child (c, clone, prev);
9952 generate_skeleton_ancestor_tree (parent);
9953 add_child_die (parent->new_die, c);
9957 generate_skeleton_bottom_up (&node);
9958 } while (next != NULL);
9961 /* Wrapper function for generate_skeleton_bottom_up. */
9964 generate_skeleton (dw_die_ref die)
9966 skeleton_chain_node node;
9969 node.new_die = NULL;
9972 /* If this type definition is nested inside another type,
9973 always leave at least a declaration in its place. */
9974 if (die->die_parent != NULL && is_type_die (die->die_parent))
9975 node.new_die = clone_as_declaration (die);
9977 generate_skeleton_bottom_up (&node);
9978 return node.new_die;
9981 /* Remove the DIE from its parent, possibly replacing it with a cloned
9982 declaration. The original DIE will be moved to a new compile unit
9983 so that existing references to it follow it to the new location. If
9984 any of the original DIE's descendants is a declaration, we need to
9985 replace the original DIE with a skeleton tree and move the
9986 declarations back into the skeleton tree. */
9989 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
9991 dw_die_ref skeleton;
9993 skeleton = generate_skeleton (child);
9994 if (skeleton == NULL)
9995 remove_child_with_prev (child, prev);
9998 skeleton->die_id.die_type_node = child->die_id.die_type_node;
9999 replace_child (child, skeleton, prev);
10005 /* Traverse the DIE and set up additional .debug_types sections for each
10006 type worthy of being placed in a COMDAT section. */
10009 break_out_comdat_types (dw_die_ref die)
10013 dw_die_ref prev = NULL;
10014 dw_die_ref next = NULL;
10015 dw_die_ref unit = NULL;
10017 first = c = die->die_child;
10021 if (prev == NULL || prev->die_sib == c)
10024 next = (c == first ? NULL : c->die_sib);
10025 if (should_move_die_to_comdat (c))
10027 dw_die_ref replacement;
10028 comdat_type_node_ref type_node;
10030 /* Create a new type unit DIE as the root for the new tree, and
10031 add it to the list of comdat types. */
10032 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10033 add_AT_unsigned (unit, DW_AT_language,
10034 get_AT_unsigned (comp_unit_die, DW_AT_language));
10035 type_node = ggc_alloc_cleared_comdat_type_node ();
10036 type_node->root_die = unit;
10037 type_node->next = comdat_type_list;
10038 comdat_type_list = type_node;
10040 /* Generate the type signature. */
10041 generate_type_signature (c, type_node);
10043 /* Copy the declaration context, attributes, and children of the
10044 declaration into the new compile unit DIE. */
10045 copy_declaration_context (unit, c);
10047 /* Remove this DIE from the main CU. */
10048 replacement = remove_child_or_replace_with_skeleton (c, prev);
10050 /* Break out nested types into their own type units. */
10051 break_out_comdat_types (c);
10053 /* Add the DIE to the new compunit. */
10054 add_child_die (unit, c);
10056 if (replacement != NULL)
10059 else if (c->die_tag == DW_TAG_namespace
10060 || c->die_tag == DW_TAG_class_type
10061 || c->die_tag == DW_TAG_structure_type
10062 || c->die_tag == DW_TAG_union_type)
10064 /* Look for nested types that can be broken out. */
10065 break_out_comdat_types (c);
10067 } while (next != NULL);
10070 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10072 struct decl_table_entry
10078 /* Routines to manipulate hash table of copied declarations. */
10081 htab_decl_hash (const void *of)
10083 const struct decl_table_entry *const entry =
10084 (const struct decl_table_entry *) of;
10086 return htab_hash_pointer (entry->orig);
10090 htab_decl_eq (const void *of1, const void *of2)
10092 const struct decl_table_entry *const entry1 =
10093 (const struct decl_table_entry *) of1;
10094 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10096 return entry1->orig == entry2;
10100 htab_decl_del (void *what)
10102 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10107 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10108 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10109 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10110 to check if the ancestor has already been copied into UNIT. */
10113 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10115 dw_die_ref parent = die->die_parent;
10116 dw_die_ref new_parent = unit;
10118 void **slot = NULL;
10119 struct decl_table_entry *entry = NULL;
10123 /* Check if the entry has already been copied to UNIT. */
10124 slot = htab_find_slot_with_hash (decl_table, die,
10125 htab_hash_pointer (die), INSERT);
10126 if (*slot != HTAB_EMPTY_ENTRY)
10128 entry = (struct decl_table_entry *) *slot;
10129 return entry->copy;
10132 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10133 entry = XCNEW (struct decl_table_entry);
10135 entry->copy = NULL;
10139 if (parent != NULL)
10141 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10144 if (parent->die_tag != DW_TAG_compile_unit
10145 && parent->die_tag != DW_TAG_type_unit)
10146 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10149 copy = clone_as_declaration (die);
10150 add_child_die (new_parent, copy);
10152 if (decl_table != NULL)
10154 /* Record the pointer to the copy. */
10155 entry->copy = copy;
10161 /* Walk the DIE and its children, looking for references to incomplete
10162 or trivial types that are unmarked (i.e., that are not in the current
10166 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10172 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10174 if (AT_class (a) == dw_val_class_die_ref)
10176 dw_die_ref targ = AT_ref (a);
10177 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10179 struct decl_table_entry *entry;
10181 if (targ->die_mark != 0 || type_node != NULL)
10184 slot = htab_find_slot_with_hash (decl_table, targ,
10185 htab_hash_pointer (targ), INSERT);
10187 if (*slot != HTAB_EMPTY_ENTRY)
10189 /* TARG has already been copied, so we just need to
10190 modify the reference to point to the copy. */
10191 entry = (struct decl_table_entry *) *slot;
10192 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10196 dw_die_ref parent = unit;
10197 dw_die_ref copy = clone_tree (targ);
10199 /* Make sure the cloned tree is marked as part of the
10203 /* Record in DECL_TABLE that TARG has been copied.
10204 Need to do this now, before the recursive call,
10205 because DECL_TABLE may be expanded and SLOT
10206 would no longer be a valid pointer. */
10207 entry = XCNEW (struct decl_table_entry);
10208 entry->orig = targ;
10209 entry->copy = copy;
10212 /* If TARG has surrounding context, copy its ancestor tree
10213 into the new type unit. */
10214 if (targ->die_parent != NULL
10215 && targ->die_parent->die_tag != DW_TAG_compile_unit
10216 && targ->die_parent->die_tag != DW_TAG_type_unit)
10217 parent = copy_ancestor_tree (unit, targ->die_parent,
10220 add_child_die (parent, copy);
10221 a->dw_attr_val.v.val_die_ref.die = copy;
10223 /* Make sure the newly-copied DIE is walked. If it was
10224 installed in a previously-added context, it won't
10225 get visited otherwise. */
10226 if (parent != unit)
10228 /* Find the highest point of the newly-added tree,
10229 mark each node along the way, and walk from there. */
10230 parent->die_mark = 1;
10231 while (parent->die_parent
10232 && parent->die_parent->die_mark == 0)
10234 parent = parent->die_parent;
10235 parent->die_mark = 1;
10237 copy_decls_walk (unit, parent, decl_table);
10243 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10246 /* Copy declarations for "unworthy" types into the new comdat section.
10247 Incomplete types, modified types, and certain other types aren't broken
10248 out into comdat sections of their own, so they don't have a signature,
10249 and we need to copy the declaration into the same section so that we
10250 don't have an external reference. */
10253 copy_decls_for_unworthy_types (dw_die_ref unit)
10258 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10259 copy_decls_walk (unit, unit, decl_table);
10260 htab_delete (decl_table);
10261 unmark_dies (unit);
10264 /* Traverse the DIE and add a sibling attribute if it may have the
10265 effect of speeding up access to siblings. To save some space,
10266 avoid generating sibling attributes for DIE's without children. */
10269 add_sibling_attributes (dw_die_ref die)
10273 if (! die->die_child)
10276 if (die->die_parent && die != die->die_parent->die_child)
10277 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10279 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10282 /* Output all location lists for the DIE and its children. */
10285 output_location_lists (dw_die_ref die)
10291 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10292 if (AT_class (a) == dw_val_class_loc_list)
10293 output_loc_list (AT_loc_list (a));
10295 FOR_EACH_CHILD (die, c, output_location_lists (c));
10298 /* The format of each DIE (and its attribute value pairs) is encoded in an
10299 abbreviation table. This routine builds the abbreviation table and assigns
10300 a unique abbreviation id for each abbreviation entry. The children of each
10301 die are visited recursively. */
10304 build_abbrev_table (dw_die_ref die)
10306 unsigned long abbrev_id;
10307 unsigned int n_alloc;
10312 /* Scan the DIE references, and mark as external any that refer to
10313 DIEs from other CUs (i.e. those which are not marked). */
10314 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10315 if (AT_class (a) == dw_val_class_die_ref
10316 && AT_ref (a)->die_mark == 0)
10318 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10319 set_AT_ref_external (a, 1);
10322 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10324 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10325 dw_attr_ref die_a, abbrev_a;
10329 if (abbrev->die_tag != die->die_tag)
10331 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10334 if (VEC_length (dw_attr_node, abbrev->die_attr)
10335 != VEC_length (dw_attr_node, die->die_attr))
10338 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10340 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10341 if ((abbrev_a->dw_attr != die_a->dw_attr)
10342 || (value_format (abbrev_a) != value_format (die_a)))
10352 if (abbrev_id >= abbrev_die_table_in_use)
10354 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10356 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10357 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10360 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10361 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10362 abbrev_die_table_allocated = n_alloc;
10365 ++abbrev_die_table_in_use;
10366 abbrev_die_table[abbrev_id] = die;
10369 die->die_abbrev = abbrev_id;
10370 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10373 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10376 constant_size (unsigned HOST_WIDE_INT value)
10383 log = floor_log2 (value);
10386 log = 1 << (floor_log2 (log) + 1);
10391 /* Return the size of a DIE as it is represented in the
10392 .debug_info section. */
10394 static unsigned long
10395 size_of_die (dw_die_ref die)
10397 unsigned long size = 0;
10401 size += size_of_uleb128 (die->die_abbrev);
10402 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10404 switch (AT_class (a))
10406 case dw_val_class_addr:
10407 size += DWARF2_ADDR_SIZE;
10409 case dw_val_class_offset:
10410 size += DWARF_OFFSET_SIZE;
10412 case dw_val_class_loc:
10414 unsigned long lsize = size_of_locs (AT_loc (a));
10416 /* Block length. */
10417 if (dwarf_version >= 4)
10418 size += size_of_uleb128 (lsize);
10420 size += constant_size (lsize);
10424 case dw_val_class_loc_list:
10425 size += DWARF_OFFSET_SIZE;
10427 case dw_val_class_range_list:
10428 size += DWARF_OFFSET_SIZE;
10430 case dw_val_class_const:
10431 size += size_of_sleb128 (AT_int (a));
10433 case dw_val_class_unsigned_const:
10434 size += constant_size (AT_unsigned (a));
10436 case dw_val_class_const_double:
10437 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10438 if (HOST_BITS_PER_WIDE_INT >= 64)
10439 size++; /* block */
10441 case dw_val_class_vec:
10442 size += constant_size (a->dw_attr_val.v.val_vec.length
10443 * a->dw_attr_val.v.val_vec.elt_size)
10444 + a->dw_attr_val.v.val_vec.length
10445 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10447 case dw_val_class_flag:
10448 if (dwarf_version >= 4)
10449 /* Currently all add_AT_flag calls pass in 1 as last argument,
10450 so DW_FORM_flag_present can be used. If that ever changes,
10451 we'll need to use DW_FORM_flag and have some optimization
10452 in build_abbrev_table that will change those to
10453 DW_FORM_flag_present if it is set to 1 in all DIEs using
10454 the same abbrev entry. */
10455 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10459 case dw_val_class_die_ref:
10460 if (AT_ref_external (a))
10462 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10463 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10464 is sized by target address length, whereas in DWARF3
10465 it's always sized as an offset. */
10466 if (dwarf_version >= 4)
10467 size += DWARF_TYPE_SIGNATURE_SIZE;
10468 else if (dwarf_version == 2)
10469 size += DWARF2_ADDR_SIZE;
10471 size += DWARF_OFFSET_SIZE;
10474 size += DWARF_OFFSET_SIZE;
10476 case dw_val_class_fde_ref:
10477 size += DWARF_OFFSET_SIZE;
10479 case dw_val_class_lbl_id:
10480 size += DWARF2_ADDR_SIZE;
10482 case dw_val_class_lineptr:
10483 case dw_val_class_macptr:
10484 size += DWARF_OFFSET_SIZE;
10486 case dw_val_class_str:
10487 if (AT_string_form (a) == DW_FORM_strp)
10488 size += DWARF_OFFSET_SIZE;
10490 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10492 case dw_val_class_file:
10493 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10495 case dw_val_class_data8:
10498 case dw_val_class_vms_delta:
10499 size += DWARF_OFFSET_SIZE;
10502 gcc_unreachable ();
10509 /* Size the debugging information associated with a given DIE. Visits the
10510 DIE's children recursively. Updates the global variable next_die_offset, on
10511 each time through. Uses the current value of next_die_offset to update the
10512 die_offset field in each DIE. */
10515 calc_die_sizes (dw_die_ref die)
10519 die->die_offset = next_die_offset;
10520 next_die_offset += size_of_die (die);
10522 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10524 if (die->die_child != NULL)
10525 /* Count the null byte used to terminate sibling lists. */
10526 next_die_offset += 1;
10529 /* Set the marks for a die and its children. We do this so
10530 that we know whether or not a reference needs to use FORM_ref_addr; only
10531 DIEs in the same CU will be marked. We used to clear out the offset
10532 and use that as the flag, but ran into ordering problems. */
10535 mark_dies (dw_die_ref die)
10539 gcc_assert (!die->die_mark);
10542 FOR_EACH_CHILD (die, c, mark_dies (c));
10545 /* Clear the marks for a die and its children. */
10548 unmark_dies (dw_die_ref die)
10552 if (dwarf_version < 4)
10553 gcc_assert (die->die_mark);
10556 FOR_EACH_CHILD (die, c, unmark_dies (c));
10559 /* Clear the marks for a die, its children and referred dies. */
10562 unmark_all_dies (dw_die_ref die)
10568 if (!die->die_mark)
10572 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10574 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10575 if (AT_class (a) == dw_val_class_die_ref)
10576 unmark_all_dies (AT_ref (a));
10579 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10580 generated for the compilation unit. */
10582 static unsigned long
10583 size_of_pubnames (VEC (pubname_entry, gc) * names)
10585 unsigned long size;
10589 size = DWARF_PUBNAMES_HEADER_SIZE;
10590 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10591 if (names != pubtype_table
10592 || p->die->die_offset != 0
10593 || !flag_eliminate_unused_debug_types)
10594 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10596 size += DWARF_OFFSET_SIZE;
10600 /* Return the size of the information in the .debug_aranges section. */
10602 static unsigned long
10603 size_of_aranges (void)
10605 unsigned long size;
10607 size = DWARF_ARANGES_HEADER_SIZE;
10609 /* Count the address/length pair for this compilation unit. */
10610 if (text_section_used)
10611 size += 2 * DWARF2_ADDR_SIZE;
10612 if (cold_text_section_used)
10613 size += 2 * DWARF2_ADDR_SIZE;
10614 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10616 /* Count the two zero words used to terminated the address range table. */
10617 size += 2 * DWARF2_ADDR_SIZE;
10621 /* Select the encoding of an attribute value. */
10623 static enum dwarf_form
10624 value_format (dw_attr_ref a)
10626 switch (a->dw_attr_val.val_class)
10628 case dw_val_class_addr:
10629 /* Only very few attributes allow DW_FORM_addr. */
10630 switch (a->dw_attr)
10633 case DW_AT_high_pc:
10634 case DW_AT_entry_pc:
10635 case DW_AT_trampoline:
10636 return DW_FORM_addr;
10640 switch (DWARF2_ADDR_SIZE)
10643 return DW_FORM_data1;
10645 return DW_FORM_data2;
10647 return DW_FORM_data4;
10649 return DW_FORM_data8;
10651 gcc_unreachable ();
10653 case dw_val_class_range_list:
10654 case dw_val_class_loc_list:
10655 if (dwarf_version >= 4)
10656 return DW_FORM_sec_offset;
10658 case dw_val_class_vms_delta:
10659 case dw_val_class_offset:
10660 switch (DWARF_OFFSET_SIZE)
10663 return DW_FORM_data4;
10665 return DW_FORM_data8;
10667 gcc_unreachable ();
10669 case dw_val_class_loc:
10670 if (dwarf_version >= 4)
10671 return DW_FORM_exprloc;
10672 switch (constant_size (size_of_locs (AT_loc (a))))
10675 return DW_FORM_block1;
10677 return DW_FORM_block2;
10679 gcc_unreachable ();
10681 case dw_val_class_const:
10682 return DW_FORM_sdata;
10683 case dw_val_class_unsigned_const:
10684 switch (constant_size (AT_unsigned (a)))
10687 return DW_FORM_data1;
10689 return DW_FORM_data2;
10691 return DW_FORM_data4;
10693 return DW_FORM_data8;
10695 gcc_unreachable ();
10697 case dw_val_class_const_double:
10698 switch (HOST_BITS_PER_WIDE_INT)
10701 return DW_FORM_data2;
10703 return DW_FORM_data4;
10705 return DW_FORM_data8;
10708 return DW_FORM_block1;
10710 case dw_val_class_vec:
10711 switch (constant_size (a->dw_attr_val.v.val_vec.length
10712 * a->dw_attr_val.v.val_vec.elt_size))
10715 return DW_FORM_block1;
10717 return DW_FORM_block2;
10719 return DW_FORM_block4;
10721 gcc_unreachable ();
10723 case dw_val_class_flag:
10724 if (dwarf_version >= 4)
10726 /* Currently all add_AT_flag calls pass in 1 as last argument,
10727 so DW_FORM_flag_present can be used. If that ever changes,
10728 we'll need to use DW_FORM_flag and have some optimization
10729 in build_abbrev_table that will change those to
10730 DW_FORM_flag_present if it is set to 1 in all DIEs using
10731 the same abbrev entry. */
10732 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10733 return DW_FORM_flag_present;
10735 return DW_FORM_flag;
10736 case dw_val_class_die_ref:
10737 if (AT_ref_external (a))
10738 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
10740 return DW_FORM_ref;
10741 case dw_val_class_fde_ref:
10742 return DW_FORM_data;
10743 case dw_val_class_lbl_id:
10744 return DW_FORM_addr;
10745 case dw_val_class_lineptr:
10746 case dw_val_class_macptr:
10747 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10748 case dw_val_class_str:
10749 return AT_string_form (a);
10750 case dw_val_class_file:
10751 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10754 return DW_FORM_data1;
10756 return DW_FORM_data2;
10758 return DW_FORM_data4;
10760 gcc_unreachable ();
10763 case dw_val_class_data8:
10764 return DW_FORM_data8;
10767 gcc_unreachable ();
10771 /* Output the encoding of an attribute value. */
10774 output_value_format (dw_attr_ref a)
10776 enum dwarf_form form = value_format (a);
10778 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10781 /* Output the .debug_abbrev section which defines the DIE abbreviation
10785 output_abbrev_section (void)
10787 unsigned long abbrev_id;
10789 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10791 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10793 dw_attr_ref a_attr;
10795 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10796 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10797 dwarf_tag_name (abbrev->die_tag));
10799 if (abbrev->die_child != NULL)
10800 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10802 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10804 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
10807 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10808 dwarf_attr_name (a_attr->dw_attr));
10809 output_value_format (a_attr);
10812 dw2_asm_output_data (1, 0, NULL);
10813 dw2_asm_output_data (1, 0, NULL);
10816 /* Terminate the table. */
10817 dw2_asm_output_data (1, 0, NULL);
10820 /* Output a symbol we can use to refer to this DIE from another CU. */
10823 output_die_symbol (dw_die_ref die)
10825 char *sym = die->die_id.die_symbol;
10830 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
10831 /* We make these global, not weak; if the target doesn't support
10832 .linkonce, it doesn't support combining the sections, so debugging
10834 targetm.asm_out.globalize_label (asm_out_file, sym);
10836 ASM_OUTPUT_LABEL (asm_out_file, sym);
10839 /* Return a new location list, given the begin and end range, and the
10842 static inline dw_loc_list_ref
10843 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
10844 const char *section)
10846 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
10848 retlist->begin = begin;
10849 retlist->end = end;
10850 retlist->expr = expr;
10851 retlist->section = section;
10856 /* Generate a new internal symbol for this location list node, if it
10857 hasn't got one yet. */
10860 gen_llsym (dw_loc_list_ref list)
10862 gcc_assert (!list->ll_symbol);
10863 list->ll_symbol = gen_internal_sym ("LLST");
10866 /* Output the location list given to us. */
10869 output_loc_list (dw_loc_list_ref list_head)
10871 dw_loc_list_ref curr = list_head;
10873 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10875 /* Walk the location list, and output each range + expression. */
10876 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
10878 unsigned long size;
10879 /* Don't output an entry that starts and ends at the same address. */
10880 if (strcmp (curr->begin, curr->end) == 0)
10882 if (!have_multiple_function_sections)
10884 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10885 "Location list begin address (%s)",
10886 list_head->ll_symbol);
10887 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
10888 "Location list end address (%s)",
10889 list_head->ll_symbol);
10893 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10894 "Location list begin address (%s)",
10895 list_head->ll_symbol);
10896 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10897 "Location list end address (%s)",
10898 list_head->ll_symbol);
10900 size = size_of_locs (curr->expr);
10902 /* Output the block length for this list of location operations. */
10903 gcc_assert (size <= 0xffff);
10904 dw2_asm_output_data (2, size, "%s", "Location expression size");
10906 output_loc_sequence (curr->expr);
10909 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10910 "Location list terminator begin (%s)",
10911 list_head->ll_symbol);
10912 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10913 "Location list terminator end (%s)",
10914 list_head->ll_symbol);
10917 /* Output a type signature. */
10920 output_signature (const char *sig, const char *name)
10924 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
10925 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
10928 /* Output the DIE and its attributes. Called recursively to generate
10929 the definitions of each child DIE. */
10932 output_die (dw_die_ref die)
10936 unsigned long size;
10939 /* If someone in another CU might refer to us, set up a symbol for
10940 them to point to. */
10941 if (dwarf_version < 4 && die->die_id.die_symbol)
10942 output_die_symbol (die);
10944 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10945 (unsigned long)die->die_offset,
10946 dwarf_tag_name (die->die_tag));
10948 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10950 const char *name = dwarf_attr_name (a->dw_attr);
10952 switch (AT_class (a))
10954 case dw_val_class_addr:
10955 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10958 case dw_val_class_offset:
10959 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
10963 case dw_val_class_range_list:
10965 char *p = strchr (ranges_section_label, '\0');
10967 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
10968 a->dw_attr_val.v.val_offset);
10969 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
10970 debug_ranges_section, "%s", name);
10975 case dw_val_class_loc:
10976 size = size_of_locs (AT_loc (a));
10978 /* Output the block length for this list of location operations. */
10979 if (dwarf_version >= 4)
10980 dw2_asm_output_data_uleb128 (size, "%s", name);
10982 dw2_asm_output_data (constant_size (size), size, "%s", name);
10984 output_loc_sequence (AT_loc (a));
10987 case dw_val_class_const:
10988 /* ??? It would be slightly more efficient to use a scheme like is
10989 used for unsigned constants below, but gdb 4.x does not sign
10990 extend. Gdb 5.x does sign extend. */
10991 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10994 case dw_val_class_unsigned_const:
10995 dw2_asm_output_data (constant_size (AT_unsigned (a)),
10996 AT_unsigned (a), "%s", name);
10999 case dw_val_class_const_double:
11001 unsigned HOST_WIDE_INT first, second;
11003 if (HOST_BITS_PER_WIDE_INT >= 64)
11004 dw2_asm_output_data (1,
11005 2 * HOST_BITS_PER_WIDE_INT
11006 / HOST_BITS_PER_CHAR,
11009 if (WORDS_BIG_ENDIAN)
11011 first = a->dw_attr_val.v.val_double.high;
11012 second = a->dw_attr_val.v.val_double.low;
11016 first = a->dw_attr_val.v.val_double.low;
11017 second = a->dw_attr_val.v.val_double.high;
11020 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11022 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11027 case dw_val_class_vec:
11029 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11030 unsigned int len = a->dw_attr_val.v.val_vec.length;
11034 dw2_asm_output_data (constant_size (len * elt_size),
11035 len * elt_size, "%s", name);
11036 if (elt_size > sizeof (HOST_WIDE_INT))
11041 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11043 i++, p += elt_size)
11044 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11045 "fp or vector constant word %u", i);
11049 case dw_val_class_flag:
11050 if (dwarf_version >= 4)
11052 /* Currently all add_AT_flag calls pass in 1 as last argument,
11053 so DW_FORM_flag_present can be used. If that ever changes,
11054 we'll need to use DW_FORM_flag and have some optimization
11055 in build_abbrev_table that will change those to
11056 DW_FORM_flag_present if it is set to 1 in all DIEs using
11057 the same abbrev entry. */
11058 gcc_assert (AT_flag (a) == 1);
11059 if (flag_debug_asm)
11060 fprintf (asm_out_file, "\t\t\t%s %s\n",
11061 ASM_COMMENT_START, name);
11064 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11067 case dw_val_class_loc_list:
11069 char *sym = AT_loc_list (a)->ll_symbol;
11072 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11077 case dw_val_class_die_ref:
11078 if (AT_ref_external (a))
11080 if (dwarf_version >= 4)
11082 comdat_type_node_ref type_node =
11083 AT_ref (a)->die_id.die_type_node;
11085 gcc_assert (type_node);
11086 output_signature (type_node->signature, name);
11090 char *sym = AT_ref (a)->die_id.die_symbol;
11094 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11095 length, whereas in DWARF3 it's always sized as an
11097 if (dwarf_version == 2)
11098 size = DWARF2_ADDR_SIZE;
11100 size = DWARF_OFFSET_SIZE;
11101 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11107 gcc_assert (AT_ref (a)->die_offset);
11108 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11113 case dw_val_class_fde_ref:
11117 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11118 a->dw_attr_val.v.val_fde_index * 2);
11119 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11124 case dw_val_class_vms_delta:
11125 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11126 AT_vms_delta2 (a), AT_vms_delta1 (a),
11130 case dw_val_class_lbl_id:
11131 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11134 case dw_val_class_lineptr:
11135 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11136 debug_line_section, "%s", name);
11139 case dw_val_class_macptr:
11140 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11141 debug_macinfo_section, "%s", name);
11144 case dw_val_class_str:
11145 if (AT_string_form (a) == DW_FORM_strp)
11146 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11147 a->dw_attr_val.v.val_str->label,
11149 "%s: \"%s\"", name, AT_string (a));
11151 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11154 case dw_val_class_file:
11156 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11158 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11159 a->dw_attr_val.v.val_file->filename);
11163 case dw_val_class_data8:
11167 for (i = 0; i < 8; i++)
11168 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11169 i == 0 ? "%s" : NULL, name);
11174 gcc_unreachable ();
11178 FOR_EACH_CHILD (die, c, output_die (c));
11180 /* Add null byte to terminate sibling list. */
11181 if (die->die_child != NULL)
11182 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11183 (unsigned long) die->die_offset);
11186 /* Output the compilation unit that appears at the beginning of the
11187 .debug_info section, and precedes the DIE descriptions. */
11190 output_compilation_unit_header (void)
11192 int ver = dwarf_version;
11194 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11195 dw2_asm_output_data (4, 0xffffffff,
11196 "Initial length escape value indicating 64-bit DWARF extension");
11197 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11198 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11199 "Length of Compilation Unit Info");
11200 dw2_asm_output_data (2, ver, "DWARF version number");
11201 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11202 debug_abbrev_section,
11203 "Offset Into Abbrev. Section");
11204 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11207 /* Output the compilation unit DIE and its children. */
11210 output_comp_unit (dw_die_ref die, int output_if_empty)
11212 const char *secname;
11213 char *oldsym, *tmp;
11215 /* Unless we are outputting main CU, we may throw away empty ones. */
11216 if (!output_if_empty && die->die_child == NULL)
11219 /* Even if there are no children of this DIE, we must output the information
11220 about the compilation unit. Otherwise, on an empty translation unit, we
11221 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11222 will then complain when examining the file. First mark all the DIEs in
11223 this CU so we know which get local refs. */
11226 build_abbrev_table (die);
11228 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11229 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11230 calc_die_sizes (die);
11232 oldsym = die->die_id.die_symbol;
11235 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11237 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11239 die->die_id.die_symbol = NULL;
11240 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11243 switch_to_section (debug_info_section);
11245 /* Output debugging information. */
11246 output_compilation_unit_header ();
11249 /* Leave the marks on the main CU, so we can check them in
11250 output_pubnames. */
11254 die->die_id.die_symbol = oldsym;
11258 /* Output a comdat type unit DIE and its children. */
11261 output_comdat_type_unit (comdat_type_node *node)
11263 const char *secname;
11266 #if defined (OBJECT_FORMAT_ELF)
11270 /* First mark all the DIEs in this CU so we know which get local refs. */
11271 mark_dies (node->root_die);
11273 build_abbrev_table (node->root_die);
11275 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11276 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11277 calc_die_sizes (node->root_die);
11279 #if defined (OBJECT_FORMAT_ELF)
11280 secname = ".debug_types";
11281 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11282 sprintf (tmp, "wt.");
11283 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11284 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11285 comdat_key = get_identifier (tmp);
11286 targetm.asm_out.named_section (secname,
11287 SECTION_DEBUG | SECTION_LINKONCE,
11290 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11291 sprintf (tmp, ".gnu.linkonce.wt.");
11292 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11293 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11295 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11298 /* Output debugging information. */
11299 output_compilation_unit_header ();
11300 output_signature (node->signature, "Type Signature");
11301 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11302 "Offset to Type DIE");
11303 output_die (node->root_die);
11305 unmark_dies (node->root_die);
11308 /* Return the DWARF2/3 pubname associated with a decl. */
11310 static const char *
11311 dwarf2_name (tree decl, int scope)
11313 if (DECL_NAMELESS (decl))
11315 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11318 /* Add a new entry to .debug_pubnames if appropriate. */
11321 add_pubname_string (const char *str, dw_die_ref die)
11323 if (targetm.want_debug_pub_sections)
11328 e.name = xstrdup (str);
11329 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11334 add_pubname (tree decl, dw_die_ref die)
11336 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11338 const char *name = dwarf2_name (decl, 1);
11340 add_pubname_string (name, die);
11344 /* Add a new entry to .debug_pubtypes if appropriate. */
11347 add_pubtype (tree decl, dw_die_ref die)
11351 if (!targetm.want_debug_pub_sections)
11355 if ((TREE_PUBLIC (decl)
11356 || die->die_parent == comp_unit_die)
11357 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11362 if (TYPE_NAME (decl))
11364 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11365 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11366 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11367 && DECL_NAME (TYPE_NAME (decl)))
11368 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11370 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11375 e.name = dwarf2_name (decl, 1);
11377 e.name = xstrdup (e.name);
11380 /* If we don't have a name for the type, there's no point in adding
11381 it to the table. */
11382 if (e.name && e.name[0] != '\0')
11383 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11387 /* Output the public names table used to speed up access to externally
11388 visible names; or the public types table used to find type definitions. */
11391 output_pubnames (VEC (pubname_entry, gc) * names)
11394 unsigned long pubnames_length = size_of_pubnames (names);
11397 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11398 dw2_asm_output_data (4, 0xffffffff,
11399 "Initial length escape value indicating 64-bit DWARF extension");
11400 if (names == pubname_table)
11401 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11402 "Length of Public Names Info");
11404 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11405 "Length of Public Type Names Info");
11406 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11407 dw2_asm_output_data (2, 2, "DWARF Version");
11408 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11409 debug_info_section,
11410 "Offset of Compilation Unit Info");
11411 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11412 "Compilation Unit Length");
11414 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11416 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11417 if (names == pubname_table)
11418 gcc_assert (pub->die->die_mark);
11420 if (names != pubtype_table
11421 || pub->die->die_offset != 0
11422 || !flag_eliminate_unused_debug_types)
11424 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11427 dw2_asm_output_nstring (pub->name, -1, "external name");
11431 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11434 /* Add a new entry to .debug_aranges if appropriate. */
11437 add_arange (tree decl, dw_die_ref die)
11439 if (! DECL_SECTION_NAME (decl))
11442 if (arange_table_in_use == arange_table_allocated)
11444 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11445 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11446 arange_table_allocated);
11447 memset (arange_table + arange_table_in_use, 0,
11448 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11451 arange_table[arange_table_in_use++] = die;
11454 /* Output the information that goes into the .debug_aranges table.
11455 Namely, define the beginning and ending address range of the
11456 text section generated for this compilation unit. */
11459 output_aranges (void)
11462 unsigned long aranges_length = size_of_aranges ();
11464 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11465 dw2_asm_output_data (4, 0xffffffff,
11466 "Initial length escape value indicating 64-bit DWARF extension");
11467 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11468 "Length of Address Ranges Info");
11469 /* Version number for aranges is still 2, even in DWARF3. */
11470 dw2_asm_output_data (2, 2, "DWARF Version");
11471 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11472 debug_info_section,
11473 "Offset of Compilation Unit Info");
11474 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11475 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11477 /* We need to align to twice the pointer size here. */
11478 if (DWARF_ARANGES_PAD_SIZE)
11480 /* Pad using a 2 byte words so that padding is correct for any
11482 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11483 2 * DWARF2_ADDR_SIZE);
11484 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11485 dw2_asm_output_data (2, 0, NULL);
11488 /* It is necessary not to output these entries if the sections were
11489 not used; if the sections were not used, the length will be 0 and
11490 the address may end up as 0 if the section is discarded by ld
11491 --gc-sections, leaving an invalid (0, 0) entry that can be
11492 confused with the terminator. */
11493 if (text_section_used)
11495 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11496 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11497 text_section_label, "Length");
11499 if (cold_text_section_used)
11501 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11503 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11504 cold_text_section_label, "Length");
11507 for (i = 0; i < arange_table_in_use; i++)
11509 dw_die_ref die = arange_table[i];
11511 /* We shouldn't see aranges for DIEs outside of the main CU. */
11512 gcc_assert (die->die_mark);
11514 if (die->die_tag == DW_TAG_subprogram)
11516 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11518 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11519 get_AT_low_pc (die), "Length");
11523 /* A static variable; extract the symbol from DW_AT_location.
11524 Note that this code isn't currently hit, as we only emit
11525 aranges for functions (jason 9/23/99). */
11526 dw_attr_ref a = get_AT (die, DW_AT_location);
11527 dw_loc_descr_ref loc;
11529 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11532 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11534 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11535 loc->dw_loc_oprnd1.v.val_addr, "Address");
11536 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11537 get_AT_unsigned (die, DW_AT_byte_size),
11542 /* Output the terminator words. */
11543 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11544 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11547 /* Add a new entry to .debug_ranges. Return the offset at which it
11550 static unsigned int
11551 add_ranges_num (int num)
11553 unsigned int in_use = ranges_table_in_use;
11555 if (in_use == ranges_table_allocated)
11557 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11558 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11559 ranges_table_allocated);
11560 memset (ranges_table + ranges_table_in_use, 0,
11561 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11564 ranges_table[in_use].num = num;
11565 ranges_table_in_use = in_use + 1;
11567 return in_use * 2 * DWARF2_ADDR_SIZE;
11570 /* Add a new entry to .debug_ranges corresponding to a block, or a
11571 range terminator if BLOCK is NULL. */
11573 static unsigned int
11574 add_ranges (const_tree block)
11576 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11579 /* Add a new entry to .debug_ranges corresponding to a pair of
11583 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11586 unsigned int in_use = ranges_by_label_in_use;
11587 unsigned int offset;
11589 if (in_use == ranges_by_label_allocated)
11591 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11592 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11594 ranges_by_label_allocated);
11595 memset (ranges_by_label + ranges_by_label_in_use, 0,
11596 RANGES_TABLE_INCREMENT
11597 * sizeof (struct dw_ranges_by_label_struct));
11600 ranges_by_label[in_use].begin = begin;
11601 ranges_by_label[in_use].end = end;
11602 ranges_by_label_in_use = in_use + 1;
11604 offset = add_ranges_num (-(int)in_use - 1);
11607 add_AT_range_list (die, DW_AT_ranges, offset);
11613 output_ranges (void)
11616 static const char *const start_fmt = "Offset %#x";
11617 const char *fmt = start_fmt;
11619 for (i = 0; i < ranges_table_in_use; i++)
11621 int block_num = ranges_table[i].num;
11625 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11626 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11628 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11629 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11631 /* If all code is in the text section, then the compilation
11632 unit base address defaults to DW_AT_low_pc, which is the
11633 base of the text section. */
11634 if (!have_multiple_function_sections)
11636 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11637 text_section_label,
11638 fmt, i * 2 * DWARF2_ADDR_SIZE);
11639 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11640 text_section_label, NULL);
11643 /* Otherwise, the compilation unit base address is zero,
11644 which allows us to use absolute addresses, and not worry
11645 about whether the target supports cross-section
11649 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11650 fmt, i * 2 * DWARF2_ADDR_SIZE);
11651 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11657 /* Negative block_num stands for an index into ranges_by_label. */
11658 else if (block_num < 0)
11660 int lab_idx = - block_num - 1;
11662 if (!have_multiple_function_sections)
11664 gcc_unreachable ();
11666 /* If we ever use add_ranges_by_labels () for a single
11667 function section, all we have to do is to take out
11668 the #if 0 above. */
11669 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11670 ranges_by_label[lab_idx].begin,
11671 text_section_label,
11672 fmt, i * 2 * DWARF2_ADDR_SIZE);
11673 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11674 ranges_by_label[lab_idx].end,
11675 text_section_label, NULL);
11680 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11681 ranges_by_label[lab_idx].begin,
11682 fmt, i * 2 * DWARF2_ADDR_SIZE);
11683 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11684 ranges_by_label[lab_idx].end,
11690 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11691 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11697 /* Data structure containing information about input files. */
11700 const char *path; /* Complete file name. */
11701 const char *fname; /* File name part. */
11702 int length; /* Length of entire string. */
11703 struct dwarf_file_data * file_idx; /* Index in input file table. */
11704 int dir_idx; /* Index in directory table. */
11707 /* Data structure containing information about directories with source
11711 const char *path; /* Path including directory name. */
11712 int length; /* Path length. */
11713 int prefix; /* Index of directory entry which is a prefix. */
11714 int count; /* Number of files in this directory. */
11715 int dir_idx; /* Index of directory used as base. */
11718 /* Callback function for file_info comparison. We sort by looking at
11719 the directories in the path. */
11722 file_info_cmp (const void *p1, const void *p2)
11724 const struct file_info *const s1 = (const struct file_info *) p1;
11725 const struct file_info *const s2 = (const struct file_info *) p2;
11726 const unsigned char *cp1;
11727 const unsigned char *cp2;
11729 /* Take care of file names without directories. We need to make sure that
11730 we return consistent values to qsort since some will get confused if
11731 we return the same value when identical operands are passed in opposite
11732 orders. So if neither has a directory, return 0 and otherwise return
11733 1 or -1 depending on which one has the directory. */
11734 if ((s1->path == s1->fname || s2->path == s2->fname))
11735 return (s2->path == s2->fname) - (s1->path == s1->fname);
11737 cp1 = (const unsigned char *) s1->path;
11738 cp2 = (const unsigned char *) s2->path;
11744 /* Reached the end of the first path? If so, handle like above. */
11745 if ((cp1 == (const unsigned char *) s1->fname)
11746 || (cp2 == (const unsigned char *) s2->fname))
11747 return ((cp2 == (const unsigned char *) s2->fname)
11748 - (cp1 == (const unsigned char *) s1->fname));
11750 /* Character of current path component the same? */
11751 else if (*cp1 != *cp2)
11752 return *cp1 - *cp2;
11756 struct file_name_acquire_data
11758 struct file_info *files;
11763 /* Traversal function for the hash table. */
11766 file_name_acquire (void ** slot, void *data)
11768 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
11769 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
11770 struct file_info *fi;
11773 gcc_assert (fnad->max_files >= d->emitted_number);
11775 if (! d->emitted_number)
11778 gcc_assert (fnad->max_files != fnad->used_files);
11780 fi = fnad->files + fnad->used_files++;
11782 /* Skip all leading "./". */
11784 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
11787 /* Create a new array entry. */
11789 fi->length = strlen (f);
11792 /* Search for the file name part. */
11793 f = strrchr (f, DIR_SEPARATOR);
11794 #if defined (DIR_SEPARATOR_2)
11796 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
11800 if (f == NULL || f < g)
11806 fi->fname = f == NULL ? fi->path : f + 1;
11810 /* Output the directory table and the file name table. We try to minimize
11811 the total amount of memory needed. A heuristic is used to avoid large
11812 slowdowns with many input files. */
11815 output_file_names (void)
11817 struct file_name_acquire_data fnad;
11819 struct file_info *files;
11820 struct dir_info *dirs;
11828 if (!last_emitted_file)
11830 dw2_asm_output_data (1, 0, "End directory table");
11831 dw2_asm_output_data (1, 0, "End file name table");
11835 numfiles = last_emitted_file->emitted_number;
11837 /* Allocate the various arrays we need. */
11838 files = XALLOCAVEC (struct file_info, numfiles);
11839 dirs = XALLOCAVEC (struct dir_info, numfiles);
11841 fnad.files = files;
11842 fnad.used_files = 0;
11843 fnad.max_files = numfiles;
11844 htab_traverse (file_table, file_name_acquire, &fnad);
11845 gcc_assert (fnad.used_files == fnad.max_files);
11847 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
11849 /* Find all the different directories used. */
11850 dirs[0].path = files[0].path;
11851 dirs[0].length = files[0].fname - files[0].path;
11852 dirs[0].prefix = -1;
11854 dirs[0].dir_idx = 0;
11855 files[0].dir_idx = 0;
11858 for (i = 1; i < numfiles; i++)
11859 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
11860 && memcmp (dirs[ndirs - 1].path, files[i].path,
11861 dirs[ndirs - 1].length) == 0)
11863 /* Same directory as last entry. */
11864 files[i].dir_idx = ndirs - 1;
11865 ++dirs[ndirs - 1].count;
11871 /* This is a new directory. */
11872 dirs[ndirs].path = files[i].path;
11873 dirs[ndirs].length = files[i].fname - files[i].path;
11874 dirs[ndirs].count = 1;
11875 dirs[ndirs].dir_idx = ndirs;
11876 files[i].dir_idx = ndirs;
11878 /* Search for a prefix. */
11879 dirs[ndirs].prefix = -1;
11880 for (j = 0; j < ndirs; j++)
11881 if (dirs[j].length < dirs[ndirs].length
11882 && dirs[j].length > 1
11883 && (dirs[ndirs].prefix == -1
11884 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
11885 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
11886 dirs[ndirs].prefix = j;
11891 /* Now to the actual work. We have to find a subset of the directories which
11892 allow expressing the file name using references to the directory table
11893 with the least amount of characters. We do not do an exhaustive search
11894 where we would have to check out every combination of every single
11895 possible prefix. Instead we use a heuristic which provides nearly optimal
11896 results in most cases and never is much off. */
11897 saved = XALLOCAVEC (int, ndirs);
11898 savehere = XALLOCAVEC (int, ndirs);
11900 memset (saved, '\0', ndirs * sizeof (saved[0]));
11901 for (i = 0; i < ndirs; i++)
11906 /* We can always save some space for the current directory. But this
11907 does not mean it will be enough to justify adding the directory. */
11908 savehere[i] = dirs[i].length;
11909 total = (savehere[i] - saved[i]) * dirs[i].count;
11911 for (j = i + 1; j < ndirs; j++)
11914 if (saved[j] < dirs[i].length)
11916 /* Determine whether the dirs[i] path is a prefix of the
11920 k = dirs[j].prefix;
11921 while (k != -1 && k != (int) i)
11922 k = dirs[k].prefix;
11926 /* Yes it is. We can possibly save some memory by
11927 writing the filenames in dirs[j] relative to
11929 savehere[j] = dirs[i].length;
11930 total += (savehere[j] - saved[j]) * dirs[j].count;
11935 /* Check whether we can save enough to justify adding the dirs[i]
11937 if (total > dirs[i].length + 1)
11939 /* It's worthwhile adding. */
11940 for (j = i; j < ndirs; j++)
11941 if (savehere[j] > 0)
11943 /* Remember how much we saved for this directory so far. */
11944 saved[j] = savehere[j];
11946 /* Remember the prefix directory. */
11947 dirs[j].dir_idx = i;
11952 /* Emit the directory name table. */
11953 idx_offset = dirs[0].length > 0 ? 1 : 0;
11954 for (i = 1 - idx_offset; i < ndirs; i++)
11955 dw2_asm_output_nstring (dirs[i].path,
11957 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
11958 "Directory Entry: %#x", i + idx_offset);
11960 dw2_asm_output_data (1, 0, "End directory table");
11962 /* We have to emit them in the order of emitted_number since that's
11963 used in the debug info generation. To do this efficiently we
11964 generate a back-mapping of the indices first. */
11965 backmap = XALLOCAVEC (int, numfiles);
11966 for (i = 0; i < numfiles; i++)
11967 backmap[files[i].file_idx->emitted_number - 1] = i;
11969 /* Now write all the file names. */
11970 for (i = 0; i < numfiles; i++)
11972 int file_idx = backmap[i];
11973 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
11975 #ifdef VMS_DEBUGGING_INFO
11976 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
11978 /* Setting these fields can lead to debugger miscomparisons,
11979 but VMS Debug requires them to be set correctly. */
11984 int maxfilelen = strlen (files[file_idx].path)
11985 + dirs[dir_idx].length
11986 + MAX_VMS_VERSION_LEN + 1;
11987 char *filebuf = XALLOCAVEC (char, maxfilelen);
11989 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
11990 snprintf (filebuf, maxfilelen, "%s;%d",
11991 files[file_idx].path + dirs[dir_idx].length, ver);
11993 dw2_asm_output_nstring
11994 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
11996 /* Include directory index. */
11997 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
11999 /* Modification time. */
12000 dw2_asm_output_data_uleb128
12001 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12005 /* File length in bytes. */
12006 dw2_asm_output_data_uleb128
12007 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12011 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12012 "File Entry: %#x", (unsigned) i + 1);
12014 /* Include directory index. */
12015 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12017 /* Modification time. */
12018 dw2_asm_output_data_uleb128 (0, NULL);
12020 /* File length in bytes. */
12021 dw2_asm_output_data_uleb128 (0, NULL);
12022 #endif /* VMS_DEBUGGING_INFO */
12025 dw2_asm_output_data (1, 0, "End file name table");
12029 /* Output the source line number correspondence information. This
12030 information goes into the .debug_line section. */
12033 output_line_info (void)
12035 char l1[20], l2[20], p1[20], p2[20];
12036 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12037 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12039 unsigned n_op_args;
12040 unsigned long lt_index;
12041 unsigned long current_line;
12044 unsigned long current_file;
12045 unsigned long function;
12046 int ver = dwarf_version;
12048 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12049 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12050 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12051 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12053 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12054 dw2_asm_output_data (4, 0xffffffff,
12055 "Initial length escape value indicating 64-bit DWARF extension");
12056 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12057 "Length of Source Line Info");
12058 ASM_OUTPUT_LABEL (asm_out_file, l1);
12060 dw2_asm_output_data (2, ver, "DWARF Version");
12061 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12062 ASM_OUTPUT_LABEL (asm_out_file, p1);
12064 /* Define the architecture-dependent minimum instruction length (in
12065 bytes). In this implementation of DWARF, this field is used for
12066 information purposes only. Since GCC generates assembly language,
12067 we have no a priori knowledge of how many instruction bytes are
12068 generated for each source line, and therefore can use only the
12069 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12070 commands. Accordingly, we fix this as `1', which is "correct
12071 enough" for all architectures, and don't let the target override. */
12072 dw2_asm_output_data (1, 1,
12073 "Minimum Instruction Length");
12076 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12077 "Maximum Operations Per Instruction");
12078 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12079 "Default is_stmt_start flag");
12080 dw2_asm_output_data (1, DWARF_LINE_BASE,
12081 "Line Base Value (Special Opcodes)");
12082 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12083 "Line Range Value (Special Opcodes)");
12084 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12085 "Special Opcode Base");
12087 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12091 case DW_LNS_advance_pc:
12092 case DW_LNS_advance_line:
12093 case DW_LNS_set_file:
12094 case DW_LNS_set_column:
12095 case DW_LNS_fixed_advance_pc:
12103 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12107 /* Write out the information about the files we use. */
12108 output_file_names ();
12109 ASM_OUTPUT_LABEL (asm_out_file, p2);
12111 /* We used to set the address register to the first location in the text
12112 section here, but that didn't accomplish anything since we already
12113 have a line note for the opening brace of the first function. */
12115 /* Generate the line number to PC correspondence table, encoded as
12116 a series of state machine operations. */
12120 if (cfun && in_cold_section_p)
12121 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12123 strcpy (prev_line_label, text_section_label);
12124 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12126 dw_line_info_ref line_info = &line_info_table[lt_index];
12129 /* Disable this optimization for now; GDB wants to see two line notes
12130 at the beginning of a function so it can find the end of the
12133 /* Don't emit anything for redundant notes. Just updating the
12134 address doesn't accomplish anything, because we already assume
12135 that anything after the last address is this line. */
12136 if (line_info->dw_line_num == current_line
12137 && line_info->dw_file_num == current_file)
12141 /* Emit debug info for the address of the current line.
12143 Unfortunately, we have little choice here currently, and must always
12144 use the most general form. GCC does not know the address delta
12145 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12146 attributes which will give an upper bound on the address range. We
12147 could perhaps use length attributes to determine when it is safe to
12148 use DW_LNS_fixed_advance_pc. */
12150 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12153 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12154 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12155 "DW_LNS_fixed_advance_pc");
12156 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12160 /* This can handle any delta. This takes
12161 4+DWARF2_ADDR_SIZE bytes. */
12162 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12163 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12164 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12165 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12168 strcpy (prev_line_label, line_label);
12170 /* Emit debug info for the source file of the current line, if
12171 different from the previous line. */
12172 if (line_info->dw_file_num != current_file)
12174 current_file = line_info->dw_file_num;
12175 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12176 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12179 /* Emit debug info for the current line number, choosing the encoding
12180 that uses the least amount of space. */
12181 if (line_info->dw_line_num != current_line)
12183 line_offset = line_info->dw_line_num - current_line;
12184 line_delta = line_offset - DWARF_LINE_BASE;
12185 current_line = line_info->dw_line_num;
12186 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12187 /* This can handle deltas from -10 to 234, using the current
12188 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12190 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12191 "line %lu", current_line);
12194 /* This can handle any delta. This takes at least 4 bytes,
12195 depending on the value being encoded. */
12196 dw2_asm_output_data (1, DW_LNS_advance_line,
12197 "advance to line %lu", current_line);
12198 dw2_asm_output_data_sleb128 (line_offset, NULL);
12199 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12203 /* We still need to start a new row, so output a copy insn. */
12204 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12207 /* Emit debug info for the address of the end of the function. */
12210 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12211 "DW_LNS_fixed_advance_pc");
12212 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12216 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12217 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12218 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12219 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12222 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12223 dw2_asm_output_data_uleb128 (1, NULL);
12224 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12229 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12231 dw_separate_line_info_ref line_info
12232 = &separate_line_info_table[lt_index];
12235 /* Don't emit anything for redundant notes. */
12236 if (line_info->dw_line_num == current_line
12237 && line_info->dw_file_num == current_file
12238 && line_info->function == function)
12242 /* Emit debug info for the address of the current line. If this is
12243 a new function, or the first line of a function, then we need
12244 to handle it differently. */
12245 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12247 if (function != line_info->function)
12249 function = line_info->function;
12251 /* Set the address register to the first line in the function. */
12252 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12253 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12254 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12255 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12259 /* ??? See the DW_LNS_advance_pc comment above. */
12262 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12263 "DW_LNS_fixed_advance_pc");
12264 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12268 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12269 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12270 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12271 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12275 strcpy (prev_line_label, line_label);
12277 /* Emit debug info for the source file of the current line, if
12278 different from the previous line. */
12279 if (line_info->dw_file_num != current_file)
12281 current_file = line_info->dw_file_num;
12282 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12283 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12286 /* Emit debug info for the current line number, choosing the encoding
12287 that uses the least amount of space. */
12288 if (line_info->dw_line_num != current_line)
12290 line_offset = line_info->dw_line_num - current_line;
12291 line_delta = line_offset - DWARF_LINE_BASE;
12292 current_line = line_info->dw_line_num;
12293 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12294 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12295 "line %lu", current_line);
12298 dw2_asm_output_data (1, DW_LNS_advance_line,
12299 "advance to line %lu", current_line);
12300 dw2_asm_output_data_sleb128 (line_offset, NULL);
12301 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12305 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12313 /* If we're done with a function, end its sequence. */
12314 if (lt_index == separate_line_info_table_in_use
12315 || separate_line_info_table[lt_index].function != function)
12320 /* Emit debug info for the address of the end of the function. */
12321 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12324 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12325 "DW_LNS_fixed_advance_pc");
12326 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12330 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12331 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12332 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12333 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12336 /* Output the marker for the end of this sequence. */
12337 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12338 dw2_asm_output_data_uleb128 (1, NULL);
12339 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12343 /* Output the marker for the end of the line number info. */
12344 ASM_OUTPUT_LABEL (asm_out_file, l2);
12347 /* Return the size of the .debug_dcall table for the compilation unit. */
12349 static unsigned long
12350 size_of_dcall_table (void)
12352 unsigned long size;
12355 tree last_poc_decl = NULL;
12357 /* Header: version + debug info section pointer + pointer size. */
12358 size = 2 + DWARF_OFFSET_SIZE + 1;
12360 /* Each entry: code label + DIE offset. */
12361 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12363 gcc_assert (p->targ_die != NULL);
12364 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12365 if (p->poc_decl != last_poc_decl)
12367 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12368 gcc_assert (poc_die);
12369 last_poc_decl = p->poc_decl;
12371 size += (DWARF_OFFSET_SIZE
12372 + size_of_uleb128 (poc_die->die_offset));
12374 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12380 /* Output the direct call table used to disambiguate PC values when
12381 identical function have been merged. */
12384 output_dcall_table (void)
12387 unsigned long dcall_length = size_of_dcall_table ();
12389 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12390 tree last_poc_decl = NULL;
12392 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12393 dw2_asm_output_data (4, 0xffffffff,
12394 "Initial length escape value indicating 64-bit DWARF extension");
12395 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12396 "Length of Direct Call Table");
12397 dw2_asm_output_data (2, 4, "Version number");
12398 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12399 debug_info_section,
12400 "Offset of Compilation Unit Info");
12401 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12403 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12405 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12406 if (p->poc_decl != last_poc_decl)
12408 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12409 last_poc_decl = p->poc_decl;
12412 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12413 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12414 "Caller DIE offset");
12417 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12418 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12419 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12420 "Callee DIE offset");
12424 /* Return the size of the .debug_vcall table for the compilation unit. */
12426 static unsigned long
12427 size_of_vcall_table (void)
12429 unsigned long size;
12433 /* Header: version + pointer size. */
12436 /* Each entry: code label + vtable slot index. */
12437 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12438 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12443 /* Output the virtual call table used to disambiguate PC values when
12444 identical function have been merged. */
12447 output_vcall_table (void)
12450 unsigned long vcall_length = size_of_vcall_table ();
12452 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12454 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12455 dw2_asm_output_data (4, 0xffffffff,
12456 "Initial length escape value indicating 64-bit DWARF extension");
12457 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12458 "Length of Virtual Call Table");
12459 dw2_asm_output_data (2, 4, "Version number");
12460 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12462 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12464 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12465 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12466 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12470 /* Given a pointer to a tree node for some base type, return a pointer to
12471 a DIE that describes the given type.
12473 This routine must only be called for GCC type nodes that correspond to
12474 Dwarf base (fundamental) types. */
12477 base_type_die (tree type)
12479 dw_die_ref base_type_result;
12480 enum dwarf_type encoding;
12482 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12485 /* If this is a subtype that should not be emitted as a subrange type,
12486 use the base type. See subrange_type_for_debug_p. */
12487 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12488 type = TREE_TYPE (type);
12490 switch (TREE_CODE (type))
12493 if ((dwarf_version >= 4 || !dwarf_strict)
12494 && TYPE_NAME (type)
12495 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12496 && DECL_IS_BUILTIN (TYPE_NAME (type))
12497 && DECL_NAME (TYPE_NAME (type)))
12499 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12500 if (strcmp (name, "char16_t") == 0
12501 || strcmp (name, "char32_t") == 0)
12503 encoding = DW_ATE_UTF;
12507 if (TYPE_STRING_FLAG (type))
12509 if (TYPE_UNSIGNED (type))
12510 encoding = DW_ATE_unsigned_char;
12512 encoding = DW_ATE_signed_char;
12514 else if (TYPE_UNSIGNED (type))
12515 encoding = DW_ATE_unsigned;
12517 encoding = DW_ATE_signed;
12521 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12523 if (dwarf_version >= 3 || !dwarf_strict)
12524 encoding = DW_ATE_decimal_float;
12526 encoding = DW_ATE_lo_user;
12529 encoding = DW_ATE_float;
12532 case FIXED_POINT_TYPE:
12533 if (!(dwarf_version >= 3 || !dwarf_strict))
12534 encoding = DW_ATE_lo_user;
12535 else if (TYPE_UNSIGNED (type))
12536 encoding = DW_ATE_unsigned_fixed;
12538 encoding = DW_ATE_signed_fixed;
12541 /* Dwarf2 doesn't know anything about complex ints, so use
12542 a user defined type for it. */
12544 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12545 encoding = DW_ATE_complex_float;
12547 encoding = DW_ATE_lo_user;
12551 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12552 encoding = DW_ATE_boolean;
12556 /* No other TREE_CODEs are Dwarf fundamental types. */
12557 gcc_unreachable ();
12560 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
12562 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12563 int_size_in_bytes (type));
12564 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12566 return base_type_result;
12569 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12570 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12573 is_base_type (tree type)
12575 switch (TREE_CODE (type))
12581 case FIXED_POINT_TYPE:
12589 case QUAL_UNION_TYPE:
12590 case ENUMERAL_TYPE:
12591 case FUNCTION_TYPE:
12594 case REFERENCE_TYPE:
12601 gcc_unreachable ();
12607 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12608 node, return the size in bits for the type if it is a constant, or else
12609 return the alignment for the type if the type's size is not constant, or
12610 else return BITS_PER_WORD if the type actually turns out to be an
12611 ERROR_MARK node. */
12613 static inline unsigned HOST_WIDE_INT
12614 simple_type_size_in_bits (const_tree type)
12616 if (TREE_CODE (type) == ERROR_MARK)
12617 return BITS_PER_WORD;
12618 else if (TYPE_SIZE (type) == NULL_TREE)
12620 else if (host_integerp (TYPE_SIZE (type), 1))
12621 return tree_low_cst (TYPE_SIZE (type), 1);
12623 return TYPE_ALIGN (type);
12626 /* Similarly, but return a double_int instead of UHWI. */
12628 static inline double_int
12629 double_int_type_size_in_bits (const_tree type)
12631 if (TREE_CODE (type) == ERROR_MARK)
12632 return uhwi_to_double_int (BITS_PER_WORD);
12633 else if (TYPE_SIZE (type) == NULL_TREE)
12634 return double_int_zero;
12635 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12636 return tree_to_double_int (TYPE_SIZE (type));
12638 return uhwi_to_double_int (TYPE_ALIGN (type));
12641 /* Given a pointer to a tree node for a subrange type, return a pointer
12642 to a DIE that describes the given type. */
12645 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12647 dw_die_ref subrange_die;
12648 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12650 if (context_die == NULL)
12651 context_die = comp_unit_die;
12653 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12655 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12657 /* The size of the subrange type and its base type do not match,
12658 so we need to generate a size attribute for the subrange type. */
12659 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12663 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12665 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12667 return subrange_die;
12670 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12671 entry that chains various modifiers in front of the given type. */
12674 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12675 dw_die_ref context_die)
12677 enum tree_code code = TREE_CODE (type);
12678 dw_die_ref mod_type_die;
12679 dw_die_ref sub_die = NULL;
12680 tree item_type = NULL;
12681 tree qualified_type;
12682 tree name, low, high;
12684 if (code == ERROR_MARK)
12687 /* See if we already have the appropriately qualified variant of
12690 = get_qualified_type (type,
12691 ((is_const_type ? TYPE_QUAL_CONST : 0)
12692 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12694 if (qualified_type == sizetype
12695 && TYPE_NAME (qualified_type)
12696 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12698 #ifdef ENABLE_CHECKING
12699 gcc_assert (TREE_CODE (TREE_TYPE (TYPE_NAME (qualified_type)))
12701 && TYPE_PRECISION (TREE_TYPE (TYPE_NAME (qualified_type)))
12702 == TYPE_PRECISION (qualified_type)
12703 && TYPE_UNSIGNED (TREE_TYPE (TYPE_NAME (qualified_type)))
12704 == TYPE_UNSIGNED (qualified_type));
12706 qualified_type = TREE_TYPE (TYPE_NAME (qualified_type));
12709 /* If we do, then we can just use its DIE, if it exists. */
12710 if (qualified_type)
12712 mod_type_die = lookup_type_die (qualified_type);
12714 return mod_type_die;
12717 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12719 /* Handle C typedef types. */
12720 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12721 && !DECL_ARTIFICIAL (name))
12723 tree dtype = TREE_TYPE (name);
12725 if (qualified_type == dtype)
12727 /* For a named type, use the typedef. */
12728 gen_type_die (qualified_type, context_die);
12729 return lookup_type_die (qualified_type);
12731 else if (is_const_type < TYPE_READONLY (dtype)
12732 || is_volatile_type < TYPE_VOLATILE (dtype)
12733 || (is_const_type <= TYPE_READONLY (dtype)
12734 && is_volatile_type <= TYPE_VOLATILE (dtype)
12735 && DECL_ORIGINAL_TYPE (name) != type))
12736 /* cv-unqualified version of named type. Just use the unnamed
12737 type to which it refers. */
12738 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12739 is_const_type, is_volatile_type,
12741 /* Else cv-qualified version of named type; fall through. */
12746 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
12747 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12749 else if (is_volatile_type)
12751 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
12752 sub_die = modified_type_die (type, 0, 0, context_die);
12754 else if (code == POINTER_TYPE)
12756 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
12757 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12758 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12759 item_type = TREE_TYPE (type);
12760 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12761 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12762 TYPE_ADDR_SPACE (item_type));
12764 else if (code == REFERENCE_TYPE)
12766 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12767 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die,
12770 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
12771 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12772 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12773 item_type = TREE_TYPE (type);
12774 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12775 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12776 TYPE_ADDR_SPACE (item_type));
12778 else if (code == INTEGER_TYPE
12779 && TREE_TYPE (type) != NULL_TREE
12780 && subrange_type_for_debug_p (type, &low, &high))
12782 mod_type_die = subrange_type_die (type, low, high, context_die);
12783 item_type = TREE_TYPE (type);
12785 else if (is_base_type (type))
12786 mod_type_die = base_type_die (type);
12789 gen_type_die (type, context_die);
12791 /* We have to get the type_main_variant here (and pass that to the
12792 `lookup_type_die' routine) because the ..._TYPE node we have
12793 might simply be a *copy* of some original type node (where the
12794 copy was created to help us keep track of typedef names) and
12795 that copy might have a different TYPE_UID from the original
12797 if (TREE_CODE (type) != VECTOR_TYPE)
12798 return lookup_type_die (type_main_variant (type));
12800 /* Vectors have the debugging information in the type,
12801 not the main variant. */
12802 return lookup_type_die (type);
12805 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12806 don't output a DW_TAG_typedef, since there isn't one in the
12807 user's program; just attach a DW_AT_name to the type.
12808 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12809 if the base type already has the same name. */
12811 && ((TREE_CODE (name) != TYPE_DECL
12812 && (qualified_type == TYPE_MAIN_VARIANT (type)
12813 || (!is_const_type && !is_volatile_type)))
12814 || (TREE_CODE (name) == TYPE_DECL
12815 && TREE_TYPE (name) == qualified_type
12816 && DECL_NAME (name))))
12818 if (TREE_CODE (name) == TYPE_DECL)
12819 /* Could just call add_name_and_src_coords_attributes here,
12820 but since this is a builtin type it doesn't have any
12821 useful source coordinates anyway. */
12822 name = DECL_NAME (name);
12823 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12825 /* This probably indicates a bug. */
12826 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12827 add_name_attribute (mod_type_die, "__unknown__");
12829 if (qualified_type)
12830 equate_type_number_to_die (qualified_type, mod_type_die);
12833 /* We must do this after the equate_type_number_to_die call, in case
12834 this is a recursive type. This ensures that the modified_type_die
12835 recursion will terminate even if the type is recursive. Recursive
12836 types are possible in Ada. */
12837 sub_die = modified_type_die (item_type,
12838 TYPE_READONLY (item_type),
12839 TYPE_VOLATILE (item_type),
12842 if (sub_die != NULL)
12843 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12845 return mod_type_die;
12848 /* Generate DIEs for the generic parameters of T.
12849 T must be either a generic type or a generic function.
12850 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12853 gen_generic_params_dies (tree t)
12857 dw_die_ref die = NULL;
12859 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12863 die = lookup_type_die (t);
12864 else if (DECL_P (t))
12865 die = lookup_decl_die (t);
12869 parms = lang_hooks.get_innermost_generic_parms (t);
12871 /* T has no generic parameter. It means T is neither a generic type
12872 or function. End of story. */
12875 parms_num = TREE_VEC_LENGTH (parms);
12876 args = lang_hooks.get_innermost_generic_args (t);
12877 for (i = 0; i < parms_num; i++)
12879 tree parm, arg, arg_pack_elems;
12881 parm = TREE_VEC_ELT (parms, i);
12882 arg = TREE_VEC_ELT (args, i);
12883 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
12884 gcc_assert (parm && TREE_VALUE (parm) && arg);
12886 if (parm && TREE_VALUE (parm) && arg)
12888 /* If PARM represents a template parameter pack,
12889 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12890 by DW_TAG_template_*_parameter DIEs for the argument
12891 pack elements of ARG. Note that ARG would then be
12892 an argument pack. */
12893 if (arg_pack_elems)
12894 template_parameter_pack_die (TREE_VALUE (parm),
12898 generic_parameter_die (TREE_VALUE (parm), arg,
12899 true /* Emit DW_AT_name */, die);
12904 /* Create and return a DIE for PARM which should be
12905 the representation of a generic type parameter.
12906 For instance, in the C++ front end, PARM would be a template parameter.
12907 ARG is the argument to PARM.
12908 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12910 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12911 as a child node. */
12914 generic_parameter_die (tree parm, tree arg,
12916 dw_die_ref parent_die)
12918 dw_die_ref tmpl_die = NULL;
12919 const char *name = NULL;
12921 if (!parm || !DECL_NAME (parm) || !arg)
12924 /* We support non-type generic parameters and arguments,
12925 type generic parameters and arguments, as well as
12926 generic generic parameters (a.k.a. template template parameters in C++)
12928 if (TREE_CODE (parm) == PARM_DECL)
12929 /* PARM is a nontype generic parameter */
12930 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
12931 else if (TREE_CODE (parm) == TYPE_DECL)
12932 /* PARM is a type generic parameter. */
12933 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
12934 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12935 /* PARM is a generic generic parameter.
12936 Its DIE is a GNU extension. It shall have a
12937 DW_AT_name attribute to represent the name of the template template
12938 parameter, and a DW_AT_GNU_template_name attribute to represent the
12939 name of the template template argument. */
12940 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
12943 gcc_unreachable ();
12949 /* If PARM is a generic parameter pack, it means we are
12950 emitting debug info for a template argument pack element.
12951 In other terms, ARG is a template argument pack element.
12952 In that case, we don't emit any DW_AT_name attribute for
12956 name = IDENTIFIER_POINTER (DECL_NAME (parm));
12958 add_AT_string (tmpl_die, DW_AT_name, name);
12961 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12963 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
12964 TMPL_DIE should have a child DW_AT_type attribute that is set
12965 to the type of the argument to PARM, which is ARG.
12966 If PARM is a type generic parameter, TMPL_DIE should have a
12967 child DW_AT_type that is set to ARG. */
12968 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
12969 add_type_attribute (tmpl_die, tmpl_type, 0,
12970 TREE_THIS_VOLATILE (tmpl_type),
12975 /* So TMPL_DIE is a DIE representing a
12976 a generic generic template parameter, a.k.a template template
12977 parameter in C++ and arg is a template. */
12979 /* The DW_AT_GNU_template_name attribute of the DIE must be set
12980 to the name of the argument. */
12981 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
12983 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
12986 if (TREE_CODE (parm) == PARM_DECL)
12987 /* So PARM is a non-type generic parameter.
12988 DWARF3 5.6.8 says we must set a DW_AT_const_value child
12989 attribute of TMPL_DIE which value represents the value
12991 We must be careful here:
12992 The value of ARG might reference some function decls.
12993 We might currently be emitting debug info for a generic
12994 type and types are emitted before function decls, we don't
12995 know if the function decls referenced by ARG will actually be
12996 emitted after cgraph computations.
12997 So must defer the generation of the DW_AT_const_value to
12998 after cgraph is ready. */
12999 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13005 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13006 PARM_PACK must be a template parameter pack. The returned DIE
13007 will be child DIE of PARENT_DIE. */
13010 template_parameter_pack_die (tree parm_pack,
13011 tree parm_pack_args,
13012 dw_die_ref parent_die)
13017 gcc_assert (parent_die && parm_pack);
13019 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13020 add_name_and_src_coords_attributes (die, parm_pack);
13021 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13022 generic_parameter_die (parm_pack,
13023 TREE_VEC_ELT (parm_pack_args, j),
13024 false /* Don't emit DW_AT_name */,
13029 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13030 an enumerated type. */
13033 type_is_enum (const_tree type)
13035 return TREE_CODE (type) == ENUMERAL_TYPE;
13038 /* Return the DBX register number described by a given RTL node. */
13040 static unsigned int
13041 dbx_reg_number (const_rtx rtl)
13043 unsigned regno = REGNO (rtl);
13045 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13047 #ifdef LEAF_REG_REMAP
13048 if (current_function_uses_only_leaf_regs)
13050 int leaf_reg = LEAF_REG_REMAP (regno);
13051 if (leaf_reg != -1)
13052 regno = (unsigned) leaf_reg;
13056 return DBX_REGISTER_NUMBER (regno);
13059 /* Optionally add a DW_OP_piece term to a location description expression.
13060 DW_OP_piece is only added if the location description expression already
13061 doesn't end with DW_OP_piece. */
13064 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13066 dw_loc_descr_ref loc;
13068 if (*list_head != NULL)
13070 /* Find the end of the chain. */
13071 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13074 if (loc->dw_loc_opc != DW_OP_piece)
13075 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13079 /* Return a location descriptor that designates a machine register or
13080 zero if there is none. */
13082 static dw_loc_descr_ref
13083 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13087 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13090 /* We only use "frame base" when we're sure we're talking about the
13091 post-prologue local stack frame. We do this by *not* running
13092 register elimination until this point, and recognizing the special
13093 argument pointer and soft frame pointer rtx's.
13094 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13095 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13096 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13098 dw_loc_descr_ref result = NULL;
13100 if (dwarf_version >= 4 || !dwarf_strict)
13102 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13104 add_loc_descr (&result,
13105 new_loc_descr (DW_OP_stack_value, 0, 0));
13110 regs = targetm.dwarf_register_span (rtl);
13112 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13113 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13115 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13118 /* Return a location descriptor that designates a machine register for
13119 a given hard register number. */
13121 static dw_loc_descr_ref
13122 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13124 dw_loc_descr_ref reg_loc_descr;
13128 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13130 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13132 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13133 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13135 return reg_loc_descr;
13138 /* Given an RTL of a register, return a location descriptor that
13139 designates a value that spans more than one register. */
13141 static dw_loc_descr_ref
13142 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13143 enum var_init_status initialized)
13145 int nregs, size, i;
13147 dw_loc_descr_ref loc_result = NULL;
13150 #ifdef LEAF_REG_REMAP
13151 if (current_function_uses_only_leaf_regs)
13153 int leaf_reg = LEAF_REG_REMAP (reg);
13154 if (leaf_reg != -1)
13155 reg = (unsigned) leaf_reg;
13158 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13159 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13161 /* Simple, contiguous registers. */
13162 if (regs == NULL_RTX)
13164 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13169 dw_loc_descr_ref t;
13171 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13172 VAR_INIT_STATUS_INITIALIZED);
13173 add_loc_descr (&loc_result, t);
13174 add_loc_descr_op_piece (&loc_result, size);
13180 /* Now onto stupid register sets in non contiguous locations. */
13182 gcc_assert (GET_CODE (regs) == PARALLEL);
13184 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13187 for (i = 0; i < XVECLEN (regs, 0); ++i)
13189 dw_loc_descr_ref t;
13191 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13192 VAR_INIT_STATUS_INITIALIZED);
13193 add_loc_descr (&loc_result, t);
13194 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13195 add_loc_descr_op_piece (&loc_result, size);
13198 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13199 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13203 /* Return a location descriptor that designates a constant. */
13205 static dw_loc_descr_ref
13206 int_loc_descriptor (HOST_WIDE_INT i)
13208 enum dwarf_location_atom op;
13210 /* Pick the smallest representation of a constant, rather than just
13211 defaulting to the LEB encoding. */
13215 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13216 else if (i <= 0xff)
13217 op = DW_OP_const1u;
13218 else if (i <= 0xffff)
13219 op = DW_OP_const2u;
13220 else if (HOST_BITS_PER_WIDE_INT == 32
13221 || i <= 0xffffffff)
13222 op = DW_OP_const4u;
13229 op = DW_OP_const1s;
13230 else if (i >= -0x8000)
13231 op = DW_OP_const2s;
13232 else if (HOST_BITS_PER_WIDE_INT == 32
13233 || i >= -0x80000000)
13234 op = DW_OP_const4s;
13239 return new_loc_descr (op, i, 0);
13242 /* Return loc description representing "address" of integer value.
13243 This can appear only as toplevel expression. */
13245 static dw_loc_descr_ref
13246 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13249 dw_loc_descr_ref loc_result = NULL;
13251 if (!(dwarf_version >= 4 || !dwarf_strict))
13258 else if (i <= 0xff)
13260 else if (i <= 0xffff)
13262 else if (HOST_BITS_PER_WIDE_INT == 32
13263 || i <= 0xffffffff)
13266 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13272 else if (i >= -0x8000)
13274 else if (HOST_BITS_PER_WIDE_INT == 32
13275 || i >= -0x80000000)
13278 litsize = 1 + size_of_sleb128 (i);
13280 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13281 is more compact. For DW_OP_stack_value we need:
13282 litsize + 1 (DW_OP_stack_value)
13283 and for DW_OP_implicit_value:
13284 1 (DW_OP_implicit_value) + 1 (length) + size. */
13285 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13287 loc_result = int_loc_descriptor (i);
13288 add_loc_descr (&loc_result,
13289 new_loc_descr (DW_OP_stack_value, 0, 0));
13293 loc_result = new_loc_descr (DW_OP_implicit_value,
13295 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13296 loc_result->dw_loc_oprnd2.v.val_int = i;
13300 /* Return a location descriptor that designates a base+offset location. */
13302 static dw_loc_descr_ref
13303 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13304 enum var_init_status initialized)
13306 unsigned int regno;
13307 dw_loc_descr_ref result;
13308 dw_fde_ref fde = current_fde ();
13310 /* We only use "frame base" when we're sure we're talking about the
13311 post-prologue local stack frame. We do this by *not* running
13312 register elimination until this point, and recognizing the special
13313 argument pointer and soft frame pointer rtx's. */
13314 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13316 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13320 if (GET_CODE (elim) == PLUS)
13322 offset += INTVAL (XEXP (elim, 1));
13323 elim = XEXP (elim, 0);
13325 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13326 && (elim == hard_frame_pointer_rtx
13327 || elim == stack_pointer_rtx))
13328 || elim == (frame_pointer_needed
13329 ? hard_frame_pointer_rtx
13330 : stack_pointer_rtx));
13332 /* If drap register is used to align stack, use frame
13333 pointer + offset to access stack variables. If stack
13334 is aligned without drap, use stack pointer + offset to
13335 access stack variables. */
13336 if (crtl->stack_realign_tried
13337 && reg == frame_pointer_rtx)
13340 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13341 ? HARD_FRAME_POINTER_REGNUM
13342 : STACK_POINTER_REGNUM);
13343 return new_reg_loc_descr (base_reg, offset);
13346 offset += frame_pointer_fb_offset;
13347 return new_loc_descr (DW_OP_fbreg, offset, 0);
13352 && (fde->drap_reg == REGNO (reg)
13353 || fde->vdrap_reg == REGNO (reg)))
13355 /* Use cfa+offset to represent the location of arguments passed
13356 on the stack when drap is used to align stack.
13357 Only do this when not optimizing, for optimized code var-tracking
13358 is supposed to track where the arguments live and the register
13359 used as vdrap or drap in some spot might be used for something
13360 else in other part of the routine. */
13361 return new_loc_descr (DW_OP_fbreg, offset, 0);
13364 regno = dbx_reg_number (reg);
13366 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13369 result = new_loc_descr (DW_OP_bregx, regno, offset);
13371 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13372 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13377 /* Return true if this RTL expression describes a base+offset calculation. */
13380 is_based_loc (const_rtx rtl)
13382 return (GET_CODE (rtl) == PLUS
13383 && ((REG_P (XEXP (rtl, 0))
13384 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13385 && CONST_INT_P (XEXP (rtl, 1)))));
13388 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13391 static dw_loc_descr_ref
13392 tls_mem_loc_descriptor (rtx mem)
13395 dw_loc_descr_ref loc_result;
13397 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13400 base = get_base_address (MEM_EXPR (mem));
13402 || TREE_CODE (base) != VAR_DECL
13403 || !DECL_THREAD_LOCAL_P (base))
13406 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13407 if (loc_result == NULL)
13410 if (INTVAL (MEM_OFFSET (mem)))
13411 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13416 /* Output debug info about reason why we failed to expand expression as dwarf
13420 expansion_failed (tree expr, rtx rtl, char const *reason)
13422 if (dump_file && (dump_flags & TDF_DETAILS))
13424 fprintf (dump_file, "Failed to expand as dwarf: ");
13426 print_generic_expr (dump_file, expr, dump_flags);
13429 fprintf (dump_file, "\n");
13430 print_rtl (dump_file, rtl);
13432 fprintf (dump_file, "\nReason: %s\n", reason);
13436 /* Helper function for const_ok_for_output, called either directly
13437 or via for_each_rtx. */
13440 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13444 if (GET_CODE (rtl) == UNSPEC)
13446 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13447 we can't express it in the debug info. */
13448 #ifdef ENABLE_CHECKING
13449 inform (current_function_decl
13450 ? DECL_SOURCE_LOCATION (current_function_decl)
13451 : UNKNOWN_LOCATION,
13452 "non-delegitimized UNSPEC %d found in variable location",
13455 expansion_failed (NULL_TREE, rtl,
13456 "UNSPEC hasn't been delegitimized.\n");
13460 if (GET_CODE (rtl) != SYMBOL_REF)
13463 if (CONSTANT_POOL_ADDRESS_P (rtl))
13466 get_pool_constant_mark (rtl, &marked);
13467 /* If all references to this pool constant were optimized away,
13468 it was not output and thus we can't represent it. */
13471 expansion_failed (NULL_TREE, rtl,
13472 "Constant was removed from constant pool.\n");
13477 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13480 /* Avoid references to external symbols in debug info, on several targets
13481 the linker might even refuse to link when linking a shared library,
13482 and in many other cases the relocations for .debug_info/.debug_loc are
13483 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13484 to be defined within the same shared library or executable are fine. */
13485 if (SYMBOL_REF_EXTERNAL_P (rtl))
13487 tree decl = SYMBOL_REF_DECL (rtl);
13489 if (decl == NULL || !targetm.binds_local_p (decl))
13491 expansion_failed (NULL_TREE, rtl,
13492 "Symbol not defined in current TU.\n");
13500 /* Return true if constant RTL can be emitted in DW_OP_addr or
13501 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13502 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13505 const_ok_for_output (rtx rtl)
13507 if (GET_CODE (rtl) == SYMBOL_REF)
13508 return const_ok_for_output_1 (&rtl, NULL) == 0;
13510 if (GET_CODE (rtl) == CONST)
13511 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13516 /* The following routine converts the RTL for a variable or parameter
13517 (resident in memory) into an equivalent Dwarf representation of a
13518 mechanism for getting the address of that same variable onto the top of a
13519 hypothetical "address evaluation" stack.
13521 When creating memory location descriptors, we are effectively transforming
13522 the RTL for a memory-resident object into its Dwarf postfix expression
13523 equivalent. This routine recursively descends an RTL tree, turning
13524 it into Dwarf postfix code as it goes.
13526 MODE is the mode of the memory reference, needed to handle some
13527 autoincrement addressing modes.
13529 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13530 location list for RTL.
13532 Return 0 if we can't represent the location. */
13534 static dw_loc_descr_ref
13535 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13536 enum var_init_status initialized)
13538 dw_loc_descr_ref mem_loc_result = NULL;
13539 enum dwarf_location_atom op;
13540 dw_loc_descr_ref op0, op1;
13542 /* Note that for a dynamically sized array, the location we will generate a
13543 description of here will be the lowest numbered location which is
13544 actually within the array. That's *not* necessarily the same as the
13545 zeroth element of the array. */
13547 rtl = targetm.delegitimize_address (rtl);
13549 switch (GET_CODE (rtl))
13554 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13557 /* The case of a subreg may arise when we have a local (register)
13558 variable or a formal (register) parameter which doesn't quite fill
13559 up an entire register. For now, just assume that it is
13560 legitimate to make the Dwarf info refer to the whole register which
13561 contains the given subreg. */
13562 if (!subreg_lowpart_p (rtl))
13564 rtl = SUBREG_REG (rtl);
13565 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13567 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13569 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13573 /* Whenever a register number forms a part of the description of the
13574 method for calculating the (dynamic) address of a memory resident
13575 object, DWARF rules require the register number be referred to as
13576 a "base register". This distinction is not based in any way upon
13577 what category of register the hardware believes the given register
13578 belongs to. This is strictly DWARF terminology we're dealing with
13579 here. Note that in cases where the location of a memory-resident
13580 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13581 OP_CONST (0)) the actual DWARF location descriptor that we generate
13582 may just be OP_BASEREG (basereg). This may look deceptively like
13583 the object in question was allocated to a register (rather than in
13584 memory) so DWARF consumers need to be aware of the subtle
13585 distinction between OP_REG and OP_BASEREG. */
13586 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13587 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13588 else if (stack_realign_drap
13590 && crtl->args.internal_arg_pointer == rtl
13591 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13593 /* If RTL is internal_arg_pointer, which has been optimized
13594 out, use DRAP instead. */
13595 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13596 VAR_INIT_STATUS_INITIALIZED);
13602 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13603 VAR_INIT_STATUS_INITIALIZED);
13608 int shift = DWARF2_ADDR_SIZE
13609 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13610 shift *= BITS_PER_UNIT;
13611 if (GET_CODE (rtl) == SIGN_EXTEND)
13615 mem_loc_result = op0;
13616 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13617 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13618 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13619 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13624 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13625 VAR_INIT_STATUS_INITIALIZED);
13626 if (mem_loc_result == NULL)
13627 mem_loc_result = tls_mem_loc_descriptor (rtl);
13628 if (mem_loc_result != 0)
13630 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13632 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13635 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13636 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13638 add_loc_descr (&mem_loc_result,
13639 new_loc_descr (DW_OP_deref_size,
13640 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13644 rtx new_rtl = avoid_constant_pool_reference (rtl);
13645 if (new_rtl != rtl)
13646 return mem_loc_descriptor (new_rtl, mode, initialized);
13651 rtl = XEXP (rtl, 1);
13653 /* ... fall through ... */
13656 /* Some ports can transform a symbol ref into a label ref, because
13657 the symbol ref is too far away and has to be dumped into a constant
13661 if (GET_CODE (rtl) == SYMBOL_REF
13662 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13664 dw_loc_descr_ref temp;
13666 /* If this is not defined, we have no way to emit the data. */
13667 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13670 /* We used to emit DW_OP_addr here, but that's wrong, since
13671 DW_OP_addr should be relocated by the debug info consumer,
13672 while DW_OP_GNU_push_tls_address operand should not. */
13673 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13674 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13675 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13676 temp->dw_loc_oprnd1.v.val_addr = rtl;
13677 temp->dtprel = true;
13679 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13680 add_loc_descr (&mem_loc_result, temp);
13685 if (!const_ok_for_output (rtl))
13689 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13690 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13691 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13692 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13698 case DEBUG_IMPLICIT_PTR:
13699 expansion_failed (NULL_TREE, rtl,
13700 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13704 /* Extract the PLUS expression nested inside and fall into
13705 PLUS code below. */
13706 rtl = XEXP (rtl, 1);
13711 /* Turn these into a PLUS expression and fall into the PLUS code
13713 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13714 GEN_INT (GET_CODE (rtl) == PRE_INC
13715 ? GET_MODE_UNIT_SIZE (mode)
13716 : -GET_MODE_UNIT_SIZE (mode)));
13718 /* ... fall through ... */
13722 if (is_based_loc (rtl))
13723 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13724 INTVAL (XEXP (rtl, 1)),
13725 VAR_INIT_STATUS_INITIALIZED);
13728 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13729 VAR_INIT_STATUS_INITIALIZED);
13730 if (mem_loc_result == 0)
13733 if (CONST_INT_P (XEXP (rtl, 1)))
13734 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13737 dw_loc_descr_ref mem_loc_result2
13738 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13739 VAR_INIT_STATUS_INITIALIZED);
13740 if (mem_loc_result2 == 0)
13742 add_loc_descr (&mem_loc_result, mem_loc_result2);
13743 add_loc_descr (&mem_loc_result,
13744 new_loc_descr (DW_OP_plus, 0, 0));
13749 /* If a pseudo-reg is optimized away, it is possible for it to
13750 be replaced with a MEM containing a multiply or shift. */
13792 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13793 VAR_INIT_STATUS_INITIALIZED);
13794 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13795 VAR_INIT_STATUS_INITIALIZED);
13797 if (op0 == 0 || op1 == 0)
13800 mem_loc_result = op0;
13801 add_loc_descr (&mem_loc_result, op1);
13802 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13806 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13807 VAR_INIT_STATUS_INITIALIZED);
13808 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13809 VAR_INIT_STATUS_INITIALIZED);
13811 if (op0 == 0 || op1 == 0)
13814 mem_loc_result = op0;
13815 add_loc_descr (&mem_loc_result, op1);
13816 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13817 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13818 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13819 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13820 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13836 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13837 VAR_INIT_STATUS_INITIALIZED);
13842 mem_loc_result = op0;
13843 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13847 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13875 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13876 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13880 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13882 if (op_mode == VOIDmode)
13883 op_mode = GET_MODE (XEXP (rtl, 1));
13884 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13887 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13888 VAR_INIT_STATUS_INITIALIZED);
13889 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13890 VAR_INIT_STATUS_INITIALIZED);
13892 if (op0 == 0 || op1 == 0)
13895 if (op_mode != VOIDmode
13896 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13898 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
13899 shift *= BITS_PER_UNIT;
13900 /* For eq/ne, if the operands are known to be zero-extended,
13901 there is no need to do the fancy shifting up. */
13902 if (op == DW_OP_eq || op == DW_OP_ne)
13904 dw_loc_descr_ref last0, last1;
13906 last0->dw_loc_next != NULL;
13907 last0 = last0->dw_loc_next)
13910 last1->dw_loc_next != NULL;
13911 last1 = last1->dw_loc_next)
13913 /* deref_size zero extends, and for constants we can check
13914 whether they are zero extended or not. */
13915 if (((last0->dw_loc_opc == DW_OP_deref_size
13916 && last0->dw_loc_oprnd1.v.val_int
13917 <= GET_MODE_SIZE (op_mode))
13918 || (CONST_INT_P (XEXP (rtl, 0))
13919 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13920 == (INTVAL (XEXP (rtl, 0))
13921 & GET_MODE_MASK (op_mode))))
13922 && ((last1->dw_loc_opc == DW_OP_deref_size
13923 && last1->dw_loc_oprnd1.v.val_int
13924 <= GET_MODE_SIZE (op_mode))
13925 || (CONST_INT_P (XEXP (rtl, 1))
13926 && (unsigned HOST_WIDE_INT)
13927 INTVAL (XEXP (rtl, 1))
13928 == (INTVAL (XEXP (rtl, 1))
13929 & GET_MODE_MASK (op_mode)))))
13932 add_loc_descr (&op0, int_loc_descriptor (shift));
13933 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
13934 if (CONST_INT_P (XEXP (rtl, 1)))
13935 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
13938 add_loc_descr (&op1, int_loc_descriptor (shift));
13939 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
13945 mem_loc_result = op0;
13946 add_loc_descr (&mem_loc_result, op1);
13947 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13948 if (STORE_FLAG_VALUE != 1)
13950 add_loc_descr (&mem_loc_result,
13951 int_loc_descriptor (STORE_FLAG_VALUE));
13952 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13973 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13974 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13978 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13980 if (op_mode == VOIDmode)
13981 op_mode = GET_MODE (XEXP (rtl, 1));
13982 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13985 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13986 VAR_INIT_STATUS_INITIALIZED);
13987 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13988 VAR_INIT_STATUS_INITIALIZED);
13990 if (op0 == 0 || op1 == 0)
13993 if (op_mode != VOIDmode
13994 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13996 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
13997 dw_loc_descr_ref last0, last1;
13999 last0->dw_loc_next != NULL;
14000 last0 = last0->dw_loc_next)
14003 last1->dw_loc_next != NULL;
14004 last1 = last1->dw_loc_next)
14006 if (CONST_INT_P (XEXP (rtl, 0)))
14007 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14008 /* deref_size zero extends, so no need to mask it again. */
14009 else if (last0->dw_loc_opc != DW_OP_deref_size
14010 || last0->dw_loc_oprnd1.v.val_int
14011 > GET_MODE_SIZE (op_mode))
14013 add_loc_descr (&op0, int_loc_descriptor (mask));
14014 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14016 if (CONST_INT_P (XEXP (rtl, 1)))
14017 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14018 /* deref_size zero extends, so no need to mask it again. */
14019 else if (last1->dw_loc_opc != DW_OP_deref_size
14020 || last1->dw_loc_oprnd1.v.val_int
14021 > GET_MODE_SIZE (op_mode))
14023 add_loc_descr (&op1, int_loc_descriptor (mask));
14024 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14029 HOST_WIDE_INT bias = 1;
14030 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14031 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14032 if (CONST_INT_P (XEXP (rtl, 1)))
14033 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14034 + INTVAL (XEXP (rtl, 1)));
14036 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14046 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14047 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14048 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14051 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14052 VAR_INIT_STATUS_INITIALIZED);
14053 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14054 VAR_INIT_STATUS_INITIALIZED);
14056 if (op0 == 0 || op1 == 0)
14059 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14060 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14061 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14062 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14064 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14066 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14067 add_loc_descr (&op0, int_loc_descriptor (mask));
14068 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14069 add_loc_descr (&op1, int_loc_descriptor (mask));
14070 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14074 HOST_WIDE_INT bias = 1;
14075 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14076 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14077 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14080 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14082 int shift = DWARF2_ADDR_SIZE
14083 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14084 shift *= BITS_PER_UNIT;
14085 add_loc_descr (&op0, int_loc_descriptor (shift));
14086 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14087 add_loc_descr (&op1, int_loc_descriptor (shift));
14088 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14091 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14095 mem_loc_result = op0;
14096 add_loc_descr (&mem_loc_result, op1);
14097 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14099 dw_loc_descr_ref bra_node, drop_node;
14101 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14102 add_loc_descr (&mem_loc_result, bra_node);
14103 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14104 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14105 add_loc_descr (&mem_loc_result, drop_node);
14106 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14107 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14113 if (CONST_INT_P (XEXP (rtl, 1))
14114 && CONST_INT_P (XEXP (rtl, 2))
14115 && ((unsigned) INTVAL (XEXP (rtl, 1))
14116 + (unsigned) INTVAL (XEXP (rtl, 2))
14117 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14118 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14119 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14122 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14123 VAR_INIT_STATUS_INITIALIZED);
14126 if (GET_CODE (rtl) == SIGN_EXTRACT)
14130 mem_loc_result = op0;
14131 size = INTVAL (XEXP (rtl, 1));
14132 shift = INTVAL (XEXP (rtl, 2));
14133 if (BITS_BIG_ENDIAN)
14134 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14136 if (shift + size != (int) DWARF2_ADDR_SIZE)
14138 add_loc_descr (&mem_loc_result,
14139 int_loc_descriptor (DWARF2_ADDR_SIZE
14141 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14143 if (size != (int) DWARF2_ADDR_SIZE)
14145 add_loc_descr (&mem_loc_result,
14146 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14147 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14157 /* In theory, we could implement the above. */
14158 /* DWARF cannot represent the unsigned compare operations
14185 case FLOAT_TRUNCATE:
14187 case UNSIGNED_FLOAT:
14190 case FRACT_CONVERT:
14191 case UNSIGNED_FRACT_CONVERT:
14193 case UNSIGNED_SAT_FRACT:
14205 case VEC_DUPLICATE:
14208 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14209 can't express it in the debug info. This can happen e.g. with some
14214 resolve_one_addr (&rtl, NULL);
14218 #ifdef ENABLE_CHECKING
14219 print_rtl (stderr, rtl);
14220 gcc_unreachable ();
14226 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14227 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14229 return mem_loc_result;
14232 /* Return a descriptor that describes the concatenation of two locations.
14233 This is typically a complex variable. */
14235 static dw_loc_descr_ref
14236 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14238 dw_loc_descr_ref cc_loc_result = NULL;
14239 dw_loc_descr_ref x0_ref
14240 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14241 dw_loc_descr_ref x1_ref
14242 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14244 if (x0_ref == 0 || x1_ref == 0)
14247 cc_loc_result = x0_ref;
14248 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14250 add_loc_descr (&cc_loc_result, x1_ref);
14251 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14253 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14254 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14256 return cc_loc_result;
14259 /* Return a descriptor that describes the concatenation of N
14262 static dw_loc_descr_ref
14263 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14266 dw_loc_descr_ref cc_loc_result = NULL;
14267 unsigned int n = XVECLEN (concatn, 0);
14269 for (i = 0; i < n; ++i)
14271 dw_loc_descr_ref ref;
14272 rtx x = XVECEXP (concatn, 0, i);
14274 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14278 add_loc_descr (&cc_loc_result, ref);
14279 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14282 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14283 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14285 return cc_loc_result;
14288 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14289 for DEBUG_IMPLICIT_PTR RTL. */
14291 static dw_loc_descr_ref
14292 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14294 dw_loc_descr_ref ret;
14299 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14300 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14301 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14302 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14303 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14304 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14307 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14308 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14309 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14313 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14314 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14319 /* Output a proper Dwarf location descriptor for a variable or parameter
14320 which is either allocated in a register or in a memory location. For a
14321 register, we just generate an OP_REG and the register number. For a
14322 memory location we provide a Dwarf postfix expression describing how to
14323 generate the (dynamic) address of the object onto the address stack.
14325 MODE is mode of the decl if this loc_descriptor is going to be used in
14326 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14327 allowed, VOIDmode otherwise.
14329 If we don't know how to describe it, return 0. */
14331 static dw_loc_descr_ref
14332 loc_descriptor (rtx rtl, enum machine_mode mode,
14333 enum var_init_status initialized)
14335 dw_loc_descr_ref loc_result = NULL;
14337 switch (GET_CODE (rtl))
14340 /* The case of a subreg may arise when we have a local (register)
14341 variable or a formal (register) parameter which doesn't quite fill
14342 up an entire register. For now, just assume that it is
14343 legitimate to make the Dwarf info refer to the whole register which
14344 contains the given subreg. */
14345 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14349 loc_result = reg_loc_descriptor (rtl, initialized);
14353 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14355 if (loc_result == NULL)
14356 loc_result = tls_mem_loc_descriptor (rtl);
14357 if (loc_result == NULL)
14359 rtx new_rtl = avoid_constant_pool_reference (rtl);
14360 if (new_rtl != rtl)
14361 loc_result = loc_descriptor (new_rtl, mode, initialized);
14366 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14371 loc_result = concatn_loc_descriptor (rtl, initialized);
14376 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14378 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14379 if (GET_CODE (loc) == EXPR_LIST)
14380 loc = XEXP (loc, 0);
14381 loc_result = loc_descriptor (loc, mode, initialized);
14385 rtl = XEXP (rtl, 1);
14390 rtvec par_elems = XVEC (rtl, 0);
14391 int num_elem = GET_NUM_ELEM (par_elems);
14392 enum machine_mode mode;
14395 /* Create the first one, so we have something to add to. */
14396 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14397 VOIDmode, initialized);
14398 if (loc_result == NULL)
14400 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14401 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14402 for (i = 1; i < num_elem; i++)
14404 dw_loc_descr_ref temp;
14406 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14407 VOIDmode, initialized);
14410 add_loc_descr (&loc_result, temp);
14411 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14412 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14418 if (mode != VOIDmode && mode != BLKmode)
14419 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14424 if (mode == VOIDmode)
14425 mode = GET_MODE (rtl);
14427 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14429 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14431 /* Note that a CONST_DOUBLE rtx could represent either an integer
14432 or a floating-point constant. A CONST_DOUBLE is used whenever
14433 the constant requires more than one word in order to be
14434 adequately represented. We output CONST_DOUBLEs as blocks. */
14435 loc_result = new_loc_descr (DW_OP_implicit_value,
14436 GET_MODE_SIZE (mode), 0);
14437 if (SCALAR_FLOAT_MODE_P (mode))
14439 unsigned int length = GET_MODE_SIZE (mode);
14440 unsigned char *array
14441 = (unsigned char*) ggc_alloc_atomic (length);
14443 insert_float (rtl, array);
14444 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14445 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14446 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14447 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14451 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14452 loc_result->dw_loc_oprnd2.v.val_double
14453 = rtx_to_double_int (rtl);
14459 if (mode == VOIDmode)
14460 mode = GET_MODE (rtl);
14462 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14464 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14465 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14466 unsigned char *array = (unsigned char *)
14467 ggc_alloc_atomic (length * elt_size);
14471 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14472 switch (GET_MODE_CLASS (mode))
14474 case MODE_VECTOR_INT:
14475 for (i = 0, p = array; i < length; i++, p += elt_size)
14477 rtx elt = CONST_VECTOR_ELT (rtl, i);
14478 double_int val = rtx_to_double_int (elt);
14480 if (elt_size <= sizeof (HOST_WIDE_INT))
14481 insert_int (double_int_to_shwi (val), elt_size, p);
14484 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14485 insert_double (val, p);
14490 case MODE_VECTOR_FLOAT:
14491 for (i = 0, p = array; i < length; i++, p += elt_size)
14493 rtx elt = CONST_VECTOR_ELT (rtl, i);
14494 insert_float (elt, p);
14499 gcc_unreachable ();
14502 loc_result = new_loc_descr (DW_OP_implicit_value,
14503 length * elt_size, 0);
14504 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14505 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14506 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14507 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14512 if (mode == VOIDmode
14513 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14514 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14515 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14517 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14522 if (!const_ok_for_output (rtl))
14525 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14526 && (dwarf_version >= 4 || !dwarf_strict))
14528 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14529 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14530 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14531 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14532 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14536 case DEBUG_IMPLICIT_PTR:
14537 loc_result = implicit_ptr_descriptor (rtl, 0);
14541 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14542 && CONST_INT_P (XEXP (rtl, 1)))
14545 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14550 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14551 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14552 && (dwarf_version >= 4 || !dwarf_strict))
14554 /* Value expression. */
14555 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14557 add_loc_descr (&loc_result,
14558 new_loc_descr (DW_OP_stack_value, 0, 0));
14566 /* We need to figure out what section we should use as the base for the
14567 address ranges where a given location is valid.
14568 1. If this particular DECL has a section associated with it, use that.
14569 2. If this function has a section associated with it, use that.
14570 3. Otherwise, use the text section.
14571 XXX: If you split a variable across multiple sections, we won't notice. */
14573 static const char *
14574 secname_for_decl (const_tree decl)
14576 const char *secname;
14578 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14580 tree sectree = DECL_SECTION_NAME (decl);
14581 secname = TREE_STRING_POINTER (sectree);
14583 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14585 tree sectree = DECL_SECTION_NAME (current_function_decl);
14586 secname = TREE_STRING_POINTER (sectree);
14588 else if (cfun && in_cold_section_p)
14589 secname = crtl->subsections.cold_section_label;
14591 secname = text_section_label;
14596 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14599 decl_by_reference_p (tree decl)
14601 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14602 || TREE_CODE (decl) == VAR_DECL)
14603 && DECL_BY_REFERENCE (decl));
14606 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14609 static dw_loc_descr_ref
14610 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14611 enum var_init_status initialized)
14613 int have_address = 0;
14614 dw_loc_descr_ref descr;
14615 enum machine_mode mode;
14617 if (want_address != 2)
14619 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14621 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14623 varloc = PAT_VAR_LOCATION_LOC (varloc);
14624 if (GET_CODE (varloc) == EXPR_LIST)
14625 varloc = XEXP (varloc, 0);
14626 mode = GET_MODE (varloc);
14627 if (MEM_P (varloc))
14629 rtx addr = XEXP (varloc, 0);
14630 descr = mem_loc_descriptor (addr, mode, initialized);
14635 rtx x = avoid_constant_pool_reference (varloc);
14637 descr = mem_loc_descriptor (x, mode, initialized);
14641 descr = mem_loc_descriptor (varloc, mode, initialized);
14648 if (GET_CODE (varloc) == VAR_LOCATION)
14649 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14651 mode = DECL_MODE (loc);
14652 descr = loc_descriptor (varloc, mode, initialized);
14659 if (want_address == 2 && !have_address
14660 && (dwarf_version >= 4 || !dwarf_strict))
14662 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14664 expansion_failed (loc, NULL_RTX,
14665 "DWARF address size mismatch");
14668 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14671 /* Show if we can't fill the request for an address. */
14672 if (want_address && !have_address)
14674 expansion_failed (loc, NULL_RTX,
14675 "Want address and only have value");
14679 /* If we've got an address and don't want one, dereference. */
14680 if (!want_address && have_address)
14682 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14683 enum dwarf_location_atom op;
14685 if (size > DWARF2_ADDR_SIZE || size == -1)
14687 expansion_failed (loc, NULL_RTX,
14688 "DWARF address size mismatch");
14691 else if (size == DWARF2_ADDR_SIZE)
14694 op = DW_OP_deref_size;
14696 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14702 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14703 if it is not possible. */
14705 static dw_loc_descr_ref
14706 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14708 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14709 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14710 else if (dwarf_version >= 3 || !dwarf_strict)
14711 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14716 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14717 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14719 static dw_loc_descr_ref
14720 dw_sra_loc_expr (tree decl, rtx loc)
14723 unsigned int padsize = 0;
14724 dw_loc_descr_ref descr, *descr_tail;
14725 unsigned HOST_WIDE_INT decl_size;
14727 enum var_init_status initialized;
14729 if (DECL_SIZE (decl) == NULL
14730 || !host_integerp (DECL_SIZE (decl), 1))
14733 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14735 descr_tail = &descr;
14737 for (p = loc; p; p = XEXP (p, 1))
14739 unsigned int bitsize = decl_piece_bitsize (p);
14740 rtx loc_note = *decl_piece_varloc_ptr (p);
14741 dw_loc_descr_ref cur_descr;
14742 dw_loc_descr_ref *tail, last = NULL;
14743 unsigned int opsize = 0;
14745 if (loc_note == NULL_RTX
14746 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14748 padsize += bitsize;
14751 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14752 varloc = NOTE_VAR_LOCATION (loc_note);
14753 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14754 if (cur_descr == NULL)
14756 padsize += bitsize;
14760 /* Check that cur_descr either doesn't use
14761 DW_OP_*piece operations, or their sum is equal
14762 to bitsize. Otherwise we can't embed it. */
14763 for (tail = &cur_descr; *tail != NULL;
14764 tail = &(*tail)->dw_loc_next)
14765 if ((*tail)->dw_loc_opc == DW_OP_piece)
14767 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14771 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14773 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14777 if (last != NULL && opsize != bitsize)
14779 padsize += bitsize;
14783 /* If there is a hole, add DW_OP_*piece after empty DWARF
14784 expression, which means that those bits are optimized out. */
14787 if (padsize > decl_size)
14789 decl_size -= padsize;
14790 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14791 if (*descr_tail == NULL)
14793 descr_tail = &(*descr_tail)->dw_loc_next;
14796 *descr_tail = cur_descr;
14798 if (bitsize > decl_size)
14800 decl_size -= bitsize;
14803 HOST_WIDE_INT offset = 0;
14804 if (GET_CODE (varloc) == VAR_LOCATION
14805 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14807 varloc = PAT_VAR_LOCATION_LOC (varloc);
14808 if (GET_CODE (varloc) == EXPR_LIST)
14809 varloc = XEXP (varloc, 0);
14813 if (GET_CODE (varloc) == CONST
14814 || GET_CODE (varloc) == SIGN_EXTEND
14815 || GET_CODE (varloc) == ZERO_EXTEND)
14816 varloc = XEXP (varloc, 0);
14817 else if (GET_CODE (varloc) == SUBREG)
14818 varloc = SUBREG_REG (varloc);
14823 /* DW_OP_bit_size offset should be zero for register
14824 or implicit location descriptions and empty location
14825 descriptions, but for memory addresses needs big endian
14827 if (MEM_P (varloc))
14829 unsigned HOST_WIDE_INT memsize
14830 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
14831 if (memsize != bitsize)
14833 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14834 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14836 if (memsize < bitsize)
14838 if (BITS_BIG_ENDIAN)
14839 offset = memsize - bitsize;
14843 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14844 if (*descr_tail == NULL)
14846 descr_tail = &(*descr_tail)->dw_loc_next;
14850 /* If there were any non-empty expressions, add padding till the end of
14852 if (descr != NULL && decl_size != 0)
14854 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14855 if (*descr_tail == NULL)
14861 /* Return the dwarf representation of the location list LOC_LIST of
14862 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14865 static dw_loc_list_ref
14866 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14868 const char *endname, *secname;
14870 enum var_init_status initialized;
14871 struct var_loc_node *node;
14872 dw_loc_descr_ref descr;
14873 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14874 dw_loc_list_ref list = NULL;
14875 dw_loc_list_ref *listp = &list;
14877 /* Now that we know what section we are using for a base,
14878 actually construct the list of locations.
14879 The first location information is what is passed to the
14880 function that creates the location list, and the remaining
14881 locations just get added on to that list.
14882 Note that we only know the start address for a location
14883 (IE location changes), so to build the range, we use
14884 the range [current location start, next location start].
14885 This means we have to special case the last node, and generate
14886 a range of [last location start, end of function label]. */
14888 secname = secname_for_decl (decl);
14890 for (node = loc_list->first; node; node = node->next)
14891 if (GET_CODE (node->loc) == EXPR_LIST
14892 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14894 if (GET_CODE (node->loc) == EXPR_LIST)
14896 /* This requires DW_OP_{,bit_}piece, which is not usable
14897 inside DWARF expressions. */
14898 if (want_address != 2)
14900 descr = dw_sra_loc_expr (decl, node->loc);
14906 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14907 varloc = NOTE_VAR_LOCATION (node->loc);
14908 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14912 /* The variable has a location between NODE->LABEL and
14913 NODE->NEXT->LABEL. */
14915 endname = node->next->label;
14916 /* If the variable has a location at the last label
14917 it keeps its location until the end of function. */
14918 else if (!current_function_decl)
14919 endname = text_end_label;
14922 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14923 current_function_funcdef_no);
14924 endname = ggc_strdup (label_id);
14927 *listp = new_loc_list (descr, node->label, endname, secname);
14928 listp = &(*listp)->dw_loc_next;
14932 /* Try to avoid the overhead of a location list emitting a location
14933 expression instead, but only if we didn't have more than one
14934 location entry in the first place. If some entries were not
14935 representable, we don't want to pretend a single entry that was
14936 applies to the entire scope in which the variable is
14938 if (list && loc_list->first->next)
14944 /* Return if the loc_list has only single element and thus can be represented
14945 as location description. */
14948 single_element_loc_list_p (dw_loc_list_ref list)
14950 gcc_assert (!list->dw_loc_next || list->ll_symbol);
14951 return !list->ll_symbol;
14954 /* To each location in list LIST add loc descr REF. */
14957 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
14959 dw_loc_descr_ref copy;
14960 add_loc_descr (&list->expr, ref);
14961 list = list->dw_loc_next;
14964 copy = ggc_alloc_dw_loc_descr_node ();
14965 memcpy (copy, ref, sizeof (dw_loc_descr_node));
14966 add_loc_descr (&list->expr, copy);
14967 while (copy->dw_loc_next)
14969 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
14970 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
14971 copy->dw_loc_next = new_copy;
14974 list = list->dw_loc_next;
14978 /* Given two lists RET and LIST
14979 produce location list that is result of adding expression in LIST
14980 to expression in RET on each possition in program.
14981 Might be destructive on both RET and LIST.
14983 TODO: We handle only simple cases of RET or LIST having at most one
14984 element. General case would inolve sorting the lists in program order
14985 and merging them that will need some additional work.
14986 Adding that will improve quality of debug info especially for SRA-ed
14990 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
14999 if (!list->dw_loc_next)
15001 add_loc_descr_to_each (*ret, list->expr);
15004 if (!(*ret)->dw_loc_next)
15006 add_loc_descr_to_each (list, (*ret)->expr);
15010 expansion_failed (NULL_TREE, NULL_RTX,
15011 "Don't know how to merge two non-trivial"
15012 " location lists.\n");
15017 /* LOC is constant expression. Try a luck, look it up in constant
15018 pool and return its loc_descr of its address. */
15020 static dw_loc_descr_ref
15021 cst_pool_loc_descr (tree loc)
15023 /* Get an RTL for this, if something has been emitted. */
15024 rtx rtl = lookup_constant_def (loc);
15025 enum machine_mode mode;
15027 if (!rtl || !MEM_P (rtl))
15032 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15034 /* TODO: We might get more coverage if we was actually delaying expansion
15035 of all expressions till end of compilation when constant pools are fully
15037 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15039 expansion_failed (loc, NULL_RTX,
15040 "CST value in contant pool but not marked.");
15043 mode = GET_MODE (rtl);
15044 rtl = XEXP (rtl, 0);
15045 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15048 /* Return dw_loc_list representing address of addr_expr LOC
15049 by looking for innder INDIRECT_REF expression and turing it
15050 into simple arithmetics. */
15052 static dw_loc_list_ref
15053 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15056 HOST_WIDE_INT bitsize, bitpos, bytepos;
15057 enum machine_mode mode;
15059 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15060 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15062 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15063 &bitsize, &bitpos, &offset, &mode,
15064 &unsignedp, &volatilep, false);
15066 if (bitpos % BITS_PER_UNIT)
15068 expansion_failed (loc, NULL_RTX, "bitfield access");
15071 if (!INDIRECT_REF_P (obj))
15073 expansion_failed (obj,
15074 NULL_RTX, "no indirect ref in inner refrence");
15077 if (!offset && !bitpos)
15078 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15080 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15081 && (dwarf_version >= 4 || !dwarf_strict))
15083 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15088 /* Variable offset. */
15089 list_ret1 = loc_list_from_tree (offset, 0);
15090 if (list_ret1 == 0)
15092 add_loc_list (&list_ret, list_ret1);
15095 add_loc_descr_to_each (list_ret,
15096 new_loc_descr (DW_OP_plus, 0, 0));
15098 bytepos = bitpos / BITS_PER_UNIT;
15100 add_loc_descr_to_each (list_ret,
15101 new_loc_descr (DW_OP_plus_uconst,
15103 else if (bytepos < 0)
15104 loc_list_plus_const (list_ret, bytepos);
15105 add_loc_descr_to_each (list_ret,
15106 new_loc_descr (DW_OP_stack_value, 0, 0));
15112 /* Generate Dwarf location list representing LOC.
15113 If WANT_ADDRESS is false, expression computing LOC will be computed
15114 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15115 if WANT_ADDRESS is 2, expression computing address useable in location
15116 will be returned (i.e. DW_OP_reg can be used
15117 to refer to register values). */
15119 static dw_loc_list_ref
15120 loc_list_from_tree (tree loc, int want_address)
15122 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15123 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15124 int have_address = 0;
15125 enum dwarf_location_atom op;
15127 /* ??? Most of the time we do not take proper care for sign/zero
15128 extending the values properly. Hopefully this won't be a real
15131 switch (TREE_CODE (loc))
15134 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15137 case PLACEHOLDER_EXPR:
15138 /* This case involves extracting fields from an object to determine the
15139 position of other fields. We don't try to encode this here. The
15140 only user of this is Ada, which encodes the needed information using
15141 the names of types. */
15142 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15146 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15147 /* There are no opcodes for these operations. */
15150 case PREINCREMENT_EXPR:
15151 case PREDECREMENT_EXPR:
15152 case POSTINCREMENT_EXPR:
15153 case POSTDECREMENT_EXPR:
15154 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15155 /* There are no opcodes for these operations. */
15159 /* If we already want an address, see if there is INDIRECT_REF inside
15160 e.g. for &this->field. */
15163 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15164 (loc, want_address == 2);
15167 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15168 && (ret = cst_pool_loc_descr (loc)))
15171 /* Otherwise, process the argument and look for the address. */
15172 if (!list_ret && !ret)
15173 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15177 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15183 if (DECL_THREAD_LOCAL_P (loc))
15186 enum dwarf_location_atom first_op;
15187 enum dwarf_location_atom second_op;
15188 bool dtprel = false;
15190 if (targetm.have_tls)
15192 /* If this is not defined, we have no way to emit the
15194 if (!targetm.asm_out.output_dwarf_dtprel)
15197 /* The way DW_OP_GNU_push_tls_address is specified, we
15198 can only look up addresses of objects in the current
15199 module. We used DW_OP_addr as first op, but that's
15200 wrong, because DW_OP_addr is relocated by the debug
15201 info consumer, while DW_OP_GNU_push_tls_address
15202 operand shouldn't be. */
15203 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15205 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15207 second_op = DW_OP_GNU_push_tls_address;
15211 if (!targetm.emutls.debug_form_tls_address
15212 || !(dwarf_version >= 3 || !dwarf_strict))
15214 /* We stuffed the control variable into the DECL_VALUE_EXPR
15215 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15216 no longer appear in gimple code. We used the control
15217 variable in specific so that we could pick it up here. */
15218 loc = DECL_VALUE_EXPR (loc);
15219 first_op = DW_OP_addr;
15220 second_op = DW_OP_form_tls_address;
15223 rtl = rtl_for_decl_location (loc);
15224 if (rtl == NULL_RTX)
15229 rtl = XEXP (rtl, 0);
15230 if (! CONSTANT_P (rtl))
15233 ret = new_loc_descr (first_op, 0, 0);
15234 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15235 ret->dw_loc_oprnd1.v.val_addr = rtl;
15236 ret->dtprel = dtprel;
15238 ret1 = new_loc_descr (second_op, 0, 0);
15239 add_loc_descr (&ret, ret1);
15247 if (DECL_HAS_VALUE_EXPR_P (loc))
15248 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15253 case FUNCTION_DECL:
15256 var_loc_list *loc_list = lookup_decl_loc (loc);
15258 if (loc_list && loc_list->first)
15260 list_ret = dw_loc_list (loc_list, loc, want_address);
15261 have_address = want_address != 0;
15264 rtl = rtl_for_decl_location (loc);
15265 if (rtl == NULL_RTX)
15267 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15270 else if (CONST_INT_P (rtl))
15272 HOST_WIDE_INT val = INTVAL (rtl);
15273 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15274 val &= GET_MODE_MASK (DECL_MODE (loc));
15275 ret = int_loc_descriptor (val);
15277 else if (GET_CODE (rtl) == CONST_STRING)
15279 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15282 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15284 ret = new_loc_descr (DW_OP_addr, 0, 0);
15285 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15286 ret->dw_loc_oprnd1.v.val_addr = rtl;
15290 enum machine_mode mode;
15292 /* Certain constructs can only be represented at top-level. */
15293 if (want_address == 2)
15295 ret = loc_descriptor (rtl, VOIDmode,
15296 VAR_INIT_STATUS_INITIALIZED);
15301 mode = GET_MODE (rtl);
15304 rtl = XEXP (rtl, 0);
15307 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15310 expansion_failed (loc, rtl,
15311 "failed to produce loc descriptor for rtl");
15318 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15322 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15326 case COMPOUND_EXPR:
15327 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15330 case VIEW_CONVERT_EXPR:
15333 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15335 case COMPONENT_REF:
15336 case BIT_FIELD_REF:
15338 case ARRAY_RANGE_REF:
15339 case REALPART_EXPR:
15340 case IMAGPART_EXPR:
15343 HOST_WIDE_INT bitsize, bitpos, bytepos;
15344 enum machine_mode mode;
15346 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15348 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15349 &unsignedp, &volatilep, false);
15351 gcc_assert (obj != loc);
15353 list_ret = loc_list_from_tree (obj,
15355 && !bitpos && !offset ? 2 : 1);
15356 /* TODO: We can extract value of the small expression via shifting even
15357 for nonzero bitpos. */
15360 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15362 expansion_failed (loc, NULL_RTX,
15363 "bitfield access");
15367 if (offset != NULL_TREE)
15369 /* Variable offset. */
15370 list_ret1 = loc_list_from_tree (offset, 0);
15371 if (list_ret1 == 0)
15373 add_loc_list (&list_ret, list_ret1);
15376 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15379 bytepos = bitpos / BITS_PER_UNIT;
15381 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15382 else if (bytepos < 0)
15383 loc_list_plus_const (list_ret, bytepos);
15390 if ((want_address || !host_integerp (loc, 0))
15391 && (ret = cst_pool_loc_descr (loc)))
15393 else if (want_address == 2
15394 && host_integerp (loc, 0)
15395 && (ret = address_of_int_loc_descriptor
15396 (int_size_in_bytes (TREE_TYPE (loc)),
15397 tree_low_cst (loc, 0))))
15399 else if (host_integerp (loc, 0))
15400 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15403 expansion_failed (loc, NULL_RTX,
15404 "Integer operand is not host integer");
15413 if ((ret = cst_pool_loc_descr (loc)))
15416 /* We can construct small constants here using int_loc_descriptor. */
15417 expansion_failed (loc, NULL_RTX,
15418 "constructor or constant not in constant pool");
15421 case TRUTH_AND_EXPR:
15422 case TRUTH_ANDIF_EXPR:
15427 case TRUTH_XOR_EXPR:
15432 case TRUTH_OR_EXPR:
15433 case TRUTH_ORIF_EXPR:
15438 case FLOOR_DIV_EXPR:
15439 case CEIL_DIV_EXPR:
15440 case ROUND_DIV_EXPR:
15441 case TRUNC_DIV_EXPR:
15442 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15451 case FLOOR_MOD_EXPR:
15452 case CEIL_MOD_EXPR:
15453 case ROUND_MOD_EXPR:
15454 case TRUNC_MOD_EXPR:
15455 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15460 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15461 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15462 if (list_ret == 0 || list_ret1 == 0)
15465 add_loc_list (&list_ret, list_ret1);
15468 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15469 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15470 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15471 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15472 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15484 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15487 case POINTER_PLUS_EXPR:
15489 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15491 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15495 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15503 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15510 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15517 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15524 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15539 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15540 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15541 if (list_ret == 0 || list_ret1 == 0)
15544 add_loc_list (&list_ret, list_ret1);
15547 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15550 case TRUTH_NOT_EXPR:
15564 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15568 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15574 const enum tree_code code =
15575 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15577 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15578 build2 (code, integer_type_node,
15579 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15580 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15583 /* ... fall through ... */
15587 dw_loc_descr_ref lhs
15588 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15589 dw_loc_list_ref rhs
15590 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15591 dw_loc_descr_ref bra_node, jump_node, tmp;
15593 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15594 if (list_ret == 0 || lhs == 0 || rhs == 0)
15597 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15598 add_loc_descr_to_each (list_ret, bra_node);
15600 add_loc_list (&list_ret, rhs);
15601 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15602 add_loc_descr_to_each (list_ret, jump_node);
15604 add_loc_descr_to_each (list_ret, lhs);
15605 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15606 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15608 /* ??? Need a node to point the skip at. Use a nop. */
15609 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15610 add_loc_descr_to_each (list_ret, tmp);
15611 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15612 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15616 case FIX_TRUNC_EXPR:
15620 /* Leave front-end specific codes as simply unknown. This comes
15621 up, for instance, with the C STMT_EXPR. */
15622 if ((unsigned int) TREE_CODE (loc)
15623 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15625 expansion_failed (loc, NULL_RTX,
15626 "language specific tree node");
15630 #ifdef ENABLE_CHECKING
15631 /* Otherwise this is a generic code; we should just lists all of
15632 these explicitly. We forgot one. */
15633 gcc_unreachable ();
15635 /* In a release build, we want to degrade gracefully: better to
15636 generate incomplete debugging information than to crash. */
15641 if (!ret && !list_ret)
15644 if (want_address == 2 && !have_address
15645 && (dwarf_version >= 4 || !dwarf_strict))
15647 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15649 expansion_failed (loc, NULL_RTX,
15650 "DWARF address size mismatch");
15654 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15656 add_loc_descr_to_each (list_ret,
15657 new_loc_descr (DW_OP_stack_value, 0, 0));
15660 /* Show if we can't fill the request for an address. */
15661 if (want_address && !have_address)
15663 expansion_failed (loc, NULL_RTX,
15664 "Want address and only have value");
15668 gcc_assert (!ret || !list_ret);
15670 /* If we've got an address and don't want one, dereference. */
15671 if (!want_address && have_address)
15673 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15675 if (size > DWARF2_ADDR_SIZE || size == -1)
15677 expansion_failed (loc, NULL_RTX,
15678 "DWARF address size mismatch");
15681 else if (size == DWARF2_ADDR_SIZE)
15684 op = DW_OP_deref_size;
15687 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15689 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15692 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15697 /* Same as above but return only single location expression. */
15698 static dw_loc_descr_ref
15699 loc_descriptor_from_tree (tree loc, int want_address)
15701 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15704 if (ret->dw_loc_next)
15706 expansion_failed (loc, NULL_RTX,
15707 "Location list where only loc descriptor needed");
15713 /* Given a value, round it up to the lowest multiple of `boundary'
15714 which is not less than the value itself. */
15716 static inline HOST_WIDE_INT
15717 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15719 return (((value + boundary - 1) / boundary) * boundary);
15722 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15723 pointer to the declared type for the relevant field variable, or return
15724 `integer_type_node' if the given node turns out to be an
15725 ERROR_MARK node. */
15728 field_type (const_tree decl)
15732 if (TREE_CODE (decl) == ERROR_MARK)
15733 return integer_type_node;
15735 type = DECL_BIT_FIELD_TYPE (decl);
15736 if (type == NULL_TREE)
15737 type = TREE_TYPE (decl);
15742 /* Given a pointer to a tree node, return the alignment in bits for
15743 it, or else return BITS_PER_WORD if the node actually turns out to
15744 be an ERROR_MARK node. */
15746 static inline unsigned
15747 simple_type_align_in_bits (const_tree type)
15749 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15752 static inline unsigned
15753 simple_decl_align_in_bits (const_tree decl)
15755 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15758 /* Return the result of rounding T up to ALIGN. */
15760 static inline double_int
15761 round_up_to_align (double_int t, unsigned int align)
15763 double_int alignd = uhwi_to_double_int (align);
15764 t = double_int_add (t, alignd);
15765 t = double_int_add (t, double_int_minus_one);
15766 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15767 t = double_int_mul (t, alignd);
15771 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15772 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15773 or return 0 if we are unable to determine what that offset is, either
15774 because the argument turns out to be a pointer to an ERROR_MARK node, or
15775 because the offset is actually variable. (We can't handle the latter case
15778 static HOST_WIDE_INT
15779 field_byte_offset (const_tree decl)
15781 double_int object_offset_in_bits;
15782 double_int object_offset_in_bytes;
15783 double_int bitpos_int;
15785 if (TREE_CODE (decl) == ERROR_MARK)
15788 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15790 /* We cannot yet cope with fields whose positions are variable, so
15791 for now, when we see such things, we simply return 0. Someday, we may
15792 be able to handle such cases, but it will be damn difficult. */
15793 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15796 bitpos_int = tree_to_double_int (bit_position (decl));
15798 #ifdef PCC_BITFIELD_TYPE_MATTERS
15799 if (PCC_BITFIELD_TYPE_MATTERS)
15802 tree field_size_tree;
15803 double_int deepest_bitpos;
15804 double_int field_size_in_bits;
15805 unsigned int type_align_in_bits;
15806 unsigned int decl_align_in_bits;
15807 double_int type_size_in_bits;
15809 type = field_type (decl);
15810 type_size_in_bits = double_int_type_size_in_bits (type);
15811 type_align_in_bits = simple_type_align_in_bits (type);
15813 field_size_tree = DECL_SIZE (decl);
15815 /* The size could be unspecified if there was an error, or for
15816 a flexible array member. */
15817 if (!field_size_tree)
15818 field_size_tree = bitsize_zero_node;
15820 /* If the size of the field is not constant, use the type size. */
15821 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15822 field_size_in_bits = tree_to_double_int (field_size_tree);
15824 field_size_in_bits = type_size_in_bits;
15826 decl_align_in_bits = simple_decl_align_in_bits (decl);
15828 /* The GCC front-end doesn't make any attempt to keep track of the
15829 starting bit offset (relative to the start of the containing
15830 structure type) of the hypothetical "containing object" for a
15831 bit-field. Thus, when computing the byte offset value for the
15832 start of the "containing object" of a bit-field, we must deduce
15833 this information on our own. This can be rather tricky to do in
15834 some cases. For example, handling the following structure type
15835 definition when compiling for an i386/i486 target (which only
15836 aligns long long's to 32-bit boundaries) can be very tricky:
15838 struct S { int field1; long long field2:31; };
15840 Fortunately, there is a simple rule-of-thumb which can be used
15841 in such cases. When compiling for an i386/i486, GCC will
15842 allocate 8 bytes for the structure shown above. It decides to
15843 do this based upon one simple rule for bit-field allocation.
15844 GCC allocates each "containing object" for each bit-field at
15845 the first (i.e. lowest addressed) legitimate alignment boundary
15846 (based upon the required minimum alignment for the declared
15847 type of the field) which it can possibly use, subject to the
15848 condition that there is still enough available space remaining
15849 in the containing object (when allocated at the selected point)
15850 to fully accommodate all of the bits of the bit-field itself.
15852 This simple rule makes it obvious why GCC allocates 8 bytes for
15853 each object of the structure type shown above. When looking
15854 for a place to allocate the "containing object" for `field2',
15855 the compiler simply tries to allocate a 64-bit "containing
15856 object" at each successive 32-bit boundary (starting at zero)
15857 until it finds a place to allocate that 64- bit field such that
15858 at least 31 contiguous (and previously unallocated) bits remain
15859 within that selected 64 bit field. (As it turns out, for the
15860 example above, the compiler finds it is OK to allocate the
15861 "containing object" 64-bit field at bit-offset zero within the
15864 Here we attempt to work backwards from the limited set of facts
15865 we're given, and we try to deduce from those facts, where GCC
15866 must have believed that the containing object started (within
15867 the structure type). The value we deduce is then used (by the
15868 callers of this routine) to generate DW_AT_location and
15869 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15870 the case of DW_AT_location, regular fields as well). */
15872 /* Figure out the bit-distance from the start of the structure to
15873 the "deepest" bit of the bit-field. */
15874 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
15876 /* This is the tricky part. Use some fancy footwork to deduce
15877 where the lowest addressed bit of the containing object must
15879 object_offset_in_bits
15880 = double_int_sub (deepest_bitpos, type_size_in_bits);
15882 /* Round up to type_align by default. This works best for
15884 object_offset_in_bits
15885 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
15887 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
15889 object_offset_in_bits
15890 = double_int_sub (deepest_bitpos, type_size_in_bits);
15892 /* Round up to decl_align instead. */
15893 object_offset_in_bits
15894 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
15898 #endif /* PCC_BITFIELD_TYPE_MATTERS */
15899 object_offset_in_bits = bitpos_int;
15901 object_offset_in_bytes
15902 = double_int_div (object_offset_in_bits,
15903 uhwi_to_double_int (BITS_PER_UNIT), true,
15905 return double_int_to_shwi (object_offset_in_bytes);
15908 /* The following routines define various Dwarf attributes and any data
15909 associated with them. */
15911 /* Add a location description attribute value to a DIE.
15913 This emits location attributes suitable for whole variables and
15914 whole parameters. Note that the location attributes for struct fields are
15915 generated by the routine `data_member_location_attribute' below. */
15918 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
15919 dw_loc_list_ref descr)
15923 if (single_element_loc_list_p (descr))
15924 add_AT_loc (die, attr_kind, descr->expr);
15926 add_AT_loc_list (die, attr_kind, descr);
15929 /* Add DW_AT_accessibility attribute to DIE if needed. */
15932 add_accessibility_attribute (dw_die_ref die, tree decl)
15934 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15935 children, otherwise the default is DW_ACCESS_public. In DWARF2
15936 the default has always been DW_ACCESS_public. */
15937 if (TREE_PROTECTED (decl))
15938 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15939 else if (TREE_PRIVATE (decl))
15941 if (dwarf_version == 2
15942 || die->die_parent == NULL
15943 || die->die_parent->die_tag != DW_TAG_class_type)
15944 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
15946 else if (dwarf_version > 2
15948 && die->die_parent->die_tag == DW_TAG_class_type)
15949 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
15952 /* Attach the specialized form of location attribute used for data members of
15953 struct and union types. In the special case of a FIELD_DECL node which
15954 represents a bit-field, the "offset" part of this special location
15955 descriptor must indicate the distance in bytes from the lowest-addressed
15956 byte of the containing struct or union type to the lowest-addressed byte of
15957 the "containing object" for the bit-field. (See the `field_byte_offset'
15960 For any given bit-field, the "containing object" is a hypothetical object
15961 (of some integral or enum type) within which the given bit-field lives. The
15962 type of this hypothetical "containing object" is always the same as the
15963 declared type of the individual bit-field itself (for GCC anyway... the
15964 DWARF spec doesn't actually mandate this). Note that it is the size (in
15965 bytes) of the hypothetical "containing object" which will be given in the
15966 DW_AT_byte_size attribute for this bit-field. (See the
15967 `byte_size_attribute' function below.) It is also used when calculating the
15968 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15969 function below.) */
15972 add_data_member_location_attribute (dw_die_ref die, tree decl)
15974 HOST_WIDE_INT offset;
15975 dw_loc_descr_ref loc_descr = 0;
15977 if (TREE_CODE (decl) == TREE_BINFO)
15979 /* We're working on the TAG_inheritance for a base class. */
15980 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
15982 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15983 aren't at a fixed offset from all (sub)objects of the same
15984 type. We need to extract the appropriate offset from our
15985 vtable. The following dwarf expression means
15987 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15989 This is specific to the V3 ABI, of course. */
15991 dw_loc_descr_ref tmp;
15993 /* Make a copy of the object address. */
15994 tmp = new_loc_descr (DW_OP_dup, 0, 0);
15995 add_loc_descr (&loc_descr, tmp);
15997 /* Extract the vtable address. */
15998 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15999 add_loc_descr (&loc_descr, tmp);
16001 /* Calculate the address of the offset. */
16002 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16003 gcc_assert (offset < 0);
16005 tmp = int_loc_descriptor (-offset);
16006 add_loc_descr (&loc_descr, tmp);
16007 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16008 add_loc_descr (&loc_descr, tmp);
16010 /* Extract the offset. */
16011 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16012 add_loc_descr (&loc_descr, tmp);
16014 /* Add it to the object address. */
16015 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16016 add_loc_descr (&loc_descr, tmp);
16019 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16022 offset = field_byte_offset (decl);
16026 if (dwarf_version > 2)
16028 /* Don't need to output a location expression, just the constant. */
16030 add_AT_int (die, DW_AT_data_member_location, offset);
16032 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16037 enum dwarf_location_atom op;
16039 /* The DWARF2 standard says that we should assume that the structure
16040 address is already on the stack, so we can specify a structure
16041 field address by using DW_OP_plus_uconst. */
16043 #ifdef MIPS_DEBUGGING_INFO
16044 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16045 operator correctly. It works only if we leave the offset on the
16049 op = DW_OP_plus_uconst;
16052 loc_descr = new_loc_descr (op, offset, 0);
16056 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16059 /* Writes integer values to dw_vec_const array. */
16062 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16066 *dest++ = val & 0xff;
16072 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16074 static HOST_WIDE_INT
16075 extract_int (const unsigned char *src, unsigned int size)
16077 HOST_WIDE_INT val = 0;
16083 val |= *--src & 0xff;
16089 /* Writes double_int values to dw_vec_const array. */
16092 insert_double (double_int val, unsigned char *dest)
16094 unsigned char *p0 = dest;
16095 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16097 if (WORDS_BIG_ENDIAN)
16103 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16104 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16107 /* Writes floating point values to dw_vec_const array. */
16110 insert_float (const_rtx rtl, unsigned char *array)
16112 REAL_VALUE_TYPE rv;
16116 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16117 real_to_target (val, &rv, GET_MODE (rtl));
16119 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16120 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16122 insert_int (val[i], 4, array);
16127 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16128 does not have a "location" either in memory or in a register. These
16129 things can arise in GNU C when a constant is passed as an actual parameter
16130 to an inlined function. They can also arise in C++ where declared
16131 constants do not necessarily get memory "homes". */
16134 add_const_value_attribute (dw_die_ref die, rtx rtl)
16136 switch (GET_CODE (rtl))
16140 HOST_WIDE_INT val = INTVAL (rtl);
16143 add_AT_int (die, DW_AT_const_value, val);
16145 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16150 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16151 floating-point constant. A CONST_DOUBLE is used whenever the
16152 constant requires more than one word in order to be adequately
16155 enum machine_mode mode = GET_MODE (rtl);
16157 if (SCALAR_FLOAT_MODE_P (mode))
16159 unsigned int length = GET_MODE_SIZE (mode);
16160 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16162 insert_float (rtl, array);
16163 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16166 add_AT_double (die, DW_AT_const_value,
16167 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16173 enum machine_mode mode = GET_MODE (rtl);
16174 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16175 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16176 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16177 (length * elt_size);
16181 switch (GET_MODE_CLASS (mode))
16183 case MODE_VECTOR_INT:
16184 for (i = 0, p = array; i < length; i++, p += elt_size)
16186 rtx elt = CONST_VECTOR_ELT (rtl, i);
16187 double_int val = rtx_to_double_int (elt);
16189 if (elt_size <= sizeof (HOST_WIDE_INT))
16190 insert_int (double_int_to_shwi (val), elt_size, p);
16193 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16194 insert_double (val, p);
16199 case MODE_VECTOR_FLOAT:
16200 for (i = 0, p = array; i < length; i++, p += elt_size)
16202 rtx elt = CONST_VECTOR_ELT (rtl, i);
16203 insert_float (elt, p);
16208 gcc_unreachable ();
16211 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16216 if (dwarf_version >= 4 || !dwarf_strict)
16218 dw_loc_descr_ref loc_result;
16219 resolve_one_addr (&rtl, NULL);
16221 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16222 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16223 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16224 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16225 add_AT_loc (die, DW_AT_location, loc_result);
16226 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16232 if (CONSTANT_P (XEXP (rtl, 0)))
16233 return add_const_value_attribute (die, XEXP (rtl, 0));
16236 if (!const_ok_for_output (rtl))
16239 if (dwarf_version >= 4 || !dwarf_strict)
16244 /* In cases where an inlined instance of an inline function is passed
16245 the address of an `auto' variable (which is local to the caller) we
16246 can get a situation where the DECL_RTL of the artificial local
16247 variable (for the inlining) which acts as a stand-in for the
16248 corresponding formal parameter (of the inline function) will look
16249 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16250 exactly a compile-time constant expression, but it isn't the address
16251 of the (artificial) local variable either. Rather, it represents the
16252 *value* which the artificial local variable always has during its
16253 lifetime. We currently have no way to represent such quasi-constant
16254 values in Dwarf, so for now we just punt and generate nothing. */
16262 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16263 && MEM_READONLY_P (rtl)
16264 && GET_MODE (rtl) == BLKmode)
16266 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16272 /* No other kinds of rtx should be possible here. */
16273 gcc_unreachable ();
16278 /* Determine whether the evaluation of EXPR references any variables
16279 or functions which aren't otherwise used (and therefore may not be
16282 reference_to_unused (tree * tp, int * walk_subtrees,
16283 void * data ATTRIBUTE_UNUSED)
16285 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16286 *walk_subtrees = 0;
16288 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16289 && ! TREE_ASM_WRITTEN (*tp))
16291 /* ??? The C++ FE emits debug information for using decls, so
16292 putting gcc_unreachable here falls over. See PR31899. For now
16293 be conservative. */
16294 else if (!cgraph_global_info_ready
16295 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16297 else if (TREE_CODE (*tp) == VAR_DECL)
16299 struct varpool_node *node = varpool_get_node (*tp);
16300 if (!node || !node->needed)
16303 else if (TREE_CODE (*tp) == FUNCTION_DECL
16304 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16306 /* The call graph machinery must have finished analyzing,
16307 optimizing and gimplifying the CU by now.
16308 So if *TP has no call graph node associated
16309 to it, it means *TP will not be emitted. */
16310 if (!cgraph_get_node (*tp))
16313 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16319 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16320 for use in a later add_const_value_attribute call. */
16323 rtl_for_decl_init (tree init, tree type)
16325 rtx rtl = NULL_RTX;
16327 /* If a variable is initialized with a string constant without embedded
16328 zeros, build CONST_STRING. */
16329 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16331 tree enttype = TREE_TYPE (type);
16332 tree domain = TYPE_DOMAIN (type);
16333 enum machine_mode mode = TYPE_MODE (enttype);
16335 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16337 && integer_zerop (TYPE_MIN_VALUE (domain))
16338 && compare_tree_int (TYPE_MAX_VALUE (domain),
16339 TREE_STRING_LENGTH (init) - 1) == 0
16340 && ((size_t) TREE_STRING_LENGTH (init)
16341 == strlen (TREE_STRING_POINTER (init)) + 1))
16343 rtl = gen_rtx_CONST_STRING (VOIDmode,
16344 ggc_strdup (TREE_STRING_POINTER (init)));
16345 rtl = gen_rtx_MEM (BLKmode, rtl);
16346 MEM_READONLY_P (rtl) = 1;
16349 /* Other aggregates, and complex values, could be represented using
16351 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
16353 /* Vectors only work if their mode is supported by the target.
16354 FIXME: generic vectors ought to work too. */
16355 else if (TREE_CODE (type) == VECTOR_TYPE
16356 && !VECTOR_MODE_P (TYPE_MODE (type)))
16358 /* If the initializer is something that we know will expand into an
16359 immediate RTL constant, expand it now. We must be careful not to
16360 reference variables which won't be output. */
16361 else if (initializer_constant_valid_p (init, type)
16362 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16364 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16366 if (TREE_CODE (type) == VECTOR_TYPE)
16367 switch (TREE_CODE (init))
16372 if (TREE_CONSTANT (init))
16374 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16375 bool constant_p = true;
16377 unsigned HOST_WIDE_INT ix;
16379 /* Even when ctor is constant, it might contain non-*_CST
16380 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16381 belong into VECTOR_CST nodes. */
16382 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16383 if (!CONSTANT_CLASS_P (value))
16385 constant_p = false;
16391 init = build_vector_from_ctor (type, elts);
16401 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16403 /* If expand_expr returns a MEM, it wasn't immediate. */
16404 gcc_assert (!rtl || !MEM_P (rtl));
16410 /* Generate RTL for the variable DECL to represent its location. */
16413 rtl_for_decl_location (tree decl)
16417 /* Here we have to decide where we are going to say the parameter "lives"
16418 (as far as the debugger is concerned). We only have a couple of
16419 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16421 DECL_RTL normally indicates where the parameter lives during most of the
16422 activation of the function. If optimization is enabled however, this
16423 could be either NULL or else a pseudo-reg. Both of those cases indicate
16424 that the parameter doesn't really live anywhere (as far as the code
16425 generation parts of GCC are concerned) during most of the function's
16426 activation. That will happen (for example) if the parameter is never
16427 referenced within the function.
16429 We could just generate a location descriptor here for all non-NULL
16430 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16431 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16432 where DECL_RTL is NULL or is a pseudo-reg.
16434 Note however that we can only get away with using DECL_INCOMING_RTL as
16435 a backup substitute for DECL_RTL in certain limited cases. In cases
16436 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16437 we can be sure that the parameter was passed using the same type as it is
16438 declared to have within the function, and that its DECL_INCOMING_RTL
16439 points us to a place where a value of that type is passed.
16441 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16442 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16443 because in these cases DECL_INCOMING_RTL points us to a value of some
16444 type which is *different* from the type of the parameter itself. Thus,
16445 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16446 such cases, the debugger would end up (for example) trying to fetch a
16447 `float' from a place which actually contains the first part of a
16448 `double'. That would lead to really incorrect and confusing
16449 output at debug-time.
16451 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16452 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16453 are a couple of exceptions however. On little-endian machines we can
16454 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16455 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16456 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16457 when (on a little-endian machine) a non-prototyped function has a
16458 parameter declared to be of type `short' or `char'. In such cases,
16459 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16460 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16461 passed `int' value. If the debugger then uses that address to fetch
16462 a `short' or a `char' (on a little-endian machine) the result will be
16463 the correct data, so we allow for such exceptional cases below.
16465 Note that our goal here is to describe the place where the given formal
16466 parameter lives during most of the function's activation (i.e. between the
16467 end of the prologue and the start of the epilogue). We'll do that as best
16468 as we can. Note however that if the given formal parameter is modified
16469 sometime during the execution of the function, then a stack backtrace (at
16470 debug-time) will show the function as having been called with the *new*
16471 value rather than the value which was originally passed in. This happens
16472 rarely enough that it is not a major problem, but it *is* a problem, and
16473 I'd like to fix it.
16475 A future version of dwarf2out.c may generate two additional attributes for
16476 any given DW_TAG_formal_parameter DIE which will describe the "passed
16477 type" and the "passed location" for the given formal parameter in addition
16478 to the attributes we now generate to indicate the "declared type" and the
16479 "active location" for each parameter. This additional set of attributes
16480 could be used by debuggers for stack backtraces. Separately, note that
16481 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16482 This happens (for example) for inlined-instances of inline function formal
16483 parameters which are never referenced. This really shouldn't be
16484 happening. All PARM_DECL nodes should get valid non-NULL
16485 DECL_INCOMING_RTL values. FIXME. */
16487 /* Use DECL_RTL as the "location" unless we find something better. */
16488 rtl = DECL_RTL_IF_SET (decl);
16490 /* When generating abstract instances, ignore everything except
16491 constants, symbols living in memory, and symbols living in
16492 fixed registers. */
16493 if (! reload_completed)
16496 && (CONSTANT_P (rtl)
16498 && CONSTANT_P (XEXP (rtl, 0)))
16500 && TREE_CODE (decl) == VAR_DECL
16501 && TREE_STATIC (decl))))
16503 rtl = targetm.delegitimize_address (rtl);
16508 else if (TREE_CODE (decl) == PARM_DECL)
16510 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16512 tree declared_type = TREE_TYPE (decl);
16513 tree passed_type = DECL_ARG_TYPE (decl);
16514 enum machine_mode dmode = TYPE_MODE (declared_type);
16515 enum machine_mode pmode = TYPE_MODE (passed_type);
16517 /* This decl represents a formal parameter which was optimized out.
16518 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16519 all cases where (rtl == NULL_RTX) just below. */
16520 if (dmode == pmode)
16521 rtl = DECL_INCOMING_RTL (decl);
16522 else if (SCALAR_INT_MODE_P (dmode)
16523 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16524 && DECL_INCOMING_RTL (decl))
16526 rtx inc = DECL_INCOMING_RTL (decl);
16529 else if (MEM_P (inc))
16531 if (BYTES_BIG_ENDIAN)
16532 rtl = adjust_address_nv (inc, dmode,
16533 GET_MODE_SIZE (pmode)
16534 - GET_MODE_SIZE (dmode));
16541 /* If the parm was passed in registers, but lives on the stack, then
16542 make a big endian correction if the mode of the type of the
16543 parameter is not the same as the mode of the rtl. */
16544 /* ??? This is the same series of checks that are made in dbxout.c before
16545 we reach the big endian correction code there. It isn't clear if all
16546 of these checks are necessary here, but keeping them all is the safe
16548 else if (MEM_P (rtl)
16549 && XEXP (rtl, 0) != const0_rtx
16550 && ! CONSTANT_P (XEXP (rtl, 0))
16551 /* Not passed in memory. */
16552 && !MEM_P (DECL_INCOMING_RTL (decl))
16553 /* Not passed by invisible reference. */
16554 && (!REG_P (XEXP (rtl, 0))
16555 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16556 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16557 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
16558 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16561 /* Big endian correction check. */
16562 && BYTES_BIG_ENDIAN
16563 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16564 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16567 int offset = (UNITS_PER_WORD
16568 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16570 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16571 plus_constant (XEXP (rtl, 0), offset));
16574 else if (TREE_CODE (decl) == VAR_DECL
16577 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16578 && BYTES_BIG_ENDIAN)
16580 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16581 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16583 /* If a variable is declared "register" yet is smaller than
16584 a register, then if we store the variable to memory, it
16585 looks like we're storing a register-sized value, when in
16586 fact we are not. We need to adjust the offset of the
16587 storage location to reflect the actual value's bytes,
16588 else gdb will not be able to display it. */
16590 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16591 plus_constant (XEXP (rtl, 0), rsize-dsize));
16594 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16595 and will have been substituted directly into all expressions that use it.
16596 C does not have such a concept, but C++ and other languages do. */
16597 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16598 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16601 rtl = targetm.delegitimize_address (rtl);
16603 /* If we don't look past the constant pool, we risk emitting a
16604 reference to a constant pool entry that isn't referenced from
16605 code, and thus is not emitted. */
16607 rtl = avoid_constant_pool_reference (rtl);
16609 /* Try harder to get a rtl. If this symbol ends up not being emitted
16610 in the current CU, resolve_addr will remove the expression referencing
16612 if (rtl == NULL_RTX
16613 && TREE_CODE (decl) == VAR_DECL
16614 && !DECL_EXTERNAL (decl)
16615 && TREE_STATIC (decl)
16616 && DECL_NAME (decl)
16617 && !DECL_HARD_REGISTER (decl)
16618 && DECL_MODE (decl) != VOIDmode)
16620 rtl = make_decl_rtl_for_debug (decl);
16622 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16623 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16630 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16631 returned. If so, the decl for the COMMON block is returned, and the
16632 value is the offset into the common block for the symbol. */
16635 fortran_common (tree decl, HOST_WIDE_INT *value)
16637 tree val_expr, cvar;
16638 enum machine_mode mode;
16639 HOST_WIDE_INT bitsize, bitpos;
16641 int volatilep = 0, unsignedp = 0;
16643 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16644 it does not have a value (the offset into the common area), or if it
16645 is thread local (as opposed to global) then it isn't common, and shouldn't
16646 be handled as such. */
16647 if (TREE_CODE (decl) != VAR_DECL
16648 || !TREE_STATIC (decl)
16649 || !DECL_HAS_VALUE_EXPR_P (decl)
16653 val_expr = DECL_VALUE_EXPR (decl);
16654 if (TREE_CODE (val_expr) != COMPONENT_REF)
16657 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16658 &mode, &unsignedp, &volatilep, true);
16660 if (cvar == NULL_TREE
16661 || TREE_CODE (cvar) != VAR_DECL
16662 || DECL_ARTIFICIAL (cvar)
16663 || !TREE_PUBLIC (cvar))
16667 if (offset != NULL)
16669 if (!host_integerp (offset, 0))
16671 *value = tree_low_cst (offset, 0);
16674 *value += bitpos / BITS_PER_UNIT;
16679 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16680 data attribute for a variable or a parameter. We generate the
16681 DW_AT_const_value attribute only in those cases where the given variable
16682 or parameter does not have a true "location" either in memory or in a
16683 register. This can happen (for example) when a constant is passed as an
16684 actual argument in a call to an inline function. (It's possible that
16685 these things can crop up in other ways also.) Note that one type of
16686 constant value which can be passed into an inlined function is a constant
16687 pointer. This can happen for example if an actual argument in an inlined
16688 function call evaluates to a compile-time constant address. */
16691 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16692 enum dwarf_attribute attr)
16695 dw_loc_list_ref list;
16696 var_loc_list *loc_list;
16698 if (TREE_CODE (decl) == ERROR_MARK)
16701 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16702 || TREE_CODE (decl) == RESULT_DECL);
16704 /* Try to get some constant RTL for this decl, and use that as the value of
16707 rtl = rtl_for_decl_location (decl);
16708 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16709 && add_const_value_attribute (die, rtl))
16712 /* See if we have single element location list that is equivalent to
16713 a constant value. That way we are better to use add_const_value_attribute
16714 rather than expanding constant value equivalent. */
16715 loc_list = lookup_decl_loc (decl);
16718 && loc_list->first->next == NULL
16719 && NOTE_P (loc_list->first->loc)
16720 && NOTE_VAR_LOCATION (loc_list->first->loc)
16721 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16723 struct var_loc_node *node;
16725 node = loc_list->first;
16726 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16727 if (GET_CODE (rtl) == EXPR_LIST)
16728 rtl = XEXP (rtl, 0);
16729 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16730 && add_const_value_attribute (die, rtl))
16733 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16736 add_AT_location_description (die, attr, list);
16739 /* None of that worked, so it must not really have a location;
16740 try adding a constant value attribute from the DECL_INITIAL. */
16741 return tree_add_const_value_attribute_for_decl (die, decl);
16744 /* Add VARIABLE and DIE into deferred locations list. */
16747 defer_location (tree variable, dw_die_ref die)
16749 deferred_locations entry;
16750 entry.variable = variable;
16752 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16755 /* Helper function for tree_add_const_value_attribute. Natively encode
16756 initializer INIT into an array. Return true if successful. */
16759 native_encode_initializer (tree init, unsigned char *array, int size)
16763 if (init == NULL_TREE)
16767 switch (TREE_CODE (init))
16770 type = TREE_TYPE (init);
16771 if (TREE_CODE (type) == ARRAY_TYPE)
16773 tree enttype = TREE_TYPE (type);
16774 enum machine_mode mode = TYPE_MODE (enttype);
16776 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16778 if (int_size_in_bytes (type) != size)
16780 if (size > TREE_STRING_LENGTH (init))
16782 memcpy (array, TREE_STRING_POINTER (init),
16783 TREE_STRING_LENGTH (init));
16784 memset (array + TREE_STRING_LENGTH (init),
16785 '\0', size - TREE_STRING_LENGTH (init));
16788 memcpy (array, TREE_STRING_POINTER (init), size);
16793 type = TREE_TYPE (init);
16794 if (int_size_in_bytes (type) != size)
16796 if (TREE_CODE (type) == ARRAY_TYPE)
16798 HOST_WIDE_INT min_index;
16799 unsigned HOST_WIDE_INT cnt;
16800 int curpos = 0, fieldsize;
16801 constructor_elt *ce;
16803 if (TYPE_DOMAIN (type) == NULL_TREE
16804 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16807 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16808 if (fieldsize <= 0)
16811 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16812 memset (array, '\0', size);
16813 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16815 tree val = ce->value;
16816 tree index = ce->index;
16818 if (index && TREE_CODE (index) == RANGE_EXPR)
16819 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
16822 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
16827 if (!native_encode_initializer (val, array + pos, fieldsize))
16830 curpos = pos + fieldsize;
16831 if (index && TREE_CODE (index) == RANGE_EXPR)
16833 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
16834 - tree_low_cst (TREE_OPERAND (index, 0), 0);
16838 memcpy (array + curpos, array + pos, fieldsize);
16839 curpos += fieldsize;
16842 gcc_assert (curpos <= size);
16846 else if (TREE_CODE (type) == RECORD_TYPE
16847 || TREE_CODE (type) == UNION_TYPE)
16849 tree field = NULL_TREE;
16850 unsigned HOST_WIDE_INT cnt;
16851 constructor_elt *ce;
16853 if (int_size_in_bytes (type) != size)
16856 if (TREE_CODE (type) == RECORD_TYPE)
16857 field = TYPE_FIELDS (type);
16859 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16861 tree val = ce->value;
16862 int pos, fieldsize;
16864 if (ce->index != 0)
16870 if (field == NULL_TREE || DECL_BIT_FIELD (field))
16873 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
16874 && TYPE_DOMAIN (TREE_TYPE (field))
16875 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
16877 else if (DECL_SIZE_UNIT (field) == NULL_TREE
16878 || !host_integerp (DECL_SIZE_UNIT (field), 0))
16880 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
16881 pos = int_byte_position (field);
16882 gcc_assert (pos + fieldsize <= size);
16884 && !native_encode_initializer (val, array + pos, fieldsize))
16890 case VIEW_CONVERT_EXPR:
16891 case NON_LVALUE_EXPR:
16892 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
16894 return native_encode_expr (init, array, size) == size;
16898 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16899 attribute is the const value T. */
16902 tree_add_const_value_attribute (dw_die_ref die, tree t)
16905 tree type = TREE_TYPE (t);
16908 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
16912 gcc_assert (!DECL_P (init));
16914 rtl = rtl_for_decl_init (init, type);
16916 return add_const_value_attribute (die, rtl);
16917 /* If the host and target are sane, try harder. */
16918 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
16919 && initializer_constant_valid_p (init, type))
16921 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
16922 if (size > 0 && (int) size == size)
16924 unsigned char *array = (unsigned char *)
16925 ggc_alloc_cleared_atomic (size);
16927 if (native_encode_initializer (init, array, size))
16929 add_AT_vec (die, DW_AT_const_value, size, 1, array);
16937 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16938 attribute is the const value of T, where T is an integral constant
16939 variable with static storage duration
16940 (so it can't be a PARM_DECL or a RESULT_DECL). */
16943 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
16947 || (TREE_CODE (decl) != VAR_DECL
16948 && TREE_CODE (decl) != CONST_DECL))
16951 if (TREE_READONLY (decl)
16952 && ! TREE_THIS_VOLATILE (decl)
16953 && DECL_INITIAL (decl))
16958 /* Don't add DW_AT_const_value if abstract origin already has one. */
16959 if (get_AT (var_die, DW_AT_const_value))
16962 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
16965 /* Convert the CFI instructions for the current function into a
16966 location list. This is used for DW_AT_frame_base when we targeting
16967 a dwarf2 consumer that does not support the dwarf3
16968 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16971 static dw_loc_list_ref
16972 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
16975 dw_loc_list_ref list, *list_tail;
16977 dw_cfa_location last_cfa, next_cfa;
16978 const char *start_label, *last_label, *section;
16979 dw_cfa_location remember;
16981 fde = current_fde ();
16982 gcc_assert (fde != NULL);
16984 section = secname_for_decl (current_function_decl);
16988 memset (&next_cfa, 0, sizeof (next_cfa));
16989 next_cfa.reg = INVALID_REGNUM;
16990 remember = next_cfa;
16992 start_label = fde->dw_fde_begin;
16994 /* ??? Bald assumption that the CIE opcode list does not contain
16995 advance opcodes. */
16996 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
16997 lookup_cfa_1 (cfi, &next_cfa, &remember);
16999 last_cfa = next_cfa;
17000 last_label = start_label;
17002 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17003 switch (cfi->dw_cfi_opc)
17005 case DW_CFA_set_loc:
17006 case DW_CFA_advance_loc1:
17007 case DW_CFA_advance_loc2:
17008 case DW_CFA_advance_loc4:
17009 if (!cfa_equal_p (&last_cfa, &next_cfa))
17011 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17012 start_label, last_label, section);
17014 list_tail = &(*list_tail)->dw_loc_next;
17015 last_cfa = next_cfa;
17016 start_label = last_label;
17018 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17021 case DW_CFA_advance_loc:
17022 /* The encoding is complex enough that we should never emit this. */
17023 gcc_unreachable ();
17026 lookup_cfa_1 (cfi, &next_cfa, &remember);
17030 if (!cfa_equal_p (&last_cfa, &next_cfa))
17032 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17033 start_label, last_label, section);
17034 list_tail = &(*list_tail)->dw_loc_next;
17035 start_label = last_label;
17038 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17039 start_label, fde->dw_fde_end, section);
17041 if (list && list->dw_loc_next)
17047 /* Compute a displacement from the "steady-state frame pointer" to the
17048 frame base (often the same as the CFA), and store it in
17049 frame_pointer_fb_offset. OFFSET is added to the displacement
17050 before the latter is negated. */
17053 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17057 #ifdef FRAME_POINTER_CFA_OFFSET
17058 reg = frame_pointer_rtx;
17059 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17061 reg = arg_pointer_rtx;
17062 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17065 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17066 if (GET_CODE (elim) == PLUS)
17068 offset += INTVAL (XEXP (elim, 1));
17069 elim = XEXP (elim, 0);
17072 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17073 && (elim == hard_frame_pointer_rtx
17074 || elim == stack_pointer_rtx))
17075 || elim == (frame_pointer_needed
17076 ? hard_frame_pointer_rtx
17077 : stack_pointer_rtx));
17079 frame_pointer_fb_offset = -offset;
17082 /* Generate a DW_AT_name attribute given some string value to be included as
17083 the value of the attribute. */
17086 add_name_attribute (dw_die_ref die, const char *name_string)
17088 if (name_string != NULL && *name_string != 0)
17090 if (demangle_name_func)
17091 name_string = (*demangle_name_func) (name_string);
17093 add_AT_string (die, DW_AT_name, name_string);
17097 /* Generate a DW_AT_comp_dir attribute for DIE. */
17100 add_comp_dir_attribute (dw_die_ref die)
17102 const char *wd = get_src_pwd ();
17108 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17112 wdlen = strlen (wd);
17113 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17115 wd1 [wdlen] = DIR_SEPARATOR;
17116 wd1 [wdlen + 1] = 0;
17120 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17123 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17127 lower_bound_default (void)
17129 switch (get_AT_unsigned (comp_unit_die, DW_AT_language))
17134 case DW_LANG_C_plus_plus:
17136 case DW_LANG_ObjC_plus_plus:
17139 case DW_LANG_Fortran77:
17140 case DW_LANG_Fortran90:
17141 case DW_LANG_Fortran95:
17145 case DW_LANG_Python:
17146 return dwarf_version >= 4 ? 0 : -1;
17147 case DW_LANG_Ada95:
17148 case DW_LANG_Ada83:
17149 case DW_LANG_Cobol74:
17150 case DW_LANG_Cobol85:
17151 case DW_LANG_Pascal83:
17152 case DW_LANG_Modula2:
17154 return dwarf_version >= 4 ? 1 : -1;
17160 /* Given a tree node describing an array bound (either lower or upper) output
17161 a representation for that bound. */
17164 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17166 switch (TREE_CODE (bound))
17171 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17174 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17177 /* Use the default if possible. */
17178 if (bound_attr == DW_AT_lower_bound
17179 && host_integerp (bound, 0)
17180 && (dflt = lower_bound_default ()) != -1
17181 && tree_low_cst (bound, 0) == dflt)
17184 /* Otherwise represent the bound as an unsigned value with the
17185 precision of its type. The precision and signedness of the
17186 type will be necessary to re-interpret it unambiguously. */
17187 else if (prec < HOST_BITS_PER_WIDE_INT)
17189 unsigned HOST_WIDE_INT mask
17190 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17191 add_AT_unsigned (subrange_die, bound_attr,
17192 TREE_INT_CST_LOW (bound) & mask);
17194 else if (prec == HOST_BITS_PER_WIDE_INT
17195 || TREE_INT_CST_HIGH (bound) == 0)
17196 add_AT_unsigned (subrange_die, bound_attr,
17197 TREE_INT_CST_LOW (bound));
17199 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17200 TREE_INT_CST_LOW (bound));
17205 case VIEW_CONVERT_EXPR:
17206 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17216 dw_die_ref decl_die = lookup_decl_die (bound);
17218 /* ??? Can this happen, or should the variable have been bound
17219 first? Probably it can, since I imagine that we try to create
17220 the types of parameters in the order in which they exist in
17221 the list, and won't have created a forward reference to a
17222 later parameter. */
17223 if (decl_die != NULL)
17225 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17233 /* Otherwise try to create a stack operation procedure to
17234 evaluate the value of the array bound. */
17236 dw_die_ref ctx, decl_die;
17237 dw_loc_list_ref list;
17239 list = loc_list_from_tree (bound, 2);
17240 if (list == NULL || single_element_loc_list_p (list))
17242 /* If DW_AT_*bound is not a reference nor constant, it is
17243 a DWARF expression rather than location description.
17244 For that loc_list_from_tree (bound, 0) is needed.
17245 If that fails to give a single element list,
17246 fall back to outputting this as a reference anyway. */
17247 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17248 if (list2 && single_element_loc_list_p (list2))
17250 add_AT_loc (subrange_die, bound_attr, list2->expr);
17257 if (current_function_decl == 0)
17258 ctx = comp_unit_die;
17260 ctx = lookup_decl_die (current_function_decl);
17262 decl_die = new_die (DW_TAG_variable, ctx, bound);
17263 add_AT_flag (decl_die, DW_AT_artificial, 1);
17264 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17265 add_AT_location_description (decl_die, DW_AT_location, list);
17266 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17272 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17273 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17274 Note that the block of subscript information for an array type also
17275 includes information about the element type of the given array type. */
17278 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17280 unsigned dimension_number;
17282 dw_die_ref subrange_die;
17284 for (dimension_number = 0;
17285 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17286 type = TREE_TYPE (type), dimension_number++)
17288 tree domain = TYPE_DOMAIN (type);
17290 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17293 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17294 and (in GNU C only) variable bounds. Handle all three forms
17296 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17299 /* We have an array type with specified bounds. */
17300 lower = TYPE_MIN_VALUE (domain);
17301 upper = TYPE_MAX_VALUE (domain);
17303 /* Define the index type. */
17304 if (TREE_TYPE (domain))
17306 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17307 TREE_TYPE field. We can't emit debug info for this
17308 because it is an unnamed integral type. */
17309 if (TREE_CODE (domain) == INTEGER_TYPE
17310 && TYPE_NAME (domain) == NULL_TREE
17311 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17312 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17315 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17319 /* ??? If upper is NULL, the array has unspecified length,
17320 but it does have a lower bound. This happens with Fortran
17322 Since the debugger is definitely going to need to know N
17323 to produce useful results, go ahead and output the lower
17324 bound solo, and hope the debugger can cope. */
17326 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17328 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17331 /* Otherwise we have an array type with an unspecified length. The
17332 DWARF-2 spec does not say how to handle this; let's just leave out the
17338 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17342 switch (TREE_CODE (tree_node))
17347 case ENUMERAL_TYPE:
17350 case QUAL_UNION_TYPE:
17351 size = int_size_in_bytes (tree_node);
17354 /* For a data member of a struct or union, the DW_AT_byte_size is
17355 generally given as the number of bytes normally allocated for an
17356 object of the *declared* type of the member itself. This is true
17357 even for bit-fields. */
17358 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17361 gcc_unreachable ();
17364 /* Note that `size' might be -1 when we get to this point. If it is, that
17365 indicates that the byte size of the entity in question is variable. We
17366 have no good way of expressing this fact in Dwarf at the present time,
17367 so just let the -1 pass on through. */
17368 add_AT_unsigned (die, DW_AT_byte_size, size);
17371 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17372 which specifies the distance in bits from the highest order bit of the
17373 "containing object" for the bit-field to the highest order bit of the
17376 For any given bit-field, the "containing object" is a hypothetical object
17377 (of some integral or enum type) within which the given bit-field lives. The
17378 type of this hypothetical "containing object" is always the same as the
17379 declared type of the individual bit-field itself. The determination of the
17380 exact location of the "containing object" for a bit-field is rather
17381 complicated. It's handled by the `field_byte_offset' function (above).
17383 Note that it is the size (in bytes) of the hypothetical "containing object"
17384 which will be given in the DW_AT_byte_size attribute for this bit-field.
17385 (See `byte_size_attribute' above). */
17388 add_bit_offset_attribute (dw_die_ref die, tree decl)
17390 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17391 tree type = DECL_BIT_FIELD_TYPE (decl);
17392 HOST_WIDE_INT bitpos_int;
17393 HOST_WIDE_INT highest_order_object_bit_offset;
17394 HOST_WIDE_INT highest_order_field_bit_offset;
17395 HOST_WIDE_INT unsigned bit_offset;
17397 /* Must be a field and a bit field. */
17398 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17400 /* We can't yet handle bit-fields whose offsets are variable, so if we
17401 encounter such things, just return without generating any attribute
17402 whatsoever. Likewise for variable or too large size. */
17403 if (! host_integerp (bit_position (decl), 0)
17404 || ! host_integerp (DECL_SIZE (decl), 1))
17407 bitpos_int = int_bit_position (decl);
17409 /* Note that the bit offset is always the distance (in bits) from the
17410 highest-order bit of the "containing object" to the highest-order bit of
17411 the bit-field itself. Since the "high-order end" of any object or field
17412 is different on big-endian and little-endian machines, the computation
17413 below must take account of these differences. */
17414 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17415 highest_order_field_bit_offset = bitpos_int;
17417 if (! BYTES_BIG_ENDIAN)
17419 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17420 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17424 = (! BYTES_BIG_ENDIAN
17425 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17426 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17428 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
17431 /* For a FIELD_DECL node which represents a bit field, output an attribute
17432 which specifies the length in bits of the given field. */
17435 add_bit_size_attribute (dw_die_ref die, tree decl)
17437 /* Must be a field and a bit field. */
17438 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17439 && DECL_BIT_FIELD_TYPE (decl));
17441 if (host_integerp (DECL_SIZE (decl), 1))
17442 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17445 /* If the compiled language is ANSI C, then add a 'prototyped'
17446 attribute, if arg types are given for the parameters of a function. */
17449 add_prototyped_attribute (dw_die_ref die, tree func_type)
17451 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
17452 && TYPE_ARG_TYPES (func_type) != NULL)
17453 add_AT_flag (die, DW_AT_prototyped, 1);
17456 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17457 by looking in either the type declaration or object declaration
17460 static inline dw_die_ref
17461 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17463 dw_die_ref origin_die = NULL;
17465 if (TREE_CODE (origin) != FUNCTION_DECL)
17467 /* We may have gotten separated from the block for the inlined
17468 function, if we're in an exception handler or some such; make
17469 sure that the abstract function has been written out.
17471 Doing this for nested functions is wrong, however; functions are
17472 distinct units, and our context might not even be inline. */
17476 fn = TYPE_STUB_DECL (fn);
17478 fn = decl_function_context (fn);
17480 dwarf2out_abstract_function (fn);
17483 if (DECL_P (origin))
17484 origin_die = lookup_decl_die (origin);
17485 else if (TYPE_P (origin))
17486 origin_die = lookup_type_die (origin);
17488 /* XXX: Functions that are never lowered don't always have correct block
17489 trees (in the case of java, they simply have no block tree, in some other
17490 languages). For these functions, there is nothing we can really do to
17491 output correct debug info for inlined functions in all cases. Rather
17492 than die, we'll just produce deficient debug info now, in that we will
17493 have variables without a proper abstract origin. In the future, when all
17494 functions are lowered, we should re-add a gcc_assert (origin_die)
17498 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17502 /* We do not currently support the pure_virtual attribute. */
17505 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17507 if (DECL_VINDEX (func_decl))
17509 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17511 if (host_integerp (DECL_VINDEX (func_decl), 0))
17512 add_AT_loc (die, DW_AT_vtable_elem_location,
17513 new_loc_descr (DW_OP_constu,
17514 tree_low_cst (DECL_VINDEX (func_decl), 0),
17517 /* GNU extension: Record what type this method came from originally. */
17518 if (debug_info_level > DINFO_LEVEL_TERSE
17519 && DECL_CONTEXT (func_decl))
17520 add_AT_die_ref (die, DW_AT_containing_type,
17521 lookup_type_die (DECL_CONTEXT (func_decl)));
17525 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17526 given decl. This used to be a vendor extension until after DWARF 4
17527 standardized it. */
17530 add_linkage_attr (dw_die_ref die, tree decl)
17532 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17534 /* Mimic what assemble_name_raw does with a leading '*'. */
17535 if (name[0] == '*')
17538 if (dwarf_version >= 4)
17539 add_AT_string (die, DW_AT_linkage_name, name);
17541 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17544 /* Add source coordinate attributes for the given decl. */
17547 add_src_coords_attributes (dw_die_ref die, tree decl)
17549 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17551 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17552 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17555 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17558 add_linkage_name (dw_die_ref die, tree decl)
17560 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17561 && TREE_PUBLIC (decl)
17562 && !DECL_ABSTRACT (decl)
17563 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17564 && die->die_tag != DW_TAG_member)
17566 /* Defer until we have an assembler name set. */
17567 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17569 limbo_die_node *asm_name;
17571 asm_name = ggc_alloc_cleared_limbo_die_node ();
17572 asm_name->die = die;
17573 asm_name->created_for = decl;
17574 asm_name->next = deferred_asm_name;
17575 deferred_asm_name = asm_name;
17577 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17578 add_linkage_attr (die, decl);
17582 /* Add a DW_AT_name attribute and source coordinate attribute for the
17583 given decl, but only if it actually has a name. */
17586 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17590 decl_name = DECL_NAME (decl);
17591 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17593 const char *name = dwarf2_name (decl, 0);
17595 add_name_attribute (die, name);
17596 if (! DECL_ARTIFICIAL (decl))
17597 add_src_coords_attributes (die, decl);
17599 add_linkage_name (die, decl);
17602 #ifdef VMS_DEBUGGING_INFO
17603 /* Get the function's name, as described by its RTL. This may be different
17604 from the DECL_NAME name used in the source file. */
17605 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17607 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17608 XEXP (DECL_RTL (decl), 0));
17609 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17611 #endif /* VMS_DEBUGGING_INFO */
17614 #ifdef VMS_DEBUGGING_INFO
17615 /* Output the debug main pointer die for VMS */
17618 dwarf2out_vms_debug_main_pointer (void)
17620 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17623 /* Allocate the VMS debug main subprogram die. */
17624 die = ggc_alloc_cleared_die_node ();
17625 die->die_tag = DW_TAG_subprogram;
17626 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17627 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17628 current_function_funcdef_no);
17629 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17631 /* Make it the first child of comp_unit_die. */
17632 die->die_parent = comp_unit_die;
17633 if (comp_unit_die->die_child)
17635 die->die_sib = comp_unit_die->die_child->die_sib;
17636 comp_unit_die->die_child->die_sib = die;
17640 die->die_sib = die;
17641 comp_unit_die->die_child = die;
17644 #endif /* VMS_DEBUGGING_INFO */
17646 /* Push a new declaration scope. */
17649 push_decl_scope (tree scope)
17651 VEC_safe_push (tree, gc, decl_scope_table, scope);
17654 /* Pop a declaration scope. */
17657 pop_decl_scope (void)
17659 VEC_pop (tree, decl_scope_table);
17662 /* Return the DIE for the scope that immediately contains this type.
17663 Non-named types get global scope. Named types nested in other
17664 types get their containing scope if it's open, or global scope
17665 otherwise. All other types (i.e. function-local named types) get
17666 the current active scope. */
17669 scope_die_for (tree t, dw_die_ref context_die)
17671 dw_die_ref scope_die = NULL;
17672 tree containing_scope;
17675 /* Non-types always go in the current scope. */
17676 gcc_assert (TYPE_P (t));
17678 containing_scope = TYPE_CONTEXT (t);
17680 /* Use the containing namespace if it was passed in (for a declaration). */
17681 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17683 if (context_die == lookup_decl_die (containing_scope))
17686 containing_scope = NULL_TREE;
17689 /* Ignore function type "scopes" from the C frontend. They mean that
17690 a tagged type is local to a parmlist of a function declarator, but
17691 that isn't useful to DWARF. */
17692 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17693 containing_scope = NULL_TREE;
17695 if (containing_scope == NULL_TREE)
17696 scope_die = comp_unit_die;
17697 else if (TYPE_P (containing_scope))
17699 /* For types, we can just look up the appropriate DIE. But
17700 first we check to see if we're in the middle of emitting it
17701 so we know where the new DIE should go. */
17702 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17703 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17708 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17709 || TREE_ASM_WRITTEN (containing_scope));
17710 /*We are not in the middle of emitting the type
17711 CONTAINING_SCOPE. Let's see if it's emitted already. */
17712 scope_die = lookup_type_die (containing_scope);
17714 /* If none of the current dies are suitable, we get file scope. */
17715 if (scope_die == NULL)
17716 scope_die = comp_unit_die;
17719 scope_die = lookup_type_die (containing_scope);
17722 scope_die = context_die;
17727 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17730 local_scope_p (dw_die_ref context_die)
17732 for (; context_die; context_die = context_die->die_parent)
17733 if (context_die->die_tag == DW_TAG_inlined_subroutine
17734 || context_die->die_tag == DW_TAG_subprogram)
17740 /* Returns nonzero if CONTEXT_DIE is a class. */
17743 class_scope_p (dw_die_ref context_die)
17745 return (context_die
17746 && (context_die->die_tag == DW_TAG_structure_type
17747 || context_die->die_tag == DW_TAG_class_type
17748 || context_die->die_tag == DW_TAG_interface_type
17749 || context_die->die_tag == DW_TAG_union_type));
17752 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17753 whether or not to treat a DIE in this context as a declaration. */
17756 class_or_namespace_scope_p (dw_die_ref context_die)
17758 return (class_scope_p (context_die)
17759 || (context_die && context_die->die_tag == DW_TAG_namespace));
17762 /* Many forms of DIEs require a "type description" attribute. This
17763 routine locates the proper "type descriptor" die for the type given
17764 by 'type', and adds a DW_AT_type attribute below the given die. */
17767 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17768 int decl_volatile, dw_die_ref context_die)
17770 enum tree_code code = TREE_CODE (type);
17771 dw_die_ref type_die = NULL;
17773 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17774 or fixed-point type, use the inner type. This is because we have no
17775 support for unnamed types in base_type_die. This can happen if this is
17776 an Ada subrange type. Correct solution is emit a subrange type die. */
17777 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17778 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17779 type = TREE_TYPE (type), code = TREE_CODE (type);
17781 if (code == ERROR_MARK
17782 /* Handle a special case. For functions whose return type is void, we
17783 generate *no* type attribute. (Note that no object may have type
17784 `void', so this only applies to function return types). */
17785 || code == VOID_TYPE)
17788 type_die = modified_type_die (type,
17789 decl_const || TYPE_READONLY (type),
17790 decl_volatile || TYPE_VOLATILE (type),
17793 if (type_die != NULL)
17794 add_AT_die_ref (object_die, DW_AT_type, type_die);
17797 /* Given an object die, add the calling convention attribute for the
17798 function call type. */
17800 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17802 enum dwarf_calling_convention value = DW_CC_normal;
17804 value = ((enum dwarf_calling_convention)
17805 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
17807 /* DWARF doesn't provide a way to identify a program's source-level
17808 entry point. DW_AT_calling_convention attributes are only meant
17809 to describe functions' calling conventions. However, lacking a
17810 better way to signal the Fortran main program, we use this for the
17811 time being, following existing custom. */
17813 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
17814 value = DW_CC_program;
17816 /* Only add the attribute if the backend requests it, and
17817 is not DW_CC_normal. */
17818 if (value && (value != DW_CC_normal))
17819 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
17822 /* Given a tree pointer to a struct, class, union, or enum type node, return
17823 a pointer to the (string) tag name for the given type, or zero if the type
17824 was declared without a tag. */
17826 static const char *
17827 type_tag (const_tree type)
17829 const char *name = 0;
17831 if (TYPE_NAME (type) != 0)
17835 /* Find the IDENTIFIER_NODE for the type name. */
17836 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
17837 && !TYPE_NAMELESS (type))
17838 t = TYPE_NAME (type);
17840 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17841 a TYPE_DECL node, regardless of whether or not a `typedef' was
17843 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
17844 && ! DECL_IGNORED_P (TYPE_NAME (type)))
17846 /* We want to be extra verbose. Don't call dwarf_name if
17847 DECL_NAME isn't set. The default hook for decl_printable_name
17848 doesn't like that, and in this context it's correct to return
17849 0, instead of "<anonymous>" or the like. */
17850 if (DECL_NAME (TYPE_NAME (type))
17851 && !DECL_NAMELESS (TYPE_NAME (type)))
17852 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
17855 /* Now get the name as a string, or invent one. */
17856 if (!name && t != 0)
17857 name = IDENTIFIER_POINTER (t);
17860 return (name == 0 || *name == '\0') ? 0 : name;
17863 /* Return the type associated with a data member, make a special check
17864 for bit field types. */
17867 member_declared_type (const_tree member)
17869 return (DECL_BIT_FIELD_TYPE (member)
17870 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
17873 /* Get the decl's label, as described by its RTL. This may be different
17874 from the DECL_NAME name used in the source file. */
17877 static const char *
17878 decl_start_label (tree decl)
17881 const char *fnname;
17883 x = DECL_RTL (decl);
17884 gcc_assert (MEM_P (x));
17887 gcc_assert (GET_CODE (x) == SYMBOL_REF);
17889 fnname = XSTR (x, 0);
17894 /* These routines generate the internal representation of the DIE's for
17895 the compilation unit. Debugging information is collected by walking
17896 the declaration trees passed in from dwarf2out_decl(). */
17899 gen_array_type_die (tree type, dw_die_ref context_die)
17901 dw_die_ref scope_die = scope_die_for (type, context_die);
17902 dw_die_ref array_die;
17904 /* GNU compilers represent multidimensional array types as sequences of one
17905 dimensional array types whose element types are themselves array types.
17906 We sometimes squish that down to a single array_type DIE with multiple
17907 subscripts in the Dwarf debugging info. The draft Dwarf specification
17908 say that we are allowed to do this kind of compression in C, because
17909 there is no difference between an array of arrays and a multidimensional
17910 array. We don't do this for Ada to remain as close as possible to the
17911 actual representation, which is especially important against the language
17912 flexibilty wrt arrays of variable size. */
17914 bool collapse_nested_arrays = !is_ada ();
17917 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17918 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17919 if (TYPE_STRING_FLAG (type)
17920 && TREE_CODE (type) == ARRAY_TYPE
17922 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
17924 HOST_WIDE_INT size;
17926 array_die = new_die (DW_TAG_string_type, scope_die, type);
17927 add_name_attribute (array_die, type_tag (type));
17928 equate_type_number_to_die (type, array_die);
17929 size = int_size_in_bytes (type);
17931 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17932 else if (TYPE_DOMAIN (type) != NULL_TREE
17933 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
17934 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
17936 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
17937 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
17939 size = int_size_in_bytes (TREE_TYPE (szdecl));
17940 if (loc && size > 0)
17942 add_AT_location_description (array_die, DW_AT_string_length, loc);
17943 if (size != DWARF2_ADDR_SIZE)
17944 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17950 /* ??? The SGI dwarf reader fails for array of array of enum types
17951 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
17952 array type comes before the outer array type. We thus call gen_type_die
17953 before we new_die and must prevent nested array types collapsing for this
17956 #ifdef MIPS_DEBUGGING_INFO
17957 gen_type_die (TREE_TYPE (type), context_die);
17958 collapse_nested_arrays = false;
17961 array_die = new_die (DW_TAG_array_type, scope_die, type);
17962 add_name_attribute (array_die, type_tag (type));
17963 equate_type_number_to_die (type, array_die);
17965 if (TREE_CODE (type) == VECTOR_TYPE)
17966 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
17968 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17970 && TREE_CODE (type) == ARRAY_TYPE
17971 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
17972 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
17973 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17976 /* We default the array ordering. SDB will probably do
17977 the right things even if DW_AT_ordering is not present. It's not even
17978 an issue until we start to get into multidimensional arrays anyway. If
17979 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17980 then we'll have to put the DW_AT_ordering attribute back in. (But if
17981 and when we find out that we need to put these in, we will only do so
17982 for multidimensional arrays. */
17983 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17986 #ifdef MIPS_DEBUGGING_INFO
17987 /* The SGI compilers handle arrays of unknown bound by setting
17988 AT_declaration and not emitting any subrange DIEs. */
17989 if (TREE_CODE (type) == ARRAY_TYPE
17990 && ! TYPE_DOMAIN (type))
17991 add_AT_flag (array_die, DW_AT_declaration, 1);
17994 if (TREE_CODE (type) == VECTOR_TYPE)
17996 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17997 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
17998 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
17999 add_bound_info (subrange_die, DW_AT_upper_bound,
18000 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18003 add_subscript_info (array_die, type, collapse_nested_arrays);
18005 /* Add representation of the type of the elements of this array type and
18006 emit the corresponding DIE if we haven't done it already. */
18007 element_type = TREE_TYPE (type);
18008 if (collapse_nested_arrays)
18009 while (TREE_CODE (element_type) == ARRAY_TYPE)
18011 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18013 element_type = TREE_TYPE (element_type);
18016 #ifndef MIPS_DEBUGGING_INFO
18017 gen_type_die (element_type, context_die);
18020 add_type_attribute (array_die, element_type, 0, 0, context_die);
18022 if (get_AT (array_die, DW_AT_name))
18023 add_pubtype (type, array_die);
18026 static dw_loc_descr_ref
18027 descr_info_loc (tree val, tree base_decl)
18029 HOST_WIDE_INT size;
18030 dw_loc_descr_ref loc, loc2;
18031 enum dwarf_location_atom op;
18033 if (val == base_decl)
18034 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18036 switch (TREE_CODE (val))
18039 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18041 return loc_descriptor_from_tree (val, 0);
18043 if (host_integerp (val, 0))
18044 return int_loc_descriptor (tree_low_cst (val, 0));
18047 size = int_size_in_bytes (TREE_TYPE (val));
18050 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18053 if (size == DWARF2_ADDR_SIZE)
18054 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18056 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18058 case POINTER_PLUS_EXPR:
18060 if (host_integerp (TREE_OPERAND (val, 1), 1)
18061 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18064 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18067 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18073 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18076 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18079 add_loc_descr (&loc, loc2);
18080 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18102 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18103 tree val, tree base_decl)
18105 dw_loc_descr_ref loc;
18107 if (host_integerp (val, 0))
18109 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18113 loc = descr_info_loc (val, base_decl);
18117 add_AT_loc (die, attr, loc);
18120 /* This routine generates DIE for array with hidden descriptor, details
18121 are filled into *info by a langhook. */
18124 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18125 dw_die_ref context_die)
18127 dw_die_ref scope_die = scope_die_for (type, context_die);
18128 dw_die_ref array_die;
18131 array_die = new_die (DW_TAG_array_type, scope_die, type);
18132 add_name_attribute (array_die, type_tag (type));
18133 equate_type_number_to_die (type, array_die);
18135 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18137 && info->ndimensions >= 2)
18138 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18140 if (info->data_location)
18141 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18143 if (info->associated)
18144 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18146 if (info->allocated)
18147 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18150 for (dim = 0; dim < info->ndimensions; dim++)
18152 dw_die_ref subrange_die
18153 = new_die (DW_TAG_subrange_type, array_die, NULL);
18155 if (info->dimen[dim].lower_bound)
18157 /* If it is the default value, omit it. */
18160 if (host_integerp (info->dimen[dim].lower_bound, 0)
18161 && (dflt = lower_bound_default ()) != -1
18162 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18165 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18166 info->dimen[dim].lower_bound,
18169 if (info->dimen[dim].upper_bound)
18170 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18171 info->dimen[dim].upper_bound,
18173 if (info->dimen[dim].stride)
18174 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18175 info->dimen[dim].stride,
18179 gen_type_die (info->element_type, context_die);
18180 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18182 if (get_AT (array_die, DW_AT_name))
18183 add_pubtype (type, array_die);
18188 gen_entry_point_die (tree decl, dw_die_ref context_die)
18190 tree origin = decl_ultimate_origin (decl);
18191 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18193 if (origin != NULL)
18194 add_abstract_origin_attribute (decl_die, origin);
18197 add_name_and_src_coords_attributes (decl_die, decl);
18198 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18199 0, 0, context_die);
18202 if (DECL_ABSTRACT (decl))
18203 equate_decl_number_to_die (decl, decl_die);
18205 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18209 /* Walk through the list of incomplete types again, trying once more to
18210 emit full debugging info for them. */
18213 retry_incomplete_types (void)
18217 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18218 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18219 DINFO_USAGE_DIR_USE))
18220 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
18223 /* Determine what tag to use for a record type. */
18225 static enum dwarf_tag
18226 record_type_tag (tree type)
18228 if (! lang_hooks.types.classify_record)
18229 return DW_TAG_structure_type;
18231 switch (lang_hooks.types.classify_record (type))
18233 case RECORD_IS_STRUCT:
18234 return DW_TAG_structure_type;
18236 case RECORD_IS_CLASS:
18237 return DW_TAG_class_type;
18239 case RECORD_IS_INTERFACE:
18240 if (dwarf_version >= 3 || !dwarf_strict)
18241 return DW_TAG_interface_type;
18242 return DW_TAG_structure_type;
18245 gcc_unreachable ();
18249 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18250 include all of the information about the enumeration values also. Each
18251 enumerated type name/value is listed as a child of the enumerated type
18255 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18257 dw_die_ref type_die = lookup_type_die (type);
18259 if (type_die == NULL)
18261 type_die = new_die (DW_TAG_enumeration_type,
18262 scope_die_for (type, context_die), type);
18263 equate_type_number_to_die (type, type_die);
18264 add_name_attribute (type_die, type_tag (type));
18265 if ((dwarf_version >= 4 || !dwarf_strict)
18266 && ENUM_IS_SCOPED (type))
18267 add_AT_flag (type_die, DW_AT_enum_class, 1);
18269 else if (! TYPE_SIZE (type))
18272 remove_AT (type_die, DW_AT_declaration);
18274 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18275 given enum type is incomplete, do not generate the DW_AT_byte_size
18276 attribute or the DW_AT_element_list attribute. */
18277 if (TYPE_SIZE (type))
18281 TREE_ASM_WRITTEN (type) = 1;
18282 add_byte_size_attribute (type_die, type);
18283 if (TYPE_STUB_DECL (type) != NULL_TREE)
18285 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18286 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18289 /* If the first reference to this type was as the return type of an
18290 inline function, then it may not have a parent. Fix this now. */
18291 if (type_die->die_parent == NULL)
18292 add_child_die (scope_die_for (type, context_die), type_die);
18294 for (link = TYPE_VALUES (type);
18295 link != NULL; link = TREE_CHAIN (link))
18297 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18298 tree value = TREE_VALUE (link);
18300 add_name_attribute (enum_die,
18301 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18303 if (TREE_CODE (value) == CONST_DECL)
18304 value = DECL_INITIAL (value);
18306 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18307 /* DWARF2 does not provide a way of indicating whether or
18308 not enumeration constants are signed or unsigned. GDB
18309 always assumes the values are signed, so we output all
18310 values as if they were signed. That means that
18311 enumeration constants with very large unsigned values
18312 will appear to have negative values in the debugger. */
18313 add_AT_int (enum_die, DW_AT_const_value,
18314 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18318 add_AT_flag (type_die, DW_AT_declaration, 1);
18320 if (get_AT (type_die, DW_AT_name))
18321 add_pubtype (type, type_die);
18326 /* Generate a DIE to represent either a real live formal parameter decl or to
18327 represent just the type of some formal parameter position in some function
18330 Note that this routine is a bit unusual because its argument may be a
18331 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18332 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18333 node. If it's the former then this function is being called to output a
18334 DIE to represent a formal parameter object (or some inlining thereof). If
18335 it's the latter, then this function is only being called to output a
18336 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18337 argument type of some subprogram type.
18338 If EMIT_NAME_P is true, name and source coordinate attributes
18342 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18343 dw_die_ref context_die)
18345 tree node_or_origin = node ? node : origin;
18346 tree ultimate_origin;
18347 dw_die_ref parm_die
18348 = new_die (DW_TAG_formal_parameter, context_die, node);
18350 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18352 case tcc_declaration:
18353 ultimate_origin = decl_ultimate_origin (node_or_origin);
18354 if (node || ultimate_origin)
18355 origin = ultimate_origin;
18356 if (origin != NULL)
18357 add_abstract_origin_attribute (parm_die, origin);
18358 else if (emit_name_p)
18359 add_name_and_src_coords_attributes (parm_die, node);
18361 || (! DECL_ABSTRACT (node_or_origin)
18362 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18363 decl_function_context
18364 (node_or_origin))))
18366 tree type = TREE_TYPE (node_or_origin);
18367 if (decl_by_reference_p (node_or_origin))
18368 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18371 add_type_attribute (parm_die, type,
18372 TREE_READONLY (node_or_origin),
18373 TREE_THIS_VOLATILE (node_or_origin),
18376 if (origin == NULL && DECL_ARTIFICIAL (node))
18377 add_AT_flag (parm_die, DW_AT_artificial, 1);
18379 if (node && node != origin)
18380 equate_decl_number_to_die (node, parm_die);
18381 if (! DECL_ABSTRACT (node_or_origin))
18382 add_location_or_const_value_attribute (parm_die, node_or_origin,
18388 /* We were called with some kind of a ..._TYPE node. */
18389 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18393 gcc_unreachable ();
18399 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18400 children DW_TAG_formal_parameter DIEs representing the arguments of the
18403 PARM_PACK must be a function parameter pack.
18404 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18405 must point to the subsequent arguments of the function PACK_ARG belongs to.
18406 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18407 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18408 following the last one for which a DIE was generated. */
18411 gen_formal_parameter_pack_die (tree parm_pack,
18413 dw_die_ref subr_die,
18417 dw_die_ref parm_pack_die;
18419 gcc_assert (parm_pack
18420 && lang_hooks.function_parameter_pack_p (parm_pack)
18423 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18424 add_src_coords_attributes (parm_pack_die, parm_pack);
18426 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18428 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18431 gen_formal_parameter_die (arg, NULL,
18432 false /* Don't emit name attribute. */,
18437 return parm_pack_die;
18440 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18441 at the end of an (ANSI prototyped) formal parameters list. */
18444 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18446 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18449 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18450 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18451 parameters as specified in some function type specification (except for
18452 those which appear as part of a function *definition*). */
18455 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18458 tree formal_type = NULL;
18459 tree first_parm_type;
18462 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18464 arg = DECL_ARGUMENTS (function_or_method_type);
18465 function_or_method_type = TREE_TYPE (function_or_method_type);
18470 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18472 /* Make our first pass over the list of formal parameter types and output a
18473 DW_TAG_formal_parameter DIE for each one. */
18474 for (link = first_parm_type; link; )
18476 dw_die_ref parm_die;
18478 formal_type = TREE_VALUE (link);
18479 if (formal_type == void_type_node)
18482 /* Output a (nameless) DIE to represent the formal parameter itself. */
18483 parm_die = gen_formal_parameter_die (formal_type, NULL,
18484 true /* Emit name attribute. */,
18486 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18487 && link == first_parm_type)
18489 add_AT_flag (parm_die, DW_AT_artificial, 1);
18490 if (dwarf_version >= 3 || !dwarf_strict)
18491 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18493 else if (arg && DECL_ARTIFICIAL (arg))
18494 add_AT_flag (parm_die, DW_AT_artificial, 1);
18496 link = TREE_CHAIN (link);
18498 arg = DECL_CHAIN (arg);
18501 /* If this function type has an ellipsis, add a
18502 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18503 if (formal_type != void_type_node)
18504 gen_unspecified_parameters_die (function_or_method_type, context_die);
18506 /* Make our second (and final) pass over the list of formal parameter types
18507 and output DIEs to represent those types (as necessary). */
18508 for (link = TYPE_ARG_TYPES (function_or_method_type);
18509 link && TREE_VALUE (link);
18510 link = TREE_CHAIN (link))
18511 gen_type_die (TREE_VALUE (link), context_die);
18514 /* We want to generate the DIE for TYPE so that we can generate the
18515 die for MEMBER, which has been defined; we will need to refer back
18516 to the member declaration nested within TYPE. If we're trying to
18517 generate minimal debug info for TYPE, processing TYPE won't do the
18518 trick; we need to attach the member declaration by hand. */
18521 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18523 gen_type_die (type, context_die);
18525 /* If we're trying to avoid duplicate debug info, we may not have
18526 emitted the member decl for this function. Emit it now. */
18527 if (TYPE_STUB_DECL (type)
18528 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18529 && ! lookup_decl_die (member))
18531 dw_die_ref type_die;
18532 gcc_assert (!decl_ultimate_origin (member));
18534 push_decl_scope (type);
18535 type_die = lookup_type_die (type);
18536 if (TREE_CODE (member) == FUNCTION_DECL)
18537 gen_subprogram_die (member, type_die);
18538 else if (TREE_CODE (member) == FIELD_DECL)
18540 /* Ignore the nameless fields that are used to skip bits but handle
18541 C++ anonymous unions and structs. */
18542 if (DECL_NAME (member) != NULL_TREE
18543 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18544 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18546 gen_type_die (member_declared_type (member), type_die);
18547 gen_field_die (member, type_die);
18551 gen_variable_die (member, NULL_TREE, type_die);
18557 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18558 may later generate inlined and/or out-of-line instances of. */
18561 dwarf2out_abstract_function (tree decl)
18563 dw_die_ref old_die;
18567 htab_t old_decl_loc_table;
18569 /* Make sure we have the actual abstract inline, not a clone. */
18570 decl = DECL_ORIGIN (decl);
18572 old_die = lookup_decl_die (decl);
18573 if (old_die && get_AT (old_die, DW_AT_inline))
18574 /* We've already generated the abstract instance. */
18577 /* We can be called while recursively when seeing block defining inlined subroutine
18578 DIE. Be sure to not clobber the outer location table nor use it or we would
18579 get locations in abstract instantces. */
18580 old_decl_loc_table = decl_loc_table;
18581 decl_loc_table = NULL;
18583 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18584 we don't get confused by DECL_ABSTRACT. */
18585 if (debug_info_level > DINFO_LEVEL_TERSE)
18587 context = decl_class_context (decl);
18589 gen_type_die_for_member
18590 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
18593 /* Pretend we've just finished compiling this function. */
18594 save_fn = current_function_decl;
18595 current_function_decl = decl;
18596 push_cfun (DECL_STRUCT_FUNCTION (decl));
18598 was_abstract = DECL_ABSTRACT (decl);
18599 set_decl_abstract_flags (decl, 1);
18600 dwarf2out_decl (decl);
18601 if (! was_abstract)
18602 set_decl_abstract_flags (decl, 0);
18604 current_function_decl = save_fn;
18605 decl_loc_table = old_decl_loc_table;
18609 /* Helper function of premark_used_types() which gets called through
18612 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18613 marked as unused by prune_unused_types. */
18616 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18621 type = (tree) *slot;
18622 die = lookup_type_die (type);
18624 die->die_perennial_p = 1;
18628 /* Helper function of premark_types_used_by_global_vars which gets called
18629 through htab_traverse.
18631 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18632 marked as unused by prune_unused_types. The DIE of the type is marked
18633 only if the global variable using the type will actually be emitted. */
18636 premark_types_used_by_global_vars_helper (void **slot,
18637 void *data ATTRIBUTE_UNUSED)
18639 struct types_used_by_vars_entry *entry;
18642 entry = (struct types_used_by_vars_entry *) *slot;
18643 gcc_assert (entry->type != NULL
18644 && entry->var_decl != NULL);
18645 die = lookup_type_die (entry->type);
18648 /* Ask cgraph if the global variable really is to be emitted.
18649 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18650 struct varpool_node *node = varpool_get_node (entry->var_decl);
18651 if (node && node->needed)
18653 die->die_perennial_p = 1;
18654 /* Keep the parent DIEs as well. */
18655 while ((die = die->die_parent) && die->die_perennial_p == 0)
18656 die->die_perennial_p = 1;
18662 /* Mark all members of used_types_hash as perennial. */
18665 premark_used_types (void)
18667 if (cfun && cfun->used_types_hash)
18668 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18671 /* Mark all members of types_used_by_vars_entry as perennial. */
18674 premark_types_used_by_global_vars (void)
18676 if (types_used_by_vars_hash)
18677 htab_traverse (types_used_by_vars_hash,
18678 premark_types_used_by_global_vars_helper, NULL);
18681 /* Generate a DIE to represent a declared function (either file-scope or
18685 gen_subprogram_die (tree decl, dw_die_ref context_die)
18687 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18688 tree origin = decl_ultimate_origin (decl);
18689 dw_die_ref subr_die;
18692 dw_die_ref old_die = lookup_decl_die (decl);
18693 int declaration = (current_function_decl != decl
18694 || class_or_namespace_scope_p (context_die));
18696 premark_used_types ();
18698 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18699 started to generate the abstract instance of an inline, decided to output
18700 its containing class, and proceeded to emit the declaration of the inline
18701 from the member list for the class. If so, DECLARATION takes priority;
18702 we'll get back to the abstract instance when done with the class. */
18704 /* The class-scope declaration DIE must be the primary DIE. */
18705 if (origin && declaration && class_or_namespace_scope_p (context_die))
18708 gcc_assert (!old_die);
18711 /* Now that the C++ front end lazily declares artificial member fns, we
18712 might need to retrofit the declaration into its class. */
18713 if (!declaration && !origin && !old_die
18714 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18715 && !class_or_namespace_scope_p (context_die)
18716 && debug_info_level > DINFO_LEVEL_TERSE)
18717 old_die = force_decl_die (decl);
18719 if (origin != NULL)
18721 gcc_assert (!declaration || local_scope_p (context_die));
18723 /* Fixup die_parent for the abstract instance of a nested
18724 inline function. */
18725 if (old_die && old_die->die_parent == NULL)
18726 add_child_die (context_die, old_die);
18728 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18729 add_abstract_origin_attribute (subr_die, origin);
18733 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18734 struct dwarf_file_data * file_index = lookup_filename (s.file);
18736 if (!get_AT_flag (old_die, DW_AT_declaration)
18737 /* We can have a normal definition following an inline one in the
18738 case of redefinition of GNU C extern inlines.
18739 It seems reasonable to use AT_specification in this case. */
18740 && !get_AT (old_die, DW_AT_inline))
18742 /* Detect and ignore this case, where we are trying to output
18743 something we have already output. */
18747 /* If the definition comes from the same place as the declaration,
18748 maybe use the old DIE. We always want the DIE for this function
18749 that has the *_pc attributes to be under comp_unit_die so the
18750 debugger can find it. We also need to do this for abstract
18751 instances of inlines, since the spec requires the out-of-line copy
18752 to have the same parent. For local class methods, this doesn't
18753 apply; we just use the old DIE. */
18754 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
18755 && (DECL_ARTIFICIAL (decl)
18756 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18757 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18758 == (unsigned) s.line))))
18760 subr_die = old_die;
18762 /* Clear out the declaration attribute and the formal parameters.
18763 Do not remove all children, because it is possible that this
18764 declaration die was forced using force_decl_die(). In such
18765 cases die that forced declaration die (e.g. TAG_imported_module)
18766 is one of the children that we do not want to remove. */
18767 remove_AT (subr_die, DW_AT_declaration);
18768 remove_AT (subr_die, DW_AT_object_pointer);
18769 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18773 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18774 add_AT_specification (subr_die, old_die);
18775 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18776 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18777 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18778 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18783 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18785 if (TREE_PUBLIC (decl))
18786 add_AT_flag (subr_die, DW_AT_external, 1);
18788 add_name_and_src_coords_attributes (subr_die, decl);
18789 if (debug_info_level > DINFO_LEVEL_TERSE)
18791 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
18792 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18793 0, 0, context_die);
18796 add_pure_or_virtual_attribute (subr_die, decl);
18797 if (DECL_ARTIFICIAL (decl))
18798 add_AT_flag (subr_die, DW_AT_artificial, 1);
18800 add_accessibility_attribute (subr_die, decl);
18805 if (!old_die || !get_AT (old_die, DW_AT_inline))
18807 add_AT_flag (subr_die, DW_AT_declaration, 1);
18809 /* If this is an explicit function declaration then generate
18810 a DW_AT_explicit attribute. */
18811 if (lang_hooks.decls.function_decl_explicit_p (decl)
18812 && (dwarf_version >= 3 || !dwarf_strict))
18813 add_AT_flag (subr_die, DW_AT_explicit, 1);
18815 /* The first time we see a member function, it is in the context of
18816 the class to which it belongs. We make sure of this by emitting
18817 the class first. The next time is the definition, which is
18818 handled above. The two may come from the same source text.
18820 Note that force_decl_die() forces function declaration die. It is
18821 later reused to represent definition. */
18822 equate_decl_number_to_die (decl, subr_die);
18825 else if (DECL_ABSTRACT (decl))
18827 if (DECL_DECLARED_INLINE_P (decl))
18829 if (cgraph_function_possibly_inlined_p (decl))
18830 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
18832 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
18836 if (cgraph_function_possibly_inlined_p (decl))
18837 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
18839 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
18842 if (DECL_DECLARED_INLINE_P (decl)
18843 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
18844 add_AT_flag (subr_die, DW_AT_artificial, 1);
18846 equate_decl_number_to_die (decl, subr_die);
18848 else if (!DECL_EXTERNAL (decl))
18850 HOST_WIDE_INT cfa_fb_offset;
18852 if (!old_die || !get_AT (old_die, DW_AT_inline))
18853 equate_decl_number_to_die (decl, subr_die);
18855 if (!flag_reorder_blocks_and_partition)
18857 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
18858 current_function_funcdef_no);
18859 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
18860 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
18861 current_function_funcdef_no);
18862 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
18864 #if VMS_DEBUGGING_INFO
18865 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18866 Section 2.3 Prologue and Epilogue Attributes:
18867 When a breakpoint is set on entry to a function, it is generally
18868 desirable for execution to be suspended, not on the very first
18869 instruction of the function, but rather at a point after the
18870 function's frame has been set up, after any language defined local
18871 declaration processing has been completed, and before execution of
18872 the first statement of the function begins. Debuggers generally
18873 cannot properly determine where this point is. Similarly for a
18874 breakpoint set on exit from a function. The prologue and epilogue
18875 attributes allow a compiler to communicate the location(s) to use. */
18878 dw_fde_ref fde = &fde_table[current_funcdef_fde];
18880 if (fde->dw_fde_vms_end_prologue)
18881 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
18882 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
18884 if (fde->dw_fde_vms_begin_epilogue)
18885 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
18886 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
18890 add_pubname (decl, subr_die);
18891 add_arange (decl, subr_die);
18894 { /* Do nothing for now; maybe need to duplicate die, one for
18895 hot section and one for cold section, then use the hot/cold
18896 section begin/end labels to generate the aranges... */
18898 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
18899 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
18900 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
18901 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
18903 add_pubname (decl, subr_die);
18904 add_arange (decl, subr_die);
18905 add_arange (decl, subr_die);
18909 #ifdef MIPS_DEBUGGING_INFO
18910 /* Add a reference to the FDE for this routine. */
18911 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
18914 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
18916 /* We define the "frame base" as the function's CFA. This is more
18917 convenient for several reasons: (1) It's stable across the prologue
18918 and epilogue, which makes it better than just a frame pointer,
18919 (2) With dwarf3, there exists a one-byte encoding that allows us
18920 to reference the .debug_frame data by proxy, but failing that,
18921 (3) We can at least reuse the code inspection and interpretation
18922 code that determines the CFA position at various points in the
18924 if (dwarf_version >= 3)
18926 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
18927 add_AT_loc (subr_die, DW_AT_frame_base, op);
18931 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
18932 if (list->dw_loc_next)
18933 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
18935 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
18938 /* Compute a displacement from the "steady-state frame pointer" to
18939 the CFA. The former is what all stack slots and argument slots
18940 will reference in the rtl; the later is what we've told the
18941 debugger about. We'll need to adjust all frame_base references
18942 by this displacement. */
18943 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
18945 if (cfun->static_chain_decl)
18946 add_AT_location_description (subr_die, DW_AT_static_link,
18947 loc_list_from_tree (cfun->static_chain_decl, 2));
18950 /* Generate child dies for template paramaters. */
18951 if (debug_info_level > DINFO_LEVEL_TERSE)
18952 gen_generic_params_dies (decl);
18954 /* Now output descriptions of the arguments for this function. This gets
18955 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18956 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18957 `...' at the end of the formal parameter list. In order to find out if
18958 there was a trailing ellipsis or not, we must instead look at the type
18959 associated with the FUNCTION_DECL. This will be a node of type
18960 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18961 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18962 an ellipsis at the end. */
18964 /* In the case where we are describing a mere function declaration, all we
18965 need to do here (and all we *can* do here) is to describe the *types* of
18966 its formal parameters. */
18967 if (debug_info_level <= DINFO_LEVEL_TERSE)
18969 else if (declaration)
18970 gen_formal_types_die (decl, subr_die);
18973 /* Generate DIEs to represent all known formal parameters. */
18974 tree parm = DECL_ARGUMENTS (decl);
18975 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
18976 tree generic_decl_parm = generic_decl
18977 ? DECL_ARGUMENTS (generic_decl)
18980 /* Now we want to walk the list of parameters of the function and
18981 emit their relevant DIEs.
18983 We consider the case of DECL being an instance of a generic function
18984 as well as it being a normal function.
18986 If DECL is an instance of a generic function we walk the
18987 parameters of the generic function declaration _and_ the parameters of
18988 DECL itself. This is useful because we want to emit specific DIEs for
18989 function parameter packs and those are declared as part of the
18990 generic function declaration. In that particular case,
18991 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18992 That DIE has children DIEs representing the set of arguments
18993 of the pack. Note that the set of pack arguments can be empty.
18994 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18997 Otherwise, we just consider the parameters of DECL. */
18998 while (generic_decl_parm || parm)
19000 if (generic_decl_parm
19001 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19002 gen_formal_parameter_pack_die (generic_decl_parm,
19007 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19009 if (parm == DECL_ARGUMENTS (decl)
19010 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19012 && (dwarf_version >= 3 || !dwarf_strict))
19013 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19015 parm = DECL_CHAIN (parm);
19018 if (generic_decl_parm)
19019 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19022 /* Decide whether we need an unspecified_parameters DIE at the end.
19023 There are 2 more cases to do this for: 1) the ansi ... declaration -
19024 this is detectable when the end of the arg list is not a
19025 void_type_node 2) an unprototyped function declaration (not a
19026 definition). This just means that we have no info about the
19027 parameters at all. */
19028 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
19029 if (fn_arg_types != NULL)
19031 /* This is the prototyped case, check for.... */
19032 if (stdarg_p (TREE_TYPE (decl)))
19033 gen_unspecified_parameters_die (decl, subr_die);
19035 else if (DECL_INITIAL (decl) == NULL_TREE)
19036 gen_unspecified_parameters_die (decl, subr_die);
19039 /* Output Dwarf info for all of the stuff within the body of the function
19040 (if it has one - it may be just a declaration). */
19041 outer_scope = DECL_INITIAL (decl);
19043 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19044 a function. This BLOCK actually represents the outermost binding contour
19045 for the function, i.e. the contour in which the function's formal
19046 parameters and labels get declared. Curiously, it appears that the front
19047 end doesn't actually put the PARM_DECL nodes for the current function onto
19048 the BLOCK_VARS list for this outer scope, but are strung off of the
19049 DECL_ARGUMENTS list for the function instead.
19051 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19052 the LABEL_DECL nodes for the function however, and we output DWARF info
19053 for those in decls_for_scope. Just within the `outer_scope' there will be
19054 a BLOCK node representing the function's outermost pair of curly braces,
19055 and any blocks used for the base and member initializers of a C++
19056 constructor function. */
19057 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19059 /* Emit a DW_TAG_variable DIE for a named return value. */
19060 if (DECL_NAME (DECL_RESULT (decl)))
19061 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19063 current_function_has_inlines = 0;
19064 decls_for_scope (outer_scope, subr_die, 0);
19066 /* Add the calling convention attribute if requested. */
19067 add_calling_convention_attribute (subr_die, decl);
19071 /* Returns a hash value for X (which really is a die_struct). */
19074 common_block_die_table_hash (const void *x)
19076 const_dw_die_ref d = (const_dw_die_ref) x;
19077 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19080 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19081 as decl_id and die_parent of die_struct Y. */
19084 common_block_die_table_eq (const void *x, const void *y)
19086 const_dw_die_ref d = (const_dw_die_ref) x;
19087 const_dw_die_ref e = (const_dw_die_ref) y;
19088 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19091 /* Generate a DIE to represent a declared data object.
19092 Either DECL or ORIGIN must be non-null. */
19095 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19099 tree decl_or_origin = decl ? decl : origin;
19100 tree ultimate_origin;
19101 dw_die_ref var_die;
19102 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19103 dw_die_ref origin_die;
19104 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19105 || class_or_namespace_scope_p (context_die));
19106 bool specialization_p = false;
19108 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19109 if (decl || ultimate_origin)
19110 origin = ultimate_origin;
19111 com_decl = fortran_common (decl_or_origin, &off);
19113 /* Symbol in common gets emitted as a child of the common block, in the form
19114 of a data member. */
19117 dw_die_ref com_die;
19118 dw_loc_list_ref loc;
19119 die_node com_die_arg;
19121 var_die = lookup_decl_die (decl_or_origin);
19124 if (get_AT (var_die, DW_AT_location) == NULL)
19126 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19131 /* Optimize the common case. */
19132 if (single_element_loc_list_p (loc)
19133 && loc->expr->dw_loc_opc == DW_OP_addr
19134 && loc->expr->dw_loc_next == NULL
19135 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19137 loc->expr->dw_loc_oprnd1.v.val_addr
19138 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19140 loc_list_plus_const (loc, off);
19142 add_AT_location_description (var_die, DW_AT_location, loc);
19143 remove_AT (var_die, DW_AT_declaration);
19149 if (common_block_die_table == NULL)
19150 common_block_die_table
19151 = htab_create_ggc (10, common_block_die_table_hash,
19152 common_block_die_table_eq, NULL);
19154 com_die_arg.decl_id = DECL_UID (com_decl);
19155 com_die_arg.die_parent = context_die;
19156 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19157 loc = loc_list_from_tree (com_decl, 2);
19158 if (com_die == NULL)
19161 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19164 com_die = new_die (DW_TAG_common_block, context_die, decl);
19165 add_name_and_src_coords_attributes (com_die, com_decl);
19168 add_AT_location_description (com_die, DW_AT_location, loc);
19169 /* Avoid sharing the same loc descriptor between
19170 DW_TAG_common_block and DW_TAG_variable. */
19171 loc = loc_list_from_tree (com_decl, 2);
19173 else if (DECL_EXTERNAL (decl))
19174 add_AT_flag (com_die, DW_AT_declaration, 1);
19175 add_pubname_string (cnam, com_die); /* ??? needed? */
19176 com_die->decl_id = DECL_UID (com_decl);
19177 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19178 *slot = (void *) com_die;
19180 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19182 add_AT_location_description (com_die, DW_AT_location, loc);
19183 loc = loc_list_from_tree (com_decl, 2);
19184 remove_AT (com_die, DW_AT_declaration);
19186 var_die = new_die (DW_TAG_variable, com_die, decl);
19187 add_name_and_src_coords_attributes (var_die, decl);
19188 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19189 TREE_THIS_VOLATILE (decl), context_die);
19190 add_AT_flag (var_die, DW_AT_external, 1);
19195 /* Optimize the common case. */
19196 if (single_element_loc_list_p (loc)
19197 && loc->expr->dw_loc_opc == DW_OP_addr
19198 && loc->expr->dw_loc_next == NULL
19199 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19200 loc->expr->dw_loc_oprnd1.v.val_addr
19201 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19203 loc_list_plus_const (loc, off);
19205 add_AT_location_description (var_die, DW_AT_location, loc);
19207 else if (DECL_EXTERNAL (decl))
19208 add_AT_flag (var_die, DW_AT_declaration, 1);
19209 equate_decl_number_to_die (decl, var_die);
19213 /* If the compiler emitted a definition for the DECL declaration
19214 and if we already emitted a DIE for it, don't emit a second
19215 DIE for it again. Allow re-declarations of DECLs that are
19216 inside functions, though. */
19217 if (old_die && declaration && !local_scope_p (context_die))
19220 /* For static data members, the declaration in the class is supposed
19221 to have DW_TAG_member tag; the specification should still be
19222 DW_TAG_variable referencing the DW_TAG_member DIE. */
19223 if (declaration && class_scope_p (context_die))
19224 var_die = new_die (DW_TAG_member, context_die, decl);
19226 var_die = new_die (DW_TAG_variable, context_die, decl);
19229 if (origin != NULL)
19230 origin_die = add_abstract_origin_attribute (var_die, origin);
19232 /* Loop unrolling can create multiple blocks that refer to the same
19233 static variable, so we must test for the DW_AT_declaration flag.
19235 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19236 copy decls and set the DECL_ABSTRACT flag on them instead of
19239 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19241 ??? The declare_in_namespace support causes us to get two DIEs for one
19242 variable, both of which are declarations. We want to avoid considering
19243 one to be a specification, so we must test that this DIE is not a
19245 else if (old_die && TREE_STATIC (decl) && ! declaration
19246 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19248 /* This is a definition of a C++ class level static. */
19249 add_AT_specification (var_die, old_die);
19250 specialization_p = true;
19251 if (DECL_NAME (decl))
19253 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19254 struct dwarf_file_data * file_index = lookup_filename (s.file);
19256 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19257 add_AT_file (var_die, DW_AT_decl_file, file_index);
19259 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19260 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19262 if (old_die->die_tag == DW_TAG_member)
19263 add_linkage_name (var_die, decl);
19267 add_name_and_src_coords_attributes (var_die, decl);
19269 if ((origin == NULL && !specialization_p)
19271 && !DECL_ABSTRACT (decl_or_origin)
19272 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19273 decl_function_context
19274 (decl_or_origin))))
19276 tree type = TREE_TYPE (decl_or_origin);
19278 if (decl_by_reference_p (decl_or_origin))
19279 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19281 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19282 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19285 if (origin == NULL && !specialization_p)
19287 if (TREE_PUBLIC (decl))
19288 add_AT_flag (var_die, DW_AT_external, 1);
19290 if (DECL_ARTIFICIAL (decl))
19291 add_AT_flag (var_die, DW_AT_artificial, 1);
19293 add_accessibility_attribute (var_die, decl);
19297 add_AT_flag (var_die, DW_AT_declaration, 1);
19299 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19300 equate_decl_number_to_die (decl, var_die);
19303 && (! DECL_ABSTRACT (decl_or_origin)
19304 /* Local static vars are shared between all clones/inlines,
19305 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19307 || (TREE_CODE (decl_or_origin) == VAR_DECL
19308 && TREE_STATIC (decl_or_origin)
19309 && DECL_RTL_SET_P (decl_or_origin)))
19310 /* When abstract origin already has DW_AT_location attribute, no need
19311 to add it again. */
19312 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19314 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19315 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19316 defer_location (decl_or_origin, var_die);
19318 add_location_or_const_value_attribute (var_die,
19321 add_pubname (decl_or_origin, var_die);
19324 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19327 /* Generate a DIE to represent a named constant. */
19330 gen_const_die (tree decl, dw_die_ref context_die)
19332 dw_die_ref const_die;
19333 tree type = TREE_TYPE (decl);
19335 const_die = new_die (DW_TAG_constant, context_die, decl);
19336 add_name_and_src_coords_attributes (const_die, decl);
19337 add_type_attribute (const_die, type, 1, 0, context_die);
19338 if (TREE_PUBLIC (decl))
19339 add_AT_flag (const_die, DW_AT_external, 1);
19340 if (DECL_ARTIFICIAL (decl))
19341 add_AT_flag (const_die, DW_AT_artificial, 1);
19342 tree_add_const_value_attribute_for_decl (const_die, decl);
19345 /* Generate a DIE to represent a label identifier. */
19348 gen_label_die (tree decl, dw_die_ref context_die)
19350 tree origin = decl_ultimate_origin (decl);
19351 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19353 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19355 if (origin != NULL)
19356 add_abstract_origin_attribute (lbl_die, origin);
19358 add_name_and_src_coords_attributes (lbl_die, decl);
19360 if (DECL_ABSTRACT (decl))
19361 equate_decl_number_to_die (decl, lbl_die);
19364 insn = DECL_RTL_IF_SET (decl);
19366 /* Deleted labels are programmer specified labels which have been
19367 eliminated because of various optimizations. We still emit them
19368 here so that it is possible to put breakpoints on them. */
19372 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19374 /* When optimization is enabled (via -O) some parts of the compiler
19375 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19376 represent source-level labels which were explicitly declared by
19377 the user. This really shouldn't be happening though, so catch
19378 it if it ever does happen. */
19379 gcc_assert (!INSN_DELETED_P (insn));
19381 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19382 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19387 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19388 attributes to the DIE for a block STMT, to describe where the inlined
19389 function was called from. This is similar to add_src_coords_attributes. */
19392 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19394 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19396 if (dwarf_version >= 3 || !dwarf_strict)
19398 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19399 add_AT_unsigned (die, DW_AT_call_line, s.line);
19404 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19405 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19408 add_high_low_attributes (tree stmt, dw_die_ref die)
19410 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19412 if (BLOCK_FRAGMENT_CHAIN (stmt)
19413 && (dwarf_version >= 3 || !dwarf_strict))
19417 if (inlined_function_outer_scope_p (stmt))
19419 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19420 BLOCK_NUMBER (stmt));
19421 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19424 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19426 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19429 add_ranges (chain);
19430 chain = BLOCK_FRAGMENT_CHAIN (chain);
19437 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19438 BLOCK_NUMBER (stmt));
19439 add_AT_lbl_id (die, DW_AT_low_pc, label);
19440 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19441 BLOCK_NUMBER (stmt));
19442 add_AT_lbl_id (die, DW_AT_high_pc, label);
19446 /* Generate a DIE for a lexical block. */
19449 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19451 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19453 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19454 add_high_low_attributes (stmt, stmt_die);
19456 decls_for_scope (stmt, stmt_die, depth);
19459 /* Generate a DIE for an inlined subprogram. */
19462 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19466 /* The instance of function that is effectively being inlined shall not
19468 gcc_assert (! BLOCK_ABSTRACT (stmt));
19470 decl = block_ultimate_origin (stmt);
19472 /* Emit info for the abstract instance first, if we haven't yet. We
19473 must emit this even if the block is abstract, otherwise when we
19474 emit the block below (or elsewhere), we may end up trying to emit
19475 a die whose origin die hasn't been emitted, and crashing. */
19476 dwarf2out_abstract_function (decl);
19478 if (! BLOCK_ABSTRACT (stmt))
19480 dw_die_ref subr_die
19481 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19483 add_abstract_origin_attribute (subr_die, decl);
19484 if (TREE_ASM_WRITTEN (stmt))
19485 add_high_low_attributes (stmt, subr_die);
19486 add_call_src_coords_attributes (stmt, subr_die);
19488 decls_for_scope (stmt, subr_die, depth);
19489 current_function_has_inlines = 1;
19493 /* Generate a DIE for a field in a record, or structure. */
19496 gen_field_die (tree decl, dw_die_ref context_die)
19498 dw_die_ref decl_die;
19500 if (TREE_TYPE (decl) == error_mark_node)
19503 decl_die = new_die (DW_TAG_member, context_die, decl);
19504 add_name_and_src_coords_attributes (decl_die, decl);
19505 add_type_attribute (decl_die, member_declared_type (decl),
19506 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
19509 if (DECL_BIT_FIELD_TYPE (decl))
19511 add_byte_size_attribute (decl_die, decl);
19512 add_bit_size_attribute (decl_die, decl);
19513 add_bit_offset_attribute (decl_die, decl);
19516 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19517 add_data_member_location_attribute (decl_die, decl);
19519 if (DECL_ARTIFICIAL (decl))
19520 add_AT_flag (decl_die, DW_AT_artificial, 1);
19522 add_accessibility_attribute (decl_die, decl);
19524 /* Equate decl number to die, so that we can look up this decl later on. */
19525 equate_decl_number_to_die (decl, decl_die);
19529 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19530 Use modified_type_die instead.
19531 We keep this code here just in case these types of DIEs may be needed to
19532 represent certain things in other languages (e.g. Pascal) someday. */
19535 gen_pointer_type_die (tree type, dw_die_ref context_die)
19538 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
19540 equate_type_number_to_die (type, ptr_die);
19541 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19542 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19545 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19546 Use modified_type_die instead.
19547 We keep this code here just in case these types of DIEs may be needed to
19548 represent certain things in other languages (e.g. Pascal) someday. */
19551 gen_reference_type_die (tree type, dw_die_ref context_die)
19553 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
19555 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
19556 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
19558 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
19560 equate_type_number_to_die (type, ref_die);
19561 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
19562 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19566 /* Generate a DIE for a pointer to a member type. */
19569 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
19572 = new_die (DW_TAG_ptr_to_member_type,
19573 scope_die_for (type, context_die), type);
19575 equate_type_number_to_die (type, ptr_die);
19576 add_AT_die_ref (ptr_die, DW_AT_containing_type,
19577 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
19578 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19581 /* Generate the DIE for the compilation unit. */
19584 gen_compile_unit_die (const char *filename)
19587 char producer[250];
19588 const char *language_string = lang_hooks.name;
19591 die = new_die (DW_TAG_compile_unit, NULL, NULL);
19595 add_name_attribute (die, filename);
19596 /* Don't add cwd for <built-in>. */
19597 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
19598 add_comp_dir_attribute (die);
19601 sprintf (producer, "%s %s", language_string, version_string);
19603 #ifdef MIPS_DEBUGGING_INFO
19604 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19605 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19606 not appear in the producer string, the debugger reaches the conclusion
19607 that the object file is stripped and has no debugging information.
19608 To get the MIPS/SGI debugger to believe that there is debugging
19609 information in the object file, we add a -g to the producer string. */
19610 if (debug_info_level > DINFO_LEVEL_TERSE)
19611 strcat (producer, " -g");
19614 add_AT_string (die, DW_AT_producer, producer);
19616 language = DW_LANG_C89;
19617 if (strcmp (language_string, "GNU C++") == 0)
19618 language = DW_LANG_C_plus_plus;
19619 else if (strcmp (language_string, "GNU F77") == 0)
19620 language = DW_LANG_Fortran77;
19621 else if (strcmp (language_string, "GNU Pascal") == 0)
19622 language = DW_LANG_Pascal83;
19623 else if (dwarf_version >= 3 || !dwarf_strict)
19625 if (strcmp (language_string, "GNU Ada") == 0)
19626 language = DW_LANG_Ada95;
19627 else if (strcmp (language_string, "GNU Fortran") == 0)
19628 language = DW_LANG_Fortran95;
19629 else if (strcmp (language_string, "GNU Java") == 0)
19630 language = DW_LANG_Java;
19631 else if (strcmp (language_string, "GNU Objective-C") == 0)
19632 language = DW_LANG_ObjC;
19633 else if (strcmp (language_string, "GNU Objective-C++") == 0)
19634 language = DW_LANG_ObjC_plus_plus;
19637 add_AT_unsigned (die, DW_AT_language, language);
19641 case DW_LANG_Fortran77:
19642 case DW_LANG_Fortran90:
19643 case DW_LANG_Fortran95:
19644 /* Fortran has case insensitive identifiers and the front-end
19645 lowercases everything. */
19646 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
19649 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19655 /* Generate the DIE for a base class. */
19658 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
19660 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
19662 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
19663 add_data_member_location_attribute (die, binfo);
19665 if (BINFO_VIRTUAL_P (binfo))
19666 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
19668 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19669 children, otherwise the default is DW_ACCESS_public. In DWARF2
19670 the default has always been DW_ACCESS_private. */
19671 if (access == access_public_node)
19673 if (dwarf_version == 2
19674 || context_die->die_tag == DW_TAG_class_type)
19675 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
19677 else if (access == access_protected_node)
19678 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
19679 else if (dwarf_version > 2
19680 && context_die->die_tag != DW_TAG_class_type)
19681 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
19684 /* Generate a DIE for a class member. */
19687 gen_member_die (tree type, dw_die_ref context_die)
19690 tree binfo = TYPE_BINFO (type);
19693 /* If this is not an incomplete type, output descriptions of each of its
19694 members. Note that as we output the DIEs necessary to represent the
19695 members of this record or union type, we will also be trying to output
19696 DIEs to represent the *types* of those members. However the `type'
19697 function (above) will specifically avoid generating type DIEs for member
19698 types *within* the list of member DIEs for this (containing) type except
19699 for those types (of members) which are explicitly marked as also being
19700 members of this (containing) type themselves. The g++ front- end can
19701 force any given type to be treated as a member of some other (containing)
19702 type by setting the TYPE_CONTEXT of the given (member) type to point to
19703 the TREE node representing the appropriate (containing) type. */
19705 /* First output info about the base classes. */
19708 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
19712 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
19713 gen_inheritance_die (base,
19714 (accesses ? VEC_index (tree, accesses, i)
19715 : access_public_node), context_die);
19718 /* Now output info about the data members and type members. */
19719 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
19721 /* If we thought we were generating minimal debug info for TYPE
19722 and then changed our minds, some of the member declarations
19723 may have already been defined. Don't define them again, but
19724 do put them in the right order. */
19726 child = lookup_decl_die (member);
19728 splice_child_die (context_die, child);
19730 gen_decl_die (member, NULL, context_die);
19733 /* Now output info about the function members (if any). */
19734 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
19736 /* Don't include clones in the member list. */
19737 if (DECL_ABSTRACT_ORIGIN (member))
19740 child = lookup_decl_die (member);
19742 splice_child_die (context_die, child);
19744 gen_decl_die (member, NULL, context_die);
19748 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19749 is set, we pretend that the type was never defined, so we only get the
19750 member DIEs needed by later specification DIEs. */
19753 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
19754 enum debug_info_usage usage)
19756 dw_die_ref type_die = lookup_type_die (type);
19757 dw_die_ref scope_die = 0;
19759 int complete = (TYPE_SIZE (type)
19760 && (! TYPE_STUB_DECL (type)
19761 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
19762 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
19763 complete = complete && should_emit_struct_debug (type, usage);
19765 if (type_die && ! complete)
19768 if (TYPE_CONTEXT (type) != NULL_TREE
19769 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19770 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
19773 scope_die = scope_die_for (type, context_die);
19775 if (! type_die || (nested && scope_die == comp_unit_die))
19776 /* First occurrence of type or toplevel definition of nested class. */
19778 dw_die_ref old_die = type_die;
19780 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
19781 ? record_type_tag (type) : DW_TAG_union_type,
19783 equate_type_number_to_die (type, type_die);
19785 add_AT_specification (type_die, old_die);
19787 add_name_attribute (type_die, type_tag (type));
19790 remove_AT (type_die, DW_AT_declaration);
19792 /* Generate child dies for template paramaters. */
19793 if (debug_info_level > DINFO_LEVEL_TERSE
19794 && COMPLETE_TYPE_P (type))
19795 gen_generic_params_dies (type);
19797 /* If this type has been completed, then give it a byte_size attribute and
19798 then give a list of members. */
19799 if (complete && !ns_decl)
19801 /* Prevent infinite recursion in cases where the type of some member of
19802 this type is expressed in terms of this type itself. */
19803 TREE_ASM_WRITTEN (type) = 1;
19804 add_byte_size_attribute (type_die, type);
19805 if (TYPE_STUB_DECL (type) != NULL_TREE)
19807 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
19808 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
19811 /* If the first reference to this type was as the return type of an
19812 inline function, then it may not have a parent. Fix this now. */
19813 if (type_die->die_parent == NULL)
19814 add_child_die (scope_die, type_die);
19816 push_decl_scope (type);
19817 gen_member_die (type, type_die);
19820 /* GNU extension: Record what type our vtable lives in. */
19821 if (TYPE_VFIELD (type))
19823 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
19825 gen_type_die (vtype, context_die);
19826 add_AT_die_ref (type_die, DW_AT_containing_type,
19827 lookup_type_die (vtype));
19832 add_AT_flag (type_die, DW_AT_declaration, 1);
19834 /* We don't need to do this for function-local types. */
19835 if (TYPE_STUB_DECL (type)
19836 && ! decl_function_context (TYPE_STUB_DECL (type)))
19837 VEC_safe_push (tree, gc, incomplete_types, type);
19840 if (get_AT (type_die, DW_AT_name))
19841 add_pubtype (type, type_die);
19844 /* Generate a DIE for a subroutine _type_. */
19847 gen_subroutine_type_die (tree type, dw_die_ref context_die)
19849 tree return_type = TREE_TYPE (type);
19850 dw_die_ref subr_die
19851 = new_die (DW_TAG_subroutine_type,
19852 scope_die_for (type, context_die), type);
19854 equate_type_number_to_die (type, subr_die);
19855 add_prototyped_attribute (subr_die, type);
19856 add_type_attribute (subr_die, return_type, 0, 0, context_die);
19857 gen_formal_types_die (type, subr_die);
19859 if (get_AT (subr_die, DW_AT_name))
19860 add_pubtype (type, subr_die);
19863 /* Generate a DIE for a type definition. */
19866 gen_typedef_die (tree decl, dw_die_ref context_die)
19868 dw_die_ref type_die;
19871 if (TREE_ASM_WRITTEN (decl))
19874 TREE_ASM_WRITTEN (decl) = 1;
19875 type_die = new_die (DW_TAG_typedef, context_die, decl);
19876 origin = decl_ultimate_origin (decl);
19877 if (origin != NULL)
19878 add_abstract_origin_attribute (type_die, origin);
19883 add_name_and_src_coords_attributes (type_die, decl);
19884 if (DECL_ORIGINAL_TYPE (decl))
19886 type = DECL_ORIGINAL_TYPE (decl);
19888 gcc_assert (type != TREE_TYPE (decl));
19889 equate_type_number_to_die (TREE_TYPE (decl), type_die);
19893 type = TREE_TYPE (decl);
19895 if (is_naming_typedef_decl (TYPE_NAME (type)))
19897 /* Here, we are in the case of decl being a typedef naming
19898 an anonymous type, e.g:
19899 typedef struct {...} foo;
19900 In that case TREE_TYPE (decl) is not a typedef variant
19901 type and TYPE_NAME of the anonymous type is set to the
19902 TYPE_DECL of the typedef. This construct is emitted by
19905 TYPE is the anonymous struct named by the typedef
19906 DECL. As we need the DW_AT_type attribute of the
19907 DW_TAG_typedef to point to the DIE of TYPE, let's
19908 generate that DIE right away. add_type_attribute
19909 called below will then pick (via lookup_type_die) that
19910 anonymous struct DIE. */
19911 if (!TREE_ASM_WRITTEN (type))
19912 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
19916 add_type_attribute (type_die, type, TREE_READONLY (decl),
19917 TREE_THIS_VOLATILE (decl), context_die);
19919 if (is_naming_typedef_decl (decl))
19920 /* We want that all subsequent calls to lookup_type_die with
19921 TYPE in argument yield the DW_TAG_typedef we have just
19923 equate_type_number_to_die (type, type_die);
19925 add_accessibility_attribute (type_die, decl);
19928 if (DECL_ABSTRACT (decl))
19929 equate_decl_number_to_die (decl, type_die);
19931 if (get_AT (type_die, DW_AT_name))
19932 add_pubtype (decl, type_die);
19935 /* Generate a DIE for a struct, class, enum or union type. */
19938 gen_tagged_type_die (tree type,
19939 dw_die_ref context_die,
19940 enum debug_info_usage usage)
19944 if (type == NULL_TREE
19945 || !is_tagged_type (type))
19948 /* If this is a nested type whose containing class hasn't been written
19949 out yet, writing it out will cover this one, too. This does not apply
19950 to instantiations of member class templates; they need to be added to
19951 the containing class as they are generated. FIXME: This hurts the
19952 idea of combining type decls from multiple TUs, since we can't predict
19953 what set of template instantiations we'll get. */
19954 if (TYPE_CONTEXT (type)
19955 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19956 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
19958 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
19960 if (TREE_ASM_WRITTEN (type))
19963 /* If that failed, attach ourselves to the stub. */
19964 push_decl_scope (TYPE_CONTEXT (type));
19965 context_die = lookup_type_die (TYPE_CONTEXT (type));
19968 else if (TYPE_CONTEXT (type) != NULL_TREE
19969 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
19971 /* If this type is local to a function that hasn't been written
19972 out yet, use a NULL context for now; it will be fixed up in
19973 decls_for_scope. */
19974 context_die = lookup_decl_die (TYPE_CONTEXT (type));
19979 context_die = declare_in_namespace (type, context_die);
19983 if (TREE_CODE (type) == ENUMERAL_TYPE)
19985 /* This might have been written out by the call to
19986 declare_in_namespace. */
19987 if (!TREE_ASM_WRITTEN (type))
19988 gen_enumeration_type_die (type, context_die);
19991 gen_struct_or_union_type_die (type, context_die, usage);
19996 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19997 it up if it is ever completed. gen_*_type_die will set it for us
19998 when appropriate. */
20001 /* Generate a type description DIE. */
20004 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20005 enum debug_info_usage usage)
20007 struct array_descr_info info;
20009 if (type == NULL_TREE || type == error_mark_node)
20012 /* If TYPE is a typedef type variant, let's generate debug info
20013 for the parent typedef which TYPE is a type of. */
20014 if (typedef_variant_p (type))
20016 if (TREE_ASM_WRITTEN (type))
20019 /* Prevent broken recursion; we can't hand off to the same type. */
20020 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20022 /* Use the DIE of the containing namespace as the parent DIE of
20023 the type description DIE we want to generate. */
20024 if (DECL_CONTEXT (TYPE_NAME (type))
20025 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20026 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20028 TREE_ASM_WRITTEN (type) = 1;
20030 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20034 /* If type is an anonymous tagged type named by a typedef, let's
20035 generate debug info for the typedef. */
20036 if (is_naming_typedef_decl (TYPE_NAME (type)))
20038 /* Use the DIE of the containing namespace as the parent DIE of
20039 the type description DIE we want to generate. */
20040 if (DECL_CONTEXT (TYPE_NAME (type))
20041 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20042 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20044 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20048 /* If this is an array type with hidden descriptor, handle it first. */
20049 if (!TREE_ASM_WRITTEN (type)
20050 && lang_hooks.types.get_array_descr_info
20051 && lang_hooks.types.get_array_descr_info (type, &info)
20052 && (dwarf_version >= 3 || !dwarf_strict))
20054 gen_descr_array_type_die (type, &info, context_die);
20055 TREE_ASM_WRITTEN (type) = 1;
20059 /* We are going to output a DIE to represent the unqualified version
20060 of this type (i.e. without any const or volatile qualifiers) so
20061 get the main variant (i.e. the unqualified version) of this type
20062 now. (Vectors are special because the debugging info is in the
20063 cloned type itself). */
20064 if (TREE_CODE (type) != VECTOR_TYPE)
20065 type = type_main_variant (type);
20067 if (TREE_ASM_WRITTEN (type))
20070 switch (TREE_CODE (type))
20076 case REFERENCE_TYPE:
20077 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20078 ensures that the gen_type_die recursion will terminate even if the
20079 type is recursive. Recursive types are possible in Ada. */
20080 /* ??? We could perhaps do this for all types before the switch
20082 TREE_ASM_WRITTEN (type) = 1;
20084 /* For these types, all that is required is that we output a DIE (or a
20085 set of DIEs) to represent the "basis" type. */
20086 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20087 DINFO_USAGE_IND_USE);
20091 /* This code is used for C++ pointer-to-data-member types.
20092 Output a description of the relevant class type. */
20093 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20094 DINFO_USAGE_IND_USE);
20096 /* Output a description of the type of the object pointed to. */
20097 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20098 DINFO_USAGE_IND_USE);
20100 /* Now output a DIE to represent this pointer-to-data-member type
20102 gen_ptr_to_mbr_type_die (type, context_die);
20105 case FUNCTION_TYPE:
20106 /* Force out return type (in case it wasn't forced out already). */
20107 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20108 DINFO_USAGE_DIR_USE);
20109 gen_subroutine_type_die (type, context_die);
20113 /* Force out return type (in case it wasn't forced out already). */
20114 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20115 DINFO_USAGE_DIR_USE);
20116 gen_subroutine_type_die (type, context_die);
20120 gen_array_type_die (type, context_die);
20124 gen_array_type_die (type, context_die);
20127 case ENUMERAL_TYPE:
20130 case QUAL_UNION_TYPE:
20131 gen_tagged_type_die (type, context_die, usage);
20137 case FIXED_POINT_TYPE:
20140 /* No DIEs needed for fundamental types. */
20144 /* Just use DW_TAG_unspecified_type. */
20146 dw_die_ref type_die = lookup_type_die (type);
20147 if (type_die == NULL)
20149 tree name = TYPE_NAME (type);
20150 if (TREE_CODE (name) == TYPE_DECL)
20151 name = DECL_NAME (name);
20152 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die, type);
20153 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20154 equate_type_number_to_die (type, type_die);
20160 gcc_unreachable ();
20163 TREE_ASM_WRITTEN (type) = 1;
20167 gen_type_die (tree type, dw_die_ref context_die)
20169 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20172 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20173 things which are local to the given block. */
20176 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20178 int must_output_die = 0;
20181 /* Ignore blocks that are NULL. */
20182 if (stmt == NULL_TREE)
20185 inlined_func = inlined_function_outer_scope_p (stmt);
20187 /* If the block is one fragment of a non-contiguous block, do not
20188 process the variables, since they will have been done by the
20189 origin block. Do process subblocks. */
20190 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20194 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20195 gen_block_die (sub, context_die, depth + 1);
20200 /* Determine if we need to output any Dwarf DIEs at all to represent this
20203 /* The outer scopes for inlinings *must* always be represented. We
20204 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20205 must_output_die = 1;
20208 /* Determine if this block directly contains any "significant"
20209 local declarations which we will need to output DIEs for. */
20210 if (debug_info_level > DINFO_LEVEL_TERSE)
20211 /* We are not in terse mode so *any* local declaration counts
20212 as being a "significant" one. */
20213 must_output_die = ((BLOCK_VARS (stmt) != NULL
20214 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20215 && (TREE_USED (stmt)
20216 || TREE_ASM_WRITTEN (stmt)
20217 || BLOCK_ABSTRACT (stmt)));
20218 else if ((TREE_USED (stmt)
20219 || TREE_ASM_WRITTEN (stmt)
20220 || BLOCK_ABSTRACT (stmt))
20221 && !dwarf2out_ignore_block (stmt))
20222 must_output_die = 1;
20225 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20226 DIE for any block which contains no significant local declarations at
20227 all. Rather, in such cases we just call `decls_for_scope' so that any
20228 needed Dwarf info for any sub-blocks will get properly generated. Note
20229 that in terse mode, our definition of what constitutes a "significant"
20230 local declaration gets restricted to include only inlined function
20231 instances and local (nested) function definitions. */
20232 if (must_output_die)
20236 /* If STMT block is abstract, that means we have been called
20237 indirectly from dwarf2out_abstract_function.
20238 That function rightfully marks the descendent blocks (of
20239 the abstract function it is dealing with) as being abstract,
20240 precisely to prevent us from emitting any
20241 DW_TAG_inlined_subroutine DIE as a descendent
20242 of an abstract function instance. So in that case, we should
20243 not call gen_inlined_subroutine_die.
20245 Later though, when cgraph asks dwarf2out to emit info
20246 for the concrete instance of the function decl into which
20247 the concrete instance of STMT got inlined, the later will lead
20248 to the generation of a DW_TAG_inlined_subroutine DIE. */
20249 if (! BLOCK_ABSTRACT (stmt))
20250 gen_inlined_subroutine_die (stmt, context_die, depth);
20253 gen_lexical_block_die (stmt, context_die, depth);
20256 decls_for_scope (stmt, context_die, depth);
20259 /* Process variable DECL (or variable with origin ORIGIN) within
20260 block STMT and add it to CONTEXT_DIE. */
20262 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20265 tree decl_or_origin = decl ? decl : origin;
20267 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20268 die = lookup_decl_die (decl_or_origin);
20269 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20270 && TYPE_DECL_IS_STUB (decl_or_origin))
20271 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20275 if (die != NULL && die->die_parent == NULL)
20276 add_child_die (context_die, die);
20277 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20278 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20279 stmt, context_die);
20281 gen_decl_die (decl, origin, context_die);
20284 /* Generate all of the decls declared within a given scope and (recursively)
20285 all of its sub-blocks. */
20288 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20294 /* Ignore NULL blocks. */
20295 if (stmt == NULL_TREE)
20298 /* Output the DIEs to represent all of the data objects and typedefs
20299 declared directly within this block but not within any nested
20300 sub-blocks. Also, nested function and tag DIEs have been
20301 generated with a parent of NULL; fix that up now. */
20302 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20303 process_scope_var (stmt, decl, NULL_TREE, context_die);
20304 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20305 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20308 /* If we're at -g1, we're not interested in subblocks. */
20309 if (debug_info_level <= DINFO_LEVEL_TERSE)
20312 /* Output the DIEs to represent all sub-blocks (and the items declared
20313 therein) of this block. */
20314 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20316 subblocks = BLOCK_CHAIN (subblocks))
20317 gen_block_die (subblocks, context_die, depth + 1);
20320 /* Is this a typedef we can avoid emitting? */
20323 is_redundant_typedef (const_tree decl)
20325 if (TYPE_DECL_IS_STUB (decl))
20328 if (DECL_ARTIFICIAL (decl)
20329 && DECL_CONTEXT (decl)
20330 && is_tagged_type (DECL_CONTEXT (decl))
20331 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20332 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20333 /* Also ignore the artificial member typedef for the class name. */
20339 /* Return TRUE if TYPE is a typedef that names a type for linkage
20340 purposes. This kind of typedefs is produced by the C++ FE for
20343 typedef struct {...} foo;
20345 In that case, there is no typedef variant type produced for foo.
20346 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20350 is_naming_typedef_decl (const_tree decl)
20352 if (decl == NULL_TREE
20353 || TREE_CODE (decl) != TYPE_DECL
20354 || !is_tagged_type (TREE_TYPE (decl))
20355 || DECL_IS_BUILTIN (decl)
20356 || is_redundant_typedef (decl)
20357 /* It looks like Ada produces TYPE_DECLs that are very similar
20358 to C++ naming typedefs but that have different
20359 semantics. Let's be specific to c++ for now. */
20363 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20364 && TYPE_NAME (TREE_TYPE (decl)) == decl
20365 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20366 != TYPE_NAME (TREE_TYPE (decl))));
20369 /* Returns the DIE for a context. */
20371 static inline dw_die_ref
20372 get_context_die (tree context)
20376 /* Find die that represents this context. */
20377 if (TYPE_P (context))
20378 return force_type_die (TYPE_MAIN_VARIANT (context));
20380 return force_decl_die (context);
20382 return comp_unit_die;
20385 /* Returns the DIE for decl. A DIE will always be returned. */
20388 force_decl_die (tree decl)
20390 dw_die_ref decl_die;
20391 unsigned saved_external_flag;
20392 tree save_fn = NULL_TREE;
20393 decl_die = lookup_decl_die (decl);
20396 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20398 decl_die = lookup_decl_die (decl);
20402 switch (TREE_CODE (decl))
20404 case FUNCTION_DECL:
20405 /* Clear current_function_decl, so that gen_subprogram_die thinks
20406 that this is a declaration. At this point, we just want to force
20407 declaration die. */
20408 save_fn = current_function_decl;
20409 current_function_decl = NULL_TREE;
20410 gen_subprogram_die (decl, context_die);
20411 current_function_decl = save_fn;
20415 /* Set external flag to force declaration die. Restore it after
20416 gen_decl_die() call. */
20417 saved_external_flag = DECL_EXTERNAL (decl);
20418 DECL_EXTERNAL (decl) = 1;
20419 gen_decl_die (decl, NULL, context_die);
20420 DECL_EXTERNAL (decl) = saved_external_flag;
20423 case NAMESPACE_DECL:
20424 if (dwarf_version >= 3 || !dwarf_strict)
20425 dwarf2out_decl (decl);
20427 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20428 decl_die = comp_unit_die;
20432 gcc_unreachable ();
20435 /* We should be able to find the DIE now. */
20437 decl_die = lookup_decl_die (decl);
20438 gcc_assert (decl_die);
20444 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20445 always returned. */
20448 force_type_die (tree type)
20450 dw_die_ref type_die;
20452 type_die = lookup_type_die (type);
20455 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
20457 type_die = modified_type_die (type, TYPE_READONLY (type),
20458 TYPE_VOLATILE (type), context_die);
20459 gcc_assert (type_die);
20464 /* Force out any required namespaces to be able to output DECL,
20465 and return the new context_die for it, if it's changed. */
20468 setup_namespace_context (tree thing, dw_die_ref context_die)
20470 tree context = (DECL_P (thing)
20471 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
20472 if (context && TREE_CODE (context) == NAMESPACE_DECL)
20473 /* Force out the namespace. */
20474 context_die = force_decl_die (context);
20476 return context_die;
20479 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20480 type) within its namespace, if appropriate.
20482 For compatibility with older debuggers, namespace DIEs only contain
20483 declarations; all definitions are emitted at CU scope. */
20486 declare_in_namespace (tree thing, dw_die_ref context_die)
20488 dw_die_ref ns_context;
20490 if (debug_info_level <= DINFO_LEVEL_TERSE)
20491 return context_die;
20493 /* If this decl is from an inlined function, then don't try to emit it in its
20494 namespace, as we will get confused. It would have already been emitted
20495 when the abstract instance of the inline function was emitted anyways. */
20496 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
20497 return context_die;
20499 ns_context = setup_namespace_context (thing, context_die);
20501 if (ns_context != context_die)
20505 if (DECL_P (thing))
20506 gen_decl_die (thing, NULL, ns_context);
20508 gen_type_die (thing, ns_context);
20510 return context_die;
20513 /* Generate a DIE for a namespace or namespace alias. */
20516 gen_namespace_die (tree decl, dw_die_ref context_die)
20518 dw_die_ref namespace_die;
20520 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20521 they are an alias of. */
20522 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
20524 /* Output a real namespace or module. */
20525 context_die = setup_namespace_context (decl, comp_unit_die);
20526 namespace_die = new_die (is_fortran ()
20527 ? DW_TAG_module : DW_TAG_namespace,
20528 context_die, decl);
20529 /* For Fortran modules defined in different CU don't add src coords. */
20530 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
20532 const char *name = dwarf2_name (decl, 0);
20534 add_name_attribute (namespace_die, name);
20537 add_name_and_src_coords_attributes (namespace_die, decl);
20538 if (DECL_EXTERNAL (decl))
20539 add_AT_flag (namespace_die, DW_AT_declaration, 1);
20540 equate_decl_number_to_die (decl, namespace_die);
20544 /* Output a namespace alias. */
20546 /* Force out the namespace we are an alias of, if necessary. */
20547 dw_die_ref origin_die
20548 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
20550 if (DECL_CONTEXT (decl) == NULL_TREE
20551 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
20552 context_die = setup_namespace_context (decl, comp_unit_die);
20553 /* Now create the namespace alias DIE. */
20554 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
20555 add_name_and_src_coords_attributes (namespace_die, decl);
20556 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
20557 equate_decl_number_to_die (decl, namespace_die);
20561 /* Generate Dwarf debug information for a decl described by DECL.
20562 The return value is currently only meaningful for PARM_DECLs,
20563 for all other decls it returns NULL. */
20566 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
20568 tree decl_or_origin = decl ? decl : origin;
20569 tree class_origin = NULL, ultimate_origin;
20571 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
20574 switch (TREE_CODE (decl_or_origin))
20580 if (!is_fortran () && !is_ada ())
20582 /* The individual enumerators of an enum type get output when we output
20583 the Dwarf representation of the relevant enum type itself. */
20587 /* Emit its type. */
20588 gen_type_die (TREE_TYPE (decl), context_die);
20590 /* And its containing namespace. */
20591 context_die = declare_in_namespace (decl, context_die);
20593 gen_const_die (decl, context_die);
20596 case FUNCTION_DECL:
20597 /* Don't output any DIEs to represent mere function declarations,
20598 unless they are class members or explicit block externs. */
20599 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
20600 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
20601 && (current_function_decl == NULL_TREE
20602 || DECL_ARTIFICIAL (decl_or_origin)))
20607 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20608 on local redeclarations of global functions. That seems broken. */
20609 if (current_function_decl != decl)
20610 /* This is only a declaration. */;
20613 /* If we're emitting a clone, emit info for the abstract instance. */
20614 if (origin || DECL_ORIGIN (decl) != decl)
20615 dwarf2out_abstract_function (origin
20616 ? DECL_ORIGIN (origin)
20617 : DECL_ABSTRACT_ORIGIN (decl));
20619 /* If we're emitting an out-of-line copy of an inline function,
20620 emit info for the abstract instance and set up to refer to it. */
20621 else if (cgraph_function_possibly_inlined_p (decl)
20622 && ! DECL_ABSTRACT (decl)
20623 && ! class_or_namespace_scope_p (context_die)
20624 /* dwarf2out_abstract_function won't emit a die if this is just
20625 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20626 that case, because that works only if we have a die. */
20627 && DECL_INITIAL (decl) != NULL_TREE)
20629 dwarf2out_abstract_function (decl);
20630 set_decl_origin_self (decl);
20633 /* Otherwise we're emitting the primary DIE for this decl. */
20634 else if (debug_info_level > DINFO_LEVEL_TERSE)
20636 /* Before we describe the FUNCTION_DECL itself, make sure that we
20637 have its containing type. */
20639 origin = decl_class_context (decl);
20640 if (origin != NULL_TREE)
20641 gen_type_die (origin, context_die);
20643 /* And its return type. */
20644 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
20646 /* And its virtual context. */
20647 if (DECL_VINDEX (decl) != NULL_TREE)
20648 gen_type_die (DECL_CONTEXT (decl), context_die);
20650 /* Make sure we have a member DIE for decl. */
20651 if (origin != NULL_TREE)
20652 gen_type_die_for_member (origin, decl, context_die);
20654 /* And its containing namespace. */
20655 context_die = declare_in_namespace (decl, context_die);
20658 /* Now output a DIE to represent the function itself. */
20660 gen_subprogram_die (decl, context_die);
20664 /* If we are in terse mode, don't generate any DIEs to represent any
20665 actual typedefs. */
20666 if (debug_info_level <= DINFO_LEVEL_TERSE)
20669 /* In the special case of a TYPE_DECL node representing the declaration
20670 of some type tag, if the given TYPE_DECL is marked as having been
20671 instantiated from some other (original) TYPE_DECL node (e.g. one which
20672 was generated within the original definition of an inline function) we
20673 used to generate a special (abbreviated) DW_TAG_structure_type,
20674 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20675 should be actually referencing those DIEs, as variable DIEs with that
20676 type would be emitted already in the abstract origin, so it was always
20677 removed during unused type prunning. Don't add anything in this
20679 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
20682 if (is_redundant_typedef (decl))
20683 gen_type_die (TREE_TYPE (decl), context_die);
20685 /* Output a DIE to represent the typedef itself. */
20686 gen_typedef_die (decl, context_die);
20690 if (debug_info_level >= DINFO_LEVEL_NORMAL)
20691 gen_label_die (decl, context_die);
20696 /* If we are in terse mode, don't generate any DIEs to represent any
20697 variable declarations or definitions. */
20698 if (debug_info_level <= DINFO_LEVEL_TERSE)
20701 /* Output any DIEs that are needed to specify the type of this data
20703 if (decl_by_reference_p (decl_or_origin))
20704 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20706 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20708 /* And its containing type. */
20709 class_origin = decl_class_context (decl_or_origin);
20710 if (class_origin != NULL_TREE)
20711 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
20713 /* And its containing namespace. */
20714 context_die = declare_in_namespace (decl_or_origin, context_die);
20716 /* Now output the DIE to represent the data object itself. This gets
20717 complicated because of the possibility that the VAR_DECL really
20718 represents an inlined instance of a formal parameter for an inline
20720 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20721 if (ultimate_origin != NULL_TREE
20722 && TREE_CODE (ultimate_origin) == PARM_DECL)
20723 gen_formal_parameter_die (decl, origin,
20724 true /* Emit name attribute. */,
20727 gen_variable_die (decl, origin, context_die);
20731 /* Ignore the nameless fields that are used to skip bits but handle C++
20732 anonymous unions and structs. */
20733 if (DECL_NAME (decl) != NULL_TREE
20734 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
20735 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
20737 gen_type_die (member_declared_type (decl), context_die);
20738 gen_field_die (decl, context_die);
20743 if (DECL_BY_REFERENCE (decl_or_origin))
20744 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20746 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20747 return gen_formal_parameter_die (decl, origin,
20748 true /* Emit name attribute. */,
20751 case NAMESPACE_DECL:
20752 case IMPORTED_DECL:
20753 if (dwarf_version >= 3 || !dwarf_strict)
20754 gen_namespace_die (decl, context_die);
20758 /* Probably some frontend-internal decl. Assume we don't care. */
20759 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
20766 /* Output debug information for global decl DECL. Called from toplev.c after
20767 compilation proper has finished. */
20770 dwarf2out_global_decl (tree decl)
20772 /* Output DWARF2 information for file-scope tentative data object
20773 declarations, file-scope (extern) function declarations (which
20774 had no corresponding body) and file-scope tagged type declarations
20775 and definitions which have not yet been forced out. */
20776 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
20777 dwarf2out_decl (decl);
20780 /* Output debug information for type decl DECL. Called from toplev.c
20781 and from language front ends (to record built-in types). */
20783 dwarf2out_type_decl (tree decl, int local)
20786 dwarf2out_decl (decl);
20789 /* Output debug information for imported module or decl DECL.
20790 NAME is non-NULL name in the lexical block if the decl has been renamed.
20791 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20792 that DECL belongs to.
20793 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20795 dwarf2out_imported_module_or_decl_1 (tree decl,
20797 tree lexical_block,
20798 dw_die_ref lexical_block_die)
20800 expanded_location xloc;
20801 dw_die_ref imported_die = NULL;
20802 dw_die_ref at_import_die;
20804 if (TREE_CODE (decl) == IMPORTED_DECL)
20806 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
20807 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
20811 xloc = expand_location (input_location);
20813 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
20815 at_import_die = force_type_die (TREE_TYPE (decl));
20816 /* For namespace N { typedef void T; } using N::T; base_type_die
20817 returns NULL, but DW_TAG_imported_declaration requires
20818 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20819 if (!at_import_die)
20821 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
20822 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
20823 at_import_die = lookup_type_die (TREE_TYPE (decl));
20824 gcc_assert (at_import_die);
20829 at_import_die = lookup_decl_die (decl);
20830 if (!at_import_die)
20832 /* If we're trying to avoid duplicate debug info, we may not have
20833 emitted the member decl for this field. Emit it now. */
20834 if (TREE_CODE (decl) == FIELD_DECL)
20836 tree type = DECL_CONTEXT (decl);
20838 if (TYPE_CONTEXT (type)
20839 && TYPE_P (TYPE_CONTEXT (type))
20840 && !should_emit_struct_debug (TYPE_CONTEXT (type),
20841 DINFO_USAGE_DIR_USE))
20843 gen_type_die_for_member (type, decl,
20844 get_context_die (TYPE_CONTEXT (type)));
20846 at_import_die = force_decl_die (decl);
20850 if (TREE_CODE (decl) == NAMESPACE_DECL)
20852 if (dwarf_version >= 3 || !dwarf_strict)
20853 imported_die = new_die (DW_TAG_imported_module,
20860 imported_die = new_die (DW_TAG_imported_declaration,
20864 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
20865 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
20867 add_AT_string (imported_die, DW_AT_name,
20868 IDENTIFIER_POINTER (name));
20869 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
20872 /* Output debug information for imported module or decl DECL.
20873 NAME is non-NULL name in context if the decl has been renamed.
20874 CHILD is true if decl is one of the renamed decls as part of
20875 importing whole module. */
20878 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
20881 /* dw_die_ref at_import_die; */
20882 dw_die_ref scope_die;
20884 if (debug_info_level <= DINFO_LEVEL_TERSE)
20889 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20890 We need decl DIE for reference and scope die. First, get DIE for the decl
20893 /* Get the scope die for decl context. Use comp_unit_die for global module
20894 or decl. If die is not found for non globals, force new die. */
20896 && TYPE_P (context)
20897 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
20900 if (!(dwarf_version >= 3 || !dwarf_strict))
20903 scope_die = get_context_die (context);
20907 gcc_assert (scope_die->die_child);
20908 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
20909 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
20910 scope_die = scope_die->die_child;
20913 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20914 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
20918 /* Write the debugging output for DECL. */
20921 dwarf2out_decl (tree decl)
20923 dw_die_ref context_die = comp_unit_die;
20925 switch (TREE_CODE (decl))
20930 case FUNCTION_DECL:
20931 /* What we would really like to do here is to filter out all mere
20932 file-scope declarations of file-scope functions which are never
20933 referenced later within this translation unit (and keep all of ones
20934 that *are* referenced later on) but we aren't clairvoyant, so we have
20935 no idea which functions will be referenced in the future (i.e. later
20936 on within the current translation unit). So here we just ignore all
20937 file-scope function declarations which are not also definitions. If
20938 and when the debugger needs to know something about these functions,
20939 it will have to hunt around and find the DWARF information associated
20940 with the definition of the function.
20942 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20943 nodes represent definitions and which ones represent mere
20944 declarations. We have to check DECL_INITIAL instead. That's because
20945 the C front-end supports some weird semantics for "extern inline"
20946 function definitions. These can get inlined within the current
20947 translation unit (and thus, we need to generate Dwarf info for their
20948 abstract instances so that the Dwarf info for the concrete inlined
20949 instances can have something to refer to) but the compiler never
20950 generates any out-of-lines instances of such things (despite the fact
20951 that they *are* definitions).
20953 The important point is that the C front-end marks these "extern
20954 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20955 them anyway. Note that the C++ front-end also plays some similar games
20956 for inline function definitions appearing within include files which
20957 also contain `#pragma interface' pragmas. */
20958 if (DECL_INITIAL (decl) == NULL_TREE)
20961 /* If we're a nested function, initially use a parent of NULL; if we're
20962 a plain function, this will be fixed up in decls_for_scope. If
20963 we're a method, it will be ignored, since we already have a DIE. */
20964 if (decl_function_context (decl)
20965 /* But if we're in terse mode, we don't care about scope. */
20966 && debug_info_level > DINFO_LEVEL_TERSE)
20967 context_die = NULL;
20971 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20972 declaration and if the declaration was never even referenced from
20973 within this entire compilation unit. We suppress these DIEs in
20974 order to save space in the .debug section (by eliminating entries
20975 which are probably useless). Note that we must not suppress
20976 block-local extern declarations (whether used or not) because that
20977 would screw-up the debugger's name lookup mechanism and cause it to
20978 miss things which really ought to be in scope at a given point. */
20979 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
20982 /* For local statics lookup proper context die. */
20983 if (TREE_STATIC (decl) && decl_function_context (decl))
20984 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20986 /* If we are in terse mode, don't generate any DIEs to represent any
20987 variable declarations or definitions. */
20988 if (debug_info_level <= DINFO_LEVEL_TERSE)
20993 if (debug_info_level <= DINFO_LEVEL_TERSE)
20995 if (!is_fortran () && !is_ada ())
20997 if (TREE_STATIC (decl) && decl_function_context (decl))
20998 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21001 case NAMESPACE_DECL:
21002 case IMPORTED_DECL:
21003 if (debug_info_level <= DINFO_LEVEL_TERSE)
21005 if (lookup_decl_die (decl) != NULL)
21010 /* Don't emit stubs for types unless they are needed by other DIEs. */
21011 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21014 /* Don't bother trying to generate any DIEs to represent any of the
21015 normal built-in types for the language we are compiling. */
21016 if (DECL_IS_BUILTIN (decl))
21019 /* If we are in terse mode, don't generate any DIEs for types. */
21020 if (debug_info_level <= DINFO_LEVEL_TERSE)
21023 /* If we're a function-scope tag, initially use a parent of NULL;
21024 this will be fixed up in decls_for_scope. */
21025 if (decl_function_context (decl))
21026 context_die = NULL;
21034 gen_decl_die (decl, NULL, context_die);
21037 /* Write the debugging output for DECL. */
21040 dwarf2out_function_decl (tree decl)
21042 dwarf2out_decl (decl);
21044 htab_empty (decl_loc_table);
21047 /* Output a marker (i.e. a label) for the beginning of the generated code for
21048 a lexical block. */
21051 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21052 unsigned int blocknum)
21054 switch_to_section (current_function_section ());
21055 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21058 /* Output a marker (i.e. a label) for the end of the generated code for a
21062 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21064 switch_to_section (current_function_section ());
21065 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21068 /* Returns nonzero if it is appropriate not to emit any debugging
21069 information for BLOCK, because it doesn't contain any instructions.
21071 Don't allow this for blocks with nested functions or local classes
21072 as we would end up with orphans, and in the presence of scheduling
21073 we may end up calling them anyway. */
21076 dwarf2out_ignore_block (const_tree block)
21081 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21082 if (TREE_CODE (decl) == FUNCTION_DECL
21083 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21085 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21087 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21088 if (TREE_CODE (decl) == FUNCTION_DECL
21089 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21096 /* Hash table routines for file_hash. */
21099 file_table_eq (const void *p1_p, const void *p2_p)
21101 const struct dwarf_file_data *const p1 =
21102 (const struct dwarf_file_data *) p1_p;
21103 const char *const p2 = (const char *) p2_p;
21104 return strcmp (p1->filename, p2) == 0;
21108 file_table_hash (const void *p_p)
21110 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21111 return htab_hash_string (p->filename);
21114 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21115 dwarf2out.c) and return its "index". The index of each (known) filename is
21116 just a unique number which is associated with only that one filename. We
21117 need such numbers for the sake of generating labels (in the .debug_sfnames
21118 section) and references to those files numbers (in the .debug_srcinfo
21119 and.debug_macinfo sections). If the filename given as an argument is not
21120 found in our current list, add it to the list and assign it the next
21121 available unique index number. In order to speed up searches, we remember
21122 the index of the filename was looked up last. This handles the majority of
21125 static struct dwarf_file_data *
21126 lookup_filename (const char *file_name)
21129 struct dwarf_file_data * created;
21131 /* Check to see if the file name that was searched on the previous
21132 call matches this file name. If so, return the index. */
21133 if (file_table_last_lookup
21134 && (file_name == file_table_last_lookup->filename
21135 || strcmp (file_table_last_lookup->filename, file_name) == 0))
21136 return file_table_last_lookup;
21138 /* Didn't match the previous lookup, search the table. */
21139 slot = htab_find_slot_with_hash (file_table, file_name,
21140 htab_hash_string (file_name), INSERT);
21142 return (struct dwarf_file_data *) *slot;
21144 created = ggc_alloc_dwarf_file_data ();
21145 created->filename = file_name;
21146 created->emitted_number = 0;
21151 /* If the assembler will construct the file table, then translate the compiler
21152 internal file table number into the assembler file table number, and emit
21153 a .file directive if we haven't already emitted one yet. The file table
21154 numbers are different because we prune debug info for unused variables and
21155 types, which may include filenames. */
21158 maybe_emit_file (struct dwarf_file_data * fd)
21160 if (! fd->emitted_number)
21162 if (last_emitted_file)
21163 fd->emitted_number = last_emitted_file->emitted_number + 1;
21165 fd->emitted_number = 1;
21166 last_emitted_file = fd;
21168 if (DWARF2_ASM_LINE_DEBUG_INFO)
21170 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21171 output_quoted_string (asm_out_file,
21172 remap_debug_filename (fd->filename));
21173 fputc ('\n', asm_out_file);
21177 return fd->emitted_number;
21180 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21181 That generation should happen after function debug info has been
21182 generated. The value of the attribute is the constant value of ARG. */
21185 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21187 die_arg_entry entry;
21192 if (!tmpl_value_parm_die_table)
21193 tmpl_value_parm_die_table
21194 = VEC_alloc (die_arg_entry, gc, 32);
21198 VEC_safe_push (die_arg_entry, gc,
21199 tmpl_value_parm_die_table,
21203 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21204 by append_entry_to_tmpl_value_parm_die_table. This function must
21205 be called after function DIEs have been generated. */
21208 gen_remaining_tmpl_value_param_die_attribute (void)
21210 if (tmpl_value_parm_die_table)
21215 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21216 tree_add_const_value_attribute (e->die, e->arg);
21221 /* Replace DW_AT_name for the decl with name. */
21224 dwarf2out_set_name (tree decl, tree name)
21230 die = TYPE_SYMTAB_DIE (decl);
21234 dname = dwarf2_name (name, 0);
21238 attr = get_AT (die, DW_AT_name);
21241 struct indirect_string_node *node;
21243 node = find_AT_string (dname);
21244 /* replace the string. */
21245 attr->dw_attr_val.v.val_str = node;
21249 add_name_attribute (die, dname);
21252 /* Called by the final INSN scan whenever we see a direct function call.
21253 Make an entry into the direct call table, recording the point of call
21254 and a reference to the target function's debug entry. */
21257 dwarf2out_direct_call (tree targ)
21260 tree origin = decl_ultimate_origin (targ);
21262 /* If this is a clone, use the abstract origin as the target. */
21266 e.poc_label_num = poc_label_num++;
21267 e.poc_decl = current_function_decl;
21268 e.targ_die = force_decl_die (targ);
21269 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21271 /* Drop a label at the return point to mark the point of call. */
21272 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21275 /* Returns a hash value for X (which really is a struct vcall_insn). */
21278 vcall_insn_table_hash (const void *x)
21280 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21283 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21284 insnd_uid of *Y. */
21287 vcall_insn_table_eq (const void *x, const void *y)
21289 return (((const struct vcall_insn *) x)->insn_uid
21290 == ((const struct vcall_insn *) y)->insn_uid);
21293 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21296 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21298 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21299 struct vcall_insn **slot;
21302 item->insn_uid = insn_uid;
21303 item->vtable_slot = vtable_slot;
21304 slot = (struct vcall_insn **)
21305 htab_find_slot_with_hash (vcall_insn_table, &item,
21306 (hashval_t) insn_uid, INSERT);
21310 /* Return the VTABLE_SLOT associated with INSN_UID. */
21312 static unsigned int
21313 lookup_vcall_insn (unsigned int insn_uid)
21315 struct vcall_insn item;
21316 struct vcall_insn *p;
21318 item.insn_uid = insn_uid;
21319 item.vtable_slot = 0;
21320 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21322 (hashval_t) insn_uid);
21324 return (unsigned int) -1;
21325 return p->vtable_slot;
21329 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21330 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21331 is the vtable slot index that we will need to put in the virtual call
21335 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21337 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21339 tree token = OBJ_TYPE_REF_TOKEN (addr);
21340 if (TREE_CODE (token) == INTEGER_CST)
21341 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21345 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21346 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21350 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21352 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
21354 if (vtable_slot != (unsigned int) -1)
21355 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
21358 /* Called by the final INSN scan whenever we see a virtual function call.
21359 Make an entry into the virtual call table, recording the point of call
21360 and the slot index of the vtable entry used to call the virtual member
21361 function. The slot index was associated with the INSN_UID during the
21362 lowering to RTL. */
21365 dwarf2out_virtual_call (int insn_uid)
21367 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
21370 if (vtable_slot == (unsigned int) -1)
21373 e.poc_label_num = poc_label_num++;
21374 e.vtable_slot = vtable_slot;
21375 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
21377 /* Drop a label at the return point to mark the point of call. */
21378 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21381 /* Called by the final INSN scan whenever we see a var location. We
21382 use it to drop labels in the right places, and throw the location in
21383 our lookup table. */
21386 dwarf2out_var_location (rtx loc_note)
21388 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21389 struct var_loc_node *newloc;
21391 static const char *last_label;
21392 static const char *last_postcall_label;
21393 static bool last_in_cold_section_p;
21396 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21399 next_real = next_real_insn (loc_note);
21400 /* If there are no instructions which would be affected by this note,
21401 don't do anything. */
21402 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
21405 /* If there were any real insns between note we processed last time
21406 and this note (or if it is the first note), clear
21407 last_{,postcall_}label so that they are not reused this time. */
21408 if (last_var_location_insn == NULL_RTX
21409 || last_var_location_insn != next_real
21410 || last_in_cold_section_p != in_cold_section_p)
21413 last_postcall_label = NULL;
21416 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21417 newloc = add_var_loc_to_decl (decl, loc_note,
21418 NOTE_DURING_CALL_P (loc_note)
21419 ? last_postcall_label : last_label);
21420 if (newloc == NULL)
21423 /* If there were no real insns between note we processed last time
21424 and this note, use the label we emitted last time. Otherwise
21425 create a new label and emit it. */
21426 if (last_label == NULL)
21428 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21429 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21431 last_label = ggc_strdup (loclabel);
21434 if (!NOTE_DURING_CALL_P (loc_note))
21435 newloc->label = last_label;
21438 if (!last_postcall_label)
21440 sprintf (loclabel, "%s-1", last_label);
21441 last_postcall_label = ggc_strdup (loclabel);
21443 newloc->label = last_postcall_label;
21446 last_var_location_insn = next_real;
21447 last_in_cold_section_p = in_cold_section_p;
21450 /* We need to reset the locations at the beginning of each
21451 function. We can't do this in the end_function hook, because the
21452 declarations that use the locations won't have been output when
21453 that hook is called. Also compute have_multiple_function_sections here. */
21456 dwarf2out_begin_function (tree fun)
21458 if (function_section (fun) != text_section)
21459 have_multiple_function_sections = true;
21461 dwarf2out_note_section_used ();
21464 /* Output a label to mark the beginning of a source code line entry
21465 and record information relating to this source line, in
21466 'line_info_table' for later output of the .debug_line section. */
21469 dwarf2out_source_line (unsigned int line, const char *filename,
21470 int discriminator, bool is_stmt)
21472 static bool last_is_stmt = true;
21474 if (debug_info_level >= DINFO_LEVEL_NORMAL
21477 int file_num = maybe_emit_file (lookup_filename (filename));
21479 switch_to_section (current_function_section ());
21481 /* If requested, emit something human-readable. */
21482 if (flag_debug_asm)
21483 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
21486 if (DWARF2_ASM_LINE_DEBUG_INFO)
21488 /* Emit the .loc directive understood by GNU as. */
21489 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
21490 if (is_stmt != last_is_stmt)
21492 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
21493 last_is_stmt = is_stmt;
21495 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
21496 fprintf (asm_out_file, " discriminator %d", discriminator);
21497 fputc ('\n', asm_out_file);
21499 /* Indicate that line number info exists. */
21500 line_info_table_in_use++;
21502 else if (function_section (current_function_decl) != text_section)
21504 dw_separate_line_info_ref line_info;
21505 targetm.asm_out.internal_label (asm_out_file,
21506 SEPARATE_LINE_CODE_LABEL,
21507 separate_line_info_table_in_use);
21509 /* Expand the line info table if necessary. */
21510 if (separate_line_info_table_in_use
21511 == separate_line_info_table_allocated)
21513 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21514 separate_line_info_table
21515 = GGC_RESIZEVEC (dw_separate_line_info_entry,
21516 separate_line_info_table,
21517 separate_line_info_table_allocated);
21518 memset (separate_line_info_table
21519 + separate_line_info_table_in_use,
21521 (LINE_INFO_TABLE_INCREMENT
21522 * sizeof (dw_separate_line_info_entry)));
21525 /* Add the new entry at the end of the line_info_table. */
21527 = &separate_line_info_table[separate_line_info_table_in_use++];
21528 line_info->dw_file_num = file_num;
21529 line_info->dw_line_num = line;
21530 line_info->function = current_function_funcdef_no;
21534 dw_line_info_ref line_info;
21536 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
21537 line_info_table_in_use);
21539 /* Expand the line info table if necessary. */
21540 if (line_info_table_in_use == line_info_table_allocated)
21542 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21544 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
21545 line_info_table_allocated);
21546 memset (line_info_table + line_info_table_in_use, 0,
21547 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
21550 /* Add the new entry at the end of the line_info_table. */
21551 line_info = &line_info_table[line_info_table_in_use++];
21552 line_info->dw_file_num = file_num;
21553 line_info->dw_line_num = line;
21558 /* Record the beginning of a new source file. */
21561 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
21563 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21565 /* Record the beginning of the file for break_out_includes. */
21566 dw_die_ref bincl_die;
21568 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
21569 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
21572 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21574 int file_num = maybe_emit_file (lookup_filename (filename));
21576 switch_to_section (debug_macinfo_section);
21577 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
21578 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
21581 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
21585 /* Record the end of a source file. */
21588 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
21590 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21591 /* Record the end of the file for break_out_includes. */
21592 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
21594 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21596 switch_to_section (debug_macinfo_section);
21597 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
21601 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21602 the tail part of the directive line, i.e. the part which is past the
21603 initial whitespace, #, whitespace, directive-name, whitespace part. */
21606 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
21607 const char *buffer ATTRIBUTE_UNUSED)
21609 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21611 switch_to_section (debug_macinfo_section);
21612 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
21613 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21614 dw2_asm_output_nstring (buffer, -1, "The macro");
21618 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21619 the tail part of the directive line, i.e. the part which is past the
21620 initial whitespace, #, whitespace, directive-name, whitespace part. */
21623 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
21624 const char *buffer ATTRIBUTE_UNUSED)
21626 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21628 switch_to_section (debug_macinfo_section);
21629 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
21630 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
21631 dw2_asm_output_nstring (buffer, -1, "The macro");
21635 /* Set up for Dwarf output at the start of compilation. */
21638 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21640 /* Allocate the file_table. */
21641 file_table = htab_create_ggc (50, file_table_hash,
21642 file_table_eq, NULL);
21644 /* Allocate the decl_die_table. */
21645 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21646 decl_die_table_eq, NULL);
21648 /* Allocate the decl_loc_table. */
21649 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21650 decl_loc_table_eq, NULL);
21652 /* Allocate the initial hunk of the decl_scope_table. */
21653 decl_scope_table = VEC_alloc (tree, gc, 256);
21655 /* Allocate the initial hunk of the abbrev_die_table. */
21656 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21657 (ABBREV_DIE_TABLE_INCREMENT);
21658 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21659 /* Zero-th entry is allocated, but unused. */
21660 abbrev_die_table_in_use = 1;
21662 /* Allocate the initial hunk of the line_info_table. */
21663 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
21664 (LINE_INFO_TABLE_INCREMENT);
21665 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
21667 /* Zero-th entry is allocated, but unused. */
21668 line_info_table_in_use = 1;
21670 /* Allocate the pubtypes and pubnames vectors. */
21671 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21672 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21674 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21675 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
21676 vcall_insn_table_eq, NULL);
21678 /* Generate the initial DIE for the .debug section. Note that the (string)
21679 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
21680 will (typically) be a relative pathname and that this pathname should be
21681 taken as being relative to the directory from which the compiler was
21682 invoked when the given (base) source file was compiled. We will fill
21683 in this value in dwarf2out_finish. */
21684 comp_unit_die = gen_compile_unit_die (NULL);
21686 incomplete_types = VEC_alloc (tree, gc, 64);
21688 used_rtx_array = VEC_alloc (rtx, gc, 32);
21690 debug_info_section = get_section (DEBUG_INFO_SECTION,
21691 SECTION_DEBUG, NULL);
21692 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21693 SECTION_DEBUG, NULL);
21694 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21695 SECTION_DEBUG, NULL);
21696 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
21697 SECTION_DEBUG, NULL);
21698 debug_line_section = get_section (DEBUG_LINE_SECTION,
21699 SECTION_DEBUG, NULL);
21700 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21701 SECTION_DEBUG, NULL);
21702 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21703 SECTION_DEBUG, NULL);
21704 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21705 SECTION_DEBUG, NULL);
21706 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
21707 SECTION_DEBUG, NULL);
21708 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
21709 SECTION_DEBUG, NULL);
21710 debug_str_section = get_section (DEBUG_STR_SECTION,
21711 DEBUG_STR_SECTION_FLAGS, NULL);
21712 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21713 SECTION_DEBUG, NULL);
21714 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21715 SECTION_DEBUG, NULL);
21717 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21718 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21719 DEBUG_ABBREV_SECTION_LABEL, 0);
21720 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21721 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21722 COLD_TEXT_SECTION_LABEL, 0);
21723 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21725 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21726 DEBUG_INFO_SECTION_LABEL, 0);
21727 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21728 DEBUG_LINE_SECTION_LABEL, 0);
21729 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21730 DEBUG_RANGES_SECTION_LABEL, 0);
21731 switch_to_section (debug_abbrev_section);
21732 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
21733 switch_to_section (debug_info_section);
21734 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
21735 switch_to_section (debug_line_section);
21736 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
21738 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21740 switch_to_section (debug_macinfo_section);
21741 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
21742 DEBUG_MACINFO_SECTION_LABEL, 0);
21743 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
21746 switch_to_section (text_section);
21747 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
21748 if (flag_reorder_blocks_and_partition)
21750 cold_text_section = unlikely_text_section ();
21751 switch_to_section (cold_text_section);
21752 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
21757 /* Called before cgraph_optimize starts outputtting functions, variables
21758 and toplevel asms into assembly. */
21761 dwarf2out_assembly_start (void)
21763 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && dwarf2out_do_cfi_asm ())
21765 #ifndef TARGET_UNWIND_INFO
21766 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
21768 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
21772 /* A helper function for dwarf2out_finish called through
21773 htab_traverse. Emit one queued .debug_str string. */
21776 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21778 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21780 if (node->label && node->refcount)
21782 switch_to_section (debug_str_section);
21783 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21784 assemble_string (node->str, strlen (node->str) + 1);
21790 #if ENABLE_ASSERT_CHECKING
21791 /* Verify that all marks are clear. */
21794 verify_marks_clear (dw_die_ref die)
21798 gcc_assert (! die->die_mark);
21799 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21801 #endif /* ENABLE_ASSERT_CHECKING */
21803 /* Clear the marks for a die and its children.
21804 Be cool if the mark isn't set. */
21807 prune_unmark_dies (dw_die_ref die)
21813 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21816 /* Given DIE that we're marking as used, find any other dies
21817 it references as attributes and mark them as used. */
21820 prune_unused_types_walk_attribs (dw_die_ref die)
21825 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21827 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21829 /* A reference to another DIE.
21830 Make sure that it will get emitted.
21831 If it was broken out into a comdat group, don't follow it. */
21832 if (dwarf_version < 4
21833 || a->dw_attr == DW_AT_specification
21834 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21835 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21837 /* Set the string's refcount to 0 so that prune_unused_types_mark
21838 accounts properly for it. */
21839 if (AT_class (a) == dw_val_class_str)
21840 a->dw_attr_val.v.val_str->refcount = 0;
21845 /* Mark DIE as being used. If DOKIDS is true, then walk down
21846 to DIE's children. */
21849 prune_unused_types_mark (dw_die_ref die, int dokids)
21853 if (die->die_mark == 0)
21855 /* We haven't done this node yet. Mark it as used. */
21858 /* We also have to mark its parents as used.
21859 (But we don't want to mark our parents' kids due to this.) */
21860 if (die->die_parent)
21861 prune_unused_types_mark (die->die_parent, 0);
21863 /* Mark any referenced nodes. */
21864 prune_unused_types_walk_attribs (die);
21866 /* If this node is a specification,
21867 also mark the definition, if it exists. */
21868 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21869 prune_unused_types_mark (die->die_definition, 1);
21872 if (dokids && die->die_mark != 2)
21874 /* We need to walk the children, but haven't done so yet.
21875 Remember that we've walked the kids. */
21878 /* If this is an array type, we need to make sure our
21879 kids get marked, even if they're types. If we're
21880 breaking out types into comdat sections, do this
21881 for all type definitions. */
21882 if (die->die_tag == DW_TAG_array_type
21883 || (dwarf_version >= 4
21884 && is_type_die (die) && ! is_declaration_die (die)))
21885 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21887 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21891 /* For local classes, look if any static member functions were emitted
21892 and if so, mark them. */
21895 prune_unused_types_walk_local_classes (dw_die_ref die)
21899 if (die->die_mark == 2)
21902 switch (die->die_tag)
21904 case DW_TAG_structure_type:
21905 case DW_TAG_union_type:
21906 case DW_TAG_class_type:
21909 case DW_TAG_subprogram:
21910 if (!get_AT_flag (die, DW_AT_declaration)
21911 || die->die_definition != NULL)
21912 prune_unused_types_mark (die, 1);
21919 /* Mark children. */
21920 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21923 /* Walk the tree DIE and mark types that we actually use. */
21926 prune_unused_types_walk (dw_die_ref die)
21930 /* Don't do anything if this node is already marked and
21931 children have been marked as well. */
21932 if (die->die_mark == 2)
21935 switch (die->die_tag)
21937 case DW_TAG_structure_type:
21938 case DW_TAG_union_type:
21939 case DW_TAG_class_type:
21940 if (die->die_perennial_p)
21943 for (c = die->die_parent; c; c = c->die_parent)
21944 if (c->die_tag == DW_TAG_subprogram)
21947 /* Finding used static member functions inside of classes
21948 is needed just for local classes, because for other classes
21949 static member function DIEs with DW_AT_specification
21950 are emitted outside of the DW_TAG_*_type. If we ever change
21951 it, we'd need to call this even for non-local classes. */
21953 prune_unused_types_walk_local_classes (die);
21955 /* It's a type node --- don't mark it. */
21958 case DW_TAG_const_type:
21959 case DW_TAG_packed_type:
21960 case DW_TAG_pointer_type:
21961 case DW_TAG_reference_type:
21962 case DW_TAG_rvalue_reference_type:
21963 case DW_TAG_volatile_type:
21964 case DW_TAG_typedef:
21965 case DW_TAG_array_type:
21966 case DW_TAG_interface_type:
21967 case DW_TAG_friend:
21968 case DW_TAG_variant_part:
21969 case DW_TAG_enumeration_type:
21970 case DW_TAG_subroutine_type:
21971 case DW_TAG_string_type:
21972 case DW_TAG_set_type:
21973 case DW_TAG_subrange_type:
21974 case DW_TAG_ptr_to_member_type:
21975 case DW_TAG_file_type:
21976 if (die->die_perennial_p)
21979 /* It's a type node --- don't mark it. */
21983 /* Mark everything else. */
21987 if (die->die_mark == 0)
21991 /* Now, mark any dies referenced from here. */
21992 prune_unused_types_walk_attribs (die);
21997 /* Mark children. */
21998 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22001 /* Increment the string counts on strings referred to from DIE's
22005 prune_unused_types_update_strings (dw_die_ref die)
22010 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22011 if (AT_class (a) == dw_val_class_str)
22013 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22015 /* Avoid unnecessarily putting strings that are used less than
22016 twice in the hash table. */
22018 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22021 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22022 htab_hash_string (s->str),
22024 gcc_assert (*slot == NULL);
22030 /* Remove from the tree DIE any dies that aren't marked. */
22033 prune_unused_types_prune (dw_die_ref die)
22037 gcc_assert (die->die_mark);
22038 prune_unused_types_update_strings (die);
22040 if (! die->die_child)
22043 c = die->die_child;
22045 dw_die_ref prev = c;
22046 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22047 if (c == die->die_child)
22049 /* No marked children between 'prev' and the end of the list. */
22051 /* No marked children at all. */
22052 die->die_child = NULL;
22055 prev->die_sib = c->die_sib;
22056 die->die_child = prev;
22061 if (c != prev->die_sib)
22063 prune_unused_types_prune (c);
22064 } while (c != die->die_child);
22067 /* A helper function for dwarf2out_finish called through
22068 htab_traverse. Clear .debug_str strings that we haven't already
22069 decided to emit. */
22072 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22074 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22076 if (!node->label || !node->refcount)
22077 htab_clear_slot (debug_str_hash, h);
22082 /* Remove dies representing declarations that we never use. */
22085 prune_unused_types (void)
22088 limbo_die_node *node;
22089 comdat_type_node *ctnode;
22091 dcall_entry *dcall;
22093 #if ENABLE_ASSERT_CHECKING
22094 /* All the marks should already be clear. */
22095 verify_marks_clear (comp_unit_die);
22096 for (node = limbo_die_list; node; node = node->next)
22097 verify_marks_clear (node->die);
22098 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22099 verify_marks_clear (ctnode->root_die);
22100 #endif /* ENABLE_ASSERT_CHECKING */
22102 /* Mark types that are used in global variables. */
22103 premark_types_used_by_global_vars ();
22105 /* Set the mark on nodes that are actually used. */
22106 prune_unused_types_walk (comp_unit_die);
22107 for (node = limbo_die_list; node; node = node->next)
22108 prune_unused_types_walk (node->die);
22109 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22111 prune_unused_types_walk (ctnode->root_die);
22112 prune_unused_types_mark (ctnode->type_die, 1);
22115 /* Also set the mark on nodes referenced from the
22116 pubname_table or arange_table. */
22117 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22118 prune_unused_types_mark (pub->die, 1);
22119 for (i = 0; i < arange_table_in_use; i++)
22120 prune_unused_types_mark (arange_table[i], 1);
22122 /* Mark nodes referenced from the direct call table. */
22123 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
22124 prune_unused_types_mark (dcall->targ_die, 1);
22126 /* Get rid of nodes that aren't marked; and update the string counts. */
22127 if (debug_str_hash && debug_str_hash_forced)
22128 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22129 else if (debug_str_hash)
22130 htab_empty (debug_str_hash);
22131 prune_unused_types_prune (comp_unit_die);
22132 for (node = limbo_die_list; node; node = node->next)
22133 prune_unused_types_prune (node->die);
22134 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22135 prune_unused_types_prune (ctnode->root_die);
22137 /* Leave the marks clear. */
22138 prune_unmark_dies (comp_unit_die);
22139 for (node = limbo_die_list; node; node = node->next)
22140 prune_unmark_dies (node->die);
22141 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22142 prune_unmark_dies (ctnode->root_die);
22145 /* Set the parameter to true if there are any relative pathnames in
22148 file_table_relative_p (void ** slot, void *param)
22150 bool *p = (bool *) param;
22151 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22152 if (!IS_ABSOLUTE_PATH (d->filename))
22160 /* Routines to manipulate hash table of comdat type units. */
22163 htab_ct_hash (const void *of)
22166 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22168 memcpy (&h, type_node->signature, sizeof (h));
22173 htab_ct_eq (const void *of1, const void *of2)
22175 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22176 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22178 return (! memcmp (type_node_1->signature, type_node_2->signature,
22179 DWARF_TYPE_SIGNATURE_SIZE));
22182 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22183 to the location it would have been added, should we know its
22184 DECL_ASSEMBLER_NAME when we added other attributes. This will
22185 probably improve compactness of debug info, removing equivalent
22186 abbrevs, and hide any differences caused by deferring the
22187 computation of the assembler name, triggered by e.g. PCH. */
22190 move_linkage_attr (dw_die_ref die)
22192 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22193 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22195 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22196 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22200 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22202 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22206 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22208 VEC_pop (dw_attr_node, die->die_attr);
22209 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22213 /* Helper function for resolve_addr, attempt to resolve
22214 one CONST_STRING, return non-zero if not successful. Similarly verify that
22215 SYMBOL_REFs refer to variables emitted in the current CU. */
22218 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22222 if (GET_CODE (rtl) == CONST_STRING)
22224 size_t len = strlen (XSTR (rtl, 0)) + 1;
22225 tree t = build_string (len, XSTR (rtl, 0));
22226 tree tlen = build_int_cst (NULL_TREE, len - 1);
22228 = build_array_type (char_type_node, build_index_type (tlen));
22229 rtl = lookup_constant_def (t);
22230 if (!rtl || !MEM_P (rtl))
22232 rtl = XEXP (rtl, 0);
22233 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22238 if (GET_CODE (rtl) == SYMBOL_REF
22239 && SYMBOL_REF_DECL (rtl)
22240 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22243 if (GET_CODE (rtl) == CONST
22244 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22250 /* Helper function for resolve_addr, handle one location
22251 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22252 the location list couldn't be resolved. */
22255 resolve_addr_in_expr (dw_loc_descr_ref loc)
22257 for (; loc; loc = loc->dw_loc_next)
22258 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22259 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22260 || (loc->dw_loc_opc == DW_OP_implicit_value
22261 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22262 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22264 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22265 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22268 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22271 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22272 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22273 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22278 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22279 an address in .rodata section if the string literal is emitted there,
22280 or remove the containing location list or replace DW_AT_const_value
22281 with DW_AT_location and empty location expression, if it isn't found
22282 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22283 to something that has been emitted in the current CU. */
22286 resolve_addr (dw_die_ref die)
22290 dw_loc_list_ref *curr;
22293 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22294 switch (AT_class (a))
22296 case dw_val_class_loc_list:
22297 curr = AT_loc_list_ptr (a);
22300 if (!resolve_addr_in_expr ((*curr)->expr))
22302 dw_loc_list_ref next = (*curr)->dw_loc_next;
22303 if (next && (*curr)->ll_symbol)
22305 gcc_assert (!next->ll_symbol);
22306 next->ll_symbol = (*curr)->ll_symbol;
22311 curr = &(*curr)->dw_loc_next;
22313 if (!AT_loc_list (a))
22315 remove_AT (die, a->dw_attr);
22319 case dw_val_class_loc:
22320 if (!resolve_addr_in_expr (AT_loc (a)))
22322 remove_AT (die, a->dw_attr);
22326 case dw_val_class_addr:
22327 if (a->dw_attr == DW_AT_const_value
22328 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22330 remove_AT (die, a->dw_attr);
22338 FOR_EACH_CHILD (die, c, resolve_addr (c));
22341 /* Output stuff that dwarf requires at the end of every file,
22342 and generate the DWARF-2 debugging info. */
22345 dwarf2out_finish (const char *filename)
22347 limbo_die_node *node, *next_node;
22348 comdat_type_node *ctnode;
22349 htab_t comdat_type_table;
22350 dw_die_ref die = 0;
22353 gen_remaining_tmpl_value_param_die_attribute ();
22355 /* Add the name for the main input file now. We delayed this from
22356 dwarf2out_init to avoid complications with PCH. */
22357 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
22358 if (!IS_ABSOLUTE_PATH (filename))
22359 add_comp_dir_attribute (comp_unit_die);
22360 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
22363 htab_traverse (file_table, file_table_relative_p, &p);
22365 add_comp_dir_attribute (comp_unit_die);
22368 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22370 add_location_or_const_value_attribute (
22371 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22372 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22376 /* Traverse the limbo die list, and add parent/child links. The only
22377 dies without parents that should be here are concrete instances of
22378 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22379 For concrete instances, we can get the parent die from the abstract
22381 for (node = limbo_die_list; node; node = next_node)
22383 next_node = node->next;
22386 if (die->die_parent == NULL)
22388 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22391 add_child_die (origin->die_parent, die);
22392 else if (die == comp_unit_die)
22394 else if (seen_error ())
22395 /* It's OK to be confused by errors in the input. */
22396 add_child_die (comp_unit_die, die);
22399 /* In certain situations, the lexical block containing a
22400 nested function can be optimized away, which results
22401 in the nested function die being orphaned. Likewise
22402 with the return type of that nested function. Force
22403 this to be a child of the containing function.
22405 It may happen that even the containing function got fully
22406 inlined and optimized out. In that case we are lost and
22407 assign the empty child. This should not be big issue as
22408 the function is likely unreachable too. */
22409 tree context = NULL_TREE;
22411 gcc_assert (node->created_for);
22413 if (DECL_P (node->created_for))
22414 context = DECL_CONTEXT (node->created_for);
22415 else if (TYPE_P (node->created_for))
22416 context = TYPE_CONTEXT (node->created_for);
22418 gcc_assert (context
22419 && (TREE_CODE (context) == FUNCTION_DECL
22420 || TREE_CODE (context) == NAMESPACE_DECL));
22422 origin = lookup_decl_die (context);
22424 add_child_die (origin, die);
22426 add_child_die (comp_unit_die, die);
22431 limbo_die_list = NULL;
22433 resolve_addr (comp_unit_die);
22435 for (node = deferred_asm_name; node; node = node->next)
22437 tree decl = node->created_for;
22438 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22440 add_linkage_attr (node->die, decl);
22441 move_linkage_attr (node->die);
22445 deferred_asm_name = NULL;
22447 /* Walk through the list of incomplete types again, trying once more to
22448 emit full debugging info for them. */
22449 retry_incomplete_types ();
22451 if (flag_eliminate_unused_debug_types)
22452 prune_unused_types ();
22454 /* Generate separate CUs for each of the include files we've seen.
22455 They will go into limbo_die_list. */
22456 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22457 break_out_includes (comp_unit_die);
22459 /* Generate separate COMDAT sections for type DIEs. */
22460 if (dwarf_version >= 4)
22462 break_out_comdat_types (comp_unit_die);
22464 /* Each new type_unit DIE was added to the limbo die list when created.
22465 Since these have all been added to comdat_type_list, clear the
22467 limbo_die_list = NULL;
22469 /* For each new comdat type unit, copy declarations for incomplete
22470 types to make the new unit self-contained (i.e., no direct
22471 references to the main compile unit). */
22472 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22473 copy_decls_for_unworthy_types (ctnode->root_die);
22474 copy_decls_for_unworthy_types (comp_unit_die);
22476 /* In the process of copying declarations from one unit to another,
22477 we may have left some declarations behind that are no longer
22478 referenced. Prune them. */
22479 prune_unused_types ();
22482 /* Traverse the DIE's and add add sibling attributes to those DIE's
22483 that have children. */
22484 add_sibling_attributes (comp_unit_die);
22485 for (node = limbo_die_list; node; node = node->next)
22486 add_sibling_attributes (node->die);
22487 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22488 add_sibling_attributes (ctnode->root_die);
22490 /* Output a terminator label for the .text section. */
22491 switch_to_section (text_section);
22492 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22493 if (flag_reorder_blocks_and_partition)
22495 switch_to_section (unlikely_text_section ());
22496 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22499 /* We can only use the low/high_pc attributes if all of the code was
22501 if (!have_multiple_function_sections
22502 || !(dwarf_version >= 3 || !dwarf_strict))
22504 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
22505 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
22510 unsigned fde_idx = 0;
22511 bool range_list_added = false;
22513 /* We need to give .debug_loc and .debug_ranges an appropriate
22514 "base address". Use zero so that these addresses become
22515 absolute. Historically, we've emitted the unexpected
22516 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22517 Emit both to give time for other tools to adapt. */
22518 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
22519 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
22521 if (text_section_used)
22522 add_ranges_by_labels (comp_unit_die, text_section_label,
22523 text_end_label, &range_list_added);
22524 if (flag_reorder_blocks_and_partition && cold_text_section_used)
22525 add_ranges_by_labels (comp_unit_die, cold_text_section_label,
22526 cold_end_label, &range_list_added);
22528 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
22530 dw_fde_ref fde = &fde_table[fde_idx];
22532 if (fde->dw_fde_switched_sections)
22534 if (!fde->in_std_section)
22535 add_ranges_by_labels (comp_unit_die,
22536 fde->dw_fde_hot_section_label,
22537 fde->dw_fde_hot_section_end_label,
22538 &range_list_added);
22539 if (!fde->cold_in_std_section)
22540 add_ranges_by_labels (comp_unit_die,
22541 fde->dw_fde_unlikely_section_label,
22542 fde->dw_fde_unlikely_section_end_label,
22543 &range_list_added);
22545 else if (!fde->in_std_section)
22546 add_ranges_by_labels (comp_unit_die, fde->dw_fde_begin,
22547 fde->dw_fde_end, &range_list_added);
22550 if (range_list_added)
22554 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22555 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
22556 debug_line_section_label);
22558 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22559 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
22561 /* Output all of the compilation units. We put the main one last so that
22562 the offsets are available to output_pubnames. */
22563 for (node = limbo_die_list; node; node = node->next)
22564 output_comp_unit (node->die, 0);
22566 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22567 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22569 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22571 /* Don't output duplicate types. */
22572 if (*slot != HTAB_EMPTY_ENTRY)
22575 /* Add a pointer to the line table for the main compilation unit
22576 so that the debugger can make sense of DW_AT_decl_file
22578 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22579 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22580 debug_line_section_label);
22582 output_comdat_type_unit (ctnode);
22585 htab_delete (comdat_type_table);
22587 /* Output the main compilation unit if non-empty or if .debug_macinfo
22588 has been emitted. */
22589 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
22591 /* Output the abbreviation table. */
22592 switch_to_section (debug_abbrev_section);
22593 output_abbrev_section ();
22595 /* Output location list section if necessary. */
22596 if (have_location_lists)
22598 /* Output the location lists info. */
22599 switch_to_section (debug_loc_section);
22600 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22601 DEBUG_LOC_SECTION_LABEL, 0);
22602 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22603 output_location_lists (die);
22606 /* Output public names table if necessary. */
22607 if (!VEC_empty (pubname_entry, pubname_table))
22609 switch_to_section (debug_pubnames_section);
22610 output_pubnames (pubname_table);
22613 /* Output public types table if necessary. */
22614 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22615 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22616 simply won't look for the section. */
22617 if (!VEC_empty (pubname_entry, pubtype_table))
22619 switch_to_section (debug_pubtypes_section);
22620 output_pubnames (pubtype_table);
22623 /* Output direct and virtual call tables if necessary. */
22624 if (!VEC_empty (dcall_entry, dcall_table))
22626 switch_to_section (debug_dcall_section);
22627 output_dcall_table ();
22629 if (!VEC_empty (vcall_entry, vcall_table))
22631 switch_to_section (debug_vcall_section);
22632 output_vcall_table ();
22635 /* Output the address range information. We only put functions in the arange
22636 table, so don't write it out if we don't have any. */
22637 if (fde_table_in_use)
22639 switch_to_section (debug_aranges_section);
22643 /* Output ranges section if necessary. */
22644 if (ranges_table_in_use)
22646 switch_to_section (debug_ranges_section);
22647 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22651 /* Output the source line correspondence table. We must do this
22652 even if there is no line information. Otherwise, on an empty
22653 translation unit, we will generate a present, but empty,
22654 .debug_info section. IRIX 6.5 `nm' will then complain when
22655 examining the file. This is done late so that any filenames
22656 used by the debug_info section are marked as 'used'. */
22657 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22659 switch_to_section (debug_line_section);
22660 output_line_info ();
22663 /* Have to end the macro section. */
22664 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22666 switch_to_section (debug_macinfo_section);
22667 dw2_asm_output_data (1, 0, "End compilation unit");
22670 /* If we emitted any DW_FORM_strp form attribute, output the string
22672 if (debug_str_hash)
22673 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22676 #include "gt-dwarf2out.h"