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);
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 void 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);
7203 gen_internal_sym (const char *prefix)
7207 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7208 return xstrdup (buf);
7211 /* Assign symbols to all worthy DIEs under DIE. */
7214 assign_symbol_names (dw_die_ref die)
7218 if (is_symbol_die (die))
7220 if (comdat_symbol_id)
7222 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7224 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7225 comdat_symbol_id, comdat_symbol_number++);
7226 die->die_symbol = xstrdup (p);
7229 die->die_symbol = gen_internal_sym ("LDIE");
7232 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7235 struct cu_hash_table_entry
7238 unsigned min_comdat_num, max_comdat_num;
7239 struct cu_hash_table_entry *next;
7242 /* Routines to manipulate hash table of CUs. */
7244 htab_cu_hash (const void *of)
7246 const struct cu_hash_table_entry *const entry =
7247 (const struct cu_hash_table_entry *) of;
7249 return htab_hash_string (entry->cu->die_symbol);
7253 htab_cu_eq (const void *of1, const void *of2)
7255 const struct cu_hash_table_entry *const entry1 =
7256 (const struct cu_hash_table_entry *) of1;
7257 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7259 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7263 htab_cu_del (void *what)
7265 struct cu_hash_table_entry *next,
7266 *entry = (struct cu_hash_table_entry *) what;
7276 /* Check whether we have already seen this CU and set up SYM_NUM
7279 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7281 struct cu_hash_table_entry dummy;
7282 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7284 dummy.max_comdat_num = 0;
7286 slot = (struct cu_hash_table_entry **)
7287 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7291 for (; entry; last = entry, entry = entry->next)
7293 if (same_die_p_wrap (cu, entry->cu))
7299 *sym_num = entry->min_comdat_num;
7303 entry = XCNEW (struct cu_hash_table_entry);
7305 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7306 entry->next = *slot;
7312 /* Record SYM_NUM to record of CU in HTABLE. */
7314 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7316 struct cu_hash_table_entry **slot, *entry;
7318 slot = (struct cu_hash_table_entry **)
7319 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7323 entry->max_comdat_num = sym_num;
7326 /* Traverse the DIE (which is always comp_unit_die), and set up
7327 additional compilation units for each of the include files we see
7328 bracketed by BINCL/EINCL. */
7331 break_out_includes (dw_die_ref die)
7334 dw_die_ref unit = NULL;
7335 limbo_die_node *node, **pnode;
7336 htab_t cu_hash_table;
7340 dw_die_ref prev = c;
7342 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7343 || (unit && is_comdat_die (c)))
7345 dw_die_ref next = c->die_sib;
7347 /* This DIE is for a secondary CU; remove it from the main one. */
7348 remove_child_with_prev (c, prev);
7350 if (c->die_tag == DW_TAG_GNU_BINCL)
7351 unit = push_new_compile_unit (unit, c);
7352 else if (c->die_tag == DW_TAG_GNU_EINCL)
7353 unit = pop_compile_unit (unit);
7355 add_child_die (unit, c);
7357 if (c == die->die_child)
7360 } while (c != die->die_child);
7363 /* We can only use this in debugging, since the frontend doesn't check
7364 to make sure that we leave every include file we enter. */
7368 assign_symbol_names (die);
7369 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7370 for (node = limbo_die_list, pnode = &limbo_die_list;
7376 compute_section_prefix (node->die);
7377 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7378 &comdat_symbol_number);
7379 assign_symbol_names (node->die);
7381 *pnode = node->next;
7384 pnode = &node->next;
7385 record_comdat_symbol_number (node->die, cu_hash_table,
7386 comdat_symbol_number);
7389 htab_delete (cu_hash_table);
7392 /* Traverse the DIE and add a sibling attribute if it may have the
7393 effect of speeding up access to siblings. To save some space,
7394 avoid generating sibling attributes for DIE's without children. */
7397 add_sibling_attributes (dw_die_ref die)
7401 if (! die->die_child)
7404 if (die->die_parent && die != die->die_parent->die_child)
7405 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7407 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7410 /* Output all location lists for the DIE and its children. */
7413 output_location_lists (dw_die_ref die)
7419 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7420 if (AT_class (a) == dw_val_class_loc_list)
7421 output_loc_list (AT_loc_list (a));
7423 FOR_EACH_CHILD (die, c, output_location_lists (c));
7426 /* The format of each DIE (and its attribute value pairs) is encoded in an
7427 abbreviation table. This routine builds the abbreviation table and assigns
7428 a unique abbreviation id for each abbreviation entry. The children of each
7429 die are visited recursively. */
7432 build_abbrev_table (dw_die_ref die)
7434 unsigned long abbrev_id;
7435 unsigned int n_alloc;
7440 /* Scan the DIE references, and mark as external any that refer to
7441 DIEs from other CUs (i.e. those which are not marked). */
7442 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7443 if (AT_class (a) == dw_val_class_die_ref
7444 && AT_ref (a)->die_mark == 0)
7446 gcc_assert (AT_ref (a)->die_symbol);
7448 set_AT_ref_external (a, 1);
7451 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7453 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7454 dw_attr_ref die_a, abbrev_a;
7458 if (abbrev->die_tag != die->die_tag)
7460 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7463 if (VEC_length (dw_attr_node, abbrev->die_attr)
7464 != VEC_length (dw_attr_node, die->die_attr))
7467 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7469 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7470 if ((abbrev_a->dw_attr != die_a->dw_attr)
7471 || (value_format (abbrev_a) != value_format (die_a)))
7481 if (abbrev_id >= abbrev_die_table_in_use)
7483 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7485 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7486 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7489 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7490 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7491 abbrev_die_table_allocated = n_alloc;
7494 ++abbrev_die_table_in_use;
7495 abbrev_die_table[abbrev_id] = die;
7498 die->die_abbrev = abbrev_id;
7499 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7502 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7505 constant_size (long unsigned int value)
7512 log = floor_log2 (value);
7515 log = 1 << (floor_log2 (log) + 1);
7520 /* Return the size of a DIE as it is represented in the
7521 .debug_info section. */
7523 static unsigned long
7524 size_of_die (dw_die_ref die)
7526 unsigned long size = 0;
7530 size += size_of_uleb128 (die->die_abbrev);
7531 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7533 switch (AT_class (a))
7535 case dw_val_class_addr:
7536 size += DWARF2_ADDR_SIZE;
7538 case dw_val_class_offset:
7539 size += DWARF_OFFSET_SIZE;
7541 case dw_val_class_loc:
7543 unsigned long lsize = size_of_locs (AT_loc (a));
7546 size += constant_size (lsize);
7550 case dw_val_class_loc_list:
7551 size += DWARF_OFFSET_SIZE;
7553 case dw_val_class_range_list:
7554 size += DWARF_OFFSET_SIZE;
7556 case dw_val_class_const:
7557 size += size_of_sleb128 (AT_int (a));
7559 case dw_val_class_unsigned_const:
7560 size += constant_size (AT_unsigned (a));
7562 case dw_val_class_long_long:
7563 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7565 case dw_val_class_vec:
7566 size += 1 + (a->dw_attr_val.v.val_vec.length
7567 * a->dw_attr_val.v.val_vec.elt_size); /* block */
7569 case dw_val_class_flag:
7572 case dw_val_class_die_ref:
7573 if (AT_ref_external (a))
7574 size += DWARF2_ADDR_SIZE;
7576 size += DWARF_OFFSET_SIZE;
7578 case dw_val_class_fde_ref:
7579 size += DWARF_OFFSET_SIZE;
7581 case dw_val_class_lbl_id:
7582 size += DWARF2_ADDR_SIZE;
7584 case dw_val_class_lineptr:
7585 case dw_val_class_macptr:
7586 size += DWARF_OFFSET_SIZE;
7588 case dw_val_class_str:
7589 if (AT_string_form (a) == DW_FORM_strp)
7590 size += DWARF_OFFSET_SIZE;
7592 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7594 case dw_val_class_file:
7595 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7605 /* Size the debugging information associated with a given DIE. Visits the
7606 DIE's children recursively. Updates the global variable next_die_offset, on
7607 each time through. Uses the current value of next_die_offset to update the
7608 die_offset field in each DIE. */
7611 calc_die_sizes (dw_die_ref die)
7615 die->die_offset = next_die_offset;
7616 next_die_offset += size_of_die (die);
7618 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7620 if (die->die_child != NULL)
7621 /* Count the null byte used to terminate sibling lists. */
7622 next_die_offset += 1;
7625 /* Set the marks for a die and its children. We do this so
7626 that we know whether or not a reference needs to use FORM_ref_addr; only
7627 DIEs in the same CU will be marked. We used to clear out the offset
7628 and use that as the flag, but ran into ordering problems. */
7631 mark_dies (dw_die_ref die)
7635 gcc_assert (!die->die_mark);
7638 FOR_EACH_CHILD (die, c, mark_dies (c));
7641 /* Clear the marks for a die and its children. */
7644 unmark_dies (dw_die_ref die)
7648 gcc_assert (die->die_mark);
7651 FOR_EACH_CHILD (die, c, unmark_dies (c));
7654 /* Clear the marks for a die, its children and referred dies. */
7657 unmark_all_dies (dw_die_ref die)
7667 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7669 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7670 if (AT_class (a) == dw_val_class_die_ref)
7671 unmark_all_dies (AT_ref (a));
7674 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7675 generated for the compilation unit. */
7677 static unsigned long
7678 size_of_pubnames (VEC (pubname_entry, gc) * names)
7684 size = DWARF_PUBNAMES_HEADER_SIZE;
7685 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7686 if (names != pubtype_table
7687 || p->die->die_offset != 0
7688 || !flag_eliminate_unused_debug_types)
7689 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7691 size += DWARF_OFFSET_SIZE;
7695 /* Return the size of the information in the .debug_aranges section. */
7697 static unsigned long
7698 size_of_aranges (void)
7702 size = DWARF_ARANGES_HEADER_SIZE;
7704 /* Count the address/length pair for this compilation unit. */
7705 if (text_section_used)
7706 size += 2 * DWARF2_ADDR_SIZE;
7707 if (cold_text_section_used)
7708 size += 2 * DWARF2_ADDR_SIZE;
7709 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7711 /* Count the two zero words used to terminated the address range table. */
7712 size += 2 * DWARF2_ADDR_SIZE;
7716 /* Select the encoding of an attribute value. */
7718 static enum dwarf_form
7719 value_format (dw_attr_ref a)
7721 switch (a->dw_attr_val.val_class)
7723 case dw_val_class_addr:
7724 return DW_FORM_addr;
7725 case dw_val_class_range_list:
7726 case dw_val_class_offset:
7727 case dw_val_class_loc_list:
7728 switch (DWARF_OFFSET_SIZE)
7731 return DW_FORM_data4;
7733 return DW_FORM_data8;
7737 case dw_val_class_loc:
7738 switch (constant_size (size_of_locs (AT_loc (a))))
7741 return DW_FORM_block1;
7743 return DW_FORM_block2;
7747 case dw_val_class_const:
7748 return DW_FORM_sdata;
7749 case dw_val_class_unsigned_const:
7750 switch (constant_size (AT_unsigned (a)))
7753 return DW_FORM_data1;
7755 return DW_FORM_data2;
7757 return DW_FORM_data4;
7759 return DW_FORM_data8;
7763 case dw_val_class_long_long:
7764 return DW_FORM_block1;
7765 case dw_val_class_vec:
7766 return DW_FORM_block1;
7767 case dw_val_class_flag:
7768 return DW_FORM_flag;
7769 case dw_val_class_die_ref:
7770 if (AT_ref_external (a))
7771 return DW_FORM_ref_addr;
7774 case dw_val_class_fde_ref:
7775 return DW_FORM_data;
7776 case dw_val_class_lbl_id:
7777 return DW_FORM_addr;
7778 case dw_val_class_lineptr:
7779 case dw_val_class_macptr:
7780 return DW_FORM_data;
7781 case dw_val_class_str:
7782 return AT_string_form (a);
7783 case dw_val_class_file:
7784 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7787 return DW_FORM_data1;
7789 return DW_FORM_data2;
7791 return DW_FORM_data4;
7801 /* Output the encoding of an attribute value. */
7804 output_value_format (dw_attr_ref a)
7806 enum dwarf_form form = value_format (a);
7808 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7811 /* Output the .debug_abbrev section which defines the DIE abbreviation
7815 output_abbrev_section (void)
7817 unsigned long abbrev_id;
7819 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7821 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7825 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7826 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7827 dwarf_tag_name (abbrev->die_tag));
7829 if (abbrev->die_child != NULL)
7830 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7832 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7834 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7837 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7838 dwarf_attr_name (a_attr->dw_attr));
7839 output_value_format (a_attr);
7842 dw2_asm_output_data (1, 0, NULL);
7843 dw2_asm_output_data (1, 0, NULL);
7846 /* Terminate the table. */
7847 dw2_asm_output_data (1, 0, NULL);
7850 /* Output a symbol we can use to refer to this DIE from another CU. */
7853 output_die_symbol (dw_die_ref die)
7855 char *sym = die->die_symbol;
7860 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7861 /* We make these global, not weak; if the target doesn't support
7862 .linkonce, it doesn't support combining the sections, so debugging
7864 targetm.asm_out.globalize_label (asm_out_file, sym);
7866 ASM_OUTPUT_LABEL (asm_out_file, sym);
7869 /* Return a new location list, given the begin and end range, and the
7870 expression. gensym tells us whether to generate a new internal symbol for
7871 this location list node, which is done for the head of the list only. */
7873 static inline dw_loc_list_ref
7874 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7875 const char *section, unsigned int gensym)
7877 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7879 retlist->begin = begin;
7881 retlist->expr = expr;
7882 retlist->section = section;
7884 retlist->ll_symbol = gen_internal_sym ("LLST");
7889 /* Add a location description expression to a location list. */
7892 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7893 const char *begin, const char *end,
7894 const char *section)
7898 /* Find the end of the chain. */
7899 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7902 /* Add a new location list node to the list. */
7903 *d = new_loc_list (descr, begin, end, section, 0);
7906 /* Output the location list given to us. */
7909 output_loc_list (dw_loc_list_ref list_head)
7911 dw_loc_list_ref curr = list_head;
7913 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7915 /* Walk the location list, and output each range + expression. */
7916 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7919 /* Don't output an entry that starts and ends at the same address. */
7920 if (strcmp (curr->begin, curr->end) == 0)
7922 if (!have_multiple_function_sections)
7924 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7925 "Location list begin address (%s)",
7926 list_head->ll_symbol);
7927 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7928 "Location list end address (%s)",
7929 list_head->ll_symbol);
7933 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7934 "Location list begin address (%s)",
7935 list_head->ll_symbol);
7936 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7937 "Location list end address (%s)",
7938 list_head->ll_symbol);
7940 size = size_of_locs (curr->expr);
7942 /* Output the block length for this list of location operations. */
7943 gcc_assert (size <= 0xffff);
7944 dw2_asm_output_data (2, size, "%s", "Location expression size");
7946 output_loc_sequence (curr->expr);
7949 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7950 "Location list terminator begin (%s)",
7951 list_head->ll_symbol);
7952 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7953 "Location list terminator end (%s)",
7954 list_head->ll_symbol);
7957 /* Output the DIE and its attributes. Called recursively to generate
7958 the definitions of each child DIE. */
7961 output_die (dw_die_ref die)
7968 /* If someone in another CU might refer to us, set up a symbol for
7969 them to point to. */
7970 if (die->die_symbol)
7971 output_die_symbol (die);
7973 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7974 (unsigned long)die->die_offset,
7975 dwarf_tag_name (die->die_tag));
7977 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7979 const char *name = dwarf_attr_name (a->dw_attr);
7981 switch (AT_class (a))
7983 case dw_val_class_addr:
7984 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7987 case dw_val_class_offset:
7988 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7992 case dw_val_class_range_list:
7994 char *p = strchr (ranges_section_label, '\0');
7996 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7997 a->dw_attr_val.v.val_offset);
7998 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7999 debug_ranges_section, "%s", name);
8004 case dw_val_class_loc:
8005 size = size_of_locs (AT_loc (a));
8007 /* Output the block length for this list of location operations. */
8008 dw2_asm_output_data (constant_size (size), size, "%s", name);
8010 output_loc_sequence (AT_loc (a));
8013 case dw_val_class_const:
8014 /* ??? It would be slightly more efficient to use a scheme like is
8015 used for unsigned constants below, but gdb 4.x does not sign
8016 extend. Gdb 5.x does sign extend. */
8017 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8020 case dw_val_class_unsigned_const:
8021 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8022 AT_unsigned (a), "%s", name);
8025 case dw_val_class_long_long:
8027 unsigned HOST_WIDE_INT first, second;
8029 dw2_asm_output_data (1,
8030 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8033 if (WORDS_BIG_ENDIAN)
8035 first = a->dw_attr_val.v.val_long_long.hi;
8036 second = a->dw_attr_val.v.val_long_long.low;
8040 first = a->dw_attr_val.v.val_long_long.low;
8041 second = a->dw_attr_val.v.val_long_long.hi;
8044 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8045 first, "long long constant");
8046 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8051 case dw_val_class_vec:
8053 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8054 unsigned int len = a->dw_attr_val.v.val_vec.length;
8058 dw2_asm_output_data (1, len * elt_size, "%s", name);
8059 if (elt_size > sizeof (HOST_WIDE_INT))
8064 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8067 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8068 "fp or vector constant word %u", i);
8072 case dw_val_class_flag:
8073 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8076 case dw_val_class_loc_list:
8078 char *sym = AT_loc_list (a)->ll_symbol;
8081 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8086 case dw_val_class_die_ref:
8087 if (AT_ref_external (a))
8089 char *sym = AT_ref (a)->die_symbol;
8092 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8097 gcc_assert (AT_ref (a)->die_offset);
8098 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8103 case dw_val_class_fde_ref:
8107 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8108 a->dw_attr_val.v.val_fde_index * 2);
8109 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8114 case dw_val_class_lbl_id:
8115 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8118 case dw_val_class_lineptr:
8119 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8120 debug_line_section, "%s", name);
8123 case dw_val_class_macptr:
8124 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8125 debug_macinfo_section, "%s", name);
8128 case dw_val_class_str:
8129 if (AT_string_form (a) == DW_FORM_strp)
8130 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8131 a->dw_attr_val.v.val_str->label,
8133 "%s: \"%s\"", name, AT_string (a));
8135 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8138 case dw_val_class_file:
8140 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8142 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8143 a->dw_attr_val.v.val_file->filename);
8152 FOR_EACH_CHILD (die, c, output_die (c));
8154 /* Add null byte to terminate sibling list. */
8155 if (die->die_child != NULL)
8156 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8157 (unsigned long) die->die_offset);
8160 /* Output the compilation unit that appears at the beginning of the
8161 .debug_info section, and precedes the DIE descriptions. */
8164 output_compilation_unit_header (void)
8166 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8167 dw2_asm_output_data (4, 0xffffffff,
8168 "Initial length escape value indicating 64-bit DWARF extension");
8169 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8170 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8171 "Length of Compilation Unit Info");
8172 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8173 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8174 debug_abbrev_section,
8175 "Offset Into Abbrev. Section");
8176 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8179 /* Output the compilation unit DIE and its children. */
8182 output_comp_unit (dw_die_ref die, int output_if_empty)
8184 const char *secname;
8187 /* Unless we are outputting main CU, we may throw away empty ones. */
8188 if (!output_if_empty && die->die_child == NULL)
8191 /* Even if there are no children of this DIE, we must output the information
8192 about the compilation unit. Otherwise, on an empty translation unit, we
8193 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8194 will then complain when examining the file. First mark all the DIEs in
8195 this CU so we know which get local refs. */
8198 build_abbrev_table (die);
8200 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8201 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8202 calc_die_sizes (die);
8204 oldsym = die->die_symbol;
8207 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8209 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8211 die->die_symbol = NULL;
8212 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8215 switch_to_section (debug_info_section);
8217 /* Output debugging information. */
8218 output_compilation_unit_header ();
8221 /* Leave the marks on the main CU, so we can check them in
8226 die->die_symbol = oldsym;
8230 /* Return the DWARF2/3 pubname associated with a decl. */
8233 dwarf2_name (tree decl, int scope)
8235 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8238 /* Add a new entry to .debug_pubnames if appropriate. */
8241 add_pubname_string (const char *str, dw_die_ref die)
8246 e.name = xstrdup (str);
8247 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8251 add_pubname (tree decl, dw_die_ref die)
8254 if (TREE_PUBLIC (decl))
8255 add_pubname_string (dwarf2_name (decl, 1), die);
8258 /* Add a new entry to .debug_pubtypes if appropriate. */
8261 add_pubtype (tree decl, dw_die_ref die)
8266 if ((TREE_PUBLIC (decl)
8267 || die->die_parent == comp_unit_die)
8268 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8273 if (TYPE_NAME (decl))
8275 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8276 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8277 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8278 && DECL_NAME (TYPE_NAME (decl)))
8279 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8281 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8285 e.name = xstrdup (dwarf2_name (decl, 1));
8287 /* If we don't have a name for the type, there's no point in adding
8289 if (e.name && e.name[0] != '\0')
8290 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8294 /* Output the public names table used to speed up access to externally
8295 visible names; or the public types table used to find type definitions. */
8298 output_pubnames (VEC (pubname_entry, gc) * names)
8301 unsigned long pubnames_length = size_of_pubnames (names);
8304 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8305 dw2_asm_output_data (4, 0xffffffff,
8306 "Initial length escape value indicating 64-bit DWARF extension");
8307 if (names == pubname_table)
8308 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8309 "Length of Public Names Info");
8311 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8312 "Length of Public Type Names Info");
8313 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8314 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8316 "Offset of Compilation Unit Info");
8317 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8318 "Compilation Unit Length");
8320 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8322 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8323 if (names == pubname_table)
8324 gcc_assert (pub->die->die_mark);
8326 if (names != pubtype_table
8327 || pub->die->die_offset != 0
8328 || !flag_eliminate_unused_debug_types)
8330 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8333 dw2_asm_output_nstring (pub->name, -1, "external name");
8337 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8340 /* Add a new entry to .debug_aranges if appropriate. */
8343 add_arange (tree decl, dw_die_ref die)
8345 if (! DECL_SECTION_NAME (decl))
8348 if (arange_table_in_use == arange_table_allocated)
8350 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8351 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8352 arange_table_allocated);
8353 memset (arange_table + arange_table_in_use, 0,
8354 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8357 arange_table[arange_table_in_use++] = die;
8360 /* Output the information that goes into the .debug_aranges table.
8361 Namely, define the beginning and ending address range of the
8362 text section generated for this compilation unit. */
8365 output_aranges (void)
8368 unsigned long aranges_length = size_of_aranges ();
8370 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8371 dw2_asm_output_data (4, 0xffffffff,
8372 "Initial length escape value indicating 64-bit DWARF extension");
8373 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8374 "Length of Address Ranges Info");
8375 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8376 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8378 "Offset of Compilation Unit Info");
8379 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8380 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8382 /* We need to align to twice the pointer size here. */
8383 if (DWARF_ARANGES_PAD_SIZE)
8385 /* Pad using a 2 byte words so that padding is correct for any
8387 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8388 2 * DWARF2_ADDR_SIZE);
8389 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8390 dw2_asm_output_data (2, 0, NULL);
8393 /* It is necessary not to output these entries if the sections were
8394 not used; if the sections were not used, the length will be 0 and
8395 the address may end up as 0 if the section is discarded by ld
8396 --gc-sections, leaving an invalid (0, 0) entry that can be
8397 confused with the terminator. */
8398 if (text_section_used)
8400 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8401 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8402 text_section_label, "Length");
8404 if (cold_text_section_used)
8406 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8408 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8409 cold_text_section_label, "Length");
8412 for (i = 0; i < arange_table_in_use; i++)
8414 dw_die_ref die = arange_table[i];
8416 /* We shouldn't see aranges for DIEs outside of the main CU. */
8417 gcc_assert (die->die_mark);
8419 if (die->die_tag == DW_TAG_subprogram)
8421 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8423 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8424 get_AT_low_pc (die), "Length");
8428 /* A static variable; extract the symbol from DW_AT_location.
8429 Note that this code isn't currently hit, as we only emit
8430 aranges for functions (jason 9/23/99). */
8431 dw_attr_ref a = get_AT (die, DW_AT_location);
8432 dw_loc_descr_ref loc;
8434 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8437 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8439 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8440 loc->dw_loc_oprnd1.v.val_addr, "Address");
8441 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8442 get_AT_unsigned (die, DW_AT_byte_size),
8447 /* Output the terminator words. */
8448 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8449 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8452 /* Add a new entry to .debug_ranges. Return the offset at which it
8456 add_ranges_num (int num)
8458 unsigned int in_use = ranges_table_in_use;
8460 if (in_use == ranges_table_allocated)
8462 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8463 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8464 ranges_table_allocated);
8465 memset (ranges_table + ranges_table_in_use, 0,
8466 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8469 ranges_table[in_use].num = num;
8470 ranges_table_in_use = in_use + 1;
8472 return in_use * 2 * DWARF2_ADDR_SIZE;
8475 /* Add a new entry to .debug_ranges corresponding to a block, or a
8476 range terminator if BLOCK is NULL. */
8479 add_ranges (const_tree block)
8481 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8484 /* Add a new entry to .debug_ranges corresponding to a pair of
8488 add_ranges_by_labels (const char *begin, const char *end)
8490 unsigned int in_use = ranges_by_label_in_use;
8492 if (in_use == ranges_by_label_allocated)
8494 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8495 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8497 ranges_by_label_allocated);
8498 memset (ranges_by_label + ranges_by_label_in_use, 0,
8499 RANGES_TABLE_INCREMENT
8500 * sizeof (struct dw_ranges_by_label_struct));
8503 ranges_by_label[in_use].begin = begin;
8504 ranges_by_label[in_use].end = end;
8505 ranges_by_label_in_use = in_use + 1;
8507 return add_ranges_num (-(int)in_use - 1);
8511 output_ranges (void)
8514 static const char *const start_fmt = "Offset 0x%x";
8515 const char *fmt = start_fmt;
8517 for (i = 0; i < ranges_table_in_use; i++)
8519 int block_num = ranges_table[i].num;
8523 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8524 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8526 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8527 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8529 /* If all code is in the text section, then the compilation
8530 unit base address defaults to DW_AT_low_pc, which is the
8531 base of the text section. */
8532 if (!have_multiple_function_sections)
8534 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8536 fmt, i * 2 * DWARF2_ADDR_SIZE);
8537 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8538 text_section_label, NULL);
8541 /* Otherwise, the compilation unit base address is zero,
8542 which allows us to use absolute addresses, and not worry
8543 about whether the target supports cross-section
8547 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8548 fmt, i * 2 * DWARF2_ADDR_SIZE);
8549 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8555 /* Negative block_num stands for an index into ranges_by_label. */
8556 else if (block_num < 0)
8558 int lab_idx = - block_num - 1;
8560 if (!have_multiple_function_sections)
8564 /* If we ever use add_ranges_by_labels () for a single
8565 function section, all we have to do is to take out
8567 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8568 ranges_by_label[lab_idx].begin,
8570 fmt, i * 2 * DWARF2_ADDR_SIZE);
8571 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8572 ranges_by_label[lab_idx].end,
8573 text_section_label, NULL);
8578 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8579 ranges_by_label[lab_idx].begin,
8580 fmt, i * 2 * DWARF2_ADDR_SIZE);
8581 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8582 ranges_by_label[lab_idx].end,
8588 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8589 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8595 /* Data structure containing information about input files. */
8598 const char *path; /* Complete file name. */
8599 const char *fname; /* File name part. */
8600 int length; /* Length of entire string. */
8601 struct dwarf_file_data * file_idx; /* Index in input file table. */
8602 int dir_idx; /* Index in directory table. */
8605 /* Data structure containing information about directories with source
8609 const char *path; /* Path including directory name. */
8610 int length; /* Path length. */
8611 int prefix; /* Index of directory entry which is a prefix. */
8612 int count; /* Number of files in this directory. */
8613 int dir_idx; /* Index of directory used as base. */
8616 /* Callback function for file_info comparison. We sort by looking at
8617 the directories in the path. */
8620 file_info_cmp (const void *p1, const void *p2)
8622 const struct file_info *const s1 = (const struct file_info *) p1;
8623 const struct file_info *const s2 = (const struct file_info *) p2;
8624 const unsigned char *cp1;
8625 const unsigned char *cp2;
8627 /* Take care of file names without directories. We need to make sure that
8628 we return consistent values to qsort since some will get confused if
8629 we return the same value when identical operands are passed in opposite
8630 orders. So if neither has a directory, return 0 and otherwise return
8631 1 or -1 depending on which one has the directory. */
8632 if ((s1->path == s1->fname || s2->path == s2->fname))
8633 return (s2->path == s2->fname) - (s1->path == s1->fname);
8635 cp1 = (const unsigned char *) s1->path;
8636 cp2 = (const unsigned char *) s2->path;
8642 /* Reached the end of the first path? If so, handle like above. */
8643 if ((cp1 == (const unsigned char *) s1->fname)
8644 || (cp2 == (const unsigned char *) s2->fname))
8645 return ((cp2 == (const unsigned char *) s2->fname)
8646 - (cp1 == (const unsigned char *) s1->fname));
8648 /* Character of current path component the same? */
8649 else if (*cp1 != *cp2)
8654 struct file_name_acquire_data
8656 struct file_info *files;
8661 /* Traversal function for the hash table. */
8664 file_name_acquire (void ** slot, void *data)
8666 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8667 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8668 struct file_info *fi;
8671 gcc_assert (fnad->max_files >= d->emitted_number);
8673 if (! d->emitted_number)
8676 gcc_assert (fnad->max_files != fnad->used_files);
8678 fi = fnad->files + fnad->used_files++;
8680 /* Skip all leading "./". */
8682 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8685 /* Create a new array entry. */
8687 fi->length = strlen (f);
8690 /* Search for the file name part. */
8691 f = strrchr (f, DIR_SEPARATOR);
8692 #if defined (DIR_SEPARATOR_2)
8694 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8698 if (f == NULL || f < g)
8704 fi->fname = f == NULL ? fi->path : f + 1;
8708 /* Output the directory table and the file name table. We try to minimize
8709 the total amount of memory needed. A heuristic is used to avoid large
8710 slowdowns with many input files. */
8713 output_file_names (void)
8715 struct file_name_acquire_data fnad;
8717 struct file_info *files;
8718 struct dir_info *dirs;
8727 if (!last_emitted_file)
8729 dw2_asm_output_data (1, 0, "End directory table");
8730 dw2_asm_output_data (1, 0, "End file name table");
8734 numfiles = last_emitted_file->emitted_number;
8736 /* Allocate the various arrays we need. */
8737 files = XALLOCAVEC (struct file_info, numfiles);
8738 dirs = XALLOCAVEC (struct dir_info, numfiles);
8741 fnad.used_files = 0;
8742 fnad.max_files = numfiles;
8743 htab_traverse (file_table, file_name_acquire, &fnad);
8744 gcc_assert (fnad.used_files == fnad.max_files);
8746 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8748 /* Find all the different directories used. */
8749 dirs[0].path = files[0].path;
8750 dirs[0].length = files[0].fname - files[0].path;
8751 dirs[0].prefix = -1;
8753 dirs[0].dir_idx = 0;
8754 files[0].dir_idx = 0;
8757 for (i = 1; i < numfiles; i++)
8758 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8759 && memcmp (dirs[ndirs - 1].path, files[i].path,
8760 dirs[ndirs - 1].length) == 0)
8762 /* Same directory as last entry. */
8763 files[i].dir_idx = ndirs - 1;
8764 ++dirs[ndirs - 1].count;
8770 /* This is a new directory. */
8771 dirs[ndirs].path = files[i].path;
8772 dirs[ndirs].length = files[i].fname - files[i].path;
8773 dirs[ndirs].count = 1;
8774 dirs[ndirs].dir_idx = ndirs;
8775 files[i].dir_idx = ndirs;
8777 /* Search for a prefix. */
8778 dirs[ndirs].prefix = -1;
8779 for (j = 0; j < ndirs; j++)
8780 if (dirs[j].length < dirs[ndirs].length
8781 && dirs[j].length > 1
8782 && (dirs[ndirs].prefix == -1
8783 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8784 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8785 dirs[ndirs].prefix = j;
8790 /* Now to the actual work. We have to find a subset of the directories which
8791 allow expressing the file name using references to the directory table
8792 with the least amount of characters. We do not do an exhaustive search
8793 where we would have to check out every combination of every single
8794 possible prefix. Instead we use a heuristic which provides nearly optimal
8795 results in most cases and never is much off. */
8796 saved = XALLOCAVEC (int, ndirs);
8797 savehere = XALLOCAVEC (int, ndirs);
8799 memset (saved, '\0', ndirs * sizeof (saved[0]));
8800 for (i = 0; i < ndirs; i++)
8805 /* We can always save some space for the current directory. But this
8806 does not mean it will be enough to justify adding the directory. */
8807 savehere[i] = dirs[i].length;
8808 total = (savehere[i] - saved[i]) * dirs[i].count;
8810 for (j = i + 1; j < ndirs; j++)
8813 if (saved[j] < dirs[i].length)
8815 /* Determine whether the dirs[i] path is a prefix of the
8820 while (k != -1 && k != (int) i)
8825 /* Yes it is. We can possibly save some memory by
8826 writing the filenames in dirs[j] relative to
8828 savehere[j] = dirs[i].length;
8829 total += (savehere[j] - saved[j]) * dirs[j].count;
8834 /* Check whether we can save enough to justify adding the dirs[i]
8836 if (total > dirs[i].length + 1)
8838 /* It's worthwhile adding. */
8839 for (j = i; j < ndirs; j++)
8840 if (savehere[j] > 0)
8842 /* Remember how much we saved for this directory so far. */
8843 saved[j] = savehere[j];
8845 /* Remember the prefix directory. */
8846 dirs[j].dir_idx = i;
8851 /* Emit the directory name table. */
8853 idx_offset = dirs[0].length > 0 ? 1 : 0;
8854 for (i = 1 - idx_offset; i < ndirs; i++)
8855 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8856 "Directory Entry: 0x%x", i + idx_offset);
8858 dw2_asm_output_data (1, 0, "End directory table");
8860 /* We have to emit them in the order of emitted_number since that's
8861 used in the debug info generation. To do this efficiently we
8862 generate a back-mapping of the indices first. */
8863 backmap = XALLOCAVEC (int, numfiles);
8864 for (i = 0; i < numfiles; i++)
8865 backmap[files[i].file_idx->emitted_number - 1] = i;
8867 /* Now write all the file names. */
8868 for (i = 0; i < numfiles; i++)
8870 int file_idx = backmap[i];
8871 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8873 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8874 "File Entry: 0x%x", (unsigned) i + 1);
8876 /* Include directory index. */
8877 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8879 /* Modification time. */
8880 dw2_asm_output_data_uleb128 (0, NULL);
8882 /* File length in bytes. */
8883 dw2_asm_output_data_uleb128 (0, NULL);
8886 dw2_asm_output_data (1, 0, "End file name table");
8890 /* Output the source line number correspondence information. This
8891 information goes into the .debug_line section. */
8894 output_line_info (void)
8896 char l1[20], l2[20], p1[20], p2[20];
8897 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8898 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8901 unsigned long lt_index;
8902 unsigned long current_line;
8905 unsigned long current_file;
8906 unsigned long function;
8908 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8909 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8910 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8911 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8913 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8914 dw2_asm_output_data (4, 0xffffffff,
8915 "Initial length escape value indicating 64-bit DWARF extension");
8916 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8917 "Length of Source Line Info");
8918 ASM_OUTPUT_LABEL (asm_out_file, l1);
8920 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8921 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8922 ASM_OUTPUT_LABEL (asm_out_file, p1);
8924 /* Define the architecture-dependent minimum instruction length (in
8925 bytes). In this implementation of DWARF, this field is used for
8926 information purposes only. Since GCC generates assembly language,
8927 we have no a priori knowledge of how many instruction bytes are
8928 generated for each source line, and therefore can use only the
8929 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8930 commands. Accordingly, we fix this as `1', which is "correct
8931 enough" for all architectures, and don't let the target override. */
8932 dw2_asm_output_data (1, 1,
8933 "Minimum Instruction Length");
8935 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8936 "Default is_stmt_start flag");
8937 dw2_asm_output_data (1, DWARF_LINE_BASE,
8938 "Line Base Value (Special Opcodes)");
8939 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8940 "Line Range Value (Special Opcodes)");
8941 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8942 "Special Opcode Base");
8944 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8948 case DW_LNS_advance_pc:
8949 case DW_LNS_advance_line:
8950 case DW_LNS_set_file:
8951 case DW_LNS_set_column:
8952 case DW_LNS_fixed_advance_pc:
8960 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8964 /* Write out the information about the files we use. */
8965 output_file_names ();
8966 ASM_OUTPUT_LABEL (asm_out_file, p2);
8968 /* We used to set the address register to the first location in the text
8969 section here, but that didn't accomplish anything since we already
8970 have a line note for the opening brace of the first function. */
8972 /* Generate the line number to PC correspondence table, encoded as
8973 a series of state machine operations. */
8977 if (cfun && in_cold_section_p)
8978 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8980 strcpy (prev_line_label, text_section_label);
8981 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8983 dw_line_info_ref line_info = &line_info_table[lt_index];
8986 /* Disable this optimization for now; GDB wants to see two line notes
8987 at the beginning of a function so it can find the end of the
8990 /* Don't emit anything for redundant notes. Just updating the
8991 address doesn't accomplish anything, because we already assume
8992 that anything after the last address is this line. */
8993 if (line_info->dw_line_num == current_line
8994 && line_info->dw_file_num == current_file)
8998 /* Emit debug info for the address of the current line.
9000 Unfortunately, we have little choice here currently, and must always
9001 use the most general form. GCC does not know the address delta
9002 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9003 attributes which will give an upper bound on the address range. We
9004 could perhaps use length attributes to determine when it is safe to
9005 use DW_LNS_fixed_advance_pc. */
9007 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9010 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9011 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9012 "DW_LNS_fixed_advance_pc");
9013 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9017 /* This can handle any delta. This takes
9018 4+DWARF2_ADDR_SIZE bytes. */
9019 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9020 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9021 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9022 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9025 strcpy (prev_line_label, line_label);
9027 /* Emit debug info for the source file of the current line, if
9028 different from the previous line. */
9029 if (line_info->dw_file_num != current_file)
9031 current_file = line_info->dw_file_num;
9032 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9033 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9036 /* Emit debug info for the current line number, choosing the encoding
9037 that uses the least amount of space. */
9038 if (line_info->dw_line_num != current_line)
9040 line_offset = line_info->dw_line_num - current_line;
9041 line_delta = line_offset - DWARF_LINE_BASE;
9042 current_line = line_info->dw_line_num;
9043 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9044 /* This can handle deltas from -10 to 234, using the current
9045 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9047 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9048 "line %lu", current_line);
9051 /* This can handle any delta. This takes at least 4 bytes,
9052 depending on the value being encoded. */
9053 dw2_asm_output_data (1, DW_LNS_advance_line,
9054 "advance to line %lu", current_line);
9055 dw2_asm_output_data_sleb128 (line_offset, NULL);
9056 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9060 /* We still need to start a new row, so output a copy insn. */
9061 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9064 /* Emit debug info for the address of the end of the function. */
9067 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9068 "DW_LNS_fixed_advance_pc");
9069 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9073 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9074 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9075 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9076 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9079 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9080 dw2_asm_output_data_uleb128 (1, NULL);
9081 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9086 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9088 dw_separate_line_info_ref line_info
9089 = &separate_line_info_table[lt_index];
9092 /* Don't emit anything for redundant notes. */
9093 if (line_info->dw_line_num == current_line
9094 && line_info->dw_file_num == current_file
9095 && line_info->function == function)
9099 /* Emit debug info for the address of the current line. If this is
9100 a new function, or the first line of a function, then we need
9101 to handle it differently. */
9102 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9104 if (function != line_info->function)
9106 function = line_info->function;
9108 /* Set the address register to the first line in the function. */
9109 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9110 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9111 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9112 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9116 /* ??? See the DW_LNS_advance_pc comment above. */
9119 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9120 "DW_LNS_fixed_advance_pc");
9121 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9125 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9126 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9127 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9128 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9132 strcpy (prev_line_label, line_label);
9134 /* Emit debug info for the source file of the current line, if
9135 different from the previous line. */
9136 if (line_info->dw_file_num != current_file)
9138 current_file = line_info->dw_file_num;
9139 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9140 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9143 /* Emit debug info for the current line number, choosing the encoding
9144 that uses the least amount of space. */
9145 if (line_info->dw_line_num != current_line)
9147 line_offset = line_info->dw_line_num - current_line;
9148 line_delta = line_offset - DWARF_LINE_BASE;
9149 current_line = line_info->dw_line_num;
9150 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9151 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9152 "line %lu", current_line);
9155 dw2_asm_output_data (1, DW_LNS_advance_line,
9156 "advance to line %lu", current_line);
9157 dw2_asm_output_data_sleb128 (line_offset, NULL);
9158 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9162 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9170 /* If we're done with a function, end its sequence. */
9171 if (lt_index == separate_line_info_table_in_use
9172 || separate_line_info_table[lt_index].function != function)
9177 /* Emit debug info for the address of the end of the function. */
9178 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9181 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9182 "DW_LNS_fixed_advance_pc");
9183 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9187 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9188 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9189 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9190 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9193 /* Output the marker for the end of this sequence. */
9194 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9195 dw2_asm_output_data_uleb128 (1, NULL);
9196 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9200 /* Output the marker for the end of the line number info. */
9201 ASM_OUTPUT_LABEL (asm_out_file, l2);
9204 /* Given a pointer to a tree node for some base type, return a pointer to
9205 a DIE that describes the given type.
9207 This routine must only be called for GCC type nodes that correspond to
9208 Dwarf base (fundamental) types. */
9211 base_type_die (tree type)
9213 dw_die_ref base_type_result;
9214 enum dwarf_type encoding;
9216 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9219 switch (TREE_CODE (type))
9222 if (TYPE_STRING_FLAG (type))
9224 if (TYPE_UNSIGNED (type))
9225 encoding = DW_ATE_unsigned_char;
9227 encoding = DW_ATE_signed_char;
9229 else if (TYPE_UNSIGNED (type))
9230 encoding = DW_ATE_unsigned;
9232 encoding = DW_ATE_signed;
9236 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9237 encoding = DW_ATE_decimal_float;
9239 encoding = DW_ATE_float;
9242 case FIXED_POINT_TYPE:
9243 if (TYPE_UNSIGNED (type))
9244 encoding = DW_ATE_unsigned_fixed;
9246 encoding = DW_ATE_signed_fixed;
9249 /* Dwarf2 doesn't know anything about complex ints, so use
9250 a user defined type for it. */
9252 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9253 encoding = DW_ATE_complex_float;
9255 encoding = DW_ATE_lo_user;
9259 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9260 encoding = DW_ATE_boolean;
9264 /* No other TREE_CODEs are Dwarf fundamental types. */
9268 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9270 /* This probably indicates a bug. */
9271 if (! TYPE_NAME (type))
9272 add_name_attribute (base_type_result, "__unknown__");
9274 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9275 int_size_in_bytes (type));
9276 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9278 return base_type_result;
9281 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9282 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9285 is_base_type (tree type)
9287 switch (TREE_CODE (type))
9293 case FIXED_POINT_TYPE:
9301 case QUAL_UNION_TYPE:
9306 case REFERENCE_TYPE:
9319 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9320 node, return the size in bits for the type if it is a constant, or else
9321 return the alignment for the type if the type's size is not constant, or
9322 else return BITS_PER_WORD if the type actually turns out to be an
9325 static inline unsigned HOST_WIDE_INT
9326 simple_type_size_in_bits (const_tree type)
9328 if (TREE_CODE (type) == ERROR_MARK)
9329 return BITS_PER_WORD;
9330 else if (TYPE_SIZE (type) == NULL_TREE)
9332 else if (host_integerp (TYPE_SIZE (type), 1))
9333 return tree_low_cst (TYPE_SIZE (type), 1);
9335 return TYPE_ALIGN (type);
9338 /* Return true if the debug information for the given type should be
9339 emitted as a subrange type. */
9342 is_subrange_type (const_tree type)
9344 tree subtype = TREE_TYPE (type);
9346 /* Subrange types are identified by the fact that they are integer
9347 types, and that they have a subtype which is either an integer type
9348 or an enumeral type. */
9350 if (TREE_CODE (type) != INTEGER_TYPE
9351 || subtype == NULL_TREE)
9354 if (TREE_CODE (subtype) != INTEGER_TYPE
9355 && TREE_CODE (subtype) != ENUMERAL_TYPE
9356 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9359 if (TREE_CODE (type) == TREE_CODE (subtype)
9360 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9361 && TYPE_MIN_VALUE (type) != NULL
9362 && TYPE_MIN_VALUE (subtype) != NULL
9363 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9364 && TYPE_MAX_VALUE (type) != NULL
9365 && TYPE_MAX_VALUE (subtype) != NULL
9366 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9368 /* The type and its subtype have the same representation. If in
9369 addition the two types also have the same name, then the given
9370 type is not a subrange type, but rather a plain base type. */
9371 /* FIXME: brobecker/2004-03-22:
9372 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9373 therefore be sufficient to check the TYPE_SIZE node pointers
9374 rather than checking the actual size. Unfortunately, we have
9375 found some cases, such as in the Ada "integer" type, where
9376 this is not the case. Until this problem is solved, we need to
9377 keep checking the actual size. */
9378 tree type_name = TYPE_NAME (type);
9379 tree subtype_name = TYPE_NAME (subtype);
9381 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9382 type_name = DECL_NAME (type_name);
9384 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9385 subtype_name = DECL_NAME (subtype_name);
9387 if (type_name == subtype_name)
9394 /* Given a pointer to a tree node for a subrange type, return a pointer
9395 to a DIE that describes the given type. */
9398 subrange_type_die (tree type, dw_die_ref context_die)
9400 dw_die_ref subrange_die;
9401 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9403 if (context_die == NULL)
9404 context_die = comp_unit_die;
9406 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9408 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9410 /* The size of the subrange type and its base type do not match,
9411 so we need to generate a size attribute for the subrange type. */
9412 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9415 if (TYPE_MIN_VALUE (type) != NULL)
9416 add_bound_info (subrange_die, DW_AT_lower_bound,
9417 TYPE_MIN_VALUE (type));
9418 if (TYPE_MAX_VALUE (type) != NULL)
9419 add_bound_info (subrange_die, DW_AT_upper_bound,
9420 TYPE_MAX_VALUE (type));
9422 return subrange_die;
9425 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9426 entry that chains various modifiers in front of the given type. */
9429 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9430 dw_die_ref context_die)
9432 enum tree_code code = TREE_CODE (type);
9433 dw_die_ref mod_type_die;
9434 dw_die_ref sub_die = NULL;
9435 tree item_type = NULL;
9436 tree qualified_type;
9439 if (code == ERROR_MARK)
9442 /* See if we already have the appropriately qualified variant of
9445 = get_qualified_type (type,
9446 ((is_const_type ? TYPE_QUAL_CONST : 0)
9447 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9449 /* If we do, then we can just use its DIE, if it exists. */
9452 mod_type_die = lookup_type_die (qualified_type);
9454 return mod_type_die;
9457 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9459 /* Handle C typedef types. */
9460 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9462 tree dtype = TREE_TYPE (name);
9464 if (qualified_type == dtype)
9466 /* For a named type, use the typedef. */
9467 gen_type_die (qualified_type, context_die);
9468 return lookup_type_die (qualified_type);
9470 else if (is_const_type < TYPE_READONLY (dtype)
9471 || is_volatile_type < TYPE_VOLATILE (dtype)
9472 || (is_const_type <= TYPE_READONLY (dtype)
9473 && is_volatile_type <= TYPE_VOLATILE (dtype)
9474 && DECL_ORIGINAL_TYPE (name) != type))
9475 /* cv-unqualified version of named type. Just use the unnamed
9476 type to which it refers. */
9477 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9478 is_const_type, is_volatile_type,
9480 /* Else cv-qualified version of named type; fall through. */
9485 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9486 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9488 else if (is_volatile_type)
9490 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9491 sub_die = modified_type_die (type, 0, 0, context_die);
9493 else if (code == POINTER_TYPE)
9495 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9496 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9497 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9498 item_type = TREE_TYPE (type);
9500 else if (code == REFERENCE_TYPE)
9502 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9503 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9504 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9505 item_type = TREE_TYPE (type);
9507 else if (is_subrange_type (type))
9509 mod_type_die = subrange_type_die (type, context_die);
9510 item_type = TREE_TYPE (type);
9512 else if (is_base_type (type))
9513 mod_type_die = base_type_die (type);
9516 gen_type_die (type, context_die);
9518 /* We have to get the type_main_variant here (and pass that to the
9519 `lookup_type_die' routine) because the ..._TYPE node we have
9520 might simply be a *copy* of some original type node (where the
9521 copy was created to help us keep track of typedef names) and
9522 that copy might have a different TYPE_UID from the original
9524 if (TREE_CODE (type) != VECTOR_TYPE)
9525 return lookup_type_die (type_main_variant (type));
9527 /* Vectors have the debugging information in the type,
9528 not the main variant. */
9529 return lookup_type_die (type);
9532 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9533 don't output a DW_TAG_typedef, since there isn't one in the
9534 user's program; just attach a DW_AT_name to the type. */
9536 && (TREE_CODE (name) != TYPE_DECL
9537 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9539 if (TREE_CODE (name) == TYPE_DECL)
9540 /* Could just call add_name_and_src_coords_attributes here,
9541 but since this is a builtin type it doesn't have any
9542 useful source coordinates anyway. */
9543 name = DECL_NAME (name);
9544 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9548 equate_type_number_to_die (qualified_type, mod_type_die);
9551 /* We must do this after the equate_type_number_to_die call, in case
9552 this is a recursive type. This ensures that the modified_type_die
9553 recursion will terminate even if the type is recursive. Recursive
9554 types are possible in Ada. */
9555 sub_die = modified_type_die (item_type,
9556 TYPE_READONLY (item_type),
9557 TYPE_VOLATILE (item_type),
9560 if (sub_die != NULL)
9561 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9563 return mod_type_die;
9566 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9567 an enumerated type. */
9570 type_is_enum (const_tree type)
9572 return TREE_CODE (type) == ENUMERAL_TYPE;
9575 /* Return the DBX register number described by a given RTL node. */
9578 dbx_reg_number (const_rtx rtl)
9580 unsigned regno = REGNO (rtl);
9582 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9584 #ifdef LEAF_REG_REMAP
9585 if (current_function_uses_only_leaf_regs)
9587 int leaf_reg = LEAF_REG_REMAP (regno);
9589 regno = (unsigned) leaf_reg;
9593 return DBX_REGISTER_NUMBER (regno);
9596 /* Optionally add a DW_OP_piece term to a location description expression.
9597 DW_OP_piece is only added if the location description expression already
9598 doesn't end with DW_OP_piece. */
9601 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9603 dw_loc_descr_ref loc;
9605 if (*list_head != NULL)
9607 /* Find the end of the chain. */
9608 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9611 if (loc->dw_loc_opc != DW_OP_piece)
9612 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9616 /* Return a location descriptor that designates a machine register or
9617 zero if there is none. */
9619 static dw_loc_descr_ref
9620 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9624 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9627 regs = targetm.dwarf_register_span (rtl);
9629 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9630 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9632 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9635 /* Return a location descriptor that designates a machine register for
9636 a given hard register number. */
9638 static dw_loc_descr_ref
9639 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9641 dw_loc_descr_ref reg_loc_descr = new_reg_loc_descr (regno, 0);
9643 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9644 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9646 return reg_loc_descr;
9649 /* Given an RTL of a register, return a location descriptor that
9650 designates a value that spans more than one register. */
9652 static dw_loc_descr_ref
9653 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9654 enum var_init_status initialized)
9658 dw_loc_descr_ref loc_result = NULL;
9661 #ifdef LEAF_REG_REMAP
9662 if (current_function_uses_only_leaf_regs)
9664 int leaf_reg = LEAF_REG_REMAP (reg);
9666 reg = (unsigned) leaf_reg;
9669 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9670 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9672 /* Simple, contiguous registers. */
9673 if (regs == NULL_RTX)
9675 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9682 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9683 VAR_INIT_STATUS_INITIALIZED);
9684 add_loc_descr (&loc_result, t);
9685 add_loc_descr_op_piece (&loc_result, size);
9691 /* Now onto stupid register sets in non contiguous locations. */
9693 gcc_assert (GET_CODE (regs) == PARALLEL);
9695 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9698 for (i = 0; i < XVECLEN (regs, 0); ++i)
9702 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9703 VAR_INIT_STATUS_INITIALIZED);
9704 add_loc_descr (&loc_result, t);
9705 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9706 add_loc_descr_op_piece (&loc_result, size);
9709 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9710 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9714 #endif /* DWARF2_DEBUGGING_INFO */
9716 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9718 /* Return a location descriptor that designates a constant. */
9720 static dw_loc_descr_ref
9721 int_loc_descriptor (HOST_WIDE_INT i)
9723 enum dwarf_location_atom op;
9725 /* Pick the smallest representation of a constant, rather than just
9726 defaulting to the LEB encoding. */
9730 op = DW_OP_lit0 + i;
9733 else if (i <= 0xffff)
9735 else if (HOST_BITS_PER_WIDE_INT == 32
9745 else if (i >= -0x8000)
9747 else if (HOST_BITS_PER_WIDE_INT == 32
9748 || i >= -0x80000000)
9754 return new_loc_descr (op, i, 0);
9758 #ifdef DWARF2_DEBUGGING_INFO
9760 /* Return a location descriptor that designates a base+offset location. */
9762 static dw_loc_descr_ref
9763 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9764 enum var_init_status initialized)
9767 dw_loc_descr_ref result;
9768 dw_fde_ref fde = current_fde ();
9770 /* We only use "frame base" when we're sure we're talking about the
9771 post-prologue local stack frame. We do this by *not* running
9772 register elimination until this point, and recognizing the special
9773 argument pointer and soft frame pointer rtx's. */
9774 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9776 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9780 if (GET_CODE (elim) == PLUS)
9782 offset += INTVAL (XEXP (elim, 1));
9783 elim = XEXP (elim, 0);
9785 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9786 && (elim == hard_frame_pointer_rtx
9787 || elim == stack_pointer_rtx))
9788 || elim == (frame_pointer_needed
9789 ? hard_frame_pointer_rtx
9790 : stack_pointer_rtx));
9792 /* If drap register is used to align stack, use frame
9793 pointer + offset to access stack variables. If stack
9794 is aligned without drap, use stack pointer + offset to
9795 access stack variables. */
9796 if (crtl->stack_realign_tried
9797 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9798 && reg == frame_pointer_rtx)
9801 = DWARF_FRAME_REGNUM (cfa.indirect
9802 ? HARD_FRAME_POINTER_REGNUM
9803 : STACK_POINTER_REGNUM);
9804 return new_reg_loc_descr (base_reg, offset);
9807 offset += frame_pointer_fb_offset;
9808 return new_loc_descr (DW_OP_fbreg, offset, 0);
9812 && fde->drap_reg != INVALID_REGNUM
9813 && (fde->drap_reg == REGNO (reg)
9814 || fde->vdrap_reg == REGNO (reg)))
9816 /* Use cfa+offset to represent the location of arguments passed
9817 on stack when drap is used to align stack. */
9818 return new_loc_descr (DW_OP_fbreg, offset, 0);
9821 regno = dbx_reg_number (reg);
9823 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9825 result = new_loc_descr (DW_OP_bregx, regno, offset);
9827 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9828 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9833 /* Return true if this RTL expression describes a base+offset calculation. */
9836 is_based_loc (const_rtx rtl)
9838 return (GET_CODE (rtl) == PLUS
9839 && ((REG_P (XEXP (rtl, 0))
9840 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9841 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9844 /* Return a descriptor that describes the concatenation of N locations
9845 used to form the address of a memory location. */
9847 static dw_loc_descr_ref
9848 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9849 enum var_init_status initialized)
9852 dw_loc_descr_ref cc_loc_result = NULL;
9853 unsigned int n = XVECLEN (concatn, 0);
9855 for (i = 0; i < n; ++i)
9857 dw_loc_descr_ref ref;
9858 rtx x = XVECEXP (concatn, 0, i);
9860 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9864 add_loc_descr (&cc_loc_result, ref);
9865 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9868 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9869 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9871 return cc_loc_result;
9874 /* The following routine converts the RTL for a variable or parameter
9875 (resident in memory) into an equivalent Dwarf representation of a
9876 mechanism for getting the address of that same variable onto the top of a
9877 hypothetical "address evaluation" stack.
9879 When creating memory location descriptors, we are effectively transforming
9880 the RTL for a memory-resident object into its Dwarf postfix expression
9881 equivalent. This routine recursively descends an RTL tree, turning
9882 it into Dwarf postfix code as it goes.
9884 MODE is the mode of the memory reference, needed to handle some
9885 autoincrement addressing modes.
9887 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9888 location list for RTL.
9890 Return 0 if we can't represent the location. */
9892 static dw_loc_descr_ref
9893 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9894 enum var_init_status initialized)
9896 dw_loc_descr_ref mem_loc_result = NULL;
9897 enum dwarf_location_atom op;
9899 /* Note that for a dynamically sized array, the location we will generate a
9900 description of here will be the lowest numbered location which is
9901 actually within the array. That's *not* necessarily the same as the
9902 zeroth element of the array. */
9904 rtl = targetm.delegitimize_address (rtl);
9906 switch (GET_CODE (rtl))
9911 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9912 just fall into the SUBREG code. */
9914 /* ... fall through ... */
9917 /* The case of a subreg may arise when we have a local (register)
9918 variable or a formal (register) parameter which doesn't quite fill
9919 up an entire register. For now, just assume that it is
9920 legitimate to make the Dwarf info refer to the whole register which
9921 contains the given subreg. */
9922 rtl = XEXP (rtl, 0);
9924 /* ... fall through ... */
9927 /* Whenever a register number forms a part of the description of the
9928 method for calculating the (dynamic) address of a memory resident
9929 object, DWARF rules require the register number be referred to as
9930 a "base register". This distinction is not based in any way upon
9931 what category of register the hardware believes the given register
9932 belongs to. This is strictly DWARF terminology we're dealing with
9933 here. Note that in cases where the location of a memory-resident
9934 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9935 OP_CONST (0)) the actual DWARF location descriptor that we generate
9936 may just be OP_BASEREG (basereg). This may look deceptively like
9937 the object in question was allocated to a register (rather than in
9938 memory) so DWARF consumers need to be aware of the subtle
9939 distinction between OP_REG and OP_BASEREG. */
9940 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9941 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9945 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9946 VAR_INIT_STATUS_INITIALIZED);
9947 if (mem_loc_result != 0)
9948 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9952 rtl = XEXP (rtl, 1);
9954 /* ... fall through ... */
9957 /* Some ports can transform a symbol ref into a label ref, because
9958 the symbol ref is too far away and has to be dumped into a constant
9962 /* Alternatively, the symbol in the constant pool might be referenced
9963 by a different symbol. */
9964 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9967 rtx tmp = get_pool_constant_mark (rtl, &marked);
9969 if (GET_CODE (tmp) == SYMBOL_REF)
9972 if (CONSTANT_POOL_ADDRESS_P (tmp))
9973 get_pool_constant_mark (tmp, &marked);
9978 /* If all references to this pool constant were optimized away,
9979 it was not output and thus we can't represent it.
9980 FIXME: might try to use DW_OP_const_value here, though
9981 DW_OP_piece complicates it. */
9986 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9987 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9988 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9989 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9993 /* Extract the PLUS expression nested inside and fall into
9995 rtl = XEXP (rtl, 1);
10000 /* Turn these into a PLUS expression and fall into the PLUS code
10002 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10003 GEN_INT (GET_CODE (rtl) == PRE_INC
10004 ? GET_MODE_UNIT_SIZE (mode)
10005 : -GET_MODE_UNIT_SIZE (mode)));
10007 /* ... fall through ... */
10011 if (is_based_loc (rtl))
10012 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10013 INTVAL (XEXP (rtl, 1)),
10014 VAR_INIT_STATUS_INITIALIZED);
10017 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10018 VAR_INIT_STATUS_INITIALIZED);
10019 if (mem_loc_result == 0)
10022 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
10023 && INTVAL (XEXP (rtl, 1)) >= 0)
10024 add_loc_descr (&mem_loc_result,
10025 new_loc_descr (DW_OP_plus_uconst,
10026 INTVAL (XEXP (rtl, 1)), 0));
10029 add_loc_descr (&mem_loc_result,
10030 mem_loc_descriptor (XEXP (rtl, 1), mode,
10031 VAR_INIT_STATUS_INITIALIZED));
10032 add_loc_descr (&mem_loc_result,
10033 new_loc_descr (DW_OP_plus, 0, 0));
10038 /* If a pseudo-reg is optimized away, it is possible for it to
10039 be replaced with a MEM containing a multiply or shift. */
10058 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10059 VAR_INIT_STATUS_INITIALIZED);
10060 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10061 VAR_INIT_STATUS_INITIALIZED);
10063 if (op0 == 0 || op1 == 0)
10066 mem_loc_result = op0;
10067 add_loc_descr (&mem_loc_result, op1);
10068 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10073 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10077 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10078 VAR_INIT_STATUS_INITIALIZED);
10082 gcc_unreachable ();
10085 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10086 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10088 return mem_loc_result;
10091 /* Return a descriptor that describes the concatenation of two locations.
10092 This is typically a complex variable. */
10094 static dw_loc_descr_ref
10095 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10097 dw_loc_descr_ref cc_loc_result = NULL;
10098 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10099 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10101 if (x0_ref == 0 || x1_ref == 0)
10104 cc_loc_result = x0_ref;
10105 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10107 add_loc_descr (&cc_loc_result, x1_ref);
10108 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10110 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10111 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10113 return cc_loc_result;
10116 /* Return a descriptor that describes the concatenation of N
10119 static dw_loc_descr_ref
10120 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10123 dw_loc_descr_ref cc_loc_result = NULL;
10124 unsigned int n = XVECLEN (concatn, 0);
10126 for (i = 0; i < n; ++i)
10128 dw_loc_descr_ref ref;
10129 rtx x = XVECEXP (concatn, 0, i);
10131 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10135 add_loc_descr (&cc_loc_result, ref);
10136 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10139 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10140 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10142 return cc_loc_result;
10145 /* Output a proper Dwarf location descriptor for a variable or parameter
10146 which is either allocated in a register or in a memory location. For a
10147 register, we just generate an OP_REG and the register number. For a
10148 memory location we provide a Dwarf postfix expression describing how to
10149 generate the (dynamic) address of the object onto the address stack.
10151 If we don't know how to describe it, return 0. */
10153 static dw_loc_descr_ref
10154 loc_descriptor (rtx rtl, enum var_init_status initialized)
10156 dw_loc_descr_ref loc_result = NULL;
10158 switch (GET_CODE (rtl))
10161 /* The case of a subreg may arise when we have a local (register)
10162 variable or a formal (register) parameter which doesn't quite fill
10163 up an entire register. For now, just assume that it is
10164 legitimate to make the Dwarf info refer to the whole register which
10165 contains the given subreg. */
10166 rtl = SUBREG_REG (rtl);
10168 /* ... fall through ... */
10171 loc_result = reg_loc_descriptor (rtl, initialized);
10175 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10180 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10185 loc_result = concatn_loc_descriptor (rtl, initialized);
10190 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10192 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10196 rtl = XEXP (rtl, 1);
10201 rtvec par_elems = XVEC (rtl, 0);
10202 int num_elem = GET_NUM_ELEM (par_elems);
10203 enum machine_mode mode;
10206 /* Create the first one, so we have something to add to. */
10207 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10209 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10210 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10211 for (i = 1; i < num_elem; i++)
10213 dw_loc_descr_ref temp;
10215 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10217 add_loc_descr (&loc_result, temp);
10218 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10219 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10225 gcc_unreachable ();
10231 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10232 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10233 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10234 top-level invocation, and we require the address of LOC; is 0 if we require
10235 the value of LOC. */
10237 static dw_loc_descr_ref
10238 loc_descriptor_from_tree_1 (tree loc, int want_address)
10240 dw_loc_descr_ref ret, ret1;
10241 int have_address = 0;
10242 enum dwarf_location_atom op;
10244 /* ??? Most of the time we do not take proper care for sign/zero
10245 extending the values properly. Hopefully this won't be a real
10248 switch (TREE_CODE (loc))
10253 case PLACEHOLDER_EXPR:
10254 /* This case involves extracting fields from an object to determine the
10255 position of other fields. We don't try to encode this here. The
10256 only user of this is Ada, which encodes the needed information using
10257 the names of types. */
10263 case PREINCREMENT_EXPR:
10264 case PREDECREMENT_EXPR:
10265 case POSTINCREMENT_EXPR:
10266 case POSTDECREMENT_EXPR:
10267 /* There are no opcodes for these operations. */
10271 /* If we already want an address, there's nothing we can do. */
10275 /* Otherwise, process the argument and look for the address. */
10276 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10279 if (DECL_THREAD_LOCAL_P (loc))
10283 unsigned second_op;
10285 if (targetm.have_tls)
10287 /* If this is not defined, we have no way to emit the
10289 if (!targetm.asm_out.output_dwarf_dtprel)
10292 /* The way DW_OP_GNU_push_tls_address is specified, we
10293 can only look up addresses of objects in the current
10295 if (DECL_EXTERNAL (loc))
10297 first_op = INTERNAL_DW_OP_tls_addr;
10298 second_op = DW_OP_GNU_push_tls_address;
10302 if (!targetm.emutls.debug_form_tls_address)
10304 loc = emutls_decl (loc);
10305 first_op = DW_OP_addr;
10306 second_op = DW_OP_form_tls_address;
10309 rtl = rtl_for_decl_location (loc);
10310 if (rtl == NULL_RTX)
10315 rtl = XEXP (rtl, 0);
10316 if (! CONSTANT_P (rtl))
10319 ret = new_loc_descr (first_op, 0, 0);
10320 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10321 ret->dw_loc_oprnd1.v.val_addr = rtl;
10323 ret1 = new_loc_descr (second_op, 0, 0);
10324 add_loc_descr (&ret, ret1);
10332 if (DECL_HAS_VALUE_EXPR_P (loc))
10333 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10338 case FUNCTION_DECL:
10340 rtx rtl = rtl_for_decl_location (loc);
10342 if (rtl == NULL_RTX)
10344 else if (GET_CODE (rtl) == CONST_INT)
10346 HOST_WIDE_INT val = INTVAL (rtl);
10347 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10348 val &= GET_MODE_MASK (DECL_MODE (loc));
10349 ret = int_loc_descriptor (val);
10351 else if (GET_CODE (rtl) == CONST_STRING)
10353 else if (CONSTANT_P (rtl))
10355 ret = new_loc_descr (DW_OP_addr, 0, 0);
10356 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10357 ret->dw_loc_oprnd1.v.val_addr = rtl;
10361 enum machine_mode mode;
10363 /* Certain constructs can only be represented at top-level. */
10364 if (want_address == 2)
10365 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10367 mode = GET_MODE (rtl);
10370 rtl = XEXP (rtl, 0);
10373 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10379 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10383 case COMPOUND_EXPR:
10384 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10387 case VIEW_CONVERT_EXPR:
10390 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10392 case COMPONENT_REF:
10393 case BIT_FIELD_REF:
10395 case ARRAY_RANGE_REF:
10398 HOST_WIDE_INT bitsize, bitpos, bytepos;
10399 enum machine_mode mode;
10401 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10403 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10404 &unsignedp, &volatilep, false);
10409 ret = loc_descriptor_from_tree_1 (obj, 1);
10411 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10414 if (offset != NULL_TREE)
10416 /* Variable offset. */
10417 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
10418 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10421 bytepos = bitpos / BITS_PER_UNIT;
10423 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10424 else if (bytepos < 0)
10426 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10427 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10435 if (host_integerp (loc, 0))
10436 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10443 /* Get an RTL for this, if something has been emitted. */
10444 rtx rtl = lookup_constant_def (loc);
10445 enum machine_mode mode;
10447 if (!rtl || !MEM_P (rtl))
10449 mode = GET_MODE (rtl);
10450 rtl = XEXP (rtl, 0);
10451 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10456 case TRUTH_AND_EXPR:
10457 case TRUTH_ANDIF_EXPR:
10462 case TRUTH_XOR_EXPR:
10467 case TRUTH_OR_EXPR:
10468 case TRUTH_ORIF_EXPR:
10473 case FLOOR_DIV_EXPR:
10474 case CEIL_DIV_EXPR:
10475 case ROUND_DIV_EXPR:
10476 case TRUNC_DIV_EXPR:
10484 case FLOOR_MOD_EXPR:
10485 case CEIL_MOD_EXPR:
10486 case ROUND_MOD_EXPR:
10487 case TRUNC_MOD_EXPR:
10500 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10503 case POINTER_PLUS_EXPR:
10505 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10506 && host_integerp (TREE_OPERAND (loc, 1), 0))
10508 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10512 add_loc_descr (&ret,
10513 new_loc_descr (DW_OP_plus_uconst,
10514 tree_low_cst (TREE_OPERAND (loc, 1),
10524 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10531 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10538 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10545 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10560 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10561 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10562 if (ret == 0 || ret1 == 0)
10565 add_loc_descr (&ret, ret1);
10566 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10569 case TRUTH_NOT_EXPR:
10583 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10587 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10593 const enum tree_code code =
10594 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10596 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10597 build2 (code, integer_type_node,
10598 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10599 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10602 /* ... fall through ... */
10606 dw_loc_descr_ref lhs
10607 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10608 dw_loc_descr_ref rhs
10609 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10610 dw_loc_descr_ref bra_node, jump_node, tmp;
10612 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10613 if (ret == 0 || lhs == 0 || rhs == 0)
10616 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10617 add_loc_descr (&ret, bra_node);
10619 add_loc_descr (&ret, rhs);
10620 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10621 add_loc_descr (&ret, jump_node);
10623 add_loc_descr (&ret, lhs);
10624 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10625 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10627 /* ??? Need a node to point the skip at. Use a nop. */
10628 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10629 add_loc_descr (&ret, tmp);
10630 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10631 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10635 case FIX_TRUNC_EXPR:
10639 /* Leave front-end specific codes as simply unknown. This comes
10640 up, for instance, with the C STMT_EXPR. */
10641 if ((unsigned int) TREE_CODE (loc)
10642 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10645 #ifdef ENABLE_CHECKING
10646 /* Otherwise this is a generic code; we should just lists all of
10647 these explicitly. We forgot one. */
10648 gcc_unreachable ();
10650 /* In a release build, we want to degrade gracefully: better to
10651 generate incomplete debugging information than to crash. */
10656 /* Show if we can't fill the request for an address. */
10657 if (want_address && !have_address)
10660 /* If we've got an address and don't want one, dereference. */
10661 if (!want_address && have_address && ret)
10663 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10665 if (size > DWARF2_ADDR_SIZE || size == -1)
10667 else if (size == DWARF2_ADDR_SIZE)
10670 op = DW_OP_deref_size;
10672 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10678 static inline dw_loc_descr_ref
10679 loc_descriptor_from_tree (tree loc)
10681 return loc_descriptor_from_tree_1 (loc, 2);
10684 /* Given a value, round it up to the lowest multiple of `boundary'
10685 which is not less than the value itself. */
10687 static inline HOST_WIDE_INT
10688 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10690 return (((value + boundary - 1) / boundary) * boundary);
10693 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10694 pointer to the declared type for the relevant field variable, or return
10695 `integer_type_node' if the given node turns out to be an
10696 ERROR_MARK node. */
10699 field_type (const_tree decl)
10703 if (TREE_CODE (decl) == ERROR_MARK)
10704 return integer_type_node;
10706 type = DECL_BIT_FIELD_TYPE (decl);
10707 if (type == NULL_TREE)
10708 type = TREE_TYPE (decl);
10713 /* Given a pointer to a tree node, return the alignment in bits for
10714 it, or else return BITS_PER_WORD if the node actually turns out to
10715 be an ERROR_MARK node. */
10717 static inline unsigned
10718 simple_type_align_in_bits (const_tree type)
10720 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10723 static inline unsigned
10724 simple_decl_align_in_bits (const_tree decl)
10726 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10729 /* Return the result of rounding T up to ALIGN. */
10731 static inline HOST_WIDE_INT
10732 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10734 /* We must be careful if T is negative because HOST_WIDE_INT can be
10735 either "above" or "below" unsigned int as per the C promotion
10736 rules, depending on the host, thus making the signedness of the
10737 direct multiplication and division unpredictable. */
10738 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10744 return (HOST_WIDE_INT) u;
10747 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10748 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10749 or return 0 if we are unable to determine what that offset is, either
10750 because the argument turns out to be a pointer to an ERROR_MARK node, or
10751 because the offset is actually variable. (We can't handle the latter case
10754 static HOST_WIDE_INT
10755 field_byte_offset (const_tree decl)
10757 HOST_WIDE_INT object_offset_in_bits;
10758 HOST_WIDE_INT bitpos_int;
10760 if (TREE_CODE (decl) == ERROR_MARK)
10763 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10765 /* We cannot yet cope with fields whose positions are variable, so
10766 for now, when we see such things, we simply return 0. Someday, we may
10767 be able to handle such cases, but it will be damn difficult. */
10768 if (! host_integerp (bit_position (decl), 0))
10771 bitpos_int = int_bit_position (decl);
10773 #ifdef PCC_BITFIELD_TYPE_MATTERS
10774 if (PCC_BITFIELD_TYPE_MATTERS)
10777 tree field_size_tree;
10778 HOST_WIDE_INT deepest_bitpos;
10779 unsigned HOST_WIDE_INT field_size_in_bits;
10780 unsigned int type_align_in_bits;
10781 unsigned int decl_align_in_bits;
10782 unsigned HOST_WIDE_INT type_size_in_bits;
10784 type = field_type (decl);
10785 field_size_tree = DECL_SIZE (decl);
10787 /* The size could be unspecified if there was an error, or for
10788 a flexible array member. */
10789 if (! field_size_tree)
10790 field_size_tree = bitsize_zero_node;
10792 /* If we don't know the size of the field, pretend it's a full word. */
10793 if (host_integerp (field_size_tree, 1))
10794 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10796 field_size_in_bits = BITS_PER_WORD;
10798 type_size_in_bits = simple_type_size_in_bits (type);
10799 type_align_in_bits = simple_type_align_in_bits (type);
10800 decl_align_in_bits = simple_decl_align_in_bits (decl);
10802 /* The GCC front-end doesn't make any attempt to keep track of the
10803 starting bit offset (relative to the start of the containing
10804 structure type) of the hypothetical "containing object" for a
10805 bit-field. Thus, when computing the byte offset value for the
10806 start of the "containing object" of a bit-field, we must deduce
10807 this information on our own. This can be rather tricky to do in
10808 some cases. For example, handling the following structure type
10809 definition when compiling for an i386/i486 target (which only
10810 aligns long long's to 32-bit boundaries) can be very tricky:
10812 struct S { int field1; long long field2:31; };
10814 Fortunately, there is a simple rule-of-thumb which can be used
10815 in such cases. When compiling for an i386/i486, GCC will
10816 allocate 8 bytes for the structure shown above. It decides to
10817 do this based upon one simple rule for bit-field allocation.
10818 GCC allocates each "containing object" for each bit-field at
10819 the first (i.e. lowest addressed) legitimate alignment boundary
10820 (based upon the required minimum alignment for the declared
10821 type of the field) which it can possibly use, subject to the
10822 condition that there is still enough available space remaining
10823 in the containing object (when allocated at the selected point)
10824 to fully accommodate all of the bits of the bit-field itself.
10826 This simple rule makes it obvious why GCC allocates 8 bytes for
10827 each object of the structure type shown above. When looking
10828 for a place to allocate the "containing object" for `field2',
10829 the compiler simply tries to allocate a 64-bit "containing
10830 object" at each successive 32-bit boundary (starting at zero)
10831 until it finds a place to allocate that 64- bit field such that
10832 at least 31 contiguous (and previously unallocated) bits remain
10833 within that selected 64 bit field. (As it turns out, for the
10834 example above, the compiler finds it is OK to allocate the
10835 "containing object" 64-bit field at bit-offset zero within the
10838 Here we attempt to work backwards from the limited set of facts
10839 we're given, and we try to deduce from those facts, where GCC
10840 must have believed that the containing object started (within
10841 the structure type). The value we deduce is then used (by the
10842 callers of this routine) to generate DW_AT_location and
10843 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10844 the case of DW_AT_location, regular fields as well). */
10846 /* Figure out the bit-distance from the start of the structure to
10847 the "deepest" bit of the bit-field. */
10848 deepest_bitpos = bitpos_int + field_size_in_bits;
10850 /* This is the tricky part. Use some fancy footwork to deduce
10851 where the lowest addressed bit of the containing object must
10853 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10855 /* Round up to type_align by default. This works best for
10857 object_offset_in_bits
10858 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10860 if (object_offset_in_bits > bitpos_int)
10862 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10864 /* Round up to decl_align instead. */
10865 object_offset_in_bits
10866 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10871 object_offset_in_bits = bitpos_int;
10873 return object_offset_in_bits / BITS_PER_UNIT;
10876 /* The following routines define various Dwarf attributes and any data
10877 associated with them. */
10879 /* Add a location description attribute value to a DIE.
10881 This emits location attributes suitable for whole variables and
10882 whole parameters. Note that the location attributes for struct fields are
10883 generated by the routine `data_member_location_attribute' below. */
10886 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10887 dw_loc_descr_ref descr)
10890 add_AT_loc (die, attr_kind, descr);
10893 /* Attach the specialized form of location attribute used for data members of
10894 struct and union types. In the special case of a FIELD_DECL node which
10895 represents a bit-field, the "offset" part of this special location
10896 descriptor must indicate the distance in bytes from the lowest-addressed
10897 byte of the containing struct or union type to the lowest-addressed byte of
10898 the "containing object" for the bit-field. (See the `field_byte_offset'
10901 For any given bit-field, the "containing object" is a hypothetical object
10902 (of some integral or enum type) within which the given bit-field lives. The
10903 type of this hypothetical "containing object" is always the same as the
10904 declared type of the individual bit-field itself (for GCC anyway... the
10905 DWARF spec doesn't actually mandate this). Note that it is the size (in
10906 bytes) of the hypothetical "containing object" which will be given in the
10907 DW_AT_byte_size attribute for this bit-field. (See the
10908 `byte_size_attribute' function below.) It is also used when calculating the
10909 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10910 function below.) */
10913 add_data_member_location_attribute (dw_die_ref die, tree decl)
10915 HOST_WIDE_INT offset;
10916 dw_loc_descr_ref loc_descr = 0;
10918 if (TREE_CODE (decl) == TREE_BINFO)
10920 /* We're working on the TAG_inheritance for a base class. */
10921 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10923 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10924 aren't at a fixed offset from all (sub)objects of the same
10925 type. We need to extract the appropriate offset from our
10926 vtable. The following dwarf expression means
10928 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10930 This is specific to the V3 ABI, of course. */
10932 dw_loc_descr_ref tmp;
10934 /* Make a copy of the object address. */
10935 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10936 add_loc_descr (&loc_descr, tmp);
10938 /* Extract the vtable address. */
10939 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10940 add_loc_descr (&loc_descr, tmp);
10942 /* Calculate the address of the offset. */
10943 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10944 gcc_assert (offset < 0);
10946 tmp = int_loc_descriptor (-offset);
10947 add_loc_descr (&loc_descr, tmp);
10948 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10949 add_loc_descr (&loc_descr, tmp);
10951 /* Extract the offset. */
10952 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10953 add_loc_descr (&loc_descr, tmp);
10955 /* Add it to the object address. */
10956 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10957 add_loc_descr (&loc_descr, tmp);
10960 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10963 offset = field_byte_offset (decl);
10967 enum dwarf_location_atom op;
10969 /* The DWARF2 standard says that we should assume that the structure
10970 address is already on the stack, so we can specify a structure field
10971 address by using DW_OP_plus_uconst. */
10973 #ifdef MIPS_DEBUGGING_INFO
10974 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10975 operator correctly. It works only if we leave the offset on the
10979 op = DW_OP_plus_uconst;
10982 loc_descr = new_loc_descr (op, offset, 0);
10985 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10988 /* Writes integer values to dw_vec_const array. */
10991 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10995 *dest++ = val & 0xff;
11001 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11003 static HOST_WIDE_INT
11004 extract_int (const unsigned char *src, unsigned int size)
11006 HOST_WIDE_INT val = 0;
11012 val |= *--src & 0xff;
11018 /* Writes floating point values to dw_vec_const array. */
11021 insert_float (const_rtx rtl, unsigned char *array)
11023 REAL_VALUE_TYPE rv;
11027 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11028 real_to_target (val, &rv, GET_MODE (rtl));
11030 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11031 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11033 insert_int (val[i], 4, array);
11038 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11039 does not have a "location" either in memory or in a register. These
11040 things can arise in GNU C when a constant is passed as an actual parameter
11041 to an inlined function. They can also arise in C++ where declared
11042 constants do not necessarily get memory "homes". */
11045 add_const_value_attribute (dw_die_ref die, rtx rtl)
11047 switch (GET_CODE (rtl))
11051 HOST_WIDE_INT val = INTVAL (rtl);
11054 add_AT_int (die, DW_AT_const_value, val);
11056 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11061 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11062 floating-point constant. A CONST_DOUBLE is used whenever the
11063 constant requires more than one word in order to be adequately
11064 represented. We output CONST_DOUBLEs as blocks. */
11066 enum machine_mode mode = GET_MODE (rtl);
11068 if (SCALAR_FLOAT_MODE_P (mode))
11070 unsigned int length = GET_MODE_SIZE (mode);
11071 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11073 insert_float (rtl, array);
11074 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11078 /* ??? We really should be using HOST_WIDE_INT throughout. */
11079 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11081 add_AT_long_long (die, DW_AT_const_value,
11082 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11089 enum machine_mode mode = GET_MODE (rtl);
11090 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11091 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11092 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11096 switch (GET_MODE_CLASS (mode))
11098 case MODE_VECTOR_INT:
11099 for (i = 0, p = array; i < length; i++, p += elt_size)
11101 rtx elt = CONST_VECTOR_ELT (rtl, i);
11102 HOST_WIDE_INT lo, hi;
11104 switch (GET_CODE (elt))
11112 lo = CONST_DOUBLE_LOW (elt);
11113 hi = CONST_DOUBLE_HIGH (elt);
11117 gcc_unreachable ();
11120 if (elt_size <= sizeof (HOST_WIDE_INT))
11121 insert_int (lo, elt_size, p);
11124 unsigned char *p0 = p;
11125 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11127 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11128 if (WORDS_BIG_ENDIAN)
11133 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11134 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11139 case MODE_VECTOR_FLOAT:
11140 for (i = 0, p = array; i < length; i++, p += elt_size)
11142 rtx elt = CONST_VECTOR_ELT (rtl, i);
11143 insert_float (elt, p);
11148 gcc_unreachable ();
11151 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11156 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11162 add_AT_addr (die, DW_AT_const_value, rtl);
11163 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11167 /* In cases where an inlined instance of an inline function is passed
11168 the address of an `auto' variable (which is local to the caller) we
11169 can get a situation where the DECL_RTL of the artificial local
11170 variable (for the inlining) which acts as a stand-in for the
11171 corresponding formal parameter (of the inline function) will look
11172 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11173 exactly a compile-time constant expression, but it isn't the address
11174 of the (artificial) local variable either. Rather, it represents the
11175 *value* which the artificial local variable always has during its
11176 lifetime. We currently have no way to represent such quasi-constant
11177 values in Dwarf, so for now we just punt and generate nothing. */
11181 /* No other kinds of rtx should be possible here. */
11182 gcc_unreachable ();
11187 /* Determine whether the evaluation of EXPR references any variables
11188 or functions which aren't otherwise used (and therefore may not be
11191 reference_to_unused (tree * tp, int * walk_subtrees,
11192 void * data ATTRIBUTE_UNUSED)
11194 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11195 *walk_subtrees = 0;
11197 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11198 && ! TREE_ASM_WRITTEN (*tp))
11200 /* ??? The C++ FE emits debug information for using decls, so
11201 putting gcc_unreachable here falls over. See PR31899. For now
11202 be conservative. */
11203 else if (!cgraph_global_info_ready
11204 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11206 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11208 struct varpool_node *node = varpool_node (*tp);
11212 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11213 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11215 struct cgraph_node *node = cgraph_node (*tp);
11219 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11225 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11226 for use in a later add_const_value_attribute call. */
11229 rtl_for_decl_init (tree init, tree type)
11231 rtx rtl = NULL_RTX;
11233 /* If a variable is initialized with a string constant without embedded
11234 zeros, build CONST_STRING. */
11235 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11237 tree enttype = TREE_TYPE (type);
11238 tree domain = TYPE_DOMAIN (type);
11239 enum machine_mode mode = TYPE_MODE (enttype);
11241 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11243 && integer_zerop (TYPE_MIN_VALUE (domain))
11244 && compare_tree_int (TYPE_MAX_VALUE (domain),
11245 TREE_STRING_LENGTH (init) - 1) == 0
11246 && ((size_t) TREE_STRING_LENGTH (init)
11247 == strlen (TREE_STRING_POINTER (init)) + 1))
11248 rtl = gen_rtx_CONST_STRING (VOIDmode,
11249 ggc_strdup (TREE_STRING_POINTER (init)));
11251 /* Other aggregates, and complex values, could be represented using
11253 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11255 /* Vectors only work if their mode is supported by the target.
11256 FIXME: generic vectors ought to work too. */
11257 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11259 /* If the initializer is something that we know will expand into an
11260 immediate RTL constant, expand it now. We must be careful not to
11261 reference variables which won't be output. */
11262 else if (initializer_constant_valid_p (init, type)
11263 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11265 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11267 if (TREE_CODE (type) == VECTOR_TYPE)
11268 switch (TREE_CODE (init))
11273 if (TREE_CONSTANT (init))
11275 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11276 bool constant_p = true;
11278 unsigned HOST_WIDE_INT ix;
11280 /* Even when ctor is constant, it might contain non-*_CST
11281 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11282 belong into VECTOR_CST nodes. */
11283 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11284 if (!CONSTANT_CLASS_P (value))
11286 constant_p = false;
11292 init = build_vector_from_ctor (type, elts);
11302 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11304 /* If expand_expr returns a MEM, it wasn't immediate. */
11305 gcc_assert (!rtl || !MEM_P (rtl));
11311 /* Generate RTL for the variable DECL to represent its location. */
11314 rtl_for_decl_location (tree decl)
11318 /* Here we have to decide where we are going to say the parameter "lives"
11319 (as far as the debugger is concerned). We only have a couple of
11320 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11322 DECL_RTL normally indicates where the parameter lives during most of the
11323 activation of the function. If optimization is enabled however, this
11324 could be either NULL or else a pseudo-reg. Both of those cases indicate
11325 that the parameter doesn't really live anywhere (as far as the code
11326 generation parts of GCC are concerned) during most of the function's
11327 activation. That will happen (for example) if the parameter is never
11328 referenced within the function.
11330 We could just generate a location descriptor here for all non-NULL
11331 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11332 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11333 where DECL_RTL is NULL or is a pseudo-reg.
11335 Note however that we can only get away with using DECL_INCOMING_RTL as
11336 a backup substitute for DECL_RTL in certain limited cases. In cases
11337 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11338 we can be sure that the parameter was passed using the same type as it is
11339 declared to have within the function, and that its DECL_INCOMING_RTL
11340 points us to a place where a value of that type is passed.
11342 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11343 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11344 because in these cases DECL_INCOMING_RTL points us to a value of some
11345 type which is *different* from the type of the parameter itself. Thus,
11346 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11347 such cases, the debugger would end up (for example) trying to fetch a
11348 `float' from a place which actually contains the first part of a
11349 `double'. That would lead to really incorrect and confusing
11350 output at debug-time.
11352 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11353 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11354 are a couple of exceptions however. On little-endian machines we can
11355 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11356 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11357 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11358 when (on a little-endian machine) a non-prototyped function has a
11359 parameter declared to be of type `short' or `char'. In such cases,
11360 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11361 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11362 passed `int' value. If the debugger then uses that address to fetch
11363 a `short' or a `char' (on a little-endian machine) the result will be
11364 the correct data, so we allow for such exceptional cases below.
11366 Note that our goal here is to describe the place where the given formal
11367 parameter lives during most of the function's activation (i.e. between the
11368 end of the prologue and the start of the epilogue). We'll do that as best
11369 as we can. Note however that if the given formal parameter is modified
11370 sometime during the execution of the function, then a stack backtrace (at
11371 debug-time) will show the function as having been called with the *new*
11372 value rather than the value which was originally passed in. This happens
11373 rarely enough that it is not a major problem, but it *is* a problem, and
11374 I'd like to fix it.
11376 A future version of dwarf2out.c may generate two additional attributes for
11377 any given DW_TAG_formal_parameter DIE which will describe the "passed
11378 type" and the "passed location" for the given formal parameter in addition
11379 to the attributes we now generate to indicate the "declared type" and the
11380 "active location" for each parameter. This additional set of attributes
11381 could be used by debuggers for stack backtraces. Separately, note that
11382 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11383 This happens (for example) for inlined-instances of inline function formal
11384 parameters which are never referenced. This really shouldn't be
11385 happening. All PARM_DECL nodes should get valid non-NULL
11386 DECL_INCOMING_RTL values. FIXME. */
11388 /* Use DECL_RTL as the "location" unless we find something better. */
11389 rtl = DECL_RTL_IF_SET (decl);
11391 /* When generating abstract instances, ignore everything except
11392 constants, symbols living in memory, and symbols living in
11393 fixed registers. */
11394 if (! reload_completed)
11397 && (CONSTANT_P (rtl)
11399 && CONSTANT_P (XEXP (rtl, 0)))
11401 && TREE_CODE (decl) == VAR_DECL
11402 && TREE_STATIC (decl))))
11404 rtl = targetm.delegitimize_address (rtl);
11409 else if (TREE_CODE (decl) == PARM_DECL)
11411 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11413 tree declared_type = TREE_TYPE (decl);
11414 tree passed_type = DECL_ARG_TYPE (decl);
11415 enum machine_mode dmode = TYPE_MODE (declared_type);
11416 enum machine_mode pmode = TYPE_MODE (passed_type);
11418 /* This decl represents a formal parameter which was optimized out.
11419 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11420 all cases where (rtl == NULL_RTX) just below. */
11421 if (dmode == pmode)
11422 rtl = DECL_INCOMING_RTL (decl);
11423 else if (SCALAR_INT_MODE_P (dmode)
11424 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11425 && DECL_INCOMING_RTL (decl))
11427 rtx inc = DECL_INCOMING_RTL (decl);
11430 else if (MEM_P (inc))
11432 if (BYTES_BIG_ENDIAN)
11433 rtl = adjust_address_nv (inc, dmode,
11434 GET_MODE_SIZE (pmode)
11435 - GET_MODE_SIZE (dmode));
11442 /* If the parm was passed in registers, but lives on the stack, then
11443 make a big endian correction if the mode of the type of the
11444 parameter is not the same as the mode of the rtl. */
11445 /* ??? This is the same series of checks that are made in dbxout.c before
11446 we reach the big endian correction code there. It isn't clear if all
11447 of these checks are necessary here, but keeping them all is the safe
11449 else if (MEM_P (rtl)
11450 && XEXP (rtl, 0) != const0_rtx
11451 && ! CONSTANT_P (XEXP (rtl, 0))
11452 /* Not passed in memory. */
11453 && !MEM_P (DECL_INCOMING_RTL (decl))
11454 /* Not passed by invisible reference. */
11455 && (!REG_P (XEXP (rtl, 0))
11456 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11457 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11458 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11459 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11462 /* Big endian correction check. */
11463 && BYTES_BIG_ENDIAN
11464 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11465 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11468 int offset = (UNITS_PER_WORD
11469 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11471 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11472 plus_constant (XEXP (rtl, 0), offset));
11475 else if (TREE_CODE (decl) == VAR_DECL
11478 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11479 && BYTES_BIG_ENDIAN)
11481 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11482 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11484 /* If a variable is declared "register" yet is smaller than
11485 a register, then if we store the variable to memory, it
11486 looks like we're storing a register-sized value, when in
11487 fact we are not. We need to adjust the offset of the
11488 storage location to reflect the actual value's bytes,
11489 else gdb will not be able to display it. */
11491 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11492 plus_constant (XEXP (rtl, 0), rsize-dsize));
11495 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11496 and will have been substituted directly into all expressions that use it.
11497 C does not have such a concept, but C++ and other languages do. */
11498 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11499 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11502 rtl = targetm.delegitimize_address (rtl);
11504 /* If we don't look past the constant pool, we risk emitting a
11505 reference to a constant pool entry that isn't referenced from
11506 code, and thus is not emitted. */
11508 rtl = avoid_constant_pool_reference (rtl);
11513 /* We need to figure out what section we should use as the base for the
11514 address ranges where a given location is valid.
11515 1. If this particular DECL has a section associated with it, use that.
11516 2. If this function has a section associated with it, use that.
11517 3. Otherwise, use the text section.
11518 XXX: If you split a variable across multiple sections, we won't notice. */
11520 static const char *
11521 secname_for_decl (const_tree decl)
11523 const char *secname;
11525 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11527 tree sectree = DECL_SECTION_NAME (decl);
11528 secname = TREE_STRING_POINTER (sectree);
11530 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11532 tree sectree = DECL_SECTION_NAME (current_function_decl);
11533 secname = TREE_STRING_POINTER (sectree);
11535 else if (cfun && in_cold_section_p)
11536 secname = crtl->subsections.cold_section_label;
11538 secname = text_section_label;
11543 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
11544 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
11545 value is the offset into the common block for the symbol. */
11548 fortran_common (tree decl, HOST_WIDE_INT *value)
11550 tree val_expr, cvar;
11551 enum machine_mode mode;
11552 HOST_WIDE_INT bitsize, bitpos;
11554 int volatilep = 0, unsignedp = 0;
11556 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11557 it does not have a value (the offset into the common area), or if it
11558 is thread local (as opposed to global) then it isn't common, and shouldn't
11559 be handled as such. */
11560 if (TREE_CODE (decl) != VAR_DECL
11561 || !TREE_PUBLIC (decl)
11562 || !TREE_STATIC (decl)
11563 || !DECL_HAS_VALUE_EXPR_P (decl)
11567 val_expr = DECL_VALUE_EXPR (decl);
11568 if (TREE_CODE (val_expr) != COMPONENT_REF)
11571 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11572 &mode, &unsignedp, &volatilep, true);
11574 if (cvar == NULL_TREE
11575 || TREE_CODE (cvar) != VAR_DECL
11576 || DECL_ARTIFICIAL (cvar)
11577 || !TREE_PUBLIC (cvar))
11581 if (offset != NULL)
11583 if (!host_integerp (offset, 0))
11585 *value = tree_low_cst (offset, 0);
11588 *value += bitpos / BITS_PER_UNIT;
11594 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11595 data attribute for a variable or a parameter. We generate the
11596 DW_AT_const_value attribute only in those cases where the given variable
11597 or parameter does not have a true "location" either in memory or in a
11598 register. This can happen (for example) when a constant is passed as an
11599 actual argument in a call to an inline function. (It's possible that
11600 these things can crop up in other ways also.) Note that one type of
11601 constant value which can be passed into an inlined function is a constant
11602 pointer. This can happen for example if an actual argument in an inlined
11603 function call evaluates to a compile-time constant address. */
11606 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11607 enum dwarf_attribute attr)
11610 dw_loc_descr_ref descr;
11611 var_loc_list *loc_list;
11612 struct var_loc_node *node;
11613 if (TREE_CODE (decl) == ERROR_MARK)
11616 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11617 || TREE_CODE (decl) == RESULT_DECL);
11619 /* See if we possibly have multiple locations for this variable. */
11620 loc_list = lookup_decl_loc (decl);
11622 /* If it truly has multiple locations, the first and last node will
11624 if (loc_list && loc_list->first != loc_list->last)
11626 const char *endname, *secname;
11627 dw_loc_list_ref list;
11629 enum var_init_status initialized;
11631 /* Now that we know what section we are using for a base,
11632 actually construct the list of locations.
11633 The first location information is what is passed to the
11634 function that creates the location list, and the remaining
11635 locations just get added on to that list.
11636 Note that we only know the start address for a location
11637 (IE location changes), so to build the range, we use
11638 the range [current location start, next location start].
11639 This means we have to special case the last node, and generate
11640 a range of [last location start, end of function label]. */
11642 node = loc_list->first;
11643 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11644 secname = secname_for_decl (decl);
11646 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11647 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11649 initialized = VAR_INIT_STATUS_INITIALIZED;
11651 list = new_loc_list (loc_descriptor (varloc, initialized),
11652 node->label, node->next->label, secname, 1);
11655 for (; node->next; node = node->next)
11656 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11658 /* The variable has a location between NODE->LABEL and
11659 NODE->NEXT->LABEL. */
11660 enum var_init_status initialized =
11661 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11662 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11663 add_loc_descr_to_loc_list (&list,
11664 loc_descriptor (varloc, initialized),
11665 node->label, node->next->label, secname);
11668 /* If the variable has a location at the last label
11669 it keeps its location until the end of function. */
11670 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11672 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11673 enum var_init_status initialized =
11674 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11676 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11677 if (!current_function_decl)
11678 endname = text_end_label;
11681 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11682 current_function_funcdef_no);
11683 endname = ggc_strdup (label_id);
11685 add_loc_descr_to_loc_list (&list,
11686 loc_descriptor (varloc, initialized),
11687 node->label, endname, secname);
11690 /* Finally, add the location list to the DIE, and we are done. */
11691 add_AT_loc_list (die, attr, list);
11695 /* Try to get some constant RTL for this decl, and use that as the value of
11698 rtl = rtl_for_decl_location (decl);
11699 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11701 add_const_value_attribute (die, rtl);
11705 /* If we have tried to generate the location otherwise, and it
11706 didn't work out (we wouldn't be here if we did), and we have a one entry
11707 location list, try generating a location from that. */
11708 if (loc_list && loc_list->first)
11710 enum var_init_status status;
11711 node = loc_list->first;
11712 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11713 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11716 add_AT_location_description (die, attr, descr);
11721 /* We couldn't get any rtl, so try directly generating the location
11722 description from the tree. */
11723 descr = loc_descriptor_from_tree (decl);
11726 add_AT_location_description (die, attr, descr);
11729 /* None of that worked, so it must not really have a location;
11730 try adding a constant value attribute from the DECL_INITIAL. */
11731 tree_add_const_value_attribute (die, decl);
11734 /* If we don't have a copy of this variable in memory for some reason (such
11735 as a C++ member constant that doesn't have an out-of-line definition),
11736 we should tell the debugger about the constant value. */
11739 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
11741 tree init = DECL_INITIAL (decl);
11742 tree type = TREE_TYPE (decl);
11745 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
11750 rtl = rtl_for_decl_init (init, type);
11752 add_const_value_attribute (var_die, rtl);
11755 /* Convert the CFI instructions for the current function into a
11756 location list. This is used for DW_AT_frame_base when we targeting
11757 a dwarf2 consumer that does not support the dwarf3
11758 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11761 static dw_loc_list_ref
11762 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
11765 dw_loc_list_ref list, *list_tail;
11767 dw_cfa_location last_cfa, next_cfa;
11768 const char *start_label, *last_label, *section;
11770 fde = current_fde ();
11771 gcc_assert (fde != NULL);
11773 section = secname_for_decl (current_function_decl);
11777 next_cfa.reg = INVALID_REGNUM;
11778 next_cfa.offset = 0;
11779 next_cfa.indirect = 0;
11780 next_cfa.base_offset = 0;
11782 start_label = fde->dw_fde_begin;
11784 /* ??? Bald assumption that the CIE opcode list does not contain
11785 advance opcodes. */
11786 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11787 lookup_cfa_1 (cfi, &next_cfa);
11789 last_cfa = next_cfa;
11790 last_label = start_label;
11792 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11793 switch (cfi->dw_cfi_opc)
11795 case DW_CFA_set_loc:
11796 case DW_CFA_advance_loc1:
11797 case DW_CFA_advance_loc2:
11798 case DW_CFA_advance_loc4:
11799 if (!cfa_equal_p (&last_cfa, &next_cfa))
11801 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11802 start_label, last_label, section,
11805 list_tail = &(*list_tail)->dw_loc_next;
11806 last_cfa = next_cfa;
11807 start_label = last_label;
11809 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11812 case DW_CFA_advance_loc:
11813 /* The encoding is complex enough that we should never emit this. */
11814 case DW_CFA_remember_state:
11815 case DW_CFA_restore_state:
11816 /* We don't handle these two in this function. It would be possible
11817 if it were to be required. */
11818 gcc_unreachable ();
11821 lookup_cfa_1 (cfi, &next_cfa);
11825 if (!cfa_equal_p (&last_cfa, &next_cfa))
11827 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11828 start_label, last_label, section,
11830 list_tail = &(*list_tail)->dw_loc_next;
11831 start_label = last_label;
11833 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11834 start_label, fde->dw_fde_end, section,
11840 /* Compute a displacement from the "steady-state frame pointer" to the
11841 frame base (often the same as the CFA), and store it in
11842 frame_pointer_fb_offset. OFFSET is added to the displacement
11843 before the latter is negated. */
11846 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11850 #ifdef FRAME_POINTER_CFA_OFFSET
11851 reg = frame_pointer_rtx;
11852 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11854 reg = arg_pointer_rtx;
11855 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11858 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11859 if (GET_CODE (elim) == PLUS)
11861 offset += INTVAL (XEXP (elim, 1));
11862 elim = XEXP (elim, 0);
11865 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11866 && (elim == hard_frame_pointer_rtx
11867 || elim == stack_pointer_rtx))
11868 || elim == (frame_pointer_needed
11869 ? hard_frame_pointer_rtx
11870 : stack_pointer_rtx));
11872 frame_pointer_fb_offset = -offset;
11875 /* Generate a DW_AT_name attribute given some string value to be included as
11876 the value of the attribute. */
11879 add_name_attribute (dw_die_ref die, const char *name_string)
11881 if (name_string != NULL && *name_string != 0)
11883 if (demangle_name_func)
11884 name_string = (*demangle_name_func) (name_string);
11886 add_AT_string (die, DW_AT_name, name_string);
11890 /* Generate a DW_AT_comp_dir attribute for DIE. */
11893 add_comp_dir_attribute (dw_die_ref die)
11895 const char *wd = get_src_pwd ();
11897 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11900 /* Given a tree node describing an array bound (either lower or upper) output
11901 a representation for that bound. */
11904 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11906 switch (TREE_CODE (bound))
11911 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11913 if (! host_integerp (bound, 0)
11914 || (bound_attr == DW_AT_lower_bound
11915 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11916 || (is_fortran () && integer_onep (bound)))))
11917 /* Use the default. */
11920 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11924 case VIEW_CONVERT_EXPR:
11925 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11935 dw_die_ref decl_die = lookup_decl_die (bound);
11937 /* ??? Can this happen, or should the variable have been bound
11938 first? Probably it can, since I imagine that we try to create
11939 the types of parameters in the order in which they exist in
11940 the list, and won't have created a forward reference to a
11941 later parameter. */
11942 if (decl_die != NULL)
11943 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11949 /* Otherwise try to create a stack operation procedure to
11950 evaluate the value of the array bound. */
11952 dw_die_ref ctx, decl_die;
11953 dw_loc_descr_ref loc;
11955 loc = loc_descriptor_from_tree (bound);
11959 if (current_function_decl == 0)
11960 ctx = comp_unit_die;
11962 ctx = lookup_decl_die (current_function_decl);
11964 decl_die = new_die (DW_TAG_variable, ctx, bound);
11965 add_AT_flag (decl_die, DW_AT_artificial, 1);
11966 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11967 add_AT_loc (decl_die, DW_AT_location, loc);
11969 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11975 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
11976 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
11977 Note that the block of subscript information for an array type also
11978 includes information about the element type of the given array type. */
11981 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
11983 unsigned dimension_number;
11985 dw_die_ref subrange_die;
11987 for (dimension_number = 0;
11988 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
11989 type = TREE_TYPE (type), dimension_number++)
11991 tree domain = TYPE_DOMAIN (type);
11993 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11994 and (in GNU C only) variable bounds. Handle all three forms
11996 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11999 /* We have an array type with specified bounds. */
12000 lower = TYPE_MIN_VALUE (domain);
12001 upper = TYPE_MAX_VALUE (domain);
12003 /* Define the index type. */
12004 if (TREE_TYPE (domain))
12006 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12007 TREE_TYPE field. We can't emit debug info for this
12008 because it is an unnamed integral type. */
12009 if (TREE_CODE (domain) == INTEGER_TYPE
12010 && TYPE_NAME (domain) == NULL_TREE
12011 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12012 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12015 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12019 /* ??? If upper is NULL, the array has unspecified length,
12020 but it does have a lower bound. This happens with Fortran
12022 Since the debugger is definitely going to need to know N
12023 to produce useful results, go ahead and output the lower
12024 bound solo, and hope the debugger can cope. */
12026 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12028 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12031 /* Otherwise we have an array type with an unspecified length. The
12032 DWARF-2 spec does not say how to handle this; let's just leave out the
12038 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12042 switch (TREE_CODE (tree_node))
12047 case ENUMERAL_TYPE:
12050 case QUAL_UNION_TYPE:
12051 size = int_size_in_bytes (tree_node);
12054 /* For a data member of a struct or union, the DW_AT_byte_size is
12055 generally given as the number of bytes normally allocated for an
12056 object of the *declared* type of the member itself. This is true
12057 even for bit-fields. */
12058 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12061 gcc_unreachable ();
12064 /* Note that `size' might be -1 when we get to this point. If it is, that
12065 indicates that the byte size of the entity in question is variable. We
12066 have no good way of expressing this fact in Dwarf at the present time,
12067 so just let the -1 pass on through. */
12068 add_AT_unsigned (die, DW_AT_byte_size, size);
12071 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12072 which specifies the distance in bits from the highest order bit of the
12073 "containing object" for the bit-field to the highest order bit of the
12076 For any given bit-field, the "containing object" is a hypothetical object
12077 (of some integral or enum type) within which the given bit-field lives. The
12078 type of this hypothetical "containing object" is always the same as the
12079 declared type of the individual bit-field itself. The determination of the
12080 exact location of the "containing object" for a bit-field is rather
12081 complicated. It's handled by the `field_byte_offset' function (above).
12083 Note that it is the size (in bytes) of the hypothetical "containing object"
12084 which will be given in the DW_AT_byte_size attribute for this bit-field.
12085 (See `byte_size_attribute' above). */
12088 add_bit_offset_attribute (dw_die_ref die, tree decl)
12090 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12091 tree type = DECL_BIT_FIELD_TYPE (decl);
12092 HOST_WIDE_INT bitpos_int;
12093 HOST_WIDE_INT highest_order_object_bit_offset;
12094 HOST_WIDE_INT highest_order_field_bit_offset;
12095 HOST_WIDE_INT unsigned bit_offset;
12097 /* Must be a field and a bit field. */
12098 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12100 /* We can't yet handle bit-fields whose offsets are variable, so if we
12101 encounter such things, just return without generating any attribute
12102 whatsoever. Likewise for variable or too large size. */
12103 if (! host_integerp (bit_position (decl), 0)
12104 || ! host_integerp (DECL_SIZE (decl), 1))
12107 bitpos_int = int_bit_position (decl);
12109 /* Note that the bit offset is always the distance (in bits) from the
12110 highest-order bit of the "containing object" to the highest-order bit of
12111 the bit-field itself. Since the "high-order end" of any object or field
12112 is different on big-endian and little-endian machines, the computation
12113 below must take account of these differences. */
12114 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12115 highest_order_field_bit_offset = bitpos_int;
12117 if (! BYTES_BIG_ENDIAN)
12119 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12120 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12124 = (! BYTES_BIG_ENDIAN
12125 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12126 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12128 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12131 /* For a FIELD_DECL node which represents a bit field, output an attribute
12132 which specifies the length in bits of the given field. */
12135 add_bit_size_attribute (dw_die_ref die, tree decl)
12137 /* Must be a field and a bit field. */
12138 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12139 && DECL_BIT_FIELD_TYPE (decl));
12141 if (host_integerp (DECL_SIZE (decl), 1))
12142 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12145 /* If the compiled language is ANSI C, then add a 'prototyped'
12146 attribute, if arg types are given for the parameters of a function. */
12149 add_prototyped_attribute (dw_die_ref die, tree func_type)
12151 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12152 && TYPE_ARG_TYPES (func_type) != NULL)
12153 add_AT_flag (die, DW_AT_prototyped, 1);
12156 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12157 by looking in either the type declaration or object declaration
12161 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12163 dw_die_ref origin_die = NULL;
12165 if (TREE_CODE (origin) != FUNCTION_DECL)
12167 /* We may have gotten separated from the block for the inlined
12168 function, if we're in an exception handler or some such; make
12169 sure that the abstract function has been written out.
12171 Doing this for nested functions is wrong, however; functions are
12172 distinct units, and our context might not even be inline. */
12176 fn = TYPE_STUB_DECL (fn);
12178 fn = decl_function_context (fn);
12180 dwarf2out_abstract_function (fn);
12183 if (DECL_P (origin))
12184 origin_die = lookup_decl_die (origin);
12185 else if (TYPE_P (origin))
12186 origin_die = lookup_type_die (origin);
12188 /* XXX: Functions that are never lowered don't always have correct block
12189 trees (in the case of java, they simply have no block tree, in some other
12190 languages). For these functions, there is nothing we can really do to
12191 output correct debug info for inlined functions in all cases. Rather
12192 than die, we'll just produce deficient debug info now, in that we will
12193 have variables without a proper abstract origin. In the future, when all
12194 functions are lowered, we should re-add a gcc_assert (origin_die)
12198 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12201 /* We do not currently support the pure_virtual attribute. */
12204 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12206 if (DECL_VINDEX (func_decl))
12208 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12210 if (host_integerp (DECL_VINDEX (func_decl), 0))
12211 add_AT_loc (die, DW_AT_vtable_elem_location,
12212 new_loc_descr (DW_OP_constu,
12213 tree_low_cst (DECL_VINDEX (func_decl), 0),
12216 /* GNU extension: Record what type this method came from originally. */
12217 if (debug_info_level > DINFO_LEVEL_TERSE)
12218 add_AT_die_ref (die, DW_AT_containing_type,
12219 lookup_type_die (DECL_CONTEXT (func_decl)));
12223 /* Add source coordinate attributes for the given decl. */
12226 add_src_coords_attributes (dw_die_ref die, tree decl)
12228 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12230 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12231 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12234 /* Add a DW_AT_name attribute and source coordinate attribute for the
12235 given decl, but only if it actually has a name. */
12238 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12242 decl_name = DECL_NAME (decl);
12243 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12245 add_name_attribute (die, dwarf2_name (decl, 0));
12246 if (! DECL_ARTIFICIAL (decl))
12247 add_src_coords_attributes (die, decl);
12249 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12250 && TREE_PUBLIC (decl)
12251 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12252 && !DECL_ABSTRACT (decl)
12253 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12255 add_AT_string (die, DW_AT_MIPS_linkage_name,
12256 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12259 #ifdef VMS_DEBUGGING_INFO
12260 /* Get the function's name, as described by its RTL. This may be different
12261 from the DECL_NAME name used in the source file. */
12262 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12264 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12265 XEXP (DECL_RTL (decl), 0));
12266 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12271 /* Push a new declaration scope. */
12274 push_decl_scope (tree scope)
12276 VEC_safe_push (tree, gc, decl_scope_table, scope);
12279 /* Pop a declaration scope. */
12282 pop_decl_scope (void)
12284 VEC_pop (tree, decl_scope_table);
12287 /* Return the DIE for the scope that immediately contains this type.
12288 Non-named types get global scope. Named types nested in other
12289 types get their containing scope if it's open, or global scope
12290 otherwise. All other types (i.e. function-local named types) get
12291 the current active scope. */
12294 scope_die_for (tree t, dw_die_ref context_die)
12296 dw_die_ref scope_die = NULL;
12297 tree containing_scope;
12300 /* Non-types always go in the current scope. */
12301 gcc_assert (TYPE_P (t));
12303 containing_scope = TYPE_CONTEXT (t);
12305 /* Use the containing namespace if it was passed in (for a declaration). */
12306 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12308 if (context_die == lookup_decl_die (containing_scope))
12311 containing_scope = NULL_TREE;
12314 /* Ignore function type "scopes" from the C frontend. They mean that
12315 a tagged type is local to a parmlist of a function declarator, but
12316 that isn't useful to DWARF. */
12317 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12318 containing_scope = NULL_TREE;
12320 if (containing_scope == NULL_TREE)
12321 scope_die = comp_unit_die;
12322 else if (TYPE_P (containing_scope))
12324 /* For types, we can just look up the appropriate DIE. But
12325 first we check to see if we're in the middle of emitting it
12326 so we know where the new DIE should go. */
12327 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12328 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12333 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12334 || TREE_ASM_WRITTEN (containing_scope));
12336 /* If none of the current dies are suitable, we get file scope. */
12337 scope_die = comp_unit_die;
12340 scope_die = lookup_type_die (containing_scope);
12343 scope_die = context_die;
12348 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12351 local_scope_p (dw_die_ref context_die)
12353 for (; context_die; context_die = context_die->die_parent)
12354 if (context_die->die_tag == DW_TAG_inlined_subroutine
12355 || context_die->die_tag == DW_TAG_subprogram)
12361 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12362 whether or not to treat a DIE in this context as a declaration. */
12365 class_or_namespace_scope_p (dw_die_ref context_die)
12367 return (context_die
12368 && (context_die->die_tag == DW_TAG_structure_type
12369 || context_die->die_tag == DW_TAG_class_type
12370 || context_die->die_tag == DW_TAG_interface_type
12371 || context_die->die_tag == DW_TAG_union_type
12372 || context_die->die_tag == DW_TAG_namespace));
12375 /* Many forms of DIEs require a "type description" attribute. This
12376 routine locates the proper "type descriptor" die for the type given
12377 by 'type', and adds a DW_AT_type attribute below the given die. */
12380 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12381 int decl_volatile, dw_die_ref context_die)
12383 enum tree_code code = TREE_CODE (type);
12384 dw_die_ref type_die = NULL;
12386 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12387 or fixed-point type, use the inner type. This is because we have no
12388 support for unnamed types in base_type_die. This can happen if this is
12389 an Ada subrange type. Correct solution is emit a subrange type die. */
12390 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12391 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12392 type = TREE_TYPE (type), code = TREE_CODE (type);
12394 if (code == ERROR_MARK
12395 /* Handle a special case. For functions whose return type is void, we
12396 generate *no* type attribute. (Note that no object may have type
12397 `void', so this only applies to function return types). */
12398 || code == VOID_TYPE)
12401 type_die = modified_type_die (type,
12402 decl_const || TYPE_READONLY (type),
12403 decl_volatile || TYPE_VOLATILE (type),
12406 if (type_die != NULL)
12407 add_AT_die_ref (object_die, DW_AT_type, type_die);
12410 /* Given an object die, add the calling convention attribute for the
12411 function call type. */
12413 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12415 enum dwarf_calling_convention value = DW_CC_normal;
12417 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12419 /* DWARF doesn't provide a way to identify a program's source-level
12420 entry point. DW_AT_calling_convention attributes are only meant
12421 to describe functions' calling conventions. However, lacking a
12422 better way to signal the Fortran main program, we use this for the
12423 time being, following existing custom. */
12425 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12426 value = DW_CC_program;
12428 /* Only add the attribute if the backend requests it, and
12429 is not DW_CC_normal. */
12430 if (value && (value != DW_CC_normal))
12431 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12434 /* Given a tree pointer to a struct, class, union, or enum type node, return
12435 a pointer to the (string) tag name for the given type, or zero if the type
12436 was declared without a tag. */
12438 static const char *
12439 type_tag (const_tree type)
12441 const char *name = 0;
12443 if (TYPE_NAME (type) != 0)
12447 /* Find the IDENTIFIER_NODE for the type name. */
12448 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12449 t = TYPE_NAME (type);
12451 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12452 a TYPE_DECL node, regardless of whether or not a `typedef' was
12454 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12455 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12457 /* We want to be extra verbose. Don't call dwarf_name if
12458 DECL_NAME isn't set. The default hook for decl_printable_name
12459 doesn't like that, and in this context it's correct to return
12460 0, instead of "<anonymous>" or the like. */
12461 if (DECL_NAME (TYPE_NAME (type)))
12462 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12465 /* Now get the name as a string, or invent one. */
12466 if (!name && t != 0)
12467 name = IDENTIFIER_POINTER (t);
12470 return (name == 0 || *name == '\0') ? 0 : name;
12473 /* Return the type associated with a data member, make a special check
12474 for bit field types. */
12477 member_declared_type (const_tree member)
12479 return (DECL_BIT_FIELD_TYPE (member)
12480 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12483 /* Get the decl's label, as described by its RTL. This may be different
12484 from the DECL_NAME name used in the source file. */
12487 static const char *
12488 decl_start_label (tree decl)
12491 const char *fnname;
12493 x = DECL_RTL (decl);
12494 gcc_assert (MEM_P (x));
12497 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12499 fnname = XSTR (x, 0);
12504 /* These routines generate the internal representation of the DIE's for
12505 the compilation unit. Debugging information is collected by walking
12506 the declaration trees passed in from dwarf2out_decl(). */
12509 gen_array_type_die (tree type, dw_die_ref context_die)
12511 dw_die_ref scope_die = scope_die_for (type, context_die);
12512 dw_die_ref array_die;
12514 /* GNU compilers represent multidimensional array types as sequences of one
12515 dimensional array types whose element types are themselves array types.
12516 We sometimes squish that down to a single array_type DIE with multiple
12517 subscripts in the Dwarf debugging info. The draft Dwarf specification
12518 say that we are allowed to do this kind of compression in C, because
12519 there is no difference between an array of arrays and a multidimensional
12520 array. We don't do this for Ada to remain as close as possible to the
12521 actual representation, which is especially important against the language
12522 flexibilty wrt arrays of variable size. */
12524 bool collapse_nested_arrays = !is_ada ();
12527 /* ??? The SGI dwarf reader fails for array of array of enum types
12528 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12529 array type comes before the outer array type. We thus call gen_type_die
12530 before we new_die and must prevent nested array types collapsing for this
12533 #ifdef MIPS_DEBUGGING_INFO
12534 gen_type_die (TREE_TYPE (type), context_die);
12535 collapse_nested_arrays = false;
12538 array_die = new_die (DW_TAG_array_type, scope_die, type);
12539 add_name_attribute (array_die, type_tag (type));
12540 equate_type_number_to_die (type, array_die);
12542 if (TREE_CODE (type) == VECTOR_TYPE)
12544 /* The frontend feeds us a representation for the vector as a struct
12545 containing an array. Pull out the array type. */
12546 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12547 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12550 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12552 && TREE_CODE (type) == ARRAY_TYPE
12553 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
12554 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12557 /* We default the array ordering. SDB will probably do
12558 the right things even if DW_AT_ordering is not present. It's not even
12559 an issue until we start to get into multidimensional arrays anyway. If
12560 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12561 then we'll have to put the DW_AT_ordering attribute back in. (But if
12562 and when we find out that we need to put these in, we will only do so
12563 for multidimensional arrays. */
12564 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
12567 #ifdef MIPS_DEBUGGING_INFO
12568 /* The SGI compilers handle arrays of unknown bound by setting
12569 AT_declaration and not emitting any subrange DIEs. */
12570 if (! TYPE_DOMAIN (type))
12571 add_AT_flag (array_die, DW_AT_declaration, 1);
12574 add_subscript_info (array_die, type, collapse_nested_arrays);
12576 /* Add representation of the type of the elements of this array type and
12577 emit the corresponding DIE if we haven't done it already. */
12578 element_type = TREE_TYPE (type);
12579 if (collapse_nested_arrays)
12580 while (TREE_CODE (element_type) == ARRAY_TYPE)
12581 element_type = TREE_TYPE (element_type);
12583 #ifndef MIPS_DEBUGGING_INFO
12584 gen_type_die (element_type, context_die);
12587 add_type_attribute (array_die, element_type, 0, 0, context_die);
12589 if (get_AT (array_die, DW_AT_name))
12590 add_pubtype (type, array_die);
12593 static dw_loc_descr_ref
12594 descr_info_loc (tree val, tree base_decl)
12596 HOST_WIDE_INT size;
12597 dw_loc_descr_ref loc, loc2;
12598 enum dwarf_location_atom op;
12600 if (val == base_decl)
12601 return new_loc_descr (DW_OP_push_object_address, 0, 0);
12603 switch (TREE_CODE (val))
12606 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12608 if (host_integerp (val, 0))
12609 return int_loc_descriptor (tree_low_cst (val, 0));
12612 size = int_size_in_bytes (TREE_TYPE (val));
12615 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12618 if (size == DWARF2_ADDR_SIZE)
12619 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
12621 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
12623 case POINTER_PLUS_EXPR:
12625 if (host_integerp (TREE_OPERAND (val, 1), 1)
12626 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
12629 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12632 add_loc_descr (&loc,
12633 new_loc_descr (DW_OP_plus_uconst,
12634 tree_low_cst (TREE_OPERAND (val, 1),
12641 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12644 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
12647 add_loc_descr (&loc, loc2);
12648 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
12670 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
12671 tree val, tree base_decl)
12673 dw_loc_descr_ref loc;
12675 if (host_integerp (val, 0))
12677 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
12681 loc = descr_info_loc (val, base_decl);
12685 add_AT_loc (die, attr, loc);
12688 /* This routine generates DIE for array with hidden descriptor, details
12689 are filled into *info by a langhook. */
12692 gen_descr_array_type_die (tree type, struct array_descr_info *info,
12693 dw_die_ref context_die)
12695 dw_die_ref scope_die = scope_die_for (type, context_die);
12696 dw_die_ref array_die;
12699 array_die = new_die (DW_TAG_array_type, scope_die, type);
12700 add_name_attribute (array_die, type_tag (type));
12701 equate_type_number_to_die (type, array_die);
12703 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12705 && info->ndimensions >= 2)
12706 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12708 if (info->data_location)
12709 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
12711 if (info->associated)
12712 add_descr_info_field (array_die, DW_AT_associated, info->associated,
12714 if (info->allocated)
12715 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
12718 for (dim = 0; dim < info->ndimensions; dim++)
12720 dw_die_ref subrange_die
12721 = new_die (DW_TAG_subrange_type, array_die, NULL);
12723 if (info->dimen[dim].lower_bound)
12725 /* If it is the default value, omit it. */
12726 if ((is_c_family () || is_java ())
12727 && integer_zerop (info->dimen[dim].lower_bound))
12729 else if (is_fortran ()
12730 && integer_onep (info->dimen[dim].lower_bound))
12733 add_descr_info_field (subrange_die, DW_AT_lower_bound,
12734 info->dimen[dim].lower_bound,
12737 if (info->dimen[dim].upper_bound)
12738 add_descr_info_field (subrange_die, DW_AT_upper_bound,
12739 info->dimen[dim].upper_bound,
12741 if (info->dimen[dim].stride)
12742 add_descr_info_field (subrange_die, DW_AT_byte_stride,
12743 info->dimen[dim].stride,
12747 gen_type_die (info->element_type, context_die);
12748 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
12750 if (get_AT (array_die, DW_AT_name))
12751 add_pubtype (type, array_die);
12756 gen_entry_point_die (tree decl, dw_die_ref context_die)
12758 tree origin = decl_ultimate_origin (decl);
12759 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
12761 if (origin != NULL)
12762 add_abstract_origin_attribute (decl_die, origin);
12765 add_name_and_src_coords_attributes (decl_die, decl);
12766 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
12767 0, 0, context_die);
12770 if (DECL_ABSTRACT (decl))
12771 equate_decl_number_to_die (decl, decl_die);
12773 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12777 /* Walk through the list of incomplete types again, trying once more to
12778 emit full debugging info for them. */
12781 retry_incomplete_types (void)
12785 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12786 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12789 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12792 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12794 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12796 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12797 be incomplete and such types are not marked. */
12798 add_abstract_origin_attribute (type_die, type);
12801 /* Determine what tag to use for a record type. */
12803 static enum dwarf_tag
12804 record_type_tag (tree type)
12806 if (! lang_hooks.types.classify_record)
12807 return DW_TAG_structure_type;
12809 switch (lang_hooks.types.classify_record (type))
12811 case RECORD_IS_STRUCT:
12812 return DW_TAG_structure_type;
12814 case RECORD_IS_CLASS:
12815 return DW_TAG_class_type;
12817 case RECORD_IS_INTERFACE:
12818 return DW_TAG_interface_type;
12821 gcc_unreachable ();
12825 /* Generate a DIE to represent an inlined instance of a structure type. */
12828 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12830 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12832 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12833 be incomplete and such types are not marked. */
12834 add_abstract_origin_attribute (type_die, type);
12837 /* Generate a DIE to represent an inlined instance of a union type. */
12840 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12842 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12844 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12845 be incomplete and such types are not marked. */
12846 add_abstract_origin_attribute (type_die, type);
12849 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12850 include all of the information about the enumeration values also. Each
12851 enumerated type name/value is listed as a child of the enumerated type
12855 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12857 dw_die_ref type_die = lookup_type_die (type);
12859 if (type_die == NULL)
12861 type_die = new_die (DW_TAG_enumeration_type,
12862 scope_die_for (type, context_die), type);
12863 equate_type_number_to_die (type, type_die);
12864 add_name_attribute (type_die, type_tag (type));
12866 else if (! TYPE_SIZE (type))
12869 remove_AT (type_die, DW_AT_declaration);
12871 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12872 given enum type is incomplete, do not generate the DW_AT_byte_size
12873 attribute or the DW_AT_element_list attribute. */
12874 if (TYPE_SIZE (type))
12878 TREE_ASM_WRITTEN (type) = 1;
12879 add_byte_size_attribute (type_die, type);
12880 if (TYPE_STUB_DECL (type) != NULL_TREE)
12881 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12883 /* If the first reference to this type was as the return type of an
12884 inline function, then it may not have a parent. Fix this now. */
12885 if (type_die->die_parent == NULL)
12886 add_child_die (scope_die_for (type, context_die), type_die);
12888 for (link = TYPE_VALUES (type);
12889 link != NULL; link = TREE_CHAIN (link))
12891 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12892 tree value = TREE_VALUE (link);
12894 add_name_attribute (enum_die,
12895 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12897 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12898 /* DWARF2 does not provide a way of indicating whether or
12899 not enumeration constants are signed or unsigned. GDB
12900 always assumes the values are signed, so we output all
12901 values as if they were signed. That means that
12902 enumeration constants with very large unsigned values
12903 will appear to have negative values in the debugger. */
12904 add_AT_int (enum_die, DW_AT_const_value,
12905 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12909 add_AT_flag (type_die, DW_AT_declaration, 1);
12911 if (get_AT (type_die, DW_AT_name))
12912 add_pubtype (type, type_die);
12917 /* Generate a DIE to represent either a real live formal parameter decl or to
12918 represent just the type of some formal parameter position in some function
12921 Note that this routine is a bit unusual because its argument may be a
12922 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12923 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12924 node. If it's the former then this function is being called to output a
12925 DIE to represent a formal parameter object (or some inlining thereof). If
12926 it's the latter, then this function is only being called to output a
12927 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12928 argument type of some subprogram type. */
12931 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12933 dw_die_ref parm_die
12934 = new_die (DW_TAG_formal_parameter, context_die, node);
12937 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12939 case tcc_declaration:
12940 origin = decl_ultimate_origin (node);
12941 if (origin != NULL)
12942 add_abstract_origin_attribute (parm_die, origin);
12945 tree type = TREE_TYPE (node);
12946 add_name_and_src_coords_attributes (parm_die, node);
12947 if (DECL_BY_REFERENCE (node))
12948 type = TREE_TYPE (type);
12949 add_type_attribute (parm_die, type,
12950 TREE_READONLY (node),
12951 TREE_THIS_VOLATILE (node),
12953 if (DECL_ARTIFICIAL (node))
12954 add_AT_flag (parm_die, DW_AT_artificial, 1);
12957 equate_decl_number_to_die (node, parm_die);
12958 if (! DECL_ABSTRACT (node))
12959 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12964 /* We were called with some kind of a ..._TYPE node. */
12965 add_type_attribute (parm_die, node, 0, 0, context_die);
12969 gcc_unreachable ();
12975 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12976 at the end of an (ANSI prototyped) formal parameters list. */
12979 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12981 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12984 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12985 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12986 parameters as specified in some function type specification (except for
12987 those which appear as part of a function *definition*). */
12990 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12993 tree formal_type = NULL;
12994 tree first_parm_type;
12997 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12999 arg = DECL_ARGUMENTS (function_or_method_type);
13000 function_or_method_type = TREE_TYPE (function_or_method_type);
13005 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13007 /* Make our first pass over the list of formal parameter types and output a
13008 DW_TAG_formal_parameter DIE for each one. */
13009 for (link = first_parm_type; link; )
13011 dw_die_ref parm_die;
13013 formal_type = TREE_VALUE (link);
13014 if (formal_type == void_type_node)
13017 /* Output a (nameless) DIE to represent the formal parameter itself. */
13018 parm_die = gen_formal_parameter_die (formal_type, context_die);
13019 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13020 && link == first_parm_type)
13021 || (arg && DECL_ARTIFICIAL (arg)))
13022 add_AT_flag (parm_die, DW_AT_artificial, 1);
13024 link = TREE_CHAIN (link);
13026 arg = TREE_CHAIN (arg);
13029 /* If this function type has an ellipsis, add a
13030 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13031 if (formal_type != void_type_node)
13032 gen_unspecified_parameters_die (function_or_method_type, context_die);
13034 /* Make our second (and final) pass over the list of formal parameter types
13035 and output DIEs to represent those types (as necessary). */
13036 for (link = TYPE_ARG_TYPES (function_or_method_type);
13037 link && TREE_VALUE (link);
13038 link = TREE_CHAIN (link))
13039 gen_type_die (TREE_VALUE (link), context_die);
13042 /* We want to generate the DIE for TYPE so that we can generate the
13043 die for MEMBER, which has been defined; we will need to refer back
13044 to the member declaration nested within TYPE. If we're trying to
13045 generate minimal debug info for TYPE, processing TYPE won't do the
13046 trick; we need to attach the member declaration by hand. */
13049 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13051 gen_type_die (type, context_die);
13053 /* If we're trying to avoid duplicate debug info, we may not have
13054 emitted the member decl for this function. Emit it now. */
13055 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13056 && ! lookup_decl_die (member))
13058 dw_die_ref type_die;
13059 gcc_assert (!decl_ultimate_origin (member));
13061 push_decl_scope (type);
13062 type_die = lookup_type_die (type);
13063 if (TREE_CODE (member) == FUNCTION_DECL)
13064 gen_subprogram_die (member, type_die);
13065 else if (TREE_CODE (member) == FIELD_DECL)
13067 /* Ignore the nameless fields that are used to skip bits but handle
13068 C++ anonymous unions and structs. */
13069 if (DECL_NAME (member) != NULL_TREE
13070 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13071 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13073 gen_type_die (member_declared_type (member), type_die);
13074 gen_field_die (member, type_die);
13078 gen_variable_die (member, type_die);
13084 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13085 may later generate inlined and/or out-of-line instances of. */
13088 dwarf2out_abstract_function (tree decl)
13090 dw_die_ref old_die;
13093 int was_abstract = DECL_ABSTRACT (decl);
13095 /* Make sure we have the actual abstract inline, not a clone. */
13096 decl = DECL_ORIGIN (decl);
13098 old_die = lookup_decl_die (decl);
13099 if (old_die && get_AT (old_die, DW_AT_inline))
13100 /* We've already generated the abstract instance. */
13103 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13104 we don't get confused by DECL_ABSTRACT. */
13105 if (debug_info_level > DINFO_LEVEL_TERSE)
13107 context = decl_class_context (decl);
13109 gen_type_die_for_member
13110 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13113 /* Pretend we've just finished compiling this function. */
13114 save_fn = current_function_decl;
13115 current_function_decl = decl;
13116 push_cfun (DECL_STRUCT_FUNCTION (decl));
13118 set_decl_abstract_flags (decl, 1);
13119 dwarf2out_decl (decl);
13120 if (! was_abstract)
13121 set_decl_abstract_flags (decl, 0);
13123 current_function_decl = save_fn;
13127 /* Helper function of premark_used_types() which gets called through
13128 htab_traverse_resize().
13130 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13131 marked as unused by prune_unused_types. */
13133 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13138 type = (tree) *slot;
13139 die = lookup_type_die (type);
13141 die->die_perennial_p = 1;
13145 /* Mark all members of used_types_hash as perennial. */
13147 premark_used_types (void)
13149 if (cfun && cfun->used_types_hash)
13150 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13153 /* Generate a DIE to represent a declared function (either file-scope or
13157 gen_subprogram_die (tree decl, dw_die_ref context_die)
13159 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13160 tree origin = decl_ultimate_origin (decl);
13161 dw_die_ref subr_die;
13164 dw_die_ref old_die = lookup_decl_die (decl);
13165 int declaration = (current_function_decl != decl
13166 || class_or_namespace_scope_p (context_die));
13168 premark_used_types ();
13170 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13171 started to generate the abstract instance of an inline, decided to output
13172 its containing class, and proceeded to emit the declaration of the inline
13173 from the member list for the class. If so, DECLARATION takes priority;
13174 we'll get back to the abstract instance when done with the class. */
13176 /* The class-scope declaration DIE must be the primary DIE. */
13177 if (origin && declaration && class_or_namespace_scope_p (context_die))
13180 gcc_assert (!old_die);
13183 /* Now that the C++ front end lazily declares artificial member fns, we
13184 might need to retrofit the declaration into its class. */
13185 if (!declaration && !origin && !old_die
13186 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13187 && !class_or_namespace_scope_p (context_die)
13188 && debug_info_level > DINFO_LEVEL_TERSE)
13189 old_die = force_decl_die (decl);
13191 if (origin != NULL)
13193 gcc_assert (!declaration || local_scope_p (context_die));
13195 /* Fixup die_parent for the abstract instance of a nested
13196 inline function. */
13197 if (old_die && old_die->die_parent == NULL)
13198 add_child_die (context_die, old_die);
13200 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13201 add_abstract_origin_attribute (subr_die, origin);
13205 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13206 struct dwarf_file_data * file_index = lookup_filename (s.file);
13208 if (!get_AT_flag (old_die, DW_AT_declaration)
13209 /* We can have a normal definition following an inline one in the
13210 case of redefinition of GNU C extern inlines.
13211 It seems reasonable to use AT_specification in this case. */
13212 && !get_AT (old_die, DW_AT_inline))
13214 /* Detect and ignore this case, where we are trying to output
13215 something we have already output. */
13219 /* If the definition comes from the same place as the declaration,
13220 maybe use the old DIE. We always want the DIE for this function
13221 that has the *_pc attributes to be under comp_unit_die so the
13222 debugger can find it. We also need to do this for abstract
13223 instances of inlines, since the spec requires the out-of-line copy
13224 to have the same parent. For local class methods, this doesn't
13225 apply; we just use the old DIE. */
13226 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13227 && (DECL_ARTIFICIAL (decl)
13228 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13229 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13230 == (unsigned) s.line))))
13232 subr_die = old_die;
13234 /* Clear out the declaration attribute and the formal parameters.
13235 Do not remove all children, because it is possible that this
13236 declaration die was forced using force_decl_die(). In such
13237 cases die that forced declaration die (e.g. TAG_imported_module)
13238 is one of the children that we do not want to remove. */
13239 remove_AT (subr_die, DW_AT_declaration);
13240 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13244 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13245 add_AT_specification (subr_die, old_die);
13246 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13247 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13248 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13249 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13254 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13256 if (TREE_PUBLIC (decl))
13257 add_AT_flag (subr_die, DW_AT_external, 1);
13259 add_name_and_src_coords_attributes (subr_die, decl);
13260 if (debug_info_level > DINFO_LEVEL_TERSE)
13262 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13263 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13264 0, 0, context_die);
13267 add_pure_or_virtual_attribute (subr_die, decl);
13268 if (DECL_ARTIFICIAL (decl))
13269 add_AT_flag (subr_die, DW_AT_artificial, 1);
13271 if (TREE_PROTECTED (decl))
13272 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13273 else if (TREE_PRIVATE (decl))
13274 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13279 if (!old_die || !get_AT (old_die, DW_AT_inline))
13281 add_AT_flag (subr_die, DW_AT_declaration, 1);
13283 /* The first time we see a member function, it is in the context of
13284 the class to which it belongs. We make sure of this by emitting
13285 the class first. The next time is the definition, which is
13286 handled above. The two may come from the same source text.
13288 Note that force_decl_die() forces function declaration die. It is
13289 later reused to represent definition. */
13290 equate_decl_number_to_die (decl, subr_die);
13293 else if (DECL_ABSTRACT (decl))
13295 if (DECL_DECLARED_INLINE_P (decl))
13297 if (cgraph_function_possibly_inlined_p (decl))
13298 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13300 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13304 if (cgraph_function_possibly_inlined_p (decl))
13305 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13307 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13310 if (DECL_DECLARED_INLINE_P (decl)
13311 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13312 add_AT_flag (subr_die, DW_AT_artificial, 1);
13314 equate_decl_number_to_die (decl, subr_die);
13316 else if (!DECL_EXTERNAL (decl))
13318 HOST_WIDE_INT cfa_fb_offset;
13320 if (!old_die || !get_AT (old_die, DW_AT_inline))
13321 equate_decl_number_to_die (decl, subr_die);
13323 if (!flag_reorder_blocks_and_partition)
13325 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13326 current_function_funcdef_no);
13327 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13328 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13329 current_function_funcdef_no);
13330 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13332 add_pubname (decl, subr_die);
13333 add_arange (decl, subr_die);
13336 { /* Do nothing for now; maybe need to duplicate die, one for
13337 hot section and one for cold section, then use the hot/cold
13338 section begin/end labels to generate the aranges... */
13340 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13341 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13342 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13343 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13345 add_pubname (decl, subr_die);
13346 add_arange (decl, subr_die);
13347 add_arange (decl, subr_die);
13351 #ifdef MIPS_DEBUGGING_INFO
13352 /* Add a reference to the FDE for this routine. */
13353 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13356 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13358 /* We define the "frame base" as the function's CFA. This is more
13359 convenient for several reasons: (1) It's stable across the prologue
13360 and epilogue, which makes it better than just a frame pointer,
13361 (2) With dwarf3, there exists a one-byte encoding that allows us
13362 to reference the .debug_frame data by proxy, but failing that,
13363 (3) We can at least reuse the code inspection and interpretation
13364 code that determines the CFA position at various points in the
13366 /* ??? Use some command-line or configury switch to enable the use
13367 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13368 consumers that understand it; fall back to "pure" dwarf2 and
13369 convert the CFA data into a location list. */
13371 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13372 if (list->dw_loc_next)
13373 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13375 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13378 /* Compute a displacement from the "steady-state frame pointer" to
13379 the CFA. The former is what all stack slots and argument slots
13380 will reference in the rtl; the later is what we've told the
13381 debugger about. We'll need to adjust all frame_base references
13382 by this displacement. */
13383 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13385 if (cfun->static_chain_decl)
13386 add_AT_location_description (subr_die, DW_AT_static_link,
13387 loc_descriptor_from_tree (cfun->static_chain_decl));
13390 /* Now output descriptions of the arguments for this function. This gets
13391 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13392 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13393 `...' at the end of the formal parameter list. In order to find out if
13394 there was a trailing ellipsis or not, we must instead look at the type
13395 associated with the FUNCTION_DECL. This will be a node of type
13396 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13397 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13398 an ellipsis at the end. */
13400 /* In the case where we are describing a mere function declaration, all we
13401 need to do here (and all we *can* do here) is to describe the *types* of
13402 its formal parameters. */
13403 if (debug_info_level <= DINFO_LEVEL_TERSE)
13405 else if (declaration)
13406 gen_formal_types_die (decl, subr_die);
13409 /* Generate DIEs to represent all known formal parameters. */
13410 tree arg_decls = DECL_ARGUMENTS (decl);
13413 /* When generating DIEs, generate the unspecified_parameters DIE
13414 instead if we come across the arg "__builtin_va_alist" */
13415 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13416 if (TREE_CODE (parm) == PARM_DECL)
13418 if (DECL_NAME (parm)
13419 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13420 "__builtin_va_alist"))
13421 gen_unspecified_parameters_die (parm, subr_die);
13423 gen_decl_die (parm, subr_die);
13426 /* Decide whether we need an unspecified_parameters DIE at the end.
13427 There are 2 more cases to do this for: 1) the ansi ... declaration -
13428 this is detectable when the end of the arg list is not a
13429 void_type_node 2) an unprototyped function declaration (not a
13430 definition). This just means that we have no info about the
13431 parameters at all. */
13432 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13433 if (fn_arg_types != NULL)
13435 /* This is the prototyped case, check for.... */
13436 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13437 gen_unspecified_parameters_die (decl, subr_die);
13439 else if (DECL_INITIAL (decl) == NULL_TREE)
13440 gen_unspecified_parameters_die (decl, subr_die);
13443 /* Output Dwarf info for all of the stuff within the body of the function
13444 (if it has one - it may be just a declaration). */
13445 outer_scope = DECL_INITIAL (decl);
13447 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13448 a function. This BLOCK actually represents the outermost binding contour
13449 for the function, i.e. the contour in which the function's formal
13450 parameters and labels get declared. Curiously, it appears that the front
13451 end doesn't actually put the PARM_DECL nodes for the current function onto
13452 the BLOCK_VARS list for this outer scope, but are strung off of the
13453 DECL_ARGUMENTS list for the function instead.
13455 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13456 the LABEL_DECL nodes for the function however, and we output DWARF info
13457 for those in decls_for_scope. Just within the `outer_scope' there will be
13458 a BLOCK node representing the function's outermost pair of curly braces,
13459 and any blocks used for the base and member initializers of a C++
13460 constructor function. */
13461 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13463 /* Emit a DW_TAG_variable DIE for a named return value. */
13464 if (DECL_NAME (DECL_RESULT (decl)))
13465 gen_decl_die (DECL_RESULT (decl), subr_die);
13467 current_function_has_inlines = 0;
13468 decls_for_scope (outer_scope, subr_die, 0);
13470 #if 0 && defined (MIPS_DEBUGGING_INFO)
13471 if (current_function_has_inlines)
13473 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13474 if (! comp_unit_has_inlines)
13476 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13477 comp_unit_has_inlines = 1;
13482 /* Add the calling convention attribute if requested. */
13483 add_calling_convention_attribute (subr_die, decl);
13487 /* Generate a DIE to represent a declared data object. */
13490 gen_variable_die (tree decl, dw_die_ref context_die)
13494 dw_die_ref var_die;
13495 tree origin = decl_ultimate_origin (decl);
13496 dw_die_ref old_die = lookup_decl_die (decl);
13497 int declaration = (DECL_EXTERNAL (decl)
13498 /* If DECL is COMDAT and has not actually been
13499 emitted, we cannot take its address; there
13500 might end up being no definition anywhere in
13501 the program. For example, consider the C++
13505 struct S { static const int i = 7; };
13510 int f() { return S<int>::i; }
13512 Here, S<int>::i is not DECL_EXTERNAL, but no
13513 definition is required, so the compiler will
13514 not emit a definition. */
13515 || (TREE_CODE (decl) == VAR_DECL
13516 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
13517 || class_or_namespace_scope_p (context_die));
13519 com_decl = fortran_common (decl, &off);
13521 /* Symbol in common gets emitted as a child of the common block, in the form
13524 ??? This creates a new common block die for every common block symbol.
13525 Better to share same common block die for all symbols in that block. */
13529 dw_die_ref com_die;
13530 const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
13531 dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl);
13533 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
13534 var_die = new_die (DW_TAG_common_block, context_die, decl);
13535 add_name_and_src_coords_attributes (var_die, field);
13536 add_AT_flag (var_die, DW_AT_external, 1);
13537 add_AT_loc (var_die, DW_AT_location, loc);
13538 com_die = new_die (DW_TAG_member, var_die, decl);
13539 add_name_and_src_coords_attributes (com_die, decl);
13540 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
13541 TREE_THIS_VOLATILE (decl), context_die);
13542 add_AT_loc (com_die, DW_AT_data_member_location,
13543 int_loc_descriptor (off));
13544 add_pubname_string (cnam, var_die); /* ??? needed? */
13548 var_die = new_die (DW_TAG_variable, context_die, decl);
13550 if (origin != NULL)
13551 add_abstract_origin_attribute (var_die, origin);
13553 /* Loop unrolling can create multiple blocks that refer to the same
13554 static variable, so we must test for the DW_AT_declaration flag.
13556 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13557 copy decls and set the DECL_ABSTRACT flag on them instead of
13560 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13562 ??? The declare_in_namespace support causes us to get two DIEs for one
13563 variable, both of which are declarations. We want to avoid considering
13564 one to be a specification, so we must test that this DIE is not a
13566 else if (old_die && TREE_STATIC (decl) && ! declaration
13567 && get_AT_flag (old_die, DW_AT_declaration) == 1)
13569 /* This is a definition of a C++ class level static. */
13570 add_AT_specification (var_die, old_die);
13571 if (DECL_NAME (decl))
13573 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13574 struct dwarf_file_data * file_index = lookup_filename (s.file);
13576 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13577 add_AT_file (var_die, DW_AT_decl_file, file_index);
13579 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13580 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
13585 tree type = TREE_TYPE (decl);
13586 if ((TREE_CODE (decl) == PARM_DECL
13587 || TREE_CODE (decl) == RESULT_DECL)
13588 && DECL_BY_REFERENCE (decl))
13589 type = TREE_TYPE (type);
13591 add_name_and_src_coords_attributes (var_die, decl);
13592 add_type_attribute (var_die, type, TREE_READONLY (decl),
13593 TREE_THIS_VOLATILE (decl), context_die);
13595 if (TREE_PUBLIC (decl))
13596 add_AT_flag (var_die, DW_AT_external, 1);
13598 if (DECL_ARTIFICIAL (decl))
13599 add_AT_flag (var_die, DW_AT_artificial, 1);
13601 if (TREE_PROTECTED (decl))
13602 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
13603 else if (TREE_PRIVATE (decl))
13604 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
13608 add_AT_flag (var_die, DW_AT_declaration, 1);
13610 if (DECL_ABSTRACT (decl) || declaration)
13611 equate_decl_number_to_die (decl, var_die);
13613 if (! declaration && ! DECL_ABSTRACT (decl))
13615 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
13616 add_pubname (decl, var_die);
13619 tree_add_const_value_attribute (var_die, decl);
13622 /* Generate a DIE to represent a label identifier. */
13625 gen_label_die (tree decl, dw_die_ref context_die)
13627 tree origin = decl_ultimate_origin (decl);
13628 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
13630 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13632 if (origin != NULL)
13633 add_abstract_origin_attribute (lbl_die, origin);
13635 add_name_and_src_coords_attributes (lbl_die, decl);
13637 if (DECL_ABSTRACT (decl))
13638 equate_decl_number_to_die (decl, lbl_die);
13641 insn = DECL_RTL_IF_SET (decl);
13643 /* Deleted labels are programmer specified labels which have been
13644 eliminated because of various optimizations. We still emit them
13645 here so that it is possible to put breakpoints on them. */
13649 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
13651 /* When optimization is enabled (via -O) some parts of the compiler
13652 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
13653 represent source-level labels which were explicitly declared by
13654 the user. This really shouldn't be happening though, so catch
13655 it if it ever does happen. */
13656 gcc_assert (!INSN_DELETED_P (insn));
13658 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
13659 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
13664 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
13665 attributes to the DIE for a block STMT, to describe where the inlined
13666 function was called from. This is similar to add_src_coords_attributes. */
13669 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
13671 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
13673 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
13674 add_AT_unsigned (die, DW_AT_call_line, s.line);
13678 /* If STMT's abstract origin is a function declaration and STMT's
13679 first subblock's abstract origin is the function's outermost block,
13680 then we're looking at the main entry point. */
13682 is_inlined_entry_point (const_tree stmt)
13686 if (!stmt || TREE_CODE (stmt) != BLOCK)
13689 decl = block_ultimate_origin (stmt);
13691 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
13694 block = BLOCK_SUBBLOCKS (stmt);
13698 if (TREE_CODE (block) != BLOCK)
13701 block = block_ultimate_origin (block);
13704 return block == DECL_INITIAL (decl);
13707 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
13708 Add low_pc and high_pc attributes to the DIE for a block STMT. */
13711 add_high_low_attributes (tree stmt, dw_die_ref die)
13713 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13715 if (BLOCK_FRAGMENT_CHAIN (stmt))
13719 if (is_inlined_entry_point (stmt))
13721 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13722 BLOCK_NUMBER (stmt));
13723 add_AT_lbl_id (die, DW_AT_entry_pc, label);
13726 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
13728 chain = BLOCK_FRAGMENT_CHAIN (stmt);
13731 add_ranges (chain);
13732 chain = BLOCK_FRAGMENT_CHAIN (chain);
13739 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13740 BLOCK_NUMBER (stmt));
13741 add_AT_lbl_id (die, DW_AT_low_pc, label);
13742 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
13743 BLOCK_NUMBER (stmt));
13744 add_AT_lbl_id (die, DW_AT_high_pc, label);
13748 /* Generate a DIE for a lexical block. */
13751 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
13753 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
13755 if (! BLOCK_ABSTRACT (stmt))
13756 add_high_low_attributes (stmt, stmt_die);
13758 decls_for_scope (stmt, stmt_die, depth);
13761 /* Generate a DIE for an inlined subprogram. */
13764 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
13766 tree decl = block_ultimate_origin (stmt);
13768 /* Emit info for the abstract instance first, if we haven't yet. We
13769 must emit this even if the block is abstract, otherwise when we
13770 emit the block below (or elsewhere), we may end up trying to emit
13771 a die whose origin die hasn't been emitted, and crashing. */
13772 dwarf2out_abstract_function (decl);
13774 if (! BLOCK_ABSTRACT (stmt))
13776 dw_die_ref subr_die
13777 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13779 add_abstract_origin_attribute (subr_die, decl);
13780 add_high_low_attributes (stmt, subr_die);
13781 add_call_src_coords_attributes (stmt, subr_die);
13783 decls_for_scope (stmt, subr_die, depth);
13784 current_function_has_inlines = 1;
13787 /* We may get here if we're the outer block of function A that was
13788 inlined into function B that was inlined into function C. When
13789 generating debugging info for C, dwarf2out_abstract_function(B)
13790 would mark all inlined blocks as abstract, including this one.
13791 So, we wouldn't (and shouldn't) expect labels to be generated
13792 for this one. Instead, just emit debugging info for
13793 declarations within the block. This is particularly important
13794 in the case of initializers of arguments passed from B to us:
13795 if they're statement expressions containing declarations, we
13796 wouldn't generate dies for their abstract variables, and then,
13797 when generating dies for the real variables, we'd die (pun
13799 gen_lexical_block_die (stmt, context_die, depth);
13802 /* Generate a DIE for a field in a record, or structure. */
13805 gen_field_die (tree decl, dw_die_ref context_die)
13807 dw_die_ref decl_die;
13809 if (TREE_TYPE (decl) == error_mark_node)
13812 decl_die = new_die (DW_TAG_member, context_die, decl);
13813 add_name_and_src_coords_attributes (decl_die, decl);
13814 add_type_attribute (decl_die, member_declared_type (decl),
13815 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13818 if (DECL_BIT_FIELD_TYPE (decl))
13820 add_byte_size_attribute (decl_die, decl);
13821 add_bit_size_attribute (decl_die, decl);
13822 add_bit_offset_attribute (decl_die, decl);
13825 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13826 add_data_member_location_attribute (decl_die, decl);
13828 if (DECL_ARTIFICIAL (decl))
13829 add_AT_flag (decl_die, DW_AT_artificial, 1);
13831 if (TREE_PROTECTED (decl))
13832 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13833 else if (TREE_PRIVATE (decl))
13834 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13836 /* Equate decl number to die, so that we can look up this decl later on. */
13837 equate_decl_number_to_die (decl, decl_die);
13841 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13842 Use modified_type_die instead.
13843 We keep this code here just in case these types of DIEs may be needed to
13844 represent certain things in other languages (e.g. Pascal) someday. */
13847 gen_pointer_type_die (tree type, dw_die_ref context_die)
13850 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13852 equate_type_number_to_die (type, ptr_die);
13853 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13854 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13857 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13858 Use modified_type_die instead.
13859 We keep this code here just in case these types of DIEs may be needed to
13860 represent certain things in other languages (e.g. Pascal) someday. */
13863 gen_reference_type_die (tree type, dw_die_ref context_die)
13866 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13868 equate_type_number_to_die (type, ref_die);
13869 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13870 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13874 /* Generate a DIE for a pointer to a member type. */
13877 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
13880 = new_die (DW_TAG_ptr_to_member_type,
13881 scope_die_for (type, context_die), type);
13883 equate_type_number_to_die (type, ptr_die);
13884 add_AT_die_ref (ptr_die, DW_AT_containing_type,
13885 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
13886 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13889 /* Generate the DIE for the compilation unit. */
13892 gen_compile_unit_die (const char *filename)
13895 char producer[250];
13896 const char *language_string = lang_hooks.name;
13899 die = new_die (DW_TAG_compile_unit, NULL, NULL);
13903 add_name_attribute (die, filename);
13904 /* Don't add cwd for <built-in>. */
13905 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
13906 add_comp_dir_attribute (die);
13909 sprintf (producer, "%s %s", language_string, version_string);
13911 #ifdef MIPS_DEBUGGING_INFO
13912 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13913 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13914 not appear in the producer string, the debugger reaches the conclusion
13915 that the object file is stripped and has no debugging information.
13916 To get the MIPS/SGI debugger to believe that there is debugging
13917 information in the object file, we add a -g to the producer string. */
13918 if (debug_info_level > DINFO_LEVEL_TERSE)
13919 strcat (producer, " -g");
13922 add_AT_string (die, DW_AT_producer, producer);
13924 if (strcmp (language_string, "GNU C++") == 0)
13925 language = DW_LANG_C_plus_plus;
13926 else if (strcmp (language_string, "GNU Ada") == 0)
13927 language = DW_LANG_Ada95;
13928 else if (strcmp (language_string, "GNU F77") == 0)
13929 language = DW_LANG_Fortran77;
13930 else if (strcmp (language_string, "GNU Fortran") == 0)
13931 language = DW_LANG_Fortran95;
13932 else if (strcmp (language_string, "GNU Pascal") == 0)
13933 language = DW_LANG_Pascal83;
13934 else if (strcmp (language_string, "GNU Java") == 0)
13935 language = DW_LANG_Java;
13936 else if (strcmp (language_string, "GNU Objective-C") == 0)
13937 language = DW_LANG_ObjC;
13938 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13939 language = DW_LANG_ObjC_plus_plus;
13941 language = DW_LANG_C89;
13943 add_AT_unsigned (die, DW_AT_language, language);
13947 /* Generate the DIE for a base class. */
13950 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13952 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13954 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13955 add_data_member_location_attribute (die, binfo);
13957 if (BINFO_VIRTUAL_P (binfo))
13958 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13960 if (access == access_public_node)
13961 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13962 else if (access == access_protected_node)
13963 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13966 /* Generate a DIE for a class member. */
13969 gen_member_die (tree type, dw_die_ref context_die)
13972 tree binfo = TYPE_BINFO (type);
13975 /* If this is not an incomplete type, output descriptions of each of its
13976 members. Note that as we output the DIEs necessary to represent the
13977 members of this record or union type, we will also be trying to output
13978 DIEs to represent the *types* of those members. However the `type'
13979 function (above) will specifically avoid generating type DIEs for member
13980 types *within* the list of member DIEs for this (containing) type except
13981 for those types (of members) which are explicitly marked as also being
13982 members of this (containing) type themselves. The g++ front- end can
13983 force any given type to be treated as a member of some other (containing)
13984 type by setting the TYPE_CONTEXT of the given (member) type to point to
13985 the TREE node representing the appropriate (containing) type. */
13987 /* First output info about the base classes. */
13990 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13994 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13995 gen_inheritance_die (base,
13996 (accesses ? VEC_index (tree, accesses, i)
13997 : access_public_node), context_die);
14000 /* Now output info about the data members and type members. */
14001 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14003 /* If we thought we were generating minimal debug info for TYPE
14004 and then changed our minds, some of the member declarations
14005 may have already been defined. Don't define them again, but
14006 do put them in the right order. */
14008 child = lookup_decl_die (member);
14010 splice_child_die (context_die, child);
14012 gen_decl_die (member, context_die);
14015 /* Now output info about the function members (if any). */
14016 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14018 /* Don't include clones in the member list. */
14019 if (DECL_ABSTRACT_ORIGIN (member))
14022 child = lookup_decl_die (member);
14024 splice_child_die (context_die, child);
14026 gen_decl_die (member, context_die);
14030 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14031 is set, we pretend that the type was never defined, so we only get the
14032 member DIEs needed by later specification DIEs. */
14035 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14036 enum debug_info_usage usage)
14038 dw_die_ref type_die = lookup_type_die (type);
14039 dw_die_ref scope_die = 0;
14041 int complete = (TYPE_SIZE (type)
14042 && (! TYPE_STUB_DECL (type)
14043 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14044 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14045 complete = complete && should_emit_struct_debug (type, usage);
14047 if (type_die && ! complete)
14050 if (TYPE_CONTEXT (type) != NULL_TREE
14051 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14052 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14055 scope_die = scope_die_for (type, context_die);
14057 if (! type_die || (nested && scope_die == comp_unit_die))
14058 /* First occurrence of type or toplevel definition of nested class. */
14060 dw_die_ref old_die = type_die;
14062 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14063 ? record_type_tag (type) : DW_TAG_union_type,
14065 equate_type_number_to_die (type, type_die);
14067 add_AT_specification (type_die, old_die);
14069 add_name_attribute (type_die, type_tag (type));
14072 remove_AT (type_die, DW_AT_declaration);
14074 /* If this type has been completed, then give it a byte_size attribute and
14075 then give a list of members. */
14076 if (complete && !ns_decl)
14078 /* Prevent infinite recursion in cases where the type of some member of
14079 this type is expressed in terms of this type itself. */
14080 TREE_ASM_WRITTEN (type) = 1;
14081 add_byte_size_attribute (type_die, type);
14082 if (TYPE_STUB_DECL (type) != NULL_TREE)
14083 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14085 /* If the first reference to this type was as the return type of an
14086 inline function, then it may not have a parent. Fix this now. */
14087 if (type_die->die_parent == NULL)
14088 add_child_die (scope_die, type_die);
14090 push_decl_scope (type);
14091 gen_member_die (type, type_die);
14094 /* GNU extension: Record what type our vtable lives in. */
14095 if (TYPE_VFIELD (type))
14097 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14099 gen_type_die (vtype, context_die);
14100 add_AT_die_ref (type_die, DW_AT_containing_type,
14101 lookup_type_die (vtype));
14106 add_AT_flag (type_die, DW_AT_declaration, 1);
14108 /* We don't need to do this for function-local types. */
14109 if (TYPE_STUB_DECL (type)
14110 && ! decl_function_context (TYPE_STUB_DECL (type)))
14111 VEC_safe_push (tree, gc, incomplete_types, type);
14114 if (get_AT (type_die, DW_AT_name))
14115 add_pubtype (type, type_die);
14118 /* Generate a DIE for a subroutine _type_. */
14121 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14123 tree return_type = TREE_TYPE (type);
14124 dw_die_ref subr_die
14125 = new_die (DW_TAG_subroutine_type,
14126 scope_die_for (type, context_die), type);
14128 equate_type_number_to_die (type, subr_die);
14129 add_prototyped_attribute (subr_die, type);
14130 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14131 gen_formal_types_die (type, subr_die);
14133 if (get_AT (subr_die, DW_AT_name))
14134 add_pubtype (type, subr_die);
14137 /* Generate a DIE for a type definition. */
14140 gen_typedef_die (tree decl, dw_die_ref context_die)
14142 dw_die_ref type_die;
14145 if (TREE_ASM_WRITTEN (decl))
14148 TREE_ASM_WRITTEN (decl) = 1;
14149 type_die = new_die (DW_TAG_typedef, context_die, decl);
14150 origin = decl_ultimate_origin (decl);
14151 if (origin != NULL)
14152 add_abstract_origin_attribute (type_die, origin);
14157 add_name_and_src_coords_attributes (type_die, decl);
14158 if (DECL_ORIGINAL_TYPE (decl))
14160 type = DECL_ORIGINAL_TYPE (decl);
14162 gcc_assert (type != TREE_TYPE (decl));
14163 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14166 type = TREE_TYPE (decl);
14168 add_type_attribute (type_die, type, TREE_READONLY (decl),
14169 TREE_THIS_VOLATILE (decl), context_die);
14172 if (DECL_ABSTRACT (decl))
14173 equate_decl_number_to_die (decl, type_die);
14175 if (get_AT (type_die, DW_AT_name))
14176 add_pubtype (decl, type_die);
14179 /* Generate a type description DIE. */
14182 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14183 enum debug_info_usage usage)
14186 struct array_descr_info info;
14188 if (type == NULL_TREE || type == error_mark_node)
14191 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14192 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14194 if (TREE_ASM_WRITTEN (type))
14197 /* Prevent broken recursion; we can't hand off to the same type. */
14198 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14200 TREE_ASM_WRITTEN (type) = 1;
14201 gen_decl_die (TYPE_NAME (type), context_die);
14205 /* If this is an array type with hidden descriptor, handle it first. */
14206 if (!TREE_ASM_WRITTEN (type)
14207 && lang_hooks.types.get_array_descr_info
14208 && lang_hooks.types.get_array_descr_info (type, &info))
14210 gen_descr_array_type_die (type, &info, context_die);
14211 TREE_ASM_WRITTEN (type) = 1;
14215 /* We are going to output a DIE to represent the unqualified version
14216 of this type (i.e. without any const or volatile qualifiers) so
14217 get the main variant (i.e. the unqualified version) of this type
14218 now. (Vectors are special because the debugging info is in the
14219 cloned type itself). */
14220 if (TREE_CODE (type) != VECTOR_TYPE)
14221 type = type_main_variant (type);
14223 if (TREE_ASM_WRITTEN (type))
14226 switch (TREE_CODE (type))
14232 case REFERENCE_TYPE:
14233 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14234 ensures that the gen_type_die recursion will terminate even if the
14235 type is recursive. Recursive types are possible in Ada. */
14236 /* ??? We could perhaps do this for all types before the switch
14238 TREE_ASM_WRITTEN (type) = 1;
14240 /* For these types, all that is required is that we output a DIE (or a
14241 set of DIEs) to represent the "basis" type. */
14242 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14243 DINFO_USAGE_IND_USE);
14247 /* This code is used for C++ pointer-to-data-member types.
14248 Output a description of the relevant class type. */
14249 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
14250 DINFO_USAGE_IND_USE);
14252 /* Output a description of the type of the object pointed to. */
14253 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14254 DINFO_USAGE_IND_USE);
14256 /* Now output a DIE to represent this pointer-to-data-member type
14258 gen_ptr_to_mbr_type_die (type, context_die);
14261 case FUNCTION_TYPE:
14262 /* Force out return type (in case it wasn't forced out already). */
14263 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14264 DINFO_USAGE_DIR_USE);
14265 gen_subroutine_type_die (type, context_die);
14269 /* Force out return type (in case it wasn't forced out already). */
14270 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14271 DINFO_USAGE_DIR_USE);
14272 gen_subroutine_type_die (type, context_die);
14276 gen_array_type_die (type, context_die);
14280 gen_array_type_die (type, context_die);
14283 case ENUMERAL_TYPE:
14286 case QUAL_UNION_TYPE:
14287 /* If this is a nested type whose containing class hasn't been written
14288 out yet, writing it out will cover this one, too. This does not apply
14289 to instantiations of member class templates; they need to be added to
14290 the containing class as they are generated. FIXME: This hurts the
14291 idea of combining type decls from multiple TUs, since we can't predict
14292 what set of template instantiations we'll get. */
14293 if (TYPE_CONTEXT (type)
14294 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14295 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
14297 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
14299 if (TREE_ASM_WRITTEN (type))
14302 /* If that failed, attach ourselves to the stub. */
14303 push_decl_scope (TYPE_CONTEXT (type));
14304 context_die = lookup_type_die (TYPE_CONTEXT (type));
14309 declare_in_namespace (type, context_die);
14313 if (TREE_CODE (type) == ENUMERAL_TYPE)
14315 /* This might have been written out by the call to
14316 declare_in_namespace. */
14317 if (!TREE_ASM_WRITTEN (type))
14318 gen_enumeration_type_die (type, context_die);
14321 gen_struct_or_union_type_die (type, context_die, usage);
14326 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14327 it up if it is ever completed. gen_*_type_die will set it for us
14328 when appropriate. */
14334 case FIXED_POINT_TYPE:
14337 /* No DIEs needed for fundamental types. */
14341 /* No Dwarf representation currently defined. */
14345 gcc_unreachable ();
14348 TREE_ASM_WRITTEN (type) = 1;
14352 gen_type_die (tree type, dw_die_ref context_die)
14354 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14357 /* Generate a DIE for a tagged type instantiation. */
14360 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
14362 if (type == NULL_TREE || type == error_mark_node)
14365 /* We are going to output a DIE to represent the unqualified version of
14366 this type (i.e. without any const or volatile qualifiers) so make sure
14367 that we have the main variant (i.e. the unqualified version) of this
14369 gcc_assert (type == type_main_variant (type));
14371 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14372 an instance of an unresolved type. */
14374 switch (TREE_CODE (type))
14379 case ENUMERAL_TYPE:
14380 gen_inlined_enumeration_type_die (type, context_die);
14384 gen_inlined_structure_type_die (type, context_die);
14388 case QUAL_UNION_TYPE:
14389 gen_inlined_union_type_die (type, context_die);
14393 gcc_unreachable ();
14397 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14398 things which are local to the given block. */
14401 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14403 int must_output_die = 0;
14406 enum tree_code origin_code;
14408 /* Ignore blocks that are NULL. */
14409 if (stmt == NULL_TREE)
14412 /* If the block is one fragment of a non-contiguous block, do not
14413 process the variables, since they will have been done by the
14414 origin block. Do process subblocks. */
14415 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14419 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14420 gen_block_die (sub, context_die, depth + 1);
14425 /* Determine the "ultimate origin" of this block. This block may be an
14426 inlined instance of an inlined instance of inline function, so we have
14427 to trace all of the way back through the origin chain to find out what
14428 sort of node actually served as the original seed for the creation of
14429 the current block. */
14430 origin = block_ultimate_origin (stmt);
14431 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
14433 /* Determine if we need to output any Dwarf DIEs at all to represent this
14435 if (origin_code == FUNCTION_DECL)
14436 /* The outer scopes for inlinings *must* always be represented. We
14437 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14438 must_output_die = 1;
14441 /* In the case where the current block represents an inlining of the
14442 "body block" of an inline function, we must *NOT* output any DIE for
14443 this block because we have already output a DIE to represent the whole
14444 inlined function scope and the "body block" of any function doesn't
14445 really represent a different scope according to ANSI C rules. So we
14446 check here to make sure that this block does not represent a "body
14447 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14448 if (! is_body_block (origin ? origin : stmt))
14450 /* Determine if this block directly contains any "significant"
14451 local declarations which we will need to output DIEs for. */
14452 if (debug_info_level > DINFO_LEVEL_TERSE)
14453 /* We are not in terse mode so *any* local declaration counts
14454 as being a "significant" one. */
14455 must_output_die = (BLOCK_VARS (stmt) != NULL
14456 && (TREE_USED (stmt)
14457 || TREE_ASM_WRITTEN (stmt)
14458 || BLOCK_ABSTRACT (stmt)));
14460 /* We are in terse mode, so only local (nested) function
14461 definitions count as "significant" local declarations. */
14462 for (decl = BLOCK_VARS (stmt);
14463 decl != NULL; decl = TREE_CHAIN (decl))
14464 if (TREE_CODE (decl) == FUNCTION_DECL
14465 && DECL_INITIAL (decl))
14467 must_output_die = 1;
14473 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14474 DIE for any block which contains no significant local declarations at
14475 all. Rather, in such cases we just call `decls_for_scope' so that any
14476 needed Dwarf info for any sub-blocks will get properly generated. Note
14477 that in terse mode, our definition of what constitutes a "significant"
14478 local declaration gets restricted to include only inlined function
14479 instances and local (nested) function definitions. */
14480 if (must_output_die)
14482 if (origin_code == FUNCTION_DECL)
14483 gen_inlined_subroutine_die (stmt, context_die, depth);
14485 gen_lexical_block_die (stmt, context_die, depth);
14488 decls_for_scope (stmt, context_die, depth);
14491 /* Generate all of the decls declared within a given scope and (recursively)
14492 all of its sub-blocks. */
14495 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
14500 /* Ignore NULL blocks. */
14501 if (stmt == NULL_TREE)
14504 if (TREE_USED (stmt))
14506 /* Output the DIEs to represent all of the data objects and typedefs
14507 declared directly within this block but not within any nested
14508 sub-blocks. Also, nested function and tag DIEs have been
14509 generated with a parent of NULL; fix that up now. */
14510 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
14514 if (TREE_CODE (decl) == FUNCTION_DECL)
14515 die = lookup_decl_die (decl);
14516 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
14517 die = lookup_type_die (TREE_TYPE (decl));
14521 if (die != NULL && die->die_parent == NULL)
14522 add_child_die (context_die, die);
14523 /* Do not produce debug information for static variables since
14524 these might be optimized out. We are called for these later
14525 in varpool_analyze_pending_decls.
14527 But *do* produce it for Fortran COMMON variables because,
14528 even though they are static, their names can differ depending
14529 on the scope, which we need to preserve. */
14530 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
14531 && !(is_fortran () && TREE_PUBLIC (decl)))
14534 gen_decl_die (decl, context_die);
14538 /* If we're at -g1, we're not interested in subblocks. */
14539 if (debug_info_level <= DINFO_LEVEL_TERSE)
14542 /* Output the DIEs to represent all sub-blocks (and the items declared
14543 therein) of this block. */
14544 for (subblocks = BLOCK_SUBBLOCKS (stmt);
14546 subblocks = BLOCK_CHAIN (subblocks))
14547 gen_block_die (subblocks, context_die, depth + 1);
14550 /* Is this a typedef we can avoid emitting? */
14553 is_redundant_typedef (const_tree decl)
14555 if (TYPE_DECL_IS_STUB (decl))
14558 if (DECL_ARTIFICIAL (decl)
14559 && DECL_CONTEXT (decl)
14560 && is_tagged_type (DECL_CONTEXT (decl))
14561 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
14562 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
14563 /* Also ignore the artificial member typedef for the class name. */
14569 /* Returns the DIE for a context. */
14571 static inline dw_die_ref
14572 get_context_die (tree context)
14576 /* Find die that represents this context. */
14577 if (TYPE_P (context))
14578 return force_type_die (context);
14580 return force_decl_die (context);
14582 return comp_unit_die;
14585 /* Returns the DIE for decl. A DIE will always be returned. */
14588 force_decl_die (tree decl)
14590 dw_die_ref decl_die;
14591 unsigned saved_external_flag;
14592 tree save_fn = NULL_TREE;
14593 decl_die = lookup_decl_die (decl);
14596 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
14598 decl_die = lookup_decl_die (decl);
14602 switch (TREE_CODE (decl))
14604 case FUNCTION_DECL:
14605 /* Clear current_function_decl, so that gen_subprogram_die thinks
14606 that this is a declaration. At this point, we just want to force
14607 declaration die. */
14608 save_fn = current_function_decl;
14609 current_function_decl = NULL_TREE;
14610 gen_subprogram_die (decl, context_die);
14611 current_function_decl = save_fn;
14615 /* Set external flag to force declaration die. Restore it after
14616 gen_decl_die() call. */
14617 saved_external_flag = DECL_EXTERNAL (decl);
14618 DECL_EXTERNAL (decl) = 1;
14619 gen_decl_die (decl, context_die);
14620 DECL_EXTERNAL (decl) = saved_external_flag;
14623 case NAMESPACE_DECL:
14624 dwarf2out_decl (decl);
14628 gcc_unreachable ();
14631 /* We should be able to find the DIE now. */
14633 decl_die = lookup_decl_die (decl);
14634 gcc_assert (decl_die);
14640 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
14641 always returned. */
14644 force_type_die (tree type)
14646 dw_die_ref type_die;
14648 type_die = lookup_type_die (type);
14651 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
14653 type_die = modified_type_die (type, TYPE_READONLY (type),
14654 TYPE_VOLATILE (type), context_die);
14655 gcc_assert (type_die);
14660 /* Force out any required namespaces to be able to output DECL,
14661 and return the new context_die for it, if it's changed. */
14664 setup_namespace_context (tree thing, dw_die_ref context_die)
14666 tree context = (DECL_P (thing)
14667 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
14668 if (context && TREE_CODE (context) == NAMESPACE_DECL)
14669 /* Force out the namespace. */
14670 context_die = force_decl_die (context);
14672 return context_die;
14675 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
14676 type) within its namespace, if appropriate.
14678 For compatibility with older debuggers, namespace DIEs only contain
14679 declarations; all definitions are emitted at CU scope. */
14682 declare_in_namespace (tree thing, dw_die_ref context_die)
14684 dw_die_ref ns_context;
14686 if (debug_info_level <= DINFO_LEVEL_TERSE)
14689 /* If this decl is from an inlined function, then don't try to emit it in its
14690 namespace, as we will get confused. It would have already been emitted
14691 when the abstract instance of the inline function was emitted anyways. */
14692 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
14695 ns_context = setup_namespace_context (thing, context_die);
14697 if (ns_context != context_die)
14699 if (DECL_P (thing))
14700 gen_decl_die (thing, ns_context);
14702 gen_type_die (thing, ns_context);
14706 /* Generate a DIE for a namespace or namespace alias. */
14709 gen_namespace_die (tree decl)
14711 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
14713 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
14714 they are an alias of. */
14715 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
14717 /* Output a real namespace. */
14718 dw_die_ref namespace_die
14719 = new_die (DW_TAG_namespace, context_die, decl);
14720 add_name_and_src_coords_attributes (namespace_die, decl);
14721 equate_decl_number_to_die (decl, namespace_die);
14725 /* Output a namespace alias. */
14727 /* Force out the namespace we are an alias of, if necessary. */
14728 dw_die_ref origin_die
14729 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
14731 /* Now create the namespace alias DIE. */
14732 dw_die_ref namespace_die
14733 = new_die (DW_TAG_imported_declaration, context_die, decl);
14734 add_name_and_src_coords_attributes (namespace_die, decl);
14735 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
14736 equate_decl_number_to_die (decl, namespace_die);
14740 /* Generate Dwarf debug information for a decl described by DECL. */
14743 gen_decl_die (tree decl, dw_die_ref context_die)
14747 if (DECL_P (decl) && DECL_IGNORED_P (decl))
14750 switch (TREE_CODE (decl))
14756 /* The individual enumerators of an enum type get output when we output
14757 the Dwarf representation of the relevant enum type itself. */
14760 case FUNCTION_DECL:
14761 /* Don't output any DIEs to represent mere function declarations,
14762 unless they are class members or explicit block externs. */
14763 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
14764 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
14769 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14770 on local redeclarations of global functions. That seems broken. */
14771 if (current_function_decl != decl)
14772 /* This is only a declaration. */;
14775 /* If we're emitting a clone, emit info for the abstract instance. */
14776 if (DECL_ORIGIN (decl) != decl)
14777 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14779 /* If we're emitting an out-of-line copy of an inline function,
14780 emit info for the abstract instance and set up to refer to it. */
14781 else if (cgraph_function_possibly_inlined_p (decl)
14782 && ! DECL_ABSTRACT (decl)
14783 && ! class_or_namespace_scope_p (context_die)
14784 /* dwarf2out_abstract_function won't emit a die if this is just
14785 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14786 that case, because that works only if we have a die. */
14787 && DECL_INITIAL (decl) != NULL_TREE)
14789 dwarf2out_abstract_function (decl);
14790 set_decl_origin_self (decl);
14793 /* Otherwise we're emitting the primary DIE for this decl. */
14794 else if (debug_info_level > DINFO_LEVEL_TERSE)
14796 /* Before we describe the FUNCTION_DECL itself, make sure that we
14797 have described its return type. */
14798 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14800 /* And its virtual context. */
14801 if (DECL_VINDEX (decl) != NULL_TREE)
14802 gen_type_die (DECL_CONTEXT (decl), context_die);
14804 /* And its containing type. */
14805 origin = decl_class_context (decl);
14806 if (origin != NULL_TREE)
14807 gen_type_die_for_member (origin, decl, context_die);
14809 /* And its containing namespace. */
14810 declare_in_namespace (decl, context_die);
14813 /* Now output a DIE to represent the function itself. */
14814 gen_subprogram_die (decl, context_die);
14818 /* If we are in terse mode, don't generate any DIEs to represent any
14819 actual typedefs. */
14820 if (debug_info_level <= DINFO_LEVEL_TERSE)
14823 /* In the special case of a TYPE_DECL node representing the declaration
14824 of some type tag, if the given TYPE_DECL is marked as having been
14825 instantiated from some other (original) TYPE_DECL node (e.g. one which
14826 was generated within the original definition of an inline function) we
14827 have to generate a special (abbreviated) DW_TAG_structure_type,
14828 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14829 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14830 && is_tagged_type (TREE_TYPE (decl)))
14832 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14836 if (is_redundant_typedef (decl))
14837 gen_type_die (TREE_TYPE (decl), context_die);
14839 /* Output a DIE to represent the typedef itself. */
14840 gen_typedef_die (decl, context_die);
14844 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14845 gen_label_die (decl, context_die);
14850 /* If we are in terse mode, don't generate any DIEs to represent any
14851 variable declarations or definitions. */
14852 if (debug_info_level <= DINFO_LEVEL_TERSE)
14855 /* If this is the global definition of the Fortran COMMON block, we don't
14856 need to do anything. Syntactically, the block itself has no identity,
14857 just its constituent identifiers. */
14858 if (TREE_CODE (decl) == VAR_DECL
14859 && TREE_PUBLIC (decl)
14860 && TREE_STATIC (decl)
14862 && !DECL_HAS_VALUE_EXPR_P (decl))
14865 /* Output any DIEs that are needed to specify the type of this data
14867 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14868 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14870 gen_type_die (TREE_TYPE (decl), context_die);
14872 /* And its containing type. */
14873 origin = decl_class_context (decl);
14874 if (origin != NULL_TREE)
14875 gen_type_die_for_member (origin, decl, context_die);
14877 /* And its containing namespace. */
14878 declare_in_namespace (decl, context_die);
14880 /* Now output the DIE to represent the data object itself. This gets
14881 complicated because of the possibility that the VAR_DECL really
14882 represents an inlined instance of a formal parameter for an inline
14884 origin = decl_ultimate_origin (decl);
14885 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
14886 gen_formal_parameter_die (decl, context_die);
14888 gen_variable_die (decl, context_die);
14892 /* Ignore the nameless fields that are used to skip bits but handle C++
14893 anonymous unions and structs. */
14894 if (DECL_NAME (decl) != NULL_TREE
14895 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
14896 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
14898 gen_type_die (member_declared_type (decl), context_die);
14899 gen_field_die (decl, context_die);
14904 if (DECL_BY_REFERENCE (decl))
14905 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14907 gen_type_die (TREE_TYPE (decl), context_die);
14908 gen_formal_parameter_die (decl, context_die);
14911 case NAMESPACE_DECL:
14912 gen_namespace_die (decl);
14916 /* Probably some frontend-internal decl. Assume we don't care. */
14917 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
14922 /* Output debug information for global decl DECL. Called from toplev.c after
14923 compilation proper has finished. */
14926 dwarf2out_global_decl (tree decl)
14928 /* Output DWARF2 information for file-scope tentative data object
14929 declarations, file-scope (extern) function declarations (which
14930 had no corresponding body) and file-scope tagged type declarations
14931 and definitions which have not yet been forced out.
14933 Ignore the global decl of any Fortran COMMON blocks which also
14934 wind up here though they have already been described in the local
14935 scope for the procedures using them. */
14936 if (TREE_CODE (decl) == VAR_DECL
14937 && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ())
14940 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14941 dwarf2out_decl (decl);
14944 /* Output debug information for type decl DECL. Called from toplev.c
14945 and from language front ends (to record built-in types). */
14947 dwarf2out_type_decl (tree decl, int local)
14950 dwarf2out_decl (decl);
14953 /* Output debug information for imported module or decl. */
14956 dwarf2out_imported_module_or_decl (tree decl, tree context)
14958 dw_die_ref imported_die, at_import_die;
14959 dw_die_ref scope_die;
14960 expanded_location xloc;
14962 if (debug_info_level <= DINFO_LEVEL_TERSE)
14967 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14968 We need decl DIE for reference and scope die. First, get DIE for the decl
14971 /* Get the scope die for decl context. Use comp_unit_die for global module
14972 or decl. If die is not found for non globals, force new die. */
14974 && TYPE_P (context)
14975 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14977 scope_die = get_context_die (context);
14979 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14980 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14982 if (is_base_type (TREE_TYPE (decl)))
14983 at_import_die = base_type_die (TREE_TYPE (decl));
14985 at_import_die = force_type_die (TREE_TYPE (decl));
14986 /* For namespace N { typedef void T; } using N::T; base_type_die
14987 returns NULL, but DW_TAG_imported_declaration requires
14988 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
14989 if (!at_import_die)
14991 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
14992 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
14993 at_import_die = lookup_type_die (TREE_TYPE (decl));
14994 gcc_assert (at_import_die);
14999 at_import_die = lookup_decl_die (decl);
15000 if (!at_import_die)
15002 /* If we're trying to avoid duplicate debug info, we may not have
15003 emitted the member decl for this field. Emit it now. */
15004 if (TREE_CODE (decl) == FIELD_DECL)
15006 tree type = DECL_CONTEXT (decl);
15008 if (TYPE_CONTEXT (type)
15009 && TYPE_P (TYPE_CONTEXT (type))
15010 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15011 DINFO_USAGE_DIR_USE))
15013 gen_type_die_for_member (type, decl,
15014 get_context_die (TYPE_CONTEXT (type)));
15016 at_import_die = force_decl_die (decl);
15020 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15021 if (TREE_CODE (decl) == NAMESPACE_DECL)
15022 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
15024 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
15026 xloc = expand_location (input_location);
15027 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15028 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15029 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15032 /* Write the debugging output for DECL. */
15035 dwarf2out_decl (tree decl)
15037 dw_die_ref context_die = comp_unit_die;
15039 switch (TREE_CODE (decl))
15044 case FUNCTION_DECL:
15045 /* What we would really like to do here is to filter out all mere
15046 file-scope declarations of file-scope functions which are never
15047 referenced later within this translation unit (and keep all of ones
15048 that *are* referenced later on) but we aren't clairvoyant, so we have
15049 no idea which functions will be referenced in the future (i.e. later
15050 on within the current translation unit). So here we just ignore all
15051 file-scope function declarations which are not also definitions. If
15052 and when the debugger needs to know something about these functions,
15053 it will have to hunt around and find the DWARF information associated
15054 with the definition of the function.
15056 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15057 nodes represent definitions and which ones represent mere
15058 declarations. We have to check DECL_INITIAL instead. That's because
15059 the C front-end supports some weird semantics for "extern inline"
15060 function definitions. These can get inlined within the current
15061 translation unit (and thus, we need to generate Dwarf info for their
15062 abstract instances so that the Dwarf info for the concrete inlined
15063 instances can have something to refer to) but the compiler never
15064 generates any out-of-lines instances of such things (despite the fact
15065 that they *are* definitions).
15067 The important point is that the C front-end marks these "extern
15068 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15069 them anyway. Note that the C++ front-end also plays some similar games
15070 for inline function definitions appearing within include files which
15071 also contain `#pragma interface' pragmas. */
15072 if (DECL_INITIAL (decl) == NULL_TREE)
15075 /* If we're a nested function, initially use a parent of NULL; if we're
15076 a plain function, this will be fixed up in decls_for_scope. If
15077 we're a method, it will be ignored, since we already have a DIE. */
15078 if (decl_function_context (decl)
15079 /* But if we're in terse mode, we don't care about scope. */
15080 && debug_info_level > DINFO_LEVEL_TERSE)
15081 context_die = NULL;
15085 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15086 declaration and if the declaration was never even referenced from
15087 within this entire compilation unit. We suppress these DIEs in
15088 order to save space in the .debug section (by eliminating entries
15089 which are probably useless). Note that we must not suppress
15090 block-local extern declarations (whether used or not) because that
15091 would screw-up the debugger's name lookup mechanism and cause it to
15092 miss things which really ought to be in scope at a given point. */
15093 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15096 /* For local statics lookup proper context die. */
15097 if (TREE_STATIC (decl) && decl_function_context (decl))
15098 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15100 /* If we are in terse mode, don't generate any DIEs to represent any
15101 variable declarations or definitions. */
15102 if (debug_info_level <= DINFO_LEVEL_TERSE)
15106 case NAMESPACE_DECL:
15107 if (debug_info_level <= DINFO_LEVEL_TERSE)
15109 if (lookup_decl_die (decl) != NULL)
15114 /* Don't emit stubs for types unless they are needed by other DIEs. */
15115 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15118 /* Don't bother trying to generate any DIEs to represent any of the
15119 normal built-in types for the language we are compiling. */
15120 if (DECL_IS_BUILTIN (decl))
15122 /* OK, we need to generate one for `bool' so GDB knows what type
15123 comparisons have. */
15125 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15126 && ! DECL_IGNORED_P (decl))
15127 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15132 /* If we are in terse mode, don't generate any DIEs for types. */
15133 if (debug_info_level <= DINFO_LEVEL_TERSE)
15136 /* If we're a function-scope tag, initially use a parent of NULL;
15137 this will be fixed up in decls_for_scope. */
15138 if (decl_function_context (decl))
15139 context_die = NULL;
15147 gen_decl_die (decl, context_die);
15150 /* Output a marker (i.e. a label) for the beginning of the generated code for
15151 a lexical block. */
15154 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15155 unsigned int blocknum)
15157 switch_to_section (current_function_section ());
15158 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15161 /* Output a marker (i.e. a label) for the end of the generated code for a
15165 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15167 switch_to_section (current_function_section ());
15168 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15171 /* Returns nonzero if it is appropriate not to emit any debugging
15172 information for BLOCK, because it doesn't contain any instructions.
15174 Don't allow this for blocks with nested functions or local classes
15175 as we would end up with orphans, and in the presence of scheduling
15176 we may end up calling them anyway. */
15179 dwarf2out_ignore_block (const_tree block)
15183 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15184 if (TREE_CODE (decl) == FUNCTION_DECL
15185 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15191 /* Hash table routines for file_hash. */
15194 file_table_eq (const void *p1_p, const void *p2_p)
15196 const struct dwarf_file_data *const p1 =
15197 (const struct dwarf_file_data *) p1_p;
15198 const char *const p2 = (const char *) p2_p;
15199 return strcmp (p1->filename, p2) == 0;
15203 file_table_hash (const void *p_p)
15205 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15206 return htab_hash_string (p->filename);
15209 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15210 dwarf2out.c) and return its "index". The index of each (known) filename is
15211 just a unique number which is associated with only that one filename. We
15212 need such numbers for the sake of generating labels (in the .debug_sfnames
15213 section) and references to those files numbers (in the .debug_srcinfo
15214 and.debug_macinfo sections). If the filename given as an argument is not
15215 found in our current list, add it to the list and assign it the next
15216 available unique index number. In order to speed up searches, we remember
15217 the index of the filename was looked up last. This handles the majority of
15220 static struct dwarf_file_data *
15221 lookup_filename (const char *file_name)
15224 struct dwarf_file_data * created;
15226 /* Check to see if the file name that was searched on the previous
15227 call matches this file name. If so, return the index. */
15228 if (file_table_last_lookup
15229 && (file_name == file_table_last_lookup->filename
15230 || strcmp (file_table_last_lookup->filename, file_name) == 0))
15231 return file_table_last_lookup;
15233 /* Didn't match the previous lookup, search the table. */
15234 slot = htab_find_slot_with_hash (file_table, file_name,
15235 htab_hash_string (file_name), INSERT);
15237 return (struct dwarf_file_data *) *slot;
15239 created = GGC_NEW (struct dwarf_file_data);
15240 created->filename = file_name;
15241 created->emitted_number = 0;
15246 /* If the assembler will construct the file table, then translate the compiler
15247 internal file table number into the assembler file table number, and emit
15248 a .file directive if we haven't already emitted one yet. The file table
15249 numbers are different because we prune debug info for unused variables and
15250 types, which may include filenames. */
15253 maybe_emit_file (struct dwarf_file_data * fd)
15255 if (! fd->emitted_number)
15257 if (last_emitted_file)
15258 fd->emitted_number = last_emitted_file->emitted_number + 1;
15260 fd->emitted_number = 1;
15261 last_emitted_file = fd;
15263 if (DWARF2_ASM_LINE_DEBUG_INFO)
15265 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
15266 output_quoted_string (asm_out_file,
15267 remap_debug_filename (fd->filename));
15268 fputc ('\n', asm_out_file);
15272 return fd->emitted_number;
15275 /* Called by the final INSN scan whenever we see a var location. We
15276 use it to drop labels in the right places, and throw the location in
15277 our lookup table. */
15280 dwarf2out_var_location (rtx loc_note)
15282 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
15283 struct var_loc_node *newloc;
15285 static rtx last_insn;
15286 static const char *last_label;
15289 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
15291 prev_insn = PREV_INSN (loc_note);
15293 newloc = GGC_CNEW (struct var_loc_node);
15294 /* If the insn we processed last time is the previous insn
15295 and it is also a var location note, use the label we emitted
15297 if (last_insn != NULL_RTX
15298 && last_insn == prev_insn
15299 && NOTE_P (prev_insn)
15300 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
15302 newloc->label = last_label;
15306 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
15307 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
15309 newloc->label = ggc_strdup (loclabel);
15311 newloc->var_loc_note = loc_note;
15312 newloc->next = NULL;
15314 if (cfun && in_cold_section_p)
15315 newloc->section_label = crtl->subsections.cold_section_label;
15317 newloc->section_label = text_section_label;
15319 last_insn = loc_note;
15320 last_label = newloc->label;
15321 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15322 add_var_loc_to_decl (decl, newloc);
15325 /* We need to reset the locations at the beginning of each
15326 function. We can't do this in the end_function hook, because the
15327 declarations that use the locations won't have been output when
15328 that hook is called. Also compute have_multiple_function_sections here. */
15331 dwarf2out_begin_function (tree fun)
15333 htab_empty (decl_loc_table);
15335 if (function_section (fun) != text_section)
15336 have_multiple_function_sections = true;
15338 dwarf2out_note_section_used ();
15341 /* Output a label to mark the beginning of a source code line entry
15342 and record information relating to this source line, in
15343 'line_info_table' for later output of the .debug_line section. */
15346 dwarf2out_source_line (unsigned int line, const char *filename)
15348 if (debug_info_level >= DINFO_LEVEL_NORMAL
15351 int file_num = maybe_emit_file (lookup_filename (filename));
15353 switch_to_section (current_function_section ());
15355 /* If requested, emit something human-readable. */
15356 if (flag_debug_asm)
15357 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15360 if (DWARF2_ASM_LINE_DEBUG_INFO)
15362 /* Emit the .loc directive understood by GNU as. */
15363 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15365 /* Indicate that line number info exists. */
15366 line_info_table_in_use++;
15368 else if (function_section (current_function_decl) != text_section)
15370 dw_separate_line_info_ref line_info;
15371 targetm.asm_out.internal_label (asm_out_file,
15372 SEPARATE_LINE_CODE_LABEL,
15373 separate_line_info_table_in_use);
15375 /* Expand the line info table if necessary. */
15376 if (separate_line_info_table_in_use
15377 == separate_line_info_table_allocated)
15379 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15380 separate_line_info_table
15381 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15382 separate_line_info_table,
15383 separate_line_info_table_allocated);
15384 memset (separate_line_info_table
15385 + separate_line_info_table_in_use,
15387 (LINE_INFO_TABLE_INCREMENT
15388 * sizeof (dw_separate_line_info_entry)));
15391 /* Add the new entry at the end of the line_info_table. */
15393 = &separate_line_info_table[separate_line_info_table_in_use++];
15394 line_info->dw_file_num = file_num;
15395 line_info->dw_line_num = line;
15396 line_info->function = current_function_funcdef_no;
15400 dw_line_info_ref line_info;
15402 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
15403 line_info_table_in_use);
15405 /* Expand the line info table if necessary. */
15406 if (line_info_table_in_use == line_info_table_allocated)
15408 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15410 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
15411 line_info_table_allocated);
15412 memset (line_info_table + line_info_table_in_use, 0,
15413 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
15416 /* Add the new entry at the end of the line_info_table. */
15417 line_info = &line_info_table[line_info_table_in_use++];
15418 line_info->dw_file_num = file_num;
15419 line_info->dw_line_num = line;
15424 /* Record the beginning of a new source file. */
15427 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
15429 if (flag_eliminate_dwarf2_dups)
15431 /* Record the beginning of the file for break_out_includes. */
15432 dw_die_ref bincl_die;
15434 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
15435 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
15438 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15440 int file_num = maybe_emit_file (lookup_filename (filename));
15442 switch_to_section (debug_macinfo_section);
15443 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
15444 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
15447 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
15451 /* Record the end of a source file. */
15454 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
15456 if (flag_eliminate_dwarf2_dups)
15457 /* Record the end of the file for break_out_includes. */
15458 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
15460 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15462 switch_to_section (debug_macinfo_section);
15463 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
15467 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15468 the tail part of the directive line, i.e. the part which is past the
15469 initial whitespace, #, whitespace, directive-name, whitespace part. */
15472 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
15473 const char *buffer ATTRIBUTE_UNUSED)
15475 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15477 switch_to_section (debug_macinfo_section);
15478 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
15479 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15480 dw2_asm_output_nstring (buffer, -1, "The macro");
15484 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15485 the tail part of the directive line, i.e. the part which is past the
15486 initial whitespace, #, whitespace, directive-name, whitespace part. */
15489 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
15490 const char *buffer ATTRIBUTE_UNUSED)
15492 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15494 switch_to_section (debug_macinfo_section);
15495 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
15496 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15497 dw2_asm_output_nstring (buffer, -1, "The macro");
15501 /* Set up for Dwarf output at the start of compilation. */
15504 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
15506 /* Allocate the file_table. */
15507 file_table = htab_create_ggc (50, file_table_hash,
15508 file_table_eq, NULL);
15510 /* Allocate the decl_die_table. */
15511 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
15512 decl_die_table_eq, NULL);
15514 /* Allocate the decl_loc_table. */
15515 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
15516 decl_loc_table_eq, NULL);
15518 /* Allocate the initial hunk of the decl_scope_table. */
15519 decl_scope_table = VEC_alloc (tree, gc, 256);
15521 /* Allocate the initial hunk of the abbrev_die_table. */
15522 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
15523 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
15524 /* Zero-th entry is allocated, but unused. */
15525 abbrev_die_table_in_use = 1;
15527 /* Allocate the initial hunk of the line_info_table. */
15528 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
15529 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
15531 /* Zero-th entry is allocated, but unused. */
15532 line_info_table_in_use = 1;
15534 /* Allocate the pubtypes and pubnames vectors. */
15535 pubname_table = VEC_alloc (pubname_entry, gc, 32);
15536 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
15538 /* Generate the initial DIE for the .debug section. Note that the (string)
15539 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15540 will (typically) be a relative pathname and that this pathname should be
15541 taken as being relative to the directory from which the compiler was
15542 invoked when the given (base) source file was compiled. We will fill
15543 in this value in dwarf2out_finish. */
15544 comp_unit_die = gen_compile_unit_die (NULL);
15546 incomplete_types = VEC_alloc (tree, gc, 64);
15548 used_rtx_array = VEC_alloc (rtx, gc, 32);
15550 debug_info_section = get_section (DEBUG_INFO_SECTION,
15551 SECTION_DEBUG, NULL);
15552 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
15553 SECTION_DEBUG, NULL);
15554 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
15555 SECTION_DEBUG, NULL);
15556 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
15557 SECTION_DEBUG, NULL);
15558 debug_line_section = get_section (DEBUG_LINE_SECTION,
15559 SECTION_DEBUG, NULL);
15560 debug_loc_section = get_section (DEBUG_LOC_SECTION,
15561 SECTION_DEBUG, NULL);
15562 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
15563 SECTION_DEBUG, NULL);
15564 #ifdef DEBUG_PUBTYPES_SECTION
15565 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
15566 SECTION_DEBUG, NULL);
15568 debug_str_section = get_section (DEBUG_STR_SECTION,
15569 DEBUG_STR_SECTION_FLAGS, NULL);
15570 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
15571 SECTION_DEBUG, NULL);
15572 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
15573 SECTION_DEBUG, NULL);
15575 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
15576 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
15577 DEBUG_ABBREV_SECTION_LABEL, 0);
15578 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
15579 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
15580 COLD_TEXT_SECTION_LABEL, 0);
15581 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
15583 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
15584 DEBUG_INFO_SECTION_LABEL, 0);
15585 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
15586 DEBUG_LINE_SECTION_LABEL, 0);
15587 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
15588 DEBUG_RANGES_SECTION_LABEL, 0);
15589 switch_to_section (debug_abbrev_section);
15590 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
15591 switch_to_section (debug_info_section);
15592 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
15593 switch_to_section (debug_line_section);
15594 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
15596 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15598 switch_to_section (debug_macinfo_section);
15599 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
15600 DEBUG_MACINFO_SECTION_LABEL, 0);
15601 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
15604 switch_to_section (text_section);
15605 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
15606 if (flag_reorder_blocks_and_partition)
15608 cold_text_section = unlikely_text_section ();
15609 switch_to_section (cold_text_section);
15610 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
15614 /* A helper function for dwarf2out_finish called through
15615 ht_forall. Emit one queued .debug_str string. */
15618 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
15620 struct indirect_string_node *node = (struct indirect_string_node *) *h;
15622 if (node->form == DW_FORM_strp)
15624 switch_to_section (debug_str_section);
15625 ASM_OUTPUT_LABEL (asm_out_file, node->label);
15626 assemble_string (node->str, strlen (node->str) + 1);
15632 #if ENABLE_ASSERT_CHECKING
15633 /* Verify that all marks are clear. */
15636 verify_marks_clear (dw_die_ref die)
15640 gcc_assert (! die->die_mark);
15641 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
15643 #endif /* ENABLE_ASSERT_CHECKING */
15645 /* Clear the marks for a die and its children.
15646 Be cool if the mark isn't set. */
15649 prune_unmark_dies (dw_die_ref die)
15655 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
15658 /* Given DIE that we're marking as used, find any other dies
15659 it references as attributes and mark them as used. */
15662 prune_unused_types_walk_attribs (dw_die_ref die)
15667 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15669 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
15671 /* A reference to another DIE.
15672 Make sure that it will get emitted. */
15673 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
15675 /* Set the string's refcount to 0 so that prune_unused_types_mark
15676 accounts properly for it. */
15677 if (AT_class (a) == dw_val_class_str)
15678 a->dw_attr_val.v.val_str->refcount = 0;
15683 /* Mark DIE as being used. If DOKIDS is true, then walk down
15684 to DIE's children. */
15687 prune_unused_types_mark (dw_die_ref die, int dokids)
15691 if (die->die_mark == 0)
15693 /* We haven't done this node yet. Mark it as used. */
15696 /* We also have to mark its parents as used.
15697 (But we don't want to mark our parents' kids due to this.) */
15698 if (die->die_parent)
15699 prune_unused_types_mark (die->die_parent, 0);
15701 /* Mark any referenced nodes. */
15702 prune_unused_types_walk_attribs (die);
15704 /* If this node is a specification,
15705 also mark the definition, if it exists. */
15706 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
15707 prune_unused_types_mark (die->die_definition, 1);
15710 if (dokids && die->die_mark != 2)
15712 /* We need to walk the children, but haven't done so yet.
15713 Remember that we've walked the kids. */
15716 /* If this is an array type, we need to make sure our
15717 kids get marked, even if they're types. */
15718 if (die->die_tag == DW_TAG_array_type)
15719 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
15721 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15726 /* Walk the tree DIE and mark types that we actually use. */
15729 prune_unused_types_walk (dw_die_ref die)
15733 /* Don't do anything if this node is already marked. */
15737 switch (die->die_tag)
15739 case DW_TAG_const_type:
15740 case DW_TAG_packed_type:
15741 case DW_TAG_pointer_type:
15742 case DW_TAG_reference_type:
15743 case DW_TAG_volatile_type:
15744 case DW_TAG_typedef:
15745 case DW_TAG_array_type:
15746 case DW_TAG_structure_type:
15747 case DW_TAG_union_type:
15748 case DW_TAG_class_type:
15749 case DW_TAG_interface_type:
15750 case DW_TAG_friend:
15751 case DW_TAG_variant_part:
15752 case DW_TAG_enumeration_type:
15753 case DW_TAG_subroutine_type:
15754 case DW_TAG_string_type:
15755 case DW_TAG_set_type:
15756 case DW_TAG_subrange_type:
15757 case DW_TAG_ptr_to_member_type:
15758 case DW_TAG_file_type:
15759 if (die->die_perennial_p)
15762 /* It's a type node --- don't mark it. */
15766 /* Mark everything else. */
15772 /* Now, mark any dies referenced from here. */
15773 prune_unused_types_walk_attribs (die);
15775 /* Mark children. */
15776 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15779 /* Increment the string counts on strings referred to from DIE's
15783 prune_unused_types_update_strings (dw_die_ref die)
15788 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15789 if (AT_class (a) == dw_val_class_str)
15791 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15793 /* Avoid unnecessarily putting strings that are used less than
15794 twice in the hash table. */
15796 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15799 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15800 htab_hash_string (s->str),
15802 gcc_assert (*slot == NULL);
15808 /* Remove from the tree DIE any dies that aren't marked. */
15811 prune_unused_types_prune (dw_die_ref die)
15815 gcc_assert (die->die_mark);
15816 prune_unused_types_update_strings (die);
15818 if (! die->die_child)
15821 c = die->die_child;
15823 dw_die_ref prev = c;
15824 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15825 if (c == die->die_child)
15827 /* No marked children between 'prev' and the end of the list. */
15829 /* No marked children at all. */
15830 die->die_child = NULL;
15833 prev->die_sib = c->die_sib;
15834 die->die_child = prev;
15839 if (c != prev->die_sib)
15841 prune_unused_types_prune (c);
15842 } while (c != die->die_child);
15846 /* Remove dies representing declarations that we never use. */
15849 prune_unused_types (void)
15852 limbo_die_node *node;
15855 #if ENABLE_ASSERT_CHECKING
15856 /* All the marks should already be clear. */
15857 verify_marks_clear (comp_unit_die);
15858 for (node = limbo_die_list; node; node = node->next)
15859 verify_marks_clear (node->die);
15860 #endif /* ENABLE_ASSERT_CHECKING */
15862 /* Set the mark on nodes that are actually used. */
15863 prune_unused_types_walk (comp_unit_die);
15864 for (node = limbo_die_list; node; node = node->next)
15865 prune_unused_types_walk (node->die);
15867 /* Also set the mark on nodes referenced from the
15868 pubname_table or arange_table. */
15869 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15870 prune_unused_types_mark (pub->die, 1);
15871 for (i = 0; i < arange_table_in_use; i++)
15872 prune_unused_types_mark (arange_table[i], 1);
15874 /* Get rid of nodes that aren't marked; and update the string counts. */
15875 if (debug_str_hash)
15876 htab_empty (debug_str_hash);
15877 prune_unused_types_prune (comp_unit_die);
15878 for (node = limbo_die_list; node; node = node->next)
15879 prune_unused_types_prune (node->die);
15881 /* Leave the marks clear. */
15882 prune_unmark_dies (comp_unit_die);
15883 for (node = limbo_die_list; node; node = node->next)
15884 prune_unmark_dies (node->die);
15887 /* Set the parameter to true if there are any relative pathnames in
15890 file_table_relative_p (void ** slot, void *param)
15892 bool *p = (bool *) param;
15893 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
15894 if (!IS_ABSOLUTE_PATH (d->filename))
15902 /* Output stuff that dwarf requires at the end of every file,
15903 and generate the DWARF-2 debugging info. */
15906 dwarf2out_finish (const char *filename)
15908 limbo_die_node *node, *next_node;
15909 dw_die_ref die = 0;
15911 /* Add the name for the main input file now. We delayed this from
15912 dwarf2out_init to avoid complications with PCH. */
15913 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
15914 if (!IS_ABSOLUTE_PATH (filename))
15915 add_comp_dir_attribute (comp_unit_die);
15916 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
15919 htab_traverse (file_table, file_table_relative_p, &p);
15921 add_comp_dir_attribute (comp_unit_die);
15924 /* Traverse the limbo die list, and add parent/child links. The only
15925 dies without parents that should be here are concrete instances of
15926 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15927 For concrete instances, we can get the parent die from the abstract
15929 for (node = limbo_die_list; node; node = next_node)
15931 next_node = node->next;
15934 if (die->die_parent == NULL)
15936 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15939 add_child_die (origin->die_parent, die);
15940 else if (die == comp_unit_die)
15942 else if (errorcount > 0 || sorrycount > 0)
15943 /* It's OK to be confused by errors in the input. */
15944 add_child_die (comp_unit_die, die);
15947 /* In certain situations, the lexical block containing a
15948 nested function can be optimized away, which results
15949 in the nested function die being orphaned. Likewise
15950 with the return type of that nested function. Force
15951 this to be a child of the containing function.
15953 It may happen that even the containing function got fully
15954 inlined and optimized out. In that case we are lost and
15955 assign the empty child. This should not be big issue as
15956 the function is likely unreachable too. */
15957 tree context = NULL_TREE;
15959 gcc_assert (node->created_for);
15961 if (DECL_P (node->created_for))
15962 context = DECL_CONTEXT (node->created_for);
15963 else if (TYPE_P (node->created_for))
15964 context = TYPE_CONTEXT (node->created_for);
15966 gcc_assert (context
15967 && (TREE_CODE (context) == FUNCTION_DECL
15968 || TREE_CODE (context) == NAMESPACE_DECL));
15970 origin = lookup_decl_die (context);
15972 add_child_die (origin, die);
15974 add_child_die (comp_unit_die, die);
15979 limbo_die_list = NULL;
15981 /* Walk through the list of incomplete types again, trying once more to
15982 emit full debugging info for them. */
15983 retry_incomplete_types ();
15985 if (flag_eliminate_unused_debug_types)
15986 prune_unused_types ();
15988 /* Generate separate CUs for each of the include files we've seen.
15989 They will go into limbo_die_list. */
15990 if (flag_eliminate_dwarf2_dups)
15991 break_out_includes (comp_unit_die);
15993 /* Traverse the DIE's and add add sibling attributes to those DIE's
15994 that have children. */
15995 add_sibling_attributes (comp_unit_die);
15996 for (node = limbo_die_list; node; node = node->next)
15997 add_sibling_attributes (node->die);
15999 /* Output a terminator label for the .text section. */
16000 switch_to_section (text_section);
16001 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16002 if (flag_reorder_blocks_and_partition)
16004 switch_to_section (unlikely_text_section ());
16005 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16008 /* We can only use the low/high_pc attributes if all of the code was
16010 if (!have_multiple_function_sections)
16012 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16013 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16018 unsigned fde_idx = 0;
16020 /* We need to give .debug_loc and .debug_ranges an appropriate
16021 "base address". Use zero so that these addresses become
16022 absolute. Historically, we've emitted the unexpected
16023 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16024 Emit both to give time for other tools to adapt. */
16025 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16026 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16028 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16029 add_ranges_by_labels (text_section_label,
16031 if (flag_reorder_blocks_and_partition)
16032 add_ranges_by_labels (cold_text_section_label,
16035 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16037 dw_fde_ref fde = &fde_table[fde_idx];
16039 if (fde->dw_fde_switched_sections)
16041 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16042 fde->dw_fde_hot_section_end_label);
16043 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16044 fde->dw_fde_unlikely_section_end_label);
16047 add_ranges_by_labels (fde->dw_fde_begin,
16054 /* Output location list section if necessary. */
16055 if (have_location_lists)
16057 /* Output the location lists info. */
16058 switch_to_section (debug_loc_section);
16059 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16060 DEBUG_LOC_SECTION_LABEL, 0);
16061 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16062 output_location_lists (die);
16065 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16066 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16067 debug_line_section_label);
16069 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16070 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16072 /* Output all of the compilation units. We put the main one last so that
16073 the offsets are available to output_pubnames. */
16074 for (node = limbo_die_list; node; node = node->next)
16075 output_comp_unit (node->die, 0);
16077 output_comp_unit (comp_unit_die, 0);
16079 /* Output the abbreviation table. */
16080 switch_to_section (debug_abbrev_section);
16081 output_abbrev_section ();
16083 /* Output public names table if necessary. */
16084 if (!VEC_empty (pubname_entry, pubname_table))
16086 switch_to_section (debug_pubnames_section);
16087 output_pubnames (pubname_table);
16090 #ifdef DEBUG_PUBTYPES_SECTION
16091 /* Output public types table if necessary. */
16092 if (!VEC_empty (pubname_entry, pubtype_table))
16094 switch_to_section (debug_pubtypes_section);
16095 output_pubnames (pubtype_table);
16099 /* Output the address range information. We only put functions in the arange
16100 table, so don't write it out if we don't have any. */
16101 if (fde_table_in_use)
16103 switch_to_section (debug_aranges_section);
16107 /* Output ranges section if necessary. */
16108 if (ranges_table_in_use)
16110 switch_to_section (debug_ranges_section);
16111 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16115 /* Output the source line correspondence table. We must do this
16116 even if there is no line information. Otherwise, on an empty
16117 translation unit, we will generate a present, but empty,
16118 .debug_info section. IRIX 6.5 `nm' will then complain when
16119 examining the file. This is done late so that any filenames
16120 used by the debug_info section are marked as 'used'. */
16121 if (! DWARF2_ASM_LINE_DEBUG_INFO)
16123 switch_to_section (debug_line_section);
16124 output_line_info ();
16127 /* Have to end the macro section. */
16128 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16130 switch_to_section (debug_macinfo_section);
16131 dw2_asm_output_data (1, 0, "End compilation unit");
16134 /* If we emitted any DW_FORM_strp form attribute, output the string
16136 if (debug_str_hash)
16137 htab_traverse (debug_str_hash, output_indirect_string, NULL);
16141 /* This should never be used, but its address is needed for comparisons. */
16142 const struct gcc_debug_hooks dwarf2_debug_hooks;
16144 #endif /* DWARF2_DEBUGGING_INFO */
16146 #include "gt-dwarf2out.h"