1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* Decide whether to emit frame unwind via assembler directives. */
136 dwarf2out_do_cfi_asm (void)
140 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
142 if (!eh_personality_libfunc)
144 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
147 /* Make sure the personality encoding is one the assembler can support.
148 In particular, aligned addresses can't be handled. */
149 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
150 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
152 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
153 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
159 /* The size of the target's pointer type. */
161 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
164 /* Array of RTXes referenced by the debugging information, which therefore
165 must be kept around forever. */
166 static GTY(()) VEC(rtx,gc) *used_rtx_array;
168 /* A pointer to the base of a list of incomplete types which might be
169 completed at some later time. incomplete_types_list needs to be a
170 VEC(tree,gc) because we want to tell the garbage collector about
172 static GTY(()) VEC(tree,gc) *incomplete_types;
174 /* A pointer to the base of a table of references to declaration
175 scopes. This table is a display which tracks the nesting
176 of declaration scopes at the current scope and containing
177 scopes. This table is used to find the proper place to
178 define type declaration DIE's. */
179 static GTY(()) VEC(tree,gc) *decl_scope_table;
181 /* Pointers to various DWARF2 sections. */
182 static GTY(()) section *debug_info_section;
183 static GTY(()) section *debug_abbrev_section;
184 static GTY(()) section *debug_aranges_section;
185 static GTY(()) section *debug_macinfo_section;
186 static GTY(()) section *debug_line_section;
187 static GTY(()) section *debug_loc_section;
188 static GTY(()) section *debug_pubnames_section;
189 static GTY(()) section *debug_pubtypes_section;
190 static GTY(()) section *debug_str_section;
191 static GTY(()) section *debug_ranges_section;
192 static GTY(()) section *debug_frame_section;
194 /* How to start an assembler comment. */
195 #ifndef ASM_COMMENT_START
196 #define ASM_COMMENT_START ";#"
199 typedef struct dw_cfi_struct *dw_cfi_ref;
200 typedef struct dw_fde_struct *dw_fde_ref;
201 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
203 /* Call frames are described using a sequence of Call Frame
204 Information instructions. The register number, offset
205 and address fields are provided as possible operands;
206 their use is selected by the opcode field. */
208 enum dw_cfi_oprnd_type {
210 dw_cfi_oprnd_reg_num,
216 typedef union dw_cfi_oprnd_struct GTY(())
218 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
219 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
220 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
221 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
225 typedef struct dw_cfi_struct GTY(())
227 dw_cfi_ref dw_cfi_next;
228 enum dwarf_call_frame_info dw_cfi_opc;
229 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
231 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
236 /* This is how we define the location of the CFA. We use to handle it
237 as REG + OFFSET all the time, but now it can be more complex.
238 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
239 Instead of passing around REG and OFFSET, we pass a copy
240 of this structure. */
241 typedef struct cfa_loc GTY(())
243 HOST_WIDE_INT offset;
244 HOST_WIDE_INT base_offset;
246 int indirect; /* 1 if CFA is accessed via a dereference. */
249 /* All call frame descriptions (FDE's) in the GCC generated DWARF
250 refer to a single Common Information Entry (CIE), defined at
251 the beginning of the .debug_frame section. This use of a single
252 CIE obviates the need to keep track of multiple CIE's
253 in the DWARF generation routines below. */
255 typedef struct dw_fde_struct GTY(())
258 const char *dw_fde_begin;
259 const char *dw_fde_current_label;
260 const char *dw_fde_end;
261 const char *dw_fde_hot_section_label;
262 const char *dw_fde_hot_section_end_label;
263 const char *dw_fde_unlikely_section_label;
264 const char *dw_fde_unlikely_section_end_label;
265 bool dw_fde_switched_sections;
266 dw_cfi_ref dw_fde_cfi;
267 unsigned funcdef_number;
268 HOST_WIDE_INT stack_realignment;
269 /* Dynamic realign argument pointer register. */
270 unsigned int drap_reg;
271 /* Virtual dynamic realign argument pointer register. */
272 unsigned int vdrap_reg;
273 unsigned all_throwers_are_sibcalls : 1;
274 unsigned nothrow : 1;
275 unsigned uses_eh_lsda : 1;
276 /* Whether we did stack realign in this call frame. */
277 unsigned stack_realign : 1;
278 /* Whether dynamic realign argument pointer register has been saved. */
279 unsigned drap_reg_saved: 1;
283 /* Maximum size (in bytes) of an artificially generated label. */
284 #define MAX_ARTIFICIAL_LABEL_BYTES 30
286 /* The size of addresses as they appear in the Dwarf 2 data.
287 Some architectures use word addresses to refer to code locations,
288 but Dwarf 2 info always uses byte addresses. On such machines,
289 Dwarf 2 addresses need to be larger than the architecture's
291 #ifndef DWARF2_ADDR_SIZE
292 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
295 /* The size in bytes of a DWARF field indicating an offset or length
296 relative to a debug info section, specified to be 4 bytes in the
297 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
300 #ifndef DWARF_OFFSET_SIZE
301 #define DWARF_OFFSET_SIZE 4
304 /* According to the (draft) DWARF 3 specification, the initial length
305 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
306 bytes are 0xffffffff, followed by the length stored in the next 8
309 However, the SGI/MIPS ABI uses an initial length which is equal to
310 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
312 #ifndef DWARF_INITIAL_LENGTH_SIZE
313 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
316 #define DWARF_VERSION 2
318 /* Round SIZE up to the nearest BOUNDARY. */
319 #define DWARF_ROUND(SIZE,BOUNDARY) \
320 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
322 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
323 #ifndef DWARF_CIE_DATA_ALIGNMENT
324 #ifdef STACK_GROWS_DOWNWARD
325 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
327 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
331 /* CIE identifier. */
332 #if HOST_BITS_PER_WIDE_INT >= 64
333 #define DWARF_CIE_ID \
334 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
336 #define DWARF_CIE_ID DW_CIE_ID
339 /* A pointer to the base of a table that contains frame description
340 information for each routine. */
341 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
343 /* Number of elements currently allocated for fde_table. */
344 static GTY(()) unsigned fde_table_allocated;
346 /* Number of elements in fde_table currently in use. */
347 static GTY(()) unsigned fde_table_in_use;
349 /* Size (in elements) of increments by which we may expand the
351 #define FDE_TABLE_INCREMENT 256
353 /* Get the current fde_table entry we should use. */
355 static inline dw_fde_ref
358 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
361 /* A list of call frame insns for the CIE. */
362 static GTY(()) dw_cfi_ref cie_cfi_head;
364 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
365 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
366 attribute that accelerates the lookup of the FDE associated
367 with the subprogram. This variable holds the table index of the FDE
368 associated with the current function (body) definition. */
369 static unsigned current_funcdef_fde;
372 struct indirect_string_node GTY(())
375 unsigned int refcount;
380 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
382 static GTY(()) int dw2_string_counter;
383 static GTY(()) unsigned long dwarf2out_cfi_label_num;
385 /* True if the compilation unit places functions in more than one section. */
386 static GTY(()) bool have_multiple_function_sections = false;
388 /* Whether the default text and cold text sections have been used at all. */
390 static GTY(()) bool text_section_used = false;
391 static GTY(()) bool cold_text_section_used = false;
393 /* The default cold text section. */
394 static GTY(()) section *cold_text_section;
396 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
398 /* Forward declarations for functions defined in this file. */
400 static char *stripattributes (const char *);
401 static const char *dwarf_cfi_name (unsigned);
402 static dw_cfi_ref new_cfi (void);
403 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
404 static void add_fde_cfi (const char *, dw_cfi_ref);
405 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
406 static void lookup_cfa (dw_cfa_location *);
407 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
408 #ifdef DWARF2_UNWIND_INFO
409 static void initial_return_save (rtx);
411 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
412 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
413 static void output_cfi_directive (dw_cfi_ref);
414 static void output_call_frame_info (int);
415 static void dwarf2out_note_section_used (void);
416 static void dwarf2out_stack_adjust (rtx, bool);
417 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
418 static void flush_queued_reg_saves (void);
419 static bool clobbers_queued_reg_save (const_rtx);
420 static void dwarf2out_frame_debug_expr (rtx, const char *);
422 /* Support for complex CFA locations. */
423 static void output_cfa_loc (dw_cfi_ref);
424 static void output_cfa_loc_raw (dw_cfi_ref);
425 static void get_cfa_from_loc_descr (dw_cfa_location *,
426 struct dw_loc_descr_struct *);
427 static struct dw_loc_descr_struct *build_cfa_loc
428 (dw_cfa_location *, HOST_WIDE_INT);
429 static struct dw_loc_descr_struct *build_cfa_aligned_loc
430 (HOST_WIDE_INT, HOST_WIDE_INT);
431 static void def_cfa_1 (const char *, dw_cfa_location *);
433 /* How to start an assembler comment. */
434 #ifndef ASM_COMMENT_START
435 #define ASM_COMMENT_START ";#"
438 /* Data and reference forms for relocatable data. */
439 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
440 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
442 #ifndef DEBUG_FRAME_SECTION
443 #define DEBUG_FRAME_SECTION ".debug_frame"
446 #ifndef FUNC_BEGIN_LABEL
447 #define FUNC_BEGIN_LABEL "LFB"
450 #ifndef FUNC_END_LABEL
451 #define FUNC_END_LABEL "LFE"
454 #ifndef FRAME_BEGIN_LABEL
455 #define FRAME_BEGIN_LABEL "Lframe"
457 #define CIE_AFTER_SIZE_LABEL "LSCIE"
458 #define CIE_END_LABEL "LECIE"
459 #define FDE_LABEL "LSFDE"
460 #define FDE_AFTER_SIZE_LABEL "LASFDE"
461 #define FDE_END_LABEL "LEFDE"
462 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
463 #define LINE_NUMBER_END_LABEL "LELT"
464 #define LN_PROLOG_AS_LABEL "LASLTP"
465 #define LN_PROLOG_END_LABEL "LELTP"
466 #define DIE_LABEL_PREFIX "DW"
468 /* The DWARF 2 CFA column which tracks the return address. Normally this
469 is the column for PC, or the first column after all of the hard
471 #ifndef DWARF_FRAME_RETURN_COLUMN
473 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
475 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
479 /* The mapping from gcc register number to DWARF 2 CFA column number. By
480 default, we just provide columns for all registers. */
481 #ifndef DWARF_FRAME_REGNUM
482 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
485 /* Hook used by __throw. */
488 expand_builtin_dwarf_sp_column (void)
490 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
491 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
494 /* Return a pointer to a copy of the section string name S with all
495 attributes stripped off, and an asterisk prepended (for assemble_name). */
498 stripattributes (const char *s)
500 char *stripped = XNEWVEC (char, strlen (s) + 2);
505 while (*s && *s != ',')
512 /* MEM is a memory reference for the register size table, each element of
513 which has mode MODE. Initialize column C as a return address column. */
516 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
518 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
519 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
520 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
523 /* Generate code to initialize the register size table. */
526 expand_builtin_init_dwarf_reg_sizes (tree address)
529 enum machine_mode mode = TYPE_MODE (char_type_node);
530 rtx addr = expand_normal (address);
531 rtx mem = gen_rtx_MEM (BLKmode, addr);
532 bool wrote_return_column = false;
534 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
536 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
538 if (rnum < DWARF_FRAME_REGISTERS)
540 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
541 enum machine_mode save_mode = reg_raw_mode[i];
544 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
545 save_mode = choose_hard_reg_mode (i, 1, true);
546 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
548 if (save_mode == VOIDmode)
550 wrote_return_column = true;
552 size = GET_MODE_SIZE (save_mode);
556 emit_move_insn (adjust_address (mem, mode, offset),
557 gen_int_mode (size, mode));
561 if (!wrote_return_column)
562 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
564 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
565 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
568 targetm.init_dwarf_reg_sizes_extra (address);
571 /* Convert a DWARF call frame info. operation to its string name */
574 dwarf_cfi_name (unsigned int cfi_opc)
578 case DW_CFA_advance_loc:
579 return "DW_CFA_advance_loc";
581 return "DW_CFA_offset";
583 return "DW_CFA_restore";
587 return "DW_CFA_set_loc";
588 case DW_CFA_advance_loc1:
589 return "DW_CFA_advance_loc1";
590 case DW_CFA_advance_loc2:
591 return "DW_CFA_advance_loc2";
592 case DW_CFA_advance_loc4:
593 return "DW_CFA_advance_loc4";
594 case DW_CFA_offset_extended:
595 return "DW_CFA_offset_extended";
596 case DW_CFA_restore_extended:
597 return "DW_CFA_restore_extended";
598 case DW_CFA_undefined:
599 return "DW_CFA_undefined";
600 case DW_CFA_same_value:
601 return "DW_CFA_same_value";
602 case DW_CFA_register:
603 return "DW_CFA_register";
604 case DW_CFA_remember_state:
605 return "DW_CFA_remember_state";
606 case DW_CFA_restore_state:
607 return "DW_CFA_restore_state";
609 return "DW_CFA_def_cfa";
610 case DW_CFA_def_cfa_register:
611 return "DW_CFA_def_cfa_register";
612 case DW_CFA_def_cfa_offset:
613 return "DW_CFA_def_cfa_offset";
616 case DW_CFA_def_cfa_expression:
617 return "DW_CFA_def_cfa_expression";
618 case DW_CFA_expression:
619 return "DW_CFA_expression";
620 case DW_CFA_offset_extended_sf:
621 return "DW_CFA_offset_extended_sf";
622 case DW_CFA_def_cfa_sf:
623 return "DW_CFA_def_cfa_sf";
624 case DW_CFA_def_cfa_offset_sf:
625 return "DW_CFA_def_cfa_offset_sf";
627 /* SGI/MIPS specific */
628 case DW_CFA_MIPS_advance_loc8:
629 return "DW_CFA_MIPS_advance_loc8";
632 case DW_CFA_GNU_window_save:
633 return "DW_CFA_GNU_window_save";
634 case DW_CFA_GNU_args_size:
635 return "DW_CFA_GNU_args_size";
636 case DW_CFA_GNU_negative_offset_extended:
637 return "DW_CFA_GNU_negative_offset_extended";
640 return "DW_CFA_<unknown>";
644 /* Return a pointer to a newly allocated Call Frame Instruction. */
646 static inline dw_cfi_ref
649 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
651 cfi->dw_cfi_next = NULL;
652 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
653 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
658 /* Add a Call Frame Instruction to list of instructions. */
661 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
664 dw_fde_ref fde = current_fde ();
666 /* When DRAP is used, CFA is defined with an expression. Redefine
667 CFA may lead to a different CFA value. */
668 if (fde && fde->drap_reg != INVALID_REGNUM)
669 switch (cfi->dw_cfi_opc)
671 case DW_CFA_def_cfa_register:
672 case DW_CFA_def_cfa_offset:
673 case DW_CFA_def_cfa_offset_sf:
675 case DW_CFA_def_cfa_sf:
682 /* Find the end of the chain. */
683 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
689 /* Generate a new label for the CFI info to refer to. */
692 dwarf2out_cfi_label (void)
694 static char label[20];
696 if (dwarf2out_do_cfi_asm ())
698 /* In this case, we will be emitting the asm directive instead of
699 the label, so just return a placeholder to keep the rest of the
701 strcpy (label, "<do not output>");
705 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
706 ASM_OUTPUT_LABEL (asm_out_file, label);
712 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
713 or to the CIE if LABEL is NULL. */
716 add_fde_cfi (const char *label, dw_cfi_ref cfi)
718 dw_cfi_ref *list_head = &cie_cfi_head;
720 if (dwarf2out_do_cfi_asm ())
724 output_cfi_directive (cfi);
726 /* We still have to add the cfi to the list so that
727 lookup_cfa works later on. */
728 list_head = ¤t_fde ()->dw_fde_cfi;
730 /* ??? If this is a CFI for the CIE, we don't emit. This
731 assumes that the standard CIE contents that the assembler
732 uses matches the standard CIE contents that the compiler
733 uses. This is probably a bad assumption. I'm not quite
734 sure how to address this for now. */
738 dw_fde_ref fde = current_fde ();
740 gcc_assert (fde != NULL);
743 label = dwarf2out_cfi_label ();
745 if (fde->dw_fde_current_label == NULL
746 || strcmp (label, fde->dw_fde_current_label) != 0)
750 label = xstrdup (label);
752 /* Set the location counter to the new label. */
754 /* If we have a current label, advance from there, otherwise
755 set the location directly using set_loc. */
756 xcfi->dw_cfi_opc = fde->dw_fde_current_label
757 ? DW_CFA_advance_loc4
759 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
760 add_cfi (&fde->dw_fde_cfi, xcfi);
762 fde->dw_fde_current_label = label;
765 list_head = &fde->dw_fde_cfi;
768 add_cfi (list_head, cfi);
771 /* Subroutine of lookup_cfa. */
774 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
776 switch (cfi->dw_cfi_opc)
778 case DW_CFA_def_cfa_offset:
779 case DW_CFA_def_cfa_offset_sf:
780 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
782 case DW_CFA_def_cfa_register:
783 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
786 case DW_CFA_def_cfa_sf:
787 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
788 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
790 case DW_CFA_def_cfa_expression:
791 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
798 /* Find the previous value for the CFA. */
801 lookup_cfa (dw_cfa_location *loc)
806 loc->reg = INVALID_REGNUM;
809 loc->base_offset = 0;
811 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
812 lookup_cfa_1 (cfi, loc);
814 fde = current_fde ();
816 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
817 lookup_cfa_1 (cfi, loc);
820 /* The current rule for calculating the DWARF2 canonical frame address. */
821 static dw_cfa_location cfa;
823 /* The register used for saving registers to the stack, and its offset
825 static dw_cfa_location cfa_store;
827 /* The running total of the size of arguments pushed onto the stack. */
828 static HOST_WIDE_INT args_size;
830 /* The last args_size we actually output. */
831 static HOST_WIDE_INT old_args_size;
833 /* Entry point to update the canonical frame address (CFA).
834 LABEL is passed to add_fde_cfi. The value of CFA is now to be
835 calculated from REG+OFFSET. */
838 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
845 def_cfa_1 (label, &loc);
848 /* Determine if two dw_cfa_location structures define the same data. */
851 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
853 return (loc1->reg == loc2->reg
854 && loc1->offset == loc2->offset
855 && loc1->indirect == loc2->indirect
856 && (loc1->indirect == 0
857 || loc1->base_offset == loc2->base_offset));
860 /* This routine does the actual work. The CFA is now calculated from
861 the dw_cfa_location structure. */
864 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
867 dw_cfa_location old_cfa, loc;
872 if (cfa_store.reg == loc.reg && loc.indirect == 0)
873 cfa_store.offset = loc.offset;
875 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
876 lookup_cfa (&old_cfa);
878 /* If nothing changed, no need to issue any call frame instructions. */
879 if (cfa_equal_p (&loc, &old_cfa))
884 if (loc.reg == old_cfa.reg && !loc.indirect)
886 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
887 the CFA register did not change but the offset did. The data
888 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
889 in the assembler via the .cfi_def_cfa_offset directive. */
891 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
893 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
894 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
897 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
898 else if (loc.offset == old_cfa.offset
899 && old_cfa.reg != INVALID_REGNUM
902 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
903 indicating the CFA register has changed to <register> but the
904 offset has not changed. */
905 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
906 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
910 else if (loc.indirect == 0)
912 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
913 indicating the CFA register has changed to <register> with
914 the specified offset. The data factoring for DW_CFA_def_cfa_sf
915 happens in output_cfi, or in the assembler via the .cfi_def_cfa
918 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
920 cfi->dw_cfi_opc = DW_CFA_def_cfa;
921 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
922 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
926 /* Construct a DW_CFA_def_cfa_expression instruction to
927 calculate the CFA using a full location expression since no
928 register-offset pair is available. */
929 struct dw_loc_descr_struct *loc_list;
931 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
932 loc_list = build_cfa_loc (&loc, 0);
933 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
936 add_fde_cfi (label, cfi);
939 /* Add the CFI for saving a register. REG is the CFA column number.
940 LABEL is passed to add_fde_cfi.
941 If SREG is -1, the register is saved at OFFSET from the CFA;
942 otherwise it is saved in SREG. */
945 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
947 dw_cfi_ref cfi = new_cfi ();
948 dw_fde_ref fde = current_fde ();
950 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
952 /* When stack is aligned, store REG using DW_CFA_expression with
955 && fde->stack_realign
956 && sreg == INVALID_REGNUM)
958 cfi->dw_cfi_opc = DW_CFA_expression;
959 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
960 cfi->dw_cfi_oprnd1.dw_cfi_loc
961 = build_cfa_aligned_loc (offset, fde->stack_realignment);
963 else if (sreg == INVALID_REGNUM)
966 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
967 else if (reg & ~0x3f)
968 cfi->dw_cfi_opc = DW_CFA_offset_extended;
970 cfi->dw_cfi_opc = DW_CFA_offset;
971 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
973 else if (sreg == reg)
974 cfi->dw_cfi_opc = DW_CFA_same_value;
977 cfi->dw_cfi_opc = DW_CFA_register;
978 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
981 add_fde_cfi (label, cfi);
984 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
985 This CFI tells the unwinder that it needs to restore the window registers
986 from the previous frame's window save area.
988 ??? Perhaps we should note in the CIE where windows are saved (instead of
989 assuming 0(cfa)) and what registers are in the window. */
992 dwarf2out_window_save (const char *label)
994 dw_cfi_ref cfi = new_cfi ();
996 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
997 add_fde_cfi (label, cfi);
1000 /* Add a CFI to update the running total of the size of arguments
1001 pushed onto the stack. */
1004 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1008 if (size == old_args_size)
1011 old_args_size = size;
1014 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1015 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1016 add_fde_cfi (label, cfi);
1019 /* Entry point for saving a register to the stack. REG is the GCC register
1020 number. LABEL and OFFSET are passed to reg_save. */
1023 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1025 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1028 /* Entry point for saving the return address in the stack.
1029 LABEL and OFFSET are passed to reg_save. */
1032 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1034 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1037 /* Entry point for saving the return address in a register.
1038 LABEL and SREG are passed to reg_save. */
1041 dwarf2out_return_reg (const char *label, unsigned int sreg)
1043 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1046 #ifdef DWARF2_UNWIND_INFO
1047 /* Record the initial position of the return address. RTL is
1048 INCOMING_RETURN_ADDR_RTX. */
1051 initial_return_save (rtx rtl)
1053 unsigned int reg = INVALID_REGNUM;
1054 HOST_WIDE_INT offset = 0;
1056 switch (GET_CODE (rtl))
1059 /* RA is in a register. */
1060 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1064 /* RA is on the stack. */
1065 rtl = XEXP (rtl, 0);
1066 switch (GET_CODE (rtl))
1069 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1074 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1075 offset = INTVAL (XEXP (rtl, 1));
1079 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1080 offset = -INTVAL (XEXP (rtl, 1));
1090 /* The return address is at some offset from any value we can
1091 actually load. For instance, on the SPARC it is in %i7+8. Just
1092 ignore the offset for now; it doesn't matter for unwinding frames. */
1093 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1094 initial_return_save (XEXP (rtl, 0));
1101 if (reg != DWARF_FRAME_RETURN_COLUMN)
1102 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1106 /* Given a SET, calculate the amount of stack adjustment it
1109 static HOST_WIDE_INT
1110 stack_adjust_offset (const_rtx pattern)
1112 const_rtx src = SET_SRC (pattern);
1113 const_rtx dest = SET_DEST (pattern);
1114 HOST_WIDE_INT offset = 0;
1117 if (dest == stack_pointer_rtx)
1119 /* (set (reg sp) (plus (reg sp) (const_int))) */
1120 code = GET_CODE (src);
1121 if (! (code == PLUS || code == MINUS)
1122 || XEXP (src, 0) != stack_pointer_rtx
1123 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1126 offset = INTVAL (XEXP (src, 1));
1130 else if (MEM_P (dest))
1132 /* (set (mem (pre_dec (reg sp))) (foo)) */
1133 src = XEXP (dest, 0);
1134 code = GET_CODE (src);
1140 if (XEXP (src, 0) == stack_pointer_rtx)
1142 rtx val = XEXP (XEXP (src, 1), 1);
1143 /* We handle only adjustments by constant amount. */
1144 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1145 && GET_CODE (val) == CONST_INT);
1146 offset = -INTVAL (val);
1153 if (XEXP (src, 0) == stack_pointer_rtx)
1155 offset = GET_MODE_SIZE (GET_MODE (dest));
1162 if (XEXP (src, 0) == stack_pointer_rtx)
1164 offset = -GET_MODE_SIZE (GET_MODE (dest));
1179 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1180 indexed by INSN_UID. */
1182 static HOST_WIDE_INT *barrier_args_size;
1184 /* Helper function for compute_barrier_args_size. Handle one insn. */
1186 static HOST_WIDE_INT
1187 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1188 VEC (rtx, heap) **next)
1190 HOST_WIDE_INT offset = 0;
1193 if (! RTX_FRAME_RELATED_P (insn))
1195 if (prologue_epilogue_contains (insn)
1196 || sibcall_epilogue_contains (insn))
1198 else if (GET_CODE (PATTERN (insn)) == SET)
1199 offset = stack_adjust_offset (PATTERN (insn));
1200 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1201 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1203 /* There may be stack adjustments inside compound insns. Search
1205 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1206 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1207 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1212 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1216 expr = XEXP (expr, 0);
1217 if (GET_CODE (expr) == PARALLEL
1218 || GET_CODE (expr) == SEQUENCE)
1219 for (i = 1; i < XVECLEN (expr, 0); i++)
1221 rtx elem = XVECEXP (expr, 0, i);
1223 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1224 offset += stack_adjust_offset (elem);
1229 #ifndef STACK_GROWS_DOWNWARD
1233 cur_args_size += offset;
1234 if (cur_args_size < 0)
1239 rtx dest = JUMP_LABEL (insn);
1243 if (barrier_args_size [INSN_UID (dest)] < 0)
1245 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1246 VEC_safe_push (rtx, heap, *next, dest);
1251 return cur_args_size;
1254 /* Walk the whole function and compute args_size on BARRIERs. */
1257 compute_barrier_args_size (void)
1259 int max_uid = get_max_uid (), i;
1261 VEC (rtx, heap) *worklist, *next, *tmp;
1263 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1264 for (i = 0; i < max_uid; i++)
1265 barrier_args_size[i] = -1;
1267 worklist = VEC_alloc (rtx, heap, 20);
1268 next = VEC_alloc (rtx, heap, 20);
1269 insn = get_insns ();
1270 barrier_args_size[INSN_UID (insn)] = 0;
1271 VEC_quick_push (rtx, worklist, insn);
1274 while (!VEC_empty (rtx, worklist))
1276 rtx prev, body, first_insn;
1277 HOST_WIDE_INT cur_args_size;
1279 first_insn = insn = VEC_pop (rtx, worklist);
1280 cur_args_size = barrier_args_size[INSN_UID (insn)];
1281 prev = prev_nonnote_insn (insn);
1282 if (prev && BARRIER_P (prev))
1283 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1285 for (; insn; insn = NEXT_INSN (insn))
1287 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1289 if (BARRIER_P (insn))
1294 if (insn == first_insn)
1296 else if (barrier_args_size[INSN_UID (insn)] < 0)
1298 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1303 /* The insns starting with this label have been
1304 already scanned or are in the worklist. */
1309 body = PATTERN (insn);
1310 if (GET_CODE (body) == SEQUENCE)
1312 for (i = 1; i < XVECLEN (body, 0); i++)
1314 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1315 cur_args_size, &next);
1317 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1318 cur_args_size, &next);
1322 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1326 if (VEC_empty (rtx, next))
1329 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1333 VEC_truncate (rtx, next, 0);
1336 VEC_free (rtx, heap, worklist);
1337 VEC_free (rtx, heap, next);
1341 /* Check INSN to see if it looks like a push or a stack adjustment, and
1342 make a note of it if it does. EH uses this information to find out how
1343 much extra space it needs to pop off the stack. */
1346 dwarf2out_stack_adjust (rtx insn, bool after_p)
1348 HOST_WIDE_INT offset;
1352 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1353 with this function. Proper support would require all frame-related
1354 insns to be marked, and to be able to handle saving state around
1355 epilogues textually in the middle of the function. */
1356 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1359 /* If only calls can throw, and we have a frame pointer,
1360 save up adjustments until we see the CALL_INSN. */
1361 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1363 if (CALL_P (insn) && !after_p)
1365 /* Extract the size of the args from the CALL rtx itself. */
1366 insn = PATTERN (insn);
1367 if (GET_CODE (insn) == PARALLEL)
1368 insn = XVECEXP (insn, 0, 0);
1369 if (GET_CODE (insn) == SET)
1370 insn = SET_SRC (insn);
1371 gcc_assert (GET_CODE (insn) == CALL);
1372 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1377 if (CALL_P (insn) && !after_p)
1379 if (!flag_asynchronous_unwind_tables)
1380 dwarf2out_args_size ("", args_size);
1383 else if (BARRIER_P (insn))
1385 /* Don't call compute_barrier_args_size () if the only
1386 BARRIER is at the end of function. */
1387 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1388 compute_barrier_args_size ();
1389 if (barrier_args_size == NULL)
1393 offset = barrier_args_size[INSN_UID (insn)];
1398 offset -= args_size;
1399 #ifndef STACK_GROWS_DOWNWARD
1403 else if (GET_CODE (PATTERN (insn)) == SET)
1404 offset = stack_adjust_offset (PATTERN (insn));
1405 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1406 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1408 /* There may be stack adjustments inside compound insns. Search
1410 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1411 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1412 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1420 label = dwarf2out_cfi_label ();
1421 dwarf2out_args_size_adjust (offset, label);
1424 /* Adjust args_size based on stack adjustment OFFSET. */
1427 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1429 if (cfa.reg == STACK_POINTER_REGNUM)
1430 cfa.offset += offset;
1432 if (cfa_store.reg == STACK_POINTER_REGNUM)
1433 cfa_store.offset += offset;
1435 #ifndef STACK_GROWS_DOWNWARD
1439 args_size += offset;
1443 def_cfa_1 (label, &cfa);
1444 if (flag_asynchronous_unwind_tables)
1445 dwarf2out_args_size (label, args_size);
1450 /* We delay emitting a register save until either (a) we reach the end
1451 of the prologue or (b) the register is clobbered. This clusters
1452 register saves so that there are fewer pc advances. */
1454 struct queued_reg_save GTY(())
1456 struct queued_reg_save *next;
1458 HOST_WIDE_INT cfa_offset;
1462 static GTY(()) struct queued_reg_save *queued_reg_saves;
1464 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1465 struct reg_saved_in_data GTY(()) {
1470 /* A list of registers saved in other registers.
1471 The list intentionally has a small maximum capacity of 4; if your
1472 port needs more than that, you might consider implementing a
1473 more efficient data structure. */
1474 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1475 static GTY(()) size_t num_regs_saved_in_regs;
1477 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1478 static const char *last_reg_save_label;
1480 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1481 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1484 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1486 struct queued_reg_save *q;
1488 /* Duplicates waste space, but it's also necessary to remove them
1489 for correctness, since the queue gets output in reverse
1491 for (q = queued_reg_saves; q != NULL; q = q->next)
1492 if (REGNO (q->reg) == REGNO (reg))
1497 q = GGC_NEW (struct queued_reg_save);
1498 q->next = queued_reg_saves;
1499 queued_reg_saves = q;
1503 q->cfa_offset = offset;
1504 q->saved_reg = sreg;
1506 last_reg_save_label = label;
1509 /* Output all the entries in QUEUED_REG_SAVES. */
1512 flush_queued_reg_saves (void)
1514 struct queued_reg_save *q;
1516 for (q = queued_reg_saves; q; q = q->next)
1519 unsigned int reg, sreg;
1521 for (i = 0; i < num_regs_saved_in_regs; i++)
1522 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1524 if (q->saved_reg && i == num_regs_saved_in_regs)
1526 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1527 num_regs_saved_in_regs++;
1529 if (i != num_regs_saved_in_regs)
1531 regs_saved_in_regs[i].orig_reg = q->reg;
1532 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1535 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1537 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1539 sreg = INVALID_REGNUM;
1540 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1543 queued_reg_saves = NULL;
1544 last_reg_save_label = NULL;
1547 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1548 location for? Or, does it clobber a register which we've previously
1549 said that some other register is saved in, and for which we now
1550 have a new location for? */
1553 clobbers_queued_reg_save (const_rtx insn)
1555 struct queued_reg_save *q;
1557 for (q = queued_reg_saves; q; q = q->next)
1560 if (modified_in_p (q->reg, insn))
1562 for (i = 0; i < num_regs_saved_in_regs; i++)
1563 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1564 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1571 /* Entry point for saving the first register into the second. */
1574 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1577 unsigned int regno, sregno;
1579 for (i = 0; i < num_regs_saved_in_regs; i++)
1580 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1582 if (i == num_regs_saved_in_regs)
1584 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1585 num_regs_saved_in_regs++;
1587 regs_saved_in_regs[i].orig_reg = reg;
1588 regs_saved_in_regs[i].saved_in_reg = sreg;
1590 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1591 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1592 reg_save (label, regno, sregno, 0);
1595 /* What register, if any, is currently saved in REG? */
1598 reg_saved_in (rtx reg)
1600 unsigned int regn = REGNO (reg);
1602 struct queued_reg_save *q;
1604 for (q = queued_reg_saves; q; q = q->next)
1605 if (q->saved_reg && regn == REGNO (q->saved_reg))
1608 for (i = 0; i < num_regs_saved_in_regs; i++)
1609 if (regs_saved_in_regs[i].saved_in_reg
1610 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1611 return regs_saved_in_regs[i].orig_reg;
1617 /* A temporary register holding an integral value used in adjusting SP
1618 or setting up the store_reg. The "offset" field holds the integer
1619 value, not an offset. */
1620 static dw_cfa_location cfa_temp;
1622 /* Record call frame debugging information for an expression EXPR,
1623 which either sets SP or FP (adjusting how we calculate the frame
1624 address) or saves a register to the stack or another register.
1625 LABEL indicates the address of EXPR.
1627 This function encodes a state machine mapping rtxes to actions on
1628 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1629 users need not read the source code.
1631 The High-Level Picture
1633 Changes in the register we use to calculate the CFA: Currently we
1634 assume that if you copy the CFA register into another register, we
1635 should take the other one as the new CFA register; this seems to
1636 work pretty well. If it's wrong for some target, it's simple
1637 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1639 Changes in the register we use for saving registers to the stack:
1640 This is usually SP, but not always. Again, we deduce that if you
1641 copy SP into another register (and SP is not the CFA register),
1642 then the new register is the one we will be using for register
1643 saves. This also seems to work.
1645 Register saves: There's not much guesswork about this one; if
1646 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1647 register save, and the register used to calculate the destination
1648 had better be the one we think we're using for this purpose.
1649 It's also assumed that a copy from a call-saved register to another
1650 register is saving that register if RTX_FRAME_RELATED_P is set on
1651 that instruction. If the copy is from a call-saved register to
1652 the *same* register, that means that the register is now the same
1653 value as in the caller.
1655 Except: If the register being saved is the CFA register, and the
1656 offset is nonzero, we are saving the CFA, so we assume we have to
1657 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1658 the intent is to save the value of SP from the previous frame.
1660 In addition, if a register has previously been saved to a different
1663 Invariants / Summaries of Rules
1665 cfa current rule for calculating the CFA. It usually
1666 consists of a register and an offset.
1667 cfa_store register used by prologue code to save things to the stack
1668 cfa_store.offset is the offset from the value of
1669 cfa_store.reg to the actual CFA
1670 cfa_temp register holding an integral value. cfa_temp.offset
1671 stores the value, which will be used to adjust the
1672 stack pointer. cfa_temp is also used like cfa_store,
1673 to track stores to the stack via fp or a temp reg.
1675 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1676 with cfa.reg as the first operand changes the cfa.reg and its
1677 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1680 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1681 expression yielding a constant. This sets cfa_temp.reg
1682 and cfa_temp.offset.
1684 Rule 5: Create a new register cfa_store used to save items to the
1687 Rules 10-14: Save a register to the stack. Define offset as the
1688 difference of the original location and cfa_store's
1689 location (or cfa_temp's location if cfa_temp is used).
1691 Rules 16-20: If AND operation happens on sp in prologue, we assume
1692 stack is realigned. We will use a group of DW_OP_XXX
1693 expressions to represent the location of the stored
1694 register instead of CFA+offset.
1698 "{a,b}" indicates a choice of a xor b.
1699 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1702 (set <reg1> <reg2>:cfa.reg)
1703 effects: cfa.reg = <reg1>
1704 cfa.offset unchanged
1705 cfa_temp.reg = <reg1>
1706 cfa_temp.offset = cfa.offset
1709 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1710 {<const_int>,<reg>:cfa_temp.reg}))
1711 effects: cfa.reg = sp if fp used
1712 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1713 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1714 if cfa_store.reg==sp
1717 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1718 effects: cfa.reg = fp
1719 cfa_offset += +/- <const_int>
1722 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1723 constraints: <reg1> != fp
1725 effects: cfa.reg = <reg1>
1726 cfa_temp.reg = <reg1>
1727 cfa_temp.offset = cfa.offset
1730 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1731 constraints: <reg1> != fp
1733 effects: cfa_store.reg = <reg1>
1734 cfa_store.offset = cfa.offset - cfa_temp.offset
1737 (set <reg> <const_int>)
1738 effects: cfa_temp.reg = <reg>
1739 cfa_temp.offset = <const_int>
1742 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1743 effects: cfa_temp.reg = <reg1>
1744 cfa_temp.offset |= <const_int>
1747 (set <reg> (high <exp>))
1751 (set <reg> (lo_sum <exp> <const_int>))
1752 effects: cfa_temp.reg = <reg>
1753 cfa_temp.offset = <const_int>
1756 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1757 effects: cfa_store.offset -= <const_int>
1758 cfa.offset = cfa_store.offset if cfa.reg == sp
1760 cfa.base_offset = -cfa_store.offset
1763 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1764 effects: cfa_store.offset += -/+ mode_size(mem)
1765 cfa.offset = cfa_store.offset if cfa.reg == sp
1767 cfa.base_offset = -cfa_store.offset
1770 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1773 effects: cfa.reg = <reg1>
1774 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1777 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1778 effects: cfa.reg = <reg1>
1779 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1782 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1783 effects: cfa.reg = <reg1>
1784 cfa.base_offset = -cfa_temp.offset
1785 cfa_temp.offset -= mode_size(mem)
1788 (set <reg> {unspec, unspec_volatile})
1789 effects: target-dependent
1792 (set sp (and: sp <const_int>))
1793 constraints: cfa_store.reg == sp
1794 effects: current_fde.stack_realign = 1
1795 cfa_store.offset = 0
1796 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1799 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1800 effects: cfa_store.offset += -/+ mode_size(mem)
1803 (set (mem ({pre_inc, pre_dec} sp)) fp)
1804 constraints: fde->stack_realign == 1
1805 effects: cfa_store.offset = 0
1806 cfa.reg != HARD_FRAME_POINTER_REGNUM
1809 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1810 constraints: fde->stack_realign == 1
1812 && cfa.indirect == 0
1813 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1814 effects: Use DW_CFA_def_cfa_expression to define cfa
1815 cfa.reg == fde->drap_reg
1818 (set reg fde->drap_reg)
1819 constraints: fde->vdrap_reg == INVALID_REGNUM
1820 effects: fde->vdrap_reg = reg.
1821 (set mem fde->drap_reg)
1822 constraints: fde->drap_reg_saved == 1
1826 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1828 rtx src, dest, span;
1829 HOST_WIDE_INT offset;
1832 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1833 the PARALLEL independently. The first element is always processed if
1834 it is a SET. This is for backward compatibility. Other elements
1835 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1836 flag is set in them. */
1837 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1840 int limit = XVECLEN (expr, 0);
1843 /* PARALLELs have strict read-modify-write semantics, so we
1844 ought to evaluate every rvalue before changing any lvalue.
1845 It's cumbersome to do that in general, but there's an
1846 easy approximation that is enough for all current users:
1847 handle register saves before register assignments. */
1848 if (GET_CODE (expr) == PARALLEL)
1849 for (par_index = 0; par_index < limit; par_index++)
1851 elem = XVECEXP (expr, 0, par_index);
1852 if (GET_CODE (elem) == SET
1853 && MEM_P (SET_DEST (elem))
1854 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1855 dwarf2out_frame_debug_expr (elem, label);
1858 for (par_index = 0; par_index < limit; par_index++)
1860 elem = XVECEXP (expr, 0, par_index);
1861 if (GET_CODE (elem) == SET
1862 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1863 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1864 dwarf2out_frame_debug_expr (elem, label);
1865 else if (GET_CODE (elem) == SET
1867 && !RTX_FRAME_RELATED_P (elem))
1869 /* Stack adjustment combining might combine some post-prologue
1870 stack adjustment into a prologue stack adjustment. */
1871 HOST_WIDE_INT offset = stack_adjust_offset (elem);
1874 dwarf2out_args_size_adjust (offset, label);
1880 gcc_assert (GET_CODE (expr) == SET);
1882 src = SET_SRC (expr);
1883 dest = SET_DEST (expr);
1887 rtx rsi = reg_saved_in (src);
1892 fde = current_fde ();
1894 if (GET_CODE (src) == REG
1896 && fde->drap_reg == REGNO (src)
1897 && (fde->drap_reg_saved
1898 || GET_CODE (dest) == REG))
1901 /* If we are saving dynamic realign argument pointer to a
1902 register, the destination is virtual dynamic realign
1903 argument pointer. It may be used to access argument. */
1904 if (GET_CODE (dest) == REG)
1906 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
1907 fde->vdrap_reg = REGNO (dest);
1912 switch (GET_CODE (dest))
1915 switch (GET_CODE (src))
1917 /* Setting FP from SP. */
1919 if (cfa.reg == (unsigned) REGNO (src))
1922 /* Update the CFA rule wrt SP or FP. Make sure src is
1923 relative to the current CFA register.
1925 We used to require that dest be either SP or FP, but the
1926 ARM copies SP to a temporary register, and from there to
1927 FP. So we just rely on the backends to only set
1928 RTX_FRAME_RELATED_P on appropriate insns. */
1929 cfa.reg = REGNO (dest);
1930 cfa_temp.reg = cfa.reg;
1931 cfa_temp.offset = cfa.offset;
1935 /* Saving a register in a register. */
1936 gcc_assert (!fixed_regs [REGNO (dest)]
1937 /* For the SPARC and its register window. */
1938 || (DWARF_FRAME_REGNUM (REGNO (src))
1939 == DWARF_FRAME_RETURN_COLUMN));
1941 /* After stack is aligned, we can only save SP in FP
1942 if drap register is used. In this case, we have
1943 to restore stack pointer with the CFA value and we
1944 don't generate this DWARF information. */
1946 && fde->stack_realign
1947 && REGNO (src) == STACK_POINTER_REGNUM)
1948 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
1949 && fde->drap_reg != INVALID_REGNUM
1950 && cfa.reg != REGNO (src));
1952 queue_reg_save (label, src, dest, 0);
1959 if (dest == stack_pointer_rtx)
1963 switch (GET_CODE (XEXP (src, 1)))
1966 offset = INTVAL (XEXP (src, 1));
1969 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1971 offset = cfa_temp.offset;
1977 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1979 /* Restoring SP from FP in the epilogue. */
1980 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1981 cfa.reg = STACK_POINTER_REGNUM;
1983 else if (GET_CODE (src) == LO_SUM)
1984 /* Assume we've set the source reg of the LO_SUM from sp. */
1987 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1989 if (GET_CODE (src) != MINUS)
1991 if (cfa.reg == STACK_POINTER_REGNUM)
1992 cfa.offset += offset;
1993 if (cfa_store.reg == STACK_POINTER_REGNUM)
1994 cfa_store.offset += offset;
1996 else if (dest == hard_frame_pointer_rtx)
1999 /* Either setting the FP from an offset of the SP,
2000 or adjusting the FP */
2001 gcc_assert (frame_pointer_needed);
2003 gcc_assert (REG_P (XEXP (src, 0))
2004 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2005 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2006 offset = INTVAL (XEXP (src, 1));
2007 if (GET_CODE (src) != MINUS)
2009 cfa.offset += offset;
2010 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2014 gcc_assert (GET_CODE (src) != MINUS);
2017 if (REG_P (XEXP (src, 0))
2018 && REGNO (XEXP (src, 0)) == cfa.reg
2019 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2021 /* Setting a temporary CFA register that will be copied
2022 into the FP later on. */
2023 offset = - INTVAL (XEXP (src, 1));
2024 cfa.offset += offset;
2025 cfa.reg = REGNO (dest);
2026 /* Or used to save regs to the stack. */
2027 cfa_temp.reg = cfa.reg;
2028 cfa_temp.offset = cfa.offset;
2032 else if (REG_P (XEXP (src, 0))
2033 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2034 && XEXP (src, 1) == stack_pointer_rtx)
2036 /* Setting a scratch register that we will use instead
2037 of SP for saving registers to the stack. */
2038 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2039 cfa_store.reg = REGNO (dest);
2040 cfa_store.offset = cfa.offset - cfa_temp.offset;
2044 else if (GET_CODE (src) == LO_SUM
2045 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2047 cfa_temp.reg = REGNO (dest);
2048 cfa_temp.offset = INTVAL (XEXP (src, 1));
2057 cfa_temp.reg = REGNO (dest);
2058 cfa_temp.offset = INTVAL (src);
2063 gcc_assert (REG_P (XEXP (src, 0))
2064 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2065 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2067 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2068 cfa_temp.reg = REGNO (dest);
2069 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2072 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2073 which will fill in all of the bits. */
2080 case UNSPEC_VOLATILE:
2081 gcc_assert (targetm.dwarf_handle_frame_unspec);
2082 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2087 /* If this AND operation happens on stack pointer in prologue,
2088 we assume the stack is realigned and we extract the
2090 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2092 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2093 fde->stack_realign = 1;
2094 fde->stack_realignment = INTVAL (XEXP (src, 1));
2095 cfa_store.offset = 0;
2097 if (cfa.reg != STACK_POINTER_REGNUM
2098 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2099 fde->drap_reg = cfa.reg;
2107 def_cfa_1 (label, &cfa);
2112 /* Saving a register to the stack. Make sure dest is relative to the
2114 switch (GET_CODE (XEXP (dest, 0)))
2119 /* We can't handle variable size modifications. */
2120 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2122 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2124 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2125 && cfa_store.reg == STACK_POINTER_REGNUM);
2127 cfa_store.offset += offset;
2128 if (cfa.reg == STACK_POINTER_REGNUM)
2129 cfa.offset = cfa_store.offset;
2131 offset = -cfa_store.offset;
2137 offset = GET_MODE_SIZE (GET_MODE (dest));
2138 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2141 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2142 == STACK_POINTER_REGNUM)
2143 && cfa_store.reg == STACK_POINTER_REGNUM);
2145 cfa_store.offset += offset;
2147 /* Rule 18: If stack is aligned, we will use FP as a
2148 reference to represent the address of the stored
2151 && fde->stack_realign
2152 && src == hard_frame_pointer_rtx)
2154 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2155 cfa_store.offset = 0;
2158 if (cfa.reg == STACK_POINTER_REGNUM)
2159 cfa.offset = cfa_store.offset;
2161 offset = -cfa_store.offset;
2165 /* With an offset. */
2172 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2173 && REG_P (XEXP (XEXP (dest, 0), 0)));
2174 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2175 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2178 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2180 if (cfa_store.reg == (unsigned) regno)
2181 offset -= cfa_store.offset;
2184 gcc_assert (cfa_temp.reg == (unsigned) regno);
2185 offset -= cfa_temp.offset;
2191 /* Without an offset. */
2194 int regno = REGNO (XEXP (dest, 0));
2196 if (cfa_store.reg == (unsigned) regno)
2197 offset = -cfa_store.offset;
2200 gcc_assert (cfa_temp.reg == (unsigned) regno);
2201 offset = -cfa_temp.offset;
2208 gcc_assert (cfa_temp.reg
2209 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2210 offset = -cfa_temp.offset;
2211 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2219 /* If the source operand of this MEM operation is not a
2220 register, basically the source is return address. Here
2221 we only care how much stack grew and we don't save it. */
2225 if (REGNO (src) != STACK_POINTER_REGNUM
2226 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2227 && (unsigned) REGNO (src) == cfa.reg)
2229 /* We're storing the current CFA reg into the stack. */
2231 if (cfa.offset == 0)
2234 /* If stack is aligned, putting CFA reg into stack means
2235 we can no longer use reg + offset to represent CFA.
2236 Here we use DW_CFA_def_cfa_expression instead. The
2237 result of this expression equals to the original CFA
2240 && fde->stack_realign
2241 && cfa.indirect == 0
2242 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2244 dw_cfa_location cfa_exp;
2246 gcc_assert (fde->drap_reg == cfa.reg);
2248 cfa_exp.indirect = 1;
2249 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2250 cfa_exp.base_offset = offset;
2253 fde->drap_reg_saved = 1;
2255 def_cfa_1 (label, &cfa_exp);
2259 /* If the source register is exactly the CFA, assume
2260 we're saving SP like any other register; this happens
2262 def_cfa_1 (label, &cfa);
2263 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2268 /* Otherwise, we'll need to look in the stack to
2269 calculate the CFA. */
2270 rtx x = XEXP (dest, 0);
2274 gcc_assert (REG_P (x));
2276 cfa.reg = REGNO (x);
2277 cfa.base_offset = offset;
2279 def_cfa_1 (label, &cfa);
2284 def_cfa_1 (label, &cfa);
2286 span = targetm.dwarf_register_span (src);
2289 queue_reg_save (label, src, NULL_RTX, offset);
2292 /* We have a PARALLEL describing where the contents of SRC
2293 live. Queue register saves for each piece of the
2297 HOST_WIDE_INT span_offset = offset;
2299 gcc_assert (GET_CODE (span) == PARALLEL);
2301 limit = XVECLEN (span, 0);
2302 for (par_index = 0; par_index < limit; par_index++)
2304 rtx elem = XVECEXP (span, 0, par_index);
2306 queue_reg_save (label, elem, NULL_RTX, span_offset);
2307 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2318 /* Record call frame debugging information for INSN, which either
2319 sets SP or FP (adjusting how we calculate the frame address) or saves a
2320 register to the stack. If INSN is NULL_RTX, initialize our state.
2322 If AFTER_P is false, we're being called before the insn is emitted,
2323 otherwise after. Call instructions get invoked twice. */
2326 dwarf2out_frame_debug (rtx insn, bool after_p)
2331 if (insn == NULL_RTX)
2335 /* Flush any queued register saves. */
2336 flush_queued_reg_saves ();
2338 /* Set up state for generating call frame debug info. */
2341 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2343 cfa.reg = STACK_POINTER_REGNUM;
2346 cfa_temp.offset = 0;
2348 for (i = 0; i < num_regs_saved_in_regs; i++)
2350 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2351 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2353 num_regs_saved_in_regs = 0;
2355 if (barrier_args_size)
2357 XDELETEVEC (barrier_args_size);
2358 barrier_args_size = NULL;
2363 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2364 flush_queued_reg_saves ();
2366 if (! RTX_FRAME_RELATED_P (insn))
2368 if (!ACCUMULATE_OUTGOING_ARGS)
2369 dwarf2out_stack_adjust (insn, after_p);
2373 label = dwarf2out_cfi_label ();
2374 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2376 insn = XEXP (src, 0);
2378 insn = PATTERN (insn);
2380 dwarf2out_frame_debug_expr (insn, label);
2385 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2386 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2387 (enum dwarf_call_frame_info cfi);
2389 static enum dw_cfi_oprnd_type
2390 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2395 case DW_CFA_GNU_window_save:
2396 return dw_cfi_oprnd_unused;
2398 case DW_CFA_set_loc:
2399 case DW_CFA_advance_loc1:
2400 case DW_CFA_advance_loc2:
2401 case DW_CFA_advance_loc4:
2402 case DW_CFA_MIPS_advance_loc8:
2403 return dw_cfi_oprnd_addr;
2406 case DW_CFA_offset_extended:
2407 case DW_CFA_def_cfa:
2408 case DW_CFA_offset_extended_sf:
2409 case DW_CFA_def_cfa_sf:
2410 case DW_CFA_restore_extended:
2411 case DW_CFA_undefined:
2412 case DW_CFA_same_value:
2413 case DW_CFA_def_cfa_register:
2414 case DW_CFA_register:
2415 return dw_cfi_oprnd_reg_num;
2417 case DW_CFA_def_cfa_offset:
2418 case DW_CFA_GNU_args_size:
2419 case DW_CFA_def_cfa_offset_sf:
2420 return dw_cfi_oprnd_offset;
2422 case DW_CFA_def_cfa_expression:
2423 case DW_CFA_expression:
2424 return dw_cfi_oprnd_loc;
2431 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2432 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2433 (enum dwarf_call_frame_info cfi);
2435 static enum dw_cfi_oprnd_type
2436 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2440 case DW_CFA_def_cfa:
2441 case DW_CFA_def_cfa_sf:
2443 case DW_CFA_offset_extended_sf:
2444 case DW_CFA_offset_extended:
2445 return dw_cfi_oprnd_offset;
2447 case DW_CFA_register:
2448 return dw_cfi_oprnd_reg_num;
2451 return dw_cfi_oprnd_unused;
2455 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2457 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2458 switch to the data section instead, and write out a synthetic label
2462 switch_to_eh_frame_section (void)
2466 #ifdef EH_FRAME_SECTION_NAME
2467 if (eh_frame_section == 0)
2471 if (EH_TABLES_CAN_BE_READ_ONLY)
2477 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2479 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2481 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2483 flags = ((! flag_pic
2484 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2485 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2486 && (per_encoding & 0x70) != DW_EH_PE_absptr
2487 && (per_encoding & 0x70) != DW_EH_PE_aligned
2488 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2489 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2490 ? 0 : SECTION_WRITE);
2493 flags = SECTION_WRITE;
2494 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2498 if (eh_frame_section)
2499 switch_to_section (eh_frame_section);
2502 /* We have no special eh_frame section. Put the information in
2503 the data section and emit special labels to guide collect2. */
2504 switch_to_section (data_section);
2505 label = get_file_function_name ("F");
2506 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2507 targetm.asm_out.globalize_label (asm_out_file,
2508 IDENTIFIER_POINTER (label));
2509 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2513 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2515 static HOST_WIDE_INT
2516 div_data_align (HOST_WIDE_INT off)
2518 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
2519 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
2523 /* Output a Call Frame Information opcode and its operand(s). */
2526 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2531 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2532 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2533 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2534 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2535 ((unsigned HOST_WIDE_INT)
2536 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2537 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2539 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2540 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2541 "DW_CFA_offset, column 0x%lx", r);
2542 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2543 dw2_asm_output_data_uleb128 (off, NULL);
2545 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2547 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2548 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2549 "DW_CFA_restore, column 0x%lx", r);
2553 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2554 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2556 switch (cfi->dw_cfi_opc)
2558 case DW_CFA_set_loc:
2560 dw2_asm_output_encoded_addr_rtx (
2561 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2562 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2565 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2566 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2567 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2570 case DW_CFA_advance_loc1:
2571 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2572 fde->dw_fde_current_label, NULL);
2573 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2576 case DW_CFA_advance_loc2:
2577 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2578 fde->dw_fde_current_label, NULL);
2579 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2582 case DW_CFA_advance_loc4:
2583 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2584 fde->dw_fde_current_label, NULL);
2585 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2588 case DW_CFA_MIPS_advance_loc8:
2589 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2590 fde->dw_fde_current_label, NULL);
2591 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2594 case DW_CFA_offset_extended:
2595 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2596 dw2_asm_output_data_uleb128 (r, NULL);
2597 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2598 dw2_asm_output_data_uleb128 (off, NULL);
2601 case DW_CFA_def_cfa:
2602 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2603 dw2_asm_output_data_uleb128 (r, NULL);
2604 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2607 case DW_CFA_offset_extended_sf:
2608 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2609 dw2_asm_output_data_uleb128 (r, NULL);
2610 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2611 dw2_asm_output_data_sleb128 (off, NULL);
2614 case DW_CFA_def_cfa_sf:
2615 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2616 dw2_asm_output_data_uleb128 (r, NULL);
2617 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2618 dw2_asm_output_data_sleb128 (off, NULL);
2621 case DW_CFA_restore_extended:
2622 case DW_CFA_undefined:
2623 case DW_CFA_same_value:
2624 case DW_CFA_def_cfa_register:
2625 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2626 dw2_asm_output_data_uleb128 (r, NULL);
2629 case DW_CFA_register:
2630 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2631 dw2_asm_output_data_uleb128 (r, NULL);
2632 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2633 dw2_asm_output_data_uleb128 (r, NULL);
2636 case DW_CFA_def_cfa_offset:
2637 case DW_CFA_GNU_args_size:
2638 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2641 case DW_CFA_def_cfa_offset_sf:
2642 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2643 dw2_asm_output_data_sleb128 (off, NULL);
2646 case DW_CFA_GNU_window_save:
2649 case DW_CFA_def_cfa_expression:
2650 case DW_CFA_expression:
2651 output_cfa_loc (cfi);
2654 case DW_CFA_GNU_negative_offset_extended:
2655 /* Obsoleted by DW_CFA_offset_extended_sf. */
2664 /* Similar, but do it via assembler directives instead. */
2667 output_cfi_directive (dw_cfi_ref cfi)
2669 unsigned long r, r2;
2671 switch (cfi->dw_cfi_opc)
2673 case DW_CFA_advance_loc:
2674 case DW_CFA_advance_loc1:
2675 case DW_CFA_advance_loc2:
2676 case DW_CFA_advance_loc4:
2677 case DW_CFA_MIPS_advance_loc8:
2678 case DW_CFA_set_loc:
2679 /* Should only be created by add_fde_cfi in a code path not
2680 followed when emitting via directives. The assembler is
2681 going to take care of this for us. */
2685 case DW_CFA_offset_extended:
2686 case DW_CFA_offset_extended_sf:
2687 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2688 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2689 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2692 case DW_CFA_restore:
2693 case DW_CFA_restore_extended:
2694 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2695 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
2698 case DW_CFA_undefined:
2699 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2700 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
2703 case DW_CFA_same_value:
2704 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2705 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
2708 case DW_CFA_def_cfa:
2709 case DW_CFA_def_cfa_sf:
2710 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2711 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2712 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2715 case DW_CFA_def_cfa_register:
2716 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2717 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
2720 case DW_CFA_register:
2721 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2722 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 0);
2723 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
2726 case DW_CFA_def_cfa_offset:
2727 case DW_CFA_def_cfa_offset_sf:
2728 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
2729 HOST_WIDE_INT_PRINT_DEC"\n",
2730 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2733 case DW_CFA_GNU_args_size:
2734 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
2735 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2737 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
2738 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
2739 fputc ('\n', asm_out_file);
2742 case DW_CFA_GNU_window_save:
2743 fprintf (asm_out_file, "\t.cfi_window_save\n");
2746 case DW_CFA_def_cfa_expression:
2747 case DW_CFA_expression:
2748 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
2749 output_cfa_loc_raw (cfi);
2750 fputc ('\n', asm_out_file);
2758 /* Output the call frame information used to record information
2759 that relates to calculating the frame pointer, and records the
2760 location of saved registers. */
2763 output_call_frame_info (int for_eh)
2768 char l1[20], l2[20], section_start_label[20];
2769 bool any_lsda_needed = false;
2770 char augmentation[6];
2771 int augmentation_size;
2772 int fde_encoding = DW_EH_PE_absptr;
2773 int per_encoding = DW_EH_PE_absptr;
2774 int lsda_encoding = DW_EH_PE_absptr;
2777 /* Don't emit a CIE if there won't be any FDEs. */
2778 if (fde_table_in_use == 0)
2781 /* Nothing to do if the assembler's doing it all. */
2782 if (dwarf2out_do_cfi_asm ())
2785 /* If we make FDEs linkonce, we may have to emit an empty label for
2786 an FDE that wouldn't otherwise be emitted. We want to avoid
2787 having an FDE kept around when the function it refers to is
2788 discarded. Example where this matters: a primary function
2789 template in C++ requires EH information, but an explicit
2790 specialization doesn't. */
2791 if (TARGET_USES_WEAK_UNWIND_INFO
2792 && ! flag_asynchronous_unwind_tables
2795 for (i = 0; i < fde_table_in_use; i++)
2796 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2797 && !fde_table[i].uses_eh_lsda
2798 && ! DECL_WEAK (fde_table[i].decl))
2799 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2800 for_eh, /* empty */ 1);
2802 /* If we don't have any functions we'll want to unwind out of, don't
2803 emit any EH unwind information. Note that if exceptions aren't
2804 enabled, we won't have collected nothrow information, and if we
2805 asked for asynchronous tables, we always want this info. */
2808 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2810 for (i = 0; i < fde_table_in_use; i++)
2811 if (fde_table[i].uses_eh_lsda)
2812 any_eh_needed = any_lsda_needed = true;
2813 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2814 any_eh_needed = true;
2815 else if (! fde_table[i].nothrow
2816 && ! fde_table[i].all_throwers_are_sibcalls)
2817 any_eh_needed = true;
2819 if (! any_eh_needed)
2823 /* We're going to be generating comments, so turn on app. */
2828 switch_to_eh_frame_section ();
2831 if (!debug_frame_section)
2832 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2833 SECTION_DEBUG, NULL);
2834 switch_to_section (debug_frame_section);
2837 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2838 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2840 /* Output the CIE. */
2841 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2842 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2843 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2844 dw2_asm_output_data (4, 0xffffffff,
2845 "Initial length escape value indicating 64-bit DWARF extension");
2846 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2847 "Length of Common Information Entry");
2848 ASM_OUTPUT_LABEL (asm_out_file, l1);
2850 /* Now that the CIE pointer is PC-relative for EH,
2851 use 0 to identify the CIE. */
2852 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2853 (for_eh ? 0 : DWARF_CIE_ID),
2854 "CIE Identifier Tag");
2856 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2858 augmentation[0] = 0;
2859 augmentation_size = 0;
2865 z Indicates that a uleb128 is present to size the
2866 augmentation section.
2867 L Indicates the encoding (and thus presence) of
2868 an LSDA pointer in the FDE augmentation.
2869 R Indicates a non-default pointer encoding for
2871 P Indicates the presence of an encoding + language
2872 personality routine in the CIE augmentation. */
2874 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2875 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2876 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2878 p = augmentation + 1;
2879 if (eh_personality_libfunc)
2882 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2883 assemble_external_libcall (eh_personality_libfunc);
2885 if (any_lsda_needed)
2888 augmentation_size += 1;
2890 if (fde_encoding != DW_EH_PE_absptr)
2893 augmentation_size += 1;
2895 if (p > augmentation + 1)
2897 augmentation[0] = 'z';
2901 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2902 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2904 int offset = ( 4 /* Length */
2906 + 1 /* CIE version */
2907 + strlen (augmentation) + 1 /* Augmentation */
2908 + size_of_uleb128 (1) /* Code alignment */
2909 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2911 + 1 /* Augmentation size */
2912 + 1 /* Personality encoding */ );
2913 int pad = -offset & (PTR_SIZE - 1);
2915 augmentation_size += pad;
2917 /* Augmentations should be small, so there's scarce need to
2918 iterate for a solution. Die if we exceed one uleb128 byte. */
2919 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2923 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2924 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2925 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2926 "CIE Data Alignment Factor");
2928 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2929 if (DW_CIE_VERSION == 1)
2930 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2932 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2934 if (augmentation[0])
2936 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2937 if (eh_personality_libfunc)
2939 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2940 eh_data_format_name (per_encoding));
2941 dw2_asm_output_encoded_addr_rtx (per_encoding,
2942 eh_personality_libfunc,
2946 if (any_lsda_needed)
2947 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2948 eh_data_format_name (lsda_encoding));
2950 if (fde_encoding != DW_EH_PE_absptr)
2951 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2952 eh_data_format_name (fde_encoding));
2955 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2956 output_cfi (cfi, NULL, for_eh);
2958 /* Pad the CIE out to an address sized boundary. */
2959 ASM_OUTPUT_ALIGN (asm_out_file,
2960 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2961 ASM_OUTPUT_LABEL (asm_out_file, l2);
2963 /* Loop through all of the FDE's. */
2964 for (i = 0; i < fde_table_in_use; i++)
2966 fde = &fde_table[i];
2968 /* Don't emit EH unwind info for leaf functions that don't need it. */
2969 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2970 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2971 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2972 && !fde->uses_eh_lsda)
2975 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2976 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2977 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2978 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2979 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2980 dw2_asm_output_data (4, 0xffffffff,
2981 "Initial length escape value indicating 64-bit DWARF extension");
2982 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2984 ASM_OUTPUT_LABEL (asm_out_file, l1);
2987 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2989 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2990 debug_frame_section, "FDE CIE offset");
2994 if (fde->dw_fde_switched_sections)
2996 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2997 fde->dw_fde_unlikely_section_label);
2998 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2999 fde->dw_fde_hot_section_label);
3000 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3001 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3002 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3003 "FDE initial location");
3004 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3005 fde->dw_fde_hot_section_end_label,
3006 fde->dw_fde_hot_section_label,
3007 "FDE address range");
3008 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3009 "FDE initial location");
3010 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3011 fde->dw_fde_unlikely_section_end_label,
3012 fde->dw_fde_unlikely_section_label,
3013 "FDE address range");
3017 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3018 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3019 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3022 "FDE initial location");
3023 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3024 fde->dw_fde_end, fde->dw_fde_begin,
3025 "FDE address range");
3030 if (fde->dw_fde_switched_sections)
3032 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3033 fde->dw_fde_hot_section_label,
3034 "FDE initial location");
3035 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3036 fde->dw_fde_hot_section_end_label,
3037 fde->dw_fde_hot_section_label,
3038 "FDE address range");
3039 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3040 fde->dw_fde_unlikely_section_label,
3041 "FDE initial location");
3042 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3043 fde->dw_fde_unlikely_section_end_label,
3044 fde->dw_fde_unlikely_section_label,
3045 "FDE address range");
3049 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3050 "FDE initial location");
3051 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3052 fde->dw_fde_end, fde->dw_fde_begin,
3053 "FDE address range");
3057 if (augmentation[0])
3059 if (any_lsda_needed)
3061 int size = size_of_encoded_value (lsda_encoding);
3063 if (lsda_encoding == DW_EH_PE_aligned)
3065 int offset = ( 4 /* Length */
3066 + 4 /* CIE offset */
3067 + 2 * size_of_encoded_value (fde_encoding)
3068 + 1 /* Augmentation size */ );
3069 int pad = -offset & (PTR_SIZE - 1);
3072 gcc_assert (size_of_uleb128 (size) == 1);
3075 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3077 if (fde->uses_eh_lsda)
3079 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3080 fde->funcdef_number);
3081 dw2_asm_output_encoded_addr_rtx (
3082 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3083 false, "Language Specific Data Area");
3087 if (lsda_encoding == DW_EH_PE_aligned)
3088 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3090 (size_of_encoded_value (lsda_encoding), 0,
3091 "Language Specific Data Area (none)");
3095 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3098 /* Loop through the Call Frame Instructions associated with
3100 fde->dw_fde_current_label = fde->dw_fde_begin;
3101 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3102 output_cfi (cfi, fde, for_eh);
3104 /* Pad the FDE out to an address sized boundary. */
3105 ASM_OUTPUT_ALIGN (asm_out_file,
3106 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3107 ASM_OUTPUT_LABEL (asm_out_file, l2);
3110 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3111 dw2_asm_output_data (4, 0, "End of Table");
3112 #ifdef MIPS_DEBUGGING_INFO
3113 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3114 get a value of 0. Putting .align 0 after the label fixes it. */
3115 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3118 /* Turn off app to make assembly quicker. */
3123 /* Output a marker (i.e. a label) for the beginning of a function, before
3127 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3128 const char *file ATTRIBUTE_UNUSED)
3130 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3134 current_function_func_begin_label = NULL;
3136 #ifdef TARGET_UNWIND_INFO
3137 /* ??? current_function_func_begin_label is also used by except.c
3138 for call-site information. We must emit this label if it might
3140 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3141 && ! dwarf2out_do_frame ())
3144 if (! dwarf2out_do_frame ())
3148 switch_to_section (function_section (current_function_decl));
3149 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3150 current_function_funcdef_no);
3151 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3152 current_function_funcdef_no);
3153 dup_label = xstrdup (label);
3154 current_function_func_begin_label = dup_label;
3156 #ifdef TARGET_UNWIND_INFO
3157 /* We can elide the fde allocation if we're not emitting debug info. */
3158 if (! dwarf2out_do_frame ())
3162 /* Expand the fde table if necessary. */
3163 if (fde_table_in_use == fde_table_allocated)
3165 fde_table_allocated += FDE_TABLE_INCREMENT;
3166 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3167 memset (fde_table + fde_table_in_use, 0,
3168 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3171 /* Record the FDE associated with this function. */
3172 current_funcdef_fde = fde_table_in_use;
3174 /* Add the new FDE at the end of the fde_table. */
3175 fde = &fde_table[fde_table_in_use++];
3176 fde->decl = current_function_decl;
3177 fde->dw_fde_begin = dup_label;
3178 fde->dw_fde_current_label = dup_label;
3179 fde->dw_fde_hot_section_label = NULL;
3180 fde->dw_fde_hot_section_end_label = NULL;
3181 fde->dw_fde_unlikely_section_label = NULL;
3182 fde->dw_fde_unlikely_section_end_label = NULL;
3183 fde->dw_fde_switched_sections = false;
3184 fde->dw_fde_end = NULL;
3185 fde->dw_fde_cfi = NULL;
3186 fde->funcdef_number = current_function_funcdef_no;
3187 fde->nothrow = TREE_NOTHROW (current_function_decl);
3188 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3189 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3190 fde->drap_reg = INVALID_REGNUM;
3191 fde->vdrap_reg = INVALID_REGNUM;
3193 args_size = old_args_size = 0;
3195 /* We only want to output line number information for the genuine dwarf2
3196 prologue case, not the eh frame case. */
3197 #ifdef DWARF2_DEBUGGING_INFO
3199 dwarf2out_source_line (line, file);
3202 if (dwarf2out_do_cfi_asm ())
3207 fprintf (asm_out_file, "\t.cfi_startproc\n");
3209 if (eh_personality_libfunc)
3211 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3212 ref = eh_personality_libfunc;
3214 /* ??? The GAS support isn't entirely consistent. We have to
3215 handle indirect support ourselves, but PC-relative is done
3216 in the assembler. Further, the assembler can't handle any
3217 of the weirder relocation types. */
3218 if (enc & DW_EH_PE_indirect)
3219 ref = dw2_force_const_mem (ref, true);
3221 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3222 output_addr_const (asm_out_file, ref);
3223 fputc ('\n', asm_out_file);
3226 if (crtl->uses_eh_lsda)
3230 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3231 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3232 current_function_funcdef_no);
3233 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3234 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3236 if (enc & DW_EH_PE_indirect)
3237 ref = dw2_force_const_mem (ref, true);
3239 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3240 output_addr_const (asm_out_file, ref);
3241 fputc ('\n', asm_out_file);
3246 /* Output a marker (i.e. a label) for the absolute end of the generated code
3247 for a function definition. This gets called *after* the epilogue code has
3251 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3252 const char *file ATTRIBUTE_UNUSED)
3255 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3257 if (dwarf2out_do_cfi_asm ())
3258 fprintf (asm_out_file, "\t.cfi_endproc\n");
3260 /* Output a label to mark the endpoint of the code generated for this
3262 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3263 current_function_funcdef_no);
3264 ASM_OUTPUT_LABEL (asm_out_file, label);
3265 fde = current_fde ();
3266 gcc_assert (fde != NULL);
3267 fde->dw_fde_end = xstrdup (label);
3271 dwarf2out_frame_init (void)
3273 /* Allocate the initial hunk of the fde_table. */
3274 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3275 fde_table_allocated = FDE_TABLE_INCREMENT;
3276 fde_table_in_use = 0;
3278 /* Generate the CFA instructions common to all FDE's. Do it now for the
3279 sake of lookup_cfa. */
3281 /* On entry, the Canonical Frame Address is at SP. */
3282 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3284 #ifdef DWARF2_UNWIND_INFO
3285 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3286 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3291 dwarf2out_frame_finish (void)
3293 /* Output call frame information. */
3294 if (DWARF2_FRAME_INFO)
3295 output_call_frame_info (0);
3297 #ifndef TARGET_UNWIND_INFO
3298 /* Output another copy for the unwinder. */
3299 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3300 output_call_frame_info (1);
3304 /* Note that the current function section is being used for code. */
3307 dwarf2out_note_section_used (void)
3309 section *sec = current_function_section ();
3310 if (sec == text_section)
3311 text_section_used = true;
3312 else if (sec == cold_text_section)
3313 cold_text_section_used = true;
3317 dwarf2out_switch_text_section (void)
3319 dw_fde_ref fde = current_fde ();
3321 gcc_assert (cfun && fde);
3323 fde->dw_fde_switched_sections = true;
3324 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3325 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3326 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3327 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3328 have_multiple_function_sections = true;
3330 /* Reset the current label on switching text sections, so that we
3331 don't attempt to advance_loc4 between labels in different sections. */
3332 fde->dw_fde_current_label = NULL;
3334 /* There is no need to mark used sections when not debugging. */
3335 if (cold_text_section != NULL)
3336 dwarf2out_note_section_used ();
3340 /* And now, the subset of the debugging information support code necessary
3341 for emitting location expressions. */
3343 /* Data about a single source file. */
3344 struct dwarf_file_data GTY(())
3346 const char * filename;
3350 /* We need some way to distinguish DW_OP_addr with a direct symbol
3351 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3352 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3355 typedef struct dw_val_struct *dw_val_ref;
3356 typedef struct die_struct *dw_die_ref;
3357 typedef const struct die_struct *const_dw_die_ref;
3358 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3359 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3361 /* Each DIE may have a series of attribute/value pairs. Values
3362 can take on several forms. The forms that are used in this
3363 implementation are listed below. */
3368 dw_val_class_offset,
3370 dw_val_class_loc_list,
3371 dw_val_class_range_list,
3373 dw_val_class_unsigned_const,
3374 dw_val_class_long_long,
3377 dw_val_class_die_ref,
3378 dw_val_class_fde_ref,
3379 dw_val_class_lbl_id,
3380 dw_val_class_lineptr,
3382 dw_val_class_macptr,
3386 /* Describe a double word constant value. */
3387 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3389 typedef struct dw_long_long_struct GTY(())
3396 /* Describe a floating point constant value, or a vector constant value. */
3398 typedef struct dw_vec_struct GTY(())
3400 unsigned char * GTY((length ("%h.length"))) array;
3406 /* The dw_val_node describes an attribute's value, as it is
3407 represented internally. */
3409 typedef struct dw_val_struct GTY(())
3411 enum dw_val_class val_class;
3412 union dw_val_struct_union
3414 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3415 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3416 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3417 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3418 HOST_WIDE_INT GTY ((default)) val_int;
3419 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3420 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3421 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3422 struct dw_val_die_union
3426 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3427 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3428 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3429 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3430 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3431 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3433 GTY ((desc ("%1.val_class"))) v;
3437 /* Locations in memory are described using a sequence of stack machine
3440 typedef struct dw_loc_descr_struct GTY(())
3442 dw_loc_descr_ref dw_loc_next;
3443 enum dwarf_location_atom dw_loc_opc;
3444 dw_val_node dw_loc_oprnd1;
3445 dw_val_node dw_loc_oprnd2;
3450 /* Location lists are ranges + location descriptions for that range,
3451 so you can track variables that are in different places over
3452 their entire life. */
3453 typedef struct dw_loc_list_struct GTY(())
3455 dw_loc_list_ref dw_loc_next;
3456 const char *begin; /* Label for begin address of range */
3457 const char *end; /* Label for end address of range */
3458 char *ll_symbol; /* Label for beginning of location list.
3459 Only on head of list */
3460 const char *section; /* Section this loclist is relative to */
3461 dw_loc_descr_ref expr;
3464 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3466 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3468 /* Convert a DWARF stack opcode into its string name. */
3471 dwarf_stack_op_name (unsigned int op)
3476 case INTERNAL_DW_OP_tls_addr:
3477 return "DW_OP_addr";
3479 return "DW_OP_deref";
3481 return "DW_OP_const1u";
3483 return "DW_OP_const1s";
3485 return "DW_OP_const2u";
3487 return "DW_OP_const2s";
3489 return "DW_OP_const4u";
3491 return "DW_OP_const4s";
3493 return "DW_OP_const8u";
3495 return "DW_OP_const8s";
3497 return "DW_OP_constu";
3499 return "DW_OP_consts";
3503 return "DW_OP_drop";
3505 return "DW_OP_over";
3507 return "DW_OP_pick";
3509 return "DW_OP_swap";
3513 return "DW_OP_xderef";
3521 return "DW_OP_minus";
3533 return "DW_OP_plus";
3534 case DW_OP_plus_uconst:
3535 return "DW_OP_plus_uconst";
3541 return "DW_OP_shra";
3559 return "DW_OP_skip";
3561 return "DW_OP_lit0";
3563 return "DW_OP_lit1";
3565 return "DW_OP_lit2";
3567 return "DW_OP_lit3";
3569 return "DW_OP_lit4";
3571 return "DW_OP_lit5";
3573 return "DW_OP_lit6";
3575 return "DW_OP_lit7";
3577 return "DW_OP_lit8";
3579 return "DW_OP_lit9";
3581 return "DW_OP_lit10";
3583 return "DW_OP_lit11";
3585 return "DW_OP_lit12";
3587 return "DW_OP_lit13";
3589 return "DW_OP_lit14";
3591 return "DW_OP_lit15";
3593 return "DW_OP_lit16";
3595 return "DW_OP_lit17";
3597 return "DW_OP_lit18";
3599 return "DW_OP_lit19";
3601 return "DW_OP_lit20";
3603 return "DW_OP_lit21";
3605 return "DW_OP_lit22";
3607 return "DW_OP_lit23";
3609 return "DW_OP_lit24";
3611 return "DW_OP_lit25";
3613 return "DW_OP_lit26";
3615 return "DW_OP_lit27";
3617 return "DW_OP_lit28";
3619 return "DW_OP_lit29";
3621 return "DW_OP_lit30";
3623 return "DW_OP_lit31";
3625 return "DW_OP_reg0";
3627 return "DW_OP_reg1";
3629 return "DW_OP_reg2";
3631 return "DW_OP_reg3";
3633 return "DW_OP_reg4";
3635 return "DW_OP_reg5";
3637 return "DW_OP_reg6";
3639 return "DW_OP_reg7";
3641 return "DW_OP_reg8";
3643 return "DW_OP_reg9";
3645 return "DW_OP_reg10";
3647 return "DW_OP_reg11";
3649 return "DW_OP_reg12";
3651 return "DW_OP_reg13";
3653 return "DW_OP_reg14";
3655 return "DW_OP_reg15";
3657 return "DW_OP_reg16";
3659 return "DW_OP_reg17";
3661 return "DW_OP_reg18";
3663 return "DW_OP_reg19";
3665 return "DW_OP_reg20";
3667 return "DW_OP_reg21";
3669 return "DW_OP_reg22";
3671 return "DW_OP_reg23";
3673 return "DW_OP_reg24";
3675 return "DW_OP_reg25";
3677 return "DW_OP_reg26";
3679 return "DW_OP_reg27";
3681 return "DW_OP_reg28";
3683 return "DW_OP_reg29";
3685 return "DW_OP_reg30";
3687 return "DW_OP_reg31";
3689 return "DW_OP_breg0";
3691 return "DW_OP_breg1";
3693 return "DW_OP_breg2";
3695 return "DW_OP_breg3";
3697 return "DW_OP_breg4";
3699 return "DW_OP_breg5";
3701 return "DW_OP_breg6";
3703 return "DW_OP_breg7";
3705 return "DW_OP_breg8";
3707 return "DW_OP_breg9";
3709 return "DW_OP_breg10";
3711 return "DW_OP_breg11";
3713 return "DW_OP_breg12";
3715 return "DW_OP_breg13";
3717 return "DW_OP_breg14";
3719 return "DW_OP_breg15";
3721 return "DW_OP_breg16";
3723 return "DW_OP_breg17";
3725 return "DW_OP_breg18";
3727 return "DW_OP_breg19";
3729 return "DW_OP_breg20";
3731 return "DW_OP_breg21";
3733 return "DW_OP_breg22";
3735 return "DW_OP_breg23";
3737 return "DW_OP_breg24";
3739 return "DW_OP_breg25";
3741 return "DW_OP_breg26";
3743 return "DW_OP_breg27";
3745 return "DW_OP_breg28";
3747 return "DW_OP_breg29";
3749 return "DW_OP_breg30";
3751 return "DW_OP_breg31";
3753 return "DW_OP_regx";
3755 return "DW_OP_fbreg";
3757 return "DW_OP_bregx";
3759 return "DW_OP_piece";
3760 case DW_OP_deref_size:
3761 return "DW_OP_deref_size";
3762 case DW_OP_xderef_size:
3763 return "DW_OP_xderef_size";
3766 case DW_OP_push_object_address:
3767 return "DW_OP_push_object_address";
3769 return "DW_OP_call2";
3771 return "DW_OP_call4";
3772 case DW_OP_call_ref:
3773 return "DW_OP_call_ref";
3774 case DW_OP_GNU_push_tls_address:
3775 return "DW_OP_GNU_push_tls_address";
3776 case DW_OP_GNU_uninit:
3777 return "DW_OP_GNU_uninit";
3779 return "OP_<unknown>";
3783 /* Return a pointer to a newly allocated location description. Location
3784 descriptions are simple expression terms that can be strung
3785 together to form more complicated location (address) descriptions. */
3787 static inline dw_loc_descr_ref
3788 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3789 unsigned HOST_WIDE_INT oprnd2)
3791 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3793 descr->dw_loc_opc = op;
3794 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3795 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3796 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3797 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3802 /* Return a pointer to a newly allocated location description for
3805 static inline dw_loc_descr_ref
3806 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
3811 return new_loc_descr (DW_OP_breg0 + reg, offset, 0);
3813 return new_loc_descr (DW_OP_bregx, reg, offset);
3816 return new_loc_descr (DW_OP_reg0 + reg, 0, 0);
3818 return new_loc_descr (DW_OP_regx, reg, 0);
3821 /* Add a location description term to a location description expression. */
3824 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3826 dw_loc_descr_ref *d;
3828 /* Find the end of the chain. */
3829 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3835 /* Return the size of a location descriptor. */
3837 static unsigned long
3838 size_of_loc_descr (dw_loc_descr_ref loc)
3840 unsigned long size = 1;
3842 switch (loc->dw_loc_opc)
3845 case INTERNAL_DW_OP_tls_addr:
3846 size += DWARF2_ADDR_SIZE;
3865 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3868 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3873 case DW_OP_plus_uconst:
3874 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3912 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3915 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3918 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3921 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3922 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3925 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3927 case DW_OP_deref_size:
3928 case DW_OP_xderef_size:
3937 case DW_OP_call_ref:
3938 size += DWARF2_ADDR_SIZE;
3947 /* Return the size of a series of location descriptors. */
3949 static unsigned long
3950 size_of_locs (dw_loc_descr_ref loc)
3955 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3956 field, to avoid writing to a PCH file. */
3957 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3959 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3961 size += size_of_loc_descr (l);
3966 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3968 l->dw_loc_addr = size;
3969 size += size_of_loc_descr (l);
3975 /* Output location description stack opcode's operands (if any). */
3978 output_loc_operands (dw_loc_descr_ref loc)
3980 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3981 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3983 switch (loc->dw_loc_opc)
3985 #ifdef DWARF2_DEBUGGING_INFO
3987 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3991 dw2_asm_output_data (2, val1->v.val_int, NULL);
3995 dw2_asm_output_data (4, val1->v.val_int, NULL);
3999 gcc_assert (HOST_BITS_PER_LONG >= 64);
4000 dw2_asm_output_data (8, val1->v.val_int, NULL);
4007 gcc_assert (val1->val_class == dw_val_class_loc);
4008 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4010 dw2_asm_output_data (2, offset, NULL);
4023 /* We currently don't make any attempt to make sure these are
4024 aligned properly like we do for the main unwind info, so
4025 don't support emitting things larger than a byte if we're
4026 only doing unwinding. */
4031 dw2_asm_output_data (1, val1->v.val_int, NULL);
4034 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4037 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4040 dw2_asm_output_data (1, val1->v.val_int, NULL);
4042 case DW_OP_plus_uconst:
4043 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4077 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4080 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4083 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4086 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4087 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4090 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4092 case DW_OP_deref_size:
4093 case DW_OP_xderef_size:
4094 dw2_asm_output_data (1, val1->v.val_int, NULL);
4097 case INTERNAL_DW_OP_tls_addr:
4098 if (targetm.asm_out.output_dwarf_dtprel)
4100 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4103 fputc ('\n', asm_out_file);
4110 /* Other codes have no operands. */
4115 /* Output a sequence of location operations. */
4118 output_loc_sequence (dw_loc_descr_ref loc)
4120 for (; loc != NULL; loc = loc->dw_loc_next)
4122 /* Output the opcode. */
4123 dw2_asm_output_data (1, loc->dw_loc_opc,
4124 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4126 /* Output the operand(s) (if any). */
4127 output_loc_operands (loc);
4131 /* Output location description stack opcode's operands (if any).
4132 The output is single bytes on a line, suitable for .cfi_escape. */
4135 output_loc_operands_raw (dw_loc_descr_ref loc)
4137 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4138 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4140 switch (loc->dw_loc_opc)
4143 /* We cannot output addresses in .cfi_escape, only bytes. */
4149 case DW_OP_deref_size:
4150 case DW_OP_xderef_size:
4151 fputc (',', asm_out_file);
4152 dw2_asm_output_data_raw (1, val1->v.val_int);
4157 fputc (',', asm_out_file);
4158 dw2_asm_output_data_raw (2, val1->v.val_int);
4163 fputc (',', asm_out_file);
4164 dw2_asm_output_data_raw (4, val1->v.val_int);
4169 gcc_assert (HOST_BITS_PER_LONG >= 64);
4170 fputc (',', asm_out_file);
4171 dw2_asm_output_data_raw (8, val1->v.val_int);
4179 gcc_assert (val1->val_class == dw_val_class_loc);
4180 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4182 fputc (',', asm_out_file);
4183 dw2_asm_output_data_raw (2, offset);
4188 case DW_OP_plus_uconst:
4191 fputc (',', asm_out_file);
4192 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4229 fputc (',', asm_out_file);
4230 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4234 fputc (',', asm_out_file);
4235 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4236 fputc (',', asm_out_file);
4237 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4240 case INTERNAL_DW_OP_tls_addr:
4244 /* Other codes have no operands. */
4250 output_loc_sequence_raw (dw_loc_descr_ref loc)
4254 /* Output the opcode. */
4255 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4256 output_loc_operands_raw (loc);
4258 if (!loc->dw_loc_next)
4260 loc = loc->dw_loc_next;
4262 fputc (',', asm_out_file);
4266 /* This routine will generate the correct assembly data for a location
4267 description based on a cfi entry with a complex address. */
4270 output_cfa_loc (dw_cfi_ref cfi)
4272 dw_loc_descr_ref loc;
4275 if (cfi->dw_cfi_opc == DW_CFA_expression)
4276 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4278 /* Output the size of the block. */
4279 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4280 size = size_of_locs (loc);
4281 dw2_asm_output_data_uleb128 (size, NULL);
4283 /* Now output the operations themselves. */
4284 output_loc_sequence (loc);
4287 /* Similar, but used for .cfi_escape. */
4290 output_cfa_loc_raw (dw_cfi_ref cfi)
4292 dw_loc_descr_ref loc;
4295 if (cfi->dw_cfi_opc == DW_CFA_expression)
4296 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4298 /* Output the size of the block. */
4299 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4300 size = size_of_locs (loc);
4301 dw2_asm_output_data_uleb128_raw (size);
4302 fputc (',', asm_out_file);
4304 /* Now output the operations themselves. */
4305 output_loc_sequence_raw (loc);
4308 /* This function builds a dwarf location descriptor sequence from a
4309 dw_cfa_location, adding the given OFFSET to the result of the
4312 static struct dw_loc_descr_struct *
4313 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4315 struct dw_loc_descr_struct *head, *tmp;
4317 offset += cfa->offset;
4321 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4322 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4323 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4324 add_loc_descr (&head, tmp);
4327 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4328 add_loc_descr (&head, tmp);
4332 head = new_reg_loc_descr (cfa->reg, offset);
4337 /* This function builds a dwarf location descriptor sequence for
4338 the address at OFFSET from the CFA when stack is aligned to
4341 static struct dw_loc_descr_struct *
4342 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4344 struct dw_loc_descr_struct *head;
4345 unsigned int dwarf_fp
4346 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4348 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4349 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4351 head = new_reg_loc_descr (dwarf_fp, 0);
4352 add_loc_descr (&head, int_loc_descriptor (alignment));
4353 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4355 add_loc_descr (&head, int_loc_descriptor (offset));
4356 add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
4359 head = new_reg_loc_descr (dwarf_fp, offset);
4363 /* This function fills in aa dw_cfa_location structure from a dwarf location
4364 descriptor sequence. */
4367 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4369 struct dw_loc_descr_struct *ptr;
4371 cfa->base_offset = 0;
4375 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4377 enum dwarf_location_atom op = ptr->dw_loc_opc;
4413 cfa->reg = op - DW_OP_reg0;
4416 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4450 cfa->reg = op - DW_OP_breg0;
4451 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4454 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4455 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4460 case DW_OP_plus_uconst:
4461 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4464 internal_error ("DW_LOC_OP %s not implemented",
4465 dwarf_stack_op_name (ptr->dw_loc_opc));
4469 #endif /* .debug_frame support */
4471 /* And now, the support for symbolic debugging information. */
4472 #ifdef DWARF2_DEBUGGING_INFO
4474 /* .debug_str support. */
4475 static int output_indirect_string (void **, void *);
4477 static void dwarf2out_init (const char *);
4478 static void dwarf2out_finish (const char *);
4479 static void dwarf2out_define (unsigned int, const char *);
4480 static void dwarf2out_undef (unsigned int, const char *);
4481 static void dwarf2out_start_source_file (unsigned, const char *);
4482 static void dwarf2out_end_source_file (unsigned);
4483 static void dwarf2out_begin_block (unsigned, unsigned);
4484 static void dwarf2out_end_block (unsigned, unsigned);
4485 static bool dwarf2out_ignore_block (const_tree);
4486 static void dwarf2out_global_decl (tree);
4487 static void dwarf2out_type_decl (tree, int);
4488 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
4489 static void dwarf2out_abstract_function (tree);
4490 static void dwarf2out_var_location (rtx);
4491 static void dwarf2out_begin_function (tree);
4493 /* The debug hooks structure. */
4495 const struct gcc_debug_hooks dwarf2_debug_hooks =
4501 dwarf2out_start_source_file,
4502 dwarf2out_end_source_file,
4503 dwarf2out_begin_block,
4504 dwarf2out_end_block,
4505 dwarf2out_ignore_block,
4506 dwarf2out_source_line,
4507 dwarf2out_begin_prologue,
4508 debug_nothing_int_charstar, /* end_prologue */
4509 dwarf2out_end_epilogue,
4510 dwarf2out_begin_function,
4511 debug_nothing_int, /* end_function */
4512 dwarf2out_decl, /* function_decl */
4513 dwarf2out_global_decl,
4514 dwarf2out_type_decl, /* type_decl */
4515 dwarf2out_imported_module_or_decl,
4516 debug_nothing_tree, /* deferred_inline_function */
4517 /* The DWARF 2 backend tries to reduce debugging bloat by not
4518 emitting the abstract description of inline functions until
4519 something tries to reference them. */
4520 dwarf2out_abstract_function, /* outlining_inline_function */
4521 debug_nothing_rtx, /* label */
4522 debug_nothing_int, /* handle_pch */
4523 dwarf2out_var_location,
4524 dwarf2out_switch_text_section,
4525 1 /* start_end_main_source_file */
4529 /* NOTE: In the comments in this file, many references are made to
4530 "Debugging Information Entries". This term is abbreviated as `DIE'
4531 throughout the remainder of this file. */
4533 /* An internal representation of the DWARF output is built, and then
4534 walked to generate the DWARF debugging info. The walk of the internal
4535 representation is done after the entire program has been compiled.
4536 The types below are used to describe the internal representation. */
4538 /* Various DIE's use offsets relative to the beginning of the
4539 .debug_info section to refer to each other. */
4541 typedef long int dw_offset;
4543 /* Define typedefs here to avoid circular dependencies. */
4545 typedef struct dw_attr_struct *dw_attr_ref;
4546 typedef struct dw_line_info_struct *dw_line_info_ref;
4547 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4548 typedef struct pubname_struct *pubname_ref;
4549 typedef struct dw_ranges_struct *dw_ranges_ref;
4550 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4552 /* Each entry in the line_info_table maintains the file and
4553 line number associated with the label generated for that
4554 entry. The label gives the PC value associated with
4555 the line number entry. */
4557 typedef struct dw_line_info_struct GTY(())
4559 unsigned long dw_file_num;
4560 unsigned long dw_line_num;
4564 /* Line information for functions in separate sections; each one gets its
4566 typedef struct dw_separate_line_info_struct GTY(())
4568 unsigned long dw_file_num;
4569 unsigned long dw_line_num;
4570 unsigned long function;
4572 dw_separate_line_info_entry;
4574 /* Each DIE attribute has a field specifying the attribute kind,
4575 a link to the next attribute in the chain, and an attribute value.
4576 Attributes are typically linked below the DIE they modify. */
4578 typedef struct dw_attr_struct GTY(())
4580 enum dwarf_attribute dw_attr;
4581 dw_val_node dw_attr_val;
4585 DEF_VEC_O(dw_attr_node);
4586 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4588 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4589 The children of each node form a circular list linked by
4590 die_sib. die_child points to the node *before* the "first" child node. */
4592 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
4594 enum dwarf_tag die_tag;
4596 VEC(dw_attr_node,gc) * die_attr;
4597 dw_die_ref die_parent;
4598 dw_die_ref die_child;
4600 dw_die_ref die_definition; /* ref from a specification to its definition */
4601 dw_offset die_offset;
4602 unsigned long die_abbrev;
4604 /* Die is used and must not be pruned as unused. */
4605 int die_perennial_p;
4606 unsigned int decl_id;
4610 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4611 #define FOR_EACH_CHILD(die, c, expr) do { \
4612 c = die->die_child; \
4616 } while (c != die->die_child); \
4619 /* The pubname structure */
4621 typedef struct pubname_struct GTY(())
4628 DEF_VEC_O(pubname_entry);
4629 DEF_VEC_ALLOC_O(pubname_entry, gc);
4631 struct dw_ranges_struct GTY(())
4633 /* If this is positive, it's a block number, otherwise it's a
4634 bitwise-negated index into dw_ranges_by_label. */
4638 struct dw_ranges_by_label_struct GTY(())
4644 /* The limbo die list structure. */
4645 typedef struct limbo_die_struct GTY(())
4649 struct limbo_die_struct *next;
4653 /* How to start an assembler comment. */
4654 #ifndef ASM_COMMENT_START
4655 #define ASM_COMMENT_START ";#"
4658 /* Define a macro which returns nonzero for a TYPE_DECL which was
4659 implicitly generated for a tagged type.
4661 Note that unlike the gcc front end (which generates a NULL named
4662 TYPE_DECL node for each complete tagged type, each array type, and
4663 each function type node created) the g++ front end generates a
4664 _named_ TYPE_DECL node for each tagged type node created.
4665 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4666 generate a DW_TAG_typedef DIE for them. */
4668 #define TYPE_DECL_IS_STUB(decl) \
4669 (DECL_NAME (decl) == NULL_TREE \
4670 || (DECL_ARTIFICIAL (decl) \
4671 && is_tagged_type (TREE_TYPE (decl)) \
4672 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4673 /* This is necessary for stub decls that \
4674 appear in nested inline functions. */ \
4675 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4676 && (decl_ultimate_origin (decl) \
4677 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4679 /* Information concerning the compilation unit's programming
4680 language, and compiler version. */
4682 /* Fixed size portion of the DWARF compilation unit header. */
4683 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4684 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4686 /* Fixed size portion of public names info. */
4687 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4689 /* Fixed size portion of the address range info. */
4690 #define DWARF_ARANGES_HEADER_SIZE \
4691 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4692 DWARF2_ADDR_SIZE * 2) \
4693 - DWARF_INITIAL_LENGTH_SIZE)
4695 /* Size of padding portion in the address range info. It must be
4696 aligned to twice the pointer size. */
4697 #define DWARF_ARANGES_PAD_SIZE \
4698 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4699 DWARF2_ADDR_SIZE * 2) \
4700 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4702 /* Use assembler line directives if available. */
4703 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4704 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4705 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4707 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4711 /* Minimum line offset in a special line info. opcode.
4712 This value was chosen to give a reasonable range of values. */
4713 #define DWARF_LINE_BASE -10
4715 /* First special line opcode - leave room for the standard opcodes. */
4716 #define DWARF_LINE_OPCODE_BASE 10
4718 /* Range of line offsets in a special line info. opcode. */
4719 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4721 /* Flag that indicates the initial value of the is_stmt_start flag.
4722 In the present implementation, we do not mark any lines as
4723 the beginning of a source statement, because that information
4724 is not made available by the GCC front-end. */
4725 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4727 #ifdef DWARF2_DEBUGGING_INFO
4728 /* This location is used by calc_die_sizes() to keep track
4729 the offset of each DIE within the .debug_info section. */
4730 static unsigned long next_die_offset;
4733 /* Record the root of the DIE's built for the current compilation unit. */
4734 static GTY(()) dw_die_ref comp_unit_die;
4736 /* A list of DIEs with a NULL parent waiting to be relocated. */
4737 static GTY(()) limbo_die_node *limbo_die_list;
4739 /* Filenames referenced by this compilation unit. */
4740 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4742 /* A hash table of references to DIE's that describe declarations.
4743 The key is a DECL_UID() which is a unique number identifying each decl. */
4744 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4746 /* Node of the variable location list. */
4747 struct var_loc_node GTY ((chain_next ("%h.next")))
4749 rtx GTY (()) var_loc_note;
4750 const char * GTY (()) label;
4751 const char * GTY (()) section_label;
4752 struct var_loc_node * GTY (()) next;
4755 /* Variable location list. */
4756 struct var_loc_list_def GTY (())
4758 struct var_loc_node * GTY (()) first;
4760 /* Do not mark the last element of the chained list because
4761 it is marked through the chain. */
4762 struct var_loc_node * GTY ((skip ("%h"))) last;
4764 /* DECL_UID of the variable decl. */
4765 unsigned int decl_id;
4767 typedef struct var_loc_list_def var_loc_list;
4770 /* Table of decl location linked lists. */
4771 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4773 /* A pointer to the base of a list of references to DIE's that
4774 are uniquely identified by their tag, presence/absence of
4775 children DIE's, and list of attribute/value pairs. */
4776 static GTY((length ("abbrev_die_table_allocated")))
4777 dw_die_ref *abbrev_die_table;
4779 /* Number of elements currently allocated for abbrev_die_table. */
4780 static GTY(()) unsigned abbrev_die_table_allocated;
4782 /* Number of elements in type_die_table currently in use. */
4783 static GTY(()) unsigned abbrev_die_table_in_use;
4785 /* Size (in elements) of increments by which we may expand the
4786 abbrev_die_table. */
4787 #define ABBREV_DIE_TABLE_INCREMENT 256
4789 /* A pointer to the base of a table that contains line information
4790 for each source code line in .text in the compilation unit. */
4791 static GTY((length ("line_info_table_allocated")))
4792 dw_line_info_ref line_info_table;
4794 /* Number of elements currently allocated for line_info_table. */
4795 static GTY(()) unsigned line_info_table_allocated;
4797 /* Number of elements in line_info_table currently in use. */
4798 static GTY(()) unsigned line_info_table_in_use;
4800 /* A pointer to the base of a table that contains line information
4801 for each source code line outside of .text in the compilation unit. */
4802 static GTY ((length ("separate_line_info_table_allocated")))
4803 dw_separate_line_info_ref separate_line_info_table;
4805 /* Number of elements currently allocated for separate_line_info_table. */
4806 static GTY(()) unsigned separate_line_info_table_allocated;
4808 /* Number of elements in separate_line_info_table currently in use. */
4809 static GTY(()) unsigned separate_line_info_table_in_use;
4811 /* Size (in elements) of increments by which we may expand the
4813 #define LINE_INFO_TABLE_INCREMENT 1024
4815 /* A pointer to the base of a table that contains a list of publicly
4816 accessible names. */
4817 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4819 /* A pointer to the base of a table that contains a list of publicly
4820 accessible types. */
4821 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4823 /* Array of dies for which we should generate .debug_arange info. */
4824 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4826 /* Number of elements currently allocated for arange_table. */
4827 static GTY(()) unsigned arange_table_allocated;
4829 /* Number of elements in arange_table currently in use. */
4830 static GTY(()) unsigned arange_table_in_use;
4832 /* Size (in elements) of increments by which we may expand the
4834 #define ARANGE_TABLE_INCREMENT 64
4836 /* Array of dies for which we should generate .debug_ranges info. */
4837 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4839 /* Number of elements currently allocated for ranges_table. */
4840 static GTY(()) unsigned ranges_table_allocated;
4842 /* Number of elements in ranges_table currently in use. */
4843 static GTY(()) unsigned ranges_table_in_use;
4845 /* Array of pairs of labels referenced in ranges_table. */
4846 static GTY ((length ("ranges_by_label_allocated")))
4847 dw_ranges_by_label_ref ranges_by_label;
4849 /* Number of elements currently allocated for ranges_by_label. */
4850 static GTY(()) unsigned ranges_by_label_allocated;
4852 /* Number of elements in ranges_by_label currently in use. */
4853 static GTY(()) unsigned ranges_by_label_in_use;
4855 /* Size (in elements) of increments by which we may expand the
4857 #define RANGES_TABLE_INCREMENT 64
4859 /* Whether we have location lists that need outputting */
4860 static GTY(()) bool have_location_lists;
4862 /* Unique label counter. */
4863 static GTY(()) unsigned int loclabel_num;
4865 #ifdef DWARF2_DEBUGGING_INFO
4866 /* Record whether the function being analyzed contains inlined functions. */
4867 static int current_function_has_inlines;
4869 #if 0 && defined (MIPS_DEBUGGING_INFO)
4870 static int comp_unit_has_inlines;
4873 /* The last file entry emitted by maybe_emit_file(). */
4874 static GTY(()) struct dwarf_file_data * last_emitted_file;
4876 /* Number of internal labels generated by gen_internal_sym(). */
4877 static GTY(()) int label_num;
4879 /* Cached result of previous call to lookup_filename. */
4880 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4882 #ifdef DWARF2_DEBUGGING_INFO
4884 /* Offset from the "steady-state frame pointer" to the frame base,
4885 within the current function. */
4886 static HOST_WIDE_INT frame_pointer_fb_offset;
4888 /* Forward declarations for functions defined in this file. */
4890 static int is_pseudo_reg (const_rtx);
4891 static tree type_main_variant (tree);
4892 static int is_tagged_type (const_tree);
4893 static const char *dwarf_tag_name (unsigned);
4894 static const char *dwarf_attr_name (unsigned);
4895 static const char *dwarf_form_name (unsigned);
4896 static tree decl_ultimate_origin (const_tree);
4897 static tree block_ultimate_origin (const_tree);
4898 static tree decl_class_context (tree);
4899 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4900 static inline enum dw_val_class AT_class (dw_attr_ref);
4901 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4902 static inline unsigned AT_flag (dw_attr_ref);
4903 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4904 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4905 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4906 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4907 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4909 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4910 unsigned int, unsigned char *);
4911 static hashval_t debug_str_do_hash (const void *);
4912 static int debug_str_eq (const void *, const void *);
4913 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4914 static inline const char *AT_string (dw_attr_ref);
4915 static int AT_string_form (dw_attr_ref);
4916 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4917 static void add_AT_specification (dw_die_ref, dw_die_ref);
4918 static inline dw_die_ref AT_ref (dw_attr_ref);
4919 static inline int AT_ref_external (dw_attr_ref);
4920 static inline void set_AT_ref_external (dw_attr_ref, int);
4921 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4922 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4923 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4924 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4926 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4927 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4928 static inline rtx AT_addr (dw_attr_ref);
4929 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4930 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4931 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4932 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4933 unsigned HOST_WIDE_INT);
4934 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4936 static inline const char *AT_lbl (dw_attr_ref);
4937 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4938 static const char *get_AT_low_pc (dw_die_ref);
4939 static const char *get_AT_hi_pc (dw_die_ref);
4940 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4941 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4942 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4943 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4944 static bool is_c_family (void);
4945 static bool is_cxx (void);
4946 static bool is_java (void);
4947 static bool is_fortran (void);
4948 static bool is_ada (void);
4949 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4950 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4951 static void add_child_die (dw_die_ref, dw_die_ref);
4952 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4953 static dw_die_ref lookup_type_die (tree);
4954 static void equate_type_number_to_die (tree, dw_die_ref);
4955 static hashval_t decl_die_table_hash (const void *);
4956 static int decl_die_table_eq (const void *, const void *);
4957 static dw_die_ref lookup_decl_die (tree);
4958 static hashval_t decl_loc_table_hash (const void *);
4959 static int decl_loc_table_eq (const void *, const void *);
4960 static var_loc_list *lookup_decl_loc (const_tree);
4961 static void equate_decl_number_to_die (tree, dw_die_ref);
4962 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4963 static void print_spaces (FILE *);
4964 static void print_die (dw_die_ref, FILE *);
4965 static void print_dwarf_line_table (FILE *);
4966 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4967 static dw_die_ref pop_compile_unit (dw_die_ref);
4968 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4969 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4970 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4971 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4972 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4973 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4974 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4975 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4976 static void compute_section_prefix (dw_die_ref);
4977 static int is_type_die (dw_die_ref);
4978 static int is_comdat_die (dw_die_ref);
4979 static int is_symbol_die (dw_die_ref);
4980 static void assign_symbol_names (dw_die_ref);
4981 static void break_out_includes (dw_die_ref);
4982 static hashval_t htab_cu_hash (const void *);
4983 static int htab_cu_eq (const void *, const void *);
4984 static void htab_cu_del (void *);
4985 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4986 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4987 static void add_sibling_attributes (dw_die_ref);
4988 static void build_abbrev_table (dw_die_ref);
4989 static void output_location_lists (dw_die_ref);
4990 static int constant_size (long unsigned);
4991 static unsigned long size_of_die (dw_die_ref);
4992 static void calc_die_sizes (dw_die_ref);
4993 static void mark_dies (dw_die_ref);
4994 static void unmark_dies (dw_die_ref);
4995 static void unmark_all_dies (dw_die_ref);
4996 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4997 static unsigned long size_of_aranges (void);
4998 static enum dwarf_form value_format (dw_attr_ref);
4999 static void output_value_format (dw_attr_ref);
5000 static void output_abbrev_section (void);
5001 static void output_die_symbol (dw_die_ref);
5002 static void output_die (dw_die_ref);
5003 static void output_compilation_unit_header (void);
5004 static void output_comp_unit (dw_die_ref, int);
5005 static const char *dwarf2_name (tree, int);
5006 static void add_pubname (tree, dw_die_ref);
5007 static void add_pubname_string (const char *, dw_die_ref);
5008 static void add_pubtype (tree, dw_die_ref);
5009 static void output_pubnames (VEC (pubname_entry,gc) *);
5010 static void add_arange (tree, dw_die_ref);
5011 static void output_aranges (void);
5012 static unsigned int add_ranges_num (int);
5013 static unsigned int add_ranges (const_tree);
5014 static unsigned int add_ranges_by_labels (const char *, const char *);
5015 static void output_ranges (void);
5016 static void output_line_info (void);
5017 static void output_file_names (void);
5018 static dw_die_ref base_type_die (tree);
5019 static int is_base_type (tree);
5020 static bool is_subrange_type (const_tree);
5021 static dw_die_ref subrange_type_die (tree, dw_die_ref);
5022 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5023 static int type_is_enum (const_tree);
5024 static unsigned int dbx_reg_number (const_rtx);
5025 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5026 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5027 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5028 enum var_init_status);
5029 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5030 enum var_init_status);
5031 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5032 enum var_init_status);
5033 static int is_based_loc (const_rtx);
5034 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5035 enum var_init_status);
5036 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5037 enum var_init_status);
5038 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5039 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5040 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5041 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5042 static tree field_type (const_tree);
5043 static unsigned int simple_type_align_in_bits (const_tree);
5044 static unsigned int simple_decl_align_in_bits (const_tree);
5045 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5046 static HOST_WIDE_INT field_byte_offset (const_tree);
5047 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5049 static void add_data_member_location_attribute (dw_die_ref, tree);
5050 static void add_const_value_attribute (dw_die_ref, rtx);
5051 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5052 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5053 static void insert_float (const_rtx, unsigned char *);
5054 static rtx rtl_for_decl_location (tree);
5055 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5056 enum dwarf_attribute);
5057 static void tree_add_const_value_attribute (dw_die_ref, tree);
5058 static void add_name_attribute (dw_die_ref, const char *);
5059 static void add_comp_dir_attribute (dw_die_ref);
5060 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5061 static void add_subscript_info (dw_die_ref, tree, bool);
5062 static void add_byte_size_attribute (dw_die_ref, tree);
5063 static void add_bit_offset_attribute (dw_die_ref, tree);
5064 static void add_bit_size_attribute (dw_die_ref, tree);
5065 static void add_prototyped_attribute (dw_die_ref, tree);
5066 static void add_abstract_origin_attribute (dw_die_ref, tree);
5067 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5068 static void add_src_coords_attributes (dw_die_ref, tree);
5069 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5070 static void push_decl_scope (tree);
5071 static void pop_decl_scope (void);
5072 static dw_die_ref scope_die_for (tree, dw_die_ref);
5073 static inline int local_scope_p (dw_die_ref);
5074 static inline int class_or_namespace_scope_p (dw_die_ref);
5075 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5076 static void add_calling_convention_attribute (dw_die_ref, tree);
5077 static const char *type_tag (const_tree);
5078 static tree member_declared_type (const_tree);
5080 static const char *decl_start_label (tree);
5082 static void gen_array_type_die (tree, dw_die_ref);
5083 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5085 static void gen_entry_point_die (tree, dw_die_ref);
5087 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
5088 static void gen_inlined_structure_type_die (tree, dw_die_ref);
5089 static void gen_inlined_union_type_die (tree, dw_die_ref);
5090 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5091 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
5092 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5093 static void gen_formal_types_die (tree, dw_die_ref);
5094 static void gen_subprogram_die (tree, dw_die_ref);
5095 static void gen_variable_die (tree, dw_die_ref);
5096 static void gen_label_die (tree, dw_die_ref);
5097 static void gen_lexical_block_die (tree, dw_die_ref, int);
5098 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5099 static void gen_field_die (tree, dw_die_ref);
5100 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5101 static dw_die_ref gen_compile_unit_die (const char *);
5102 static void gen_inheritance_die (tree, tree, dw_die_ref);
5103 static void gen_member_die (tree, dw_die_ref);
5104 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5105 enum debug_info_usage);
5106 static void gen_subroutine_type_die (tree, dw_die_ref);
5107 static void gen_typedef_die (tree, dw_die_ref);
5108 static void gen_type_die (tree, dw_die_ref);
5109 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
5110 static void gen_block_die (tree, dw_die_ref, int);
5111 static void decls_for_scope (tree, dw_die_ref, int);
5112 static int is_redundant_typedef (const_tree);
5113 static void gen_namespace_die (tree);
5114 static void gen_decl_die (tree, dw_die_ref);
5115 static dw_die_ref force_decl_die (tree);
5116 static dw_die_ref force_type_die (tree);
5117 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5118 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5119 static struct dwarf_file_data * lookup_filename (const char *);
5120 static void retry_incomplete_types (void);
5121 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5122 static void splice_child_die (dw_die_ref, dw_die_ref);
5123 static int file_info_cmp (const void *, const void *);
5124 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5125 const char *, const char *, unsigned);
5126 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5127 const char *, const char *,
5129 static void output_loc_list (dw_loc_list_ref);
5130 static char *gen_internal_sym (const char *);
5132 static void prune_unmark_dies (dw_die_ref);
5133 static void prune_unused_types_mark (dw_die_ref, int);
5134 static void prune_unused_types_walk (dw_die_ref);
5135 static void prune_unused_types_walk_attribs (dw_die_ref);
5136 static void prune_unused_types_prune (dw_die_ref);
5137 static void prune_unused_types (void);
5138 static int maybe_emit_file (struct dwarf_file_data *fd);
5140 /* Section names used to hold DWARF debugging information. */
5141 #ifndef DEBUG_INFO_SECTION
5142 #define DEBUG_INFO_SECTION ".debug_info"
5144 #ifndef DEBUG_ABBREV_SECTION
5145 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5147 #ifndef DEBUG_ARANGES_SECTION
5148 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5150 #ifndef DEBUG_MACINFO_SECTION
5151 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5153 #ifndef DEBUG_LINE_SECTION
5154 #define DEBUG_LINE_SECTION ".debug_line"
5156 #ifndef DEBUG_LOC_SECTION
5157 #define DEBUG_LOC_SECTION ".debug_loc"
5159 #ifndef DEBUG_PUBNAMES_SECTION
5160 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5162 #ifndef DEBUG_STR_SECTION
5163 #define DEBUG_STR_SECTION ".debug_str"
5165 #ifndef DEBUG_RANGES_SECTION
5166 #define DEBUG_RANGES_SECTION ".debug_ranges"
5169 /* Standard ELF section names for compiled code and data. */
5170 #ifndef TEXT_SECTION_NAME
5171 #define TEXT_SECTION_NAME ".text"
5174 /* Section flags for .debug_str section. */
5175 #define DEBUG_STR_SECTION_FLAGS \
5176 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5177 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5180 /* Labels we insert at beginning sections we can reference instead of
5181 the section names themselves. */
5183 #ifndef TEXT_SECTION_LABEL
5184 #define TEXT_SECTION_LABEL "Ltext"
5186 #ifndef COLD_TEXT_SECTION_LABEL
5187 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5189 #ifndef DEBUG_LINE_SECTION_LABEL
5190 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5192 #ifndef DEBUG_INFO_SECTION_LABEL
5193 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5195 #ifndef DEBUG_ABBREV_SECTION_LABEL
5196 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5198 #ifndef DEBUG_LOC_SECTION_LABEL
5199 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5201 #ifndef DEBUG_RANGES_SECTION_LABEL
5202 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5204 #ifndef DEBUG_MACINFO_SECTION_LABEL
5205 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5208 /* Definitions of defaults for formats and names of various special
5209 (artificial) labels which may be generated within this file (when the -g
5210 options is used and DWARF2_DEBUGGING_INFO is in effect.
5211 If necessary, these may be overridden from within the tm.h file, but
5212 typically, overriding these defaults is unnecessary. */
5214 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5215 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5216 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5217 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5218 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5219 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5220 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5221 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5222 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5223 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5225 #ifndef TEXT_END_LABEL
5226 #define TEXT_END_LABEL "Letext"
5228 #ifndef COLD_END_LABEL
5229 #define COLD_END_LABEL "Letext_cold"
5231 #ifndef BLOCK_BEGIN_LABEL
5232 #define BLOCK_BEGIN_LABEL "LBB"
5234 #ifndef BLOCK_END_LABEL
5235 #define BLOCK_END_LABEL "LBE"
5237 #ifndef LINE_CODE_LABEL
5238 #define LINE_CODE_LABEL "LM"
5240 #ifndef SEPARATE_LINE_CODE_LABEL
5241 #define SEPARATE_LINE_CODE_LABEL "LSM"
5245 /* We allow a language front-end to designate a function that is to be
5246 called to "demangle" any name before it is put into a DIE. */
5248 static const char *(*demangle_name_func) (const char *);
5251 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5253 demangle_name_func = func;
5256 /* Test if rtl node points to a pseudo register. */
5259 is_pseudo_reg (const_rtx rtl)
5261 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5262 || (GET_CODE (rtl) == SUBREG
5263 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5266 /* Return a reference to a type, with its const and volatile qualifiers
5270 type_main_variant (tree type)
5272 type = TYPE_MAIN_VARIANT (type);
5274 /* ??? There really should be only one main variant among any group of
5275 variants of a given type (and all of the MAIN_VARIANT values for all
5276 members of the group should point to that one type) but sometimes the C
5277 front-end messes this up for array types, so we work around that bug
5279 if (TREE_CODE (type) == ARRAY_TYPE)
5280 while (type != TYPE_MAIN_VARIANT (type))
5281 type = TYPE_MAIN_VARIANT (type);
5286 /* Return nonzero if the given type node represents a tagged type. */
5289 is_tagged_type (const_tree type)
5291 enum tree_code code = TREE_CODE (type);
5293 return (code == RECORD_TYPE || code == UNION_TYPE
5294 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5297 /* Convert a DIE tag into its string name. */
5300 dwarf_tag_name (unsigned int tag)
5304 case DW_TAG_padding:
5305 return "DW_TAG_padding";
5306 case DW_TAG_array_type:
5307 return "DW_TAG_array_type";
5308 case DW_TAG_class_type:
5309 return "DW_TAG_class_type";
5310 case DW_TAG_entry_point:
5311 return "DW_TAG_entry_point";
5312 case DW_TAG_enumeration_type:
5313 return "DW_TAG_enumeration_type";
5314 case DW_TAG_formal_parameter:
5315 return "DW_TAG_formal_parameter";
5316 case DW_TAG_imported_declaration:
5317 return "DW_TAG_imported_declaration";
5319 return "DW_TAG_label";
5320 case DW_TAG_lexical_block:
5321 return "DW_TAG_lexical_block";
5323 return "DW_TAG_member";
5324 case DW_TAG_pointer_type:
5325 return "DW_TAG_pointer_type";
5326 case DW_TAG_reference_type:
5327 return "DW_TAG_reference_type";
5328 case DW_TAG_compile_unit:
5329 return "DW_TAG_compile_unit";
5330 case DW_TAG_string_type:
5331 return "DW_TAG_string_type";
5332 case DW_TAG_structure_type:
5333 return "DW_TAG_structure_type";
5334 case DW_TAG_subroutine_type:
5335 return "DW_TAG_subroutine_type";
5336 case DW_TAG_typedef:
5337 return "DW_TAG_typedef";
5338 case DW_TAG_union_type:
5339 return "DW_TAG_union_type";
5340 case DW_TAG_unspecified_parameters:
5341 return "DW_TAG_unspecified_parameters";
5342 case DW_TAG_variant:
5343 return "DW_TAG_variant";
5344 case DW_TAG_common_block:
5345 return "DW_TAG_common_block";
5346 case DW_TAG_common_inclusion:
5347 return "DW_TAG_common_inclusion";
5348 case DW_TAG_inheritance:
5349 return "DW_TAG_inheritance";
5350 case DW_TAG_inlined_subroutine:
5351 return "DW_TAG_inlined_subroutine";
5353 return "DW_TAG_module";
5354 case DW_TAG_ptr_to_member_type:
5355 return "DW_TAG_ptr_to_member_type";
5356 case DW_TAG_set_type:
5357 return "DW_TAG_set_type";
5358 case DW_TAG_subrange_type:
5359 return "DW_TAG_subrange_type";
5360 case DW_TAG_with_stmt:
5361 return "DW_TAG_with_stmt";
5362 case DW_TAG_access_declaration:
5363 return "DW_TAG_access_declaration";
5364 case DW_TAG_base_type:
5365 return "DW_TAG_base_type";
5366 case DW_TAG_catch_block:
5367 return "DW_TAG_catch_block";
5368 case DW_TAG_const_type:
5369 return "DW_TAG_const_type";
5370 case DW_TAG_constant:
5371 return "DW_TAG_constant";
5372 case DW_TAG_enumerator:
5373 return "DW_TAG_enumerator";
5374 case DW_TAG_file_type:
5375 return "DW_TAG_file_type";
5377 return "DW_TAG_friend";
5378 case DW_TAG_namelist:
5379 return "DW_TAG_namelist";
5380 case DW_TAG_namelist_item:
5381 return "DW_TAG_namelist_item";
5382 case DW_TAG_packed_type:
5383 return "DW_TAG_packed_type";
5384 case DW_TAG_subprogram:
5385 return "DW_TAG_subprogram";
5386 case DW_TAG_template_type_param:
5387 return "DW_TAG_template_type_param";
5388 case DW_TAG_template_value_param:
5389 return "DW_TAG_template_value_param";
5390 case DW_TAG_thrown_type:
5391 return "DW_TAG_thrown_type";
5392 case DW_TAG_try_block:
5393 return "DW_TAG_try_block";
5394 case DW_TAG_variant_part:
5395 return "DW_TAG_variant_part";
5396 case DW_TAG_variable:
5397 return "DW_TAG_variable";
5398 case DW_TAG_volatile_type:
5399 return "DW_TAG_volatile_type";
5400 case DW_TAG_dwarf_procedure:
5401 return "DW_TAG_dwarf_procedure";
5402 case DW_TAG_restrict_type:
5403 return "DW_TAG_restrict_type";
5404 case DW_TAG_interface_type:
5405 return "DW_TAG_interface_type";
5406 case DW_TAG_namespace:
5407 return "DW_TAG_namespace";
5408 case DW_TAG_imported_module:
5409 return "DW_TAG_imported_module";
5410 case DW_TAG_unspecified_type:
5411 return "DW_TAG_unspecified_type";
5412 case DW_TAG_partial_unit:
5413 return "DW_TAG_partial_unit";
5414 case DW_TAG_imported_unit:
5415 return "DW_TAG_imported_unit";
5416 case DW_TAG_condition:
5417 return "DW_TAG_condition";
5418 case DW_TAG_shared_type:
5419 return "DW_TAG_shared_type";
5420 case DW_TAG_MIPS_loop:
5421 return "DW_TAG_MIPS_loop";
5422 case DW_TAG_format_label:
5423 return "DW_TAG_format_label";
5424 case DW_TAG_function_template:
5425 return "DW_TAG_function_template";
5426 case DW_TAG_class_template:
5427 return "DW_TAG_class_template";
5428 case DW_TAG_GNU_BINCL:
5429 return "DW_TAG_GNU_BINCL";
5430 case DW_TAG_GNU_EINCL:
5431 return "DW_TAG_GNU_EINCL";
5433 return "DW_TAG_<unknown>";
5437 /* Convert a DWARF attribute code into its string name. */
5440 dwarf_attr_name (unsigned int attr)
5445 return "DW_AT_sibling";
5446 case DW_AT_location:
5447 return "DW_AT_location";
5449 return "DW_AT_name";
5450 case DW_AT_ordering:
5451 return "DW_AT_ordering";
5452 case DW_AT_subscr_data:
5453 return "DW_AT_subscr_data";
5454 case DW_AT_byte_size:
5455 return "DW_AT_byte_size";
5456 case DW_AT_bit_offset:
5457 return "DW_AT_bit_offset";
5458 case DW_AT_bit_size:
5459 return "DW_AT_bit_size";
5460 case DW_AT_element_list:
5461 return "DW_AT_element_list";
5462 case DW_AT_stmt_list:
5463 return "DW_AT_stmt_list";
5465 return "DW_AT_low_pc";
5467 return "DW_AT_high_pc";
5468 case DW_AT_language:
5469 return "DW_AT_language";
5471 return "DW_AT_member";
5473 return "DW_AT_discr";
5474 case DW_AT_discr_value:
5475 return "DW_AT_discr_value";
5476 case DW_AT_visibility:
5477 return "DW_AT_visibility";
5479 return "DW_AT_import";
5480 case DW_AT_string_length:
5481 return "DW_AT_string_length";
5482 case DW_AT_common_reference:
5483 return "DW_AT_common_reference";
5484 case DW_AT_comp_dir:
5485 return "DW_AT_comp_dir";
5486 case DW_AT_const_value:
5487 return "DW_AT_const_value";
5488 case DW_AT_containing_type:
5489 return "DW_AT_containing_type";
5490 case DW_AT_default_value:
5491 return "DW_AT_default_value";
5493 return "DW_AT_inline";
5494 case DW_AT_is_optional:
5495 return "DW_AT_is_optional";
5496 case DW_AT_lower_bound:
5497 return "DW_AT_lower_bound";
5498 case DW_AT_producer:
5499 return "DW_AT_producer";
5500 case DW_AT_prototyped:
5501 return "DW_AT_prototyped";
5502 case DW_AT_return_addr:
5503 return "DW_AT_return_addr";
5504 case DW_AT_start_scope:
5505 return "DW_AT_start_scope";
5506 case DW_AT_bit_stride:
5507 return "DW_AT_bit_stride";
5508 case DW_AT_upper_bound:
5509 return "DW_AT_upper_bound";
5510 case DW_AT_abstract_origin:
5511 return "DW_AT_abstract_origin";
5512 case DW_AT_accessibility:
5513 return "DW_AT_accessibility";
5514 case DW_AT_address_class:
5515 return "DW_AT_address_class";
5516 case DW_AT_artificial:
5517 return "DW_AT_artificial";
5518 case DW_AT_base_types:
5519 return "DW_AT_base_types";
5520 case DW_AT_calling_convention:
5521 return "DW_AT_calling_convention";
5523 return "DW_AT_count";
5524 case DW_AT_data_member_location:
5525 return "DW_AT_data_member_location";
5526 case DW_AT_decl_column:
5527 return "DW_AT_decl_column";
5528 case DW_AT_decl_file:
5529 return "DW_AT_decl_file";
5530 case DW_AT_decl_line:
5531 return "DW_AT_decl_line";
5532 case DW_AT_declaration:
5533 return "DW_AT_declaration";
5534 case DW_AT_discr_list:
5535 return "DW_AT_discr_list";
5536 case DW_AT_encoding:
5537 return "DW_AT_encoding";
5538 case DW_AT_external:
5539 return "DW_AT_external";
5540 case DW_AT_frame_base:
5541 return "DW_AT_frame_base";
5543 return "DW_AT_friend";
5544 case DW_AT_identifier_case:
5545 return "DW_AT_identifier_case";
5546 case DW_AT_macro_info:
5547 return "DW_AT_macro_info";
5548 case DW_AT_namelist_items:
5549 return "DW_AT_namelist_items";
5550 case DW_AT_priority:
5551 return "DW_AT_priority";
5553 return "DW_AT_segment";
5554 case DW_AT_specification:
5555 return "DW_AT_specification";
5556 case DW_AT_static_link:
5557 return "DW_AT_static_link";
5559 return "DW_AT_type";
5560 case DW_AT_use_location:
5561 return "DW_AT_use_location";
5562 case DW_AT_variable_parameter:
5563 return "DW_AT_variable_parameter";
5564 case DW_AT_virtuality:
5565 return "DW_AT_virtuality";
5566 case DW_AT_vtable_elem_location:
5567 return "DW_AT_vtable_elem_location";
5569 case DW_AT_allocated:
5570 return "DW_AT_allocated";
5571 case DW_AT_associated:
5572 return "DW_AT_associated";
5573 case DW_AT_data_location:
5574 return "DW_AT_data_location";
5575 case DW_AT_byte_stride:
5576 return "DW_AT_byte_stride";
5577 case DW_AT_entry_pc:
5578 return "DW_AT_entry_pc";
5579 case DW_AT_use_UTF8:
5580 return "DW_AT_use_UTF8";
5581 case DW_AT_extension:
5582 return "DW_AT_extension";
5584 return "DW_AT_ranges";
5585 case DW_AT_trampoline:
5586 return "DW_AT_trampoline";
5587 case DW_AT_call_column:
5588 return "DW_AT_call_column";
5589 case DW_AT_call_file:
5590 return "DW_AT_call_file";
5591 case DW_AT_call_line:
5592 return "DW_AT_call_line";
5594 case DW_AT_MIPS_fde:
5595 return "DW_AT_MIPS_fde";
5596 case DW_AT_MIPS_loop_begin:
5597 return "DW_AT_MIPS_loop_begin";
5598 case DW_AT_MIPS_tail_loop_begin:
5599 return "DW_AT_MIPS_tail_loop_begin";
5600 case DW_AT_MIPS_epilog_begin:
5601 return "DW_AT_MIPS_epilog_begin";
5602 case DW_AT_MIPS_loop_unroll_factor:
5603 return "DW_AT_MIPS_loop_unroll_factor";
5604 case DW_AT_MIPS_software_pipeline_depth:
5605 return "DW_AT_MIPS_software_pipeline_depth";
5606 case DW_AT_MIPS_linkage_name:
5607 return "DW_AT_MIPS_linkage_name";
5608 case DW_AT_MIPS_stride:
5609 return "DW_AT_MIPS_stride";
5610 case DW_AT_MIPS_abstract_name:
5611 return "DW_AT_MIPS_abstract_name";
5612 case DW_AT_MIPS_clone_origin:
5613 return "DW_AT_MIPS_clone_origin";
5614 case DW_AT_MIPS_has_inlines:
5615 return "DW_AT_MIPS_has_inlines";
5617 case DW_AT_sf_names:
5618 return "DW_AT_sf_names";
5619 case DW_AT_src_info:
5620 return "DW_AT_src_info";
5621 case DW_AT_mac_info:
5622 return "DW_AT_mac_info";
5623 case DW_AT_src_coords:
5624 return "DW_AT_src_coords";
5625 case DW_AT_body_begin:
5626 return "DW_AT_body_begin";
5627 case DW_AT_body_end:
5628 return "DW_AT_body_end";
5629 case DW_AT_GNU_vector:
5630 return "DW_AT_GNU_vector";
5632 case DW_AT_VMS_rtnbeg_pd_address:
5633 return "DW_AT_VMS_rtnbeg_pd_address";
5636 return "DW_AT_<unknown>";
5640 /* Convert a DWARF value form code into its string name. */
5643 dwarf_form_name (unsigned int form)
5648 return "DW_FORM_addr";
5649 case DW_FORM_block2:
5650 return "DW_FORM_block2";
5651 case DW_FORM_block4:
5652 return "DW_FORM_block4";
5654 return "DW_FORM_data2";
5656 return "DW_FORM_data4";
5658 return "DW_FORM_data8";
5659 case DW_FORM_string:
5660 return "DW_FORM_string";
5662 return "DW_FORM_block";
5663 case DW_FORM_block1:
5664 return "DW_FORM_block1";
5666 return "DW_FORM_data1";
5668 return "DW_FORM_flag";
5670 return "DW_FORM_sdata";
5672 return "DW_FORM_strp";
5674 return "DW_FORM_udata";
5675 case DW_FORM_ref_addr:
5676 return "DW_FORM_ref_addr";
5678 return "DW_FORM_ref1";
5680 return "DW_FORM_ref2";
5682 return "DW_FORM_ref4";
5684 return "DW_FORM_ref8";
5685 case DW_FORM_ref_udata:
5686 return "DW_FORM_ref_udata";
5687 case DW_FORM_indirect:
5688 return "DW_FORM_indirect";
5690 return "DW_FORM_<unknown>";
5694 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5695 instance of an inlined instance of a decl which is local to an inline
5696 function, so we have to trace all of the way back through the origin chain
5697 to find out what sort of node actually served as the original seed for the
5701 decl_ultimate_origin (const_tree decl)
5703 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
5706 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5707 nodes in the function to point to themselves; ignore that if
5708 we're trying to output the abstract instance of this function. */
5709 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
5712 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5713 most distant ancestor, this should never happen. */
5714 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
5716 return DECL_ABSTRACT_ORIGIN (decl);
5719 /* Determine the "ultimate origin" of a block. The block may be an inlined
5720 instance of an inlined instance of a block which is local to an inline
5721 function, so we have to trace all of the way back through the origin chain
5722 to find out what sort of node actually served as the original seed for the
5726 block_ultimate_origin (const_tree block)
5728 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
5730 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5731 nodes in the function to point to themselves; ignore that if
5732 we're trying to output the abstract instance of this function. */
5733 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
5736 if (immediate_origin == NULL_TREE)
5741 tree lookahead = immediate_origin;
5745 ret_val = lookahead;
5746 lookahead = (TREE_CODE (ret_val) == BLOCK
5747 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
5749 while (lookahead != NULL && lookahead != ret_val);
5751 /* The block's abstract origin chain may not be the *ultimate* origin of
5752 the block. It could lead to a DECL that has an abstract origin set.
5753 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5754 will give us if it has one). Note that DECL's abstract origins are
5755 supposed to be the most distant ancestor (or so decl_ultimate_origin
5756 claims), so we don't need to loop following the DECL origins. */
5757 if (DECL_P (ret_val))
5758 return DECL_ORIGIN (ret_val);
5764 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5765 of a virtual function may refer to a base class, so we check the 'this'
5769 decl_class_context (tree decl)
5771 tree context = NULL_TREE;
5773 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5774 context = DECL_CONTEXT (decl);
5776 context = TYPE_MAIN_VARIANT
5777 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5779 if (context && !TYPE_P (context))
5780 context = NULL_TREE;
5785 /* Add an attribute/value pair to a DIE. */
5788 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5790 /* Maybe this should be an assert? */
5794 if (die->die_attr == NULL)
5795 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5796 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5799 static inline enum dw_val_class
5800 AT_class (dw_attr_ref a)
5802 return a->dw_attr_val.val_class;
5805 /* Add a flag value attribute to a DIE. */
5808 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5812 attr.dw_attr = attr_kind;
5813 attr.dw_attr_val.val_class = dw_val_class_flag;
5814 attr.dw_attr_val.v.val_flag = flag;
5815 add_dwarf_attr (die, &attr);
5818 static inline unsigned
5819 AT_flag (dw_attr_ref a)
5821 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5822 return a->dw_attr_val.v.val_flag;
5825 /* Add a signed integer attribute value to a DIE. */
5828 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5832 attr.dw_attr = attr_kind;
5833 attr.dw_attr_val.val_class = dw_val_class_const;
5834 attr.dw_attr_val.v.val_int = int_val;
5835 add_dwarf_attr (die, &attr);
5838 static inline HOST_WIDE_INT
5839 AT_int (dw_attr_ref a)
5841 gcc_assert (a && AT_class (a) == dw_val_class_const);
5842 return a->dw_attr_val.v.val_int;
5845 /* Add an unsigned integer attribute value to a DIE. */
5848 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5849 unsigned HOST_WIDE_INT unsigned_val)
5853 attr.dw_attr = attr_kind;
5854 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5855 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5856 add_dwarf_attr (die, &attr);
5859 static inline unsigned HOST_WIDE_INT
5860 AT_unsigned (dw_attr_ref a)
5862 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5863 return a->dw_attr_val.v.val_unsigned;
5866 /* Add an unsigned double integer attribute value to a DIE. */
5869 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5870 long unsigned int val_hi, long unsigned int val_low)
5874 attr.dw_attr = attr_kind;
5875 attr.dw_attr_val.val_class = dw_val_class_long_long;
5876 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5877 attr.dw_attr_val.v.val_long_long.low = val_low;
5878 add_dwarf_attr (die, &attr);
5881 /* Add a floating point attribute value to a DIE and return it. */
5884 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5885 unsigned int length, unsigned int elt_size, unsigned char *array)
5889 attr.dw_attr = attr_kind;
5890 attr.dw_attr_val.val_class = dw_val_class_vec;
5891 attr.dw_attr_val.v.val_vec.length = length;
5892 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5893 attr.dw_attr_val.v.val_vec.array = array;
5894 add_dwarf_attr (die, &attr);
5897 /* Hash and equality functions for debug_str_hash. */
5900 debug_str_do_hash (const void *x)
5902 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5906 debug_str_eq (const void *x1, const void *x2)
5908 return strcmp ((((const struct indirect_string_node *)x1)->str),
5909 (const char *)x2) == 0;
5912 /* Add a string attribute value to a DIE. */
5915 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5918 struct indirect_string_node *node;
5921 if (! debug_str_hash)
5922 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5923 debug_str_eq, NULL);
5925 slot = htab_find_slot_with_hash (debug_str_hash, str,
5926 htab_hash_string (str), INSERT);
5929 node = (struct indirect_string_node *)
5930 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5931 node->str = ggc_strdup (str);
5935 node = (struct indirect_string_node *) *slot;
5939 attr.dw_attr = attr_kind;
5940 attr.dw_attr_val.val_class = dw_val_class_str;
5941 attr.dw_attr_val.v.val_str = node;
5942 add_dwarf_attr (die, &attr);
5945 static inline const char *
5946 AT_string (dw_attr_ref a)
5948 gcc_assert (a && AT_class (a) == dw_val_class_str);
5949 return a->dw_attr_val.v.val_str->str;
5952 /* Find out whether a string should be output inline in DIE
5953 or out-of-line in .debug_str section. */
5956 AT_string_form (dw_attr_ref a)
5958 struct indirect_string_node *node;
5962 gcc_assert (a && AT_class (a) == dw_val_class_str);
5964 node = a->dw_attr_val.v.val_str;
5968 len = strlen (node->str) + 1;
5970 /* If the string is shorter or equal to the size of the reference, it is
5971 always better to put it inline. */
5972 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5973 return node->form = DW_FORM_string;
5975 /* If we cannot expect the linker to merge strings in .debug_str
5976 section, only put it into .debug_str if it is worth even in this
5978 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5979 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5980 return node->form = DW_FORM_string;
5982 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5983 ++dw2_string_counter;
5984 node->label = xstrdup (label);
5986 return node->form = DW_FORM_strp;
5989 /* Add a DIE reference attribute value to a DIE. */
5992 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5996 attr.dw_attr = attr_kind;
5997 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5998 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5999 attr.dw_attr_val.v.val_die_ref.external = 0;
6000 add_dwarf_attr (die, &attr);
6003 /* Add an AT_specification attribute to a DIE, and also make the back
6004 pointer from the specification to the definition. */
6007 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6009 add_AT_die_ref (die, DW_AT_specification, targ_die);
6010 gcc_assert (!targ_die->die_definition);
6011 targ_die->die_definition = die;
6014 static inline dw_die_ref
6015 AT_ref (dw_attr_ref a)
6017 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6018 return a->dw_attr_val.v.val_die_ref.die;
6022 AT_ref_external (dw_attr_ref a)
6024 if (a && AT_class (a) == dw_val_class_die_ref)
6025 return a->dw_attr_val.v.val_die_ref.external;
6031 set_AT_ref_external (dw_attr_ref a, int i)
6033 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6034 a->dw_attr_val.v.val_die_ref.external = i;
6037 /* Add an FDE reference attribute value to a DIE. */
6040 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6044 attr.dw_attr = attr_kind;
6045 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6046 attr.dw_attr_val.v.val_fde_index = targ_fde;
6047 add_dwarf_attr (die, &attr);
6050 /* Add a location description attribute value to a DIE. */
6053 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6057 attr.dw_attr = attr_kind;
6058 attr.dw_attr_val.val_class = dw_val_class_loc;
6059 attr.dw_attr_val.v.val_loc = loc;
6060 add_dwarf_attr (die, &attr);
6063 static inline dw_loc_descr_ref
6064 AT_loc (dw_attr_ref a)
6066 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6067 return a->dw_attr_val.v.val_loc;
6071 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6075 attr.dw_attr = attr_kind;
6076 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6077 attr.dw_attr_val.v.val_loc_list = loc_list;
6078 add_dwarf_attr (die, &attr);
6079 have_location_lists = true;
6082 static inline dw_loc_list_ref
6083 AT_loc_list (dw_attr_ref a)
6085 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6086 return a->dw_attr_val.v.val_loc_list;
6089 /* Add an address constant attribute value to a DIE. */
6092 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6096 attr.dw_attr = attr_kind;
6097 attr.dw_attr_val.val_class = dw_val_class_addr;
6098 attr.dw_attr_val.v.val_addr = addr;
6099 add_dwarf_attr (die, &attr);
6102 /* Get the RTX from to an address DIE attribute. */
6105 AT_addr (dw_attr_ref a)
6107 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6108 return a->dw_attr_val.v.val_addr;
6111 /* Add a file attribute value to a DIE. */
6114 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6115 struct dwarf_file_data *fd)
6119 attr.dw_attr = attr_kind;
6120 attr.dw_attr_val.val_class = dw_val_class_file;
6121 attr.dw_attr_val.v.val_file = fd;
6122 add_dwarf_attr (die, &attr);
6125 /* Get the dwarf_file_data from a file DIE attribute. */
6127 static inline struct dwarf_file_data *
6128 AT_file (dw_attr_ref a)
6130 gcc_assert (a && AT_class (a) == dw_val_class_file);
6131 return a->dw_attr_val.v.val_file;
6134 /* Add a label identifier attribute value to a DIE. */
6137 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6141 attr.dw_attr = attr_kind;
6142 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6143 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6144 add_dwarf_attr (die, &attr);
6147 /* Add a section offset attribute value to a DIE, an offset into the
6148 debug_line section. */
6151 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6156 attr.dw_attr = attr_kind;
6157 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6158 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6159 add_dwarf_attr (die, &attr);
6162 /* Add a section offset attribute value to a DIE, an offset into the
6163 debug_macinfo section. */
6166 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6171 attr.dw_attr = attr_kind;
6172 attr.dw_attr_val.val_class = dw_val_class_macptr;
6173 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6174 add_dwarf_attr (die, &attr);
6177 /* Add an offset attribute value to a DIE. */
6180 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6181 unsigned HOST_WIDE_INT offset)
6185 attr.dw_attr = attr_kind;
6186 attr.dw_attr_val.val_class = dw_val_class_offset;
6187 attr.dw_attr_val.v.val_offset = offset;
6188 add_dwarf_attr (die, &attr);
6191 /* Add an range_list attribute value to a DIE. */
6194 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6195 long unsigned int offset)
6199 attr.dw_attr = attr_kind;
6200 attr.dw_attr_val.val_class = dw_val_class_range_list;
6201 attr.dw_attr_val.v.val_offset = offset;
6202 add_dwarf_attr (die, &attr);
6205 static inline const char *
6206 AT_lbl (dw_attr_ref a)
6208 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6209 || AT_class (a) == dw_val_class_lineptr
6210 || AT_class (a) == dw_val_class_macptr));
6211 return a->dw_attr_val.v.val_lbl_id;
6214 /* Get the attribute of type attr_kind. */
6217 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6221 dw_die_ref spec = NULL;
6226 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6227 if (a->dw_attr == attr_kind)
6229 else if (a->dw_attr == DW_AT_specification
6230 || a->dw_attr == DW_AT_abstract_origin)
6234 return get_AT (spec, attr_kind);
6239 /* Return the "low pc" attribute value, typically associated with a subprogram
6240 DIE. Return null if the "low pc" attribute is either not present, or if it
6241 cannot be represented as an assembler label identifier. */
6243 static inline const char *
6244 get_AT_low_pc (dw_die_ref die)
6246 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6248 return a ? AT_lbl (a) : NULL;
6251 /* Return the "high pc" attribute value, typically associated with a subprogram
6252 DIE. Return null if the "high pc" attribute is either not present, or if it
6253 cannot be represented as an assembler label identifier. */
6255 static inline const char *
6256 get_AT_hi_pc (dw_die_ref die)
6258 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6260 return a ? AT_lbl (a) : NULL;
6263 /* Return the value of the string attribute designated by ATTR_KIND, or
6264 NULL if it is not present. */
6266 static inline const char *
6267 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6269 dw_attr_ref a = get_AT (die, attr_kind);
6271 return a ? AT_string (a) : NULL;
6274 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6275 if it is not present. */
6278 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6280 dw_attr_ref a = get_AT (die, attr_kind);
6282 return a ? AT_flag (a) : 0;
6285 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6286 if it is not present. */
6288 static inline unsigned
6289 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6291 dw_attr_ref a = get_AT (die, attr_kind);
6293 return a ? AT_unsigned (a) : 0;
6296 static inline dw_die_ref
6297 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6299 dw_attr_ref a = get_AT (die, attr_kind);
6301 return a ? AT_ref (a) : NULL;
6304 static inline struct dwarf_file_data *
6305 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6307 dw_attr_ref a = get_AT (die, attr_kind);
6309 return a ? AT_file (a) : NULL;
6312 /* Return TRUE if the language is C or C++. */
6317 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6319 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6320 || lang == DW_LANG_C99
6321 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6324 /* Return TRUE if the language is C++. */
6329 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6331 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6334 /* Return TRUE if the language is Fortran. */
6339 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6341 return (lang == DW_LANG_Fortran77
6342 || lang == DW_LANG_Fortran90
6343 || lang == DW_LANG_Fortran95);
6346 /* Return TRUE if the language is Java. */
6351 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6353 return lang == DW_LANG_Java;
6356 /* Return TRUE if the language is Ada. */
6361 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6363 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6366 /* Remove the specified attribute if present. */
6369 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6377 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6378 if (a->dw_attr == attr_kind)
6380 if (AT_class (a) == dw_val_class_str)
6381 if (a->dw_attr_val.v.val_str->refcount)
6382 a->dw_attr_val.v.val_str->refcount--;
6384 /* VEC_ordered_remove should help reduce the number of abbrevs
6386 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6391 /* Remove CHILD from its parent. PREV must have the property that
6392 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6395 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6397 gcc_assert (child->die_parent == prev->die_parent);
6398 gcc_assert (prev->die_sib == child);
6401 gcc_assert (child->die_parent->die_child == child);
6405 prev->die_sib = child->die_sib;
6406 if (child->die_parent->die_child == child)
6407 child->die_parent->die_child = prev;
6410 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6414 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6420 dw_die_ref prev = c;
6422 while (c->die_tag == tag)
6424 remove_child_with_prev (c, prev);
6425 /* Might have removed every child. */
6426 if (c == c->die_sib)
6430 } while (c != die->die_child);
6433 /* Add a CHILD_DIE as the last child of DIE. */
6436 add_child_die (dw_die_ref die, dw_die_ref child_die)
6438 /* FIXME this should probably be an assert. */
6439 if (! die || ! child_die)
6441 gcc_assert (die != child_die);
6443 child_die->die_parent = die;
6446 child_die->die_sib = die->die_child->die_sib;
6447 die->die_child->die_sib = child_die;
6450 child_die->die_sib = child_die;
6451 die->die_child = child_die;
6454 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6455 is the specification, to the end of PARENT's list of children.
6456 This is done by removing and re-adding it. */
6459 splice_child_die (dw_die_ref parent, dw_die_ref child)
6463 /* We want the declaration DIE from inside the class, not the
6464 specification DIE at toplevel. */
6465 if (child->die_parent != parent)
6467 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6473 gcc_assert (child->die_parent == parent
6474 || (child->die_parent
6475 == get_AT_ref (parent, DW_AT_specification)));
6477 for (p = child->die_parent->die_child; ; p = p->die_sib)
6478 if (p->die_sib == child)
6480 remove_child_with_prev (child, p);
6484 add_child_die (parent, child);
6487 /* Return a pointer to a newly created DIE node. */
6489 static inline dw_die_ref
6490 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6492 dw_die_ref die = GGC_CNEW (die_node);
6494 die->die_tag = tag_value;
6496 if (parent_die != NULL)
6497 add_child_die (parent_die, die);
6500 limbo_die_node *limbo_node;
6502 limbo_node = GGC_CNEW (limbo_die_node);
6503 limbo_node->die = die;
6504 limbo_node->created_for = t;
6505 limbo_node->next = limbo_die_list;
6506 limbo_die_list = limbo_node;
6512 /* Return the DIE associated with the given type specifier. */
6514 static inline dw_die_ref
6515 lookup_type_die (tree type)
6517 return TYPE_SYMTAB_DIE (type);
6520 /* Equate a DIE to a given type specifier. */
6523 equate_type_number_to_die (tree type, dw_die_ref type_die)
6525 TYPE_SYMTAB_DIE (type) = type_die;
6528 /* Returns a hash value for X (which really is a die_struct). */
6531 decl_die_table_hash (const void *x)
6533 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6536 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6539 decl_die_table_eq (const void *x, const void *y)
6541 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6544 /* Return the DIE associated with a given declaration. */
6546 static inline dw_die_ref
6547 lookup_decl_die (tree decl)
6549 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6552 /* Returns a hash value for X (which really is a var_loc_list). */
6555 decl_loc_table_hash (const void *x)
6557 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6560 /* Return nonzero if decl_id of var_loc_list X is the same as
6564 decl_loc_table_eq (const void *x, const void *y)
6566 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6569 /* Return the var_loc list associated with a given declaration. */
6571 static inline var_loc_list *
6572 lookup_decl_loc (const_tree decl)
6574 return (var_loc_list *)
6575 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6578 /* Equate a DIE to a particular declaration. */
6581 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6583 unsigned int decl_id = DECL_UID (decl);
6586 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6588 decl_die->decl_id = decl_id;
6591 /* Add a variable location node to the linked list for DECL. */
6594 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6596 unsigned int decl_id = DECL_UID (decl);
6600 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6603 temp = GGC_CNEW (var_loc_list);
6604 temp->decl_id = decl_id;
6608 temp = (var_loc_list *) *slot;
6612 /* If the current location is the same as the end of the list,
6613 and either both or neither of the locations is uninitialized,
6614 we have nothing to do. */
6615 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6616 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6617 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6618 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6619 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6620 == VAR_INIT_STATUS_UNINITIALIZED)
6621 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6622 == VAR_INIT_STATUS_UNINITIALIZED))))
6624 /* Add LOC to the end of list and update LAST. */
6625 temp->last->next = loc;
6629 /* Do not add empty location to the beginning of the list. */
6630 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
6637 /* Keep track of the number of spaces used to indent the
6638 output of the debugging routines that print the structure of
6639 the DIE internal representation. */
6640 static int print_indent;
6642 /* Indent the line the number of spaces given by print_indent. */
6645 print_spaces (FILE *outfile)
6647 fprintf (outfile, "%*s", print_indent, "");
6650 /* Print the information associated with a given DIE, and its children.
6651 This routine is a debugging aid only. */
6654 print_die (dw_die_ref die, FILE *outfile)
6660 print_spaces (outfile);
6661 fprintf (outfile, "DIE %4ld: %s\n",
6662 die->die_offset, dwarf_tag_name (die->die_tag));
6663 print_spaces (outfile);
6664 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6665 fprintf (outfile, " offset: %ld\n", die->die_offset);
6667 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6669 print_spaces (outfile);
6670 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6672 switch (AT_class (a))
6674 case dw_val_class_addr:
6675 fprintf (outfile, "address");
6677 case dw_val_class_offset:
6678 fprintf (outfile, "offset");
6680 case dw_val_class_loc:
6681 fprintf (outfile, "location descriptor");
6683 case dw_val_class_loc_list:
6684 fprintf (outfile, "location list -> label:%s",
6685 AT_loc_list (a)->ll_symbol);
6687 case dw_val_class_range_list:
6688 fprintf (outfile, "range list");
6690 case dw_val_class_const:
6691 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6693 case dw_val_class_unsigned_const:
6694 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6696 case dw_val_class_long_long:
6697 fprintf (outfile, "constant (%lu,%lu)",
6698 a->dw_attr_val.v.val_long_long.hi,
6699 a->dw_attr_val.v.val_long_long.low);
6701 case dw_val_class_vec:
6702 fprintf (outfile, "floating-point or vector constant");
6704 case dw_val_class_flag:
6705 fprintf (outfile, "%u", AT_flag (a));
6707 case dw_val_class_die_ref:
6708 if (AT_ref (a) != NULL)
6710 if (AT_ref (a)->die_symbol)
6711 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
6713 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6716 fprintf (outfile, "die -> <null>");
6718 case dw_val_class_lbl_id:
6719 case dw_val_class_lineptr:
6720 case dw_val_class_macptr:
6721 fprintf (outfile, "label: %s", AT_lbl (a));
6723 case dw_val_class_str:
6724 if (AT_string (a) != NULL)
6725 fprintf (outfile, "\"%s\"", AT_string (a));
6727 fprintf (outfile, "<null>");
6729 case dw_val_class_file:
6730 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6731 AT_file (a)->emitted_number);
6737 fprintf (outfile, "\n");
6740 if (die->die_child != NULL)
6743 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6746 if (print_indent == 0)
6747 fprintf (outfile, "\n");
6750 /* Print the contents of the source code line number correspondence table.
6751 This routine is a debugging aid only. */
6754 print_dwarf_line_table (FILE *outfile)
6757 dw_line_info_ref line_info;
6759 fprintf (outfile, "\n\nDWARF source line information\n");
6760 for (i = 1; i < line_info_table_in_use; i++)
6762 line_info = &line_info_table[i];
6763 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6764 line_info->dw_file_num,
6765 line_info->dw_line_num);
6768 fprintf (outfile, "\n\n");
6771 /* Print the information collected for a given DIE. */
6774 debug_dwarf_die (dw_die_ref die)
6776 print_die (die, stderr);
6779 /* Print all DWARF information collected for the compilation unit.
6780 This routine is a debugging aid only. */
6786 print_die (comp_unit_die, stderr);
6787 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6788 print_dwarf_line_table (stderr);
6791 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6792 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6793 DIE that marks the start of the DIEs for this include file. */
6796 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6798 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6799 dw_die_ref new_unit = gen_compile_unit_die (filename);
6801 new_unit->die_sib = old_unit;
6805 /* Close an include-file CU and reopen the enclosing one. */
6808 pop_compile_unit (dw_die_ref old_unit)
6810 dw_die_ref new_unit = old_unit->die_sib;
6812 old_unit->die_sib = NULL;
6816 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6817 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6819 /* Calculate the checksum of a location expression. */
6822 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6824 CHECKSUM (loc->dw_loc_opc);
6825 CHECKSUM (loc->dw_loc_oprnd1);
6826 CHECKSUM (loc->dw_loc_oprnd2);
6829 /* Calculate the checksum of an attribute. */
6832 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6834 dw_loc_descr_ref loc;
6837 CHECKSUM (at->dw_attr);
6839 /* We don't care that this was compiled with a different compiler
6840 snapshot; if the output is the same, that's what matters. */
6841 if (at->dw_attr == DW_AT_producer)
6844 switch (AT_class (at))
6846 case dw_val_class_const:
6847 CHECKSUM (at->dw_attr_val.v.val_int);
6849 case dw_val_class_unsigned_const:
6850 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6852 case dw_val_class_long_long:
6853 CHECKSUM (at->dw_attr_val.v.val_long_long);
6855 case dw_val_class_vec:
6856 CHECKSUM (at->dw_attr_val.v.val_vec);
6858 case dw_val_class_flag:
6859 CHECKSUM (at->dw_attr_val.v.val_flag);
6861 case dw_val_class_str:
6862 CHECKSUM_STRING (AT_string (at));
6865 case dw_val_class_addr:
6867 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6868 CHECKSUM_STRING (XSTR (r, 0));
6871 case dw_val_class_offset:
6872 CHECKSUM (at->dw_attr_val.v.val_offset);
6875 case dw_val_class_loc:
6876 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6877 loc_checksum (loc, ctx);
6880 case dw_val_class_die_ref:
6881 die_checksum (AT_ref (at), ctx, mark);
6884 case dw_val_class_fde_ref:
6885 case dw_val_class_lbl_id:
6886 case dw_val_class_lineptr:
6887 case dw_val_class_macptr:
6890 case dw_val_class_file:
6891 CHECKSUM_STRING (AT_file (at)->filename);
6899 /* Calculate the checksum of a DIE. */
6902 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6908 /* To avoid infinite recursion. */
6911 CHECKSUM (die->die_mark);
6914 die->die_mark = ++(*mark);
6916 CHECKSUM (die->die_tag);
6918 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6919 attr_checksum (a, ctx, mark);
6921 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6925 #undef CHECKSUM_STRING
6927 /* Do the location expressions look same? */
6929 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6931 return loc1->dw_loc_opc == loc2->dw_loc_opc
6932 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6933 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6936 /* Do the values look the same? */
6938 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6940 dw_loc_descr_ref loc1, loc2;
6943 if (v1->val_class != v2->val_class)
6946 switch (v1->val_class)
6948 case dw_val_class_const:
6949 return v1->v.val_int == v2->v.val_int;
6950 case dw_val_class_unsigned_const:
6951 return v1->v.val_unsigned == v2->v.val_unsigned;
6952 case dw_val_class_long_long:
6953 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6954 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6955 case dw_val_class_vec:
6956 if (v1->v.val_vec.length != v2->v.val_vec.length
6957 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6959 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6960 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6963 case dw_val_class_flag:
6964 return v1->v.val_flag == v2->v.val_flag;
6965 case dw_val_class_str:
6966 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6968 case dw_val_class_addr:
6969 r1 = v1->v.val_addr;
6970 r2 = v2->v.val_addr;
6971 if (GET_CODE (r1) != GET_CODE (r2))
6973 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6974 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6976 case dw_val_class_offset:
6977 return v1->v.val_offset == v2->v.val_offset;
6979 case dw_val_class_loc:
6980 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6982 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6983 if (!same_loc_p (loc1, loc2, mark))
6985 return !loc1 && !loc2;
6987 case dw_val_class_die_ref:
6988 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6990 case dw_val_class_fde_ref:
6991 case dw_val_class_lbl_id:
6992 case dw_val_class_lineptr:
6993 case dw_val_class_macptr:
6996 case dw_val_class_file:
6997 return v1->v.val_file == v2->v.val_file;
7004 /* Do the attributes look the same? */
7007 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7009 if (at1->dw_attr != at2->dw_attr)
7012 /* We don't care that this was compiled with a different compiler
7013 snapshot; if the output is the same, that's what matters. */
7014 if (at1->dw_attr == DW_AT_producer)
7017 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7020 /* Do the dies look the same? */
7023 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7029 /* To avoid infinite recursion. */
7031 return die1->die_mark == die2->die_mark;
7032 die1->die_mark = die2->die_mark = ++(*mark);
7034 if (die1->die_tag != die2->die_tag)
7037 if (VEC_length (dw_attr_node, die1->die_attr)
7038 != VEC_length (dw_attr_node, die2->die_attr))
7041 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7042 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7045 c1 = die1->die_child;
7046 c2 = die2->die_child;
7055 if (!same_die_p (c1, c2, mark))
7059 if (c1 == die1->die_child)
7061 if (c2 == die2->die_child)
7071 /* Do the dies look the same? Wrapper around same_die_p. */
7074 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7077 int ret = same_die_p (die1, die2, &mark);
7079 unmark_all_dies (die1);
7080 unmark_all_dies (die2);
7085 /* The prefix to attach to symbols on DIEs in the current comdat debug
7087 static char *comdat_symbol_id;
7089 /* The index of the current symbol within the current comdat CU. */
7090 static unsigned int comdat_symbol_number;
7092 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7093 children, and set comdat_symbol_id accordingly. */
7096 compute_section_prefix (dw_die_ref unit_die)
7098 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7099 const char *base = die_name ? lbasename (die_name) : "anonymous";
7100 char *name = XALLOCAVEC (char, strlen (base) + 64);
7103 unsigned char checksum[16];
7106 /* Compute the checksum of the DIE, then append part of it as hex digits to
7107 the name filename of the unit. */
7109 md5_init_ctx (&ctx);
7111 die_checksum (unit_die, &ctx, &mark);
7112 unmark_all_dies (unit_die);
7113 md5_finish_ctx (&ctx, checksum);
7115 sprintf (name, "%s.", base);
7116 clean_symbol_name (name);
7118 p = name + strlen (name);
7119 for (i = 0; i < 4; i++)
7121 sprintf (p, "%.2x", checksum[i]);
7125 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7126 comdat_symbol_number = 0;
7129 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7132 is_type_die (dw_die_ref die)
7134 switch (die->die_tag)
7136 case DW_TAG_array_type:
7137 case DW_TAG_class_type:
7138 case DW_TAG_interface_type:
7139 case DW_TAG_enumeration_type:
7140 case DW_TAG_pointer_type:
7141 case DW_TAG_reference_type:
7142 case DW_TAG_string_type:
7143 case DW_TAG_structure_type:
7144 case DW_TAG_subroutine_type:
7145 case DW_TAG_union_type:
7146 case DW_TAG_ptr_to_member_type:
7147 case DW_TAG_set_type:
7148 case DW_TAG_subrange_type:
7149 case DW_TAG_base_type:
7150 case DW_TAG_const_type:
7151 case DW_TAG_file_type:
7152 case DW_TAG_packed_type:
7153 case DW_TAG_volatile_type:
7154 case DW_TAG_typedef:
7161 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7162 Basically, we want to choose the bits that are likely to be shared between
7163 compilations (types) and leave out the bits that are specific to individual
7164 compilations (functions). */
7167 is_comdat_die (dw_die_ref c)
7169 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7170 we do for stabs. The advantage is a greater likelihood of sharing between
7171 objects that don't include headers in the same order (and therefore would
7172 put the base types in a different comdat). jason 8/28/00 */
7174 if (c->die_tag == DW_TAG_base_type)
7177 if (c->die_tag == DW_TAG_pointer_type
7178 || c->die_tag == DW_TAG_reference_type
7179 || c->die_tag == DW_TAG_const_type
7180 || c->die_tag == DW_TAG_volatile_type)
7182 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7184 return t ? is_comdat_die (t) : 0;
7187 return is_type_die (c);
7190 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7191 compilation unit. */
7194 is_symbol_die (dw_die_ref c)
7196 return (is_type_die (c)
7197 || (get_AT (c, DW_AT_declaration)
7198 && !get_AT (c, DW_AT_specification))
7199 || c->die_tag == DW_TAG_namespace
7200 || c->die_tag == DW_TAG_module);
7204 gen_internal_sym (const char *prefix)
7208 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7209 return xstrdup (buf);
7212 /* Assign symbols to all worthy DIEs under DIE. */
7215 assign_symbol_names (dw_die_ref die)
7219 if (is_symbol_die (die))
7221 if (comdat_symbol_id)
7223 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7225 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7226 comdat_symbol_id, comdat_symbol_number++);
7227 die->die_symbol = xstrdup (p);
7230 die->die_symbol = gen_internal_sym ("LDIE");
7233 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7236 struct cu_hash_table_entry
7239 unsigned min_comdat_num, max_comdat_num;
7240 struct cu_hash_table_entry *next;
7243 /* Routines to manipulate hash table of CUs. */
7245 htab_cu_hash (const void *of)
7247 const struct cu_hash_table_entry *const entry =
7248 (const struct cu_hash_table_entry *) of;
7250 return htab_hash_string (entry->cu->die_symbol);
7254 htab_cu_eq (const void *of1, const void *of2)
7256 const struct cu_hash_table_entry *const entry1 =
7257 (const struct cu_hash_table_entry *) of1;
7258 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7260 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7264 htab_cu_del (void *what)
7266 struct cu_hash_table_entry *next,
7267 *entry = (struct cu_hash_table_entry *) what;
7277 /* Check whether we have already seen this CU and set up SYM_NUM
7280 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7282 struct cu_hash_table_entry dummy;
7283 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7285 dummy.max_comdat_num = 0;
7287 slot = (struct cu_hash_table_entry **)
7288 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7292 for (; entry; last = entry, entry = entry->next)
7294 if (same_die_p_wrap (cu, entry->cu))
7300 *sym_num = entry->min_comdat_num;
7304 entry = XCNEW (struct cu_hash_table_entry);
7306 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7307 entry->next = *slot;
7313 /* Record SYM_NUM to record of CU in HTABLE. */
7315 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7317 struct cu_hash_table_entry **slot, *entry;
7319 slot = (struct cu_hash_table_entry **)
7320 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7324 entry->max_comdat_num = sym_num;
7327 /* Traverse the DIE (which is always comp_unit_die), and set up
7328 additional compilation units for each of the include files we see
7329 bracketed by BINCL/EINCL. */
7332 break_out_includes (dw_die_ref die)
7335 dw_die_ref unit = NULL;
7336 limbo_die_node *node, **pnode;
7337 htab_t cu_hash_table;
7341 dw_die_ref prev = c;
7343 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7344 || (unit && is_comdat_die (c)))
7346 dw_die_ref next = c->die_sib;
7348 /* This DIE is for a secondary CU; remove it from the main one. */
7349 remove_child_with_prev (c, prev);
7351 if (c->die_tag == DW_TAG_GNU_BINCL)
7352 unit = push_new_compile_unit (unit, c);
7353 else if (c->die_tag == DW_TAG_GNU_EINCL)
7354 unit = pop_compile_unit (unit);
7356 add_child_die (unit, c);
7358 if (c == die->die_child)
7361 } while (c != die->die_child);
7364 /* We can only use this in debugging, since the frontend doesn't check
7365 to make sure that we leave every include file we enter. */
7369 assign_symbol_names (die);
7370 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7371 for (node = limbo_die_list, pnode = &limbo_die_list;
7377 compute_section_prefix (node->die);
7378 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7379 &comdat_symbol_number);
7380 assign_symbol_names (node->die);
7382 *pnode = node->next;
7385 pnode = &node->next;
7386 record_comdat_symbol_number (node->die, cu_hash_table,
7387 comdat_symbol_number);
7390 htab_delete (cu_hash_table);
7393 /* Traverse the DIE and add a sibling attribute if it may have the
7394 effect of speeding up access to siblings. To save some space,
7395 avoid generating sibling attributes for DIE's without children. */
7398 add_sibling_attributes (dw_die_ref die)
7402 if (! die->die_child)
7405 if (die->die_parent && die != die->die_parent->die_child)
7406 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7408 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7411 /* Output all location lists for the DIE and its children. */
7414 output_location_lists (dw_die_ref die)
7420 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7421 if (AT_class (a) == dw_val_class_loc_list)
7422 output_loc_list (AT_loc_list (a));
7424 FOR_EACH_CHILD (die, c, output_location_lists (c));
7427 /* The format of each DIE (and its attribute value pairs) is encoded in an
7428 abbreviation table. This routine builds the abbreviation table and assigns
7429 a unique abbreviation id for each abbreviation entry. The children of each
7430 die are visited recursively. */
7433 build_abbrev_table (dw_die_ref die)
7435 unsigned long abbrev_id;
7436 unsigned int n_alloc;
7441 /* Scan the DIE references, and mark as external any that refer to
7442 DIEs from other CUs (i.e. those which are not marked). */
7443 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7444 if (AT_class (a) == dw_val_class_die_ref
7445 && AT_ref (a)->die_mark == 0)
7447 gcc_assert (AT_ref (a)->die_symbol);
7449 set_AT_ref_external (a, 1);
7452 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7454 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7455 dw_attr_ref die_a, abbrev_a;
7459 if (abbrev->die_tag != die->die_tag)
7461 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7464 if (VEC_length (dw_attr_node, abbrev->die_attr)
7465 != VEC_length (dw_attr_node, die->die_attr))
7468 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7470 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7471 if ((abbrev_a->dw_attr != die_a->dw_attr)
7472 || (value_format (abbrev_a) != value_format (die_a)))
7482 if (abbrev_id >= abbrev_die_table_in_use)
7484 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7486 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7487 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7490 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7491 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7492 abbrev_die_table_allocated = n_alloc;
7495 ++abbrev_die_table_in_use;
7496 abbrev_die_table[abbrev_id] = die;
7499 die->die_abbrev = abbrev_id;
7500 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7503 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7506 constant_size (long unsigned int value)
7513 log = floor_log2 (value);
7516 log = 1 << (floor_log2 (log) + 1);
7521 /* Return the size of a DIE as it is represented in the
7522 .debug_info section. */
7524 static unsigned long
7525 size_of_die (dw_die_ref die)
7527 unsigned long size = 0;
7531 size += size_of_uleb128 (die->die_abbrev);
7532 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7534 switch (AT_class (a))
7536 case dw_val_class_addr:
7537 size += DWARF2_ADDR_SIZE;
7539 case dw_val_class_offset:
7540 size += DWARF_OFFSET_SIZE;
7542 case dw_val_class_loc:
7544 unsigned long lsize = size_of_locs (AT_loc (a));
7547 size += constant_size (lsize);
7551 case dw_val_class_loc_list:
7552 size += DWARF_OFFSET_SIZE;
7554 case dw_val_class_range_list:
7555 size += DWARF_OFFSET_SIZE;
7557 case dw_val_class_const:
7558 size += size_of_sleb128 (AT_int (a));
7560 case dw_val_class_unsigned_const:
7561 size += constant_size (AT_unsigned (a));
7563 case dw_val_class_long_long:
7564 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7566 case dw_val_class_vec:
7567 size += 1 + (a->dw_attr_val.v.val_vec.length
7568 * a->dw_attr_val.v.val_vec.elt_size); /* block */
7570 case dw_val_class_flag:
7573 case dw_val_class_die_ref:
7574 if (AT_ref_external (a))
7575 size += DWARF2_ADDR_SIZE;
7577 size += DWARF_OFFSET_SIZE;
7579 case dw_val_class_fde_ref:
7580 size += DWARF_OFFSET_SIZE;
7582 case dw_val_class_lbl_id:
7583 size += DWARF2_ADDR_SIZE;
7585 case dw_val_class_lineptr:
7586 case dw_val_class_macptr:
7587 size += DWARF_OFFSET_SIZE;
7589 case dw_val_class_str:
7590 if (AT_string_form (a) == DW_FORM_strp)
7591 size += DWARF_OFFSET_SIZE;
7593 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7595 case dw_val_class_file:
7596 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7606 /* Size the debugging information associated with a given DIE. Visits the
7607 DIE's children recursively. Updates the global variable next_die_offset, on
7608 each time through. Uses the current value of next_die_offset to update the
7609 die_offset field in each DIE. */
7612 calc_die_sizes (dw_die_ref die)
7616 die->die_offset = next_die_offset;
7617 next_die_offset += size_of_die (die);
7619 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7621 if (die->die_child != NULL)
7622 /* Count the null byte used to terminate sibling lists. */
7623 next_die_offset += 1;
7626 /* Set the marks for a die and its children. We do this so
7627 that we know whether or not a reference needs to use FORM_ref_addr; only
7628 DIEs in the same CU will be marked. We used to clear out the offset
7629 and use that as the flag, but ran into ordering problems. */
7632 mark_dies (dw_die_ref die)
7636 gcc_assert (!die->die_mark);
7639 FOR_EACH_CHILD (die, c, mark_dies (c));
7642 /* Clear the marks for a die and its children. */
7645 unmark_dies (dw_die_ref die)
7649 gcc_assert (die->die_mark);
7652 FOR_EACH_CHILD (die, c, unmark_dies (c));
7655 /* Clear the marks for a die, its children and referred dies. */
7658 unmark_all_dies (dw_die_ref die)
7668 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7670 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7671 if (AT_class (a) == dw_val_class_die_ref)
7672 unmark_all_dies (AT_ref (a));
7675 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7676 generated for the compilation unit. */
7678 static unsigned long
7679 size_of_pubnames (VEC (pubname_entry, gc) * names)
7685 size = DWARF_PUBNAMES_HEADER_SIZE;
7686 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7687 if (names != pubtype_table
7688 || p->die->die_offset != 0
7689 || !flag_eliminate_unused_debug_types)
7690 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7692 size += DWARF_OFFSET_SIZE;
7696 /* Return the size of the information in the .debug_aranges section. */
7698 static unsigned long
7699 size_of_aranges (void)
7703 size = DWARF_ARANGES_HEADER_SIZE;
7705 /* Count the address/length pair for this compilation unit. */
7706 if (text_section_used)
7707 size += 2 * DWARF2_ADDR_SIZE;
7708 if (cold_text_section_used)
7709 size += 2 * DWARF2_ADDR_SIZE;
7710 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7712 /* Count the two zero words used to terminated the address range table. */
7713 size += 2 * DWARF2_ADDR_SIZE;
7717 /* Select the encoding of an attribute value. */
7719 static enum dwarf_form
7720 value_format (dw_attr_ref a)
7722 switch (a->dw_attr_val.val_class)
7724 case dw_val_class_addr:
7725 return DW_FORM_addr;
7726 case dw_val_class_range_list:
7727 case dw_val_class_offset:
7728 case dw_val_class_loc_list:
7729 switch (DWARF_OFFSET_SIZE)
7732 return DW_FORM_data4;
7734 return DW_FORM_data8;
7738 case dw_val_class_loc:
7739 switch (constant_size (size_of_locs (AT_loc (a))))
7742 return DW_FORM_block1;
7744 return DW_FORM_block2;
7748 case dw_val_class_const:
7749 return DW_FORM_sdata;
7750 case dw_val_class_unsigned_const:
7751 switch (constant_size (AT_unsigned (a)))
7754 return DW_FORM_data1;
7756 return DW_FORM_data2;
7758 return DW_FORM_data4;
7760 return DW_FORM_data8;
7764 case dw_val_class_long_long:
7765 return DW_FORM_block1;
7766 case dw_val_class_vec:
7767 return DW_FORM_block1;
7768 case dw_val_class_flag:
7769 return DW_FORM_flag;
7770 case dw_val_class_die_ref:
7771 if (AT_ref_external (a))
7772 return DW_FORM_ref_addr;
7775 case dw_val_class_fde_ref:
7776 return DW_FORM_data;
7777 case dw_val_class_lbl_id:
7778 return DW_FORM_addr;
7779 case dw_val_class_lineptr:
7780 case dw_val_class_macptr:
7781 return DW_FORM_data;
7782 case dw_val_class_str:
7783 return AT_string_form (a);
7784 case dw_val_class_file:
7785 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7788 return DW_FORM_data1;
7790 return DW_FORM_data2;
7792 return DW_FORM_data4;
7802 /* Output the encoding of an attribute value. */
7805 output_value_format (dw_attr_ref a)
7807 enum dwarf_form form = value_format (a);
7809 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7812 /* Output the .debug_abbrev section which defines the DIE abbreviation
7816 output_abbrev_section (void)
7818 unsigned long abbrev_id;
7820 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7822 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7826 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7827 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7828 dwarf_tag_name (abbrev->die_tag));
7830 if (abbrev->die_child != NULL)
7831 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7833 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7835 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7838 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7839 dwarf_attr_name (a_attr->dw_attr));
7840 output_value_format (a_attr);
7843 dw2_asm_output_data (1, 0, NULL);
7844 dw2_asm_output_data (1, 0, NULL);
7847 /* Terminate the table. */
7848 dw2_asm_output_data (1, 0, NULL);
7851 /* Output a symbol we can use to refer to this DIE from another CU. */
7854 output_die_symbol (dw_die_ref die)
7856 char *sym = die->die_symbol;
7861 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7862 /* We make these global, not weak; if the target doesn't support
7863 .linkonce, it doesn't support combining the sections, so debugging
7865 targetm.asm_out.globalize_label (asm_out_file, sym);
7867 ASM_OUTPUT_LABEL (asm_out_file, sym);
7870 /* Return a new location list, given the begin and end range, and the
7871 expression. gensym tells us whether to generate a new internal symbol for
7872 this location list node, which is done for the head of the list only. */
7874 static inline dw_loc_list_ref
7875 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7876 const char *section, unsigned int gensym)
7878 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7880 retlist->begin = begin;
7882 retlist->expr = expr;
7883 retlist->section = section;
7885 retlist->ll_symbol = gen_internal_sym ("LLST");
7890 /* Add a location description expression to a location list. */
7893 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7894 const char *begin, const char *end,
7895 const char *section)
7899 /* Find the end of the chain. */
7900 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7903 /* Add a new location list node to the list. */
7904 *d = new_loc_list (descr, begin, end, section, 0);
7907 /* Output the location list given to us. */
7910 output_loc_list (dw_loc_list_ref list_head)
7912 dw_loc_list_ref curr = list_head;
7914 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7916 /* Walk the location list, and output each range + expression. */
7917 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7920 /* Don't output an entry that starts and ends at the same address. */
7921 if (strcmp (curr->begin, curr->end) == 0)
7923 if (!have_multiple_function_sections)
7925 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7926 "Location list begin address (%s)",
7927 list_head->ll_symbol);
7928 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7929 "Location list end address (%s)",
7930 list_head->ll_symbol);
7934 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7935 "Location list begin address (%s)",
7936 list_head->ll_symbol);
7937 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7938 "Location list end address (%s)",
7939 list_head->ll_symbol);
7941 size = size_of_locs (curr->expr);
7943 /* Output the block length for this list of location operations. */
7944 gcc_assert (size <= 0xffff);
7945 dw2_asm_output_data (2, size, "%s", "Location expression size");
7947 output_loc_sequence (curr->expr);
7950 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7951 "Location list terminator begin (%s)",
7952 list_head->ll_symbol);
7953 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7954 "Location list terminator end (%s)",
7955 list_head->ll_symbol);
7958 /* Output the DIE and its attributes. Called recursively to generate
7959 the definitions of each child DIE. */
7962 output_die (dw_die_ref die)
7969 /* If someone in another CU might refer to us, set up a symbol for
7970 them to point to. */
7971 if (die->die_symbol)
7972 output_die_symbol (die);
7974 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7975 (unsigned long)die->die_offset,
7976 dwarf_tag_name (die->die_tag));
7978 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7980 const char *name = dwarf_attr_name (a->dw_attr);
7982 switch (AT_class (a))
7984 case dw_val_class_addr:
7985 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7988 case dw_val_class_offset:
7989 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7993 case dw_val_class_range_list:
7995 char *p = strchr (ranges_section_label, '\0');
7997 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7998 a->dw_attr_val.v.val_offset);
7999 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8000 debug_ranges_section, "%s", name);
8005 case dw_val_class_loc:
8006 size = size_of_locs (AT_loc (a));
8008 /* Output the block length for this list of location operations. */
8009 dw2_asm_output_data (constant_size (size), size, "%s", name);
8011 output_loc_sequence (AT_loc (a));
8014 case dw_val_class_const:
8015 /* ??? It would be slightly more efficient to use a scheme like is
8016 used for unsigned constants below, but gdb 4.x does not sign
8017 extend. Gdb 5.x does sign extend. */
8018 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8021 case dw_val_class_unsigned_const:
8022 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8023 AT_unsigned (a), "%s", name);
8026 case dw_val_class_long_long:
8028 unsigned HOST_WIDE_INT first, second;
8030 dw2_asm_output_data (1,
8031 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8034 if (WORDS_BIG_ENDIAN)
8036 first = a->dw_attr_val.v.val_long_long.hi;
8037 second = a->dw_attr_val.v.val_long_long.low;
8041 first = a->dw_attr_val.v.val_long_long.low;
8042 second = a->dw_attr_val.v.val_long_long.hi;
8045 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8046 first, "long long constant");
8047 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8052 case dw_val_class_vec:
8054 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8055 unsigned int len = a->dw_attr_val.v.val_vec.length;
8059 dw2_asm_output_data (1, len * elt_size, "%s", name);
8060 if (elt_size > sizeof (HOST_WIDE_INT))
8065 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8068 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8069 "fp or vector constant word %u", i);
8073 case dw_val_class_flag:
8074 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8077 case dw_val_class_loc_list:
8079 char *sym = AT_loc_list (a)->ll_symbol;
8082 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8087 case dw_val_class_die_ref:
8088 if (AT_ref_external (a))
8090 char *sym = AT_ref (a)->die_symbol;
8093 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8098 gcc_assert (AT_ref (a)->die_offset);
8099 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8104 case dw_val_class_fde_ref:
8108 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8109 a->dw_attr_val.v.val_fde_index * 2);
8110 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8115 case dw_val_class_lbl_id:
8116 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8119 case dw_val_class_lineptr:
8120 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8121 debug_line_section, "%s", name);
8124 case dw_val_class_macptr:
8125 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8126 debug_macinfo_section, "%s", name);
8129 case dw_val_class_str:
8130 if (AT_string_form (a) == DW_FORM_strp)
8131 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8132 a->dw_attr_val.v.val_str->label,
8134 "%s: \"%s\"", name, AT_string (a));
8136 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8139 case dw_val_class_file:
8141 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8143 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8144 a->dw_attr_val.v.val_file->filename);
8153 FOR_EACH_CHILD (die, c, output_die (c));
8155 /* Add null byte to terminate sibling list. */
8156 if (die->die_child != NULL)
8157 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8158 (unsigned long) die->die_offset);
8161 /* Output the compilation unit that appears at the beginning of the
8162 .debug_info section, and precedes the DIE descriptions. */
8165 output_compilation_unit_header (void)
8167 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8168 dw2_asm_output_data (4, 0xffffffff,
8169 "Initial length escape value indicating 64-bit DWARF extension");
8170 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8171 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8172 "Length of Compilation Unit Info");
8173 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8174 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8175 debug_abbrev_section,
8176 "Offset Into Abbrev. Section");
8177 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8180 /* Output the compilation unit DIE and its children. */
8183 output_comp_unit (dw_die_ref die, int output_if_empty)
8185 const char *secname;
8188 /* Unless we are outputting main CU, we may throw away empty ones. */
8189 if (!output_if_empty && die->die_child == NULL)
8192 /* Even if there are no children of this DIE, we must output the information
8193 about the compilation unit. Otherwise, on an empty translation unit, we
8194 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8195 will then complain when examining the file. First mark all the DIEs in
8196 this CU so we know which get local refs. */
8199 build_abbrev_table (die);
8201 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8202 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8203 calc_die_sizes (die);
8205 oldsym = die->die_symbol;
8208 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8210 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8212 die->die_symbol = NULL;
8213 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8216 switch_to_section (debug_info_section);
8218 /* Output debugging information. */
8219 output_compilation_unit_header ();
8222 /* Leave the marks on the main CU, so we can check them in
8227 die->die_symbol = oldsym;
8231 /* Return the DWARF2/3 pubname associated with a decl. */
8234 dwarf2_name (tree decl, int scope)
8236 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8239 /* Add a new entry to .debug_pubnames if appropriate. */
8242 add_pubname_string (const char *str, dw_die_ref die)
8247 e.name = xstrdup (str);
8248 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8252 add_pubname (tree decl, dw_die_ref die)
8255 if (TREE_PUBLIC (decl))
8256 add_pubname_string (dwarf2_name (decl, 1), die);
8259 /* Add a new entry to .debug_pubtypes if appropriate. */
8262 add_pubtype (tree decl, dw_die_ref die)
8267 if ((TREE_PUBLIC (decl)
8268 || die->die_parent == comp_unit_die)
8269 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8274 if (TYPE_NAME (decl))
8276 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8277 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8278 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8279 && DECL_NAME (TYPE_NAME (decl)))
8280 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8282 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8286 e.name = xstrdup (dwarf2_name (decl, 1));
8288 /* If we don't have a name for the type, there's no point in adding
8290 if (e.name && e.name[0] != '\0')
8291 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8295 /* Output the public names table used to speed up access to externally
8296 visible names; or the public types table used to find type definitions. */
8299 output_pubnames (VEC (pubname_entry, gc) * names)
8302 unsigned long pubnames_length = size_of_pubnames (names);
8305 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8306 dw2_asm_output_data (4, 0xffffffff,
8307 "Initial length escape value indicating 64-bit DWARF extension");
8308 if (names == pubname_table)
8309 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8310 "Length of Public Names Info");
8312 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8313 "Length of Public Type Names Info");
8314 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8315 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8317 "Offset of Compilation Unit Info");
8318 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8319 "Compilation Unit Length");
8321 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8323 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8324 if (names == pubname_table)
8325 gcc_assert (pub->die->die_mark);
8327 if (names != pubtype_table
8328 || pub->die->die_offset != 0
8329 || !flag_eliminate_unused_debug_types)
8331 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8334 dw2_asm_output_nstring (pub->name, -1, "external name");
8338 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8341 /* Add a new entry to .debug_aranges if appropriate. */
8344 add_arange (tree decl, dw_die_ref die)
8346 if (! DECL_SECTION_NAME (decl))
8349 if (arange_table_in_use == arange_table_allocated)
8351 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8352 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8353 arange_table_allocated);
8354 memset (arange_table + arange_table_in_use, 0,
8355 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8358 arange_table[arange_table_in_use++] = die;
8361 /* Output the information that goes into the .debug_aranges table.
8362 Namely, define the beginning and ending address range of the
8363 text section generated for this compilation unit. */
8366 output_aranges (void)
8369 unsigned long aranges_length = size_of_aranges ();
8371 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8372 dw2_asm_output_data (4, 0xffffffff,
8373 "Initial length escape value indicating 64-bit DWARF extension");
8374 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8375 "Length of Address Ranges Info");
8376 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8377 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8379 "Offset of Compilation Unit Info");
8380 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8381 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8383 /* We need to align to twice the pointer size here. */
8384 if (DWARF_ARANGES_PAD_SIZE)
8386 /* Pad using a 2 byte words so that padding is correct for any
8388 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8389 2 * DWARF2_ADDR_SIZE);
8390 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8391 dw2_asm_output_data (2, 0, NULL);
8394 /* It is necessary not to output these entries if the sections were
8395 not used; if the sections were not used, the length will be 0 and
8396 the address may end up as 0 if the section is discarded by ld
8397 --gc-sections, leaving an invalid (0, 0) entry that can be
8398 confused with the terminator. */
8399 if (text_section_used)
8401 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8402 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8403 text_section_label, "Length");
8405 if (cold_text_section_used)
8407 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8409 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8410 cold_text_section_label, "Length");
8413 for (i = 0; i < arange_table_in_use; i++)
8415 dw_die_ref die = arange_table[i];
8417 /* We shouldn't see aranges for DIEs outside of the main CU. */
8418 gcc_assert (die->die_mark);
8420 if (die->die_tag == DW_TAG_subprogram)
8422 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8424 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8425 get_AT_low_pc (die), "Length");
8429 /* A static variable; extract the symbol from DW_AT_location.
8430 Note that this code isn't currently hit, as we only emit
8431 aranges for functions (jason 9/23/99). */
8432 dw_attr_ref a = get_AT (die, DW_AT_location);
8433 dw_loc_descr_ref loc;
8435 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8438 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8440 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8441 loc->dw_loc_oprnd1.v.val_addr, "Address");
8442 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8443 get_AT_unsigned (die, DW_AT_byte_size),
8448 /* Output the terminator words. */
8449 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8450 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8453 /* Add a new entry to .debug_ranges. Return the offset at which it
8457 add_ranges_num (int num)
8459 unsigned int in_use = ranges_table_in_use;
8461 if (in_use == ranges_table_allocated)
8463 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8464 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8465 ranges_table_allocated);
8466 memset (ranges_table + ranges_table_in_use, 0,
8467 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8470 ranges_table[in_use].num = num;
8471 ranges_table_in_use = in_use + 1;
8473 return in_use * 2 * DWARF2_ADDR_SIZE;
8476 /* Add a new entry to .debug_ranges corresponding to a block, or a
8477 range terminator if BLOCK is NULL. */
8480 add_ranges (const_tree block)
8482 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8485 /* Add a new entry to .debug_ranges corresponding to a pair of
8489 add_ranges_by_labels (const char *begin, const char *end)
8491 unsigned int in_use = ranges_by_label_in_use;
8493 if (in_use == ranges_by_label_allocated)
8495 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8496 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8498 ranges_by_label_allocated);
8499 memset (ranges_by_label + ranges_by_label_in_use, 0,
8500 RANGES_TABLE_INCREMENT
8501 * sizeof (struct dw_ranges_by_label_struct));
8504 ranges_by_label[in_use].begin = begin;
8505 ranges_by_label[in_use].end = end;
8506 ranges_by_label_in_use = in_use + 1;
8508 return add_ranges_num (-(int)in_use - 1);
8512 output_ranges (void)
8515 static const char *const start_fmt = "Offset 0x%x";
8516 const char *fmt = start_fmt;
8518 for (i = 0; i < ranges_table_in_use; i++)
8520 int block_num = ranges_table[i].num;
8524 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8525 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8527 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8528 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8530 /* If all code is in the text section, then the compilation
8531 unit base address defaults to DW_AT_low_pc, which is the
8532 base of the text section. */
8533 if (!have_multiple_function_sections)
8535 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8537 fmt, i * 2 * DWARF2_ADDR_SIZE);
8538 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8539 text_section_label, NULL);
8542 /* Otherwise, the compilation unit base address is zero,
8543 which allows us to use absolute addresses, and not worry
8544 about whether the target supports cross-section
8548 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8549 fmt, i * 2 * DWARF2_ADDR_SIZE);
8550 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8556 /* Negative block_num stands for an index into ranges_by_label. */
8557 else if (block_num < 0)
8559 int lab_idx = - block_num - 1;
8561 if (!have_multiple_function_sections)
8565 /* If we ever use add_ranges_by_labels () for a single
8566 function section, all we have to do is to take out
8568 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8569 ranges_by_label[lab_idx].begin,
8571 fmt, i * 2 * DWARF2_ADDR_SIZE);
8572 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8573 ranges_by_label[lab_idx].end,
8574 text_section_label, NULL);
8579 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8580 ranges_by_label[lab_idx].begin,
8581 fmt, i * 2 * DWARF2_ADDR_SIZE);
8582 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8583 ranges_by_label[lab_idx].end,
8589 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8590 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8596 /* Data structure containing information about input files. */
8599 const char *path; /* Complete file name. */
8600 const char *fname; /* File name part. */
8601 int length; /* Length of entire string. */
8602 struct dwarf_file_data * file_idx; /* Index in input file table. */
8603 int dir_idx; /* Index in directory table. */
8606 /* Data structure containing information about directories with source
8610 const char *path; /* Path including directory name. */
8611 int length; /* Path length. */
8612 int prefix; /* Index of directory entry which is a prefix. */
8613 int count; /* Number of files in this directory. */
8614 int dir_idx; /* Index of directory used as base. */
8617 /* Callback function for file_info comparison. We sort by looking at
8618 the directories in the path. */
8621 file_info_cmp (const void *p1, const void *p2)
8623 const struct file_info *const s1 = (const struct file_info *) p1;
8624 const struct file_info *const s2 = (const struct file_info *) p2;
8625 const unsigned char *cp1;
8626 const unsigned char *cp2;
8628 /* Take care of file names without directories. We need to make sure that
8629 we return consistent values to qsort since some will get confused if
8630 we return the same value when identical operands are passed in opposite
8631 orders. So if neither has a directory, return 0 and otherwise return
8632 1 or -1 depending on which one has the directory. */
8633 if ((s1->path == s1->fname || s2->path == s2->fname))
8634 return (s2->path == s2->fname) - (s1->path == s1->fname);
8636 cp1 = (const unsigned char *) s1->path;
8637 cp2 = (const unsigned char *) s2->path;
8643 /* Reached the end of the first path? If so, handle like above. */
8644 if ((cp1 == (const unsigned char *) s1->fname)
8645 || (cp2 == (const unsigned char *) s2->fname))
8646 return ((cp2 == (const unsigned char *) s2->fname)
8647 - (cp1 == (const unsigned char *) s1->fname));
8649 /* Character of current path component the same? */
8650 else if (*cp1 != *cp2)
8655 struct file_name_acquire_data
8657 struct file_info *files;
8662 /* Traversal function for the hash table. */
8665 file_name_acquire (void ** slot, void *data)
8667 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8668 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8669 struct file_info *fi;
8672 gcc_assert (fnad->max_files >= d->emitted_number);
8674 if (! d->emitted_number)
8677 gcc_assert (fnad->max_files != fnad->used_files);
8679 fi = fnad->files + fnad->used_files++;
8681 /* Skip all leading "./". */
8683 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8686 /* Create a new array entry. */
8688 fi->length = strlen (f);
8691 /* Search for the file name part. */
8692 f = strrchr (f, DIR_SEPARATOR);
8693 #if defined (DIR_SEPARATOR_2)
8695 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8699 if (f == NULL || f < g)
8705 fi->fname = f == NULL ? fi->path : f + 1;
8709 /* Output the directory table and the file name table. We try to minimize
8710 the total amount of memory needed. A heuristic is used to avoid large
8711 slowdowns with many input files. */
8714 output_file_names (void)
8716 struct file_name_acquire_data fnad;
8718 struct file_info *files;
8719 struct dir_info *dirs;
8728 if (!last_emitted_file)
8730 dw2_asm_output_data (1, 0, "End directory table");
8731 dw2_asm_output_data (1, 0, "End file name table");
8735 numfiles = last_emitted_file->emitted_number;
8737 /* Allocate the various arrays we need. */
8738 files = XALLOCAVEC (struct file_info, numfiles);
8739 dirs = XALLOCAVEC (struct dir_info, numfiles);
8742 fnad.used_files = 0;
8743 fnad.max_files = numfiles;
8744 htab_traverse (file_table, file_name_acquire, &fnad);
8745 gcc_assert (fnad.used_files == fnad.max_files);
8747 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8749 /* Find all the different directories used. */
8750 dirs[0].path = files[0].path;
8751 dirs[0].length = files[0].fname - files[0].path;
8752 dirs[0].prefix = -1;
8754 dirs[0].dir_idx = 0;
8755 files[0].dir_idx = 0;
8758 for (i = 1; i < numfiles; i++)
8759 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8760 && memcmp (dirs[ndirs - 1].path, files[i].path,
8761 dirs[ndirs - 1].length) == 0)
8763 /* Same directory as last entry. */
8764 files[i].dir_idx = ndirs - 1;
8765 ++dirs[ndirs - 1].count;
8771 /* This is a new directory. */
8772 dirs[ndirs].path = files[i].path;
8773 dirs[ndirs].length = files[i].fname - files[i].path;
8774 dirs[ndirs].count = 1;
8775 dirs[ndirs].dir_idx = ndirs;
8776 files[i].dir_idx = ndirs;
8778 /* Search for a prefix. */
8779 dirs[ndirs].prefix = -1;
8780 for (j = 0; j < ndirs; j++)
8781 if (dirs[j].length < dirs[ndirs].length
8782 && dirs[j].length > 1
8783 && (dirs[ndirs].prefix == -1
8784 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8785 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8786 dirs[ndirs].prefix = j;
8791 /* Now to the actual work. We have to find a subset of the directories which
8792 allow expressing the file name using references to the directory table
8793 with the least amount of characters. We do not do an exhaustive search
8794 where we would have to check out every combination of every single
8795 possible prefix. Instead we use a heuristic which provides nearly optimal
8796 results in most cases and never is much off. */
8797 saved = XALLOCAVEC (int, ndirs);
8798 savehere = XALLOCAVEC (int, ndirs);
8800 memset (saved, '\0', ndirs * sizeof (saved[0]));
8801 for (i = 0; i < ndirs; i++)
8806 /* We can always save some space for the current directory. But this
8807 does not mean it will be enough to justify adding the directory. */
8808 savehere[i] = dirs[i].length;
8809 total = (savehere[i] - saved[i]) * dirs[i].count;
8811 for (j = i + 1; j < ndirs; j++)
8814 if (saved[j] < dirs[i].length)
8816 /* Determine whether the dirs[i] path is a prefix of the
8821 while (k != -1 && k != (int) i)
8826 /* Yes it is. We can possibly save some memory by
8827 writing the filenames in dirs[j] relative to
8829 savehere[j] = dirs[i].length;
8830 total += (savehere[j] - saved[j]) * dirs[j].count;
8835 /* Check whether we can save enough to justify adding the dirs[i]
8837 if (total > dirs[i].length + 1)
8839 /* It's worthwhile adding. */
8840 for (j = i; j < ndirs; j++)
8841 if (savehere[j] > 0)
8843 /* Remember how much we saved for this directory so far. */
8844 saved[j] = savehere[j];
8846 /* Remember the prefix directory. */
8847 dirs[j].dir_idx = i;
8852 /* Emit the directory name table. */
8854 idx_offset = dirs[0].length > 0 ? 1 : 0;
8855 for (i = 1 - idx_offset; i < ndirs; i++)
8856 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8857 "Directory Entry: 0x%x", i + idx_offset);
8859 dw2_asm_output_data (1, 0, "End directory table");
8861 /* We have to emit them in the order of emitted_number since that's
8862 used in the debug info generation. To do this efficiently we
8863 generate a back-mapping of the indices first. */
8864 backmap = XALLOCAVEC (int, numfiles);
8865 for (i = 0; i < numfiles; i++)
8866 backmap[files[i].file_idx->emitted_number - 1] = i;
8868 /* Now write all the file names. */
8869 for (i = 0; i < numfiles; i++)
8871 int file_idx = backmap[i];
8872 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8874 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8875 "File Entry: 0x%x", (unsigned) i + 1);
8877 /* Include directory index. */
8878 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8880 /* Modification time. */
8881 dw2_asm_output_data_uleb128 (0, NULL);
8883 /* File length in bytes. */
8884 dw2_asm_output_data_uleb128 (0, NULL);
8887 dw2_asm_output_data (1, 0, "End file name table");
8891 /* Output the source line number correspondence information. This
8892 information goes into the .debug_line section. */
8895 output_line_info (void)
8897 char l1[20], l2[20], p1[20], p2[20];
8898 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8899 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8902 unsigned long lt_index;
8903 unsigned long current_line;
8906 unsigned long current_file;
8907 unsigned long function;
8909 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8910 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8911 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8912 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8914 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8915 dw2_asm_output_data (4, 0xffffffff,
8916 "Initial length escape value indicating 64-bit DWARF extension");
8917 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8918 "Length of Source Line Info");
8919 ASM_OUTPUT_LABEL (asm_out_file, l1);
8921 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8922 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8923 ASM_OUTPUT_LABEL (asm_out_file, p1);
8925 /* Define the architecture-dependent minimum instruction length (in
8926 bytes). In this implementation of DWARF, this field is used for
8927 information purposes only. Since GCC generates assembly language,
8928 we have no a priori knowledge of how many instruction bytes are
8929 generated for each source line, and therefore can use only the
8930 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8931 commands. Accordingly, we fix this as `1', which is "correct
8932 enough" for all architectures, and don't let the target override. */
8933 dw2_asm_output_data (1, 1,
8934 "Minimum Instruction Length");
8936 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8937 "Default is_stmt_start flag");
8938 dw2_asm_output_data (1, DWARF_LINE_BASE,
8939 "Line Base Value (Special Opcodes)");
8940 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8941 "Line Range Value (Special Opcodes)");
8942 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8943 "Special Opcode Base");
8945 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8949 case DW_LNS_advance_pc:
8950 case DW_LNS_advance_line:
8951 case DW_LNS_set_file:
8952 case DW_LNS_set_column:
8953 case DW_LNS_fixed_advance_pc:
8961 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8965 /* Write out the information about the files we use. */
8966 output_file_names ();
8967 ASM_OUTPUT_LABEL (asm_out_file, p2);
8969 /* We used to set the address register to the first location in the text
8970 section here, but that didn't accomplish anything since we already
8971 have a line note for the opening brace of the first function. */
8973 /* Generate the line number to PC correspondence table, encoded as
8974 a series of state machine operations. */
8978 if (cfun && in_cold_section_p)
8979 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8981 strcpy (prev_line_label, text_section_label);
8982 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8984 dw_line_info_ref line_info = &line_info_table[lt_index];
8987 /* Disable this optimization for now; GDB wants to see two line notes
8988 at the beginning of a function so it can find the end of the
8991 /* Don't emit anything for redundant notes. Just updating the
8992 address doesn't accomplish anything, because we already assume
8993 that anything after the last address is this line. */
8994 if (line_info->dw_line_num == current_line
8995 && line_info->dw_file_num == current_file)
8999 /* Emit debug info for the address of the current line.
9001 Unfortunately, we have little choice here currently, and must always
9002 use the most general form. GCC does not know the address delta
9003 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9004 attributes which will give an upper bound on the address range. We
9005 could perhaps use length attributes to determine when it is safe to
9006 use DW_LNS_fixed_advance_pc. */
9008 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9011 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9012 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9013 "DW_LNS_fixed_advance_pc");
9014 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9018 /* This can handle any delta. This takes
9019 4+DWARF2_ADDR_SIZE bytes. */
9020 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9021 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9022 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9023 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9026 strcpy (prev_line_label, line_label);
9028 /* Emit debug info for the source file of the current line, if
9029 different from the previous line. */
9030 if (line_info->dw_file_num != current_file)
9032 current_file = line_info->dw_file_num;
9033 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9034 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9037 /* Emit debug info for the current line number, choosing the encoding
9038 that uses the least amount of space. */
9039 if (line_info->dw_line_num != current_line)
9041 line_offset = line_info->dw_line_num - current_line;
9042 line_delta = line_offset - DWARF_LINE_BASE;
9043 current_line = line_info->dw_line_num;
9044 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9045 /* This can handle deltas from -10 to 234, using the current
9046 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9048 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9049 "line %lu", current_line);
9052 /* This can handle any delta. This takes at least 4 bytes,
9053 depending on the value being encoded. */
9054 dw2_asm_output_data (1, DW_LNS_advance_line,
9055 "advance to line %lu", current_line);
9056 dw2_asm_output_data_sleb128 (line_offset, NULL);
9057 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9061 /* We still need to start a new row, so output a copy insn. */
9062 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9065 /* Emit debug info for the address of the end of the function. */
9068 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9069 "DW_LNS_fixed_advance_pc");
9070 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9074 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9075 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9076 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9077 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9080 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9081 dw2_asm_output_data_uleb128 (1, NULL);
9082 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9087 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9089 dw_separate_line_info_ref line_info
9090 = &separate_line_info_table[lt_index];
9093 /* Don't emit anything for redundant notes. */
9094 if (line_info->dw_line_num == current_line
9095 && line_info->dw_file_num == current_file
9096 && line_info->function == function)
9100 /* Emit debug info for the address of the current line. If this is
9101 a new function, or the first line of a function, then we need
9102 to handle it differently. */
9103 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9105 if (function != line_info->function)
9107 function = line_info->function;
9109 /* Set the address register to the first line in the function. */
9110 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9111 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9112 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9113 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9117 /* ??? See the DW_LNS_advance_pc comment above. */
9120 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9121 "DW_LNS_fixed_advance_pc");
9122 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9126 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9127 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9128 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9129 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9133 strcpy (prev_line_label, line_label);
9135 /* Emit debug info for the source file of the current line, if
9136 different from the previous line. */
9137 if (line_info->dw_file_num != current_file)
9139 current_file = line_info->dw_file_num;
9140 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9141 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9144 /* Emit debug info for the current line number, choosing the encoding
9145 that uses the least amount of space. */
9146 if (line_info->dw_line_num != current_line)
9148 line_offset = line_info->dw_line_num - current_line;
9149 line_delta = line_offset - DWARF_LINE_BASE;
9150 current_line = line_info->dw_line_num;
9151 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9152 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9153 "line %lu", current_line);
9156 dw2_asm_output_data (1, DW_LNS_advance_line,
9157 "advance to line %lu", current_line);
9158 dw2_asm_output_data_sleb128 (line_offset, NULL);
9159 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9163 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9171 /* If we're done with a function, end its sequence. */
9172 if (lt_index == separate_line_info_table_in_use
9173 || separate_line_info_table[lt_index].function != function)
9178 /* Emit debug info for the address of the end of the function. */
9179 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9182 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9183 "DW_LNS_fixed_advance_pc");
9184 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9188 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9189 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9190 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9191 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9194 /* Output the marker for the end of this sequence. */
9195 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9196 dw2_asm_output_data_uleb128 (1, NULL);
9197 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9201 /* Output the marker for the end of the line number info. */
9202 ASM_OUTPUT_LABEL (asm_out_file, l2);
9205 /* Given a pointer to a tree node for some base type, return a pointer to
9206 a DIE that describes the given type.
9208 This routine must only be called for GCC type nodes that correspond to
9209 Dwarf base (fundamental) types. */
9212 base_type_die (tree type)
9214 dw_die_ref base_type_result;
9215 enum dwarf_type encoding;
9217 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9220 switch (TREE_CODE (type))
9223 if (TYPE_STRING_FLAG (type))
9225 if (TYPE_UNSIGNED (type))
9226 encoding = DW_ATE_unsigned_char;
9228 encoding = DW_ATE_signed_char;
9230 else if (TYPE_UNSIGNED (type))
9231 encoding = DW_ATE_unsigned;
9233 encoding = DW_ATE_signed;
9237 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9238 encoding = DW_ATE_decimal_float;
9240 encoding = DW_ATE_float;
9243 case FIXED_POINT_TYPE:
9244 if (TYPE_UNSIGNED (type))
9245 encoding = DW_ATE_unsigned_fixed;
9247 encoding = DW_ATE_signed_fixed;
9250 /* Dwarf2 doesn't know anything about complex ints, so use
9251 a user defined type for it. */
9253 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9254 encoding = DW_ATE_complex_float;
9256 encoding = DW_ATE_lo_user;
9260 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9261 encoding = DW_ATE_boolean;
9265 /* No other TREE_CODEs are Dwarf fundamental types. */
9269 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9271 /* This probably indicates a bug. */
9272 if (! TYPE_NAME (type))
9273 add_name_attribute (base_type_result, "__unknown__");
9275 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9276 int_size_in_bytes (type));
9277 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9279 return base_type_result;
9282 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9283 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9286 is_base_type (tree type)
9288 switch (TREE_CODE (type))
9294 case FIXED_POINT_TYPE:
9302 case QUAL_UNION_TYPE:
9307 case REFERENCE_TYPE:
9320 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9321 node, return the size in bits for the type if it is a constant, or else
9322 return the alignment for the type if the type's size is not constant, or
9323 else return BITS_PER_WORD if the type actually turns out to be an
9326 static inline unsigned HOST_WIDE_INT
9327 simple_type_size_in_bits (const_tree type)
9329 if (TREE_CODE (type) == ERROR_MARK)
9330 return BITS_PER_WORD;
9331 else if (TYPE_SIZE (type) == NULL_TREE)
9333 else if (host_integerp (TYPE_SIZE (type), 1))
9334 return tree_low_cst (TYPE_SIZE (type), 1);
9336 return TYPE_ALIGN (type);
9339 /* Return true if the debug information for the given type should be
9340 emitted as a subrange type. */
9343 is_subrange_type (const_tree type)
9345 tree subtype = TREE_TYPE (type);
9347 /* Subrange types are identified by the fact that they are integer
9348 types, and that they have a subtype which is either an integer type
9349 or an enumeral type. */
9351 if (TREE_CODE (type) != INTEGER_TYPE
9352 || subtype == NULL_TREE)
9355 if (TREE_CODE (subtype) != INTEGER_TYPE
9356 && TREE_CODE (subtype) != ENUMERAL_TYPE
9357 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9360 if (TREE_CODE (type) == TREE_CODE (subtype)
9361 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9362 && TYPE_MIN_VALUE (type) != NULL
9363 && TYPE_MIN_VALUE (subtype) != NULL
9364 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9365 && TYPE_MAX_VALUE (type) != NULL
9366 && TYPE_MAX_VALUE (subtype) != NULL
9367 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9369 /* The type and its subtype have the same representation. If in
9370 addition the two types also have the same name, then the given
9371 type is not a subrange type, but rather a plain base type. */
9372 /* FIXME: brobecker/2004-03-22:
9373 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9374 therefore be sufficient to check the TYPE_SIZE node pointers
9375 rather than checking the actual size. Unfortunately, we have
9376 found some cases, such as in the Ada "integer" type, where
9377 this is not the case. Until this problem is solved, we need to
9378 keep checking the actual size. */
9379 tree type_name = TYPE_NAME (type);
9380 tree subtype_name = TYPE_NAME (subtype);
9382 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9383 type_name = DECL_NAME (type_name);
9385 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9386 subtype_name = DECL_NAME (subtype_name);
9388 if (type_name == subtype_name)
9395 /* Given a pointer to a tree node for a subrange type, return a pointer
9396 to a DIE that describes the given type. */
9399 subrange_type_die (tree type, dw_die_ref context_die)
9401 dw_die_ref subrange_die;
9402 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9404 if (context_die == NULL)
9405 context_die = comp_unit_die;
9407 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9409 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9411 /* The size of the subrange type and its base type do not match,
9412 so we need to generate a size attribute for the subrange type. */
9413 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9416 if (TYPE_MIN_VALUE (type) != NULL)
9417 add_bound_info (subrange_die, DW_AT_lower_bound,
9418 TYPE_MIN_VALUE (type));
9419 if (TYPE_MAX_VALUE (type) != NULL)
9420 add_bound_info (subrange_die, DW_AT_upper_bound,
9421 TYPE_MAX_VALUE (type));
9423 return subrange_die;
9426 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9427 entry that chains various modifiers in front of the given type. */
9430 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9431 dw_die_ref context_die)
9433 enum tree_code code = TREE_CODE (type);
9434 dw_die_ref mod_type_die;
9435 dw_die_ref sub_die = NULL;
9436 tree item_type = NULL;
9437 tree qualified_type;
9440 if (code == ERROR_MARK)
9443 /* See if we already have the appropriately qualified variant of
9446 = get_qualified_type (type,
9447 ((is_const_type ? TYPE_QUAL_CONST : 0)
9448 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9450 /* If we do, then we can just use its DIE, if it exists. */
9453 mod_type_die = lookup_type_die (qualified_type);
9455 return mod_type_die;
9458 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9460 /* Handle C typedef types. */
9461 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9463 tree dtype = TREE_TYPE (name);
9465 if (qualified_type == dtype)
9467 /* For a named type, use the typedef. */
9468 gen_type_die (qualified_type, context_die);
9469 return lookup_type_die (qualified_type);
9471 else if (is_const_type < TYPE_READONLY (dtype)
9472 || is_volatile_type < TYPE_VOLATILE (dtype)
9473 || (is_const_type <= TYPE_READONLY (dtype)
9474 && is_volatile_type <= TYPE_VOLATILE (dtype)
9475 && DECL_ORIGINAL_TYPE (name) != type))
9476 /* cv-unqualified version of named type. Just use the unnamed
9477 type to which it refers. */
9478 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9479 is_const_type, is_volatile_type,
9481 /* Else cv-qualified version of named type; fall through. */
9486 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9487 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9489 else if (is_volatile_type)
9491 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9492 sub_die = modified_type_die (type, 0, 0, context_die);
9494 else if (code == POINTER_TYPE)
9496 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9497 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9498 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9499 item_type = TREE_TYPE (type);
9501 else if (code == REFERENCE_TYPE)
9503 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9504 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9505 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9506 item_type = TREE_TYPE (type);
9508 else if (is_subrange_type (type))
9510 mod_type_die = subrange_type_die (type, context_die);
9511 item_type = TREE_TYPE (type);
9513 else if (is_base_type (type))
9514 mod_type_die = base_type_die (type);
9517 gen_type_die (type, context_die);
9519 /* We have to get the type_main_variant here (and pass that to the
9520 `lookup_type_die' routine) because the ..._TYPE node we have
9521 might simply be a *copy* of some original type node (where the
9522 copy was created to help us keep track of typedef names) and
9523 that copy might have a different TYPE_UID from the original
9525 if (TREE_CODE (type) != VECTOR_TYPE)
9526 return lookup_type_die (type_main_variant (type));
9528 /* Vectors have the debugging information in the type,
9529 not the main variant. */
9530 return lookup_type_die (type);
9533 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9534 don't output a DW_TAG_typedef, since there isn't one in the
9535 user's program; just attach a DW_AT_name to the type. */
9537 && (TREE_CODE (name) != TYPE_DECL
9538 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9540 if (TREE_CODE (name) == TYPE_DECL)
9541 /* Could just call add_name_and_src_coords_attributes here,
9542 but since this is a builtin type it doesn't have any
9543 useful source coordinates anyway. */
9544 name = DECL_NAME (name);
9545 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9549 equate_type_number_to_die (qualified_type, mod_type_die);
9552 /* We must do this after the equate_type_number_to_die call, in case
9553 this is a recursive type. This ensures that the modified_type_die
9554 recursion will terminate even if the type is recursive. Recursive
9555 types are possible in Ada. */
9556 sub_die = modified_type_die (item_type,
9557 TYPE_READONLY (item_type),
9558 TYPE_VOLATILE (item_type),
9561 if (sub_die != NULL)
9562 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9564 return mod_type_die;
9567 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9568 an enumerated type. */
9571 type_is_enum (const_tree type)
9573 return TREE_CODE (type) == ENUMERAL_TYPE;
9576 /* Return the DBX register number described by a given RTL node. */
9579 dbx_reg_number (const_rtx rtl)
9581 unsigned regno = REGNO (rtl);
9583 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9585 #ifdef LEAF_REG_REMAP
9586 if (current_function_uses_only_leaf_regs)
9588 int leaf_reg = LEAF_REG_REMAP (regno);
9590 regno = (unsigned) leaf_reg;
9594 return DBX_REGISTER_NUMBER (regno);
9597 /* Optionally add a DW_OP_piece term to a location description expression.
9598 DW_OP_piece is only added if the location description expression already
9599 doesn't end with DW_OP_piece. */
9602 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9604 dw_loc_descr_ref loc;
9606 if (*list_head != NULL)
9608 /* Find the end of the chain. */
9609 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9612 if (loc->dw_loc_opc != DW_OP_piece)
9613 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9617 /* Return a location descriptor that designates a machine register or
9618 zero if there is none. */
9620 static dw_loc_descr_ref
9621 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9625 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9628 regs = targetm.dwarf_register_span (rtl);
9630 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9631 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9633 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9636 /* Return a location descriptor that designates a machine register for
9637 a given hard register number. */
9639 static dw_loc_descr_ref
9640 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9642 dw_loc_descr_ref reg_loc_descr = new_reg_loc_descr (regno, 0);
9644 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9645 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9647 return reg_loc_descr;
9650 /* Given an RTL of a register, return a location descriptor that
9651 designates a value that spans more than one register. */
9653 static dw_loc_descr_ref
9654 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9655 enum var_init_status initialized)
9659 dw_loc_descr_ref loc_result = NULL;
9662 #ifdef LEAF_REG_REMAP
9663 if (current_function_uses_only_leaf_regs)
9665 int leaf_reg = LEAF_REG_REMAP (reg);
9667 reg = (unsigned) leaf_reg;
9670 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9671 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9673 /* Simple, contiguous registers. */
9674 if (regs == NULL_RTX)
9676 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9683 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9684 VAR_INIT_STATUS_INITIALIZED);
9685 add_loc_descr (&loc_result, t);
9686 add_loc_descr_op_piece (&loc_result, size);
9692 /* Now onto stupid register sets in non contiguous locations. */
9694 gcc_assert (GET_CODE (regs) == PARALLEL);
9696 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9699 for (i = 0; i < XVECLEN (regs, 0); ++i)
9703 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9704 VAR_INIT_STATUS_INITIALIZED);
9705 add_loc_descr (&loc_result, t);
9706 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9707 add_loc_descr_op_piece (&loc_result, size);
9710 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9711 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9715 #endif /* DWARF2_DEBUGGING_INFO */
9717 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9719 /* Return a location descriptor that designates a constant. */
9721 static dw_loc_descr_ref
9722 int_loc_descriptor (HOST_WIDE_INT i)
9724 enum dwarf_location_atom op;
9726 /* Pick the smallest representation of a constant, rather than just
9727 defaulting to the LEB encoding. */
9731 op = DW_OP_lit0 + i;
9734 else if (i <= 0xffff)
9736 else if (HOST_BITS_PER_WIDE_INT == 32
9746 else if (i >= -0x8000)
9748 else if (HOST_BITS_PER_WIDE_INT == 32
9749 || i >= -0x80000000)
9755 return new_loc_descr (op, i, 0);
9759 #ifdef DWARF2_DEBUGGING_INFO
9761 /* Return a location descriptor that designates a base+offset location. */
9763 static dw_loc_descr_ref
9764 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9765 enum var_init_status initialized)
9768 dw_loc_descr_ref result;
9769 dw_fde_ref fde = current_fde ();
9771 /* We only use "frame base" when we're sure we're talking about the
9772 post-prologue local stack frame. We do this by *not* running
9773 register elimination until this point, and recognizing the special
9774 argument pointer and soft frame pointer rtx's. */
9775 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9777 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9781 if (GET_CODE (elim) == PLUS)
9783 offset += INTVAL (XEXP (elim, 1));
9784 elim = XEXP (elim, 0);
9786 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9787 && (elim == hard_frame_pointer_rtx
9788 || elim == stack_pointer_rtx))
9789 || elim == (frame_pointer_needed
9790 ? hard_frame_pointer_rtx
9791 : stack_pointer_rtx));
9793 /* If drap register is used to align stack, use frame
9794 pointer + offset to access stack variables. If stack
9795 is aligned without drap, use stack pointer + offset to
9796 access stack variables. */
9797 if (crtl->stack_realign_tried
9798 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9799 && reg == frame_pointer_rtx)
9802 = DWARF_FRAME_REGNUM (cfa.indirect
9803 ? HARD_FRAME_POINTER_REGNUM
9804 : STACK_POINTER_REGNUM);
9805 return new_reg_loc_descr (base_reg, offset);
9808 offset += frame_pointer_fb_offset;
9809 return new_loc_descr (DW_OP_fbreg, offset, 0);
9813 && fde->drap_reg != INVALID_REGNUM
9814 && (fde->drap_reg == REGNO (reg)
9815 || fde->vdrap_reg == REGNO (reg)))
9817 /* Use cfa+offset to represent the location of arguments passed
9818 on stack when drap is used to align stack. */
9819 return new_loc_descr (DW_OP_fbreg, offset, 0);
9822 regno = dbx_reg_number (reg);
9824 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9826 result = new_loc_descr (DW_OP_bregx, regno, offset);
9828 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9829 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9834 /* Return true if this RTL expression describes a base+offset calculation. */
9837 is_based_loc (const_rtx rtl)
9839 return (GET_CODE (rtl) == PLUS
9840 && ((REG_P (XEXP (rtl, 0))
9841 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9842 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9845 /* Return a descriptor that describes the concatenation of N locations
9846 used to form the address of a memory location. */
9848 static dw_loc_descr_ref
9849 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9850 enum var_init_status initialized)
9853 dw_loc_descr_ref cc_loc_result = NULL;
9854 unsigned int n = XVECLEN (concatn, 0);
9856 for (i = 0; i < n; ++i)
9858 dw_loc_descr_ref ref;
9859 rtx x = XVECEXP (concatn, 0, i);
9861 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9865 add_loc_descr (&cc_loc_result, ref);
9866 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9869 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9870 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9872 return cc_loc_result;
9875 /* The following routine converts the RTL for a variable or parameter
9876 (resident in memory) into an equivalent Dwarf representation of a
9877 mechanism for getting the address of that same variable onto the top of a
9878 hypothetical "address evaluation" stack.
9880 When creating memory location descriptors, we are effectively transforming
9881 the RTL for a memory-resident object into its Dwarf postfix expression
9882 equivalent. This routine recursively descends an RTL tree, turning
9883 it into Dwarf postfix code as it goes.
9885 MODE is the mode of the memory reference, needed to handle some
9886 autoincrement addressing modes.
9888 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9889 location list for RTL.
9891 Return 0 if we can't represent the location. */
9893 static dw_loc_descr_ref
9894 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9895 enum var_init_status initialized)
9897 dw_loc_descr_ref mem_loc_result = NULL;
9898 enum dwarf_location_atom op;
9900 /* Note that for a dynamically sized array, the location we will generate a
9901 description of here will be the lowest numbered location which is
9902 actually within the array. That's *not* necessarily the same as the
9903 zeroth element of the array. */
9905 rtl = targetm.delegitimize_address (rtl);
9907 switch (GET_CODE (rtl))
9912 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9913 just fall into the SUBREG code. */
9915 /* ... fall through ... */
9918 /* The case of a subreg may arise when we have a local (register)
9919 variable or a formal (register) parameter which doesn't quite fill
9920 up an entire register. For now, just assume that it is
9921 legitimate to make the Dwarf info refer to the whole register which
9922 contains the given subreg. */
9923 rtl = XEXP (rtl, 0);
9925 /* ... fall through ... */
9928 /* Whenever a register number forms a part of the description of the
9929 method for calculating the (dynamic) address of a memory resident
9930 object, DWARF rules require the register number be referred to as
9931 a "base register". This distinction is not based in any way upon
9932 what category of register the hardware believes the given register
9933 belongs to. This is strictly DWARF terminology we're dealing with
9934 here. Note that in cases where the location of a memory-resident
9935 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9936 OP_CONST (0)) the actual DWARF location descriptor that we generate
9937 may just be OP_BASEREG (basereg). This may look deceptively like
9938 the object in question was allocated to a register (rather than in
9939 memory) so DWARF consumers need to be aware of the subtle
9940 distinction between OP_REG and OP_BASEREG. */
9941 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9942 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9946 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9947 VAR_INIT_STATUS_INITIALIZED);
9948 if (mem_loc_result != 0)
9949 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9953 rtl = XEXP (rtl, 1);
9955 /* ... fall through ... */
9958 /* Some ports can transform a symbol ref into a label ref, because
9959 the symbol ref is too far away and has to be dumped into a constant
9963 /* Alternatively, the symbol in the constant pool might be referenced
9964 by a different symbol. */
9965 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9968 rtx tmp = get_pool_constant_mark (rtl, &marked);
9970 if (GET_CODE (tmp) == SYMBOL_REF)
9973 if (CONSTANT_POOL_ADDRESS_P (tmp))
9974 get_pool_constant_mark (tmp, &marked);
9979 /* If all references to this pool constant were optimized away,
9980 it was not output and thus we can't represent it.
9981 FIXME: might try to use DW_OP_const_value here, though
9982 DW_OP_piece complicates it. */
9987 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9988 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9989 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9990 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9994 /* Extract the PLUS expression nested inside and fall into
9996 rtl = XEXP (rtl, 1);
10001 /* Turn these into a PLUS expression and fall into the PLUS code
10003 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10004 GEN_INT (GET_CODE (rtl) == PRE_INC
10005 ? GET_MODE_UNIT_SIZE (mode)
10006 : -GET_MODE_UNIT_SIZE (mode)));
10008 /* ... fall through ... */
10012 if (is_based_loc (rtl))
10013 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10014 INTVAL (XEXP (rtl, 1)),
10015 VAR_INIT_STATUS_INITIALIZED);
10018 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10019 VAR_INIT_STATUS_INITIALIZED);
10020 if (mem_loc_result == 0)
10023 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
10024 && INTVAL (XEXP (rtl, 1)) >= 0)
10025 add_loc_descr (&mem_loc_result,
10026 new_loc_descr (DW_OP_plus_uconst,
10027 INTVAL (XEXP (rtl, 1)), 0));
10030 add_loc_descr (&mem_loc_result,
10031 mem_loc_descriptor (XEXP (rtl, 1), mode,
10032 VAR_INIT_STATUS_INITIALIZED));
10033 add_loc_descr (&mem_loc_result,
10034 new_loc_descr (DW_OP_plus, 0, 0));
10039 /* If a pseudo-reg is optimized away, it is possible for it to
10040 be replaced with a MEM containing a multiply or shift. */
10059 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10060 VAR_INIT_STATUS_INITIALIZED);
10061 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10062 VAR_INIT_STATUS_INITIALIZED);
10064 if (op0 == 0 || op1 == 0)
10067 mem_loc_result = op0;
10068 add_loc_descr (&mem_loc_result, op1);
10069 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10074 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10078 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10079 VAR_INIT_STATUS_INITIALIZED);
10083 gcc_unreachable ();
10086 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10087 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10089 return mem_loc_result;
10092 /* Return a descriptor that describes the concatenation of two locations.
10093 This is typically a complex variable. */
10095 static dw_loc_descr_ref
10096 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10098 dw_loc_descr_ref cc_loc_result = NULL;
10099 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10100 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10102 if (x0_ref == 0 || x1_ref == 0)
10105 cc_loc_result = x0_ref;
10106 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10108 add_loc_descr (&cc_loc_result, x1_ref);
10109 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10111 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10112 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10114 return cc_loc_result;
10117 /* Return a descriptor that describes the concatenation of N
10120 static dw_loc_descr_ref
10121 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10124 dw_loc_descr_ref cc_loc_result = NULL;
10125 unsigned int n = XVECLEN (concatn, 0);
10127 for (i = 0; i < n; ++i)
10129 dw_loc_descr_ref ref;
10130 rtx x = XVECEXP (concatn, 0, i);
10132 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10136 add_loc_descr (&cc_loc_result, ref);
10137 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10140 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10141 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10143 return cc_loc_result;
10146 /* Output a proper Dwarf location descriptor for a variable or parameter
10147 which is either allocated in a register or in a memory location. For a
10148 register, we just generate an OP_REG and the register number. For a
10149 memory location we provide a Dwarf postfix expression describing how to
10150 generate the (dynamic) address of the object onto the address stack.
10152 If we don't know how to describe it, return 0. */
10154 static dw_loc_descr_ref
10155 loc_descriptor (rtx rtl, enum var_init_status initialized)
10157 dw_loc_descr_ref loc_result = NULL;
10159 switch (GET_CODE (rtl))
10162 /* The case of a subreg may arise when we have a local (register)
10163 variable or a formal (register) parameter which doesn't quite fill
10164 up an entire register. For now, just assume that it is
10165 legitimate to make the Dwarf info refer to the whole register which
10166 contains the given subreg. */
10167 rtl = SUBREG_REG (rtl);
10169 /* ... fall through ... */
10172 loc_result = reg_loc_descriptor (rtl, initialized);
10176 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10181 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10186 loc_result = concatn_loc_descriptor (rtl, initialized);
10191 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10193 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10197 rtl = XEXP (rtl, 1);
10202 rtvec par_elems = XVEC (rtl, 0);
10203 int num_elem = GET_NUM_ELEM (par_elems);
10204 enum machine_mode mode;
10207 /* Create the first one, so we have something to add to. */
10208 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10210 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10211 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10212 for (i = 1; i < num_elem; i++)
10214 dw_loc_descr_ref temp;
10216 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10218 add_loc_descr (&loc_result, temp);
10219 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10220 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10226 gcc_unreachable ();
10232 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10233 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10234 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10235 top-level invocation, and we require the address of LOC; is 0 if we require
10236 the value of LOC. */
10238 static dw_loc_descr_ref
10239 loc_descriptor_from_tree_1 (tree loc, int want_address)
10241 dw_loc_descr_ref ret, ret1;
10242 int have_address = 0;
10243 enum dwarf_location_atom op;
10245 /* ??? Most of the time we do not take proper care for sign/zero
10246 extending the values properly. Hopefully this won't be a real
10249 switch (TREE_CODE (loc))
10254 case PLACEHOLDER_EXPR:
10255 /* This case involves extracting fields from an object to determine the
10256 position of other fields. We don't try to encode this here. The
10257 only user of this is Ada, which encodes the needed information using
10258 the names of types. */
10264 case PREINCREMENT_EXPR:
10265 case PREDECREMENT_EXPR:
10266 case POSTINCREMENT_EXPR:
10267 case POSTDECREMENT_EXPR:
10268 /* There are no opcodes for these operations. */
10272 /* If we already want an address, there's nothing we can do. */
10276 /* Otherwise, process the argument and look for the address. */
10277 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10280 if (DECL_THREAD_LOCAL_P (loc))
10284 unsigned second_op;
10286 if (targetm.have_tls)
10288 /* If this is not defined, we have no way to emit the
10290 if (!targetm.asm_out.output_dwarf_dtprel)
10293 /* The way DW_OP_GNU_push_tls_address is specified, we
10294 can only look up addresses of objects in the current
10296 if (DECL_EXTERNAL (loc))
10298 first_op = INTERNAL_DW_OP_tls_addr;
10299 second_op = DW_OP_GNU_push_tls_address;
10303 if (!targetm.emutls.debug_form_tls_address)
10305 loc = emutls_decl (loc);
10306 first_op = DW_OP_addr;
10307 second_op = DW_OP_form_tls_address;
10310 rtl = rtl_for_decl_location (loc);
10311 if (rtl == NULL_RTX)
10316 rtl = XEXP (rtl, 0);
10317 if (! CONSTANT_P (rtl))
10320 ret = new_loc_descr (first_op, 0, 0);
10321 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10322 ret->dw_loc_oprnd1.v.val_addr = rtl;
10324 ret1 = new_loc_descr (second_op, 0, 0);
10325 add_loc_descr (&ret, ret1);
10333 if (DECL_HAS_VALUE_EXPR_P (loc))
10334 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10339 case FUNCTION_DECL:
10341 rtx rtl = rtl_for_decl_location (loc);
10343 if (rtl == NULL_RTX)
10345 else if (GET_CODE (rtl) == CONST_INT)
10347 HOST_WIDE_INT val = INTVAL (rtl);
10348 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10349 val &= GET_MODE_MASK (DECL_MODE (loc));
10350 ret = int_loc_descriptor (val);
10352 else if (GET_CODE (rtl) == CONST_STRING)
10354 else if (CONSTANT_P (rtl))
10356 ret = new_loc_descr (DW_OP_addr, 0, 0);
10357 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10358 ret->dw_loc_oprnd1.v.val_addr = rtl;
10362 enum machine_mode mode;
10364 /* Certain constructs can only be represented at top-level. */
10365 if (want_address == 2)
10366 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10368 mode = GET_MODE (rtl);
10371 rtl = XEXP (rtl, 0);
10374 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10380 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10384 case COMPOUND_EXPR:
10385 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10388 case VIEW_CONVERT_EXPR:
10391 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10393 case COMPONENT_REF:
10394 case BIT_FIELD_REF:
10396 case ARRAY_RANGE_REF:
10399 HOST_WIDE_INT bitsize, bitpos, bytepos;
10400 enum machine_mode mode;
10402 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10404 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10405 &unsignedp, &volatilep, false);
10410 ret = loc_descriptor_from_tree_1 (obj, 1);
10412 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10415 if (offset != NULL_TREE)
10417 /* Variable offset. */
10418 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
10419 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10422 bytepos = bitpos / BITS_PER_UNIT;
10424 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10425 else if (bytepos < 0)
10427 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10428 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10436 if (host_integerp (loc, 0))
10437 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10444 /* Get an RTL for this, if something has been emitted. */
10445 rtx rtl = lookup_constant_def (loc);
10446 enum machine_mode mode;
10448 if (!rtl || !MEM_P (rtl))
10450 mode = GET_MODE (rtl);
10451 rtl = XEXP (rtl, 0);
10452 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10457 case TRUTH_AND_EXPR:
10458 case TRUTH_ANDIF_EXPR:
10463 case TRUTH_XOR_EXPR:
10468 case TRUTH_OR_EXPR:
10469 case TRUTH_ORIF_EXPR:
10474 case FLOOR_DIV_EXPR:
10475 case CEIL_DIV_EXPR:
10476 case ROUND_DIV_EXPR:
10477 case TRUNC_DIV_EXPR:
10485 case FLOOR_MOD_EXPR:
10486 case CEIL_MOD_EXPR:
10487 case ROUND_MOD_EXPR:
10488 case TRUNC_MOD_EXPR:
10501 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10504 case POINTER_PLUS_EXPR:
10506 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10507 && host_integerp (TREE_OPERAND (loc, 1), 0))
10509 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10513 add_loc_descr (&ret,
10514 new_loc_descr (DW_OP_plus_uconst,
10515 tree_low_cst (TREE_OPERAND (loc, 1),
10525 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10532 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10539 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10546 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10561 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10562 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10563 if (ret == 0 || ret1 == 0)
10566 add_loc_descr (&ret, ret1);
10567 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10570 case TRUTH_NOT_EXPR:
10584 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10588 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10594 const enum tree_code code =
10595 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10597 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10598 build2 (code, integer_type_node,
10599 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10600 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10603 /* ... fall through ... */
10607 dw_loc_descr_ref lhs
10608 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10609 dw_loc_descr_ref rhs
10610 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10611 dw_loc_descr_ref bra_node, jump_node, tmp;
10613 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10614 if (ret == 0 || lhs == 0 || rhs == 0)
10617 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10618 add_loc_descr (&ret, bra_node);
10620 add_loc_descr (&ret, rhs);
10621 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10622 add_loc_descr (&ret, jump_node);
10624 add_loc_descr (&ret, lhs);
10625 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10626 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10628 /* ??? Need a node to point the skip at. Use a nop. */
10629 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10630 add_loc_descr (&ret, tmp);
10631 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10632 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10636 case FIX_TRUNC_EXPR:
10640 /* Leave front-end specific codes as simply unknown. This comes
10641 up, for instance, with the C STMT_EXPR. */
10642 if ((unsigned int) TREE_CODE (loc)
10643 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10646 #ifdef ENABLE_CHECKING
10647 /* Otherwise this is a generic code; we should just lists all of
10648 these explicitly. We forgot one. */
10649 gcc_unreachable ();
10651 /* In a release build, we want to degrade gracefully: better to
10652 generate incomplete debugging information than to crash. */
10657 /* Show if we can't fill the request for an address. */
10658 if (want_address && !have_address)
10661 /* If we've got an address and don't want one, dereference. */
10662 if (!want_address && have_address && ret)
10664 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10666 if (size > DWARF2_ADDR_SIZE || size == -1)
10668 else if (size == DWARF2_ADDR_SIZE)
10671 op = DW_OP_deref_size;
10673 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10679 static inline dw_loc_descr_ref
10680 loc_descriptor_from_tree (tree loc)
10682 return loc_descriptor_from_tree_1 (loc, 2);
10685 /* Given a value, round it up to the lowest multiple of `boundary'
10686 which is not less than the value itself. */
10688 static inline HOST_WIDE_INT
10689 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10691 return (((value + boundary - 1) / boundary) * boundary);
10694 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10695 pointer to the declared type for the relevant field variable, or return
10696 `integer_type_node' if the given node turns out to be an
10697 ERROR_MARK node. */
10700 field_type (const_tree decl)
10704 if (TREE_CODE (decl) == ERROR_MARK)
10705 return integer_type_node;
10707 type = DECL_BIT_FIELD_TYPE (decl);
10708 if (type == NULL_TREE)
10709 type = TREE_TYPE (decl);
10714 /* Given a pointer to a tree node, return the alignment in bits for
10715 it, or else return BITS_PER_WORD if the node actually turns out to
10716 be an ERROR_MARK node. */
10718 static inline unsigned
10719 simple_type_align_in_bits (const_tree type)
10721 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10724 static inline unsigned
10725 simple_decl_align_in_bits (const_tree decl)
10727 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10730 /* Return the result of rounding T up to ALIGN. */
10732 static inline HOST_WIDE_INT
10733 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10735 /* We must be careful if T is negative because HOST_WIDE_INT can be
10736 either "above" or "below" unsigned int as per the C promotion
10737 rules, depending on the host, thus making the signedness of the
10738 direct multiplication and division unpredictable. */
10739 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10745 return (HOST_WIDE_INT) u;
10748 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10749 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10750 or return 0 if we are unable to determine what that offset is, either
10751 because the argument turns out to be a pointer to an ERROR_MARK node, or
10752 because the offset is actually variable. (We can't handle the latter case
10755 static HOST_WIDE_INT
10756 field_byte_offset (const_tree decl)
10758 HOST_WIDE_INT object_offset_in_bits;
10759 HOST_WIDE_INT bitpos_int;
10761 if (TREE_CODE (decl) == ERROR_MARK)
10764 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10766 /* We cannot yet cope with fields whose positions are variable, so
10767 for now, when we see such things, we simply return 0. Someday, we may
10768 be able to handle such cases, but it will be damn difficult. */
10769 if (! host_integerp (bit_position (decl), 0))
10772 bitpos_int = int_bit_position (decl);
10774 #ifdef PCC_BITFIELD_TYPE_MATTERS
10775 if (PCC_BITFIELD_TYPE_MATTERS)
10778 tree field_size_tree;
10779 HOST_WIDE_INT deepest_bitpos;
10780 unsigned HOST_WIDE_INT field_size_in_bits;
10781 unsigned int type_align_in_bits;
10782 unsigned int decl_align_in_bits;
10783 unsigned HOST_WIDE_INT type_size_in_bits;
10785 type = field_type (decl);
10786 field_size_tree = DECL_SIZE (decl);
10788 /* The size could be unspecified if there was an error, or for
10789 a flexible array member. */
10790 if (! field_size_tree)
10791 field_size_tree = bitsize_zero_node;
10793 /* If we don't know the size of the field, pretend it's a full word. */
10794 if (host_integerp (field_size_tree, 1))
10795 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10797 field_size_in_bits = BITS_PER_WORD;
10799 type_size_in_bits = simple_type_size_in_bits (type);
10800 type_align_in_bits = simple_type_align_in_bits (type);
10801 decl_align_in_bits = simple_decl_align_in_bits (decl);
10803 /* The GCC front-end doesn't make any attempt to keep track of the
10804 starting bit offset (relative to the start of the containing
10805 structure type) of the hypothetical "containing object" for a
10806 bit-field. Thus, when computing the byte offset value for the
10807 start of the "containing object" of a bit-field, we must deduce
10808 this information on our own. This can be rather tricky to do in
10809 some cases. For example, handling the following structure type
10810 definition when compiling for an i386/i486 target (which only
10811 aligns long long's to 32-bit boundaries) can be very tricky:
10813 struct S { int field1; long long field2:31; };
10815 Fortunately, there is a simple rule-of-thumb which can be used
10816 in such cases. When compiling for an i386/i486, GCC will
10817 allocate 8 bytes for the structure shown above. It decides to
10818 do this based upon one simple rule for bit-field allocation.
10819 GCC allocates each "containing object" for each bit-field at
10820 the first (i.e. lowest addressed) legitimate alignment boundary
10821 (based upon the required minimum alignment for the declared
10822 type of the field) which it can possibly use, subject to the
10823 condition that there is still enough available space remaining
10824 in the containing object (when allocated at the selected point)
10825 to fully accommodate all of the bits of the bit-field itself.
10827 This simple rule makes it obvious why GCC allocates 8 bytes for
10828 each object of the structure type shown above. When looking
10829 for a place to allocate the "containing object" for `field2',
10830 the compiler simply tries to allocate a 64-bit "containing
10831 object" at each successive 32-bit boundary (starting at zero)
10832 until it finds a place to allocate that 64- bit field such that
10833 at least 31 contiguous (and previously unallocated) bits remain
10834 within that selected 64 bit field. (As it turns out, for the
10835 example above, the compiler finds it is OK to allocate the
10836 "containing object" 64-bit field at bit-offset zero within the
10839 Here we attempt to work backwards from the limited set of facts
10840 we're given, and we try to deduce from those facts, where GCC
10841 must have believed that the containing object started (within
10842 the structure type). The value we deduce is then used (by the
10843 callers of this routine) to generate DW_AT_location and
10844 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10845 the case of DW_AT_location, regular fields as well). */
10847 /* Figure out the bit-distance from the start of the structure to
10848 the "deepest" bit of the bit-field. */
10849 deepest_bitpos = bitpos_int + field_size_in_bits;
10851 /* This is the tricky part. Use some fancy footwork to deduce
10852 where the lowest addressed bit of the containing object must
10854 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10856 /* Round up to type_align by default. This works best for
10858 object_offset_in_bits
10859 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10861 if (object_offset_in_bits > bitpos_int)
10863 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10865 /* Round up to decl_align instead. */
10866 object_offset_in_bits
10867 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10872 object_offset_in_bits = bitpos_int;
10874 return object_offset_in_bits / BITS_PER_UNIT;
10877 /* The following routines define various Dwarf attributes and any data
10878 associated with them. */
10880 /* Add a location description attribute value to a DIE.
10882 This emits location attributes suitable for whole variables and
10883 whole parameters. Note that the location attributes for struct fields are
10884 generated by the routine `data_member_location_attribute' below. */
10887 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10888 dw_loc_descr_ref descr)
10891 add_AT_loc (die, attr_kind, descr);
10894 /* Attach the specialized form of location attribute used for data members of
10895 struct and union types. In the special case of a FIELD_DECL node which
10896 represents a bit-field, the "offset" part of this special location
10897 descriptor must indicate the distance in bytes from the lowest-addressed
10898 byte of the containing struct or union type to the lowest-addressed byte of
10899 the "containing object" for the bit-field. (See the `field_byte_offset'
10902 For any given bit-field, the "containing object" is a hypothetical object
10903 (of some integral or enum type) within which the given bit-field lives. The
10904 type of this hypothetical "containing object" is always the same as the
10905 declared type of the individual bit-field itself (for GCC anyway... the
10906 DWARF spec doesn't actually mandate this). Note that it is the size (in
10907 bytes) of the hypothetical "containing object" which will be given in the
10908 DW_AT_byte_size attribute for this bit-field. (See the
10909 `byte_size_attribute' function below.) It is also used when calculating the
10910 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10911 function below.) */
10914 add_data_member_location_attribute (dw_die_ref die, tree decl)
10916 HOST_WIDE_INT offset;
10917 dw_loc_descr_ref loc_descr = 0;
10919 if (TREE_CODE (decl) == TREE_BINFO)
10921 /* We're working on the TAG_inheritance for a base class. */
10922 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10924 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10925 aren't at a fixed offset from all (sub)objects of the same
10926 type. We need to extract the appropriate offset from our
10927 vtable. The following dwarf expression means
10929 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10931 This is specific to the V3 ABI, of course. */
10933 dw_loc_descr_ref tmp;
10935 /* Make a copy of the object address. */
10936 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10937 add_loc_descr (&loc_descr, tmp);
10939 /* Extract the vtable address. */
10940 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10941 add_loc_descr (&loc_descr, tmp);
10943 /* Calculate the address of the offset. */
10944 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10945 gcc_assert (offset < 0);
10947 tmp = int_loc_descriptor (-offset);
10948 add_loc_descr (&loc_descr, tmp);
10949 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10950 add_loc_descr (&loc_descr, tmp);
10952 /* Extract the offset. */
10953 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10954 add_loc_descr (&loc_descr, tmp);
10956 /* Add it to the object address. */
10957 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10958 add_loc_descr (&loc_descr, tmp);
10961 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10964 offset = field_byte_offset (decl);
10968 enum dwarf_location_atom op;
10970 /* The DWARF2 standard says that we should assume that the structure
10971 address is already on the stack, so we can specify a structure field
10972 address by using DW_OP_plus_uconst. */
10974 #ifdef MIPS_DEBUGGING_INFO
10975 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10976 operator correctly. It works only if we leave the offset on the
10980 op = DW_OP_plus_uconst;
10983 loc_descr = new_loc_descr (op, offset, 0);
10986 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10989 /* Writes integer values to dw_vec_const array. */
10992 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10996 *dest++ = val & 0xff;
11002 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11004 static HOST_WIDE_INT
11005 extract_int (const unsigned char *src, unsigned int size)
11007 HOST_WIDE_INT val = 0;
11013 val |= *--src & 0xff;
11019 /* Writes floating point values to dw_vec_const array. */
11022 insert_float (const_rtx rtl, unsigned char *array)
11024 REAL_VALUE_TYPE rv;
11028 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11029 real_to_target (val, &rv, GET_MODE (rtl));
11031 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11032 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11034 insert_int (val[i], 4, array);
11039 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11040 does not have a "location" either in memory or in a register. These
11041 things can arise in GNU C when a constant is passed as an actual parameter
11042 to an inlined function. They can also arise in C++ where declared
11043 constants do not necessarily get memory "homes". */
11046 add_const_value_attribute (dw_die_ref die, rtx rtl)
11048 switch (GET_CODE (rtl))
11052 HOST_WIDE_INT val = INTVAL (rtl);
11055 add_AT_int (die, DW_AT_const_value, val);
11057 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11062 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11063 floating-point constant. A CONST_DOUBLE is used whenever the
11064 constant requires more than one word in order to be adequately
11065 represented. We output CONST_DOUBLEs as blocks. */
11067 enum machine_mode mode = GET_MODE (rtl);
11069 if (SCALAR_FLOAT_MODE_P (mode))
11071 unsigned int length = GET_MODE_SIZE (mode);
11072 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11074 insert_float (rtl, array);
11075 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11079 /* ??? We really should be using HOST_WIDE_INT throughout. */
11080 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11082 add_AT_long_long (die, DW_AT_const_value,
11083 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11090 enum machine_mode mode = GET_MODE (rtl);
11091 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11092 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11093 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11097 switch (GET_MODE_CLASS (mode))
11099 case MODE_VECTOR_INT:
11100 for (i = 0, p = array; i < length; i++, p += elt_size)
11102 rtx elt = CONST_VECTOR_ELT (rtl, i);
11103 HOST_WIDE_INT lo, hi;
11105 switch (GET_CODE (elt))
11113 lo = CONST_DOUBLE_LOW (elt);
11114 hi = CONST_DOUBLE_HIGH (elt);
11118 gcc_unreachable ();
11121 if (elt_size <= sizeof (HOST_WIDE_INT))
11122 insert_int (lo, elt_size, p);
11125 unsigned char *p0 = p;
11126 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11128 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11129 if (WORDS_BIG_ENDIAN)
11134 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11135 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11140 case MODE_VECTOR_FLOAT:
11141 for (i = 0, p = array; i < length; i++, p += elt_size)
11143 rtx elt = CONST_VECTOR_ELT (rtl, i);
11144 insert_float (elt, p);
11149 gcc_unreachable ();
11152 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11157 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11163 add_AT_addr (die, DW_AT_const_value, rtl);
11164 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11168 /* In cases where an inlined instance of an inline function is passed
11169 the address of an `auto' variable (which is local to the caller) we
11170 can get a situation where the DECL_RTL of the artificial local
11171 variable (for the inlining) which acts as a stand-in for the
11172 corresponding formal parameter (of the inline function) will look
11173 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11174 exactly a compile-time constant expression, but it isn't the address
11175 of the (artificial) local variable either. Rather, it represents the
11176 *value* which the artificial local variable always has during its
11177 lifetime. We currently have no way to represent such quasi-constant
11178 values in Dwarf, so for now we just punt and generate nothing. */
11182 /* No other kinds of rtx should be possible here. */
11183 gcc_unreachable ();
11188 /* Determine whether the evaluation of EXPR references any variables
11189 or functions which aren't otherwise used (and therefore may not be
11192 reference_to_unused (tree * tp, int * walk_subtrees,
11193 void * data ATTRIBUTE_UNUSED)
11195 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11196 *walk_subtrees = 0;
11198 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11199 && ! TREE_ASM_WRITTEN (*tp))
11201 /* ??? The C++ FE emits debug information for using decls, so
11202 putting gcc_unreachable here falls over. See PR31899. For now
11203 be conservative. */
11204 else if (!cgraph_global_info_ready
11205 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11207 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11209 struct varpool_node *node = varpool_node (*tp);
11213 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11214 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11216 struct cgraph_node *node = cgraph_node (*tp);
11220 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11226 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11227 for use in a later add_const_value_attribute call. */
11230 rtl_for_decl_init (tree init, tree type)
11232 rtx rtl = NULL_RTX;
11234 /* If a variable is initialized with a string constant without embedded
11235 zeros, build CONST_STRING. */
11236 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11238 tree enttype = TREE_TYPE (type);
11239 tree domain = TYPE_DOMAIN (type);
11240 enum machine_mode mode = TYPE_MODE (enttype);
11242 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11244 && integer_zerop (TYPE_MIN_VALUE (domain))
11245 && compare_tree_int (TYPE_MAX_VALUE (domain),
11246 TREE_STRING_LENGTH (init) - 1) == 0
11247 && ((size_t) TREE_STRING_LENGTH (init)
11248 == strlen (TREE_STRING_POINTER (init)) + 1))
11249 rtl = gen_rtx_CONST_STRING (VOIDmode,
11250 ggc_strdup (TREE_STRING_POINTER (init)));
11252 /* Other aggregates, and complex values, could be represented using
11254 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11256 /* Vectors only work if their mode is supported by the target.
11257 FIXME: generic vectors ought to work too. */
11258 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11260 /* If the initializer is something that we know will expand into an
11261 immediate RTL constant, expand it now. We must be careful not to
11262 reference variables which won't be output. */
11263 else if (initializer_constant_valid_p (init, type)
11264 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11266 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11268 if (TREE_CODE (type) == VECTOR_TYPE)
11269 switch (TREE_CODE (init))
11274 if (TREE_CONSTANT (init))
11276 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11277 bool constant_p = true;
11279 unsigned HOST_WIDE_INT ix;
11281 /* Even when ctor is constant, it might contain non-*_CST
11282 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11283 belong into VECTOR_CST nodes. */
11284 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11285 if (!CONSTANT_CLASS_P (value))
11287 constant_p = false;
11293 init = build_vector_from_ctor (type, elts);
11303 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11305 /* If expand_expr returns a MEM, it wasn't immediate. */
11306 gcc_assert (!rtl || !MEM_P (rtl));
11312 /* Generate RTL for the variable DECL to represent its location. */
11315 rtl_for_decl_location (tree decl)
11319 /* Here we have to decide where we are going to say the parameter "lives"
11320 (as far as the debugger is concerned). We only have a couple of
11321 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11323 DECL_RTL normally indicates where the parameter lives during most of the
11324 activation of the function. If optimization is enabled however, this
11325 could be either NULL or else a pseudo-reg. Both of those cases indicate
11326 that the parameter doesn't really live anywhere (as far as the code
11327 generation parts of GCC are concerned) during most of the function's
11328 activation. That will happen (for example) if the parameter is never
11329 referenced within the function.
11331 We could just generate a location descriptor here for all non-NULL
11332 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11333 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11334 where DECL_RTL is NULL or is a pseudo-reg.
11336 Note however that we can only get away with using DECL_INCOMING_RTL as
11337 a backup substitute for DECL_RTL in certain limited cases. In cases
11338 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11339 we can be sure that the parameter was passed using the same type as it is
11340 declared to have within the function, and that its DECL_INCOMING_RTL
11341 points us to a place where a value of that type is passed.
11343 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11344 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11345 because in these cases DECL_INCOMING_RTL points us to a value of some
11346 type which is *different* from the type of the parameter itself. Thus,
11347 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11348 such cases, the debugger would end up (for example) trying to fetch a
11349 `float' from a place which actually contains the first part of a
11350 `double'. That would lead to really incorrect and confusing
11351 output at debug-time.
11353 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11354 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11355 are a couple of exceptions however. On little-endian machines we can
11356 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11357 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11358 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11359 when (on a little-endian machine) a non-prototyped function has a
11360 parameter declared to be of type `short' or `char'. In such cases,
11361 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11362 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11363 passed `int' value. If the debugger then uses that address to fetch
11364 a `short' or a `char' (on a little-endian machine) the result will be
11365 the correct data, so we allow for such exceptional cases below.
11367 Note that our goal here is to describe the place where the given formal
11368 parameter lives during most of the function's activation (i.e. between the
11369 end of the prologue and the start of the epilogue). We'll do that as best
11370 as we can. Note however that if the given formal parameter is modified
11371 sometime during the execution of the function, then a stack backtrace (at
11372 debug-time) will show the function as having been called with the *new*
11373 value rather than the value which was originally passed in. This happens
11374 rarely enough that it is not a major problem, but it *is* a problem, and
11375 I'd like to fix it.
11377 A future version of dwarf2out.c may generate two additional attributes for
11378 any given DW_TAG_formal_parameter DIE which will describe the "passed
11379 type" and the "passed location" for the given formal parameter in addition
11380 to the attributes we now generate to indicate the "declared type" and the
11381 "active location" for each parameter. This additional set of attributes
11382 could be used by debuggers for stack backtraces. Separately, note that
11383 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11384 This happens (for example) for inlined-instances of inline function formal
11385 parameters which are never referenced. This really shouldn't be
11386 happening. All PARM_DECL nodes should get valid non-NULL
11387 DECL_INCOMING_RTL values. FIXME. */
11389 /* Use DECL_RTL as the "location" unless we find something better. */
11390 rtl = DECL_RTL_IF_SET (decl);
11392 /* When generating abstract instances, ignore everything except
11393 constants, symbols living in memory, and symbols living in
11394 fixed registers. */
11395 if (! reload_completed)
11398 && (CONSTANT_P (rtl)
11400 && CONSTANT_P (XEXP (rtl, 0)))
11402 && TREE_CODE (decl) == VAR_DECL
11403 && TREE_STATIC (decl))))
11405 rtl = targetm.delegitimize_address (rtl);
11410 else if (TREE_CODE (decl) == PARM_DECL)
11412 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11414 tree declared_type = TREE_TYPE (decl);
11415 tree passed_type = DECL_ARG_TYPE (decl);
11416 enum machine_mode dmode = TYPE_MODE (declared_type);
11417 enum machine_mode pmode = TYPE_MODE (passed_type);
11419 /* This decl represents a formal parameter which was optimized out.
11420 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11421 all cases where (rtl == NULL_RTX) just below. */
11422 if (dmode == pmode)
11423 rtl = DECL_INCOMING_RTL (decl);
11424 else if (SCALAR_INT_MODE_P (dmode)
11425 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11426 && DECL_INCOMING_RTL (decl))
11428 rtx inc = DECL_INCOMING_RTL (decl);
11431 else if (MEM_P (inc))
11433 if (BYTES_BIG_ENDIAN)
11434 rtl = adjust_address_nv (inc, dmode,
11435 GET_MODE_SIZE (pmode)
11436 - GET_MODE_SIZE (dmode));
11443 /* If the parm was passed in registers, but lives on the stack, then
11444 make a big endian correction if the mode of the type of the
11445 parameter is not the same as the mode of the rtl. */
11446 /* ??? This is the same series of checks that are made in dbxout.c before
11447 we reach the big endian correction code there. It isn't clear if all
11448 of these checks are necessary here, but keeping them all is the safe
11450 else if (MEM_P (rtl)
11451 && XEXP (rtl, 0) != const0_rtx
11452 && ! CONSTANT_P (XEXP (rtl, 0))
11453 /* Not passed in memory. */
11454 && !MEM_P (DECL_INCOMING_RTL (decl))
11455 /* Not passed by invisible reference. */
11456 && (!REG_P (XEXP (rtl, 0))
11457 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11458 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11459 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11460 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11463 /* Big endian correction check. */
11464 && BYTES_BIG_ENDIAN
11465 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11466 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11469 int offset = (UNITS_PER_WORD
11470 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11472 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11473 plus_constant (XEXP (rtl, 0), offset));
11476 else if (TREE_CODE (decl) == VAR_DECL
11479 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11480 && BYTES_BIG_ENDIAN)
11482 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11483 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11485 /* If a variable is declared "register" yet is smaller than
11486 a register, then if we store the variable to memory, it
11487 looks like we're storing a register-sized value, when in
11488 fact we are not. We need to adjust the offset of the
11489 storage location to reflect the actual value's bytes,
11490 else gdb will not be able to display it. */
11492 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11493 plus_constant (XEXP (rtl, 0), rsize-dsize));
11496 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11497 and will have been substituted directly into all expressions that use it.
11498 C does not have such a concept, but C++ and other languages do. */
11499 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11500 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11503 rtl = targetm.delegitimize_address (rtl);
11505 /* If we don't look past the constant pool, we risk emitting a
11506 reference to a constant pool entry that isn't referenced from
11507 code, and thus is not emitted. */
11509 rtl = avoid_constant_pool_reference (rtl);
11514 /* We need to figure out what section we should use as the base for the
11515 address ranges where a given location is valid.
11516 1. If this particular DECL has a section associated with it, use that.
11517 2. If this function has a section associated with it, use that.
11518 3. Otherwise, use the text section.
11519 XXX: If you split a variable across multiple sections, we won't notice. */
11521 static const char *
11522 secname_for_decl (const_tree decl)
11524 const char *secname;
11526 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11528 tree sectree = DECL_SECTION_NAME (decl);
11529 secname = TREE_STRING_POINTER (sectree);
11531 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11533 tree sectree = DECL_SECTION_NAME (current_function_decl);
11534 secname = TREE_STRING_POINTER (sectree);
11536 else if (cfun && in_cold_section_p)
11537 secname = crtl->subsections.cold_section_label;
11539 secname = text_section_label;
11544 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
11545 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
11546 value is the offset into the common block for the symbol. */
11549 fortran_common (tree decl, HOST_WIDE_INT *value)
11551 tree val_expr, cvar;
11552 enum machine_mode mode;
11553 HOST_WIDE_INT bitsize, bitpos;
11555 int volatilep = 0, unsignedp = 0;
11557 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11558 it does not have a value (the offset into the common area), or if it
11559 is thread local (as opposed to global) then it isn't common, and shouldn't
11560 be handled as such. */
11561 if (TREE_CODE (decl) != VAR_DECL
11562 || !TREE_PUBLIC (decl)
11563 || !TREE_STATIC (decl)
11564 || !DECL_HAS_VALUE_EXPR_P (decl)
11568 val_expr = DECL_VALUE_EXPR (decl);
11569 if (TREE_CODE (val_expr) != COMPONENT_REF)
11572 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11573 &mode, &unsignedp, &volatilep, true);
11575 if (cvar == NULL_TREE
11576 || TREE_CODE (cvar) != VAR_DECL
11577 || DECL_ARTIFICIAL (cvar)
11578 || !TREE_PUBLIC (cvar))
11582 if (offset != NULL)
11584 if (!host_integerp (offset, 0))
11586 *value = tree_low_cst (offset, 0);
11589 *value += bitpos / BITS_PER_UNIT;
11594 /* Dereference a location expression LOC if DECL is passed by invisible
11597 static dw_loc_descr_ref
11598 loc_by_reference (dw_loc_descr_ref loc, tree decl)
11600 HOST_WIDE_INT size;
11601 enum dwarf_location_atom op;
11606 if ((TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != RESULT_DECL)
11607 || !DECL_BY_REFERENCE (decl))
11610 size = int_size_in_bytes (TREE_TYPE (decl));
11611 if (size > DWARF2_ADDR_SIZE || size == -1)
11613 else if (size == DWARF2_ADDR_SIZE)
11616 op = DW_OP_deref_size;
11617 add_loc_descr (&loc, new_loc_descr (op, size, 0));
11621 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11622 data attribute for a variable or a parameter. We generate the
11623 DW_AT_const_value attribute only in those cases where the given variable
11624 or parameter does not have a true "location" either in memory or in a
11625 register. This can happen (for example) when a constant is passed as an
11626 actual argument in a call to an inline function. (It's possible that
11627 these things can crop up in other ways also.) Note that one type of
11628 constant value which can be passed into an inlined function is a constant
11629 pointer. This can happen for example if an actual argument in an inlined
11630 function call evaluates to a compile-time constant address. */
11633 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11634 enum dwarf_attribute attr)
11637 dw_loc_descr_ref descr;
11638 var_loc_list *loc_list;
11639 struct var_loc_node *node;
11640 if (TREE_CODE (decl) == ERROR_MARK)
11643 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11644 || TREE_CODE (decl) == RESULT_DECL);
11646 /* See if we possibly have multiple locations for this variable. */
11647 loc_list = lookup_decl_loc (decl);
11649 /* If it truly has multiple locations, the first and last node will
11651 if (loc_list && loc_list->first != loc_list->last)
11653 const char *endname, *secname;
11654 dw_loc_list_ref list;
11656 enum var_init_status initialized;
11658 /* Now that we know what section we are using for a base,
11659 actually construct the list of locations.
11660 The first location information is what is passed to the
11661 function that creates the location list, and the remaining
11662 locations just get added on to that list.
11663 Note that we only know the start address for a location
11664 (IE location changes), so to build the range, we use
11665 the range [current location start, next location start].
11666 This means we have to special case the last node, and generate
11667 a range of [last location start, end of function label]. */
11669 node = loc_list->first;
11670 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11671 secname = secname_for_decl (decl);
11673 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11674 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11676 initialized = VAR_INIT_STATUS_INITIALIZED;
11678 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
11679 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
11682 for (; node->next; node = node->next)
11683 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11685 /* The variable has a location between NODE->LABEL and
11686 NODE->NEXT->LABEL. */
11687 enum var_init_status initialized =
11688 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11689 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11690 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11692 add_loc_descr_to_loc_list (&list, descr,
11693 node->label, node->next->label, secname);
11696 /* If the variable has a location at the last label
11697 it keeps its location until the end of function. */
11698 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11700 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11701 enum var_init_status initialized =
11702 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11704 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11705 if (!current_function_decl)
11706 endname = text_end_label;
11709 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11710 current_function_funcdef_no);
11711 endname = ggc_strdup (label_id);
11713 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11715 add_loc_descr_to_loc_list (&list, descr,
11716 node->label, endname, secname);
11719 /* Finally, add the location list to the DIE, and we are done. */
11720 add_AT_loc_list (die, attr, list);
11724 /* Try to get some constant RTL for this decl, and use that as the value of
11727 rtl = rtl_for_decl_location (decl);
11728 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11730 add_const_value_attribute (die, rtl);
11734 /* If we have tried to generate the location otherwise, and it
11735 didn't work out (we wouldn't be here if we did), and we have a one entry
11736 location list, try generating a location from that. */
11737 if (loc_list && loc_list->first)
11739 enum var_init_status status;
11740 node = loc_list->first;
11741 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11742 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11745 descr = loc_by_reference (descr, decl);
11746 add_AT_location_description (die, attr, descr);
11751 /* We couldn't get any rtl, so try directly generating the location
11752 description from the tree. */
11753 descr = loc_descriptor_from_tree (decl);
11756 descr = loc_by_reference (descr, decl);
11757 add_AT_location_description (die, attr, descr);
11760 /* None of that worked, so it must not really have a location;
11761 try adding a constant value attribute from the DECL_INITIAL. */
11762 tree_add_const_value_attribute (die, decl);
11765 /* If we don't have a copy of this variable in memory for some reason (such
11766 as a C++ member constant that doesn't have an out-of-line definition),
11767 we should tell the debugger about the constant value. */
11770 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
11772 tree init = DECL_INITIAL (decl);
11773 tree type = TREE_TYPE (decl);
11776 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
11781 rtl = rtl_for_decl_init (init, type);
11783 add_const_value_attribute (var_die, rtl);
11786 /* Convert the CFI instructions for the current function into a
11787 location list. This is used for DW_AT_frame_base when we targeting
11788 a dwarf2 consumer that does not support the dwarf3
11789 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11792 static dw_loc_list_ref
11793 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
11796 dw_loc_list_ref list, *list_tail;
11798 dw_cfa_location last_cfa, next_cfa;
11799 const char *start_label, *last_label, *section;
11801 fde = current_fde ();
11802 gcc_assert (fde != NULL);
11804 section = secname_for_decl (current_function_decl);
11808 next_cfa.reg = INVALID_REGNUM;
11809 next_cfa.offset = 0;
11810 next_cfa.indirect = 0;
11811 next_cfa.base_offset = 0;
11813 start_label = fde->dw_fde_begin;
11815 /* ??? Bald assumption that the CIE opcode list does not contain
11816 advance opcodes. */
11817 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11818 lookup_cfa_1 (cfi, &next_cfa);
11820 last_cfa = next_cfa;
11821 last_label = start_label;
11823 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11824 switch (cfi->dw_cfi_opc)
11826 case DW_CFA_set_loc:
11827 case DW_CFA_advance_loc1:
11828 case DW_CFA_advance_loc2:
11829 case DW_CFA_advance_loc4:
11830 if (!cfa_equal_p (&last_cfa, &next_cfa))
11832 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11833 start_label, last_label, section,
11836 list_tail = &(*list_tail)->dw_loc_next;
11837 last_cfa = next_cfa;
11838 start_label = last_label;
11840 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11843 case DW_CFA_advance_loc:
11844 /* The encoding is complex enough that we should never emit this. */
11845 case DW_CFA_remember_state:
11846 case DW_CFA_restore_state:
11847 /* We don't handle these two in this function. It would be possible
11848 if it were to be required. */
11849 gcc_unreachable ();
11852 lookup_cfa_1 (cfi, &next_cfa);
11856 if (!cfa_equal_p (&last_cfa, &next_cfa))
11858 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11859 start_label, last_label, section,
11861 list_tail = &(*list_tail)->dw_loc_next;
11862 start_label = last_label;
11864 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11865 start_label, fde->dw_fde_end, section,
11871 /* Compute a displacement from the "steady-state frame pointer" to the
11872 frame base (often the same as the CFA), and store it in
11873 frame_pointer_fb_offset. OFFSET is added to the displacement
11874 before the latter is negated. */
11877 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11881 #ifdef FRAME_POINTER_CFA_OFFSET
11882 reg = frame_pointer_rtx;
11883 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11885 reg = arg_pointer_rtx;
11886 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11889 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11890 if (GET_CODE (elim) == PLUS)
11892 offset += INTVAL (XEXP (elim, 1));
11893 elim = XEXP (elim, 0);
11896 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11897 && (elim == hard_frame_pointer_rtx
11898 || elim == stack_pointer_rtx))
11899 || elim == (frame_pointer_needed
11900 ? hard_frame_pointer_rtx
11901 : stack_pointer_rtx));
11903 frame_pointer_fb_offset = -offset;
11906 /* Generate a DW_AT_name attribute given some string value to be included as
11907 the value of the attribute. */
11910 add_name_attribute (dw_die_ref die, const char *name_string)
11912 if (name_string != NULL && *name_string != 0)
11914 if (demangle_name_func)
11915 name_string = (*demangle_name_func) (name_string);
11917 add_AT_string (die, DW_AT_name, name_string);
11921 /* Generate a DW_AT_comp_dir attribute for DIE. */
11924 add_comp_dir_attribute (dw_die_ref die)
11926 const char *wd = get_src_pwd ();
11928 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11931 /* Given a tree node describing an array bound (either lower or upper) output
11932 a representation for that bound. */
11935 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11937 switch (TREE_CODE (bound))
11942 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11944 if (! host_integerp (bound, 0)
11945 || (bound_attr == DW_AT_lower_bound
11946 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11947 || (is_fortran () && integer_onep (bound)))))
11948 /* Use the default. */
11951 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11955 case VIEW_CONVERT_EXPR:
11956 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11966 dw_die_ref decl_die = lookup_decl_die (bound);
11967 dw_loc_descr_ref loc;
11969 /* ??? Can this happen, or should the variable have been bound
11970 first? Probably it can, since I imagine that we try to create
11971 the types of parameters in the order in which they exist in
11972 the list, and won't have created a forward reference to a
11973 later parameter. */
11974 if (decl_die != NULL)
11975 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11978 loc = loc_descriptor_from_tree_1 (bound, 0);
11979 add_AT_location_description (subrange_die, bound_attr, loc);
11986 /* Otherwise try to create a stack operation procedure to
11987 evaluate the value of the array bound. */
11989 dw_die_ref ctx, decl_die;
11990 dw_loc_descr_ref loc;
11992 loc = loc_descriptor_from_tree (bound);
11996 if (current_function_decl == 0)
11997 ctx = comp_unit_die;
11999 ctx = lookup_decl_die (current_function_decl);
12001 decl_die = new_die (DW_TAG_variable, ctx, bound);
12002 add_AT_flag (decl_die, DW_AT_artificial, 1);
12003 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12004 add_AT_loc (decl_die, DW_AT_location, loc);
12006 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12012 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12013 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12014 Note that the block of subscript information for an array type also
12015 includes information about the element type of the given array type. */
12018 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12020 unsigned dimension_number;
12022 dw_die_ref subrange_die;
12024 for (dimension_number = 0;
12025 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12026 type = TREE_TYPE (type), dimension_number++)
12028 tree domain = TYPE_DOMAIN (type);
12030 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12033 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12034 and (in GNU C only) variable bounds. Handle all three forms
12036 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12039 /* We have an array type with specified bounds. */
12040 lower = TYPE_MIN_VALUE (domain);
12041 upper = TYPE_MAX_VALUE (domain);
12043 /* Define the index type. */
12044 if (TREE_TYPE (domain))
12046 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12047 TREE_TYPE field. We can't emit debug info for this
12048 because it is an unnamed integral type. */
12049 if (TREE_CODE (domain) == INTEGER_TYPE
12050 && TYPE_NAME (domain) == NULL_TREE
12051 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12052 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12055 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12059 /* ??? If upper is NULL, the array has unspecified length,
12060 but it does have a lower bound. This happens with Fortran
12062 Since the debugger is definitely going to need to know N
12063 to produce useful results, go ahead and output the lower
12064 bound solo, and hope the debugger can cope. */
12066 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12068 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12071 /* Otherwise we have an array type with an unspecified length. The
12072 DWARF-2 spec does not say how to handle this; let's just leave out the
12078 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12082 switch (TREE_CODE (tree_node))
12087 case ENUMERAL_TYPE:
12090 case QUAL_UNION_TYPE:
12091 size = int_size_in_bytes (tree_node);
12094 /* For a data member of a struct or union, the DW_AT_byte_size is
12095 generally given as the number of bytes normally allocated for an
12096 object of the *declared* type of the member itself. This is true
12097 even for bit-fields. */
12098 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12101 gcc_unreachable ();
12104 /* Note that `size' might be -1 when we get to this point. If it is, that
12105 indicates that the byte size of the entity in question is variable. We
12106 have no good way of expressing this fact in Dwarf at the present time,
12107 so just let the -1 pass on through. */
12108 add_AT_unsigned (die, DW_AT_byte_size, size);
12111 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12112 which specifies the distance in bits from the highest order bit of the
12113 "containing object" for the bit-field to the highest order bit of the
12116 For any given bit-field, the "containing object" is a hypothetical object
12117 (of some integral or enum type) within which the given bit-field lives. The
12118 type of this hypothetical "containing object" is always the same as the
12119 declared type of the individual bit-field itself. The determination of the
12120 exact location of the "containing object" for a bit-field is rather
12121 complicated. It's handled by the `field_byte_offset' function (above).
12123 Note that it is the size (in bytes) of the hypothetical "containing object"
12124 which will be given in the DW_AT_byte_size attribute for this bit-field.
12125 (See `byte_size_attribute' above). */
12128 add_bit_offset_attribute (dw_die_ref die, tree decl)
12130 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12131 tree type = DECL_BIT_FIELD_TYPE (decl);
12132 HOST_WIDE_INT bitpos_int;
12133 HOST_WIDE_INT highest_order_object_bit_offset;
12134 HOST_WIDE_INT highest_order_field_bit_offset;
12135 HOST_WIDE_INT unsigned bit_offset;
12137 /* Must be a field and a bit field. */
12138 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12140 /* We can't yet handle bit-fields whose offsets are variable, so if we
12141 encounter such things, just return without generating any attribute
12142 whatsoever. Likewise for variable or too large size. */
12143 if (! host_integerp (bit_position (decl), 0)
12144 || ! host_integerp (DECL_SIZE (decl), 1))
12147 bitpos_int = int_bit_position (decl);
12149 /* Note that the bit offset is always the distance (in bits) from the
12150 highest-order bit of the "containing object" to the highest-order bit of
12151 the bit-field itself. Since the "high-order end" of any object or field
12152 is different on big-endian and little-endian machines, the computation
12153 below must take account of these differences. */
12154 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12155 highest_order_field_bit_offset = bitpos_int;
12157 if (! BYTES_BIG_ENDIAN)
12159 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12160 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12164 = (! BYTES_BIG_ENDIAN
12165 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12166 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12168 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12171 /* For a FIELD_DECL node which represents a bit field, output an attribute
12172 which specifies the length in bits of the given field. */
12175 add_bit_size_attribute (dw_die_ref die, tree decl)
12177 /* Must be a field and a bit field. */
12178 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12179 && DECL_BIT_FIELD_TYPE (decl));
12181 if (host_integerp (DECL_SIZE (decl), 1))
12182 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12185 /* If the compiled language is ANSI C, then add a 'prototyped'
12186 attribute, if arg types are given for the parameters of a function. */
12189 add_prototyped_attribute (dw_die_ref die, tree func_type)
12191 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12192 && TYPE_ARG_TYPES (func_type) != NULL)
12193 add_AT_flag (die, DW_AT_prototyped, 1);
12196 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12197 by looking in either the type declaration or object declaration
12201 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12203 dw_die_ref origin_die = NULL;
12205 if (TREE_CODE (origin) != FUNCTION_DECL)
12207 /* We may have gotten separated from the block for the inlined
12208 function, if we're in an exception handler or some such; make
12209 sure that the abstract function has been written out.
12211 Doing this for nested functions is wrong, however; functions are
12212 distinct units, and our context might not even be inline. */
12216 fn = TYPE_STUB_DECL (fn);
12218 fn = decl_function_context (fn);
12220 dwarf2out_abstract_function (fn);
12223 if (DECL_P (origin))
12224 origin_die = lookup_decl_die (origin);
12225 else if (TYPE_P (origin))
12226 origin_die = lookup_type_die (origin);
12228 /* XXX: Functions that are never lowered don't always have correct block
12229 trees (in the case of java, they simply have no block tree, in some other
12230 languages). For these functions, there is nothing we can really do to
12231 output correct debug info for inlined functions in all cases. Rather
12232 than die, we'll just produce deficient debug info now, in that we will
12233 have variables without a proper abstract origin. In the future, when all
12234 functions are lowered, we should re-add a gcc_assert (origin_die)
12238 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12241 /* We do not currently support the pure_virtual attribute. */
12244 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12246 if (DECL_VINDEX (func_decl))
12248 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12250 if (host_integerp (DECL_VINDEX (func_decl), 0))
12251 add_AT_loc (die, DW_AT_vtable_elem_location,
12252 new_loc_descr (DW_OP_constu,
12253 tree_low_cst (DECL_VINDEX (func_decl), 0),
12256 /* GNU extension: Record what type this method came from originally. */
12257 if (debug_info_level > DINFO_LEVEL_TERSE)
12258 add_AT_die_ref (die, DW_AT_containing_type,
12259 lookup_type_die (DECL_CONTEXT (func_decl)));
12263 /* Add source coordinate attributes for the given decl. */
12266 add_src_coords_attributes (dw_die_ref die, tree decl)
12268 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12270 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12271 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12274 /* Add a DW_AT_name attribute and source coordinate attribute for the
12275 given decl, but only if it actually has a name. */
12278 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12282 decl_name = DECL_NAME (decl);
12283 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12285 add_name_attribute (die, dwarf2_name (decl, 0));
12286 if (! DECL_ARTIFICIAL (decl))
12287 add_src_coords_attributes (die, decl);
12289 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12290 && TREE_PUBLIC (decl)
12291 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12292 && !DECL_ABSTRACT (decl)
12293 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12295 add_AT_string (die, DW_AT_MIPS_linkage_name,
12296 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12299 #ifdef VMS_DEBUGGING_INFO
12300 /* Get the function's name, as described by its RTL. This may be different
12301 from the DECL_NAME name used in the source file. */
12302 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12304 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12305 XEXP (DECL_RTL (decl), 0));
12306 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12311 /* Push a new declaration scope. */
12314 push_decl_scope (tree scope)
12316 VEC_safe_push (tree, gc, decl_scope_table, scope);
12319 /* Pop a declaration scope. */
12322 pop_decl_scope (void)
12324 VEC_pop (tree, decl_scope_table);
12327 /* Return the DIE for the scope that immediately contains this type.
12328 Non-named types get global scope. Named types nested in other
12329 types get their containing scope if it's open, or global scope
12330 otherwise. All other types (i.e. function-local named types) get
12331 the current active scope. */
12334 scope_die_for (tree t, dw_die_ref context_die)
12336 dw_die_ref scope_die = NULL;
12337 tree containing_scope;
12340 /* Non-types always go in the current scope. */
12341 gcc_assert (TYPE_P (t));
12343 containing_scope = TYPE_CONTEXT (t);
12345 /* Use the containing namespace if it was passed in (for a declaration). */
12346 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12348 if (context_die == lookup_decl_die (containing_scope))
12351 containing_scope = NULL_TREE;
12354 /* Ignore function type "scopes" from the C frontend. They mean that
12355 a tagged type is local to a parmlist of a function declarator, but
12356 that isn't useful to DWARF. */
12357 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12358 containing_scope = NULL_TREE;
12360 if (containing_scope == NULL_TREE)
12361 scope_die = comp_unit_die;
12362 else if (TYPE_P (containing_scope))
12364 /* For types, we can just look up the appropriate DIE. But
12365 first we check to see if we're in the middle of emitting it
12366 so we know where the new DIE should go. */
12367 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12368 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12373 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12374 || TREE_ASM_WRITTEN (containing_scope));
12376 /* If none of the current dies are suitable, we get file scope. */
12377 scope_die = comp_unit_die;
12380 scope_die = lookup_type_die (containing_scope);
12383 scope_die = context_die;
12388 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12391 local_scope_p (dw_die_ref context_die)
12393 for (; context_die; context_die = context_die->die_parent)
12394 if (context_die->die_tag == DW_TAG_inlined_subroutine
12395 || context_die->die_tag == DW_TAG_subprogram)
12401 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12402 whether or not to treat a DIE in this context as a declaration. */
12405 class_or_namespace_scope_p (dw_die_ref context_die)
12407 return (context_die
12408 && (context_die->die_tag == DW_TAG_structure_type
12409 || context_die->die_tag == DW_TAG_class_type
12410 || context_die->die_tag == DW_TAG_interface_type
12411 || context_die->die_tag == DW_TAG_union_type
12412 || context_die->die_tag == DW_TAG_namespace));
12415 /* Many forms of DIEs require a "type description" attribute. This
12416 routine locates the proper "type descriptor" die for the type given
12417 by 'type', and adds a DW_AT_type attribute below the given die. */
12420 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12421 int decl_volatile, dw_die_ref context_die)
12423 enum tree_code code = TREE_CODE (type);
12424 dw_die_ref type_die = NULL;
12426 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12427 or fixed-point type, use the inner type. This is because we have no
12428 support for unnamed types in base_type_die. This can happen if this is
12429 an Ada subrange type. Correct solution is emit a subrange type die. */
12430 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12431 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12432 type = TREE_TYPE (type), code = TREE_CODE (type);
12434 if (code == ERROR_MARK
12435 /* Handle a special case. For functions whose return type is void, we
12436 generate *no* type attribute. (Note that no object may have type
12437 `void', so this only applies to function return types). */
12438 || code == VOID_TYPE)
12441 type_die = modified_type_die (type,
12442 decl_const || TYPE_READONLY (type),
12443 decl_volatile || TYPE_VOLATILE (type),
12446 if (type_die != NULL)
12447 add_AT_die_ref (object_die, DW_AT_type, type_die);
12450 /* Given an object die, add the calling convention attribute for the
12451 function call type. */
12453 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12455 enum dwarf_calling_convention value = DW_CC_normal;
12457 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12459 /* DWARF doesn't provide a way to identify a program's source-level
12460 entry point. DW_AT_calling_convention attributes are only meant
12461 to describe functions' calling conventions. However, lacking a
12462 better way to signal the Fortran main program, we use this for the
12463 time being, following existing custom. */
12465 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12466 value = DW_CC_program;
12468 /* Only add the attribute if the backend requests it, and
12469 is not DW_CC_normal. */
12470 if (value && (value != DW_CC_normal))
12471 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12474 /* Given a tree pointer to a struct, class, union, or enum type node, return
12475 a pointer to the (string) tag name for the given type, or zero if the type
12476 was declared without a tag. */
12478 static const char *
12479 type_tag (const_tree type)
12481 const char *name = 0;
12483 if (TYPE_NAME (type) != 0)
12487 /* Find the IDENTIFIER_NODE for the type name. */
12488 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12489 t = TYPE_NAME (type);
12491 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12492 a TYPE_DECL node, regardless of whether or not a `typedef' was
12494 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12495 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12497 /* We want to be extra verbose. Don't call dwarf_name if
12498 DECL_NAME isn't set. The default hook for decl_printable_name
12499 doesn't like that, and in this context it's correct to return
12500 0, instead of "<anonymous>" or the like. */
12501 if (DECL_NAME (TYPE_NAME (type)))
12502 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12505 /* Now get the name as a string, or invent one. */
12506 if (!name && t != 0)
12507 name = IDENTIFIER_POINTER (t);
12510 return (name == 0 || *name == '\0') ? 0 : name;
12513 /* Return the type associated with a data member, make a special check
12514 for bit field types. */
12517 member_declared_type (const_tree member)
12519 return (DECL_BIT_FIELD_TYPE (member)
12520 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12523 /* Get the decl's label, as described by its RTL. This may be different
12524 from the DECL_NAME name used in the source file. */
12527 static const char *
12528 decl_start_label (tree decl)
12531 const char *fnname;
12533 x = DECL_RTL (decl);
12534 gcc_assert (MEM_P (x));
12537 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12539 fnname = XSTR (x, 0);
12544 /* These routines generate the internal representation of the DIE's for
12545 the compilation unit. Debugging information is collected by walking
12546 the declaration trees passed in from dwarf2out_decl(). */
12549 gen_array_type_die (tree type, dw_die_ref context_die)
12551 dw_die_ref scope_die = scope_die_for (type, context_die);
12552 dw_die_ref array_die;
12554 /* GNU compilers represent multidimensional array types as sequences of one
12555 dimensional array types whose element types are themselves array types.
12556 We sometimes squish that down to a single array_type DIE with multiple
12557 subscripts in the Dwarf debugging info. The draft Dwarf specification
12558 say that we are allowed to do this kind of compression in C, because
12559 there is no difference between an array of arrays and a multidimensional
12560 array. We don't do this for Ada to remain as close as possible to the
12561 actual representation, which is especially important against the language
12562 flexibilty wrt arrays of variable size. */
12564 bool collapse_nested_arrays = !is_ada ();
12567 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
12568 DW_TAG_string_type doesn't have DW_AT_type attribute). */
12569 if (TYPE_STRING_FLAG (type)
12570 && TREE_CODE (type) == ARRAY_TYPE
12572 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
12574 HOST_WIDE_INT size;
12576 array_die = new_die (DW_TAG_string_type, scope_die, type);
12577 add_name_attribute (array_die, type_tag (type));
12578 equate_type_number_to_die (type, array_die);
12579 size = int_size_in_bytes (type);
12581 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12582 else if (TYPE_DOMAIN (type) != NULL_TREE
12583 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
12584 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
12586 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
12587 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
12589 size = int_size_in_bytes (TREE_TYPE (szdecl));
12590 if (loc && size > 0)
12592 add_AT_loc (array_die, DW_AT_string_length, loc);
12593 if (size != DWARF2_ADDR_SIZE)
12594 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12600 /* ??? The SGI dwarf reader fails for array of array of enum types
12601 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12602 array type comes before the outer array type. We thus call gen_type_die
12603 before we new_die and must prevent nested array types collapsing for this
12606 #ifdef MIPS_DEBUGGING_INFO
12607 gen_type_die (TREE_TYPE (type), context_die);
12608 collapse_nested_arrays = false;
12611 array_die = new_die (DW_TAG_array_type, scope_die, type);
12612 add_name_attribute (array_die, type_tag (type));
12613 equate_type_number_to_die (type, array_die);
12615 if (TREE_CODE (type) == VECTOR_TYPE)
12617 /* The frontend feeds us a representation for the vector as a struct
12618 containing an array. Pull out the array type. */
12619 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12620 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12623 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12625 && TREE_CODE (type) == ARRAY_TYPE
12626 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
12627 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
12628 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12631 /* We default the array ordering. SDB will probably do
12632 the right things even if DW_AT_ordering is not present. It's not even
12633 an issue until we start to get into multidimensional arrays anyway. If
12634 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12635 then we'll have to put the DW_AT_ordering attribute back in. (But if
12636 and when we find out that we need to put these in, we will only do so
12637 for multidimensional arrays. */
12638 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
12641 #ifdef MIPS_DEBUGGING_INFO
12642 /* The SGI compilers handle arrays of unknown bound by setting
12643 AT_declaration and not emitting any subrange DIEs. */
12644 if (! TYPE_DOMAIN (type))
12645 add_AT_flag (array_die, DW_AT_declaration, 1);
12648 add_subscript_info (array_die, type, collapse_nested_arrays);
12650 /* Add representation of the type of the elements of this array type and
12651 emit the corresponding DIE if we haven't done it already. */
12652 element_type = TREE_TYPE (type);
12653 if (collapse_nested_arrays)
12654 while (TREE_CODE (element_type) == ARRAY_TYPE)
12656 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
12658 element_type = TREE_TYPE (element_type);
12661 #ifndef MIPS_DEBUGGING_INFO
12662 gen_type_die (element_type, context_die);
12665 add_type_attribute (array_die, element_type, 0, 0, context_die);
12667 if (get_AT (array_die, DW_AT_name))
12668 add_pubtype (type, array_die);
12671 static dw_loc_descr_ref
12672 descr_info_loc (tree val, tree base_decl)
12674 HOST_WIDE_INT size;
12675 dw_loc_descr_ref loc, loc2;
12676 enum dwarf_location_atom op;
12678 if (val == base_decl)
12679 return new_loc_descr (DW_OP_push_object_address, 0, 0);
12681 switch (TREE_CODE (val))
12684 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12686 if (host_integerp (val, 0))
12687 return int_loc_descriptor (tree_low_cst (val, 0));
12690 size = int_size_in_bytes (TREE_TYPE (val));
12693 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12696 if (size == DWARF2_ADDR_SIZE)
12697 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
12699 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
12701 case POINTER_PLUS_EXPR:
12703 if (host_integerp (TREE_OPERAND (val, 1), 1)
12704 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
12707 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12710 add_loc_descr (&loc,
12711 new_loc_descr (DW_OP_plus_uconst,
12712 tree_low_cst (TREE_OPERAND (val, 1),
12719 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12722 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
12725 add_loc_descr (&loc, loc2);
12726 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
12748 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
12749 tree val, tree base_decl)
12751 dw_loc_descr_ref loc;
12753 if (host_integerp (val, 0))
12755 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
12759 loc = descr_info_loc (val, base_decl);
12763 add_AT_loc (die, attr, loc);
12766 /* This routine generates DIE for array with hidden descriptor, details
12767 are filled into *info by a langhook. */
12770 gen_descr_array_type_die (tree type, struct array_descr_info *info,
12771 dw_die_ref context_die)
12773 dw_die_ref scope_die = scope_die_for (type, context_die);
12774 dw_die_ref array_die;
12777 array_die = new_die (DW_TAG_array_type, scope_die, type);
12778 add_name_attribute (array_die, type_tag (type));
12779 equate_type_number_to_die (type, array_die);
12781 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12783 && info->ndimensions >= 2)
12784 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12786 if (info->data_location)
12787 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
12789 if (info->associated)
12790 add_descr_info_field (array_die, DW_AT_associated, info->associated,
12792 if (info->allocated)
12793 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
12796 for (dim = 0; dim < info->ndimensions; dim++)
12798 dw_die_ref subrange_die
12799 = new_die (DW_TAG_subrange_type, array_die, NULL);
12801 if (info->dimen[dim].lower_bound)
12803 /* If it is the default value, omit it. */
12804 if ((is_c_family () || is_java ())
12805 && integer_zerop (info->dimen[dim].lower_bound))
12807 else if (is_fortran ()
12808 && integer_onep (info->dimen[dim].lower_bound))
12811 add_descr_info_field (subrange_die, DW_AT_lower_bound,
12812 info->dimen[dim].lower_bound,
12815 if (info->dimen[dim].upper_bound)
12816 add_descr_info_field (subrange_die, DW_AT_upper_bound,
12817 info->dimen[dim].upper_bound,
12819 if (info->dimen[dim].stride)
12820 add_descr_info_field (subrange_die, DW_AT_byte_stride,
12821 info->dimen[dim].stride,
12825 gen_type_die (info->element_type, context_die);
12826 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
12828 if (get_AT (array_die, DW_AT_name))
12829 add_pubtype (type, array_die);
12834 gen_entry_point_die (tree decl, dw_die_ref context_die)
12836 tree origin = decl_ultimate_origin (decl);
12837 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
12839 if (origin != NULL)
12840 add_abstract_origin_attribute (decl_die, origin);
12843 add_name_and_src_coords_attributes (decl_die, decl);
12844 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
12845 0, 0, context_die);
12848 if (DECL_ABSTRACT (decl))
12849 equate_decl_number_to_die (decl, decl_die);
12851 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12855 /* Walk through the list of incomplete types again, trying once more to
12856 emit full debugging info for them. */
12859 retry_incomplete_types (void)
12863 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12864 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12867 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12870 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12872 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12874 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12875 be incomplete and such types are not marked. */
12876 add_abstract_origin_attribute (type_die, type);
12879 /* Determine what tag to use for a record type. */
12881 static enum dwarf_tag
12882 record_type_tag (tree type)
12884 if (! lang_hooks.types.classify_record)
12885 return DW_TAG_structure_type;
12887 switch (lang_hooks.types.classify_record (type))
12889 case RECORD_IS_STRUCT:
12890 return DW_TAG_structure_type;
12892 case RECORD_IS_CLASS:
12893 return DW_TAG_class_type;
12895 case RECORD_IS_INTERFACE:
12896 return DW_TAG_interface_type;
12899 gcc_unreachable ();
12903 /* Generate a DIE to represent an inlined instance of a structure type. */
12906 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12908 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12910 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12911 be incomplete and such types are not marked. */
12912 add_abstract_origin_attribute (type_die, type);
12915 /* Generate a DIE to represent an inlined instance of a union type. */
12918 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12920 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12922 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12923 be incomplete and such types are not marked. */
12924 add_abstract_origin_attribute (type_die, type);
12927 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12928 include all of the information about the enumeration values also. Each
12929 enumerated type name/value is listed as a child of the enumerated type
12933 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12935 dw_die_ref type_die = lookup_type_die (type);
12937 if (type_die == NULL)
12939 type_die = new_die (DW_TAG_enumeration_type,
12940 scope_die_for (type, context_die), type);
12941 equate_type_number_to_die (type, type_die);
12942 add_name_attribute (type_die, type_tag (type));
12944 else if (! TYPE_SIZE (type))
12947 remove_AT (type_die, DW_AT_declaration);
12949 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12950 given enum type is incomplete, do not generate the DW_AT_byte_size
12951 attribute or the DW_AT_element_list attribute. */
12952 if (TYPE_SIZE (type))
12956 TREE_ASM_WRITTEN (type) = 1;
12957 add_byte_size_attribute (type_die, type);
12958 if (TYPE_STUB_DECL (type) != NULL_TREE)
12959 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12961 /* If the first reference to this type was as the return type of an
12962 inline function, then it may not have a parent. Fix this now. */
12963 if (type_die->die_parent == NULL)
12964 add_child_die (scope_die_for (type, context_die), type_die);
12966 for (link = TYPE_VALUES (type);
12967 link != NULL; link = TREE_CHAIN (link))
12969 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12970 tree value = TREE_VALUE (link);
12972 add_name_attribute (enum_die,
12973 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12975 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12976 /* DWARF2 does not provide a way of indicating whether or
12977 not enumeration constants are signed or unsigned. GDB
12978 always assumes the values are signed, so we output all
12979 values as if they were signed. That means that
12980 enumeration constants with very large unsigned values
12981 will appear to have negative values in the debugger. */
12982 add_AT_int (enum_die, DW_AT_const_value,
12983 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12987 add_AT_flag (type_die, DW_AT_declaration, 1);
12989 if (get_AT (type_die, DW_AT_name))
12990 add_pubtype (type, type_die);
12995 /* Generate a DIE to represent either a real live formal parameter decl or to
12996 represent just the type of some formal parameter position in some function
12999 Note that this routine is a bit unusual because its argument may be a
13000 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13001 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13002 node. If it's the former then this function is being called to output a
13003 DIE to represent a formal parameter object (or some inlining thereof). If
13004 it's the latter, then this function is only being called to output a
13005 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13006 argument type of some subprogram type. */
13009 gen_formal_parameter_die (tree node, dw_die_ref context_die)
13011 dw_die_ref parm_die
13012 = new_die (DW_TAG_formal_parameter, context_die, node);
13015 switch (TREE_CODE_CLASS (TREE_CODE (node)))
13017 case tcc_declaration:
13018 origin = decl_ultimate_origin (node);
13019 if (origin != NULL)
13020 add_abstract_origin_attribute (parm_die, origin);
13023 tree type = TREE_TYPE (node);
13024 add_name_and_src_coords_attributes (parm_die, node);
13025 if (DECL_BY_REFERENCE (node))
13026 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13029 add_type_attribute (parm_die, type,
13030 TREE_READONLY (node),
13031 TREE_THIS_VOLATILE (node),
13033 if (DECL_ARTIFICIAL (node))
13034 add_AT_flag (parm_die, DW_AT_artificial, 1);
13037 equate_decl_number_to_die (node, parm_die);
13038 if (! DECL_ABSTRACT (node))
13039 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
13044 /* We were called with some kind of a ..._TYPE node. */
13045 add_type_attribute (parm_die, node, 0, 0, context_die);
13049 gcc_unreachable ();
13055 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13056 at the end of an (ANSI prototyped) formal parameters list. */
13059 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13061 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13064 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13065 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13066 parameters as specified in some function type specification (except for
13067 those which appear as part of a function *definition*). */
13070 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13073 tree formal_type = NULL;
13074 tree first_parm_type;
13077 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13079 arg = DECL_ARGUMENTS (function_or_method_type);
13080 function_or_method_type = TREE_TYPE (function_or_method_type);
13085 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13087 /* Make our first pass over the list of formal parameter types and output a
13088 DW_TAG_formal_parameter DIE for each one. */
13089 for (link = first_parm_type; link; )
13091 dw_die_ref parm_die;
13093 formal_type = TREE_VALUE (link);
13094 if (formal_type == void_type_node)
13097 /* Output a (nameless) DIE to represent the formal parameter itself. */
13098 parm_die = gen_formal_parameter_die (formal_type, context_die);
13099 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13100 && link == first_parm_type)
13101 || (arg && DECL_ARTIFICIAL (arg)))
13102 add_AT_flag (parm_die, DW_AT_artificial, 1);
13104 link = TREE_CHAIN (link);
13106 arg = TREE_CHAIN (arg);
13109 /* If this function type has an ellipsis, add a
13110 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13111 if (formal_type != void_type_node)
13112 gen_unspecified_parameters_die (function_or_method_type, context_die);
13114 /* Make our second (and final) pass over the list of formal parameter types
13115 and output DIEs to represent those types (as necessary). */
13116 for (link = TYPE_ARG_TYPES (function_or_method_type);
13117 link && TREE_VALUE (link);
13118 link = TREE_CHAIN (link))
13119 gen_type_die (TREE_VALUE (link), context_die);
13122 /* We want to generate the DIE for TYPE so that we can generate the
13123 die for MEMBER, which has been defined; we will need to refer back
13124 to the member declaration nested within TYPE. If we're trying to
13125 generate minimal debug info for TYPE, processing TYPE won't do the
13126 trick; we need to attach the member declaration by hand. */
13129 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13131 gen_type_die (type, context_die);
13133 /* If we're trying to avoid duplicate debug info, we may not have
13134 emitted the member decl for this function. Emit it now. */
13135 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13136 && ! lookup_decl_die (member))
13138 dw_die_ref type_die;
13139 gcc_assert (!decl_ultimate_origin (member));
13141 push_decl_scope (type);
13142 type_die = lookup_type_die (type);
13143 if (TREE_CODE (member) == FUNCTION_DECL)
13144 gen_subprogram_die (member, type_die);
13145 else if (TREE_CODE (member) == FIELD_DECL)
13147 /* Ignore the nameless fields that are used to skip bits but handle
13148 C++ anonymous unions and structs. */
13149 if (DECL_NAME (member) != NULL_TREE
13150 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13151 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13153 gen_type_die (member_declared_type (member), type_die);
13154 gen_field_die (member, type_die);
13158 gen_variable_die (member, type_die);
13164 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13165 may later generate inlined and/or out-of-line instances of. */
13168 dwarf2out_abstract_function (tree decl)
13170 dw_die_ref old_die;
13173 int was_abstract = DECL_ABSTRACT (decl);
13175 /* Make sure we have the actual abstract inline, not a clone. */
13176 decl = DECL_ORIGIN (decl);
13178 old_die = lookup_decl_die (decl);
13179 if (old_die && get_AT (old_die, DW_AT_inline))
13180 /* We've already generated the abstract instance. */
13183 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13184 we don't get confused by DECL_ABSTRACT. */
13185 if (debug_info_level > DINFO_LEVEL_TERSE)
13187 context = decl_class_context (decl);
13189 gen_type_die_for_member
13190 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13193 /* Pretend we've just finished compiling this function. */
13194 save_fn = current_function_decl;
13195 current_function_decl = decl;
13196 push_cfun (DECL_STRUCT_FUNCTION (decl));
13198 set_decl_abstract_flags (decl, 1);
13199 dwarf2out_decl (decl);
13200 if (! was_abstract)
13201 set_decl_abstract_flags (decl, 0);
13203 current_function_decl = save_fn;
13207 /* Helper function of premark_used_types() which gets called through
13208 htab_traverse_resize().
13210 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13211 marked as unused by prune_unused_types. */
13213 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13218 type = (tree) *slot;
13219 die = lookup_type_die (type);
13221 die->die_perennial_p = 1;
13225 /* Mark all members of used_types_hash as perennial. */
13227 premark_used_types (void)
13229 if (cfun && cfun->used_types_hash)
13230 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13233 /* Generate a DIE to represent a declared function (either file-scope or
13237 gen_subprogram_die (tree decl, dw_die_ref context_die)
13239 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13240 tree origin = decl_ultimate_origin (decl);
13241 dw_die_ref subr_die;
13244 dw_die_ref old_die = lookup_decl_die (decl);
13245 int declaration = (current_function_decl != decl
13246 || class_or_namespace_scope_p (context_die));
13248 premark_used_types ();
13250 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13251 started to generate the abstract instance of an inline, decided to output
13252 its containing class, and proceeded to emit the declaration of the inline
13253 from the member list for the class. If so, DECLARATION takes priority;
13254 we'll get back to the abstract instance when done with the class. */
13256 /* The class-scope declaration DIE must be the primary DIE. */
13257 if (origin && declaration && class_or_namespace_scope_p (context_die))
13260 gcc_assert (!old_die);
13263 /* Now that the C++ front end lazily declares artificial member fns, we
13264 might need to retrofit the declaration into its class. */
13265 if (!declaration && !origin && !old_die
13266 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13267 && !class_or_namespace_scope_p (context_die)
13268 && debug_info_level > DINFO_LEVEL_TERSE)
13269 old_die = force_decl_die (decl);
13271 if (origin != NULL)
13273 gcc_assert (!declaration || local_scope_p (context_die));
13275 /* Fixup die_parent for the abstract instance of a nested
13276 inline function. */
13277 if (old_die && old_die->die_parent == NULL)
13278 add_child_die (context_die, old_die);
13280 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13281 add_abstract_origin_attribute (subr_die, origin);
13285 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13286 struct dwarf_file_data * file_index = lookup_filename (s.file);
13288 if (!get_AT_flag (old_die, DW_AT_declaration)
13289 /* We can have a normal definition following an inline one in the
13290 case of redefinition of GNU C extern inlines.
13291 It seems reasonable to use AT_specification in this case. */
13292 && !get_AT (old_die, DW_AT_inline))
13294 /* Detect and ignore this case, where we are trying to output
13295 something we have already output. */
13299 /* If the definition comes from the same place as the declaration,
13300 maybe use the old DIE. We always want the DIE for this function
13301 that has the *_pc attributes to be under comp_unit_die so the
13302 debugger can find it. We also need to do this for abstract
13303 instances of inlines, since the spec requires the out-of-line copy
13304 to have the same parent. For local class methods, this doesn't
13305 apply; we just use the old DIE. */
13306 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13307 && (DECL_ARTIFICIAL (decl)
13308 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13309 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13310 == (unsigned) s.line))))
13312 subr_die = old_die;
13314 /* Clear out the declaration attribute and the formal parameters.
13315 Do not remove all children, because it is possible that this
13316 declaration die was forced using force_decl_die(). In such
13317 cases die that forced declaration die (e.g. TAG_imported_module)
13318 is one of the children that we do not want to remove. */
13319 remove_AT (subr_die, DW_AT_declaration);
13320 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13324 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13325 add_AT_specification (subr_die, old_die);
13326 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13327 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13328 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13329 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13334 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13336 if (TREE_PUBLIC (decl))
13337 add_AT_flag (subr_die, DW_AT_external, 1);
13339 add_name_and_src_coords_attributes (subr_die, decl);
13340 if (debug_info_level > DINFO_LEVEL_TERSE)
13342 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13343 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13344 0, 0, context_die);
13347 add_pure_or_virtual_attribute (subr_die, decl);
13348 if (DECL_ARTIFICIAL (decl))
13349 add_AT_flag (subr_die, DW_AT_artificial, 1);
13351 if (TREE_PROTECTED (decl))
13352 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13353 else if (TREE_PRIVATE (decl))
13354 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13359 if (!old_die || !get_AT (old_die, DW_AT_inline))
13361 add_AT_flag (subr_die, DW_AT_declaration, 1);
13363 /* The first time we see a member function, it is in the context of
13364 the class to which it belongs. We make sure of this by emitting
13365 the class first. The next time is the definition, which is
13366 handled above. The two may come from the same source text.
13368 Note that force_decl_die() forces function declaration die. It is
13369 later reused to represent definition. */
13370 equate_decl_number_to_die (decl, subr_die);
13373 else if (DECL_ABSTRACT (decl))
13375 if (DECL_DECLARED_INLINE_P (decl))
13377 if (cgraph_function_possibly_inlined_p (decl))
13378 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13380 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13384 if (cgraph_function_possibly_inlined_p (decl))
13385 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13387 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13390 if (DECL_DECLARED_INLINE_P (decl)
13391 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13392 add_AT_flag (subr_die, DW_AT_artificial, 1);
13394 equate_decl_number_to_die (decl, subr_die);
13396 else if (!DECL_EXTERNAL (decl))
13398 HOST_WIDE_INT cfa_fb_offset;
13400 if (!old_die || !get_AT (old_die, DW_AT_inline))
13401 equate_decl_number_to_die (decl, subr_die);
13403 if (!flag_reorder_blocks_and_partition)
13405 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13406 current_function_funcdef_no);
13407 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13408 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13409 current_function_funcdef_no);
13410 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13412 add_pubname (decl, subr_die);
13413 add_arange (decl, subr_die);
13416 { /* Do nothing for now; maybe need to duplicate die, one for
13417 hot section and one for cold section, then use the hot/cold
13418 section begin/end labels to generate the aranges... */
13420 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13421 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13422 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13423 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13425 add_pubname (decl, subr_die);
13426 add_arange (decl, subr_die);
13427 add_arange (decl, subr_die);
13431 #ifdef MIPS_DEBUGGING_INFO
13432 /* Add a reference to the FDE for this routine. */
13433 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13436 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13438 /* We define the "frame base" as the function's CFA. This is more
13439 convenient for several reasons: (1) It's stable across the prologue
13440 and epilogue, which makes it better than just a frame pointer,
13441 (2) With dwarf3, there exists a one-byte encoding that allows us
13442 to reference the .debug_frame data by proxy, but failing that,
13443 (3) We can at least reuse the code inspection and interpretation
13444 code that determines the CFA position at various points in the
13446 /* ??? Use some command-line or configury switch to enable the use
13447 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13448 consumers that understand it; fall back to "pure" dwarf2 and
13449 convert the CFA data into a location list. */
13451 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13452 if (list->dw_loc_next)
13453 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13455 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13458 /* Compute a displacement from the "steady-state frame pointer" to
13459 the CFA. The former is what all stack slots and argument slots
13460 will reference in the rtl; the later is what we've told the
13461 debugger about. We'll need to adjust all frame_base references
13462 by this displacement. */
13463 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13465 if (cfun->static_chain_decl)
13466 add_AT_location_description (subr_die, DW_AT_static_link,
13467 loc_descriptor_from_tree (cfun->static_chain_decl));
13470 /* Now output descriptions of the arguments for this function. This gets
13471 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13472 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13473 `...' at the end of the formal parameter list. In order to find out if
13474 there was a trailing ellipsis or not, we must instead look at the type
13475 associated with the FUNCTION_DECL. This will be a node of type
13476 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13477 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13478 an ellipsis at the end. */
13480 /* In the case where we are describing a mere function declaration, all we
13481 need to do here (and all we *can* do here) is to describe the *types* of
13482 its formal parameters. */
13483 if (debug_info_level <= DINFO_LEVEL_TERSE)
13485 else if (declaration)
13486 gen_formal_types_die (decl, subr_die);
13489 /* Generate DIEs to represent all known formal parameters. */
13490 tree arg_decls = DECL_ARGUMENTS (decl);
13493 /* When generating DIEs, generate the unspecified_parameters DIE
13494 instead if we come across the arg "__builtin_va_alist" */
13495 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13496 if (TREE_CODE (parm) == PARM_DECL)
13498 if (DECL_NAME (parm)
13499 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13500 "__builtin_va_alist"))
13501 gen_unspecified_parameters_die (parm, subr_die);
13503 gen_decl_die (parm, subr_die);
13506 /* Decide whether we need an unspecified_parameters DIE at the end.
13507 There are 2 more cases to do this for: 1) the ansi ... declaration -
13508 this is detectable when the end of the arg list is not a
13509 void_type_node 2) an unprototyped function declaration (not a
13510 definition). This just means that we have no info about the
13511 parameters at all. */
13512 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13513 if (fn_arg_types != NULL)
13515 /* This is the prototyped case, check for.... */
13516 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13517 gen_unspecified_parameters_die (decl, subr_die);
13519 else if (DECL_INITIAL (decl) == NULL_TREE)
13520 gen_unspecified_parameters_die (decl, subr_die);
13523 /* Output Dwarf info for all of the stuff within the body of the function
13524 (if it has one - it may be just a declaration). */
13525 outer_scope = DECL_INITIAL (decl);
13527 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13528 a function. This BLOCK actually represents the outermost binding contour
13529 for the function, i.e. the contour in which the function's formal
13530 parameters and labels get declared. Curiously, it appears that the front
13531 end doesn't actually put the PARM_DECL nodes for the current function onto
13532 the BLOCK_VARS list for this outer scope, but are strung off of the
13533 DECL_ARGUMENTS list for the function instead.
13535 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13536 the LABEL_DECL nodes for the function however, and we output DWARF info
13537 for those in decls_for_scope. Just within the `outer_scope' there will be
13538 a BLOCK node representing the function's outermost pair of curly braces,
13539 and any blocks used for the base and member initializers of a C++
13540 constructor function. */
13541 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13543 /* Emit a DW_TAG_variable DIE for a named return value. */
13544 if (DECL_NAME (DECL_RESULT (decl)))
13545 gen_decl_die (DECL_RESULT (decl), subr_die);
13547 current_function_has_inlines = 0;
13548 decls_for_scope (outer_scope, subr_die, 0);
13550 #if 0 && defined (MIPS_DEBUGGING_INFO)
13551 if (current_function_has_inlines)
13553 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13554 if (! comp_unit_has_inlines)
13556 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13557 comp_unit_has_inlines = 1;
13562 /* Add the calling convention attribute if requested. */
13563 add_calling_convention_attribute (subr_die, decl);
13567 /* Generate a DIE to represent a declared data object. */
13570 gen_variable_die (tree decl, dw_die_ref context_die)
13574 dw_die_ref var_die;
13575 tree origin = decl_ultimate_origin (decl);
13576 dw_die_ref old_die = lookup_decl_die (decl);
13577 int declaration = (DECL_EXTERNAL (decl)
13578 /* If DECL is COMDAT and has not actually been
13579 emitted, we cannot take its address; there
13580 might end up being no definition anywhere in
13581 the program. For example, consider the C++
13585 struct S { static const int i = 7; };
13590 int f() { return S<int>::i; }
13592 Here, S<int>::i is not DECL_EXTERNAL, but no
13593 definition is required, so the compiler will
13594 not emit a definition. */
13595 || (TREE_CODE (decl) == VAR_DECL
13596 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
13597 || class_or_namespace_scope_p (context_die));
13599 com_decl = fortran_common (decl, &off);
13601 /* Symbol in common gets emitted as a child of the common block, in the form
13602 of a data member. */
13606 dw_die_ref com_die;
13607 dw_loc_descr_ref loc;
13609 com_die = lookup_decl_die (decl);
13612 if (get_AT (com_die, DW_AT_location) == NULL)
13614 loc = loc_descriptor_from_tree (com_decl);
13618 add_loc_descr (&loc, new_loc_descr (DW_OP_plus_uconst,
13620 add_AT_loc (com_die, DW_AT_location, loc);
13621 remove_AT (com_die, DW_AT_declaration);
13626 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
13627 var_die = lookup_decl_die (com_decl);
13628 loc = loc_descriptor_from_tree (com_decl);
13629 if (var_die == NULL)
13632 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
13634 var_die = new_die (DW_TAG_common_block, context_die, decl);
13635 add_name_and_src_coords_attributes (var_die, com_decl);
13638 add_AT_loc (var_die, DW_AT_location, loc);
13639 /* Avoid sharing the same loc descriptor between
13640 DW_TAG_common_block and DW_TAG_variable. */
13641 loc = loc_descriptor_from_tree (com_decl);
13643 else if (DECL_EXTERNAL (decl))
13644 add_AT_flag (var_die, DW_AT_declaration, 1);
13645 add_pubname_string (cnam, var_die); /* ??? needed? */
13646 equate_decl_number_to_die (com_decl, var_die);
13648 else if (get_AT (var_die, DW_AT_location) == NULL && loc)
13650 add_AT_loc (var_die, DW_AT_location, loc);
13651 loc = loc_descriptor_from_tree (com_decl);
13652 remove_AT (var_die, DW_AT_declaration);
13654 com_die = new_die (DW_TAG_variable, var_die, decl);
13655 add_name_and_src_coords_attributes (com_die, decl);
13656 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
13657 TREE_THIS_VOLATILE (decl), context_die);
13658 add_AT_flag (com_die, DW_AT_external, 1);
13662 add_loc_descr (&loc, new_loc_descr (DW_OP_plus_uconst, off, 0));
13663 add_AT_loc (com_die, DW_AT_location, loc);
13665 else if (DECL_EXTERNAL (decl))
13666 add_AT_flag (com_die, DW_AT_declaration, 1);
13667 equate_decl_number_to_die (decl, com_die);
13671 var_die = new_die (DW_TAG_variable, context_die, decl);
13673 if (origin != NULL)
13674 add_abstract_origin_attribute (var_die, origin);
13676 /* Loop unrolling can create multiple blocks that refer to the same
13677 static variable, so we must test for the DW_AT_declaration flag.
13679 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13680 copy decls and set the DECL_ABSTRACT flag on them instead of
13683 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13685 ??? The declare_in_namespace support causes us to get two DIEs for one
13686 variable, both of which are declarations. We want to avoid considering
13687 one to be a specification, so we must test that this DIE is not a
13689 else if (old_die && TREE_STATIC (decl) && ! declaration
13690 && get_AT_flag (old_die, DW_AT_declaration) == 1)
13692 /* This is a definition of a C++ class level static. */
13693 add_AT_specification (var_die, old_die);
13694 if (DECL_NAME (decl))
13696 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13697 struct dwarf_file_data * file_index = lookup_filename (s.file);
13699 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13700 add_AT_file (var_die, DW_AT_decl_file, file_index);
13702 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13703 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
13708 tree type = TREE_TYPE (decl);
13710 add_name_and_src_coords_attributes (var_die, decl);
13711 if ((TREE_CODE (decl) == PARM_DECL
13712 || TREE_CODE (decl) == RESULT_DECL)
13713 && DECL_BY_REFERENCE (decl))
13714 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
13716 add_type_attribute (var_die, type, TREE_READONLY (decl),
13717 TREE_THIS_VOLATILE (decl), context_die);
13719 if (TREE_PUBLIC (decl))
13720 add_AT_flag (var_die, DW_AT_external, 1);
13722 if (DECL_ARTIFICIAL (decl))
13723 add_AT_flag (var_die, DW_AT_artificial, 1);
13725 if (TREE_PROTECTED (decl))
13726 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
13727 else if (TREE_PRIVATE (decl))
13728 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
13732 add_AT_flag (var_die, DW_AT_declaration, 1);
13734 if (DECL_ABSTRACT (decl) || declaration)
13735 equate_decl_number_to_die (decl, var_die);
13737 if (! declaration && ! DECL_ABSTRACT (decl))
13739 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
13740 add_pubname (decl, var_die);
13743 tree_add_const_value_attribute (var_die, decl);
13746 /* Generate a DIE to represent a label identifier. */
13749 gen_label_die (tree decl, dw_die_ref context_die)
13751 tree origin = decl_ultimate_origin (decl);
13752 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
13754 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13756 if (origin != NULL)
13757 add_abstract_origin_attribute (lbl_die, origin);
13759 add_name_and_src_coords_attributes (lbl_die, decl);
13761 if (DECL_ABSTRACT (decl))
13762 equate_decl_number_to_die (decl, lbl_die);
13765 insn = DECL_RTL_IF_SET (decl);
13767 /* Deleted labels are programmer specified labels which have been
13768 eliminated because of various optimizations. We still emit them
13769 here so that it is possible to put breakpoints on them. */
13773 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
13775 /* When optimization is enabled (via -O) some parts of the compiler
13776 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
13777 represent source-level labels which were explicitly declared by
13778 the user. This really shouldn't be happening though, so catch
13779 it if it ever does happen. */
13780 gcc_assert (!INSN_DELETED_P (insn));
13782 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
13783 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
13788 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
13789 attributes to the DIE for a block STMT, to describe where the inlined
13790 function was called from. This is similar to add_src_coords_attributes. */
13793 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
13795 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
13797 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
13798 add_AT_unsigned (die, DW_AT_call_line, s.line);
13802 /* If STMT's abstract origin is a function declaration and STMT's
13803 first subblock's abstract origin is the function's outermost block,
13804 then we're looking at the main entry point. */
13806 is_inlined_entry_point (const_tree stmt)
13810 if (!stmt || TREE_CODE (stmt) != BLOCK)
13813 decl = block_ultimate_origin (stmt);
13815 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
13818 block = BLOCK_SUBBLOCKS (stmt);
13822 if (TREE_CODE (block) != BLOCK)
13825 block = block_ultimate_origin (block);
13828 return block == DECL_INITIAL (decl);
13831 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
13832 Add low_pc and high_pc attributes to the DIE for a block STMT. */
13835 add_high_low_attributes (tree stmt, dw_die_ref die)
13837 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13839 if (BLOCK_FRAGMENT_CHAIN (stmt))
13843 if (is_inlined_entry_point (stmt))
13845 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13846 BLOCK_NUMBER (stmt));
13847 add_AT_lbl_id (die, DW_AT_entry_pc, label);
13850 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
13852 chain = BLOCK_FRAGMENT_CHAIN (stmt);
13855 add_ranges (chain);
13856 chain = BLOCK_FRAGMENT_CHAIN (chain);
13863 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13864 BLOCK_NUMBER (stmt));
13865 add_AT_lbl_id (die, DW_AT_low_pc, label);
13866 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
13867 BLOCK_NUMBER (stmt));
13868 add_AT_lbl_id (die, DW_AT_high_pc, label);
13872 /* Generate a DIE for a lexical block. */
13875 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
13877 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
13879 if (! BLOCK_ABSTRACT (stmt))
13880 add_high_low_attributes (stmt, stmt_die);
13882 decls_for_scope (stmt, stmt_die, depth);
13885 /* Generate a DIE for an inlined subprogram. */
13888 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
13890 tree decl = block_ultimate_origin (stmt);
13892 /* Emit info for the abstract instance first, if we haven't yet. We
13893 must emit this even if the block is abstract, otherwise when we
13894 emit the block below (or elsewhere), we may end up trying to emit
13895 a die whose origin die hasn't been emitted, and crashing. */
13896 dwarf2out_abstract_function (decl);
13898 if (! BLOCK_ABSTRACT (stmt))
13900 dw_die_ref subr_die
13901 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13903 add_abstract_origin_attribute (subr_die, decl);
13904 add_high_low_attributes (stmt, subr_die);
13905 add_call_src_coords_attributes (stmt, subr_die);
13907 decls_for_scope (stmt, subr_die, depth);
13908 current_function_has_inlines = 1;
13911 /* We may get here if we're the outer block of function A that was
13912 inlined into function B that was inlined into function C. When
13913 generating debugging info for C, dwarf2out_abstract_function(B)
13914 would mark all inlined blocks as abstract, including this one.
13915 So, we wouldn't (and shouldn't) expect labels to be generated
13916 for this one. Instead, just emit debugging info for
13917 declarations within the block. This is particularly important
13918 in the case of initializers of arguments passed from B to us:
13919 if they're statement expressions containing declarations, we
13920 wouldn't generate dies for their abstract variables, and then,
13921 when generating dies for the real variables, we'd die (pun
13923 gen_lexical_block_die (stmt, context_die, depth);
13926 /* Generate a DIE for a field in a record, or structure. */
13929 gen_field_die (tree decl, dw_die_ref context_die)
13931 dw_die_ref decl_die;
13933 if (TREE_TYPE (decl) == error_mark_node)
13936 decl_die = new_die (DW_TAG_member, context_die, decl);
13937 add_name_and_src_coords_attributes (decl_die, decl);
13938 add_type_attribute (decl_die, member_declared_type (decl),
13939 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13942 if (DECL_BIT_FIELD_TYPE (decl))
13944 add_byte_size_attribute (decl_die, decl);
13945 add_bit_size_attribute (decl_die, decl);
13946 add_bit_offset_attribute (decl_die, decl);
13949 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13950 add_data_member_location_attribute (decl_die, decl);
13952 if (DECL_ARTIFICIAL (decl))
13953 add_AT_flag (decl_die, DW_AT_artificial, 1);
13955 if (TREE_PROTECTED (decl))
13956 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13957 else if (TREE_PRIVATE (decl))
13958 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13960 /* Equate decl number to die, so that we can look up this decl later on. */
13961 equate_decl_number_to_die (decl, decl_die);
13965 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13966 Use modified_type_die instead.
13967 We keep this code here just in case these types of DIEs may be needed to
13968 represent certain things in other languages (e.g. Pascal) someday. */
13971 gen_pointer_type_die (tree type, dw_die_ref context_die)
13974 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13976 equate_type_number_to_die (type, ptr_die);
13977 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13978 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13981 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13982 Use modified_type_die instead.
13983 We keep this code here just in case these types of DIEs may be needed to
13984 represent certain things in other languages (e.g. Pascal) someday. */
13987 gen_reference_type_die (tree type, dw_die_ref context_die)
13990 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13992 equate_type_number_to_die (type, ref_die);
13993 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13994 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13998 /* Generate a DIE for a pointer to a member type. */
14001 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14004 = new_die (DW_TAG_ptr_to_member_type,
14005 scope_die_for (type, context_die), type);
14007 equate_type_number_to_die (type, ptr_die);
14008 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14009 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14010 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14013 /* Generate the DIE for the compilation unit. */
14016 gen_compile_unit_die (const char *filename)
14019 char producer[250];
14020 const char *language_string = lang_hooks.name;
14023 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14027 add_name_attribute (die, filename);
14028 /* Don't add cwd for <built-in>. */
14029 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14030 add_comp_dir_attribute (die);
14033 sprintf (producer, "%s %s", language_string, version_string);
14035 #ifdef MIPS_DEBUGGING_INFO
14036 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14037 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14038 not appear in the producer string, the debugger reaches the conclusion
14039 that the object file is stripped and has no debugging information.
14040 To get the MIPS/SGI debugger to believe that there is debugging
14041 information in the object file, we add a -g to the producer string. */
14042 if (debug_info_level > DINFO_LEVEL_TERSE)
14043 strcat (producer, " -g");
14046 add_AT_string (die, DW_AT_producer, producer);
14048 if (strcmp (language_string, "GNU C++") == 0)
14049 language = DW_LANG_C_plus_plus;
14050 else if (strcmp (language_string, "GNU Ada") == 0)
14051 language = DW_LANG_Ada95;
14052 else if (strcmp (language_string, "GNU F77") == 0)
14053 language = DW_LANG_Fortran77;
14054 else if (strcmp (language_string, "GNU Fortran") == 0)
14055 language = DW_LANG_Fortran95;
14056 else if (strcmp (language_string, "GNU Pascal") == 0)
14057 language = DW_LANG_Pascal83;
14058 else if (strcmp (language_string, "GNU Java") == 0)
14059 language = DW_LANG_Java;
14060 else if (strcmp (language_string, "GNU Objective-C") == 0)
14061 language = DW_LANG_ObjC;
14062 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14063 language = DW_LANG_ObjC_plus_plus;
14065 language = DW_LANG_C89;
14067 add_AT_unsigned (die, DW_AT_language, language);
14071 /* Generate the DIE for a base class. */
14074 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14076 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14078 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14079 add_data_member_location_attribute (die, binfo);
14081 if (BINFO_VIRTUAL_P (binfo))
14082 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14084 if (access == access_public_node)
14085 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14086 else if (access == access_protected_node)
14087 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14090 /* Generate a DIE for a class member. */
14093 gen_member_die (tree type, dw_die_ref context_die)
14096 tree binfo = TYPE_BINFO (type);
14099 /* If this is not an incomplete type, output descriptions of each of its
14100 members. Note that as we output the DIEs necessary to represent the
14101 members of this record or union type, we will also be trying to output
14102 DIEs to represent the *types* of those members. However the `type'
14103 function (above) will specifically avoid generating type DIEs for member
14104 types *within* the list of member DIEs for this (containing) type except
14105 for those types (of members) which are explicitly marked as also being
14106 members of this (containing) type themselves. The g++ front- end can
14107 force any given type to be treated as a member of some other (containing)
14108 type by setting the TYPE_CONTEXT of the given (member) type to point to
14109 the TREE node representing the appropriate (containing) type. */
14111 /* First output info about the base classes. */
14114 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14118 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14119 gen_inheritance_die (base,
14120 (accesses ? VEC_index (tree, accesses, i)
14121 : access_public_node), context_die);
14124 /* Now output info about the data members and type members. */
14125 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14127 /* If we thought we were generating minimal debug info for TYPE
14128 and then changed our minds, some of the member declarations
14129 may have already been defined. Don't define them again, but
14130 do put them in the right order. */
14132 child = lookup_decl_die (member);
14134 splice_child_die (context_die, child);
14136 gen_decl_die (member, context_die);
14139 /* Now output info about the function members (if any). */
14140 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14142 /* Don't include clones in the member list. */
14143 if (DECL_ABSTRACT_ORIGIN (member))
14146 child = lookup_decl_die (member);
14148 splice_child_die (context_die, child);
14150 gen_decl_die (member, context_die);
14154 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14155 is set, we pretend that the type was never defined, so we only get the
14156 member DIEs needed by later specification DIEs. */
14159 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14160 enum debug_info_usage usage)
14162 dw_die_ref type_die = lookup_type_die (type);
14163 dw_die_ref scope_die = 0;
14165 int complete = (TYPE_SIZE (type)
14166 && (! TYPE_STUB_DECL (type)
14167 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14168 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14169 complete = complete && should_emit_struct_debug (type, usage);
14171 if (type_die && ! complete)
14174 if (TYPE_CONTEXT (type) != NULL_TREE
14175 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14176 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14179 scope_die = scope_die_for (type, context_die);
14181 if (! type_die || (nested && scope_die == comp_unit_die))
14182 /* First occurrence of type or toplevel definition of nested class. */
14184 dw_die_ref old_die = type_die;
14186 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14187 ? record_type_tag (type) : DW_TAG_union_type,
14189 equate_type_number_to_die (type, type_die);
14191 add_AT_specification (type_die, old_die);
14193 add_name_attribute (type_die, type_tag (type));
14196 remove_AT (type_die, DW_AT_declaration);
14198 /* If this type has been completed, then give it a byte_size attribute and
14199 then give a list of members. */
14200 if (complete && !ns_decl)
14202 /* Prevent infinite recursion in cases where the type of some member of
14203 this type is expressed in terms of this type itself. */
14204 TREE_ASM_WRITTEN (type) = 1;
14205 add_byte_size_attribute (type_die, type);
14206 if (TYPE_STUB_DECL (type) != NULL_TREE)
14207 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14209 /* If the first reference to this type was as the return type of an
14210 inline function, then it may not have a parent. Fix this now. */
14211 if (type_die->die_parent == NULL)
14212 add_child_die (scope_die, type_die);
14214 push_decl_scope (type);
14215 gen_member_die (type, type_die);
14218 /* GNU extension: Record what type our vtable lives in. */
14219 if (TYPE_VFIELD (type))
14221 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14223 gen_type_die (vtype, context_die);
14224 add_AT_die_ref (type_die, DW_AT_containing_type,
14225 lookup_type_die (vtype));
14230 add_AT_flag (type_die, DW_AT_declaration, 1);
14232 /* We don't need to do this for function-local types. */
14233 if (TYPE_STUB_DECL (type)
14234 && ! decl_function_context (TYPE_STUB_DECL (type)))
14235 VEC_safe_push (tree, gc, incomplete_types, type);
14238 if (get_AT (type_die, DW_AT_name))
14239 add_pubtype (type, type_die);
14242 /* Generate a DIE for a subroutine _type_. */
14245 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14247 tree return_type = TREE_TYPE (type);
14248 dw_die_ref subr_die
14249 = new_die (DW_TAG_subroutine_type,
14250 scope_die_for (type, context_die), type);
14252 equate_type_number_to_die (type, subr_die);
14253 add_prototyped_attribute (subr_die, type);
14254 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14255 gen_formal_types_die (type, subr_die);
14257 if (get_AT (subr_die, DW_AT_name))
14258 add_pubtype (type, subr_die);
14261 /* Generate a DIE for a type definition. */
14264 gen_typedef_die (tree decl, dw_die_ref context_die)
14266 dw_die_ref type_die;
14269 if (TREE_ASM_WRITTEN (decl))
14272 TREE_ASM_WRITTEN (decl) = 1;
14273 type_die = new_die (DW_TAG_typedef, context_die, decl);
14274 origin = decl_ultimate_origin (decl);
14275 if (origin != NULL)
14276 add_abstract_origin_attribute (type_die, origin);
14281 add_name_and_src_coords_attributes (type_die, decl);
14282 if (DECL_ORIGINAL_TYPE (decl))
14284 type = DECL_ORIGINAL_TYPE (decl);
14286 gcc_assert (type != TREE_TYPE (decl));
14287 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14290 type = TREE_TYPE (decl);
14292 add_type_attribute (type_die, type, TREE_READONLY (decl),
14293 TREE_THIS_VOLATILE (decl), context_die);
14296 if (DECL_ABSTRACT (decl))
14297 equate_decl_number_to_die (decl, type_die);
14299 if (get_AT (type_die, DW_AT_name))
14300 add_pubtype (decl, type_die);
14303 /* Generate a type description DIE. */
14306 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14307 enum debug_info_usage usage)
14310 struct array_descr_info info;
14312 if (type == NULL_TREE || type == error_mark_node)
14315 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14316 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14318 if (TREE_ASM_WRITTEN (type))
14321 /* Prevent broken recursion; we can't hand off to the same type. */
14322 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14324 TREE_ASM_WRITTEN (type) = 1;
14325 gen_decl_die (TYPE_NAME (type), context_die);
14329 /* If this is an array type with hidden descriptor, handle it first. */
14330 if (!TREE_ASM_WRITTEN (type)
14331 && lang_hooks.types.get_array_descr_info
14332 && lang_hooks.types.get_array_descr_info (type, &info))
14334 gen_descr_array_type_die (type, &info, context_die);
14335 TREE_ASM_WRITTEN (type) = 1;
14339 /* We are going to output a DIE to represent the unqualified version
14340 of this type (i.e. without any const or volatile qualifiers) so
14341 get the main variant (i.e. the unqualified version) of this type
14342 now. (Vectors are special because the debugging info is in the
14343 cloned type itself). */
14344 if (TREE_CODE (type) != VECTOR_TYPE)
14345 type = type_main_variant (type);
14347 if (TREE_ASM_WRITTEN (type))
14350 switch (TREE_CODE (type))
14356 case REFERENCE_TYPE:
14357 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14358 ensures that the gen_type_die recursion will terminate even if the
14359 type is recursive. Recursive types are possible in Ada. */
14360 /* ??? We could perhaps do this for all types before the switch
14362 TREE_ASM_WRITTEN (type) = 1;
14364 /* For these types, all that is required is that we output a DIE (or a
14365 set of DIEs) to represent the "basis" type. */
14366 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14367 DINFO_USAGE_IND_USE);
14371 /* This code is used for C++ pointer-to-data-member types.
14372 Output a description of the relevant class type. */
14373 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
14374 DINFO_USAGE_IND_USE);
14376 /* Output a description of the type of the object pointed to. */
14377 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14378 DINFO_USAGE_IND_USE);
14380 /* Now output a DIE to represent this pointer-to-data-member type
14382 gen_ptr_to_mbr_type_die (type, context_die);
14385 case FUNCTION_TYPE:
14386 /* Force out return type (in case it wasn't forced out already). */
14387 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14388 DINFO_USAGE_DIR_USE);
14389 gen_subroutine_type_die (type, context_die);
14393 /* Force out return type (in case it wasn't forced out already). */
14394 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14395 DINFO_USAGE_DIR_USE);
14396 gen_subroutine_type_die (type, context_die);
14400 gen_array_type_die (type, context_die);
14404 gen_array_type_die (type, context_die);
14407 case ENUMERAL_TYPE:
14410 case QUAL_UNION_TYPE:
14411 /* If this is a nested type whose containing class hasn't been written
14412 out yet, writing it out will cover this one, too. This does not apply
14413 to instantiations of member class templates; they need to be added to
14414 the containing class as they are generated. FIXME: This hurts the
14415 idea of combining type decls from multiple TUs, since we can't predict
14416 what set of template instantiations we'll get. */
14417 if (TYPE_CONTEXT (type)
14418 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14419 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
14421 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
14423 if (TREE_ASM_WRITTEN (type))
14426 /* If that failed, attach ourselves to the stub. */
14427 push_decl_scope (TYPE_CONTEXT (type));
14428 context_die = lookup_type_die (TYPE_CONTEXT (type));
14433 context_die = declare_in_namespace (type, context_die);
14437 if (TREE_CODE (type) == ENUMERAL_TYPE)
14439 /* This might have been written out by the call to
14440 declare_in_namespace. */
14441 if (!TREE_ASM_WRITTEN (type))
14442 gen_enumeration_type_die (type, context_die);
14445 gen_struct_or_union_type_die (type, context_die, usage);
14450 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14451 it up if it is ever completed. gen_*_type_die will set it for us
14452 when appropriate. */
14458 case FIXED_POINT_TYPE:
14461 /* No DIEs needed for fundamental types. */
14465 /* No Dwarf representation currently defined. */
14469 gcc_unreachable ();
14472 TREE_ASM_WRITTEN (type) = 1;
14476 gen_type_die (tree type, dw_die_ref context_die)
14478 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14481 /* Generate a DIE for a tagged type instantiation. */
14484 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
14486 if (type == NULL_TREE || type == error_mark_node)
14489 /* We are going to output a DIE to represent the unqualified version of
14490 this type (i.e. without any const or volatile qualifiers) so make sure
14491 that we have the main variant (i.e. the unqualified version) of this
14493 gcc_assert (type == type_main_variant (type));
14495 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14496 an instance of an unresolved type. */
14498 switch (TREE_CODE (type))
14503 case ENUMERAL_TYPE:
14504 gen_inlined_enumeration_type_die (type, context_die);
14508 gen_inlined_structure_type_die (type, context_die);
14512 case QUAL_UNION_TYPE:
14513 gen_inlined_union_type_die (type, context_die);
14517 gcc_unreachable ();
14521 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14522 things which are local to the given block. */
14525 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14527 int must_output_die = 0;
14530 enum tree_code origin_code;
14532 /* Ignore blocks that are NULL. */
14533 if (stmt == NULL_TREE)
14536 /* If the block is one fragment of a non-contiguous block, do not
14537 process the variables, since they will have been done by the
14538 origin block. Do process subblocks. */
14539 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14543 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14544 gen_block_die (sub, context_die, depth + 1);
14549 /* Determine the "ultimate origin" of this block. This block may be an
14550 inlined instance of an inlined instance of inline function, so we have
14551 to trace all of the way back through the origin chain to find out what
14552 sort of node actually served as the original seed for the creation of
14553 the current block. */
14554 origin = block_ultimate_origin (stmt);
14555 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
14557 /* Determine if we need to output any Dwarf DIEs at all to represent this
14559 if (origin_code == FUNCTION_DECL)
14560 /* The outer scopes for inlinings *must* always be represented. We
14561 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14562 must_output_die = 1;
14565 /* In the case where the current block represents an inlining of the
14566 "body block" of an inline function, we must *NOT* output any DIE for
14567 this block because we have already output a DIE to represent the whole
14568 inlined function scope and the "body block" of any function doesn't
14569 really represent a different scope according to ANSI C rules. So we
14570 check here to make sure that this block does not represent a "body
14571 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14572 if (! is_body_block (origin ? origin : stmt))
14574 /* Determine if this block directly contains any "significant"
14575 local declarations which we will need to output DIEs for. */
14576 if (debug_info_level > DINFO_LEVEL_TERSE)
14577 /* We are not in terse mode so *any* local declaration counts
14578 as being a "significant" one. */
14579 must_output_die = (BLOCK_VARS (stmt) != NULL
14580 && (TREE_USED (stmt)
14581 || TREE_ASM_WRITTEN (stmt)
14582 || BLOCK_ABSTRACT (stmt)));
14584 /* We are in terse mode, so only local (nested) function
14585 definitions count as "significant" local declarations. */
14586 for (decl = BLOCK_VARS (stmt);
14587 decl != NULL; decl = TREE_CHAIN (decl))
14588 if (TREE_CODE (decl) == FUNCTION_DECL
14589 && DECL_INITIAL (decl))
14591 must_output_die = 1;
14597 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14598 DIE for any block which contains no significant local declarations at
14599 all. Rather, in such cases we just call `decls_for_scope' so that any
14600 needed Dwarf info for any sub-blocks will get properly generated. Note
14601 that in terse mode, our definition of what constitutes a "significant"
14602 local declaration gets restricted to include only inlined function
14603 instances and local (nested) function definitions. */
14604 if (must_output_die)
14606 if (origin_code == FUNCTION_DECL)
14607 gen_inlined_subroutine_die (stmt, context_die, depth);
14609 gen_lexical_block_die (stmt, context_die, depth);
14612 decls_for_scope (stmt, context_die, depth);
14615 /* Generate all of the decls declared within a given scope and (recursively)
14616 all of its sub-blocks. */
14619 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
14624 /* Ignore NULL blocks. */
14625 if (stmt == NULL_TREE)
14628 if (TREE_USED (stmt))
14630 /* Output the DIEs to represent all of the data objects and typedefs
14631 declared directly within this block but not within any nested
14632 sub-blocks. Also, nested function and tag DIEs have been
14633 generated with a parent of NULL; fix that up now. */
14634 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
14638 if (TREE_CODE (decl) == FUNCTION_DECL)
14639 die = lookup_decl_die (decl);
14640 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
14641 die = lookup_type_die (TREE_TYPE (decl));
14645 if (die != NULL && die->die_parent == NULL)
14646 add_child_die (context_die, die);
14647 /* Do not produce debug information for static variables since
14648 these might be optimized out. We are called for these later
14649 in varpool_analyze_pending_decls.
14651 But *do* produce it for Fortran COMMON variables because,
14652 even though they are static, their names can differ depending
14653 on the scope, which we need to preserve. */
14654 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
14655 && !(is_fortran () && TREE_PUBLIC (decl)))
14658 gen_decl_die (decl, context_die);
14662 /* If we're at -g1, we're not interested in subblocks. */
14663 if (debug_info_level <= DINFO_LEVEL_TERSE)
14666 /* Output the DIEs to represent all sub-blocks (and the items declared
14667 therein) of this block. */
14668 for (subblocks = BLOCK_SUBBLOCKS (stmt);
14670 subblocks = BLOCK_CHAIN (subblocks))
14671 gen_block_die (subblocks, context_die, depth + 1);
14674 /* Is this a typedef we can avoid emitting? */
14677 is_redundant_typedef (const_tree decl)
14679 if (TYPE_DECL_IS_STUB (decl))
14682 if (DECL_ARTIFICIAL (decl)
14683 && DECL_CONTEXT (decl)
14684 && is_tagged_type (DECL_CONTEXT (decl))
14685 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
14686 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
14687 /* Also ignore the artificial member typedef for the class name. */
14693 /* Returns the DIE for a context. */
14695 static inline dw_die_ref
14696 get_context_die (tree context)
14700 /* Find die that represents this context. */
14701 if (TYPE_P (context))
14702 return force_type_die (context);
14704 return force_decl_die (context);
14706 return comp_unit_die;
14709 /* Returns the DIE for decl. A DIE will always be returned. */
14712 force_decl_die (tree decl)
14714 dw_die_ref decl_die;
14715 unsigned saved_external_flag;
14716 tree save_fn = NULL_TREE;
14717 decl_die = lookup_decl_die (decl);
14720 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
14722 decl_die = lookup_decl_die (decl);
14726 switch (TREE_CODE (decl))
14728 case FUNCTION_DECL:
14729 /* Clear current_function_decl, so that gen_subprogram_die thinks
14730 that this is a declaration. At this point, we just want to force
14731 declaration die. */
14732 save_fn = current_function_decl;
14733 current_function_decl = NULL_TREE;
14734 gen_subprogram_die (decl, context_die);
14735 current_function_decl = save_fn;
14739 /* Set external flag to force declaration die. Restore it after
14740 gen_decl_die() call. */
14741 saved_external_flag = DECL_EXTERNAL (decl);
14742 DECL_EXTERNAL (decl) = 1;
14743 gen_decl_die (decl, context_die);
14744 DECL_EXTERNAL (decl) = saved_external_flag;
14747 case NAMESPACE_DECL:
14748 dwarf2out_decl (decl);
14752 gcc_unreachable ();
14755 /* We should be able to find the DIE now. */
14757 decl_die = lookup_decl_die (decl);
14758 gcc_assert (decl_die);
14764 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
14765 always returned. */
14768 force_type_die (tree type)
14770 dw_die_ref type_die;
14772 type_die = lookup_type_die (type);
14775 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
14777 type_die = modified_type_die (type, TYPE_READONLY (type),
14778 TYPE_VOLATILE (type), context_die);
14779 gcc_assert (type_die);
14784 /* Force out any required namespaces to be able to output DECL,
14785 and return the new context_die for it, if it's changed. */
14788 setup_namespace_context (tree thing, dw_die_ref context_die)
14790 tree context = (DECL_P (thing)
14791 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
14792 if (context && TREE_CODE (context) == NAMESPACE_DECL)
14793 /* Force out the namespace. */
14794 context_die = force_decl_die (context);
14796 return context_die;
14799 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
14800 type) within its namespace, if appropriate.
14802 For compatibility with older debuggers, namespace DIEs only contain
14803 declarations; all definitions are emitted at CU scope. */
14806 declare_in_namespace (tree thing, dw_die_ref context_die)
14808 dw_die_ref ns_context;
14810 if (debug_info_level <= DINFO_LEVEL_TERSE)
14811 return context_die;
14813 /* If this decl is from an inlined function, then don't try to emit it in its
14814 namespace, as we will get confused. It would have already been emitted
14815 when the abstract instance of the inline function was emitted anyways. */
14816 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
14817 return context_die;
14819 ns_context = setup_namespace_context (thing, context_die);
14821 if (ns_context != context_die)
14825 if (DECL_P (thing))
14826 gen_decl_die (thing, ns_context);
14828 gen_type_die (thing, ns_context);
14830 return context_die;
14833 /* Generate a DIE for a namespace or namespace alias. */
14836 gen_namespace_die (tree decl)
14838 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
14840 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
14841 they are an alias of. */
14842 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
14844 /* Output a real namespace. */
14845 dw_die_ref namespace_die
14846 = new_die (is_fortran () ? DW_TAG_module : DW_TAG_namespace,
14847 context_die, decl);
14848 add_name_and_src_coords_attributes (namespace_die, decl);
14849 if (DECL_EXTERNAL (decl))
14850 add_AT_flag (namespace_die, DW_AT_declaration, 1);
14851 equate_decl_number_to_die (decl, namespace_die);
14855 /* Output a namespace alias. */
14857 /* Force out the namespace we are an alias of, if necessary. */
14858 dw_die_ref origin_die
14859 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
14861 /* Now create the namespace alias DIE. */
14862 dw_die_ref namespace_die
14863 = new_die (DW_TAG_imported_declaration, context_die, decl);
14864 add_name_and_src_coords_attributes (namespace_die, decl);
14865 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
14866 equate_decl_number_to_die (decl, namespace_die);
14870 /* Generate Dwarf debug information for a decl described by DECL. */
14873 gen_decl_die (tree decl, dw_die_ref context_die)
14877 if (DECL_P (decl) && DECL_IGNORED_P (decl))
14880 switch (TREE_CODE (decl))
14886 /* The individual enumerators of an enum type get output when we output
14887 the Dwarf representation of the relevant enum type itself. */
14890 case FUNCTION_DECL:
14891 /* Don't output any DIEs to represent mere function declarations,
14892 unless they are class members or explicit block externs. */
14893 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
14894 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
14899 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14900 on local redeclarations of global functions. That seems broken. */
14901 if (current_function_decl != decl)
14902 /* This is only a declaration. */;
14905 /* If we're emitting a clone, emit info for the abstract instance. */
14906 if (DECL_ORIGIN (decl) != decl)
14907 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14909 /* If we're emitting an out-of-line copy of an inline function,
14910 emit info for the abstract instance and set up to refer to it. */
14911 else if (cgraph_function_possibly_inlined_p (decl)
14912 && ! DECL_ABSTRACT (decl)
14913 && ! class_or_namespace_scope_p (context_die)
14914 /* dwarf2out_abstract_function won't emit a die if this is just
14915 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14916 that case, because that works only if we have a die. */
14917 && DECL_INITIAL (decl) != NULL_TREE)
14919 dwarf2out_abstract_function (decl);
14920 set_decl_origin_self (decl);
14923 /* Otherwise we're emitting the primary DIE for this decl. */
14924 else if (debug_info_level > DINFO_LEVEL_TERSE)
14926 /* Before we describe the FUNCTION_DECL itself, make sure that we
14927 have described its return type. */
14928 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14930 /* And its virtual context. */
14931 if (DECL_VINDEX (decl) != NULL_TREE)
14932 gen_type_die (DECL_CONTEXT (decl), context_die);
14934 /* And its containing type. */
14935 origin = decl_class_context (decl);
14936 if (origin != NULL_TREE)
14937 gen_type_die_for_member (origin, decl, context_die);
14939 /* And its containing namespace. */
14940 context_die = declare_in_namespace (decl, context_die);
14943 /* Now output a DIE to represent the function itself. */
14944 gen_subprogram_die (decl, context_die);
14948 /* If we are in terse mode, don't generate any DIEs to represent any
14949 actual typedefs. */
14950 if (debug_info_level <= DINFO_LEVEL_TERSE)
14953 /* In the special case of a TYPE_DECL node representing the declaration
14954 of some type tag, if the given TYPE_DECL is marked as having been
14955 instantiated from some other (original) TYPE_DECL node (e.g. one which
14956 was generated within the original definition of an inline function) we
14957 have to generate a special (abbreviated) DW_TAG_structure_type,
14958 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14959 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14960 && is_tagged_type (TREE_TYPE (decl)))
14962 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14966 if (is_redundant_typedef (decl))
14967 gen_type_die (TREE_TYPE (decl), context_die);
14969 /* Output a DIE to represent the typedef itself. */
14970 gen_typedef_die (decl, context_die);
14974 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14975 gen_label_die (decl, context_die);
14980 /* If we are in terse mode, don't generate any DIEs to represent any
14981 variable declarations or definitions. */
14982 if (debug_info_level <= DINFO_LEVEL_TERSE)
14985 /* Output any DIEs that are needed to specify the type of this data
14987 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14988 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14990 gen_type_die (TREE_TYPE (decl), context_die);
14992 /* And its containing type. */
14993 origin = decl_class_context (decl);
14994 if (origin != NULL_TREE)
14995 gen_type_die_for_member (origin, decl, context_die);
14997 /* And its containing namespace. */
14998 context_die = declare_in_namespace (decl, context_die);
15000 /* Now output the DIE to represent the data object itself. This gets
15001 complicated because of the possibility that the VAR_DECL really
15002 represents an inlined instance of a formal parameter for an inline
15004 origin = decl_ultimate_origin (decl);
15005 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15006 gen_formal_parameter_die (decl, context_die);
15008 gen_variable_die (decl, context_die);
15012 /* Ignore the nameless fields that are used to skip bits but handle C++
15013 anonymous unions and structs. */
15014 if (DECL_NAME (decl) != NULL_TREE
15015 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15016 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15018 gen_type_die (member_declared_type (decl), context_die);
15019 gen_field_die (decl, context_die);
15024 if (DECL_BY_REFERENCE (decl))
15025 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15027 gen_type_die (TREE_TYPE (decl), context_die);
15028 gen_formal_parameter_die (decl, context_die);
15031 case NAMESPACE_DECL:
15032 gen_namespace_die (decl);
15036 /* Probably some frontend-internal decl. Assume we don't care. */
15037 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15042 /* Output debug information for global decl DECL. Called from toplev.c after
15043 compilation proper has finished. */
15046 dwarf2out_global_decl (tree decl)
15048 /* Output DWARF2 information for file-scope tentative data object
15049 declarations, file-scope (extern) function declarations (which
15050 had no corresponding body) and file-scope tagged type declarations
15051 and definitions which have not yet been forced out. */
15052 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15053 dwarf2out_decl (decl);
15056 /* Output debug information for type decl DECL. Called from toplev.c
15057 and from language front ends (to record built-in types). */
15059 dwarf2out_type_decl (tree decl, int local)
15062 dwarf2out_decl (decl);
15065 /* Output debug information for imported module or decl DECL.
15066 NAME is non-NULL name in context if the decl has been renamed.
15067 CHILD is true if decl is one of the renamed decls as part of
15068 importing whole module. */
15071 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15074 dw_die_ref imported_die, at_import_die;
15075 dw_die_ref scope_die;
15076 expanded_location xloc;
15078 if (debug_info_level <= DINFO_LEVEL_TERSE)
15083 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15084 We need decl DIE for reference and scope die. First, get DIE for the decl
15087 /* Get the scope die for decl context. Use comp_unit_die for global module
15088 or decl. If die is not found for non globals, force new die. */
15090 && TYPE_P (context)
15091 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15093 scope_die = get_context_die (context);
15097 gcc_assert (scope_die->die_child);
15098 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15099 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15100 scope_die = scope_die->die_child;
15103 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
15104 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15106 if (is_base_type (TREE_TYPE (decl)))
15107 at_import_die = base_type_die (TREE_TYPE (decl));
15109 at_import_die = force_type_die (TREE_TYPE (decl));
15110 /* For namespace N { typedef void T; } using N::T; base_type_die
15111 returns NULL, but DW_TAG_imported_declaration requires
15112 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15113 if (!at_import_die)
15115 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15116 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15117 at_import_die = lookup_type_die (TREE_TYPE (decl));
15118 gcc_assert (at_import_die);
15123 at_import_die = lookup_decl_die (decl);
15124 if (!at_import_die)
15126 /* If we're trying to avoid duplicate debug info, we may not have
15127 emitted the member decl for this field. Emit it now. */
15128 if (TREE_CODE (decl) == FIELD_DECL)
15130 tree type = DECL_CONTEXT (decl);
15132 if (TYPE_CONTEXT (type)
15133 && TYPE_P (TYPE_CONTEXT (type))
15134 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15135 DINFO_USAGE_DIR_USE))
15137 gen_type_die_for_member (type, decl,
15138 get_context_die (TYPE_CONTEXT (type)));
15140 at_import_die = force_decl_die (decl);
15144 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15145 if (TREE_CODE (decl) == NAMESPACE_DECL)
15146 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
15148 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
15150 xloc = expand_location (input_location);
15151 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15152 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15154 add_AT_string (imported_die, DW_AT_name, IDENTIFIER_POINTER (name));
15155 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15158 /* Write the debugging output for DECL. */
15161 dwarf2out_decl (tree decl)
15163 dw_die_ref context_die = comp_unit_die;
15165 switch (TREE_CODE (decl))
15170 case FUNCTION_DECL:
15171 /* What we would really like to do here is to filter out all mere
15172 file-scope declarations of file-scope functions which are never
15173 referenced later within this translation unit (and keep all of ones
15174 that *are* referenced later on) but we aren't clairvoyant, so we have
15175 no idea which functions will be referenced in the future (i.e. later
15176 on within the current translation unit). So here we just ignore all
15177 file-scope function declarations which are not also definitions. If
15178 and when the debugger needs to know something about these functions,
15179 it will have to hunt around and find the DWARF information associated
15180 with the definition of the function.
15182 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15183 nodes represent definitions and which ones represent mere
15184 declarations. We have to check DECL_INITIAL instead. That's because
15185 the C front-end supports some weird semantics for "extern inline"
15186 function definitions. These can get inlined within the current
15187 translation unit (and thus, we need to generate Dwarf info for their
15188 abstract instances so that the Dwarf info for the concrete inlined
15189 instances can have something to refer to) but the compiler never
15190 generates any out-of-lines instances of such things (despite the fact
15191 that they *are* definitions).
15193 The important point is that the C front-end marks these "extern
15194 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15195 them anyway. Note that the C++ front-end also plays some similar games
15196 for inline function definitions appearing within include files which
15197 also contain `#pragma interface' pragmas. */
15198 if (DECL_INITIAL (decl) == NULL_TREE)
15201 /* If we're a nested function, initially use a parent of NULL; if we're
15202 a plain function, this will be fixed up in decls_for_scope. If
15203 we're a method, it will be ignored, since we already have a DIE. */
15204 if (decl_function_context (decl)
15205 /* But if we're in terse mode, we don't care about scope. */
15206 && debug_info_level > DINFO_LEVEL_TERSE)
15207 context_die = NULL;
15211 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15212 declaration and if the declaration was never even referenced from
15213 within this entire compilation unit. We suppress these DIEs in
15214 order to save space in the .debug section (by eliminating entries
15215 which are probably useless). Note that we must not suppress
15216 block-local extern declarations (whether used or not) because that
15217 would screw-up the debugger's name lookup mechanism and cause it to
15218 miss things which really ought to be in scope at a given point. */
15219 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15222 /* For local statics lookup proper context die. */
15223 if (TREE_STATIC (decl) && decl_function_context (decl))
15224 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15226 /* If we are in terse mode, don't generate any DIEs to represent any
15227 variable declarations or definitions. */
15228 if (debug_info_level <= DINFO_LEVEL_TERSE)
15232 case NAMESPACE_DECL:
15233 if (debug_info_level <= DINFO_LEVEL_TERSE)
15235 if (lookup_decl_die (decl) != NULL)
15240 /* Don't emit stubs for types unless they are needed by other DIEs. */
15241 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15244 /* Don't bother trying to generate any DIEs to represent any of the
15245 normal built-in types for the language we are compiling. */
15246 if (DECL_IS_BUILTIN (decl))
15248 /* OK, we need to generate one for `bool' so GDB knows what type
15249 comparisons have. */
15251 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15252 && ! DECL_IGNORED_P (decl))
15253 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15258 /* If we are in terse mode, don't generate any DIEs for types. */
15259 if (debug_info_level <= DINFO_LEVEL_TERSE)
15262 /* If we're a function-scope tag, initially use a parent of NULL;
15263 this will be fixed up in decls_for_scope. */
15264 if (decl_function_context (decl))
15265 context_die = NULL;
15273 gen_decl_die (decl, context_die);
15276 /* Output a marker (i.e. a label) for the beginning of the generated code for
15277 a lexical block. */
15280 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15281 unsigned int blocknum)
15283 switch_to_section (current_function_section ());
15284 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15287 /* Output a marker (i.e. a label) for the end of the generated code for a
15291 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15293 switch_to_section (current_function_section ());
15294 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15297 /* Returns nonzero if it is appropriate not to emit any debugging
15298 information for BLOCK, because it doesn't contain any instructions.
15300 Don't allow this for blocks with nested functions or local classes
15301 as we would end up with orphans, and in the presence of scheduling
15302 we may end up calling them anyway. */
15305 dwarf2out_ignore_block (const_tree block)
15309 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15310 if (TREE_CODE (decl) == FUNCTION_DECL
15311 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15317 /* Hash table routines for file_hash. */
15320 file_table_eq (const void *p1_p, const void *p2_p)
15322 const struct dwarf_file_data *const p1 =
15323 (const struct dwarf_file_data *) p1_p;
15324 const char *const p2 = (const char *) p2_p;
15325 return strcmp (p1->filename, p2) == 0;
15329 file_table_hash (const void *p_p)
15331 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15332 return htab_hash_string (p->filename);
15335 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15336 dwarf2out.c) and return its "index". The index of each (known) filename is
15337 just a unique number which is associated with only that one filename. We
15338 need such numbers for the sake of generating labels (in the .debug_sfnames
15339 section) and references to those files numbers (in the .debug_srcinfo
15340 and.debug_macinfo sections). If the filename given as an argument is not
15341 found in our current list, add it to the list and assign it the next
15342 available unique index number. In order to speed up searches, we remember
15343 the index of the filename was looked up last. This handles the majority of
15346 static struct dwarf_file_data *
15347 lookup_filename (const char *file_name)
15350 struct dwarf_file_data * created;
15352 /* Check to see if the file name that was searched on the previous
15353 call matches this file name. If so, return the index. */
15354 if (file_table_last_lookup
15355 && (file_name == file_table_last_lookup->filename
15356 || strcmp (file_table_last_lookup->filename, file_name) == 0))
15357 return file_table_last_lookup;
15359 /* Didn't match the previous lookup, search the table. */
15360 slot = htab_find_slot_with_hash (file_table, file_name,
15361 htab_hash_string (file_name), INSERT);
15363 return (struct dwarf_file_data *) *slot;
15365 created = GGC_NEW (struct dwarf_file_data);
15366 created->filename = file_name;
15367 created->emitted_number = 0;
15372 /* If the assembler will construct the file table, then translate the compiler
15373 internal file table number into the assembler file table number, and emit
15374 a .file directive if we haven't already emitted one yet. The file table
15375 numbers are different because we prune debug info for unused variables and
15376 types, which may include filenames. */
15379 maybe_emit_file (struct dwarf_file_data * fd)
15381 if (! fd->emitted_number)
15383 if (last_emitted_file)
15384 fd->emitted_number = last_emitted_file->emitted_number + 1;
15386 fd->emitted_number = 1;
15387 last_emitted_file = fd;
15389 if (DWARF2_ASM_LINE_DEBUG_INFO)
15391 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
15392 output_quoted_string (asm_out_file,
15393 remap_debug_filename (fd->filename));
15394 fputc ('\n', asm_out_file);
15398 return fd->emitted_number;
15401 /* Called by the final INSN scan whenever we see a var location. We
15402 use it to drop labels in the right places, and throw the location in
15403 our lookup table. */
15406 dwarf2out_var_location (rtx loc_note)
15408 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
15409 struct var_loc_node *newloc;
15411 static rtx last_insn;
15412 static const char *last_label;
15415 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
15417 prev_insn = PREV_INSN (loc_note);
15419 newloc = GGC_CNEW (struct var_loc_node);
15420 /* If the insn we processed last time is the previous insn
15421 and it is also a var location note, use the label we emitted
15423 if (last_insn != NULL_RTX
15424 && last_insn == prev_insn
15425 && NOTE_P (prev_insn)
15426 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
15428 newloc->label = last_label;
15432 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
15433 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
15435 newloc->label = ggc_strdup (loclabel);
15437 newloc->var_loc_note = loc_note;
15438 newloc->next = NULL;
15440 if (cfun && in_cold_section_p)
15441 newloc->section_label = crtl->subsections.cold_section_label;
15443 newloc->section_label = text_section_label;
15445 last_insn = loc_note;
15446 last_label = newloc->label;
15447 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15448 add_var_loc_to_decl (decl, newloc);
15451 /* We need to reset the locations at the beginning of each
15452 function. We can't do this in the end_function hook, because the
15453 declarations that use the locations won't have been output when
15454 that hook is called. Also compute have_multiple_function_sections here. */
15457 dwarf2out_begin_function (tree fun)
15459 htab_empty (decl_loc_table);
15461 if (function_section (fun) != text_section)
15462 have_multiple_function_sections = true;
15464 dwarf2out_note_section_used ();
15467 /* Output a label to mark the beginning of a source code line entry
15468 and record information relating to this source line, in
15469 'line_info_table' for later output of the .debug_line section. */
15472 dwarf2out_source_line (unsigned int line, const char *filename)
15474 if (debug_info_level >= DINFO_LEVEL_NORMAL
15477 int file_num = maybe_emit_file (lookup_filename (filename));
15479 switch_to_section (current_function_section ());
15481 /* If requested, emit something human-readable. */
15482 if (flag_debug_asm)
15483 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15486 if (DWARF2_ASM_LINE_DEBUG_INFO)
15488 /* Emit the .loc directive understood by GNU as. */
15489 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15491 /* Indicate that line number info exists. */
15492 line_info_table_in_use++;
15494 else if (function_section (current_function_decl) != text_section)
15496 dw_separate_line_info_ref line_info;
15497 targetm.asm_out.internal_label (asm_out_file,
15498 SEPARATE_LINE_CODE_LABEL,
15499 separate_line_info_table_in_use);
15501 /* Expand the line info table if necessary. */
15502 if (separate_line_info_table_in_use
15503 == separate_line_info_table_allocated)
15505 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15506 separate_line_info_table
15507 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15508 separate_line_info_table,
15509 separate_line_info_table_allocated);
15510 memset (separate_line_info_table
15511 + separate_line_info_table_in_use,
15513 (LINE_INFO_TABLE_INCREMENT
15514 * sizeof (dw_separate_line_info_entry)));
15517 /* Add the new entry at the end of the line_info_table. */
15519 = &separate_line_info_table[separate_line_info_table_in_use++];
15520 line_info->dw_file_num = file_num;
15521 line_info->dw_line_num = line;
15522 line_info->function = current_function_funcdef_no;
15526 dw_line_info_ref line_info;
15528 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
15529 line_info_table_in_use);
15531 /* Expand the line info table if necessary. */
15532 if (line_info_table_in_use == line_info_table_allocated)
15534 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15536 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
15537 line_info_table_allocated);
15538 memset (line_info_table + line_info_table_in_use, 0,
15539 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
15542 /* Add the new entry at the end of the line_info_table. */
15543 line_info = &line_info_table[line_info_table_in_use++];
15544 line_info->dw_file_num = file_num;
15545 line_info->dw_line_num = line;
15550 /* Record the beginning of a new source file. */
15553 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
15555 if (flag_eliminate_dwarf2_dups)
15557 /* Record the beginning of the file for break_out_includes. */
15558 dw_die_ref bincl_die;
15560 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
15561 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
15564 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15566 int file_num = maybe_emit_file (lookup_filename (filename));
15568 switch_to_section (debug_macinfo_section);
15569 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
15570 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
15573 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
15577 /* Record the end of a source file. */
15580 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
15582 if (flag_eliminate_dwarf2_dups)
15583 /* Record the end of the file for break_out_includes. */
15584 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
15586 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15588 switch_to_section (debug_macinfo_section);
15589 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
15593 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15594 the tail part of the directive line, i.e. the part which is past the
15595 initial whitespace, #, whitespace, directive-name, whitespace part. */
15598 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
15599 const char *buffer ATTRIBUTE_UNUSED)
15601 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15603 switch_to_section (debug_macinfo_section);
15604 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
15605 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15606 dw2_asm_output_nstring (buffer, -1, "The macro");
15610 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15611 the tail part of the directive line, i.e. the part which is past the
15612 initial whitespace, #, whitespace, directive-name, whitespace part. */
15615 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
15616 const char *buffer ATTRIBUTE_UNUSED)
15618 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15620 switch_to_section (debug_macinfo_section);
15621 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
15622 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15623 dw2_asm_output_nstring (buffer, -1, "The macro");
15627 /* Set up for Dwarf output at the start of compilation. */
15630 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
15632 /* Allocate the file_table. */
15633 file_table = htab_create_ggc (50, file_table_hash,
15634 file_table_eq, NULL);
15636 /* Allocate the decl_die_table. */
15637 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
15638 decl_die_table_eq, NULL);
15640 /* Allocate the decl_loc_table. */
15641 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
15642 decl_loc_table_eq, NULL);
15644 /* Allocate the initial hunk of the decl_scope_table. */
15645 decl_scope_table = VEC_alloc (tree, gc, 256);
15647 /* Allocate the initial hunk of the abbrev_die_table. */
15648 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
15649 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
15650 /* Zero-th entry is allocated, but unused. */
15651 abbrev_die_table_in_use = 1;
15653 /* Allocate the initial hunk of the line_info_table. */
15654 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
15655 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
15657 /* Zero-th entry is allocated, but unused. */
15658 line_info_table_in_use = 1;
15660 /* Allocate the pubtypes and pubnames vectors. */
15661 pubname_table = VEC_alloc (pubname_entry, gc, 32);
15662 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
15664 /* Generate the initial DIE for the .debug section. Note that the (string)
15665 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15666 will (typically) be a relative pathname and that this pathname should be
15667 taken as being relative to the directory from which the compiler was
15668 invoked when the given (base) source file was compiled. We will fill
15669 in this value in dwarf2out_finish. */
15670 comp_unit_die = gen_compile_unit_die (NULL);
15672 incomplete_types = VEC_alloc (tree, gc, 64);
15674 used_rtx_array = VEC_alloc (rtx, gc, 32);
15676 debug_info_section = get_section (DEBUG_INFO_SECTION,
15677 SECTION_DEBUG, NULL);
15678 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
15679 SECTION_DEBUG, NULL);
15680 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
15681 SECTION_DEBUG, NULL);
15682 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
15683 SECTION_DEBUG, NULL);
15684 debug_line_section = get_section (DEBUG_LINE_SECTION,
15685 SECTION_DEBUG, NULL);
15686 debug_loc_section = get_section (DEBUG_LOC_SECTION,
15687 SECTION_DEBUG, NULL);
15688 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
15689 SECTION_DEBUG, NULL);
15690 #ifdef DEBUG_PUBTYPES_SECTION
15691 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
15692 SECTION_DEBUG, NULL);
15694 debug_str_section = get_section (DEBUG_STR_SECTION,
15695 DEBUG_STR_SECTION_FLAGS, NULL);
15696 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
15697 SECTION_DEBUG, NULL);
15698 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
15699 SECTION_DEBUG, NULL);
15701 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
15702 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
15703 DEBUG_ABBREV_SECTION_LABEL, 0);
15704 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
15705 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
15706 COLD_TEXT_SECTION_LABEL, 0);
15707 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
15709 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
15710 DEBUG_INFO_SECTION_LABEL, 0);
15711 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
15712 DEBUG_LINE_SECTION_LABEL, 0);
15713 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
15714 DEBUG_RANGES_SECTION_LABEL, 0);
15715 switch_to_section (debug_abbrev_section);
15716 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
15717 switch_to_section (debug_info_section);
15718 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
15719 switch_to_section (debug_line_section);
15720 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
15722 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15724 switch_to_section (debug_macinfo_section);
15725 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
15726 DEBUG_MACINFO_SECTION_LABEL, 0);
15727 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
15730 switch_to_section (text_section);
15731 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
15732 if (flag_reorder_blocks_and_partition)
15734 cold_text_section = unlikely_text_section ();
15735 switch_to_section (cold_text_section);
15736 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
15740 /* A helper function for dwarf2out_finish called through
15741 ht_forall. Emit one queued .debug_str string. */
15744 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
15746 struct indirect_string_node *node = (struct indirect_string_node *) *h;
15748 if (node->form == DW_FORM_strp)
15750 switch_to_section (debug_str_section);
15751 ASM_OUTPUT_LABEL (asm_out_file, node->label);
15752 assemble_string (node->str, strlen (node->str) + 1);
15758 #if ENABLE_ASSERT_CHECKING
15759 /* Verify that all marks are clear. */
15762 verify_marks_clear (dw_die_ref die)
15766 gcc_assert (! die->die_mark);
15767 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
15769 #endif /* ENABLE_ASSERT_CHECKING */
15771 /* Clear the marks for a die and its children.
15772 Be cool if the mark isn't set. */
15775 prune_unmark_dies (dw_die_ref die)
15781 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
15784 /* Given DIE that we're marking as used, find any other dies
15785 it references as attributes and mark them as used. */
15788 prune_unused_types_walk_attribs (dw_die_ref die)
15793 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15795 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
15797 /* A reference to another DIE.
15798 Make sure that it will get emitted. */
15799 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
15801 /* Set the string's refcount to 0 so that prune_unused_types_mark
15802 accounts properly for it. */
15803 if (AT_class (a) == dw_val_class_str)
15804 a->dw_attr_val.v.val_str->refcount = 0;
15809 /* Mark DIE as being used. If DOKIDS is true, then walk down
15810 to DIE's children. */
15813 prune_unused_types_mark (dw_die_ref die, int dokids)
15817 if (die->die_mark == 0)
15819 /* We haven't done this node yet. Mark it as used. */
15822 /* We also have to mark its parents as used.
15823 (But we don't want to mark our parents' kids due to this.) */
15824 if (die->die_parent)
15825 prune_unused_types_mark (die->die_parent, 0);
15827 /* Mark any referenced nodes. */
15828 prune_unused_types_walk_attribs (die);
15830 /* If this node is a specification,
15831 also mark the definition, if it exists. */
15832 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
15833 prune_unused_types_mark (die->die_definition, 1);
15836 if (dokids && die->die_mark != 2)
15838 /* We need to walk the children, but haven't done so yet.
15839 Remember that we've walked the kids. */
15842 /* If this is an array type, we need to make sure our
15843 kids get marked, even if they're types. */
15844 if (die->die_tag == DW_TAG_array_type)
15845 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
15847 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15852 /* Walk the tree DIE and mark types that we actually use. */
15855 prune_unused_types_walk (dw_die_ref die)
15859 /* Don't do anything if this node is already marked. */
15863 switch (die->die_tag)
15865 case DW_TAG_const_type:
15866 case DW_TAG_packed_type:
15867 case DW_TAG_pointer_type:
15868 case DW_TAG_reference_type:
15869 case DW_TAG_volatile_type:
15870 case DW_TAG_typedef:
15871 case DW_TAG_array_type:
15872 case DW_TAG_structure_type:
15873 case DW_TAG_union_type:
15874 case DW_TAG_class_type:
15875 case DW_TAG_interface_type:
15876 case DW_TAG_friend:
15877 case DW_TAG_variant_part:
15878 case DW_TAG_enumeration_type:
15879 case DW_TAG_subroutine_type:
15880 case DW_TAG_string_type:
15881 case DW_TAG_set_type:
15882 case DW_TAG_subrange_type:
15883 case DW_TAG_ptr_to_member_type:
15884 case DW_TAG_file_type:
15885 if (die->die_perennial_p)
15888 /* It's a type node --- don't mark it. */
15892 /* Mark everything else. */
15898 /* Now, mark any dies referenced from here. */
15899 prune_unused_types_walk_attribs (die);
15901 /* Mark children. */
15902 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15905 /* Increment the string counts on strings referred to from DIE's
15909 prune_unused_types_update_strings (dw_die_ref die)
15914 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15915 if (AT_class (a) == dw_val_class_str)
15917 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15919 /* Avoid unnecessarily putting strings that are used less than
15920 twice in the hash table. */
15922 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15925 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15926 htab_hash_string (s->str),
15928 gcc_assert (*slot == NULL);
15934 /* Remove from the tree DIE any dies that aren't marked. */
15937 prune_unused_types_prune (dw_die_ref die)
15941 gcc_assert (die->die_mark);
15942 prune_unused_types_update_strings (die);
15944 if (! die->die_child)
15947 c = die->die_child;
15949 dw_die_ref prev = c;
15950 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15951 if (c == die->die_child)
15953 /* No marked children between 'prev' and the end of the list. */
15955 /* No marked children at all. */
15956 die->die_child = NULL;
15959 prev->die_sib = c->die_sib;
15960 die->die_child = prev;
15965 if (c != prev->die_sib)
15967 prune_unused_types_prune (c);
15968 } while (c != die->die_child);
15972 /* Remove dies representing declarations that we never use. */
15975 prune_unused_types (void)
15978 limbo_die_node *node;
15981 #if ENABLE_ASSERT_CHECKING
15982 /* All the marks should already be clear. */
15983 verify_marks_clear (comp_unit_die);
15984 for (node = limbo_die_list; node; node = node->next)
15985 verify_marks_clear (node->die);
15986 #endif /* ENABLE_ASSERT_CHECKING */
15988 /* Set the mark on nodes that are actually used. */
15989 prune_unused_types_walk (comp_unit_die);
15990 for (node = limbo_die_list; node; node = node->next)
15991 prune_unused_types_walk (node->die);
15993 /* Also set the mark on nodes referenced from the
15994 pubname_table or arange_table. */
15995 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15996 prune_unused_types_mark (pub->die, 1);
15997 for (i = 0; i < arange_table_in_use; i++)
15998 prune_unused_types_mark (arange_table[i], 1);
16000 /* Get rid of nodes that aren't marked; and update the string counts. */
16001 if (debug_str_hash)
16002 htab_empty (debug_str_hash);
16003 prune_unused_types_prune (comp_unit_die);
16004 for (node = limbo_die_list; node; node = node->next)
16005 prune_unused_types_prune (node->die);
16007 /* Leave the marks clear. */
16008 prune_unmark_dies (comp_unit_die);
16009 for (node = limbo_die_list; node; node = node->next)
16010 prune_unmark_dies (node->die);
16013 /* Set the parameter to true if there are any relative pathnames in
16016 file_table_relative_p (void ** slot, void *param)
16018 bool *p = (bool *) param;
16019 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16020 if (!IS_ABSOLUTE_PATH (d->filename))
16028 /* Output stuff that dwarf requires at the end of every file,
16029 and generate the DWARF-2 debugging info. */
16032 dwarf2out_finish (const char *filename)
16034 limbo_die_node *node, *next_node;
16035 dw_die_ref die = 0;
16037 /* Add the name for the main input file now. We delayed this from
16038 dwarf2out_init to avoid complications with PCH. */
16039 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
16040 if (!IS_ABSOLUTE_PATH (filename))
16041 add_comp_dir_attribute (comp_unit_die);
16042 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
16045 htab_traverse (file_table, file_table_relative_p, &p);
16047 add_comp_dir_attribute (comp_unit_die);
16050 /* Traverse the limbo die list, and add parent/child links. The only
16051 dies without parents that should be here are concrete instances of
16052 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16053 For concrete instances, we can get the parent die from the abstract
16055 for (node = limbo_die_list; node; node = next_node)
16057 next_node = node->next;
16060 if (die->die_parent == NULL)
16062 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
16065 add_child_die (origin->die_parent, die);
16066 else if (die == comp_unit_die)
16068 else if (errorcount > 0 || sorrycount > 0)
16069 /* It's OK to be confused by errors in the input. */
16070 add_child_die (comp_unit_die, die);
16073 /* In certain situations, the lexical block containing a
16074 nested function can be optimized away, which results
16075 in the nested function die being orphaned. Likewise
16076 with the return type of that nested function. Force
16077 this to be a child of the containing function.
16079 It may happen that even the containing function got fully
16080 inlined and optimized out. In that case we are lost and
16081 assign the empty child. This should not be big issue as
16082 the function is likely unreachable too. */
16083 tree context = NULL_TREE;
16085 gcc_assert (node->created_for);
16087 if (DECL_P (node->created_for))
16088 context = DECL_CONTEXT (node->created_for);
16089 else if (TYPE_P (node->created_for))
16090 context = TYPE_CONTEXT (node->created_for);
16092 gcc_assert (context
16093 && (TREE_CODE (context) == FUNCTION_DECL
16094 || TREE_CODE (context) == NAMESPACE_DECL));
16096 origin = lookup_decl_die (context);
16098 add_child_die (origin, die);
16100 add_child_die (comp_unit_die, die);
16105 limbo_die_list = NULL;
16107 /* Walk through the list of incomplete types again, trying once more to
16108 emit full debugging info for them. */
16109 retry_incomplete_types ();
16111 if (flag_eliminate_unused_debug_types)
16112 prune_unused_types ();
16114 /* Generate separate CUs for each of the include files we've seen.
16115 They will go into limbo_die_list. */
16116 if (flag_eliminate_dwarf2_dups)
16117 break_out_includes (comp_unit_die);
16119 /* Traverse the DIE's and add add sibling attributes to those DIE's
16120 that have children. */
16121 add_sibling_attributes (comp_unit_die);
16122 for (node = limbo_die_list; node; node = node->next)
16123 add_sibling_attributes (node->die);
16125 /* Output a terminator label for the .text section. */
16126 switch_to_section (text_section);
16127 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16128 if (flag_reorder_blocks_and_partition)
16130 switch_to_section (unlikely_text_section ());
16131 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16134 /* We can only use the low/high_pc attributes if all of the code was
16136 if (!have_multiple_function_sections)
16138 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16139 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16144 unsigned fde_idx = 0;
16146 /* We need to give .debug_loc and .debug_ranges an appropriate
16147 "base address". Use zero so that these addresses become
16148 absolute. Historically, we've emitted the unexpected
16149 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16150 Emit both to give time for other tools to adapt. */
16151 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16152 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16154 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16155 add_ranges_by_labels (text_section_label,
16157 if (flag_reorder_blocks_and_partition)
16158 add_ranges_by_labels (cold_text_section_label,
16161 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16163 dw_fde_ref fde = &fde_table[fde_idx];
16165 if (fde->dw_fde_switched_sections)
16167 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16168 fde->dw_fde_hot_section_end_label);
16169 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16170 fde->dw_fde_unlikely_section_end_label);
16173 add_ranges_by_labels (fde->dw_fde_begin,
16180 /* Output location list section if necessary. */
16181 if (have_location_lists)
16183 /* Output the location lists info. */
16184 switch_to_section (debug_loc_section);
16185 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16186 DEBUG_LOC_SECTION_LABEL, 0);
16187 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16188 output_location_lists (die);
16191 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16192 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16193 debug_line_section_label);
16195 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16196 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16198 /* Output all of the compilation units. We put the main one last so that
16199 the offsets are available to output_pubnames. */
16200 for (node = limbo_die_list; node; node = node->next)
16201 output_comp_unit (node->die, 0);
16203 output_comp_unit (comp_unit_die, 0);
16205 /* Output the abbreviation table. */
16206 switch_to_section (debug_abbrev_section);
16207 output_abbrev_section ();
16209 /* Output public names table if necessary. */
16210 if (!VEC_empty (pubname_entry, pubname_table))
16212 switch_to_section (debug_pubnames_section);
16213 output_pubnames (pubname_table);
16216 #ifdef DEBUG_PUBTYPES_SECTION
16217 /* Output public types table if necessary. */
16218 if (!VEC_empty (pubname_entry, pubtype_table))
16220 switch_to_section (debug_pubtypes_section);
16221 output_pubnames (pubtype_table);
16225 /* Output the address range information. We only put functions in the arange
16226 table, so don't write it out if we don't have any. */
16227 if (fde_table_in_use)
16229 switch_to_section (debug_aranges_section);
16233 /* Output ranges section if necessary. */
16234 if (ranges_table_in_use)
16236 switch_to_section (debug_ranges_section);
16237 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16241 /* Output the source line correspondence table. We must do this
16242 even if there is no line information. Otherwise, on an empty
16243 translation unit, we will generate a present, but empty,
16244 .debug_info section. IRIX 6.5 `nm' will then complain when
16245 examining the file. This is done late so that any filenames
16246 used by the debug_info section are marked as 'used'. */
16247 if (! DWARF2_ASM_LINE_DEBUG_INFO)
16249 switch_to_section (debug_line_section);
16250 output_line_info ();
16253 /* Have to end the macro section. */
16254 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16256 switch_to_section (debug_macinfo_section);
16257 dw2_asm_output_data (1, 0, "End compilation unit");
16260 /* If we emitted any DW_FORM_strp form attribute, output the string
16262 if (debug_str_hash)
16263 htab_traverse (debug_str_hash, output_indirect_string, NULL);
16267 /* This should never be used, but its address is needed for comparisons. */
16268 const struct gcc_debug_hooks dwarf2_debug_hooks;
16270 #endif /* DWARF2_DEBUGGING_INFO */
16272 #include "gt-dwarf2out.h"