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 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 2, 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 COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 #ifndef DWARF2_FRAME_INFO
94 # ifdef DWARF2_DEBUGGING_INFO
95 # define DWARF2_FRAME_INFO \
96 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
98 # define DWARF2_FRAME_INFO 0
102 /* Map register numbers held in the call frame info that gcc has
103 collected using DWARF_FRAME_REGNUM to those that should be output in
104 .debug_frame and .eh_frame. */
105 #ifndef DWARF2_FRAME_REG_OUT
106 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
109 /* Decide whether we want to emit frame unwind information for the current
113 dwarf2out_do_frame (void)
115 /* We want to emit correct CFA location expressions or lists, so we
116 have to return true if we're going to output debug info, even if
117 we're not going to output frame or unwind info. */
118 return (write_symbols == DWARF2_DEBUG
119 || write_symbols == VMS_AND_DWARF2_DEBUG
121 #ifdef DWARF2_UNWIND_INFO
122 || (DWARF2_UNWIND_INFO
123 && (flag_unwind_tables
124 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) VEC(rtx,gc) *used_rtx_array;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 VEC(tree,gc) because we want to tell the garbage collector about
142 static GTY(()) VEC(tree,gc) *incomplete_types;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) VEC(tree,gc) *decl_scope_table;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section *debug_info_section;
153 static GTY(()) section *debug_abbrev_section;
154 static GTY(()) section *debug_aranges_section;
155 static GTY(()) section *debug_macinfo_section;
156 static GTY(()) section *debug_line_section;
157 static GTY(()) section *debug_loc_section;
158 static GTY(()) section *debug_pubnames_section;
159 static GTY(()) section *debug_pubtypes_section;
160 static GTY(()) section *debug_str_section;
161 static GTY(()) section *debug_ranges_section;
162 static GTY(()) section *debug_frame_section;
164 /* How to start an assembler comment. */
165 #ifndef ASM_COMMENT_START
166 #define ASM_COMMENT_START ";#"
169 typedef struct dw_cfi_struct *dw_cfi_ref;
170 typedef struct dw_fde_struct *dw_fde_ref;
171 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
173 /* Call frames are described using a sequence of Call Frame
174 Information instructions. The register number, offset
175 and address fields are provided as possible operands;
176 their use is selected by the opcode field. */
178 enum dw_cfi_oprnd_type {
180 dw_cfi_oprnd_reg_num,
186 typedef union dw_cfi_oprnd_struct GTY(())
188 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
189 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
190 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
191 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
195 typedef struct dw_cfi_struct GTY(())
197 dw_cfi_ref dw_cfi_next;
198 enum dwarf_call_frame_info dw_cfi_opc;
199 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
201 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
206 /* This is how we define the location of the CFA. We use to handle it
207 as REG + OFFSET all the time, but now it can be more complex.
208 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
209 Instead of passing around REG and OFFSET, we pass a copy
210 of this structure. */
211 typedef struct cfa_loc GTY(())
213 HOST_WIDE_INT offset;
214 HOST_WIDE_INT base_offset;
216 int indirect; /* 1 if CFA is accessed via a dereference. */
219 /* All call frame descriptions (FDE's) in the GCC generated DWARF
220 refer to a single Common Information Entry (CIE), defined at
221 the beginning of the .debug_frame section. This use of a single
222 CIE obviates the need to keep track of multiple CIE's
223 in the DWARF generation routines below. */
225 typedef struct dw_fde_struct GTY(())
228 const char *dw_fde_begin;
229 const char *dw_fde_current_label;
230 const char *dw_fde_end;
231 const char *dw_fde_hot_section_label;
232 const char *dw_fde_hot_section_end_label;
233 const char *dw_fde_unlikely_section_label;
234 const char *dw_fde_unlikely_section_end_label;
235 bool dw_fde_switched_sections;
236 dw_cfi_ref dw_fde_cfi;
237 unsigned funcdef_number;
238 unsigned all_throwers_are_sibcalls : 1;
239 unsigned nothrow : 1;
240 unsigned uses_eh_lsda : 1;
244 /* Maximum size (in bytes) of an artificially generated label. */
245 #define MAX_ARTIFICIAL_LABEL_BYTES 30
247 /* The size of addresses as they appear in the Dwarf 2 data.
248 Some architectures use word addresses to refer to code locations,
249 but Dwarf 2 info always uses byte addresses. On such machines,
250 Dwarf 2 addresses need to be larger than the architecture's
252 #ifndef DWARF2_ADDR_SIZE
253 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
256 /* The size in bytes of a DWARF field indicating an offset or length
257 relative to a debug info section, specified to be 4 bytes in the
258 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
261 #ifndef DWARF_OFFSET_SIZE
262 #define DWARF_OFFSET_SIZE 4
265 /* According to the (draft) DWARF 3 specification, the initial length
266 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
267 bytes are 0xffffffff, followed by the length stored in the next 8
270 However, the SGI/MIPS ABI uses an initial length which is equal to
271 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
273 #ifndef DWARF_INITIAL_LENGTH_SIZE
274 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
277 #define DWARF_VERSION 2
279 /* Round SIZE up to the nearest BOUNDARY. */
280 #define DWARF_ROUND(SIZE,BOUNDARY) \
281 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
283 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
284 #ifndef DWARF_CIE_DATA_ALIGNMENT
285 #ifdef STACK_GROWS_DOWNWARD
286 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
288 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
292 /* CIE identifier. */
293 #if HOST_BITS_PER_WIDE_INT >= 64
294 #define DWARF_CIE_ID \
295 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
297 #define DWARF_CIE_ID DW_CIE_ID
300 /* A pointer to the base of a table that contains frame description
301 information for each routine. */
302 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
304 /* Number of elements currently allocated for fde_table. */
305 static GTY(()) unsigned fde_table_allocated;
307 /* Number of elements in fde_table currently in use. */
308 static GTY(()) unsigned fde_table_in_use;
310 /* Size (in elements) of increments by which we may expand the
312 #define FDE_TABLE_INCREMENT 256
314 /* A list of call frame insns for the CIE. */
315 static GTY(()) dw_cfi_ref cie_cfi_head;
317 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
318 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
319 attribute that accelerates the lookup of the FDE associated
320 with the subprogram. This variable holds the table index of the FDE
321 associated with the current function (body) definition. */
322 static unsigned current_funcdef_fde;
325 struct indirect_string_node GTY(())
328 unsigned int refcount;
333 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
335 static GTY(()) int dw2_string_counter;
336 static GTY(()) unsigned long dwarf2out_cfi_label_num;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
340 /* Forward declarations for functions defined in this file. */
342 static char *stripattributes (const char *);
343 static const char *dwarf_cfi_name (unsigned);
344 static dw_cfi_ref new_cfi (void);
345 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
346 static void add_fde_cfi (const char *, dw_cfi_ref);
347 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
348 static void lookup_cfa (dw_cfa_location *);
349 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
350 static void initial_return_save (rtx);
351 static HOST_WIDE_INT stack_adjust_offset (rtx);
352 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
353 static void output_call_frame_info (int);
354 static void dwarf2out_stack_adjust (rtx, bool);
355 static void flush_queued_reg_saves (void);
356 static bool clobbers_queued_reg_save (rtx);
357 static void dwarf2out_frame_debug_expr (rtx, const char *);
359 /* Support for complex CFA locations. */
360 static void output_cfa_loc (dw_cfi_ref);
361 static void get_cfa_from_loc_descr (dw_cfa_location *,
362 struct dw_loc_descr_struct *);
363 static struct dw_loc_descr_struct *build_cfa_loc
364 (dw_cfa_location *, HOST_WIDE_INT);
365 static void def_cfa_1 (const char *, dw_cfa_location *);
367 /* How to start an assembler comment. */
368 #ifndef ASM_COMMENT_START
369 #define ASM_COMMENT_START ";#"
372 /* Data and reference forms for relocatable data. */
373 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
374 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
376 #ifndef DEBUG_FRAME_SECTION
377 #define DEBUG_FRAME_SECTION ".debug_frame"
380 #ifndef FUNC_BEGIN_LABEL
381 #define FUNC_BEGIN_LABEL "LFB"
384 #ifndef FUNC_END_LABEL
385 #define FUNC_END_LABEL "LFE"
388 #ifndef FRAME_BEGIN_LABEL
389 #define FRAME_BEGIN_LABEL "Lframe"
391 #define CIE_AFTER_SIZE_LABEL "LSCIE"
392 #define CIE_END_LABEL "LECIE"
393 #define FDE_LABEL "LSFDE"
394 #define FDE_AFTER_SIZE_LABEL "LASFDE"
395 #define FDE_END_LABEL "LEFDE"
396 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
397 #define LINE_NUMBER_END_LABEL "LELT"
398 #define LN_PROLOG_AS_LABEL "LASLTP"
399 #define LN_PROLOG_END_LABEL "LELTP"
400 #define DIE_LABEL_PREFIX "DW"
402 /* The DWARF 2 CFA column which tracks the return address. Normally this
403 is the column for PC, or the first column after all of the hard
405 #ifndef DWARF_FRAME_RETURN_COLUMN
407 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
409 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
413 /* The mapping from gcc register number to DWARF 2 CFA column number. By
414 default, we just provide columns for all registers. */
415 #ifndef DWARF_FRAME_REGNUM
416 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
419 /* Hook used by __throw. */
422 expand_builtin_dwarf_sp_column (void)
424 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
425 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
428 /* Return a pointer to a copy of the section string name S with all
429 attributes stripped off, and an asterisk prepended (for assemble_name). */
432 stripattributes (const char *s)
434 char *stripped = XNEWVEC (char, strlen (s) + 2);
439 while (*s && *s != ',')
446 /* MEM is a memory reference for the register size table, each element of
447 which has mode MODE. Initialize column C as a return address column. */
450 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
452 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
453 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
454 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
457 /* Generate code to initialize the register size table. */
460 expand_builtin_init_dwarf_reg_sizes (tree address)
463 enum machine_mode mode = TYPE_MODE (char_type_node);
464 rtx addr = expand_normal (address);
465 rtx mem = gen_rtx_MEM (BLKmode, addr);
466 bool wrote_return_column = false;
468 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
470 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
472 if (rnum < DWARF_FRAME_REGISTERS)
474 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
475 enum machine_mode save_mode = reg_raw_mode[i];
478 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
479 save_mode = choose_hard_reg_mode (i, 1, true);
480 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
482 if (save_mode == VOIDmode)
484 wrote_return_column = true;
486 size = GET_MODE_SIZE (save_mode);
490 emit_move_insn (adjust_address (mem, mode, offset),
491 gen_int_mode (size, mode));
495 if (!wrote_return_column)
496 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
498 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
499 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
502 targetm.init_dwarf_reg_sizes_extra (address);
505 /* Convert a DWARF call frame info. operation to its string name */
508 dwarf_cfi_name (unsigned int cfi_opc)
512 case DW_CFA_advance_loc:
513 return "DW_CFA_advance_loc";
515 return "DW_CFA_offset";
517 return "DW_CFA_restore";
521 return "DW_CFA_set_loc";
522 case DW_CFA_advance_loc1:
523 return "DW_CFA_advance_loc1";
524 case DW_CFA_advance_loc2:
525 return "DW_CFA_advance_loc2";
526 case DW_CFA_advance_loc4:
527 return "DW_CFA_advance_loc4";
528 case DW_CFA_offset_extended:
529 return "DW_CFA_offset_extended";
530 case DW_CFA_restore_extended:
531 return "DW_CFA_restore_extended";
532 case DW_CFA_undefined:
533 return "DW_CFA_undefined";
534 case DW_CFA_same_value:
535 return "DW_CFA_same_value";
536 case DW_CFA_register:
537 return "DW_CFA_register";
538 case DW_CFA_remember_state:
539 return "DW_CFA_remember_state";
540 case DW_CFA_restore_state:
541 return "DW_CFA_restore_state";
543 return "DW_CFA_def_cfa";
544 case DW_CFA_def_cfa_register:
545 return "DW_CFA_def_cfa_register";
546 case DW_CFA_def_cfa_offset:
547 return "DW_CFA_def_cfa_offset";
550 case DW_CFA_def_cfa_expression:
551 return "DW_CFA_def_cfa_expression";
552 case DW_CFA_expression:
553 return "DW_CFA_expression";
554 case DW_CFA_offset_extended_sf:
555 return "DW_CFA_offset_extended_sf";
556 case DW_CFA_def_cfa_sf:
557 return "DW_CFA_def_cfa_sf";
558 case DW_CFA_def_cfa_offset_sf:
559 return "DW_CFA_def_cfa_offset_sf";
561 /* SGI/MIPS specific */
562 case DW_CFA_MIPS_advance_loc8:
563 return "DW_CFA_MIPS_advance_loc8";
566 case DW_CFA_GNU_window_save:
567 return "DW_CFA_GNU_window_save";
568 case DW_CFA_GNU_args_size:
569 return "DW_CFA_GNU_args_size";
570 case DW_CFA_GNU_negative_offset_extended:
571 return "DW_CFA_GNU_negative_offset_extended";
574 return "DW_CFA_<unknown>";
578 /* Return a pointer to a newly allocated Call Frame Instruction. */
580 static inline dw_cfi_ref
583 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
585 cfi->dw_cfi_next = NULL;
586 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
587 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
592 /* Add a Call Frame Instruction to list of instructions. */
595 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
599 /* Find the end of the chain. */
600 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
606 /* Generate a new label for the CFI info to refer to. */
609 dwarf2out_cfi_label (void)
611 static char label[20];
613 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
614 ASM_OUTPUT_LABEL (asm_out_file, label);
618 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
619 or to the CIE if LABEL is NULL. */
622 add_fde_cfi (const char *label, dw_cfi_ref cfi)
626 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
629 label = dwarf2out_cfi_label ();
631 if (fde->dw_fde_current_label == NULL
632 || strcmp (label, fde->dw_fde_current_label) != 0)
636 label = xstrdup (label);
638 /* Set the location counter to the new label. */
640 /* If we have a current label, advance from there, otherwise
641 set the location directly using set_loc. */
642 xcfi->dw_cfi_opc = fde->dw_fde_current_label
643 ? DW_CFA_advance_loc4
645 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
646 add_cfi (&fde->dw_fde_cfi, xcfi);
648 fde->dw_fde_current_label = label;
651 add_cfi (&fde->dw_fde_cfi, cfi);
655 add_cfi (&cie_cfi_head, cfi);
658 /* Subroutine of lookup_cfa. */
661 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
663 switch (cfi->dw_cfi_opc)
665 case DW_CFA_def_cfa_offset:
666 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
668 case DW_CFA_def_cfa_offset_sf:
670 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
672 case DW_CFA_def_cfa_register:
673 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
676 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
677 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
679 case DW_CFA_def_cfa_sf:
680 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
682 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
684 case DW_CFA_def_cfa_expression:
685 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
692 /* Find the previous value for the CFA. */
695 lookup_cfa (dw_cfa_location *loc)
699 loc->reg = INVALID_REGNUM;
702 loc->base_offset = 0;
704 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
705 lookup_cfa_1 (cfi, loc);
707 if (fde_table_in_use)
709 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
710 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
711 lookup_cfa_1 (cfi, loc);
715 /* The current rule for calculating the DWARF2 canonical frame address. */
716 static dw_cfa_location cfa;
718 /* The register used for saving registers to the stack, and its offset
720 static dw_cfa_location cfa_store;
722 /* The running total of the size of arguments pushed onto the stack. */
723 static HOST_WIDE_INT args_size;
725 /* The last args_size we actually output. */
726 static HOST_WIDE_INT old_args_size;
728 /* Entry point to update the canonical frame address (CFA).
729 LABEL is passed to add_fde_cfi. The value of CFA is now to be
730 calculated from REG+OFFSET. */
733 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
740 def_cfa_1 (label, &loc);
743 /* Determine if two dw_cfa_location structures define the same data. */
746 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
748 return (loc1->reg == loc2->reg
749 && loc1->offset == loc2->offset
750 && loc1->indirect == loc2->indirect
751 && (loc1->indirect == 0
752 || loc1->base_offset == loc2->base_offset));
755 /* This routine does the actual work. The CFA is now calculated from
756 the dw_cfa_location structure. */
759 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
762 dw_cfa_location old_cfa, loc;
767 if (cfa_store.reg == loc.reg && loc.indirect == 0)
768 cfa_store.offset = loc.offset;
770 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
771 lookup_cfa (&old_cfa);
773 /* If nothing changed, no need to issue any call frame instructions. */
774 if (cfa_equal_p (&loc, &old_cfa))
779 if (loc.reg == old_cfa.reg && !loc.indirect)
781 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
782 the CFA register did not change but the offset did. */
785 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
786 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
788 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
789 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
793 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
794 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
798 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
799 else if (loc.offset == old_cfa.offset
800 && old_cfa.reg != INVALID_REGNUM
803 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
804 indicating the CFA register has changed to <register> but the
805 offset has not changed. */
806 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
807 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
811 else if (loc.indirect == 0)
813 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
814 indicating the CFA register has changed to <register> with
815 the specified offset. */
818 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
819 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
821 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
822 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
823 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
827 cfi->dw_cfi_opc = DW_CFA_def_cfa;
828 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
834 /* Construct a DW_CFA_def_cfa_expression instruction to
835 calculate the CFA using a full location expression since no
836 register-offset pair is available. */
837 struct dw_loc_descr_struct *loc_list;
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
840 loc_list = build_cfa_loc (&loc, 0);
841 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
844 add_fde_cfi (label, cfi);
847 /* Add the CFI for saving a register. REG is the CFA column number.
848 LABEL is passed to add_fde_cfi.
849 If SREG is -1, the register is saved at OFFSET from the CFA;
850 otherwise it is saved in SREG. */
853 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
855 dw_cfi_ref cfi = new_cfi ();
857 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
859 if (sreg == INVALID_REGNUM)
862 /* The register number won't fit in 6 bits, so we have to use
864 cfi->dw_cfi_opc = DW_CFA_offset_extended;
866 cfi->dw_cfi_opc = DW_CFA_offset;
868 #ifdef ENABLE_CHECKING
870 /* If we get an offset that is not a multiple of
871 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
872 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
874 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
876 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
879 offset /= DWARF_CIE_DATA_ALIGNMENT;
881 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
883 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
885 else if (sreg == reg)
886 cfi->dw_cfi_opc = DW_CFA_same_value;
889 cfi->dw_cfi_opc = DW_CFA_register;
890 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
893 add_fde_cfi (label, cfi);
896 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
897 This CFI tells the unwinder that it needs to restore the window registers
898 from the previous frame's window save area.
900 ??? Perhaps we should note in the CIE where windows are saved (instead of
901 assuming 0(cfa)) and what registers are in the window. */
904 dwarf2out_window_save (const char *label)
906 dw_cfi_ref cfi = new_cfi ();
908 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
909 add_fde_cfi (label, cfi);
912 /* Add a CFI to update the running total of the size of arguments
913 pushed onto the stack. */
916 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
920 if (size == old_args_size)
923 old_args_size = size;
926 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
927 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
928 add_fde_cfi (label, cfi);
931 /* Entry point for saving a register to the stack. REG is the GCC register
932 number. LABEL and OFFSET are passed to reg_save. */
935 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
937 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
940 /* Entry point for saving the return address in the stack.
941 LABEL and OFFSET are passed to reg_save. */
944 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
946 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
949 /* Entry point for saving the return address in a register.
950 LABEL and SREG are passed to reg_save. */
953 dwarf2out_return_reg (const char *label, unsigned int sreg)
955 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
958 /* Record the initial position of the return address. RTL is
959 INCOMING_RETURN_ADDR_RTX. */
962 initial_return_save (rtx rtl)
964 unsigned int reg = INVALID_REGNUM;
965 HOST_WIDE_INT offset = 0;
967 switch (GET_CODE (rtl))
970 /* RA is in a register. */
971 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
975 /* RA is on the stack. */
977 switch (GET_CODE (rtl))
980 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
985 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
986 offset = INTVAL (XEXP (rtl, 1));
990 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
991 offset = -INTVAL (XEXP (rtl, 1));
1001 /* The return address is at some offset from any value we can
1002 actually load. For instance, on the SPARC it is in %i7+8. Just
1003 ignore the offset for now; it doesn't matter for unwinding frames. */
1004 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1005 initial_return_save (XEXP (rtl, 0));
1012 if (reg != DWARF_FRAME_RETURN_COLUMN)
1013 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1016 /* Given a SET, calculate the amount of stack adjustment it
1019 static HOST_WIDE_INT
1020 stack_adjust_offset (rtx pattern)
1022 rtx src = SET_SRC (pattern);
1023 rtx dest = SET_DEST (pattern);
1024 HOST_WIDE_INT offset = 0;
1027 if (dest == stack_pointer_rtx)
1029 /* (set (reg sp) (plus (reg sp) (const_int))) */
1030 code = GET_CODE (src);
1031 if (! (code == PLUS || code == MINUS)
1032 || XEXP (src, 0) != stack_pointer_rtx
1033 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1036 offset = INTVAL (XEXP (src, 1));
1040 else if (MEM_P (dest))
1042 /* (set (mem (pre_dec (reg sp))) (foo)) */
1043 src = XEXP (dest, 0);
1044 code = GET_CODE (src);
1050 if (XEXP (src, 0) == stack_pointer_rtx)
1052 rtx val = XEXP (XEXP (src, 1), 1);
1053 /* We handle only adjustments by constant amount. */
1054 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1055 && GET_CODE (val) == CONST_INT);
1056 offset = -INTVAL (val);
1063 if (XEXP (src, 0) == stack_pointer_rtx)
1065 offset = GET_MODE_SIZE (GET_MODE (dest));
1072 if (XEXP (src, 0) == stack_pointer_rtx)
1074 offset = -GET_MODE_SIZE (GET_MODE (dest));
1089 /* Check INSN to see if it looks like a push or a stack adjustment, and
1090 make a note of it if it does. EH uses this information to find out how
1091 much extra space it needs to pop off the stack. */
1094 dwarf2out_stack_adjust (rtx insn, bool after_p)
1096 HOST_WIDE_INT offset;
1100 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1101 with this function. Proper support would require all frame-related
1102 insns to be marked, and to be able to handle saving state around
1103 epilogues textually in the middle of the function. */
1104 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1107 /* If only calls can throw, and we have a frame pointer,
1108 save up adjustments until we see the CALL_INSN. */
1109 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1111 if (CALL_P (insn) && !after_p)
1113 /* Extract the size of the args from the CALL rtx itself. */
1114 insn = PATTERN (insn);
1115 if (GET_CODE (insn) == PARALLEL)
1116 insn = XVECEXP (insn, 0, 0);
1117 if (GET_CODE (insn) == SET)
1118 insn = SET_SRC (insn);
1119 gcc_assert (GET_CODE (insn) == CALL);
1120 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1125 if (CALL_P (insn) && !after_p)
1127 if (!flag_asynchronous_unwind_tables)
1128 dwarf2out_args_size ("", args_size);
1131 else if (BARRIER_P (insn))
1133 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1134 the compiler will have already emitted a stack adjustment, but
1135 doesn't bother for calls to noreturn functions. */
1136 #ifdef STACK_GROWS_DOWNWARD
1137 offset = -args_size;
1142 else if (GET_CODE (PATTERN (insn)) == SET)
1143 offset = stack_adjust_offset (PATTERN (insn));
1144 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1145 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1147 /* There may be stack adjustments inside compound insns. Search
1149 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1150 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1151 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1159 if (cfa.reg == STACK_POINTER_REGNUM)
1160 cfa.offset += offset;
1162 #ifndef STACK_GROWS_DOWNWARD
1166 args_size += offset;
1170 label = dwarf2out_cfi_label ();
1171 def_cfa_1 (label, &cfa);
1172 if (flag_asynchronous_unwind_tables)
1173 dwarf2out_args_size (label, args_size);
1178 /* We delay emitting a register save until either (a) we reach the end
1179 of the prologue or (b) the register is clobbered. This clusters
1180 register saves so that there are fewer pc advances. */
1182 struct queued_reg_save GTY(())
1184 struct queued_reg_save *next;
1186 HOST_WIDE_INT cfa_offset;
1190 static GTY(()) struct queued_reg_save *queued_reg_saves;
1192 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1193 struct reg_saved_in_data GTY(()) {
1198 /* A list of registers saved in other registers.
1199 The list intentionally has a small maximum capacity of 4; if your
1200 port needs more than that, you might consider implementing a
1201 more efficient data structure. */
1202 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1203 static GTY(()) size_t num_regs_saved_in_regs;
1205 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1206 static const char *last_reg_save_label;
1208 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1209 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1212 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1214 struct queued_reg_save *q;
1216 /* Duplicates waste space, but it's also necessary to remove them
1217 for correctness, since the queue gets output in reverse
1219 for (q = queued_reg_saves; q != NULL; q = q->next)
1220 if (REGNO (q->reg) == REGNO (reg))
1225 q = ggc_alloc (sizeof (*q));
1226 q->next = queued_reg_saves;
1227 queued_reg_saves = q;
1231 q->cfa_offset = offset;
1232 q->saved_reg = sreg;
1234 last_reg_save_label = label;
1237 /* Output all the entries in QUEUED_REG_SAVES. */
1240 flush_queued_reg_saves (void)
1242 struct queued_reg_save *q;
1244 for (q = queued_reg_saves; q; q = q->next)
1247 unsigned int reg, sreg;
1249 for (i = 0; i < num_regs_saved_in_regs; i++)
1250 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1252 if (q->saved_reg && i == num_regs_saved_in_regs)
1254 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1255 num_regs_saved_in_regs++;
1257 if (i != num_regs_saved_in_regs)
1259 regs_saved_in_regs[i].orig_reg = q->reg;
1260 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1263 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1265 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1267 sreg = INVALID_REGNUM;
1268 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1271 queued_reg_saves = NULL;
1272 last_reg_save_label = NULL;
1275 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1276 location for? Or, does it clobber a register which we've previously
1277 said that some other register is saved in, and for which we now
1278 have a new location for? */
1281 clobbers_queued_reg_save (rtx insn)
1283 struct queued_reg_save *q;
1285 for (q = queued_reg_saves; q; q = q->next)
1288 if (modified_in_p (q->reg, insn))
1290 for (i = 0; i < num_regs_saved_in_regs; i++)
1291 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1292 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1299 /* Entry point for saving the first register into the second. */
1302 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1305 unsigned int regno, sregno;
1307 for (i = 0; i < num_regs_saved_in_regs; i++)
1308 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1310 if (i == num_regs_saved_in_regs)
1312 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1313 num_regs_saved_in_regs++;
1315 regs_saved_in_regs[i].orig_reg = reg;
1316 regs_saved_in_regs[i].saved_in_reg = sreg;
1318 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1319 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1320 reg_save (label, regno, sregno, 0);
1323 /* What register, if any, is currently saved in REG? */
1326 reg_saved_in (rtx reg)
1328 unsigned int regn = REGNO (reg);
1330 struct queued_reg_save *q;
1332 for (q = queued_reg_saves; q; q = q->next)
1333 if (q->saved_reg && regn == REGNO (q->saved_reg))
1336 for (i = 0; i < num_regs_saved_in_regs; i++)
1337 if (regs_saved_in_regs[i].saved_in_reg
1338 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1339 return regs_saved_in_regs[i].orig_reg;
1345 /* A temporary register holding an integral value used in adjusting SP
1346 or setting up the store_reg. The "offset" field holds the integer
1347 value, not an offset. */
1348 static dw_cfa_location cfa_temp;
1350 /* Record call frame debugging information for an expression EXPR,
1351 which either sets SP or FP (adjusting how we calculate the frame
1352 address) or saves a register to the stack or another register.
1353 LABEL indicates the address of EXPR.
1355 This function encodes a state machine mapping rtxes to actions on
1356 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1357 users need not read the source code.
1359 The High-Level Picture
1361 Changes in the register we use to calculate the CFA: Currently we
1362 assume that if you copy the CFA register into another register, we
1363 should take the other one as the new CFA register; this seems to
1364 work pretty well. If it's wrong for some target, it's simple
1365 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1367 Changes in the register we use for saving registers to the stack:
1368 This is usually SP, but not always. Again, we deduce that if you
1369 copy SP into another register (and SP is not the CFA register),
1370 then the new register is the one we will be using for register
1371 saves. This also seems to work.
1373 Register saves: There's not much guesswork about this one; if
1374 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1375 register save, and the register used to calculate the destination
1376 had better be the one we think we're using for this purpose.
1377 It's also assumed that a copy from a call-saved register to another
1378 register is saving that register if RTX_FRAME_RELATED_P is set on
1379 that instruction. If the copy is from a call-saved register to
1380 the *same* register, that means that the register is now the same
1381 value as in the caller.
1383 Except: If the register being saved is the CFA register, and the
1384 offset is nonzero, we are saving the CFA, so we assume we have to
1385 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1386 the intent is to save the value of SP from the previous frame.
1388 In addition, if a register has previously been saved to a different
1391 Invariants / Summaries of Rules
1393 cfa current rule for calculating the CFA. It usually
1394 consists of a register and an offset.
1395 cfa_store register used by prologue code to save things to the stack
1396 cfa_store.offset is the offset from the value of
1397 cfa_store.reg to the actual CFA
1398 cfa_temp register holding an integral value. cfa_temp.offset
1399 stores the value, which will be used to adjust the
1400 stack pointer. cfa_temp is also used like cfa_store,
1401 to track stores to the stack via fp or a temp reg.
1403 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1404 with cfa.reg as the first operand changes the cfa.reg and its
1405 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1408 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1409 expression yielding a constant. This sets cfa_temp.reg
1410 and cfa_temp.offset.
1412 Rule 5: Create a new register cfa_store used to save items to the
1415 Rules 10-14: Save a register to the stack. Define offset as the
1416 difference of the original location and cfa_store's
1417 location (or cfa_temp's location if cfa_temp is used).
1421 "{a,b}" indicates a choice of a xor b.
1422 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1425 (set <reg1> <reg2>:cfa.reg)
1426 effects: cfa.reg = <reg1>
1427 cfa.offset unchanged
1428 cfa_temp.reg = <reg1>
1429 cfa_temp.offset = cfa.offset
1432 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1433 {<const_int>,<reg>:cfa_temp.reg}))
1434 effects: cfa.reg = sp if fp used
1435 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1436 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1437 if cfa_store.reg==sp
1440 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1441 effects: cfa.reg = fp
1442 cfa_offset += +/- <const_int>
1445 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1446 constraints: <reg1> != fp
1448 effects: cfa.reg = <reg1>
1449 cfa_temp.reg = <reg1>
1450 cfa_temp.offset = cfa.offset
1453 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1454 constraints: <reg1> != fp
1456 effects: cfa_store.reg = <reg1>
1457 cfa_store.offset = cfa.offset - cfa_temp.offset
1460 (set <reg> <const_int>)
1461 effects: cfa_temp.reg = <reg>
1462 cfa_temp.offset = <const_int>
1465 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1466 effects: cfa_temp.reg = <reg1>
1467 cfa_temp.offset |= <const_int>
1470 (set <reg> (high <exp>))
1474 (set <reg> (lo_sum <exp> <const_int>))
1475 effects: cfa_temp.reg = <reg>
1476 cfa_temp.offset = <const_int>
1479 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1480 effects: cfa_store.offset -= <const_int>
1481 cfa.offset = cfa_store.offset if cfa.reg == sp
1483 cfa.base_offset = -cfa_store.offset
1486 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1487 effects: cfa_store.offset += -/+ mode_size(mem)
1488 cfa.offset = cfa_store.offset if cfa.reg == sp
1490 cfa.base_offset = -cfa_store.offset
1493 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1496 effects: cfa.reg = <reg1>
1497 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1500 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1501 effects: cfa.reg = <reg1>
1502 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1505 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1506 effects: cfa.reg = <reg1>
1507 cfa.base_offset = -cfa_temp.offset
1508 cfa_temp.offset -= mode_size(mem)
1511 (set <reg> {unspec, unspec_volatile})
1512 effects: target-dependent */
1515 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1518 HOST_WIDE_INT offset;
1520 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1521 the PARALLEL independently. The first element is always processed if
1522 it is a SET. This is for backward compatibility. Other elements
1523 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1524 flag is set in them. */
1525 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1528 int limit = XVECLEN (expr, 0);
1531 /* PARALLELs have strict read-modify-write semantics, so we
1532 ought to evaluate every rvalue before changing any lvalue.
1533 It's cumbersome to do that in general, but there's an
1534 easy approximation that is enough for all current users:
1535 handle register saves before register assignments. */
1536 if (GET_CODE (expr) == PARALLEL)
1537 for (par_index = 0; par_index < limit; par_index++)
1539 elem = XVECEXP (expr, 0, par_index);
1540 if (GET_CODE (elem) == SET
1541 && MEM_P (SET_DEST (elem))
1542 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1543 dwarf2out_frame_debug_expr (elem, label);
1546 for (par_index = 0; par_index < limit; par_index++)
1548 elem = XVECEXP (expr, 0, par_index);
1549 if (GET_CODE (elem) == SET
1550 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1551 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1552 dwarf2out_frame_debug_expr (elem, label);
1557 gcc_assert (GET_CODE (expr) == SET);
1559 src = SET_SRC (expr);
1560 dest = SET_DEST (expr);
1564 rtx rsi = reg_saved_in (src);
1569 switch (GET_CODE (dest))
1572 switch (GET_CODE (src))
1574 /* Setting FP from SP. */
1576 if (cfa.reg == (unsigned) REGNO (src))
1579 /* Update the CFA rule wrt SP or FP. Make sure src is
1580 relative to the current CFA register.
1582 We used to require that dest be either SP or FP, but the
1583 ARM copies SP to a temporary register, and from there to
1584 FP. So we just rely on the backends to only set
1585 RTX_FRAME_RELATED_P on appropriate insns. */
1586 cfa.reg = REGNO (dest);
1587 cfa_temp.reg = cfa.reg;
1588 cfa_temp.offset = cfa.offset;
1592 /* Saving a register in a register. */
1593 gcc_assert (!fixed_regs [REGNO (dest)]
1594 /* For the SPARC and its register window. */
1595 || (DWARF_FRAME_REGNUM (REGNO (src))
1596 == DWARF_FRAME_RETURN_COLUMN));
1597 queue_reg_save (label, src, dest, 0);
1604 if (dest == stack_pointer_rtx)
1608 switch (GET_CODE (XEXP (src, 1)))
1611 offset = INTVAL (XEXP (src, 1));
1614 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1616 offset = cfa_temp.offset;
1622 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1624 /* Restoring SP from FP in the epilogue. */
1625 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1626 cfa.reg = STACK_POINTER_REGNUM;
1628 else if (GET_CODE (src) == LO_SUM)
1629 /* Assume we've set the source reg of the LO_SUM from sp. */
1632 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1634 if (GET_CODE (src) != MINUS)
1636 if (cfa.reg == STACK_POINTER_REGNUM)
1637 cfa.offset += offset;
1638 if (cfa_store.reg == STACK_POINTER_REGNUM)
1639 cfa_store.offset += offset;
1641 else if (dest == hard_frame_pointer_rtx)
1644 /* Either setting the FP from an offset of the SP,
1645 or adjusting the FP */
1646 gcc_assert (frame_pointer_needed);
1648 gcc_assert (REG_P (XEXP (src, 0))
1649 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1650 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1651 offset = INTVAL (XEXP (src, 1));
1652 if (GET_CODE (src) != MINUS)
1654 cfa.offset += offset;
1655 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1659 gcc_assert (GET_CODE (src) != MINUS);
1662 if (REG_P (XEXP (src, 0))
1663 && REGNO (XEXP (src, 0)) == cfa.reg
1664 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1666 /* Setting a temporary CFA register that will be copied
1667 into the FP later on. */
1668 offset = - INTVAL (XEXP (src, 1));
1669 cfa.offset += offset;
1670 cfa.reg = REGNO (dest);
1671 /* Or used to save regs to the stack. */
1672 cfa_temp.reg = cfa.reg;
1673 cfa_temp.offset = cfa.offset;
1677 else if (REG_P (XEXP (src, 0))
1678 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1679 && XEXP (src, 1) == stack_pointer_rtx)
1681 /* Setting a scratch register that we will use instead
1682 of SP for saving registers to the stack. */
1683 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1684 cfa_store.reg = REGNO (dest);
1685 cfa_store.offset = cfa.offset - cfa_temp.offset;
1689 else if (GET_CODE (src) == LO_SUM
1690 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1692 cfa_temp.reg = REGNO (dest);
1693 cfa_temp.offset = INTVAL (XEXP (src, 1));
1702 cfa_temp.reg = REGNO (dest);
1703 cfa_temp.offset = INTVAL (src);
1708 gcc_assert (REG_P (XEXP (src, 0))
1709 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1710 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1712 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1713 cfa_temp.reg = REGNO (dest);
1714 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1717 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1718 which will fill in all of the bits. */
1725 case UNSPEC_VOLATILE:
1726 gcc_assert (targetm.dwarf_handle_frame_unspec);
1727 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1734 def_cfa_1 (label, &cfa);
1738 gcc_assert (REG_P (src));
1740 /* Saving a register to the stack. Make sure dest is relative to the
1742 switch (GET_CODE (XEXP (dest, 0)))
1747 /* We can't handle variable size modifications. */
1748 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1750 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1752 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1753 && cfa_store.reg == STACK_POINTER_REGNUM);
1755 cfa_store.offset += offset;
1756 if (cfa.reg == STACK_POINTER_REGNUM)
1757 cfa.offset = cfa_store.offset;
1759 offset = -cfa_store.offset;
1765 offset = GET_MODE_SIZE (GET_MODE (dest));
1766 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1769 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1770 && cfa_store.reg == STACK_POINTER_REGNUM);
1772 cfa_store.offset += offset;
1773 if (cfa.reg == STACK_POINTER_REGNUM)
1774 cfa.offset = cfa_store.offset;
1776 offset = -cfa_store.offset;
1780 /* With an offset. */
1787 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1788 && REG_P (XEXP (XEXP (dest, 0), 0)));
1789 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1790 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1793 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1795 if (cfa_store.reg == (unsigned) regno)
1796 offset -= cfa_store.offset;
1799 gcc_assert (cfa_temp.reg == (unsigned) regno);
1800 offset -= cfa_temp.offset;
1806 /* Without an offset. */
1809 int regno = REGNO (XEXP (dest, 0));
1811 if (cfa_store.reg == (unsigned) regno)
1812 offset = -cfa_store.offset;
1815 gcc_assert (cfa_temp.reg == (unsigned) regno);
1816 offset = -cfa_temp.offset;
1823 gcc_assert (cfa_temp.reg
1824 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1825 offset = -cfa_temp.offset;
1826 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1833 if (REGNO (src) != STACK_POINTER_REGNUM
1834 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1835 && (unsigned) REGNO (src) == cfa.reg)
1837 /* We're storing the current CFA reg into the stack. */
1839 if (cfa.offset == 0)
1841 /* If the source register is exactly the CFA, assume
1842 we're saving SP like any other register; this happens
1844 def_cfa_1 (label, &cfa);
1845 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1850 /* Otherwise, we'll need to look in the stack to
1851 calculate the CFA. */
1852 rtx x = XEXP (dest, 0);
1856 gcc_assert (REG_P (x));
1858 cfa.reg = REGNO (x);
1859 cfa.base_offset = offset;
1861 def_cfa_1 (label, &cfa);
1866 def_cfa_1 (label, &cfa);
1867 queue_reg_save (label, src, NULL_RTX, offset);
1875 /* Record call frame debugging information for INSN, which either
1876 sets SP or FP (adjusting how we calculate the frame address) or saves a
1877 register to the stack. If INSN is NULL_RTX, initialize our state.
1879 If AFTER_P is false, we're being called before the insn is emitted,
1880 otherwise after. Call instructions get invoked twice. */
1883 dwarf2out_frame_debug (rtx insn, bool after_p)
1888 if (insn == NULL_RTX)
1892 /* Flush any queued register saves. */
1893 flush_queued_reg_saves ();
1895 /* Set up state for generating call frame debug info. */
1898 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1900 cfa.reg = STACK_POINTER_REGNUM;
1903 cfa_temp.offset = 0;
1905 for (i = 0; i < num_regs_saved_in_regs; i++)
1907 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1908 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1910 num_regs_saved_in_regs = 0;
1914 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1915 flush_queued_reg_saves ();
1917 if (! RTX_FRAME_RELATED_P (insn))
1919 if (!ACCUMULATE_OUTGOING_ARGS)
1920 dwarf2out_stack_adjust (insn, after_p);
1924 label = dwarf2out_cfi_label ();
1925 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1927 insn = XEXP (src, 0);
1929 insn = PATTERN (insn);
1931 dwarf2out_frame_debug_expr (insn, label);
1936 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1937 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1938 (enum dwarf_call_frame_info cfi);
1940 static enum dw_cfi_oprnd_type
1941 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1946 case DW_CFA_GNU_window_save:
1947 return dw_cfi_oprnd_unused;
1949 case DW_CFA_set_loc:
1950 case DW_CFA_advance_loc1:
1951 case DW_CFA_advance_loc2:
1952 case DW_CFA_advance_loc4:
1953 case DW_CFA_MIPS_advance_loc8:
1954 return dw_cfi_oprnd_addr;
1957 case DW_CFA_offset_extended:
1958 case DW_CFA_def_cfa:
1959 case DW_CFA_offset_extended_sf:
1960 case DW_CFA_def_cfa_sf:
1961 case DW_CFA_restore_extended:
1962 case DW_CFA_undefined:
1963 case DW_CFA_same_value:
1964 case DW_CFA_def_cfa_register:
1965 case DW_CFA_register:
1966 return dw_cfi_oprnd_reg_num;
1968 case DW_CFA_def_cfa_offset:
1969 case DW_CFA_GNU_args_size:
1970 case DW_CFA_def_cfa_offset_sf:
1971 return dw_cfi_oprnd_offset;
1973 case DW_CFA_def_cfa_expression:
1974 case DW_CFA_expression:
1975 return dw_cfi_oprnd_loc;
1982 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1983 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1984 (enum dwarf_call_frame_info cfi);
1986 static enum dw_cfi_oprnd_type
1987 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1991 case DW_CFA_def_cfa:
1992 case DW_CFA_def_cfa_sf:
1994 case DW_CFA_offset_extended_sf:
1995 case DW_CFA_offset_extended:
1996 return dw_cfi_oprnd_offset;
1998 case DW_CFA_register:
1999 return dw_cfi_oprnd_reg_num;
2002 return dw_cfi_oprnd_unused;
2006 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2008 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2009 switch to the data section instead, and write out a synthetic label
2013 switch_to_eh_frame_section (void)
2017 #ifdef EH_FRAME_SECTION_NAME
2018 if (eh_frame_section == 0)
2022 if (EH_TABLES_CAN_BE_READ_ONLY)
2028 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2030 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2032 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2034 flags = ((! flag_pic
2035 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2036 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2037 && (per_encoding & 0x70) != DW_EH_PE_absptr
2038 && (per_encoding & 0x70) != DW_EH_PE_aligned
2039 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2040 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2041 ? 0 : SECTION_WRITE);
2044 flags = SECTION_WRITE;
2045 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2049 if (eh_frame_section)
2050 switch_to_section (eh_frame_section);
2053 /* We have no special eh_frame section. Put the information in
2054 the data section and emit special labels to guide collect2. */
2055 switch_to_section (data_section);
2056 label = get_file_function_name ("F");
2057 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2058 targetm.asm_out.globalize_label (asm_out_file,
2059 IDENTIFIER_POINTER (label));
2060 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2064 /* Output a Call Frame Information opcode and its operand(s). */
2067 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2070 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2071 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2072 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2073 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2074 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2075 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2077 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2078 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2079 "DW_CFA_offset, column 0x%lx", r);
2080 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2082 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2084 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2085 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2086 "DW_CFA_restore, column 0x%lx", r);
2090 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2091 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2093 switch (cfi->dw_cfi_opc)
2095 case DW_CFA_set_loc:
2097 dw2_asm_output_encoded_addr_rtx (
2098 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2099 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2102 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2103 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2104 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2107 case DW_CFA_advance_loc1:
2108 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2109 fde->dw_fde_current_label, NULL);
2110 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2113 case DW_CFA_advance_loc2:
2114 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2115 fde->dw_fde_current_label, NULL);
2116 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2119 case DW_CFA_advance_loc4:
2120 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2121 fde->dw_fde_current_label, NULL);
2122 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2125 case DW_CFA_MIPS_advance_loc8:
2126 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2127 fde->dw_fde_current_label, NULL);
2128 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2131 case DW_CFA_offset_extended:
2132 case DW_CFA_def_cfa:
2133 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2134 dw2_asm_output_data_uleb128 (r, NULL);
2135 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2138 case DW_CFA_offset_extended_sf:
2139 case DW_CFA_def_cfa_sf:
2140 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2141 dw2_asm_output_data_uleb128 (r, NULL);
2142 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2145 case DW_CFA_restore_extended:
2146 case DW_CFA_undefined:
2147 case DW_CFA_same_value:
2148 case DW_CFA_def_cfa_register:
2149 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2150 dw2_asm_output_data_uleb128 (r, NULL);
2153 case DW_CFA_register:
2154 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2155 dw2_asm_output_data_uleb128 (r, NULL);
2156 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2157 dw2_asm_output_data_uleb128 (r, NULL);
2160 case DW_CFA_def_cfa_offset:
2161 case DW_CFA_GNU_args_size:
2162 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2165 case DW_CFA_def_cfa_offset_sf:
2166 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2169 case DW_CFA_GNU_window_save:
2172 case DW_CFA_def_cfa_expression:
2173 case DW_CFA_expression:
2174 output_cfa_loc (cfi);
2177 case DW_CFA_GNU_negative_offset_extended:
2178 /* Obsoleted by DW_CFA_offset_extended_sf. */
2187 /* Output the call frame information used to record information
2188 that relates to calculating the frame pointer, and records the
2189 location of saved registers. */
2192 output_call_frame_info (int for_eh)
2197 char l1[20], l2[20], section_start_label[20];
2198 bool any_lsda_needed = false;
2199 char augmentation[6];
2200 int augmentation_size;
2201 int fde_encoding = DW_EH_PE_absptr;
2202 int per_encoding = DW_EH_PE_absptr;
2203 int lsda_encoding = DW_EH_PE_absptr;
2206 /* Don't emit a CIE if there won't be any FDEs. */
2207 if (fde_table_in_use == 0)
2210 /* If we make FDEs linkonce, we may have to emit an empty label for
2211 an FDE that wouldn't otherwise be emitted. We want to avoid
2212 having an FDE kept around when the function it refers to is
2213 discarded. Example where this matters: a primary function
2214 template in C++ requires EH information, but an explicit
2215 specialization doesn't. */
2216 if (TARGET_USES_WEAK_UNWIND_INFO
2217 && ! flag_asynchronous_unwind_tables
2219 for (i = 0; i < fde_table_in_use; i++)
2220 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2221 && !fde_table[i].uses_eh_lsda
2222 && ! DECL_WEAK (fde_table[i].decl))
2223 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2224 for_eh, /* empty */ 1);
2226 /* If we don't have any functions we'll want to unwind out of, don't
2227 emit any EH unwind information. Note that if exceptions aren't
2228 enabled, we won't have collected nothrow information, and if we
2229 asked for asynchronous tables, we always want this info. */
2232 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2234 for (i = 0; i < fde_table_in_use; i++)
2235 if (fde_table[i].uses_eh_lsda)
2236 any_eh_needed = any_lsda_needed = true;
2237 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2238 any_eh_needed = true;
2239 else if (! fde_table[i].nothrow
2240 && ! fde_table[i].all_throwers_are_sibcalls)
2241 any_eh_needed = true;
2243 if (! any_eh_needed)
2247 /* We're going to be generating comments, so turn on app. */
2252 switch_to_eh_frame_section ();
2255 if (!debug_frame_section)
2256 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2257 SECTION_DEBUG, NULL);
2258 switch_to_section (debug_frame_section);
2261 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2262 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2264 /* Output the CIE. */
2265 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2266 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2267 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2268 dw2_asm_output_data (4, 0xffffffff,
2269 "Initial length escape value indicating 64-bit DWARF extension");
2270 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2271 "Length of Common Information Entry");
2272 ASM_OUTPUT_LABEL (asm_out_file, l1);
2274 /* Now that the CIE pointer is PC-relative for EH,
2275 use 0 to identify the CIE. */
2276 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2277 (for_eh ? 0 : DWARF_CIE_ID),
2278 "CIE Identifier Tag");
2280 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2282 augmentation[0] = 0;
2283 augmentation_size = 0;
2289 z Indicates that a uleb128 is present to size the
2290 augmentation section.
2291 L Indicates the encoding (and thus presence) of
2292 an LSDA pointer in the FDE augmentation.
2293 R Indicates a non-default pointer encoding for
2295 P Indicates the presence of an encoding + language
2296 personality routine in the CIE augmentation. */
2298 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2299 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2300 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2302 p = augmentation + 1;
2303 if (eh_personality_libfunc)
2306 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2307 assemble_external_libcall (eh_personality_libfunc);
2309 if (any_lsda_needed)
2312 augmentation_size += 1;
2314 if (fde_encoding != DW_EH_PE_absptr)
2317 augmentation_size += 1;
2319 if (p > augmentation + 1)
2321 augmentation[0] = 'z';
2325 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2326 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2328 int offset = ( 4 /* Length */
2330 + 1 /* CIE version */
2331 + strlen (augmentation) + 1 /* Augmentation */
2332 + size_of_uleb128 (1) /* Code alignment */
2333 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2335 + 1 /* Augmentation size */
2336 + 1 /* Personality encoding */ );
2337 int pad = -offset & (PTR_SIZE - 1);
2339 augmentation_size += pad;
2341 /* Augmentations should be small, so there's scarce need to
2342 iterate for a solution. Die if we exceed one uleb128 byte. */
2343 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2347 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2348 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2349 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2350 "CIE Data Alignment Factor");
2352 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2353 if (DW_CIE_VERSION == 1)
2354 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2356 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2358 if (augmentation[0])
2360 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2361 if (eh_personality_libfunc)
2363 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2364 eh_data_format_name (per_encoding));
2365 dw2_asm_output_encoded_addr_rtx (per_encoding,
2366 eh_personality_libfunc,
2370 if (any_lsda_needed)
2371 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2372 eh_data_format_name (lsda_encoding));
2374 if (fde_encoding != DW_EH_PE_absptr)
2375 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2376 eh_data_format_name (fde_encoding));
2379 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2380 output_cfi (cfi, NULL, for_eh);
2382 /* Pad the CIE out to an address sized boundary. */
2383 ASM_OUTPUT_ALIGN (asm_out_file,
2384 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2385 ASM_OUTPUT_LABEL (asm_out_file, l2);
2387 /* Loop through all of the FDE's. */
2388 for (i = 0; i < fde_table_in_use; i++)
2390 fde = &fde_table[i];
2392 /* Don't emit EH unwind info for leaf functions that don't need it. */
2393 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2394 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2395 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2396 && !fde->uses_eh_lsda)
2399 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2400 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2401 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2402 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2403 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2404 dw2_asm_output_data (4, 0xffffffff,
2405 "Initial length escape value indicating 64-bit DWARF extension");
2406 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2408 ASM_OUTPUT_LABEL (asm_out_file, l1);
2411 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2413 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2414 debug_frame_section, "FDE CIE offset");
2418 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2419 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2420 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2423 "FDE initial location");
2424 if (fde->dw_fde_switched_sections)
2426 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2427 fde->dw_fde_unlikely_section_label);
2428 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2429 fde->dw_fde_hot_section_label);
2430 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2431 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2432 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2433 "FDE initial location");
2434 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2435 fde->dw_fde_hot_section_end_label,
2436 fde->dw_fde_hot_section_label,
2437 "FDE address range");
2438 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2439 "FDE initial location");
2440 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2441 fde->dw_fde_unlikely_section_end_label,
2442 fde->dw_fde_unlikely_section_label,
2443 "FDE address range");
2446 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2447 fde->dw_fde_end, fde->dw_fde_begin,
2448 "FDE address range");
2452 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2453 "FDE initial location");
2454 if (fde->dw_fde_switched_sections)
2456 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2457 fde->dw_fde_hot_section_label,
2458 "FDE initial location");
2459 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2460 fde->dw_fde_hot_section_end_label,
2461 fde->dw_fde_hot_section_label,
2462 "FDE address range");
2463 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2464 fde->dw_fde_unlikely_section_label,
2465 "FDE initial location");
2466 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2467 fde->dw_fde_unlikely_section_end_label,
2468 fde->dw_fde_unlikely_section_label,
2469 "FDE address range");
2472 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2473 fde->dw_fde_end, fde->dw_fde_begin,
2474 "FDE address range");
2477 if (augmentation[0])
2479 if (any_lsda_needed)
2481 int size = size_of_encoded_value (lsda_encoding);
2483 if (lsda_encoding == DW_EH_PE_aligned)
2485 int offset = ( 4 /* Length */
2486 + 4 /* CIE offset */
2487 + 2 * size_of_encoded_value (fde_encoding)
2488 + 1 /* Augmentation size */ );
2489 int pad = -offset & (PTR_SIZE - 1);
2492 gcc_assert (size_of_uleb128 (size) == 1);
2495 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2497 if (fde->uses_eh_lsda)
2499 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2500 fde->funcdef_number);
2501 dw2_asm_output_encoded_addr_rtx (
2502 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2503 false, "Language Specific Data Area");
2507 if (lsda_encoding == DW_EH_PE_aligned)
2508 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2510 (size_of_encoded_value (lsda_encoding), 0,
2511 "Language Specific Data Area (none)");
2515 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2518 /* Loop through the Call Frame Instructions associated with
2520 fde->dw_fde_current_label = fde->dw_fde_begin;
2521 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2522 output_cfi (cfi, fde, for_eh);
2524 /* Pad the FDE out to an address sized boundary. */
2525 ASM_OUTPUT_ALIGN (asm_out_file,
2526 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2527 ASM_OUTPUT_LABEL (asm_out_file, l2);
2530 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2531 dw2_asm_output_data (4, 0, "End of Table");
2532 #ifdef MIPS_DEBUGGING_INFO
2533 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2534 get a value of 0. Putting .align 0 after the label fixes it. */
2535 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2538 /* Turn off app to make assembly quicker. */
2543 /* Output a marker (i.e. a label) for the beginning of a function, before
2547 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2548 const char *file ATTRIBUTE_UNUSED)
2550 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2554 current_function_func_begin_label = NULL;
2556 #ifdef TARGET_UNWIND_INFO
2557 /* ??? current_function_func_begin_label is also used by except.c
2558 for call-site information. We must emit this label if it might
2560 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2561 && ! dwarf2out_do_frame ())
2564 if (! dwarf2out_do_frame ())
2568 switch_to_section (function_section (current_function_decl));
2569 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2570 current_function_funcdef_no);
2571 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2572 current_function_funcdef_no);
2573 dup_label = xstrdup (label);
2574 current_function_func_begin_label = dup_label;
2576 #ifdef TARGET_UNWIND_INFO
2577 /* We can elide the fde allocation if we're not emitting debug info. */
2578 if (! dwarf2out_do_frame ())
2582 /* Expand the fde table if necessary. */
2583 if (fde_table_in_use == fde_table_allocated)
2585 fde_table_allocated += FDE_TABLE_INCREMENT;
2586 fde_table = ggc_realloc (fde_table,
2587 fde_table_allocated * sizeof (dw_fde_node));
2588 memset (fde_table + fde_table_in_use, 0,
2589 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2592 /* Record the FDE associated with this function. */
2593 current_funcdef_fde = fde_table_in_use;
2595 /* Add the new FDE at the end of the fde_table. */
2596 fde = &fde_table[fde_table_in_use++];
2597 fde->decl = current_function_decl;
2598 fde->dw_fde_begin = dup_label;
2599 fde->dw_fde_current_label = dup_label;
2600 fde->dw_fde_hot_section_label = NULL;
2601 fde->dw_fde_hot_section_end_label = NULL;
2602 fde->dw_fde_unlikely_section_label = NULL;
2603 fde->dw_fde_unlikely_section_end_label = NULL;
2604 fde->dw_fde_switched_sections = false;
2605 fde->dw_fde_end = NULL;
2606 fde->dw_fde_cfi = NULL;
2607 fde->funcdef_number = current_function_funcdef_no;
2608 fde->nothrow = TREE_NOTHROW (current_function_decl);
2609 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2610 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2612 args_size = old_args_size = 0;
2614 /* We only want to output line number information for the genuine dwarf2
2615 prologue case, not the eh frame case. */
2616 #ifdef DWARF2_DEBUGGING_INFO
2618 dwarf2out_source_line (line, file);
2622 /* Output a marker (i.e. a label) for the absolute end of the generated code
2623 for a function definition. This gets called *after* the epilogue code has
2627 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2628 const char *file ATTRIBUTE_UNUSED)
2631 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2633 /* Output a label to mark the endpoint of the code generated for this
2635 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2636 current_function_funcdef_no);
2637 ASM_OUTPUT_LABEL (asm_out_file, label);
2638 fde = &fde_table[fde_table_in_use - 1];
2639 fde->dw_fde_end = xstrdup (label);
2643 dwarf2out_frame_init (void)
2645 /* Allocate the initial hunk of the fde_table. */
2646 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2647 fde_table_allocated = FDE_TABLE_INCREMENT;
2648 fde_table_in_use = 0;
2650 /* Generate the CFA instructions common to all FDE's. Do it now for the
2651 sake of lookup_cfa. */
2653 /* On entry, the Canonical Frame Address is at SP. */
2654 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2656 #ifdef DWARF2_UNWIND_INFO
2657 if (DWARF2_UNWIND_INFO)
2658 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2663 dwarf2out_frame_finish (void)
2665 /* Output call frame information. */
2666 if (DWARF2_FRAME_INFO)
2667 output_call_frame_info (0);
2669 #ifndef TARGET_UNWIND_INFO
2670 /* Output another copy for the unwinder. */
2671 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2672 output_call_frame_info (1);
2677 /* And now, the subset of the debugging information support code necessary
2678 for emitting location expressions. */
2680 /* Data about a single source file. */
2681 struct dwarf_file_data GTY(())
2683 const char * filename;
2687 /* We need some way to distinguish DW_OP_addr with a direct symbol
2688 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2689 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2692 typedef struct dw_val_struct *dw_val_ref;
2693 typedef struct die_struct *dw_die_ref;
2694 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2695 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2697 /* Each DIE may have a series of attribute/value pairs. Values
2698 can take on several forms. The forms that are used in this
2699 implementation are listed below. */
2704 dw_val_class_offset,
2706 dw_val_class_loc_list,
2707 dw_val_class_range_list,
2709 dw_val_class_unsigned_const,
2710 dw_val_class_long_long,
2713 dw_val_class_die_ref,
2714 dw_val_class_fde_ref,
2715 dw_val_class_lbl_id,
2716 dw_val_class_lineptr,
2718 dw_val_class_macptr,
2722 /* Describe a double word constant value. */
2723 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2725 typedef struct dw_long_long_struct GTY(())
2732 /* Describe a floating point constant value, or a vector constant value. */
2734 typedef struct dw_vec_struct GTY(())
2736 unsigned char * GTY((length ("%h.length"))) array;
2742 /* The dw_val_node describes an attribute's value, as it is
2743 represented internally. */
2745 typedef struct dw_val_struct GTY(())
2747 enum dw_val_class val_class;
2748 union dw_val_struct_union
2750 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2751 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2752 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2753 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2754 HOST_WIDE_INT GTY ((default)) val_int;
2755 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2756 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2757 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2758 struct dw_val_die_union
2762 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2763 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2764 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2765 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2766 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2767 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2769 GTY ((desc ("%1.val_class"))) v;
2773 /* Locations in memory are described using a sequence of stack machine
2776 typedef struct dw_loc_descr_struct GTY(())
2778 dw_loc_descr_ref dw_loc_next;
2779 enum dwarf_location_atom dw_loc_opc;
2780 dw_val_node dw_loc_oprnd1;
2781 dw_val_node dw_loc_oprnd2;
2786 /* Location lists are ranges + location descriptions for that range,
2787 so you can track variables that are in different places over
2788 their entire life. */
2789 typedef struct dw_loc_list_struct GTY(())
2791 dw_loc_list_ref dw_loc_next;
2792 const char *begin; /* Label for begin address of range */
2793 const char *end; /* Label for end address of range */
2794 char *ll_symbol; /* Label for beginning of location list.
2795 Only on head of list */
2796 const char *section; /* Section this loclist is relative to */
2797 dw_loc_descr_ref expr;
2800 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2802 static const char *dwarf_stack_op_name (unsigned);
2803 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2804 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2805 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2806 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2807 static unsigned long size_of_locs (dw_loc_descr_ref);
2808 static void output_loc_operands (dw_loc_descr_ref);
2809 static void output_loc_sequence (dw_loc_descr_ref);
2811 /* Convert a DWARF stack opcode into its string name. */
2814 dwarf_stack_op_name (unsigned int op)
2819 case INTERNAL_DW_OP_tls_addr:
2820 return "DW_OP_addr";
2822 return "DW_OP_deref";
2824 return "DW_OP_const1u";
2826 return "DW_OP_const1s";
2828 return "DW_OP_const2u";
2830 return "DW_OP_const2s";
2832 return "DW_OP_const4u";
2834 return "DW_OP_const4s";
2836 return "DW_OP_const8u";
2838 return "DW_OP_const8s";
2840 return "DW_OP_constu";
2842 return "DW_OP_consts";
2846 return "DW_OP_drop";
2848 return "DW_OP_over";
2850 return "DW_OP_pick";
2852 return "DW_OP_swap";
2856 return "DW_OP_xderef";
2864 return "DW_OP_minus";
2876 return "DW_OP_plus";
2877 case DW_OP_plus_uconst:
2878 return "DW_OP_plus_uconst";
2884 return "DW_OP_shra";
2902 return "DW_OP_skip";
2904 return "DW_OP_lit0";
2906 return "DW_OP_lit1";
2908 return "DW_OP_lit2";
2910 return "DW_OP_lit3";
2912 return "DW_OP_lit4";
2914 return "DW_OP_lit5";
2916 return "DW_OP_lit6";
2918 return "DW_OP_lit7";
2920 return "DW_OP_lit8";
2922 return "DW_OP_lit9";
2924 return "DW_OP_lit10";
2926 return "DW_OP_lit11";
2928 return "DW_OP_lit12";
2930 return "DW_OP_lit13";
2932 return "DW_OP_lit14";
2934 return "DW_OP_lit15";
2936 return "DW_OP_lit16";
2938 return "DW_OP_lit17";
2940 return "DW_OP_lit18";
2942 return "DW_OP_lit19";
2944 return "DW_OP_lit20";
2946 return "DW_OP_lit21";
2948 return "DW_OP_lit22";
2950 return "DW_OP_lit23";
2952 return "DW_OP_lit24";
2954 return "DW_OP_lit25";
2956 return "DW_OP_lit26";
2958 return "DW_OP_lit27";
2960 return "DW_OP_lit28";
2962 return "DW_OP_lit29";
2964 return "DW_OP_lit30";
2966 return "DW_OP_lit31";
2968 return "DW_OP_reg0";
2970 return "DW_OP_reg1";
2972 return "DW_OP_reg2";
2974 return "DW_OP_reg3";
2976 return "DW_OP_reg4";
2978 return "DW_OP_reg5";
2980 return "DW_OP_reg6";
2982 return "DW_OP_reg7";
2984 return "DW_OP_reg8";
2986 return "DW_OP_reg9";
2988 return "DW_OP_reg10";
2990 return "DW_OP_reg11";
2992 return "DW_OP_reg12";
2994 return "DW_OP_reg13";
2996 return "DW_OP_reg14";
2998 return "DW_OP_reg15";
3000 return "DW_OP_reg16";
3002 return "DW_OP_reg17";
3004 return "DW_OP_reg18";
3006 return "DW_OP_reg19";
3008 return "DW_OP_reg20";
3010 return "DW_OP_reg21";
3012 return "DW_OP_reg22";
3014 return "DW_OP_reg23";
3016 return "DW_OP_reg24";
3018 return "DW_OP_reg25";
3020 return "DW_OP_reg26";
3022 return "DW_OP_reg27";
3024 return "DW_OP_reg28";
3026 return "DW_OP_reg29";
3028 return "DW_OP_reg30";
3030 return "DW_OP_reg31";
3032 return "DW_OP_breg0";
3034 return "DW_OP_breg1";
3036 return "DW_OP_breg2";
3038 return "DW_OP_breg3";
3040 return "DW_OP_breg4";
3042 return "DW_OP_breg5";
3044 return "DW_OP_breg6";
3046 return "DW_OP_breg7";
3048 return "DW_OP_breg8";
3050 return "DW_OP_breg9";
3052 return "DW_OP_breg10";
3054 return "DW_OP_breg11";
3056 return "DW_OP_breg12";
3058 return "DW_OP_breg13";
3060 return "DW_OP_breg14";
3062 return "DW_OP_breg15";
3064 return "DW_OP_breg16";
3066 return "DW_OP_breg17";
3068 return "DW_OP_breg18";
3070 return "DW_OP_breg19";
3072 return "DW_OP_breg20";
3074 return "DW_OP_breg21";
3076 return "DW_OP_breg22";
3078 return "DW_OP_breg23";
3080 return "DW_OP_breg24";
3082 return "DW_OP_breg25";
3084 return "DW_OP_breg26";
3086 return "DW_OP_breg27";
3088 return "DW_OP_breg28";
3090 return "DW_OP_breg29";
3092 return "DW_OP_breg30";
3094 return "DW_OP_breg31";
3096 return "DW_OP_regx";
3098 return "DW_OP_fbreg";
3100 return "DW_OP_bregx";
3102 return "DW_OP_piece";
3103 case DW_OP_deref_size:
3104 return "DW_OP_deref_size";
3105 case DW_OP_xderef_size:
3106 return "DW_OP_xderef_size";
3109 case DW_OP_push_object_address:
3110 return "DW_OP_push_object_address";
3112 return "DW_OP_call2";
3114 return "DW_OP_call4";
3115 case DW_OP_call_ref:
3116 return "DW_OP_call_ref";
3117 case DW_OP_GNU_push_tls_address:
3118 return "DW_OP_GNU_push_tls_address";
3120 return "OP_<unknown>";
3124 /* Return a pointer to a newly allocated location description. Location
3125 descriptions are simple expression terms that can be strung
3126 together to form more complicated location (address) descriptions. */
3128 static inline dw_loc_descr_ref
3129 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3130 unsigned HOST_WIDE_INT oprnd2)
3132 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3134 descr->dw_loc_opc = op;
3135 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3136 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3137 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3138 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3143 /* Add a location description term to a location description expression. */
3146 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3148 dw_loc_descr_ref *d;
3150 /* Find the end of the chain. */
3151 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3157 /* Return the size of a location descriptor. */
3159 static unsigned long
3160 size_of_loc_descr (dw_loc_descr_ref loc)
3162 unsigned long size = 1;
3164 switch (loc->dw_loc_opc)
3167 case INTERNAL_DW_OP_tls_addr:
3168 size += DWARF2_ADDR_SIZE;
3187 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3190 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3195 case DW_OP_plus_uconst:
3196 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3234 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3237 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3240 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3243 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3244 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3247 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3249 case DW_OP_deref_size:
3250 case DW_OP_xderef_size:
3259 case DW_OP_call_ref:
3260 size += DWARF2_ADDR_SIZE;
3269 /* Return the size of a series of location descriptors. */
3271 static unsigned long
3272 size_of_locs (dw_loc_descr_ref loc)
3277 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3278 field, to avoid writing to a PCH file. */
3279 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3281 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3283 size += size_of_loc_descr (l);
3288 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3290 l->dw_loc_addr = size;
3291 size += size_of_loc_descr (l);
3297 /* Output location description stack opcode's operands (if any). */
3300 output_loc_operands (dw_loc_descr_ref loc)
3302 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3303 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3305 switch (loc->dw_loc_opc)
3307 #ifdef DWARF2_DEBUGGING_INFO
3309 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3313 dw2_asm_output_data (2, val1->v.val_int, NULL);
3317 dw2_asm_output_data (4, val1->v.val_int, NULL);
3321 gcc_assert (HOST_BITS_PER_LONG >= 64);
3322 dw2_asm_output_data (8, val1->v.val_int, NULL);
3329 gcc_assert (val1->val_class == dw_val_class_loc);
3330 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3332 dw2_asm_output_data (2, offset, NULL);
3345 /* We currently don't make any attempt to make sure these are
3346 aligned properly like we do for the main unwind info, so
3347 don't support emitting things larger than a byte if we're
3348 only doing unwinding. */
3353 dw2_asm_output_data (1, val1->v.val_int, NULL);
3356 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3359 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3362 dw2_asm_output_data (1, val1->v.val_int, NULL);
3364 case DW_OP_plus_uconst:
3365 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3399 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3402 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3405 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3408 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3409 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3412 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3414 case DW_OP_deref_size:
3415 case DW_OP_xderef_size:
3416 dw2_asm_output_data (1, val1->v.val_int, NULL);
3419 case INTERNAL_DW_OP_tls_addr:
3420 if (targetm.asm_out.output_dwarf_dtprel)
3422 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3425 fputc ('\n', asm_out_file);
3432 /* Other codes have no operands. */
3437 /* Output a sequence of location operations. */
3440 output_loc_sequence (dw_loc_descr_ref loc)
3442 for (; loc != NULL; loc = loc->dw_loc_next)
3444 /* Output the opcode. */
3445 dw2_asm_output_data (1, loc->dw_loc_opc,
3446 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3448 /* Output the operand(s) (if any). */
3449 output_loc_operands (loc);
3453 /* This routine will generate the correct assembly data for a location
3454 description based on a cfi entry with a complex address. */
3457 output_cfa_loc (dw_cfi_ref cfi)
3459 dw_loc_descr_ref loc;
3462 /* Output the size of the block. */
3463 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3464 size = size_of_locs (loc);
3465 dw2_asm_output_data_uleb128 (size, NULL);
3467 /* Now output the operations themselves. */
3468 output_loc_sequence (loc);
3471 /* This function builds a dwarf location descriptor sequence from a
3472 dw_cfa_location, adding the given OFFSET to the result of the
3475 static struct dw_loc_descr_struct *
3476 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3478 struct dw_loc_descr_struct *head, *tmp;
3480 offset += cfa->offset;
3484 if (cfa->base_offset)
3487 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3489 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3491 else if (cfa->reg <= 31)
3492 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3494 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3496 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3497 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3498 add_loc_descr (&head, tmp);
3501 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3502 add_loc_descr (&head, tmp);
3509 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3511 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3512 else if (cfa->reg <= 31)
3513 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3515 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3521 /* This function fills in aa dw_cfa_location structure from a dwarf location
3522 descriptor sequence. */
3525 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3527 struct dw_loc_descr_struct *ptr;
3529 cfa->base_offset = 0;
3533 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3535 enum dwarf_location_atom op = ptr->dw_loc_opc;
3571 cfa->reg = op - DW_OP_reg0;
3574 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3608 cfa->reg = op - DW_OP_breg0;
3609 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3612 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3613 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3618 case DW_OP_plus_uconst:
3619 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3622 internal_error ("DW_LOC_OP %s not implemented",
3623 dwarf_stack_op_name (ptr->dw_loc_opc));
3627 #endif /* .debug_frame support */
3629 /* And now, the support for symbolic debugging information. */
3630 #ifdef DWARF2_DEBUGGING_INFO
3632 /* .debug_str support. */
3633 static int output_indirect_string (void **, void *);
3635 static void dwarf2out_init (const char *);
3636 static void dwarf2out_finish (const char *);
3637 static void dwarf2out_define (unsigned int, const char *);
3638 static void dwarf2out_undef (unsigned int, const char *);
3639 static void dwarf2out_start_source_file (unsigned, const char *);
3640 static void dwarf2out_end_source_file (unsigned);
3641 static void dwarf2out_begin_block (unsigned, unsigned);
3642 static void dwarf2out_end_block (unsigned, unsigned);
3643 static bool dwarf2out_ignore_block (tree);
3644 static void dwarf2out_global_decl (tree);
3645 static void dwarf2out_type_decl (tree, int);
3646 static void dwarf2out_imported_module_or_decl (tree, tree);
3647 static void dwarf2out_abstract_function (tree);
3648 static void dwarf2out_var_location (rtx);
3649 static void dwarf2out_begin_function (tree);
3650 static void dwarf2out_switch_text_section (void);
3652 /* The debug hooks structure. */
3654 const struct gcc_debug_hooks dwarf2_debug_hooks =
3660 dwarf2out_start_source_file,
3661 dwarf2out_end_source_file,
3662 dwarf2out_begin_block,
3663 dwarf2out_end_block,
3664 dwarf2out_ignore_block,
3665 dwarf2out_source_line,
3666 dwarf2out_begin_prologue,
3667 debug_nothing_int_charstar, /* end_prologue */
3668 dwarf2out_end_epilogue,
3669 dwarf2out_begin_function,
3670 debug_nothing_int, /* end_function */
3671 dwarf2out_decl, /* function_decl */
3672 dwarf2out_global_decl,
3673 dwarf2out_type_decl, /* type_decl */
3674 dwarf2out_imported_module_or_decl,
3675 debug_nothing_tree, /* deferred_inline_function */
3676 /* The DWARF 2 backend tries to reduce debugging bloat by not
3677 emitting the abstract description of inline functions until
3678 something tries to reference them. */
3679 dwarf2out_abstract_function, /* outlining_inline_function */
3680 debug_nothing_rtx, /* label */
3681 debug_nothing_int, /* handle_pch */
3682 dwarf2out_var_location,
3683 dwarf2out_switch_text_section,
3684 1 /* start_end_main_source_file */
3688 /* NOTE: In the comments in this file, many references are made to
3689 "Debugging Information Entries". This term is abbreviated as `DIE'
3690 throughout the remainder of this file. */
3692 /* An internal representation of the DWARF output is built, and then
3693 walked to generate the DWARF debugging info. The walk of the internal
3694 representation is done after the entire program has been compiled.
3695 The types below are used to describe the internal representation. */
3697 /* Various DIE's use offsets relative to the beginning of the
3698 .debug_info section to refer to each other. */
3700 typedef long int dw_offset;
3702 /* Define typedefs here to avoid circular dependencies. */
3704 typedef struct dw_attr_struct *dw_attr_ref;
3705 typedef struct dw_line_info_struct *dw_line_info_ref;
3706 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3707 typedef struct pubname_struct *pubname_ref;
3708 typedef struct dw_ranges_struct *dw_ranges_ref;
3710 /* Each entry in the line_info_table maintains the file and
3711 line number associated with the label generated for that
3712 entry. The label gives the PC value associated with
3713 the line number entry. */
3715 typedef struct dw_line_info_struct GTY(())
3717 unsigned long dw_file_num;
3718 unsigned long dw_line_num;
3722 /* Line information for functions in separate sections; each one gets its
3724 typedef struct dw_separate_line_info_struct GTY(())
3726 unsigned long dw_file_num;
3727 unsigned long dw_line_num;
3728 unsigned long function;
3730 dw_separate_line_info_entry;
3732 /* Each DIE attribute has a field specifying the attribute kind,
3733 a link to the next attribute in the chain, and an attribute value.
3734 Attributes are typically linked below the DIE they modify. */
3736 typedef struct dw_attr_struct GTY(())
3738 enum dwarf_attribute dw_attr;
3739 dw_val_node dw_attr_val;
3743 DEF_VEC_O(dw_attr_node);
3744 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3746 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3747 The children of each node form a circular list linked by
3748 die_sib. die_child points to the node *before* the "first" child node. */
3750 typedef struct die_struct GTY(())
3752 enum dwarf_tag die_tag;
3754 VEC(dw_attr_node,gc) * die_attr;
3755 dw_die_ref die_parent;
3756 dw_die_ref die_child;
3758 dw_die_ref die_definition; /* ref from a specification to its definition */
3759 dw_offset die_offset;
3760 unsigned long die_abbrev;
3762 /* Die is used and must not be pruned as unused. */
3763 int die_perennial_p;
3764 unsigned int decl_id;
3768 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3769 #define FOR_EACH_CHILD(die, c, expr) do { \
3770 c = die->die_child; \
3774 } while (c != die->die_child); \
3777 /* The pubname structure */
3779 typedef struct pubname_struct GTY(())
3786 DEF_VEC_O(pubname_entry);
3787 DEF_VEC_ALLOC_O(pubname_entry, gc);
3789 struct dw_ranges_struct GTY(())
3794 /* The limbo die list structure. */
3795 typedef struct limbo_die_struct GTY(())
3799 struct limbo_die_struct *next;
3803 /* How to start an assembler comment. */
3804 #ifndef ASM_COMMENT_START
3805 #define ASM_COMMENT_START ";#"
3808 /* Define a macro which returns nonzero for a TYPE_DECL which was
3809 implicitly generated for a tagged type.
3811 Note that unlike the gcc front end (which generates a NULL named
3812 TYPE_DECL node for each complete tagged type, each array type, and
3813 each function type node created) the g++ front end generates a
3814 _named_ TYPE_DECL node for each tagged type node created.
3815 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3816 generate a DW_TAG_typedef DIE for them. */
3818 #define TYPE_DECL_IS_STUB(decl) \
3819 (DECL_NAME (decl) == NULL_TREE \
3820 || (DECL_ARTIFICIAL (decl) \
3821 && is_tagged_type (TREE_TYPE (decl)) \
3822 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3823 /* This is necessary for stub decls that \
3824 appear in nested inline functions. */ \
3825 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3826 && (decl_ultimate_origin (decl) \
3827 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3829 /* Information concerning the compilation unit's programming
3830 language, and compiler version. */
3832 /* Fixed size portion of the DWARF compilation unit header. */
3833 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3834 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3836 /* Fixed size portion of public names info. */
3837 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3839 /* Fixed size portion of the address range info. */
3840 #define DWARF_ARANGES_HEADER_SIZE \
3841 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3842 DWARF2_ADDR_SIZE * 2) \
3843 - DWARF_INITIAL_LENGTH_SIZE)
3845 /* Size of padding portion in the address range info. It must be
3846 aligned to twice the pointer size. */
3847 #define DWARF_ARANGES_PAD_SIZE \
3848 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3849 DWARF2_ADDR_SIZE * 2) \
3850 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3852 /* Use assembler line directives if available. */
3853 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3854 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3855 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3857 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3861 /* Minimum line offset in a special line info. opcode.
3862 This value was chosen to give a reasonable range of values. */
3863 #define DWARF_LINE_BASE -10
3865 /* First special line opcode - leave room for the standard opcodes. */
3866 #define DWARF_LINE_OPCODE_BASE 10
3868 /* Range of line offsets in a special line info. opcode. */
3869 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3871 /* Flag that indicates the initial value of the is_stmt_start flag.
3872 In the present implementation, we do not mark any lines as
3873 the beginning of a source statement, because that information
3874 is not made available by the GCC front-end. */
3875 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3877 #ifdef DWARF2_DEBUGGING_INFO
3878 /* This location is used by calc_die_sizes() to keep track
3879 the offset of each DIE within the .debug_info section. */
3880 static unsigned long next_die_offset;
3883 /* Record the root of the DIE's built for the current compilation unit. */
3884 static GTY(()) dw_die_ref comp_unit_die;
3886 /* A list of DIEs with a NULL parent waiting to be relocated. */
3887 static GTY(()) limbo_die_node *limbo_die_list;
3889 /* Filenames referenced by this compilation unit. */
3890 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3892 /* A hash table of references to DIE's that describe declarations.
3893 The key is a DECL_UID() which is a unique number identifying each decl. */
3894 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3896 /* Node of the variable location list. */
3897 struct var_loc_node GTY ((chain_next ("%h.next")))
3899 rtx GTY (()) var_loc_note;
3900 const char * GTY (()) label;
3901 const char * GTY (()) section_label;
3902 struct var_loc_node * GTY (()) next;
3905 /* Variable location list. */
3906 struct var_loc_list_def GTY (())
3908 struct var_loc_node * GTY (()) first;
3910 /* Do not mark the last element of the chained list because
3911 it is marked through the chain. */
3912 struct var_loc_node * GTY ((skip ("%h"))) last;
3914 /* DECL_UID of the variable decl. */
3915 unsigned int decl_id;
3917 typedef struct var_loc_list_def var_loc_list;
3920 /* Table of decl location linked lists. */
3921 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3923 /* A pointer to the base of a list of references to DIE's that
3924 are uniquely identified by their tag, presence/absence of
3925 children DIE's, and list of attribute/value pairs. */
3926 static GTY((length ("abbrev_die_table_allocated")))
3927 dw_die_ref *abbrev_die_table;
3929 /* Number of elements currently allocated for abbrev_die_table. */
3930 static GTY(()) unsigned abbrev_die_table_allocated;
3932 /* Number of elements in type_die_table currently in use. */
3933 static GTY(()) unsigned abbrev_die_table_in_use;
3935 /* Size (in elements) of increments by which we may expand the
3936 abbrev_die_table. */
3937 #define ABBREV_DIE_TABLE_INCREMENT 256
3939 /* A pointer to the base of a table that contains line information
3940 for each source code line in .text in the compilation unit. */
3941 static GTY((length ("line_info_table_allocated")))
3942 dw_line_info_ref line_info_table;
3944 /* Number of elements currently allocated for line_info_table. */
3945 static GTY(()) unsigned line_info_table_allocated;
3947 /* Number of elements in line_info_table currently in use. */
3948 static GTY(()) unsigned line_info_table_in_use;
3950 /* True if the compilation unit places functions in more than one section. */
3951 static GTY(()) bool have_multiple_function_sections = false;
3953 /* A pointer to the base of a table that contains line information
3954 for each source code line outside of .text in the compilation unit. */
3955 static GTY ((length ("separate_line_info_table_allocated")))
3956 dw_separate_line_info_ref separate_line_info_table;
3958 /* Number of elements currently allocated for separate_line_info_table. */
3959 static GTY(()) unsigned separate_line_info_table_allocated;
3961 /* Number of elements in separate_line_info_table currently in use. */
3962 static GTY(()) unsigned separate_line_info_table_in_use;
3964 /* Size (in elements) of increments by which we may expand the
3966 #define LINE_INFO_TABLE_INCREMENT 1024
3968 /* A pointer to the base of a table that contains a list of publicly
3969 accessible names. */
3970 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3972 /* A pointer to the base of a table that contains a list of publicly
3973 accessible types. */
3974 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3976 /* Array of dies for which we should generate .debug_arange info. */
3977 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3979 /* Number of elements currently allocated for arange_table. */
3980 static GTY(()) unsigned arange_table_allocated;
3982 /* Number of elements in arange_table currently in use. */
3983 static GTY(()) unsigned arange_table_in_use;
3985 /* Size (in elements) of increments by which we may expand the
3987 #define ARANGE_TABLE_INCREMENT 64
3989 /* Array of dies for which we should generate .debug_ranges info. */
3990 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3992 /* Number of elements currently allocated for ranges_table. */
3993 static GTY(()) unsigned ranges_table_allocated;
3995 /* Number of elements in ranges_table currently in use. */
3996 static GTY(()) unsigned ranges_table_in_use;
3998 /* Size (in elements) of increments by which we may expand the
4000 #define RANGES_TABLE_INCREMENT 64
4002 /* Whether we have location lists that need outputting */
4003 static GTY(()) bool have_location_lists;
4005 /* Unique label counter. */
4006 static GTY(()) unsigned int loclabel_num;
4008 #ifdef DWARF2_DEBUGGING_INFO
4009 /* Record whether the function being analyzed contains inlined functions. */
4010 static int current_function_has_inlines;
4012 #if 0 && defined (MIPS_DEBUGGING_INFO)
4013 static int comp_unit_has_inlines;
4016 /* The last file entry emitted by maybe_emit_file(). */
4017 static GTY(()) struct dwarf_file_data * last_emitted_file;
4019 /* Number of internal labels generated by gen_internal_sym(). */
4020 static GTY(()) int label_num;
4022 /* Cached result of previous call to lookup_filename. */
4023 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4025 #ifdef DWARF2_DEBUGGING_INFO
4027 /* Offset from the "steady-state frame pointer" to the frame base,
4028 within the current function. */
4029 static HOST_WIDE_INT frame_pointer_fb_offset;
4031 /* Forward declarations for functions defined in this file. */
4033 static int is_pseudo_reg (rtx);
4034 static tree type_main_variant (tree);
4035 static int is_tagged_type (tree);
4036 static const char *dwarf_tag_name (unsigned);
4037 static const char *dwarf_attr_name (unsigned);
4038 static const char *dwarf_form_name (unsigned);
4039 static tree decl_ultimate_origin (tree);
4040 static tree block_ultimate_origin (tree);
4041 static tree decl_class_context (tree);
4042 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4043 static inline enum dw_val_class AT_class (dw_attr_ref);
4044 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4045 static inline unsigned AT_flag (dw_attr_ref);
4046 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4047 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4048 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4049 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4050 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4052 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4053 unsigned int, unsigned char *);
4054 static hashval_t debug_str_do_hash (const void *);
4055 static int debug_str_eq (const void *, const void *);
4056 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4057 static inline const char *AT_string (dw_attr_ref);
4058 static int AT_string_form (dw_attr_ref);
4059 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4060 static void add_AT_specification (dw_die_ref, dw_die_ref);
4061 static inline dw_die_ref AT_ref (dw_attr_ref);
4062 static inline int AT_ref_external (dw_attr_ref);
4063 static inline void set_AT_ref_external (dw_attr_ref, int);
4064 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4065 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4066 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4067 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4069 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4070 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4071 static inline rtx AT_addr (dw_attr_ref);
4072 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4073 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4074 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4075 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4076 unsigned HOST_WIDE_INT);
4077 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4079 static inline const char *AT_lbl (dw_attr_ref);
4080 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4081 static const char *get_AT_low_pc (dw_die_ref);
4082 static const char *get_AT_hi_pc (dw_die_ref);
4083 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4084 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4085 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4086 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4087 static bool is_c_family (void);
4088 static bool is_cxx (void);
4089 static bool is_java (void);
4090 static bool is_fortran (void);
4091 static bool is_ada (void);
4092 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4093 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4094 static void add_child_die (dw_die_ref, dw_die_ref);
4095 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4096 static dw_die_ref lookup_type_die (tree);
4097 static void equate_type_number_to_die (tree, dw_die_ref);
4098 static hashval_t decl_die_table_hash (const void *);
4099 static int decl_die_table_eq (const void *, const void *);
4100 static dw_die_ref lookup_decl_die (tree);
4101 static hashval_t decl_loc_table_hash (const void *);
4102 static int decl_loc_table_eq (const void *, const void *);
4103 static var_loc_list *lookup_decl_loc (tree);
4104 static void equate_decl_number_to_die (tree, dw_die_ref);
4105 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4106 static void print_spaces (FILE *);
4107 static void print_die (dw_die_ref, FILE *);
4108 static void print_dwarf_line_table (FILE *);
4109 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4110 static dw_die_ref pop_compile_unit (dw_die_ref);
4111 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4112 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4113 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4114 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4115 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
4116 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4117 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4118 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4119 static void compute_section_prefix (dw_die_ref);
4120 static int is_type_die (dw_die_ref);
4121 static int is_comdat_die (dw_die_ref);
4122 static int is_symbol_die (dw_die_ref);
4123 static void assign_symbol_names (dw_die_ref);
4124 static void break_out_includes (dw_die_ref);
4125 static hashval_t htab_cu_hash (const void *);
4126 static int htab_cu_eq (const void *, const void *);
4127 static void htab_cu_del (void *);
4128 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4129 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4130 static void add_sibling_attributes (dw_die_ref);
4131 static void build_abbrev_table (dw_die_ref);
4132 static void output_location_lists (dw_die_ref);
4133 static int constant_size (long unsigned);
4134 static unsigned long size_of_die (dw_die_ref);
4135 static void calc_die_sizes (dw_die_ref);
4136 static void mark_dies (dw_die_ref);
4137 static void unmark_dies (dw_die_ref);
4138 static void unmark_all_dies (dw_die_ref);
4139 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4140 static unsigned long size_of_aranges (void);
4141 static enum dwarf_form value_format (dw_attr_ref);
4142 static void output_value_format (dw_attr_ref);
4143 static void output_abbrev_section (void);
4144 static void output_die_symbol (dw_die_ref);
4145 static void output_die (dw_die_ref);
4146 static void output_compilation_unit_header (void);
4147 static void output_comp_unit (dw_die_ref, int);
4148 static const char *dwarf2_name (tree, int);
4149 static void add_pubname (tree, dw_die_ref);
4150 static void add_pubtype (tree, dw_die_ref);
4151 static void output_pubnames (VEC (pubname_entry,gc) *);
4152 static void add_arange (tree, dw_die_ref);
4153 static void output_aranges (void);
4154 static unsigned int add_ranges (tree);
4155 static void output_ranges (void);
4156 static void output_line_info (void);
4157 static void output_file_names (void);
4158 static dw_die_ref base_type_die (tree);
4159 static int is_base_type (tree);
4160 static bool is_subrange_type (tree);
4161 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4162 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4163 static int type_is_enum (tree);
4164 static unsigned int dbx_reg_number (rtx);
4165 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4166 static dw_loc_descr_ref reg_loc_descriptor (rtx);
4167 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
4168 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
4169 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4170 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT);
4171 static int is_based_loc (rtx);
4172 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
4173 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
4174 static dw_loc_descr_ref loc_descriptor (rtx);
4175 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4176 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4177 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4178 static tree field_type (tree);
4179 static unsigned int simple_type_align_in_bits (tree);
4180 static unsigned int simple_decl_align_in_bits (tree);
4181 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
4182 static HOST_WIDE_INT field_byte_offset (tree);
4183 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4185 static void add_data_member_location_attribute (dw_die_ref, tree);
4186 static void add_const_value_attribute (dw_die_ref, rtx);
4187 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4188 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4189 static void insert_float (rtx, unsigned char *);
4190 static rtx rtl_for_decl_location (tree);
4191 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4192 enum dwarf_attribute);
4193 static void tree_add_const_value_attribute (dw_die_ref, tree);
4194 static void add_name_attribute (dw_die_ref, const char *);
4195 static void add_comp_dir_attribute (dw_die_ref);
4196 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4197 static void add_subscript_info (dw_die_ref, tree);
4198 static void add_byte_size_attribute (dw_die_ref, tree);
4199 static void add_bit_offset_attribute (dw_die_ref, tree);
4200 static void add_bit_size_attribute (dw_die_ref, tree);
4201 static void add_prototyped_attribute (dw_die_ref, tree);
4202 static void add_abstract_origin_attribute (dw_die_ref, tree);
4203 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4204 static void add_src_coords_attributes (dw_die_ref, tree);
4205 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4206 static void push_decl_scope (tree);
4207 static void pop_decl_scope (void);
4208 static dw_die_ref scope_die_for (tree, dw_die_ref);
4209 static inline int local_scope_p (dw_die_ref);
4210 static inline int class_or_namespace_scope_p (dw_die_ref);
4211 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4212 static void add_calling_convention_attribute (dw_die_ref, tree);
4213 static const char *type_tag (tree);
4214 static tree member_declared_type (tree);
4216 static const char *decl_start_label (tree);
4218 static void gen_array_type_die (tree, dw_die_ref);
4220 static void gen_entry_point_die (tree, dw_die_ref);
4222 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4223 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4224 static void gen_inlined_union_type_die (tree, dw_die_ref);
4225 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4226 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4227 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4228 static void gen_formal_types_die (tree, dw_die_ref);
4229 static void gen_subprogram_die (tree, dw_die_ref);
4230 static void gen_variable_die (tree, dw_die_ref);
4231 static void gen_label_die (tree, dw_die_ref);
4232 static void gen_lexical_block_die (tree, dw_die_ref, int);
4233 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4234 static void gen_field_die (tree, dw_die_ref);
4235 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4236 static dw_die_ref gen_compile_unit_die (const char *);
4237 static void gen_inheritance_die (tree, tree, dw_die_ref);
4238 static void gen_member_die (tree, dw_die_ref);
4239 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4240 enum debug_info_usage);
4241 static void gen_subroutine_type_die (tree, dw_die_ref);
4242 static void gen_typedef_die (tree, dw_die_ref);
4243 static void gen_type_die (tree, dw_die_ref);
4244 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4245 static void gen_block_die (tree, dw_die_ref, int);
4246 static void decls_for_scope (tree, dw_die_ref, int);
4247 static int is_redundant_typedef (tree);
4248 static void gen_namespace_die (tree);
4249 static void gen_decl_die (tree, dw_die_ref);
4250 static dw_die_ref force_decl_die (tree);
4251 static dw_die_ref force_type_die (tree);
4252 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4253 static void declare_in_namespace (tree, dw_die_ref);
4254 static struct dwarf_file_data * lookup_filename (const char *);
4255 static void retry_incomplete_types (void);
4256 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4257 static void splice_child_die (dw_die_ref, dw_die_ref);
4258 static int file_info_cmp (const void *, const void *);
4259 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4260 const char *, const char *, unsigned);
4261 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4262 const char *, const char *,
4264 static void output_loc_list (dw_loc_list_ref);
4265 static char *gen_internal_sym (const char *);
4267 static void prune_unmark_dies (dw_die_ref);
4268 static void prune_unused_types_mark (dw_die_ref, int);
4269 static void prune_unused_types_walk (dw_die_ref);
4270 static void prune_unused_types_walk_attribs (dw_die_ref);
4271 static void prune_unused_types_prune (dw_die_ref);
4272 static void prune_unused_types (void);
4273 static int maybe_emit_file (struct dwarf_file_data *fd);
4275 /* Section names used to hold DWARF debugging information. */
4276 #ifndef DEBUG_INFO_SECTION
4277 #define DEBUG_INFO_SECTION ".debug_info"
4279 #ifndef DEBUG_ABBREV_SECTION
4280 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4282 #ifndef DEBUG_ARANGES_SECTION
4283 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4285 #ifndef DEBUG_MACINFO_SECTION
4286 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4288 #ifndef DEBUG_LINE_SECTION
4289 #define DEBUG_LINE_SECTION ".debug_line"
4291 #ifndef DEBUG_LOC_SECTION
4292 #define DEBUG_LOC_SECTION ".debug_loc"
4294 #ifndef DEBUG_PUBNAMES_SECTION
4295 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4297 #ifndef DEBUG_STR_SECTION
4298 #define DEBUG_STR_SECTION ".debug_str"
4300 #ifndef DEBUG_RANGES_SECTION
4301 #define DEBUG_RANGES_SECTION ".debug_ranges"
4304 /* Standard ELF section names for compiled code and data. */
4305 #ifndef TEXT_SECTION_NAME
4306 #define TEXT_SECTION_NAME ".text"
4309 /* Section flags for .debug_str section. */
4310 #define DEBUG_STR_SECTION_FLAGS \
4311 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4312 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4315 /* Labels we insert at beginning sections we can reference instead of
4316 the section names themselves. */
4318 #ifndef TEXT_SECTION_LABEL
4319 #define TEXT_SECTION_LABEL "Ltext"
4321 #ifndef COLD_TEXT_SECTION_LABEL
4322 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4324 #ifndef DEBUG_LINE_SECTION_LABEL
4325 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4327 #ifndef DEBUG_INFO_SECTION_LABEL
4328 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4330 #ifndef DEBUG_ABBREV_SECTION_LABEL
4331 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4333 #ifndef DEBUG_LOC_SECTION_LABEL
4334 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4336 #ifndef DEBUG_RANGES_SECTION_LABEL
4337 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4339 #ifndef DEBUG_MACINFO_SECTION_LABEL
4340 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4343 /* Definitions of defaults for formats and names of various special
4344 (artificial) labels which may be generated within this file (when the -g
4345 options is used and DWARF2_DEBUGGING_INFO is in effect.
4346 If necessary, these may be overridden from within the tm.h file, but
4347 typically, overriding these defaults is unnecessary. */
4349 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4350 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4351 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4352 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4353 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4354 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4355 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4356 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4357 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4358 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4360 #ifndef TEXT_END_LABEL
4361 #define TEXT_END_LABEL "Letext"
4363 #ifndef COLD_END_LABEL
4364 #define COLD_END_LABEL "Letext_cold"
4366 #ifndef BLOCK_BEGIN_LABEL
4367 #define BLOCK_BEGIN_LABEL "LBB"
4369 #ifndef BLOCK_END_LABEL
4370 #define BLOCK_END_LABEL "LBE"
4372 #ifndef LINE_CODE_LABEL
4373 #define LINE_CODE_LABEL "LM"
4375 #ifndef SEPARATE_LINE_CODE_LABEL
4376 #define SEPARATE_LINE_CODE_LABEL "LSM"
4379 /* We allow a language front-end to designate a function that is to be
4380 called to "demangle" any name before it is put into a DIE. */
4382 static const char *(*demangle_name_func) (const char *);
4385 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4387 demangle_name_func = func;
4390 /* Test if rtl node points to a pseudo register. */
4393 is_pseudo_reg (rtx rtl)
4395 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4396 || (GET_CODE (rtl) == SUBREG
4397 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4400 /* Return a reference to a type, with its const and volatile qualifiers
4404 type_main_variant (tree type)
4406 type = TYPE_MAIN_VARIANT (type);
4408 /* ??? There really should be only one main variant among any group of
4409 variants of a given type (and all of the MAIN_VARIANT values for all
4410 members of the group should point to that one type) but sometimes the C
4411 front-end messes this up for array types, so we work around that bug
4413 if (TREE_CODE (type) == ARRAY_TYPE)
4414 while (type != TYPE_MAIN_VARIANT (type))
4415 type = TYPE_MAIN_VARIANT (type);
4420 /* Return nonzero if the given type node represents a tagged type. */
4423 is_tagged_type (tree type)
4425 enum tree_code code = TREE_CODE (type);
4427 return (code == RECORD_TYPE || code == UNION_TYPE
4428 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4431 /* Convert a DIE tag into its string name. */
4434 dwarf_tag_name (unsigned int tag)
4438 case DW_TAG_padding:
4439 return "DW_TAG_padding";
4440 case DW_TAG_array_type:
4441 return "DW_TAG_array_type";
4442 case DW_TAG_class_type:
4443 return "DW_TAG_class_type";
4444 case DW_TAG_entry_point:
4445 return "DW_TAG_entry_point";
4446 case DW_TAG_enumeration_type:
4447 return "DW_TAG_enumeration_type";
4448 case DW_TAG_formal_parameter:
4449 return "DW_TAG_formal_parameter";
4450 case DW_TAG_imported_declaration:
4451 return "DW_TAG_imported_declaration";
4453 return "DW_TAG_label";
4454 case DW_TAG_lexical_block:
4455 return "DW_TAG_lexical_block";
4457 return "DW_TAG_member";
4458 case DW_TAG_pointer_type:
4459 return "DW_TAG_pointer_type";
4460 case DW_TAG_reference_type:
4461 return "DW_TAG_reference_type";
4462 case DW_TAG_compile_unit:
4463 return "DW_TAG_compile_unit";
4464 case DW_TAG_string_type:
4465 return "DW_TAG_string_type";
4466 case DW_TAG_structure_type:
4467 return "DW_TAG_structure_type";
4468 case DW_TAG_subroutine_type:
4469 return "DW_TAG_subroutine_type";
4470 case DW_TAG_typedef:
4471 return "DW_TAG_typedef";
4472 case DW_TAG_union_type:
4473 return "DW_TAG_union_type";
4474 case DW_TAG_unspecified_parameters:
4475 return "DW_TAG_unspecified_parameters";
4476 case DW_TAG_variant:
4477 return "DW_TAG_variant";
4478 case DW_TAG_common_block:
4479 return "DW_TAG_common_block";
4480 case DW_TAG_common_inclusion:
4481 return "DW_TAG_common_inclusion";
4482 case DW_TAG_inheritance:
4483 return "DW_TAG_inheritance";
4484 case DW_TAG_inlined_subroutine:
4485 return "DW_TAG_inlined_subroutine";
4487 return "DW_TAG_module";
4488 case DW_TAG_ptr_to_member_type:
4489 return "DW_TAG_ptr_to_member_type";
4490 case DW_TAG_set_type:
4491 return "DW_TAG_set_type";
4492 case DW_TAG_subrange_type:
4493 return "DW_TAG_subrange_type";
4494 case DW_TAG_with_stmt:
4495 return "DW_TAG_with_stmt";
4496 case DW_TAG_access_declaration:
4497 return "DW_TAG_access_declaration";
4498 case DW_TAG_base_type:
4499 return "DW_TAG_base_type";
4500 case DW_TAG_catch_block:
4501 return "DW_TAG_catch_block";
4502 case DW_TAG_const_type:
4503 return "DW_TAG_const_type";
4504 case DW_TAG_constant:
4505 return "DW_TAG_constant";
4506 case DW_TAG_enumerator:
4507 return "DW_TAG_enumerator";
4508 case DW_TAG_file_type:
4509 return "DW_TAG_file_type";
4511 return "DW_TAG_friend";
4512 case DW_TAG_namelist:
4513 return "DW_TAG_namelist";
4514 case DW_TAG_namelist_item:
4515 return "DW_TAG_namelist_item";
4516 case DW_TAG_namespace:
4517 return "DW_TAG_namespace";
4518 case DW_TAG_packed_type:
4519 return "DW_TAG_packed_type";
4520 case DW_TAG_subprogram:
4521 return "DW_TAG_subprogram";
4522 case DW_TAG_template_type_param:
4523 return "DW_TAG_template_type_param";
4524 case DW_TAG_template_value_param:
4525 return "DW_TAG_template_value_param";
4526 case DW_TAG_thrown_type:
4527 return "DW_TAG_thrown_type";
4528 case DW_TAG_try_block:
4529 return "DW_TAG_try_block";
4530 case DW_TAG_variant_part:
4531 return "DW_TAG_variant_part";
4532 case DW_TAG_variable:
4533 return "DW_TAG_variable";
4534 case DW_TAG_volatile_type:
4535 return "DW_TAG_volatile_type";
4536 case DW_TAG_imported_module:
4537 return "DW_TAG_imported_module";
4538 case DW_TAG_MIPS_loop:
4539 return "DW_TAG_MIPS_loop";
4540 case DW_TAG_format_label:
4541 return "DW_TAG_format_label";
4542 case DW_TAG_function_template:
4543 return "DW_TAG_function_template";
4544 case DW_TAG_class_template:
4545 return "DW_TAG_class_template";
4546 case DW_TAG_GNU_BINCL:
4547 return "DW_TAG_GNU_BINCL";
4548 case DW_TAG_GNU_EINCL:
4549 return "DW_TAG_GNU_EINCL";
4551 return "DW_TAG_<unknown>";
4555 /* Convert a DWARF attribute code into its string name. */
4558 dwarf_attr_name (unsigned int attr)
4563 return "DW_AT_sibling";
4564 case DW_AT_location:
4565 return "DW_AT_location";
4567 return "DW_AT_name";
4568 case DW_AT_ordering:
4569 return "DW_AT_ordering";
4570 case DW_AT_subscr_data:
4571 return "DW_AT_subscr_data";
4572 case DW_AT_byte_size:
4573 return "DW_AT_byte_size";
4574 case DW_AT_bit_offset:
4575 return "DW_AT_bit_offset";
4576 case DW_AT_bit_size:
4577 return "DW_AT_bit_size";
4578 case DW_AT_element_list:
4579 return "DW_AT_element_list";
4580 case DW_AT_stmt_list:
4581 return "DW_AT_stmt_list";
4583 return "DW_AT_low_pc";
4585 return "DW_AT_high_pc";
4586 case DW_AT_language:
4587 return "DW_AT_language";
4589 return "DW_AT_member";
4591 return "DW_AT_discr";
4592 case DW_AT_discr_value:
4593 return "DW_AT_discr_value";
4594 case DW_AT_visibility:
4595 return "DW_AT_visibility";
4597 return "DW_AT_import";
4598 case DW_AT_string_length:
4599 return "DW_AT_string_length";
4600 case DW_AT_common_reference:
4601 return "DW_AT_common_reference";
4602 case DW_AT_comp_dir:
4603 return "DW_AT_comp_dir";
4604 case DW_AT_const_value:
4605 return "DW_AT_const_value";
4606 case DW_AT_containing_type:
4607 return "DW_AT_containing_type";
4608 case DW_AT_default_value:
4609 return "DW_AT_default_value";
4611 return "DW_AT_inline";
4612 case DW_AT_is_optional:
4613 return "DW_AT_is_optional";
4614 case DW_AT_lower_bound:
4615 return "DW_AT_lower_bound";
4616 case DW_AT_producer:
4617 return "DW_AT_producer";
4618 case DW_AT_prototyped:
4619 return "DW_AT_prototyped";
4620 case DW_AT_return_addr:
4621 return "DW_AT_return_addr";
4622 case DW_AT_start_scope:
4623 return "DW_AT_start_scope";
4624 case DW_AT_stride_size:
4625 return "DW_AT_stride_size";
4626 case DW_AT_upper_bound:
4627 return "DW_AT_upper_bound";
4628 case DW_AT_abstract_origin:
4629 return "DW_AT_abstract_origin";
4630 case DW_AT_accessibility:
4631 return "DW_AT_accessibility";
4632 case DW_AT_address_class:
4633 return "DW_AT_address_class";
4634 case DW_AT_artificial:
4635 return "DW_AT_artificial";
4636 case DW_AT_base_types:
4637 return "DW_AT_base_types";
4638 case DW_AT_calling_convention:
4639 return "DW_AT_calling_convention";
4641 return "DW_AT_count";
4642 case DW_AT_data_member_location:
4643 return "DW_AT_data_member_location";
4644 case DW_AT_decl_column:
4645 return "DW_AT_decl_column";
4646 case DW_AT_decl_file:
4647 return "DW_AT_decl_file";
4648 case DW_AT_decl_line:
4649 return "DW_AT_decl_line";
4650 case DW_AT_declaration:
4651 return "DW_AT_declaration";
4652 case DW_AT_discr_list:
4653 return "DW_AT_discr_list";
4654 case DW_AT_encoding:
4655 return "DW_AT_encoding";
4656 case DW_AT_external:
4657 return "DW_AT_external";
4658 case DW_AT_frame_base:
4659 return "DW_AT_frame_base";
4661 return "DW_AT_friend";
4662 case DW_AT_identifier_case:
4663 return "DW_AT_identifier_case";
4664 case DW_AT_macro_info:
4665 return "DW_AT_macro_info";
4666 case DW_AT_namelist_items:
4667 return "DW_AT_namelist_items";
4668 case DW_AT_priority:
4669 return "DW_AT_priority";
4671 return "DW_AT_segment";
4672 case DW_AT_specification:
4673 return "DW_AT_specification";
4674 case DW_AT_static_link:
4675 return "DW_AT_static_link";
4677 return "DW_AT_type";
4678 case DW_AT_use_location:
4679 return "DW_AT_use_location";
4680 case DW_AT_variable_parameter:
4681 return "DW_AT_variable_parameter";
4682 case DW_AT_virtuality:
4683 return "DW_AT_virtuality";
4684 case DW_AT_vtable_elem_location:
4685 return "DW_AT_vtable_elem_location";
4687 case DW_AT_allocated:
4688 return "DW_AT_allocated";
4689 case DW_AT_associated:
4690 return "DW_AT_associated";
4691 case DW_AT_data_location:
4692 return "DW_AT_data_location";
4694 return "DW_AT_stride";
4695 case DW_AT_entry_pc:
4696 return "DW_AT_entry_pc";
4697 case DW_AT_use_UTF8:
4698 return "DW_AT_use_UTF8";
4699 case DW_AT_extension:
4700 return "DW_AT_extension";
4702 return "DW_AT_ranges";
4703 case DW_AT_trampoline:
4704 return "DW_AT_trampoline";
4705 case DW_AT_call_column:
4706 return "DW_AT_call_column";
4707 case DW_AT_call_file:
4708 return "DW_AT_call_file";
4709 case DW_AT_call_line:
4710 return "DW_AT_call_line";
4712 case DW_AT_MIPS_fde:
4713 return "DW_AT_MIPS_fde";
4714 case DW_AT_MIPS_loop_begin:
4715 return "DW_AT_MIPS_loop_begin";
4716 case DW_AT_MIPS_tail_loop_begin:
4717 return "DW_AT_MIPS_tail_loop_begin";
4718 case DW_AT_MIPS_epilog_begin:
4719 return "DW_AT_MIPS_epilog_begin";
4720 case DW_AT_MIPS_loop_unroll_factor:
4721 return "DW_AT_MIPS_loop_unroll_factor";
4722 case DW_AT_MIPS_software_pipeline_depth:
4723 return "DW_AT_MIPS_software_pipeline_depth";
4724 case DW_AT_MIPS_linkage_name:
4725 return "DW_AT_MIPS_linkage_name";
4726 case DW_AT_MIPS_stride:
4727 return "DW_AT_MIPS_stride";
4728 case DW_AT_MIPS_abstract_name:
4729 return "DW_AT_MIPS_abstract_name";
4730 case DW_AT_MIPS_clone_origin:
4731 return "DW_AT_MIPS_clone_origin";
4732 case DW_AT_MIPS_has_inlines:
4733 return "DW_AT_MIPS_has_inlines";
4735 case DW_AT_sf_names:
4736 return "DW_AT_sf_names";
4737 case DW_AT_src_info:
4738 return "DW_AT_src_info";
4739 case DW_AT_mac_info:
4740 return "DW_AT_mac_info";
4741 case DW_AT_src_coords:
4742 return "DW_AT_src_coords";
4743 case DW_AT_body_begin:
4744 return "DW_AT_body_begin";
4745 case DW_AT_body_end:
4746 return "DW_AT_body_end";
4747 case DW_AT_GNU_vector:
4748 return "DW_AT_GNU_vector";
4750 case DW_AT_VMS_rtnbeg_pd_address:
4751 return "DW_AT_VMS_rtnbeg_pd_address";
4754 return "DW_AT_<unknown>";
4758 /* Convert a DWARF value form code into its string name. */
4761 dwarf_form_name (unsigned int form)
4766 return "DW_FORM_addr";
4767 case DW_FORM_block2:
4768 return "DW_FORM_block2";
4769 case DW_FORM_block4:
4770 return "DW_FORM_block4";
4772 return "DW_FORM_data2";
4774 return "DW_FORM_data4";
4776 return "DW_FORM_data8";
4777 case DW_FORM_string:
4778 return "DW_FORM_string";
4780 return "DW_FORM_block";
4781 case DW_FORM_block1:
4782 return "DW_FORM_block1";
4784 return "DW_FORM_data1";
4786 return "DW_FORM_flag";
4788 return "DW_FORM_sdata";
4790 return "DW_FORM_strp";
4792 return "DW_FORM_udata";
4793 case DW_FORM_ref_addr:
4794 return "DW_FORM_ref_addr";
4796 return "DW_FORM_ref1";
4798 return "DW_FORM_ref2";
4800 return "DW_FORM_ref4";
4802 return "DW_FORM_ref8";
4803 case DW_FORM_ref_udata:
4804 return "DW_FORM_ref_udata";
4805 case DW_FORM_indirect:
4806 return "DW_FORM_indirect";
4808 return "DW_FORM_<unknown>";
4812 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4813 instance of an inlined instance of a decl which is local to an inline
4814 function, so we have to trace all of the way back through the origin chain
4815 to find out what sort of node actually served as the original seed for the
4819 decl_ultimate_origin (tree decl)
4821 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4824 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4825 nodes in the function to point to themselves; ignore that if
4826 we're trying to output the abstract instance of this function. */
4827 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4830 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4831 most distant ancestor, this should never happen. */
4832 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4834 return DECL_ABSTRACT_ORIGIN (decl);
4837 /* Determine the "ultimate origin" of a block. The block may be an inlined
4838 instance of an inlined instance of a block which is local to an inline
4839 function, so we have to trace all of the way back through the origin chain
4840 to find out what sort of node actually served as the original seed for the
4844 block_ultimate_origin (tree block)
4846 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4848 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4849 nodes in the function to point to themselves; ignore that if
4850 we're trying to output the abstract instance of this function. */
4851 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4854 if (immediate_origin == NULL_TREE)
4859 tree lookahead = immediate_origin;
4863 ret_val = lookahead;
4864 lookahead = (TREE_CODE (ret_val) == BLOCK
4865 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4867 while (lookahead != NULL && lookahead != ret_val);
4869 /* The block's abstract origin chain may not be the *ultimate* origin of
4870 the block. It could lead to a DECL that has an abstract origin set.
4871 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4872 will give us if it has one). Note that DECL's abstract origins are
4873 supposed to be the most distant ancestor (or so decl_ultimate_origin
4874 claims), so we don't need to loop following the DECL origins. */
4875 if (DECL_P (ret_val))
4876 return DECL_ORIGIN (ret_val);
4882 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4883 of a virtual function may refer to a base class, so we check the 'this'
4887 decl_class_context (tree decl)
4889 tree context = NULL_TREE;
4891 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4892 context = DECL_CONTEXT (decl);
4894 context = TYPE_MAIN_VARIANT
4895 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4897 if (context && !TYPE_P (context))
4898 context = NULL_TREE;
4903 /* Add an attribute/value pair to a DIE. */
4906 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4908 /* Maybe this should be an assert? */
4912 if (die->die_attr == NULL)
4913 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4914 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4917 static inline enum dw_val_class
4918 AT_class (dw_attr_ref a)
4920 return a->dw_attr_val.val_class;
4923 /* Add a flag value attribute to a DIE. */
4926 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4930 attr.dw_attr = attr_kind;
4931 attr.dw_attr_val.val_class = dw_val_class_flag;
4932 attr.dw_attr_val.v.val_flag = flag;
4933 add_dwarf_attr (die, &attr);
4936 static inline unsigned
4937 AT_flag (dw_attr_ref a)
4939 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4940 return a->dw_attr_val.v.val_flag;
4943 /* Add a signed integer attribute value to a DIE. */
4946 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4950 attr.dw_attr = attr_kind;
4951 attr.dw_attr_val.val_class = dw_val_class_const;
4952 attr.dw_attr_val.v.val_int = int_val;
4953 add_dwarf_attr (die, &attr);
4956 static inline HOST_WIDE_INT
4957 AT_int (dw_attr_ref a)
4959 gcc_assert (a && AT_class (a) == dw_val_class_const);
4960 return a->dw_attr_val.v.val_int;
4963 /* Add an unsigned integer attribute value to a DIE. */
4966 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4967 unsigned HOST_WIDE_INT unsigned_val)
4971 attr.dw_attr = attr_kind;
4972 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4973 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4974 add_dwarf_attr (die, &attr);
4977 static inline unsigned HOST_WIDE_INT
4978 AT_unsigned (dw_attr_ref a)
4980 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4981 return a->dw_attr_val.v.val_unsigned;
4984 /* Add an unsigned double integer attribute value to a DIE. */
4987 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4988 long unsigned int val_hi, long unsigned int val_low)
4992 attr.dw_attr = attr_kind;
4993 attr.dw_attr_val.val_class = dw_val_class_long_long;
4994 attr.dw_attr_val.v.val_long_long.hi = val_hi;
4995 attr.dw_attr_val.v.val_long_long.low = val_low;
4996 add_dwarf_attr (die, &attr);
4999 /* Add a floating point attribute value to a DIE and return it. */
5002 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5003 unsigned int length, unsigned int elt_size, unsigned char *array)
5007 attr.dw_attr = attr_kind;
5008 attr.dw_attr_val.val_class = dw_val_class_vec;
5009 attr.dw_attr_val.v.val_vec.length = length;
5010 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5011 attr.dw_attr_val.v.val_vec.array = array;
5012 add_dwarf_attr (die, &attr);
5015 /* Hash and equality functions for debug_str_hash. */
5018 debug_str_do_hash (const void *x)
5020 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5024 debug_str_eq (const void *x1, const void *x2)
5026 return strcmp ((((const struct indirect_string_node *)x1)->str),
5027 (const char *)x2) == 0;
5030 /* Add a string attribute value to a DIE. */
5033 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5036 struct indirect_string_node *node;
5039 if (! debug_str_hash)
5040 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5041 debug_str_eq, NULL);
5043 slot = htab_find_slot_with_hash (debug_str_hash, str,
5044 htab_hash_string (str), INSERT);
5047 node = (struct indirect_string_node *)
5048 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5049 node->str = ggc_strdup (str);
5053 node = (struct indirect_string_node *) *slot;
5057 attr.dw_attr = attr_kind;
5058 attr.dw_attr_val.val_class = dw_val_class_str;
5059 attr.dw_attr_val.v.val_str = node;
5060 add_dwarf_attr (die, &attr);
5063 static inline const char *
5064 AT_string (dw_attr_ref a)
5066 gcc_assert (a && AT_class (a) == dw_val_class_str);
5067 return a->dw_attr_val.v.val_str->str;
5070 /* Find out whether a string should be output inline in DIE
5071 or out-of-line in .debug_str section. */
5074 AT_string_form (dw_attr_ref a)
5076 struct indirect_string_node *node;
5080 gcc_assert (a && AT_class (a) == dw_val_class_str);
5082 node = a->dw_attr_val.v.val_str;
5086 len = strlen (node->str) + 1;
5088 /* If the string is shorter or equal to the size of the reference, it is
5089 always better to put it inline. */
5090 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5091 return node->form = DW_FORM_string;
5093 /* If we cannot expect the linker to merge strings in .debug_str
5094 section, only put it into .debug_str if it is worth even in this
5096 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5097 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5098 return node->form = DW_FORM_string;
5100 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5101 ++dw2_string_counter;
5102 node->label = xstrdup (label);
5104 return node->form = DW_FORM_strp;
5107 /* Add a DIE reference attribute value to a DIE. */
5110 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5114 attr.dw_attr = attr_kind;
5115 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5116 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5117 attr.dw_attr_val.v.val_die_ref.external = 0;
5118 add_dwarf_attr (die, &attr);
5121 /* Add an AT_specification attribute to a DIE, and also make the back
5122 pointer from the specification to the definition. */
5125 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5127 add_AT_die_ref (die, DW_AT_specification, targ_die);
5128 gcc_assert (!targ_die->die_definition);
5129 targ_die->die_definition = die;
5132 static inline dw_die_ref
5133 AT_ref (dw_attr_ref a)
5135 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5136 return a->dw_attr_val.v.val_die_ref.die;
5140 AT_ref_external (dw_attr_ref a)
5142 if (a && AT_class (a) == dw_val_class_die_ref)
5143 return a->dw_attr_val.v.val_die_ref.external;
5149 set_AT_ref_external (dw_attr_ref a, int i)
5151 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5152 a->dw_attr_val.v.val_die_ref.external = i;
5155 /* Add an FDE reference attribute value to a DIE. */
5158 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5162 attr.dw_attr = attr_kind;
5163 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5164 attr.dw_attr_val.v.val_fde_index = targ_fde;
5165 add_dwarf_attr (die, &attr);
5168 /* Add a location description attribute value to a DIE. */
5171 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5175 attr.dw_attr = attr_kind;
5176 attr.dw_attr_val.val_class = dw_val_class_loc;
5177 attr.dw_attr_val.v.val_loc = loc;
5178 add_dwarf_attr (die, &attr);
5181 static inline dw_loc_descr_ref
5182 AT_loc (dw_attr_ref a)
5184 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5185 return a->dw_attr_val.v.val_loc;
5189 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5193 attr.dw_attr = attr_kind;
5194 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5195 attr.dw_attr_val.v.val_loc_list = loc_list;
5196 add_dwarf_attr (die, &attr);
5197 have_location_lists = true;
5200 static inline dw_loc_list_ref
5201 AT_loc_list (dw_attr_ref a)
5203 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5204 return a->dw_attr_val.v.val_loc_list;
5207 /* Add an address constant attribute value to a DIE. */
5210 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5214 attr.dw_attr = attr_kind;
5215 attr.dw_attr_val.val_class = dw_val_class_addr;
5216 attr.dw_attr_val.v.val_addr = addr;
5217 add_dwarf_attr (die, &attr);
5220 /* Get the RTX from to an address DIE attribute. */
5223 AT_addr (dw_attr_ref a)
5225 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5226 return a->dw_attr_val.v.val_addr;
5229 /* Add a file attribute value to a DIE. */
5232 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5233 struct dwarf_file_data *fd)
5237 attr.dw_attr = attr_kind;
5238 attr.dw_attr_val.val_class = dw_val_class_file;
5239 attr.dw_attr_val.v.val_file = fd;
5240 add_dwarf_attr (die, &attr);
5243 /* Get the dwarf_file_data from a file DIE attribute. */
5245 static inline struct dwarf_file_data *
5246 AT_file (dw_attr_ref a)
5248 gcc_assert (a && AT_class (a) == dw_val_class_file);
5249 return a->dw_attr_val.v.val_file;
5252 /* Add a label identifier attribute value to a DIE. */
5255 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5259 attr.dw_attr = attr_kind;
5260 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5261 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5262 add_dwarf_attr (die, &attr);
5265 /* Add a section offset attribute value to a DIE, an offset into the
5266 debug_line section. */
5269 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5274 attr.dw_attr = attr_kind;
5275 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5276 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5277 add_dwarf_attr (die, &attr);
5280 /* Add a section offset attribute value to a DIE, an offset into the
5281 debug_macinfo section. */
5284 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5289 attr.dw_attr = attr_kind;
5290 attr.dw_attr_val.val_class = dw_val_class_macptr;
5291 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5292 add_dwarf_attr (die, &attr);
5295 /* Add an offset attribute value to a DIE. */
5298 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5299 unsigned HOST_WIDE_INT offset)
5303 attr.dw_attr = attr_kind;
5304 attr.dw_attr_val.val_class = dw_val_class_offset;
5305 attr.dw_attr_val.v.val_offset = offset;
5306 add_dwarf_attr (die, &attr);
5309 /* Add an range_list attribute value to a DIE. */
5312 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5313 long unsigned int offset)
5317 attr.dw_attr = attr_kind;
5318 attr.dw_attr_val.val_class = dw_val_class_range_list;
5319 attr.dw_attr_val.v.val_offset = offset;
5320 add_dwarf_attr (die, &attr);
5323 static inline const char *
5324 AT_lbl (dw_attr_ref a)
5326 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5327 || AT_class (a) == dw_val_class_lineptr
5328 || AT_class (a) == dw_val_class_macptr));
5329 return a->dw_attr_val.v.val_lbl_id;
5332 /* Get the attribute of type attr_kind. */
5335 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5339 dw_die_ref spec = NULL;
5344 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5345 if (a->dw_attr == attr_kind)
5347 else if (a->dw_attr == DW_AT_specification
5348 || a->dw_attr == DW_AT_abstract_origin)
5352 return get_AT (spec, attr_kind);
5357 /* Return the "low pc" attribute value, typically associated with a subprogram
5358 DIE. Return null if the "low pc" attribute is either not present, or if it
5359 cannot be represented as an assembler label identifier. */
5361 static inline const char *
5362 get_AT_low_pc (dw_die_ref die)
5364 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5366 return a ? AT_lbl (a) : NULL;
5369 /* Return the "high pc" attribute value, typically associated with a subprogram
5370 DIE. Return null if the "high pc" attribute is either not present, or if it
5371 cannot be represented as an assembler label identifier. */
5373 static inline const char *
5374 get_AT_hi_pc (dw_die_ref die)
5376 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5378 return a ? AT_lbl (a) : NULL;
5381 /* Return the value of the string attribute designated by ATTR_KIND, or
5382 NULL if it is not present. */
5384 static inline const char *
5385 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5387 dw_attr_ref a = get_AT (die, attr_kind);
5389 return a ? AT_string (a) : NULL;
5392 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5393 if it is not present. */
5396 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5398 dw_attr_ref a = get_AT (die, attr_kind);
5400 return a ? AT_flag (a) : 0;
5403 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5404 if it is not present. */
5406 static inline unsigned
5407 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5409 dw_attr_ref a = get_AT (die, attr_kind);
5411 return a ? AT_unsigned (a) : 0;
5414 static inline dw_die_ref
5415 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5417 dw_attr_ref a = get_AT (die, attr_kind);
5419 return a ? AT_ref (a) : NULL;
5422 static inline struct dwarf_file_data *
5423 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5425 dw_attr_ref a = get_AT (die, attr_kind);
5427 return a ? AT_file (a) : NULL;
5430 /* Return TRUE if the language is C or C++. */
5435 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5437 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5438 || lang == DW_LANG_C99
5439 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5442 /* Return TRUE if the language is C++. */
5447 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5449 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5452 /* Return TRUE if the language is Fortran. */
5457 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5459 return (lang == DW_LANG_Fortran77
5460 || lang == DW_LANG_Fortran90
5461 || lang == DW_LANG_Fortran95);
5464 /* Return TRUE if the language is Java. */
5469 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5471 return lang == DW_LANG_Java;
5474 /* Return TRUE if the language is Ada. */
5479 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5481 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5484 /* Remove the specified attribute if present. */
5487 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5495 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5496 if (a->dw_attr == attr_kind)
5498 if (AT_class (a) == dw_val_class_str)
5499 if (a->dw_attr_val.v.val_str->refcount)
5500 a->dw_attr_val.v.val_str->refcount--;
5502 /* VEC_ordered_remove should help reduce the number of abbrevs
5504 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5509 /* Remove CHILD from its parent. PREV must have the property that
5510 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5513 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5515 gcc_assert (child->die_parent == prev->die_parent);
5516 gcc_assert (prev->die_sib == child);
5519 gcc_assert (child->die_parent->die_child == child);
5523 prev->die_sib = child->die_sib;
5524 if (child->die_parent->die_child == child)
5525 child->die_parent->die_child = prev;
5528 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5532 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5538 dw_die_ref prev = c;
5540 while (c->die_tag == tag)
5542 remove_child_with_prev (c, prev);
5543 /* Might have removed every child. */
5544 if (c == c->die_sib)
5548 } while (c != die->die_child);
5551 /* Add a CHILD_DIE as the last child of DIE. */
5554 add_child_die (dw_die_ref die, dw_die_ref child_die)
5556 /* FIXME this should probably be an assert. */
5557 if (! die || ! child_die)
5559 gcc_assert (die != child_die);
5561 child_die->die_parent = die;
5564 child_die->die_sib = die->die_child->die_sib;
5565 die->die_child->die_sib = child_die;
5568 child_die->die_sib = child_die;
5569 die->die_child = child_die;
5572 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5573 is the specification, to the end of PARENT's list of children.
5574 This is done by removing and re-adding it. */
5577 splice_child_die (dw_die_ref parent, dw_die_ref child)
5581 /* We want the declaration DIE from inside the class, not the
5582 specification DIE at toplevel. */
5583 if (child->die_parent != parent)
5585 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5591 gcc_assert (child->die_parent == parent
5592 || (child->die_parent
5593 == get_AT_ref (parent, DW_AT_specification)));
5595 for (p = child->die_parent->die_child; ; p = p->die_sib)
5596 if (p->die_sib == child)
5598 remove_child_with_prev (child, p);
5602 add_child_die (parent, child);
5605 /* Return a pointer to a newly created DIE node. */
5607 static inline dw_die_ref
5608 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5610 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5612 die->die_tag = tag_value;
5614 if (parent_die != NULL)
5615 add_child_die (parent_die, die);
5618 limbo_die_node *limbo_node;
5620 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5621 limbo_node->die = die;
5622 limbo_node->created_for = t;
5623 limbo_node->next = limbo_die_list;
5624 limbo_die_list = limbo_node;
5630 /* Return the DIE associated with the given type specifier. */
5632 static inline dw_die_ref
5633 lookup_type_die (tree type)
5635 return TYPE_SYMTAB_DIE (type);
5638 /* Equate a DIE to a given type specifier. */
5641 equate_type_number_to_die (tree type, dw_die_ref type_die)
5643 TYPE_SYMTAB_DIE (type) = type_die;
5646 /* Returns a hash value for X (which really is a die_struct). */
5649 decl_die_table_hash (const void *x)
5651 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5654 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5657 decl_die_table_eq (const void *x, const void *y)
5659 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5662 /* Return the DIE associated with a given declaration. */
5664 static inline dw_die_ref
5665 lookup_decl_die (tree decl)
5667 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5670 /* Returns a hash value for X (which really is a var_loc_list). */
5673 decl_loc_table_hash (const void *x)
5675 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5678 /* Return nonzero if decl_id of var_loc_list X is the same as
5682 decl_loc_table_eq (const void *x, const void *y)
5684 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5687 /* Return the var_loc list associated with a given declaration. */
5689 static inline var_loc_list *
5690 lookup_decl_loc (tree decl)
5692 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5695 /* Equate a DIE to a particular declaration. */
5698 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5700 unsigned int decl_id = DECL_UID (decl);
5703 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5705 decl_die->decl_id = decl_id;
5708 /* Add a variable location node to the linked list for DECL. */
5711 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5713 unsigned int decl_id = DECL_UID (decl);
5717 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5720 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5721 temp->decl_id = decl_id;
5729 /* If the current location is the same as the end of the list,
5730 we have nothing to do. */
5731 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5732 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5734 /* Add LOC to the end of list and update LAST. */
5735 temp->last->next = loc;
5739 /* Do not add empty location to the beginning of the list. */
5740 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5747 /* Keep track of the number of spaces used to indent the
5748 output of the debugging routines that print the structure of
5749 the DIE internal representation. */
5750 static int print_indent;
5752 /* Indent the line the number of spaces given by print_indent. */
5755 print_spaces (FILE *outfile)
5757 fprintf (outfile, "%*s", print_indent, "");
5760 /* Print the information associated with a given DIE, and its children.
5761 This routine is a debugging aid only. */
5764 print_die (dw_die_ref die, FILE *outfile)
5770 print_spaces (outfile);
5771 fprintf (outfile, "DIE %4ld: %s\n",
5772 die->die_offset, dwarf_tag_name (die->die_tag));
5773 print_spaces (outfile);
5774 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5775 fprintf (outfile, " offset: %ld\n", die->die_offset);
5777 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5779 print_spaces (outfile);
5780 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5782 switch (AT_class (a))
5784 case dw_val_class_addr:
5785 fprintf (outfile, "address");
5787 case dw_val_class_offset:
5788 fprintf (outfile, "offset");
5790 case dw_val_class_loc:
5791 fprintf (outfile, "location descriptor");
5793 case dw_val_class_loc_list:
5794 fprintf (outfile, "location list -> label:%s",
5795 AT_loc_list (a)->ll_symbol);
5797 case dw_val_class_range_list:
5798 fprintf (outfile, "range list");
5800 case dw_val_class_const:
5801 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5803 case dw_val_class_unsigned_const:
5804 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5806 case dw_val_class_long_long:
5807 fprintf (outfile, "constant (%lu,%lu)",
5808 a->dw_attr_val.v.val_long_long.hi,
5809 a->dw_attr_val.v.val_long_long.low);
5811 case dw_val_class_vec:
5812 fprintf (outfile, "floating-point or vector constant");
5814 case dw_val_class_flag:
5815 fprintf (outfile, "%u", AT_flag (a));
5817 case dw_val_class_die_ref:
5818 if (AT_ref (a) != NULL)
5820 if (AT_ref (a)->die_symbol)
5821 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5823 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5826 fprintf (outfile, "die -> <null>");
5828 case dw_val_class_lbl_id:
5829 case dw_val_class_lineptr:
5830 case dw_val_class_macptr:
5831 fprintf (outfile, "label: %s", AT_lbl (a));
5833 case dw_val_class_str:
5834 if (AT_string (a) != NULL)
5835 fprintf (outfile, "\"%s\"", AT_string (a));
5837 fprintf (outfile, "<null>");
5839 case dw_val_class_file:
5840 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5841 AT_file (a)->emitted_number);
5847 fprintf (outfile, "\n");
5850 if (die->die_child != NULL)
5853 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5856 if (print_indent == 0)
5857 fprintf (outfile, "\n");
5860 /* Print the contents of the source code line number correspondence table.
5861 This routine is a debugging aid only. */
5864 print_dwarf_line_table (FILE *outfile)
5867 dw_line_info_ref line_info;
5869 fprintf (outfile, "\n\nDWARF source line information\n");
5870 for (i = 1; i < line_info_table_in_use; i++)
5872 line_info = &line_info_table[i];
5873 fprintf (outfile, "%5d: %4ld %6ld\n", i,
5874 line_info->dw_file_num,
5875 line_info->dw_line_num);
5878 fprintf (outfile, "\n\n");
5881 /* Print the information collected for a given DIE. */
5884 debug_dwarf_die (dw_die_ref die)
5886 print_die (die, stderr);
5889 /* Print all DWARF information collected for the compilation unit.
5890 This routine is a debugging aid only. */
5896 print_die (comp_unit_die, stderr);
5897 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5898 print_dwarf_line_table (stderr);
5901 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5902 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5903 DIE that marks the start of the DIEs for this include file. */
5906 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5908 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5909 dw_die_ref new_unit = gen_compile_unit_die (filename);
5911 new_unit->die_sib = old_unit;
5915 /* Close an include-file CU and reopen the enclosing one. */
5918 pop_compile_unit (dw_die_ref old_unit)
5920 dw_die_ref new_unit = old_unit->die_sib;
5922 old_unit->die_sib = NULL;
5926 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5927 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5929 /* Calculate the checksum of a location expression. */
5932 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5934 CHECKSUM (loc->dw_loc_opc);
5935 CHECKSUM (loc->dw_loc_oprnd1);
5936 CHECKSUM (loc->dw_loc_oprnd2);
5939 /* Calculate the checksum of an attribute. */
5942 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5944 dw_loc_descr_ref loc;
5947 CHECKSUM (at->dw_attr);
5949 /* We don't care that this was compiled with a different compiler
5950 snapshot; if the output is the same, that's what matters. */
5951 if (at->dw_attr == DW_AT_producer)
5954 switch (AT_class (at))
5956 case dw_val_class_const:
5957 CHECKSUM (at->dw_attr_val.v.val_int);
5959 case dw_val_class_unsigned_const:
5960 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5962 case dw_val_class_long_long:
5963 CHECKSUM (at->dw_attr_val.v.val_long_long);
5965 case dw_val_class_vec:
5966 CHECKSUM (at->dw_attr_val.v.val_vec);
5968 case dw_val_class_flag:
5969 CHECKSUM (at->dw_attr_val.v.val_flag);
5971 case dw_val_class_str:
5972 CHECKSUM_STRING (AT_string (at));
5975 case dw_val_class_addr:
5977 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5978 CHECKSUM_STRING (XSTR (r, 0));
5981 case dw_val_class_offset:
5982 CHECKSUM (at->dw_attr_val.v.val_offset);
5985 case dw_val_class_loc:
5986 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5987 loc_checksum (loc, ctx);
5990 case dw_val_class_die_ref:
5991 die_checksum (AT_ref (at), ctx, mark);
5994 case dw_val_class_fde_ref:
5995 case dw_val_class_lbl_id:
5996 case dw_val_class_lineptr:
5997 case dw_val_class_macptr:
6000 case dw_val_class_file:
6001 CHECKSUM_STRING (AT_file (at)->filename);
6009 /* Calculate the checksum of a DIE. */
6012 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6018 /* To avoid infinite recursion. */
6021 CHECKSUM (die->die_mark);
6024 die->die_mark = ++(*mark);
6026 CHECKSUM (die->die_tag);
6028 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6029 attr_checksum (a, ctx, mark);
6031 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6035 #undef CHECKSUM_STRING
6037 /* Do the location expressions look same? */
6039 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6041 return loc1->dw_loc_opc == loc2->dw_loc_opc
6042 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6043 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6046 /* Do the values look the same? */
6048 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
6050 dw_loc_descr_ref loc1, loc2;
6053 if (v1->val_class != v2->val_class)
6056 switch (v1->val_class)
6058 case dw_val_class_const:
6059 return v1->v.val_int == v2->v.val_int;
6060 case dw_val_class_unsigned_const:
6061 return v1->v.val_unsigned == v2->v.val_unsigned;
6062 case dw_val_class_long_long:
6063 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6064 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6065 case dw_val_class_vec:
6066 if (v1->v.val_vec.length != v2->v.val_vec.length
6067 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6069 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6070 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6073 case dw_val_class_flag:
6074 return v1->v.val_flag == v2->v.val_flag;
6075 case dw_val_class_str:
6076 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6078 case dw_val_class_addr:
6079 r1 = v1->v.val_addr;
6080 r2 = v2->v.val_addr;
6081 if (GET_CODE (r1) != GET_CODE (r2))
6083 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6084 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6086 case dw_val_class_offset:
6087 return v1->v.val_offset == v2->v.val_offset;
6089 case dw_val_class_loc:
6090 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6092 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6093 if (!same_loc_p (loc1, loc2, mark))
6095 return !loc1 && !loc2;
6097 case dw_val_class_die_ref:
6098 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6100 case dw_val_class_fde_ref:
6101 case dw_val_class_lbl_id:
6102 case dw_val_class_lineptr:
6103 case dw_val_class_macptr:
6106 case dw_val_class_file:
6107 return v1->v.val_file == v2->v.val_file;
6114 /* Do the attributes look the same? */
6117 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6119 if (at1->dw_attr != at2->dw_attr)
6122 /* We don't care that this was compiled with a different compiler
6123 snapshot; if the output is the same, that's what matters. */
6124 if (at1->dw_attr == DW_AT_producer)
6127 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6130 /* Do the dies look the same? */
6133 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6139 /* To avoid infinite recursion. */
6141 return die1->die_mark == die2->die_mark;
6142 die1->die_mark = die2->die_mark = ++(*mark);
6144 if (die1->die_tag != die2->die_tag)
6147 if (VEC_length (dw_attr_node, die1->die_attr)
6148 != VEC_length (dw_attr_node, die2->die_attr))
6151 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6152 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6155 c1 = die1->die_child;
6156 c2 = die2->die_child;
6165 if (!same_die_p (c1, c2, mark))
6169 if (c1 == die1->die_child)
6171 if (c2 == die2->die_child)
6181 /* Do the dies look the same? Wrapper around same_die_p. */
6184 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6187 int ret = same_die_p (die1, die2, &mark);
6189 unmark_all_dies (die1);
6190 unmark_all_dies (die2);
6195 /* The prefix to attach to symbols on DIEs in the current comdat debug
6197 static char *comdat_symbol_id;
6199 /* The index of the current symbol within the current comdat CU. */
6200 static unsigned int comdat_symbol_number;
6202 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6203 children, and set comdat_symbol_id accordingly. */
6206 compute_section_prefix (dw_die_ref unit_die)
6208 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6209 const char *base = die_name ? lbasename (die_name) : "anonymous";
6210 char *name = alloca (strlen (base) + 64);
6213 unsigned char checksum[16];
6216 /* Compute the checksum of the DIE, then append part of it as hex digits to
6217 the name filename of the unit. */
6219 md5_init_ctx (&ctx);
6221 die_checksum (unit_die, &ctx, &mark);
6222 unmark_all_dies (unit_die);
6223 md5_finish_ctx (&ctx, checksum);
6225 sprintf (name, "%s.", base);
6226 clean_symbol_name (name);
6228 p = name + strlen (name);
6229 for (i = 0; i < 4; i++)
6231 sprintf (p, "%.2x", checksum[i]);
6235 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6236 comdat_symbol_number = 0;
6239 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6242 is_type_die (dw_die_ref die)
6244 switch (die->die_tag)
6246 case DW_TAG_array_type:
6247 case DW_TAG_class_type:
6248 case DW_TAG_enumeration_type:
6249 case DW_TAG_pointer_type:
6250 case DW_TAG_reference_type:
6251 case DW_TAG_string_type:
6252 case DW_TAG_structure_type:
6253 case DW_TAG_subroutine_type:
6254 case DW_TAG_union_type:
6255 case DW_TAG_ptr_to_member_type:
6256 case DW_TAG_set_type:
6257 case DW_TAG_subrange_type:
6258 case DW_TAG_base_type:
6259 case DW_TAG_const_type:
6260 case DW_TAG_file_type:
6261 case DW_TAG_packed_type:
6262 case DW_TAG_volatile_type:
6263 case DW_TAG_typedef:
6270 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6271 Basically, we want to choose the bits that are likely to be shared between
6272 compilations (types) and leave out the bits that are specific to individual
6273 compilations (functions). */
6276 is_comdat_die (dw_die_ref c)
6278 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6279 we do for stabs. The advantage is a greater likelihood of sharing between
6280 objects that don't include headers in the same order (and therefore would
6281 put the base types in a different comdat). jason 8/28/00 */
6283 if (c->die_tag == DW_TAG_base_type)
6286 if (c->die_tag == DW_TAG_pointer_type
6287 || c->die_tag == DW_TAG_reference_type
6288 || c->die_tag == DW_TAG_const_type
6289 || c->die_tag == DW_TAG_volatile_type)
6291 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6293 return t ? is_comdat_die (t) : 0;
6296 return is_type_die (c);
6299 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6300 compilation unit. */
6303 is_symbol_die (dw_die_ref c)
6305 return (is_type_die (c)
6306 || (get_AT (c, DW_AT_declaration)
6307 && !get_AT (c, DW_AT_specification))
6308 || c->die_tag == DW_TAG_namespace);
6312 gen_internal_sym (const char *prefix)
6316 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6317 return xstrdup (buf);
6320 /* Assign symbols to all worthy DIEs under DIE. */
6323 assign_symbol_names (dw_die_ref die)
6327 if (is_symbol_die (die))
6329 if (comdat_symbol_id)
6331 char *p = alloca (strlen (comdat_symbol_id) + 64);
6333 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6334 comdat_symbol_id, comdat_symbol_number++);
6335 die->die_symbol = xstrdup (p);
6338 die->die_symbol = gen_internal_sym ("LDIE");
6341 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6344 struct cu_hash_table_entry
6347 unsigned min_comdat_num, max_comdat_num;
6348 struct cu_hash_table_entry *next;
6351 /* Routines to manipulate hash table of CUs. */
6353 htab_cu_hash (const void *of)
6355 const struct cu_hash_table_entry *entry = of;
6357 return htab_hash_string (entry->cu->die_symbol);
6361 htab_cu_eq (const void *of1, const void *of2)
6363 const struct cu_hash_table_entry *entry1 = of1;
6364 const struct die_struct *entry2 = of2;
6366 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6370 htab_cu_del (void *what)
6372 struct cu_hash_table_entry *next, *entry = what;
6382 /* Check whether we have already seen this CU and set up SYM_NUM
6385 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6387 struct cu_hash_table_entry dummy;
6388 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6390 dummy.max_comdat_num = 0;
6392 slot = (struct cu_hash_table_entry **)
6393 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6397 for (; entry; last = entry, entry = entry->next)
6399 if (same_die_p_wrap (cu, entry->cu))
6405 *sym_num = entry->min_comdat_num;
6409 entry = XCNEW (struct cu_hash_table_entry);
6411 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6412 entry->next = *slot;
6418 /* Record SYM_NUM to record of CU in HTABLE. */
6420 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6422 struct cu_hash_table_entry **slot, *entry;
6424 slot = (struct cu_hash_table_entry **)
6425 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6429 entry->max_comdat_num = sym_num;
6432 /* Traverse the DIE (which is always comp_unit_die), and set up
6433 additional compilation units for each of the include files we see
6434 bracketed by BINCL/EINCL. */
6437 break_out_includes (dw_die_ref die)
6440 dw_die_ref unit = NULL;
6441 limbo_die_node *node, **pnode;
6442 htab_t cu_hash_table;
6446 dw_die_ref prev = c;
6448 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6449 || (unit && is_comdat_die (c)))
6451 dw_die_ref next = c->die_sib;
6453 /* This DIE is for a secondary CU; remove it from the main one. */
6454 remove_child_with_prev (c, prev);
6456 if (c->die_tag == DW_TAG_GNU_BINCL)
6457 unit = push_new_compile_unit (unit, c);
6458 else if (c->die_tag == DW_TAG_GNU_EINCL)
6459 unit = pop_compile_unit (unit);
6461 add_child_die (unit, c);
6463 if (c == die->die_child)
6466 } while (c != die->die_child);
6469 /* We can only use this in debugging, since the frontend doesn't check
6470 to make sure that we leave every include file we enter. */
6474 assign_symbol_names (die);
6475 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6476 for (node = limbo_die_list, pnode = &limbo_die_list;
6482 compute_section_prefix (node->die);
6483 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6484 &comdat_symbol_number);
6485 assign_symbol_names (node->die);
6487 *pnode = node->next;
6490 pnode = &node->next;
6491 record_comdat_symbol_number (node->die, cu_hash_table,
6492 comdat_symbol_number);
6495 htab_delete (cu_hash_table);
6498 /* Traverse the DIE and add a sibling attribute if it may have the
6499 effect of speeding up access to siblings. To save some space,
6500 avoid generating sibling attributes for DIE's without children. */
6503 add_sibling_attributes (dw_die_ref die)
6507 if (! die->die_child)
6510 if (die->die_parent && die != die->die_parent->die_child)
6511 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6513 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6516 /* Output all location lists for the DIE and its children. */
6519 output_location_lists (dw_die_ref die)
6525 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6526 if (AT_class (a) == dw_val_class_loc_list)
6527 output_loc_list (AT_loc_list (a));
6529 FOR_EACH_CHILD (die, c, output_location_lists (c));
6532 /* The format of each DIE (and its attribute value pairs) is encoded in an
6533 abbreviation table. This routine builds the abbreviation table and assigns
6534 a unique abbreviation id for each abbreviation entry. The children of each
6535 die are visited recursively. */
6538 build_abbrev_table (dw_die_ref die)
6540 unsigned long abbrev_id;
6541 unsigned int n_alloc;
6546 /* Scan the DIE references, and mark as external any that refer to
6547 DIEs from other CUs (i.e. those which are not marked). */
6548 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6549 if (AT_class (a) == dw_val_class_die_ref
6550 && AT_ref (a)->die_mark == 0)
6552 gcc_assert (AT_ref (a)->die_symbol);
6554 set_AT_ref_external (a, 1);
6557 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6559 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6560 dw_attr_ref die_a, abbrev_a;
6564 if (abbrev->die_tag != die->die_tag)
6566 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6569 if (VEC_length (dw_attr_node, abbrev->die_attr)
6570 != VEC_length (dw_attr_node, die->die_attr))
6573 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6575 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6576 if ((abbrev_a->dw_attr != die_a->dw_attr)
6577 || (value_format (abbrev_a) != value_format (die_a)))
6587 if (abbrev_id >= abbrev_die_table_in_use)
6589 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6591 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6592 abbrev_die_table = ggc_realloc (abbrev_die_table,
6593 sizeof (dw_die_ref) * n_alloc);
6595 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6596 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6597 abbrev_die_table_allocated = n_alloc;
6600 ++abbrev_die_table_in_use;
6601 abbrev_die_table[abbrev_id] = die;
6604 die->die_abbrev = abbrev_id;
6605 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6608 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6611 constant_size (long unsigned int value)
6618 log = floor_log2 (value);
6621 log = 1 << (floor_log2 (log) + 1);
6626 /* Return the size of a DIE as it is represented in the
6627 .debug_info section. */
6629 static unsigned long
6630 size_of_die (dw_die_ref die)
6632 unsigned long size = 0;
6636 size += size_of_uleb128 (die->die_abbrev);
6637 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6639 switch (AT_class (a))
6641 case dw_val_class_addr:
6642 size += DWARF2_ADDR_SIZE;
6644 case dw_val_class_offset:
6645 size += DWARF_OFFSET_SIZE;
6647 case dw_val_class_loc:
6649 unsigned long lsize = size_of_locs (AT_loc (a));
6652 size += constant_size (lsize);
6656 case dw_val_class_loc_list:
6657 size += DWARF_OFFSET_SIZE;
6659 case dw_val_class_range_list:
6660 size += DWARF_OFFSET_SIZE;
6662 case dw_val_class_const:
6663 size += size_of_sleb128 (AT_int (a));
6665 case dw_val_class_unsigned_const:
6666 size += constant_size (AT_unsigned (a));
6668 case dw_val_class_long_long:
6669 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6671 case dw_val_class_vec:
6672 size += 1 + (a->dw_attr_val.v.val_vec.length
6673 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6675 case dw_val_class_flag:
6678 case dw_val_class_die_ref:
6679 if (AT_ref_external (a))
6680 size += DWARF2_ADDR_SIZE;
6682 size += DWARF_OFFSET_SIZE;
6684 case dw_val_class_fde_ref:
6685 size += DWARF_OFFSET_SIZE;
6687 case dw_val_class_lbl_id:
6688 size += DWARF2_ADDR_SIZE;
6690 case dw_val_class_lineptr:
6691 case dw_val_class_macptr:
6692 size += DWARF_OFFSET_SIZE;
6694 case dw_val_class_str:
6695 if (AT_string_form (a) == DW_FORM_strp)
6696 size += DWARF_OFFSET_SIZE;
6698 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6700 case dw_val_class_file:
6701 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6711 /* Size the debugging information associated with a given DIE. Visits the
6712 DIE's children recursively. Updates the global variable next_die_offset, on
6713 each time through. Uses the current value of next_die_offset to update the
6714 die_offset field in each DIE. */
6717 calc_die_sizes (dw_die_ref die)
6721 die->die_offset = next_die_offset;
6722 next_die_offset += size_of_die (die);
6724 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6726 if (die->die_child != NULL)
6727 /* Count the null byte used to terminate sibling lists. */
6728 next_die_offset += 1;
6731 /* Set the marks for a die and its children. We do this so
6732 that we know whether or not a reference needs to use FORM_ref_addr; only
6733 DIEs in the same CU will be marked. We used to clear out the offset
6734 and use that as the flag, but ran into ordering problems. */
6737 mark_dies (dw_die_ref die)
6741 gcc_assert (!die->die_mark);
6744 FOR_EACH_CHILD (die, c, mark_dies (c));
6747 /* Clear the marks for a die and its children. */
6750 unmark_dies (dw_die_ref die)
6754 gcc_assert (die->die_mark);
6757 FOR_EACH_CHILD (die, c, unmark_dies (c));
6760 /* Clear the marks for a die, its children and referred dies. */
6763 unmark_all_dies (dw_die_ref die)
6773 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6775 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6776 if (AT_class (a) == dw_val_class_die_ref)
6777 unmark_all_dies (AT_ref (a));
6780 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6781 generated for the compilation unit. */
6783 static unsigned long
6784 size_of_pubnames (VEC (pubname_entry, gc) * names)
6790 size = DWARF_PUBNAMES_HEADER_SIZE;
6791 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6792 if (names != pubtype_table
6793 || p->die->die_offset != 0
6794 || !flag_eliminate_unused_debug_types)
6795 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6797 size += DWARF_OFFSET_SIZE;
6801 /* Return the size of the information in the .debug_aranges section. */
6803 static unsigned long
6804 size_of_aranges (void)
6808 size = DWARF_ARANGES_HEADER_SIZE;
6810 /* Count the address/length pair for this compilation unit. */
6811 size += 2 * DWARF2_ADDR_SIZE;
6812 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6814 /* Count the two zero words used to terminated the address range table. */
6815 size += 2 * DWARF2_ADDR_SIZE;
6819 /* Select the encoding of an attribute value. */
6821 static enum dwarf_form
6822 value_format (dw_attr_ref a)
6824 switch (a->dw_attr_val.val_class)
6826 case dw_val_class_addr:
6827 return DW_FORM_addr;
6828 case dw_val_class_range_list:
6829 case dw_val_class_offset:
6830 case dw_val_class_loc_list:
6831 switch (DWARF_OFFSET_SIZE)
6834 return DW_FORM_data4;
6836 return DW_FORM_data8;
6840 case dw_val_class_loc:
6841 switch (constant_size (size_of_locs (AT_loc (a))))
6844 return DW_FORM_block1;
6846 return DW_FORM_block2;
6850 case dw_val_class_const:
6851 return DW_FORM_sdata;
6852 case dw_val_class_unsigned_const:
6853 switch (constant_size (AT_unsigned (a)))
6856 return DW_FORM_data1;
6858 return DW_FORM_data2;
6860 return DW_FORM_data4;
6862 return DW_FORM_data8;
6866 case dw_val_class_long_long:
6867 return DW_FORM_block1;
6868 case dw_val_class_vec:
6869 return DW_FORM_block1;
6870 case dw_val_class_flag:
6871 return DW_FORM_flag;
6872 case dw_val_class_die_ref:
6873 if (AT_ref_external (a))
6874 return DW_FORM_ref_addr;
6877 case dw_val_class_fde_ref:
6878 return DW_FORM_data;
6879 case dw_val_class_lbl_id:
6880 return DW_FORM_addr;
6881 case dw_val_class_lineptr:
6882 case dw_val_class_macptr:
6883 return DW_FORM_data;
6884 case dw_val_class_str:
6885 return AT_string_form (a);
6886 case dw_val_class_file:
6887 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
6890 return DW_FORM_data1;
6892 return DW_FORM_data2;
6894 return DW_FORM_data4;
6904 /* Output the encoding of an attribute value. */
6907 output_value_format (dw_attr_ref a)
6909 enum dwarf_form form = value_format (a);
6911 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6914 /* Output the .debug_abbrev section which defines the DIE abbreviation
6918 output_abbrev_section (void)
6920 unsigned long abbrev_id;
6922 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6924 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6928 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6929 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6930 dwarf_tag_name (abbrev->die_tag));
6932 if (abbrev->die_child != NULL)
6933 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6935 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6937 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
6940 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6941 dwarf_attr_name (a_attr->dw_attr));
6942 output_value_format (a_attr);
6945 dw2_asm_output_data (1, 0, NULL);
6946 dw2_asm_output_data (1, 0, NULL);
6949 /* Terminate the table. */
6950 dw2_asm_output_data (1, 0, NULL);
6953 /* Output a symbol we can use to refer to this DIE from another CU. */
6956 output_die_symbol (dw_die_ref die)
6958 char *sym = die->die_symbol;
6963 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6964 /* We make these global, not weak; if the target doesn't support
6965 .linkonce, it doesn't support combining the sections, so debugging
6967 targetm.asm_out.globalize_label (asm_out_file, sym);
6969 ASM_OUTPUT_LABEL (asm_out_file, sym);
6972 /* Return a new location list, given the begin and end range, and the
6973 expression. gensym tells us whether to generate a new internal symbol for
6974 this location list node, which is done for the head of the list only. */
6976 static inline dw_loc_list_ref
6977 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6978 const char *section, unsigned int gensym)
6980 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6982 retlist->begin = begin;
6984 retlist->expr = expr;
6985 retlist->section = section;
6987 retlist->ll_symbol = gen_internal_sym ("LLST");
6992 /* Add a location description expression to a location list. */
6995 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6996 const char *begin, const char *end,
6997 const char *section)
7001 /* Find the end of the chain. */
7002 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7005 /* Add a new location list node to the list. */
7006 *d = new_loc_list (descr, begin, end, section, 0);
7010 dwarf2out_switch_text_section (void)
7016 fde = &fde_table[fde_table_in_use - 1];
7017 fde->dw_fde_switched_sections = true;
7018 fde->dw_fde_hot_section_label = cfun->hot_section_label;
7019 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
7020 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
7021 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
7022 have_multiple_function_sections = true;
7024 /* Reset the current label on switching text sections, so that we
7025 don't attempt to advance_loc4 between labels in different sections. */
7026 fde->dw_fde_current_label = NULL;
7029 /* Output the location list given to us. */
7032 output_loc_list (dw_loc_list_ref list_head)
7034 dw_loc_list_ref curr = list_head;
7036 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7038 /* Walk the location list, and output each range + expression. */
7039 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7042 if (!have_multiple_function_sections)
7044 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7045 "Location list begin address (%s)",
7046 list_head->ll_symbol);
7047 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7048 "Location list end address (%s)",
7049 list_head->ll_symbol);
7053 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7054 "Location list begin address (%s)",
7055 list_head->ll_symbol);
7056 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7057 "Location list end address (%s)",
7058 list_head->ll_symbol);
7060 size = size_of_locs (curr->expr);
7062 /* Output the block length for this list of location operations. */
7063 gcc_assert (size <= 0xffff);
7064 dw2_asm_output_data (2, size, "%s", "Location expression size");
7066 output_loc_sequence (curr->expr);
7069 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7070 "Location list terminator begin (%s)",
7071 list_head->ll_symbol);
7072 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7073 "Location list terminator end (%s)",
7074 list_head->ll_symbol);
7077 /* Output the DIE and its attributes. Called recursively to generate
7078 the definitions of each child DIE. */
7081 output_die (dw_die_ref die)
7088 /* If someone in another CU might refer to us, set up a symbol for
7089 them to point to. */
7090 if (die->die_symbol)
7091 output_die_symbol (die);
7093 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7094 (unsigned long)die->die_offset,
7095 dwarf_tag_name (die->die_tag));
7097 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7099 const char *name = dwarf_attr_name (a->dw_attr);
7101 switch (AT_class (a))
7103 case dw_val_class_addr:
7104 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7107 case dw_val_class_offset:
7108 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7112 case dw_val_class_range_list:
7114 char *p = strchr (ranges_section_label, '\0');
7116 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7117 a->dw_attr_val.v.val_offset);
7118 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7119 debug_ranges_section, "%s", name);
7124 case dw_val_class_loc:
7125 size = size_of_locs (AT_loc (a));
7127 /* Output the block length for this list of location operations. */
7128 dw2_asm_output_data (constant_size (size), size, "%s", name);
7130 output_loc_sequence (AT_loc (a));
7133 case dw_val_class_const:
7134 /* ??? It would be slightly more efficient to use a scheme like is
7135 used for unsigned constants below, but gdb 4.x does not sign
7136 extend. Gdb 5.x does sign extend. */
7137 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7140 case dw_val_class_unsigned_const:
7141 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7142 AT_unsigned (a), "%s", name);
7145 case dw_val_class_long_long:
7147 unsigned HOST_WIDE_INT first, second;
7149 dw2_asm_output_data (1,
7150 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7153 if (WORDS_BIG_ENDIAN)
7155 first = a->dw_attr_val.v.val_long_long.hi;
7156 second = a->dw_attr_val.v.val_long_long.low;
7160 first = a->dw_attr_val.v.val_long_long.low;
7161 second = a->dw_attr_val.v.val_long_long.hi;
7164 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7165 first, "long long constant");
7166 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7171 case dw_val_class_vec:
7173 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7174 unsigned int len = a->dw_attr_val.v.val_vec.length;
7178 dw2_asm_output_data (1, len * elt_size, "%s", name);
7179 if (elt_size > sizeof (HOST_WIDE_INT))
7184 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7187 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7188 "fp or vector constant word %u", i);
7192 case dw_val_class_flag:
7193 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7196 case dw_val_class_loc_list:
7198 char *sym = AT_loc_list (a)->ll_symbol;
7201 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7206 case dw_val_class_die_ref:
7207 if (AT_ref_external (a))
7209 char *sym = AT_ref (a)->die_symbol;
7212 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7217 gcc_assert (AT_ref (a)->die_offset);
7218 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7223 case dw_val_class_fde_ref:
7227 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7228 a->dw_attr_val.v.val_fde_index * 2);
7229 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7234 case dw_val_class_lbl_id:
7235 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7238 case dw_val_class_lineptr:
7239 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7240 debug_line_section, "%s", name);
7243 case dw_val_class_macptr:
7244 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7245 debug_macinfo_section, "%s", name);
7248 case dw_val_class_str:
7249 if (AT_string_form (a) == DW_FORM_strp)
7250 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7251 a->dw_attr_val.v.val_str->label,
7253 "%s: \"%s\"", name, AT_string (a));
7255 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7258 case dw_val_class_file:
7260 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7262 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7263 a->dw_attr_val.v.val_file->filename);
7272 FOR_EACH_CHILD (die, c, output_die (c));
7274 /* Add null byte to terminate sibling list. */
7275 if (die->die_child != NULL)
7276 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7277 (unsigned long) die->die_offset);
7280 /* Output the compilation unit that appears at the beginning of the
7281 .debug_info section, and precedes the DIE descriptions. */
7284 output_compilation_unit_header (void)
7286 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7287 dw2_asm_output_data (4, 0xffffffff,
7288 "Initial length escape value indicating 64-bit DWARF extension");
7289 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7290 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7291 "Length of Compilation Unit Info");
7292 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7293 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7294 debug_abbrev_section,
7295 "Offset Into Abbrev. Section");
7296 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7299 /* Output the compilation unit DIE and its children. */
7302 output_comp_unit (dw_die_ref die, int output_if_empty)
7304 const char *secname;
7307 /* Unless we are outputting main CU, we may throw away empty ones. */
7308 if (!output_if_empty && die->die_child == NULL)
7311 /* Even if there are no children of this DIE, we must output the information
7312 about the compilation unit. Otherwise, on an empty translation unit, we
7313 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7314 will then complain when examining the file. First mark all the DIEs in
7315 this CU so we know which get local refs. */
7318 build_abbrev_table (die);
7320 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7321 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7322 calc_die_sizes (die);
7324 oldsym = die->die_symbol;
7327 tmp = alloca (strlen (oldsym) + 24);
7329 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7331 die->die_symbol = NULL;
7332 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7335 switch_to_section (debug_info_section);
7337 /* Output debugging information. */
7338 output_compilation_unit_header ();
7341 /* Leave the marks on the main CU, so we can check them in
7346 die->die_symbol = oldsym;
7350 /* Return the DWARF2/3 pubname associated with a decl. */
7353 dwarf2_name (tree decl, int scope)
7355 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7358 /* Add a new entry to .debug_pubnames if appropriate. */
7361 add_pubname (tree decl, dw_die_ref die)
7365 if (! TREE_PUBLIC (decl))
7369 e.name = xstrdup (dwarf2_name (decl, 1));
7370 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7373 /* Add a new entry to .debug_pubtypes if appropriate. */
7376 add_pubtype (tree decl, dw_die_ref die)
7381 if ((TREE_PUBLIC (decl)
7382 || die->die_parent == comp_unit_die)
7383 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7388 if (TYPE_NAME (decl))
7390 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7391 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7392 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7393 && DECL_NAME (TYPE_NAME (decl)))
7394 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7396 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7400 e.name = xstrdup (dwarf2_name (decl, 1));
7402 /* If we don't have a name for the type, there's no point in adding
7404 if (e.name && e.name[0] != '\0')
7405 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7409 /* Output the public names table used to speed up access to externally
7410 visible names; or the public types table used to find type definitions. */
7413 output_pubnames (VEC (pubname_entry, gc) * names)
7416 unsigned long pubnames_length = size_of_pubnames (names);
7419 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7420 dw2_asm_output_data (4, 0xffffffff,
7421 "Initial length escape value indicating 64-bit DWARF extension");
7422 if (names == pubname_table)
7423 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7424 "Length of Public Names Info");
7426 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7427 "Length of Public Type Names Info");
7428 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7429 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7431 "Offset of Compilation Unit Info");
7432 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7433 "Compilation Unit Length");
7435 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7437 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7438 if (names == pubname_table)
7439 gcc_assert (pub->die->die_mark);
7441 if (names != pubtype_table
7442 || pub->die->die_offset != 0
7443 || !flag_eliminate_unused_debug_types)
7445 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7448 dw2_asm_output_nstring (pub->name, -1, "external name");
7452 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7455 /* Add a new entry to .debug_aranges if appropriate. */
7458 add_arange (tree decl, dw_die_ref die)
7460 if (! DECL_SECTION_NAME (decl))
7463 if (arange_table_in_use == arange_table_allocated)
7465 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7466 arange_table = ggc_realloc (arange_table,
7467 (arange_table_allocated
7468 * sizeof (dw_die_ref)));
7469 memset (arange_table + arange_table_in_use, 0,
7470 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7473 arange_table[arange_table_in_use++] = die;
7476 /* Output the information that goes into the .debug_aranges table.
7477 Namely, define the beginning and ending address range of the
7478 text section generated for this compilation unit. */
7481 output_aranges (void)
7484 unsigned long aranges_length = size_of_aranges ();
7486 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7487 dw2_asm_output_data (4, 0xffffffff,
7488 "Initial length escape value indicating 64-bit DWARF extension");
7489 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7490 "Length of Address Ranges Info");
7491 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7492 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7494 "Offset of Compilation Unit Info");
7495 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7496 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7498 /* We need to align to twice the pointer size here. */
7499 if (DWARF_ARANGES_PAD_SIZE)
7501 /* Pad using a 2 byte words so that padding is correct for any
7503 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7504 2 * DWARF2_ADDR_SIZE);
7505 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7506 dw2_asm_output_data (2, 0, NULL);
7509 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7510 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7511 text_section_label, "Length");
7512 if (flag_reorder_blocks_and_partition)
7514 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7516 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7517 cold_text_section_label, "Length");
7520 for (i = 0; i < arange_table_in_use; i++)
7522 dw_die_ref die = arange_table[i];
7524 /* We shouldn't see aranges for DIEs outside of the main CU. */
7525 gcc_assert (die->die_mark);
7527 if (die->die_tag == DW_TAG_subprogram)
7529 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7531 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7532 get_AT_low_pc (die), "Length");
7536 /* A static variable; extract the symbol from DW_AT_location.
7537 Note that this code isn't currently hit, as we only emit
7538 aranges for functions (jason 9/23/99). */
7539 dw_attr_ref a = get_AT (die, DW_AT_location);
7540 dw_loc_descr_ref loc;
7542 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7545 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7547 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7548 loc->dw_loc_oprnd1.v.val_addr, "Address");
7549 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7550 get_AT_unsigned (die, DW_AT_byte_size),
7555 /* Output the terminator words. */
7556 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7557 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7560 /* Add a new entry to .debug_ranges. Return the offset at which it
7564 add_ranges (tree block)
7566 unsigned int in_use = ranges_table_in_use;
7568 if (in_use == ranges_table_allocated)
7570 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7572 = ggc_realloc (ranges_table, (ranges_table_allocated
7573 * sizeof (struct dw_ranges_struct)));
7574 memset (ranges_table + ranges_table_in_use, 0,
7575 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7578 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7579 ranges_table_in_use = in_use + 1;
7581 return in_use * 2 * DWARF2_ADDR_SIZE;
7585 output_ranges (void)
7588 static const char *const start_fmt = "Offset 0x%x";
7589 const char *fmt = start_fmt;
7591 for (i = 0; i < ranges_table_in_use; i++)
7593 int block_num = ranges_table[i].block_num;
7597 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7598 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7600 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7601 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7603 /* If all code is in the text section, then the compilation
7604 unit base address defaults to DW_AT_low_pc, which is the
7605 base of the text section. */
7606 if (!have_multiple_function_sections)
7608 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7610 fmt, i * 2 * DWARF2_ADDR_SIZE);
7611 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7612 text_section_label, NULL);
7615 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7616 compilation unit base address to zero, which allows us to
7617 use absolute addresses, and not worry about whether the
7618 target supports cross-section arithmetic. */
7621 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7622 fmt, i * 2 * DWARF2_ADDR_SIZE);
7623 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7630 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7631 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7637 /* Data structure containing information about input files. */
7640 const char *path; /* Complete file name. */
7641 const char *fname; /* File name part. */
7642 int length; /* Length of entire string. */
7643 struct dwarf_file_data * file_idx; /* Index in input file table. */
7644 int dir_idx; /* Index in directory table. */
7647 /* Data structure containing information about directories with source
7651 const char *path; /* Path including directory name. */
7652 int length; /* Path length. */
7653 int prefix; /* Index of directory entry which is a prefix. */
7654 int count; /* Number of files in this directory. */
7655 int dir_idx; /* Index of directory used as base. */
7658 /* Callback function for file_info comparison. We sort by looking at
7659 the directories in the path. */
7662 file_info_cmp (const void *p1, const void *p2)
7664 const struct file_info *s1 = p1;
7665 const struct file_info *s2 = p2;
7669 /* Take care of file names without directories. We need to make sure that
7670 we return consistent values to qsort since some will get confused if
7671 we return the same value when identical operands are passed in opposite
7672 orders. So if neither has a directory, return 0 and otherwise return
7673 1 or -1 depending on which one has the directory. */
7674 if ((s1->path == s1->fname || s2->path == s2->fname))
7675 return (s2->path == s2->fname) - (s1->path == s1->fname);
7677 cp1 = (unsigned char *) s1->path;
7678 cp2 = (unsigned char *) s2->path;
7684 /* Reached the end of the first path? If so, handle like above. */
7685 if ((cp1 == (unsigned char *) s1->fname)
7686 || (cp2 == (unsigned char *) s2->fname))
7687 return ((cp2 == (unsigned char *) s2->fname)
7688 - (cp1 == (unsigned char *) s1->fname));
7690 /* Character of current path component the same? */
7691 else if (*cp1 != *cp2)
7696 struct file_name_acquire_data
7698 struct file_info *files;
7703 /* Traversal function for the hash table. */
7706 file_name_acquire (void ** slot, void *data)
7708 struct file_name_acquire_data *fnad = data;
7709 struct dwarf_file_data *d = *slot;
7710 struct file_info *fi;
7713 gcc_assert (fnad->max_files >= d->emitted_number);
7715 if (! d->emitted_number)
7718 gcc_assert (fnad->max_files != fnad->used_files);
7720 fi = fnad->files + fnad->used_files++;
7722 /* Skip all leading "./". */
7724 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7727 /* Create a new array entry. */
7729 fi->length = strlen (f);
7732 /* Search for the file name part. */
7733 f = strrchr (f, DIR_SEPARATOR);
7734 #if defined (DIR_SEPARATOR_2)
7736 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7740 if (f == NULL || f < g)
7746 fi->fname = f == NULL ? fi->path : f + 1;
7750 /* Output the directory table and the file name table. We try to minimize
7751 the total amount of memory needed. A heuristic is used to avoid large
7752 slowdowns with many input files. */
7755 output_file_names (void)
7757 struct file_name_acquire_data fnad;
7759 struct file_info *files;
7760 struct dir_info *dirs;
7769 if (!last_emitted_file)
7771 dw2_asm_output_data (1, 0, "End directory table");
7772 dw2_asm_output_data (1, 0, "End file name table");
7776 numfiles = last_emitted_file->emitted_number;
7778 /* Allocate the various arrays we need. */
7779 files = alloca (numfiles * sizeof (struct file_info));
7780 dirs = alloca (numfiles * sizeof (struct dir_info));
7783 fnad.used_files = 0;
7784 fnad.max_files = numfiles;
7785 htab_traverse (file_table, file_name_acquire, &fnad);
7786 gcc_assert (fnad.used_files == fnad.max_files);
7788 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
7790 /* Find all the different directories used. */
7791 dirs[0].path = files[0].path;
7792 dirs[0].length = files[0].fname - files[0].path;
7793 dirs[0].prefix = -1;
7795 dirs[0].dir_idx = 0;
7796 files[0].dir_idx = 0;
7799 for (i = 1; i < numfiles; i++)
7800 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7801 && memcmp (dirs[ndirs - 1].path, files[i].path,
7802 dirs[ndirs - 1].length) == 0)
7804 /* Same directory as last entry. */
7805 files[i].dir_idx = ndirs - 1;
7806 ++dirs[ndirs - 1].count;
7812 /* This is a new directory. */
7813 dirs[ndirs].path = files[i].path;
7814 dirs[ndirs].length = files[i].fname - files[i].path;
7815 dirs[ndirs].count = 1;
7816 dirs[ndirs].dir_idx = ndirs;
7817 files[i].dir_idx = ndirs;
7819 /* Search for a prefix. */
7820 dirs[ndirs].prefix = -1;
7821 for (j = 0; j < ndirs; j++)
7822 if (dirs[j].length < dirs[ndirs].length
7823 && dirs[j].length > 1
7824 && (dirs[ndirs].prefix == -1
7825 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7826 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7827 dirs[ndirs].prefix = j;
7832 /* Now to the actual work. We have to find a subset of the directories which
7833 allow expressing the file name using references to the directory table
7834 with the least amount of characters. We do not do an exhaustive search
7835 where we would have to check out every combination of every single
7836 possible prefix. Instead we use a heuristic which provides nearly optimal
7837 results in most cases and never is much off. */
7838 saved = alloca (ndirs * sizeof (int));
7839 savehere = alloca (ndirs * sizeof (int));
7841 memset (saved, '\0', ndirs * sizeof (saved[0]));
7842 for (i = 0; i < ndirs; i++)
7847 /* We can always save some space for the current directory. But this
7848 does not mean it will be enough to justify adding the directory. */
7849 savehere[i] = dirs[i].length;
7850 total = (savehere[i] - saved[i]) * dirs[i].count;
7852 for (j = i + 1; j < ndirs; j++)
7855 if (saved[j] < dirs[i].length)
7857 /* Determine whether the dirs[i] path is a prefix of the
7862 while (k != -1 && k != (int) i)
7867 /* Yes it is. We can possibly save some memory by
7868 writing the filenames in dirs[j] relative to
7870 savehere[j] = dirs[i].length;
7871 total += (savehere[j] - saved[j]) * dirs[j].count;
7876 /* Check whether we can save enough to justify adding the dirs[i]
7878 if (total > dirs[i].length + 1)
7880 /* It's worthwhile adding. */
7881 for (j = i; j < ndirs; j++)
7882 if (savehere[j] > 0)
7884 /* Remember how much we saved for this directory so far. */
7885 saved[j] = savehere[j];
7887 /* Remember the prefix directory. */
7888 dirs[j].dir_idx = i;
7893 /* Emit the directory name table. */
7895 idx_offset = dirs[0].length > 0 ? 1 : 0;
7896 for (i = 1 - idx_offset; i < ndirs; i++)
7897 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7898 "Directory Entry: 0x%x", i + idx_offset);
7900 dw2_asm_output_data (1, 0, "End directory table");
7902 /* We have to emit them in the order of emitted_number since that's
7903 used in the debug info generation. To do this efficiently we
7904 generate a back-mapping of the indices first. */
7905 backmap = alloca (numfiles * sizeof (int));
7906 for (i = 0; i < numfiles; i++)
7907 backmap[files[i].file_idx->emitted_number - 1] = i;
7909 /* Now write all the file names. */
7910 for (i = 0; i < numfiles; i++)
7912 int file_idx = backmap[i];
7913 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7915 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7916 "File Entry: 0x%x", (unsigned) i + 1);
7918 /* Include directory index. */
7919 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
7921 /* Modification time. */
7922 dw2_asm_output_data_uleb128 (0, NULL);
7924 /* File length in bytes. */
7925 dw2_asm_output_data_uleb128 (0, NULL);
7928 dw2_asm_output_data (1, 0, "End file name table");
7932 /* Output the source line number correspondence information. This
7933 information goes into the .debug_line section. */
7936 output_line_info (void)
7938 char l1[20], l2[20], p1[20], p2[20];
7939 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7940 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7943 unsigned long lt_index;
7944 unsigned long current_line;
7947 unsigned long current_file;
7948 unsigned long function;
7950 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7951 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7952 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7953 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7955 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7956 dw2_asm_output_data (4, 0xffffffff,
7957 "Initial length escape value indicating 64-bit DWARF extension");
7958 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7959 "Length of Source Line Info");
7960 ASM_OUTPUT_LABEL (asm_out_file, l1);
7962 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7963 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7964 ASM_OUTPUT_LABEL (asm_out_file, p1);
7966 /* Define the architecture-dependent minimum instruction length (in
7967 bytes). In this implementation of DWARF, this field is used for
7968 information purposes only. Since GCC generates assembly language,
7969 we have no a priori knowledge of how many instruction bytes are
7970 generated for each source line, and therefore can use only the
7971 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7972 commands. Accordingly, we fix this as `1', which is "correct
7973 enough" for all architectures, and don't let the target override. */
7974 dw2_asm_output_data (1, 1,
7975 "Minimum Instruction Length");
7977 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7978 "Default is_stmt_start flag");
7979 dw2_asm_output_data (1, DWARF_LINE_BASE,
7980 "Line Base Value (Special Opcodes)");
7981 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7982 "Line Range Value (Special Opcodes)");
7983 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7984 "Special Opcode Base");
7986 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7990 case DW_LNS_advance_pc:
7991 case DW_LNS_advance_line:
7992 case DW_LNS_set_file:
7993 case DW_LNS_set_column:
7994 case DW_LNS_fixed_advance_pc:
8002 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8006 /* Write out the information about the files we use. */
8007 output_file_names ();
8008 ASM_OUTPUT_LABEL (asm_out_file, p2);
8010 /* We used to set the address register to the first location in the text
8011 section here, but that didn't accomplish anything since we already
8012 have a line note for the opening brace of the first function. */
8014 /* Generate the line number to PC correspondence table, encoded as
8015 a series of state machine operations. */
8019 if (cfun && in_cold_section_p)
8020 strcpy (prev_line_label, cfun->cold_section_label);
8022 strcpy (prev_line_label, text_section_label);
8023 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8025 dw_line_info_ref line_info = &line_info_table[lt_index];
8028 /* Disable this optimization for now; GDB wants to see two line notes
8029 at the beginning of a function so it can find the end of the
8032 /* Don't emit anything for redundant notes. Just updating the
8033 address doesn't accomplish anything, because we already assume
8034 that anything after the last address is this line. */
8035 if (line_info->dw_line_num == current_line
8036 && line_info->dw_file_num == current_file)
8040 /* Emit debug info for the address of the current line.
8042 Unfortunately, we have little choice here currently, and must always
8043 use the most general form. GCC does not know the address delta
8044 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8045 attributes which will give an upper bound on the address range. We
8046 could perhaps use length attributes to determine when it is safe to
8047 use DW_LNS_fixed_advance_pc. */
8049 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8052 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8053 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8054 "DW_LNS_fixed_advance_pc");
8055 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8059 /* This can handle any delta. This takes
8060 4+DWARF2_ADDR_SIZE bytes. */
8061 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8062 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8063 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8064 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8067 strcpy (prev_line_label, line_label);
8069 /* Emit debug info for the source file of the current line, if
8070 different from the previous line. */
8071 if (line_info->dw_file_num != current_file)
8073 current_file = line_info->dw_file_num;
8074 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8075 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8078 /* Emit debug info for the current line number, choosing the encoding
8079 that uses the least amount of space. */
8080 if (line_info->dw_line_num != current_line)
8082 line_offset = line_info->dw_line_num - current_line;
8083 line_delta = line_offset - DWARF_LINE_BASE;
8084 current_line = line_info->dw_line_num;
8085 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8086 /* This can handle deltas from -10 to 234, using the current
8087 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8089 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8090 "line %lu", current_line);
8093 /* This can handle any delta. This takes at least 4 bytes,
8094 depending on the value being encoded. */
8095 dw2_asm_output_data (1, DW_LNS_advance_line,
8096 "advance to line %lu", current_line);
8097 dw2_asm_output_data_sleb128 (line_offset, NULL);
8098 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8102 /* We still need to start a new row, so output a copy insn. */
8103 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8106 /* Emit debug info for the address of the end of the function. */
8109 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8110 "DW_LNS_fixed_advance_pc");
8111 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8115 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8116 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8117 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8118 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8121 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8122 dw2_asm_output_data_uleb128 (1, NULL);
8123 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8128 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8130 dw_separate_line_info_ref line_info
8131 = &separate_line_info_table[lt_index];
8134 /* Don't emit anything for redundant notes. */
8135 if (line_info->dw_line_num == current_line
8136 && line_info->dw_file_num == current_file
8137 && line_info->function == function)
8141 /* Emit debug info for the address of the current line. If this is
8142 a new function, or the first line of a function, then we need
8143 to handle it differently. */
8144 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8146 if (function != line_info->function)
8148 function = line_info->function;
8150 /* Set the address register to the first line in the function. */
8151 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8152 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8153 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8154 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8158 /* ??? See the DW_LNS_advance_pc comment above. */
8161 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8162 "DW_LNS_fixed_advance_pc");
8163 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8167 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8168 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8169 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8170 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8174 strcpy (prev_line_label, line_label);
8176 /* Emit debug info for the source file of the current line, if
8177 different from the previous line. */
8178 if (line_info->dw_file_num != current_file)
8180 current_file = line_info->dw_file_num;
8181 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8182 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8185 /* Emit debug info for the current line number, choosing the encoding
8186 that uses the least amount of space. */
8187 if (line_info->dw_line_num != current_line)
8189 line_offset = line_info->dw_line_num - current_line;
8190 line_delta = line_offset - DWARF_LINE_BASE;
8191 current_line = line_info->dw_line_num;
8192 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8193 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8194 "line %lu", current_line);
8197 dw2_asm_output_data (1, DW_LNS_advance_line,
8198 "advance to line %lu", current_line);
8199 dw2_asm_output_data_sleb128 (line_offset, NULL);
8200 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8204 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8212 /* If we're done with a function, end its sequence. */
8213 if (lt_index == separate_line_info_table_in_use
8214 || separate_line_info_table[lt_index].function != function)
8219 /* Emit debug info for the address of the end of the function. */
8220 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8223 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8224 "DW_LNS_fixed_advance_pc");
8225 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8229 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8230 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8231 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8232 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8235 /* Output the marker for the end of this sequence. */
8236 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8237 dw2_asm_output_data_uleb128 (1, NULL);
8238 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8242 /* Output the marker for the end of the line number info. */
8243 ASM_OUTPUT_LABEL (asm_out_file, l2);
8246 /* Given a pointer to a tree node for some base type, return a pointer to
8247 a DIE that describes the given type.
8249 This routine must only be called for GCC type nodes that correspond to
8250 Dwarf base (fundamental) types. */
8253 base_type_die (tree type)
8255 dw_die_ref base_type_result;
8256 enum dwarf_type encoding;
8258 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8261 switch (TREE_CODE (type))
8264 if (TYPE_STRING_FLAG (type))
8266 if (TYPE_UNSIGNED (type))
8267 encoding = DW_ATE_unsigned_char;
8269 encoding = DW_ATE_signed_char;
8271 else if (TYPE_UNSIGNED (type))
8272 encoding = DW_ATE_unsigned;
8274 encoding = DW_ATE_signed;
8278 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8279 encoding = DW_ATE_decimal_float;
8281 encoding = DW_ATE_float;
8284 /* Dwarf2 doesn't know anything about complex ints, so use
8285 a user defined type for it. */
8287 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8288 encoding = DW_ATE_complex_float;
8290 encoding = DW_ATE_lo_user;
8294 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8295 encoding = DW_ATE_boolean;
8299 /* No other TREE_CODEs are Dwarf fundamental types. */
8303 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8305 /* This probably indicates a bug. */
8306 if (! TYPE_NAME (type))
8307 add_name_attribute (base_type_result, "__unknown__");
8309 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8310 int_size_in_bytes (type));
8311 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8313 return base_type_result;
8316 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8317 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8320 is_base_type (tree type)
8322 switch (TREE_CODE (type))
8335 case QUAL_UNION_TYPE:
8340 case REFERENCE_TYPE:
8353 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8354 node, return the size in bits for the type if it is a constant, or else
8355 return the alignment for the type if the type's size is not constant, or
8356 else return BITS_PER_WORD if the type actually turns out to be an
8359 static inline unsigned HOST_WIDE_INT
8360 simple_type_size_in_bits (tree type)
8362 if (TREE_CODE (type) == ERROR_MARK)
8363 return BITS_PER_WORD;
8364 else if (TYPE_SIZE (type) == NULL_TREE)
8366 else if (host_integerp (TYPE_SIZE (type), 1))
8367 return tree_low_cst (TYPE_SIZE (type), 1);
8369 return TYPE_ALIGN (type);
8372 /* Return true if the debug information for the given type should be
8373 emitted as a subrange type. */
8376 is_subrange_type (tree type)
8378 tree subtype = TREE_TYPE (type);
8380 /* Subrange types are identified by the fact that they are integer
8381 types, and that they have a subtype which is either an integer type
8382 or an enumeral type. */
8384 if (TREE_CODE (type) != INTEGER_TYPE
8385 || subtype == NULL_TREE)
8388 if (TREE_CODE (subtype) != INTEGER_TYPE
8389 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8392 if (TREE_CODE (type) == TREE_CODE (subtype)
8393 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8394 && TYPE_MIN_VALUE (type) != NULL
8395 && TYPE_MIN_VALUE (subtype) != NULL
8396 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8397 && TYPE_MAX_VALUE (type) != NULL
8398 && TYPE_MAX_VALUE (subtype) != NULL
8399 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8401 /* The type and its subtype have the same representation. If in
8402 addition the two types also have the same name, then the given
8403 type is not a subrange type, but rather a plain base type. */
8404 /* FIXME: brobecker/2004-03-22:
8405 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8406 therefore be sufficient to check the TYPE_SIZE node pointers
8407 rather than checking the actual size. Unfortunately, we have
8408 found some cases, such as in the Ada "integer" type, where
8409 this is not the case. Until this problem is solved, we need to
8410 keep checking the actual size. */
8411 tree type_name = TYPE_NAME (type);
8412 tree subtype_name = TYPE_NAME (subtype);
8414 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8415 type_name = DECL_NAME (type_name);
8417 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8418 subtype_name = DECL_NAME (subtype_name);
8420 if (type_name == subtype_name)
8427 /* Given a pointer to a tree node for a subrange type, return a pointer
8428 to a DIE that describes the given type. */
8431 subrange_type_die (tree type, dw_die_ref context_die)
8433 dw_die_ref subrange_die;
8434 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8436 if (context_die == NULL)
8437 context_die = comp_unit_die;
8439 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8441 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8443 /* The size of the subrange type and its base type do not match,
8444 so we need to generate a size attribute for the subrange type. */
8445 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8448 if (TYPE_MIN_VALUE (type) != NULL)
8449 add_bound_info (subrange_die, DW_AT_lower_bound,
8450 TYPE_MIN_VALUE (type));
8451 if (TYPE_MAX_VALUE (type) != NULL)
8452 add_bound_info (subrange_die, DW_AT_upper_bound,
8453 TYPE_MAX_VALUE (type));
8455 return subrange_die;
8458 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8459 entry that chains various modifiers in front of the given type. */
8462 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8463 dw_die_ref context_die)
8465 enum tree_code code = TREE_CODE (type);
8466 dw_die_ref mod_type_die;
8467 dw_die_ref sub_die = NULL;
8468 tree item_type = NULL;
8469 tree qualified_type;
8472 if (code == ERROR_MARK)
8475 /* See if we already have the appropriately qualified variant of
8478 = get_qualified_type (type,
8479 ((is_const_type ? TYPE_QUAL_CONST : 0)
8480 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8482 /* If we do, then we can just use its DIE, if it exists. */
8485 mod_type_die = lookup_type_die (qualified_type);
8487 return mod_type_die;
8490 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8492 /* Handle C typedef types. */
8493 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8495 tree dtype = TREE_TYPE (name);
8497 if (qualified_type == dtype)
8499 /* For a named type, use the typedef. */
8500 gen_type_die (qualified_type, context_die);
8501 return lookup_type_die (qualified_type);
8503 else if (is_const_type < TYPE_READONLY (dtype)
8504 || is_volatile_type < TYPE_VOLATILE (dtype)
8505 || (is_const_type <= TYPE_READONLY (dtype)
8506 && is_volatile_type <= TYPE_VOLATILE (dtype)
8507 && DECL_ORIGINAL_TYPE (name) != type))
8508 /* cv-unqualified version of named type. Just use the unnamed
8509 type to which it refers. */
8510 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8511 is_const_type, is_volatile_type,
8513 /* Else cv-qualified version of named type; fall through. */
8518 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8519 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8521 else if (is_volatile_type)
8523 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8524 sub_die = modified_type_die (type, 0, 0, context_die);
8526 else if (code == POINTER_TYPE)
8528 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8529 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8530 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8531 item_type = TREE_TYPE (type);
8533 else if (code == REFERENCE_TYPE)
8535 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8536 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8537 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8538 item_type = TREE_TYPE (type);
8540 else if (is_subrange_type (type))
8542 mod_type_die = subrange_type_die (type, context_die);
8543 item_type = TREE_TYPE (type);
8545 else if (is_base_type (type))
8546 mod_type_die = base_type_die (type);
8549 gen_type_die (type, context_die);
8551 /* We have to get the type_main_variant here (and pass that to the
8552 `lookup_type_die' routine) because the ..._TYPE node we have
8553 might simply be a *copy* of some original type node (where the
8554 copy was created to help us keep track of typedef names) and
8555 that copy might have a different TYPE_UID from the original
8557 if (TREE_CODE (type) != VECTOR_TYPE)
8558 return lookup_type_die (type_main_variant (type));
8560 /* Vectors have the debugging information in the type,
8561 not the main variant. */
8562 return lookup_type_die (type);
8565 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8566 don't output a DW_TAG_typedef, since there isn't one in the
8567 user's program; just attach a DW_AT_name to the type. */
8569 && (TREE_CODE (name) != TYPE_DECL || TREE_TYPE (name) == qualified_type))
8571 if (TREE_CODE (name) == TYPE_DECL)
8572 /* Could just call add_name_and_src_coords_attributes here,
8573 but since this is a builtin type it doesn't have any
8574 useful source coordinates anyway. */
8575 name = DECL_NAME (name);
8576 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8580 equate_type_number_to_die (qualified_type, mod_type_die);
8583 /* We must do this after the equate_type_number_to_die call, in case
8584 this is a recursive type. This ensures that the modified_type_die
8585 recursion will terminate even if the type is recursive. Recursive
8586 types are possible in Ada. */
8587 sub_die = modified_type_die (item_type,
8588 TYPE_READONLY (item_type),
8589 TYPE_VOLATILE (item_type),
8592 if (sub_die != NULL)
8593 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8595 return mod_type_die;
8598 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8599 an enumerated type. */
8602 type_is_enum (tree type)
8604 return TREE_CODE (type) == ENUMERAL_TYPE;
8607 /* Return the DBX register number described by a given RTL node. */
8610 dbx_reg_number (rtx rtl)
8612 unsigned regno = REGNO (rtl);
8614 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8616 #ifdef LEAF_REG_REMAP
8617 if (current_function_uses_only_leaf_regs)
8619 int leaf_reg = LEAF_REG_REMAP (regno);
8621 regno = (unsigned) leaf_reg;
8625 return DBX_REGISTER_NUMBER (regno);
8628 /* Optionally add a DW_OP_piece term to a location description expression.
8629 DW_OP_piece is only added if the location description expression already
8630 doesn't end with DW_OP_piece. */
8633 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8635 dw_loc_descr_ref loc;
8637 if (*list_head != NULL)
8639 /* Find the end of the chain. */
8640 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8643 if (loc->dw_loc_opc != DW_OP_piece)
8644 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8648 /* Return a location descriptor that designates a machine register or
8649 zero if there is none. */
8651 static dw_loc_descr_ref
8652 reg_loc_descriptor (rtx rtl)
8656 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8659 regs = targetm.dwarf_register_span (rtl);
8661 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8662 return multiple_reg_loc_descriptor (rtl, regs);
8664 return one_reg_loc_descriptor (dbx_reg_number (rtl));
8667 /* Return a location descriptor that designates a machine register for
8668 a given hard register number. */
8670 static dw_loc_descr_ref
8671 one_reg_loc_descriptor (unsigned int regno)
8674 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8676 return new_loc_descr (DW_OP_regx, regno, 0);
8679 /* Given an RTL of a register, return a location descriptor that
8680 designates a value that spans more than one register. */
8682 static dw_loc_descr_ref
8683 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8687 dw_loc_descr_ref loc_result = NULL;
8690 #ifdef LEAF_REG_REMAP
8691 if (current_function_uses_only_leaf_regs)
8693 int leaf_reg = LEAF_REG_REMAP (reg);
8695 reg = (unsigned) leaf_reg;
8698 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8699 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8701 /* Simple, contiguous registers. */
8702 if (regs == NULL_RTX)
8704 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8711 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg));
8712 add_loc_descr (&loc_result, t);
8713 add_loc_descr_op_piece (&loc_result, size);
8719 /* Now onto stupid register sets in non contiguous locations. */
8721 gcc_assert (GET_CODE (regs) == PARALLEL);
8723 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8726 for (i = 0; i < XVECLEN (regs, 0); ++i)
8730 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8731 add_loc_descr (&loc_result, t);
8732 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8733 add_loc_descr_op_piece (&loc_result, size);
8738 /* Return a location descriptor that designates a constant. */
8740 static dw_loc_descr_ref
8741 int_loc_descriptor (HOST_WIDE_INT i)
8743 enum dwarf_location_atom op;
8745 /* Pick the smallest representation of a constant, rather than just
8746 defaulting to the LEB encoding. */
8750 op = DW_OP_lit0 + i;
8753 else if (i <= 0xffff)
8755 else if (HOST_BITS_PER_WIDE_INT == 32
8765 else if (i >= -0x8000)
8767 else if (HOST_BITS_PER_WIDE_INT == 32
8768 || i >= -0x80000000)
8774 return new_loc_descr (op, i, 0);
8777 /* Return a location descriptor that designates a base+offset location. */
8779 static dw_loc_descr_ref
8780 based_loc_descr (rtx reg, HOST_WIDE_INT offset)
8784 /* We only use "frame base" when we're sure we're talking about the
8785 post-prologue local stack frame. We do this by *not* running
8786 register elimination until this point, and recognizing the special
8787 argument pointer and soft frame pointer rtx's. */
8788 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8790 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8794 if (GET_CODE (elim) == PLUS)
8796 offset += INTVAL (XEXP (elim, 1));
8797 elim = XEXP (elim, 0);
8799 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8800 : stack_pointer_rtx));
8801 offset += frame_pointer_fb_offset;
8803 return new_loc_descr (DW_OP_fbreg, offset, 0);
8807 regno = dbx_reg_number (reg);
8809 return new_loc_descr (DW_OP_breg0 + regno, offset, 0);
8811 return new_loc_descr (DW_OP_bregx, regno, offset);
8814 /* Return true if this RTL expression describes a base+offset calculation. */
8817 is_based_loc (rtx rtl)
8819 return (GET_CODE (rtl) == PLUS
8820 && ((REG_P (XEXP (rtl, 0))
8821 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8822 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8825 /* Return a descriptor that describes the concatenation of N locations
8826 used to form the address of a memory location. */
8828 static dw_loc_descr_ref
8829 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode)
8832 dw_loc_descr_ref cc_loc_result = NULL;
8833 unsigned int n = XVECLEN (concatn, 0);
8835 for (i = 0; i < n; ++i)
8837 dw_loc_descr_ref ref;
8838 rtx x = XVECEXP (concatn, 0, i);
8840 ref = mem_loc_descriptor (x, mode);
8844 add_loc_descr (&cc_loc_result, ref);
8845 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
8848 return cc_loc_result;
8851 /* The following routine converts the RTL for a variable or parameter
8852 (resident in memory) into an equivalent Dwarf representation of a
8853 mechanism for getting the address of that same variable onto the top of a
8854 hypothetical "address evaluation" stack.
8856 When creating memory location descriptors, we are effectively transforming
8857 the RTL for a memory-resident object into its Dwarf postfix expression
8858 equivalent. This routine recursively descends an RTL tree, turning
8859 it into Dwarf postfix code as it goes.
8861 MODE is the mode of the memory reference, needed to handle some
8862 autoincrement addressing modes.
8864 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8865 location list for RTL.
8867 Return 0 if we can't represent the location. */
8869 static dw_loc_descr_ref
8870 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8872 dw_loc_descr_ref mem_loc_result = NULL;
8873 enum dwarf_location_atom op;
8875 /* Note that for a dynamically sized array, the location we will generate a
8876 description of here will be the lowest numbered location which is
8877 actually within the array. That's *not* necessarily the same as the
8878 zeroth element of the array. */
8880 rtl = targetm.delegitimize_address (rtl);
8882 switch (GET_CODE (rtl))
8887 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8888 just fall into the SUBREG code. */
8890 /* ... fall through ... */
8893 /* The case of a subreg may arise when we have a local (register)
8894 variable or a formal (register) parameter which doesn't quite fill
8895 up an entire register. For now, just assume that it is
8896 legitimate to make the Dwarf info refer to the whole register which
8897 contains the given subreg. */
8898 rtl = XEXP (rtl, 0);
8900 /* ... fall through ... */
8903 /* Whenever a register number forms a part of the description of the
8904 method for calculating the (dynamic) address of a memory resident
8905 object, DWARF rules require the register number be referred to as
8906 a "base register". This distinction is not based in any way upon
8907 what category of register the hardware believes the given register
8908 belongs to. This is strictly DWARF terminology we're dealing with
8909 here. Note that in cases where the location of a memory-resident
8910 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8911 OP_CONST (0)) the actual DWARF location descriptor that we generate
8912 may just be OP_BASEREG (basereg). This may look deceptively like
8913 the object in question was allocated to a register (rather than in
8914 memory) so DWARF consumers need to be aware of the subtle
8915 distinction between OP_REG and OP_BASEREG. */
8916 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8917 mem_loc_result = based_loc_descr (rtl, 0);
8921 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8922 if (mem_loc_result != 0)
8923 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8927 rtl = XEXP (rtl, 1);
8929 /* ... fall through ... */
8932 /* Some ports can transform a symbol ref into a label ref, because
8933 the symbol ref is too far away and has to be dumped into a constant
8937 /* Alternatively, the symbol in the constant pool might be referenced
8938 by a different symbol. */
8939 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8942 rtx tmp = get_pool_constant_mark (rtl, &marked);
8944 if (GET_CODE (tmp) == SYMBOL_REF)
8947 if (CONSTANT_POOL_ADDRESS_P (tmp))
8948 get_pool_constant_mark (tmp, &marked);
8953 /* If all references to this pool constant were optimized away,
8954 it was not output and thus we can't represent it.
8955 FIXME: might try to use DW_OP_const_value here, though
8956 DW_OP_piece complicates it. */
8961 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8962 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8963 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8964 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
8968 /* Extract the PLUS expression nested inside and fall into
8970 rtl = XEXP (rtl, 1);
8975 /* Turn these into a PLUS expression and fall into the PLUS code
8977 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8978 GEN_INT (GET_CODE (rtl) == PRE_INC
8979 ? GET_MODE_UNIT_SIZE (mode)
8980 : -GET_MODE_UNIT_SIZE (mode)));
8982 /* ... fall through ... */
8986 if (is_based_loc (rtl))
8987 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
8988 INTVAL (XEXP (rtl, 1)));
8991 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8992 if (mem_loc_result == 0)
8995 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8996 && INTVAL (XEXP (rtl, 1)) >= 0)
8997 add_loc_descr (&mem_loc_result,
8998 new_loc_descr (DW_OP_plus_uconst,
8999 INTVAL (XEXP (rtl, 1)), 0));
9002 add_loc_descr (&mem_loc_result,
9003 mem_loc_descriptor (XEXP (rtl, 1), mode));
9004 add_loc_descr (&mem_loc_result,
9005 new_loc_descr (DW_OP_plus, 0, 0));
9010 /* If a pseudo-reg is optimized away, it is possible for it to
9011 be replaced with a MEM containing a multiply or shift. */
9030 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
9031 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
9033 if (op0 == 0 || op1 == 0)
9036 mem_loc_result = op0;
9037 add_loc_descr (&mem_loc_result, op1);
9038 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9043 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9047 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode);
9054 return mem_loc_result;
9057 /* Return a descriptor that describes the concatenation of two locations.
9058 This is typically a complex variable. */
9060 static dw_loc_descr_ref
9061 concat_loc_descriptor (rtx x0, rtx x1)
9063 dw_loc_descr_ref cc_loc_result = NULL;
9064 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
9065 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
9067 if (x0_ref == 0 || x1_ref == 0)
9070 cc_loc_result = x0_ref;
9071 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9073 add_loc_descr (&cc_loc_result, x1_ref);
9074 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9076 return cc_loc_result;
9079 /* Return a descriptor that describes the concatenation of N
9082 static dw_loc_descr_ref
9083 concatn_loc_descriptor (rtx concatn)
9086 dw_loc_descr_ref cc_loc_result = NULL;
9087 unsigned int n = XVECLEN (concatn, 0);
9089 for (i = 0; i < n; ++i)
9091 dw_loc_descr_ref ref;
9092 rtx x = XVECEXP (concatn, 0, i);
9094 ref = loc_descriptor (x);
9098 add_loc_descr (&cc_loc_result, ref);
9099 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9102 return cc_loc_result;
9105 /* Output a proper Dwarf location descriptor for a variable or parameter
9106 which is either allocated in a register or in a memory location. For a
9107 register, we just generate an OP_REG and the register number. For a
9108 memory location we provide a Dwarf postfix expression describing how to
9109 generate the (dynamic) address of the object onto the address stack.
9111 If we don't know how to describe it, return 0. */
9113 static dw_loc_descr_ref
9114 loc_descriptor (rtx rtl)
9116 dw_loc_descr_ref loc_result = NULL;
9118 switch (GET_CODE (rtl))
9121 /* The case of a subreg may arise when we have a local (register)
9122 variable or a formal (register) parameter which doesn't quite fill
9123 up an entire register. For now, just assume that it is
9124 legitimate to make the Dwarf info refer to the whole register which
9125 contains the given subreg. */
9126 rtl = SUBREG_REG (rtl);
9128 /* ... fall through ... */
9131 loc_result = reg_loc_descriptor (rtl);
9135 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
9139 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
9143 loc_result = concatn_loc_descriptor (rtl);
9148 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9150 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0));
9154 rtl = XEXP (rtl, 1);
9159 rtvec par_elems = XVEC (rtl, 0);
9160 int num_elem = GET_NUM_ELEM (par_elems);
9161 enum machine_mode mode;
9164 /* Create the first one, so we have something to add to. */
9165 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0));
9166 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9167 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9168 for (i = 1; i < num_elem; i++)
9170 dw_loc_descr_ref temp;
9172 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0));
9173 add_loc_descr (&loc_result, temp);
9174 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9175 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9187 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9188 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9189 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9190 top-level invocation, and we require the address of LOC; is 0 if we require
9191 the value of LOC. */
9193 static dw_loc_descr_ref
9194 loc_descriptor_from_tree_1 (tree loc, int want_address)
9196 dw_loc_descr_ref ret, ret1;
9197 int have_address = 0;
9198 enum dwarf_location_atom op;
9200 /* ??? Most of the time we do not take proper care for sign/zero
9201 extending the values properly. Hopefully this won't be a real
9204 switch (TREE_CODE (loc))
9209 case PLACEHOLDER_EXPR:
9210 /* This case involves extracting fields from an object to determine the
9211 position of other fields. We don't try to encode this here. The
9212 only user of this is Ada, which encodes the needed information using
9213 the names of types. */
9219 case PREINCREMENT_EXPR:
9220 case PREDECREMENT_EXPR:
9221 case POSTINCREMENT_EXPR:
9222 case POSTDECREMENT_EXPR:
9223 /* There are no opcodes for these operations. */
9227 /* If we already want an address, there's nothing we can do. */
9231 /* Otherwise, process the argument and look for the address. */
9232 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9235 if (DECL_THREAD_LOCAL_P (loc))
9239 /* If this is not defined, we have no way to emit the data. */
9240 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
9243 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9244 look up addresses of objects in the current module. */
9245 if (DECL_EXTERNAL (loc))
9248 rtl = rtl_for_decl_location (loc);
9249 if (rtl == NULL_RTX)
9254 rtl = XEXP (rtl, 0);
9255 if (! CONSTANT_P (rtl))
9258 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9259 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9260 ret->dw_loc_oprnd1.v.val_addr = rtl;
9262 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9263 add_loc_descr (&ret, ret1);
9271 if (DECL_HAS_VALUE_EXPR_P (loc))
9272 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9279 rtx rtl = rtl_for_decl_location (loc);
9281 if (rtl == NULL_RTX)
9283 else if (GET_CODE (rtl) == CONST_INT)
9285 HOST_WIDE_INT val = INTVAL (rtl);
9286 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9287 val &= GET_MODE_MASK (DECL_MODE (loc));
9288 ret = int_loc_descriptor (val);
9290 else if (GET_CODE (rtl) == CONST_STRING)
9292 else if (CONSTANT_P (rtl))
9294 ret = new_loc_descr (DW_OP_addr, 0, 0);
9295 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9296 ret->dw_loc_oprnd1.v.val_addr = rtl;
9300 enum machine_mode mode;
9302 /* Certain constructs can only be represented at top-level. */
9303 if (want_address == 2)
9304 return loc_descriptor (rtl);
9306 mode = GET_MODE (rtl);
9309 rtl = XEXP (rtl, 0);
9312 ret = mem_loc_descriptor (rtl, mode);
9318 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9323 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9327 case NON_LVALUE_EXPR:
9328 case VIEW_CONVERT_EXPR:
9330 case GIMPLE_MODIFY_STMT:
9331 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0),
9337 case ARRAY_RANGE_REF:
9340 HOST_WIDE_INT bitsize, bitpos, bytepos;
9341 enum machine_mode mode;
9343 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9345 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9346 &unsignedp, &volatilep, false);
9351 ret = loc_descriptor_from_tree_1 (obj, 1);
9353 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9356 if (offset != NULL_TREE)
9358 /* Variable offset. */
9359 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9360 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9363 bytepos = bitpos / BITS_PER_UNIT;
9365 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9366 else if (bytepos < 0)
9368 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9369 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9377 if (host_integerp (loc, 0))
9378 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9385 /* Get an RTL for this, if something has been emitted. */
9386 rtx rtl = lookup_constant_def (loc);
9387 enum machine_mode mode;
9389 if (!rtl || !MEM_P (rtl))
9391 mode = GET_MODE (rtl);
9392 rtl = XEXP (rtl, 0);
9393 ret = mem_loc_descriptor (rtl, mode);
9398 case TRUTH_AND_EXPR:
9399 case TRUTH_ANDIF_EXPR:
9404 case TRUTH_XOR_EXPR:
9410 case TRUTH_ORIF_EXPR:
9415 case FLOOR_DIV_EXPR:
9417 case ROUND_DIV_EXPR:
9418 case TRUNC_DIV_EXPR:
9426 case FLOOR_MOD_EXPR:
9428 case ROUND_MOD_EXPR:
9429 case TRUNC_MOD_EXPR:
9442 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9445 case POINTER_PLUS_EXPR:
9447 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9448 && host_integerp (TREE_OPERAND (loc, 1), 0))
9450 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9454 add_loc_descr (&ret,
9455 new_loc_descr (DW_OP_plus_uconst,
9456 tree_low_cst (TREE_OPERAND (loc, 1),
9466 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9473 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9480 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9487 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9502 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9503 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9504 if (ret == 0 || ret1 == 0)
9507 add_loc_descr (&ret, ret1);
9508 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9511 case TRUTH_NOT_EXPR:
9525 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9529 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9535 const enum tree_code code =
9536 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9538 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9539 build2 (code, integer_type_node,
9540 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9541 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9544 /* ... fall through ... */
9548 dw_loc_descr_ref lhs
9549 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9550 dw_loc_descr_ref rhs
9551 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9552 dw_loc_descr_ref bra_node, jump_node, tmp;
9554 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9555 if (ret == 0 || lhs == 0 || rhs == 0)
9558 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9559 add_loc_descr (&ret, bra_node);
9561 add_loc_descr (&ret, rhs);
9562 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9563 add_loc_descr (&ret, jump_node);
9565 add_loc_descr (&ret, lhs);
9566 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9567 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9569 /* ??? Need a node to point the skip at. Use a nop. */
9570 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9571 add_loc_descr (&ret, tmp);
9572 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9573 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9577 case FIX_TRUNC_EXPR:
9581 /* Leave front-end specific codes as simply unknown. This comes
9582 up, for instance, with the C STMT_EXPR. */
9583 if ((unsigned int) TREE_CODE (loc)
9584 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9587 #ifdef ENABLE_CHECKING
9588 /* Otherwise this is a generic code; we should just lists all of
9589 these explicitly. We forgot one. */
9592 /* In a release build, we want to degrade gracefully: better to
9593 generate incomplete debugging information than to crash. */
9598 /* Show if we can't fill the request for an address. */
9599 if (want_address && !have_address)
9602 /* If we've got an address and don't want one, dereference. */
9603 if (!want_address && have_address && ret)
9605 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9607 if (size > DWARF2_ADDR_SIZE || size == -1)
9609 else if (size == DWARF2_ADDR_SIZE)
9612 op = DW_OP_deref_size;
9614 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9620 static inline dw_loc_descr_ref
9621 loc_descriptor_from_tree (tree loc)
9623 return loc_descriptor_from_tree_1 (loc, 2);
9626 /* Given a value, round it up to the lowest multiple of `boundary'
9627 which is not less than the value itself. */
9629 static inline HOST_WIDE_INT
9630 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9632 return (((value + boundary - 1) / boundary) * boundary);
9635 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9636 pointer to the declared type for the relevant field variable, or return
9637 `integer_type_node' if the given node turns out to be an
9641 field_type (tree decl)
9645 if (TREE_CODE (decl) == ERROR_MARK)
9646 return integer_type_node;
9648 type = DECL_BIT_FIELD_TYPE (decl);
9649 if (type == NULL_TREE)
9650 type = TREE_TYPE (decl);
9655 /* Given a pointer to a tree node, return the alignment in bits for
9656 it, or else return BITS_PER_WORD if the node actually turns out to
9657 be an ERROR_MARK node. */
9659 static inline unsigned
9660 simple_type_align_in_bits (tree type)
9662 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9665 static inline unsigned
9666 simple_decl_align_in_bits (tree decl)
9668 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9671 /* Return the result of rounding T up to ALIGN. */
9673 static inline HOST_WIDE_INT
9674 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9676 /* We must be careful if T is negative because HOST_WIDE_INT can be
9677 either "above" or "below" unsigned int as per the C promotion
9678 rules, depending on the host, thus making the signedness of the
9679 direct multiplication and division unpredictable. */
9680 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9686 return (HOST_WIDE_INT) u;
9689 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9690 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9691 or return 0 if we are unable to determine what that offset is, either
9692 because the argument turns out to be a pointer to an ERROR_MARK node, or
9693 because the offset is actually variable. (We can't handle the latter case
9696 static HOST_WIDE_INT
9697 field_byte_offset (tree decl)
9699 HOST_WIDE_INT object_offset_in_bits;
9700 HOST_WIDE_INT bitpos_int;
9702 if (TREE_CODE (decl) == ERROR_MARK)
9705 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9707 /* We cannot yet cope with fields whose positions are variable, so
9708 for now, when we see such things, we simply return 0. Someday, we may
9709 be able to handle such cases, but it will be damn difficult. */
9710 if (! host_integerp (bit_position (decl), 0))
9713 bitpos_int = int_bit_position (decl);
9715 #ifdef PCC_BITFIELD_TYPE_MATTERS
9716 if (PCC_BITFIELD_TYPE_MATTERS)
9719 tree field_size_tree;
9720 HOST_WIDE_INT deepest_bitpos;
9721 unsigned HOST_WIDE_INT field_size_in_bits;
9722 unsigned int type_align_in_bits;
9723 unsigned int decl_align_in_bits;
9724 unsigned HOST_WIDE_INT type_size_in_bits;
9726 type = field_type (decl);
9727 field_size_tree = DECL_SIZE (decl);
9729 /* The size could be unspecified if there was an error, or for
9730 a flexible array member. */
9731 if (! field_size_tree)
9732 field_size_tree = bitsize_zero_node;
9734 /* If we don't know the size of the field, pretend it's a full word. */
9735 if (host_integerp (field_size_tree, 1))
9736 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9738 field_size_in_bits = BITS_PER_WORD;
9740 type_size_in_bits = simple_type_size_in_bits (type);
9741 type_align_in_bits = simple_type_align_in_bits (type);
9742 decl_align_in_bits = simple_decl_align_in_bits (decl);
9744 /* The GCC front-end doesn't make any attempt to keep track of the
9745 starting bit offset (relative to the start of the containing
9746 structure type) of the hypothetical "containing object" for a
9747 bit-field. Thus, when computing the byte offset value for the
9748 start of the "containing object" of a bit-field, we must deduce
9749 this information on our own. This can be rather tricky to do in
9750 some cases. For example, handling the following structure type
9751 definition when compiling for an i386/i486 target (which only
9752 aligns long long's to 32-bit boundaries) can be very tricky:
9754 struct S { int field1; long long field2:31; };
9756 Fortunately, there is a simple rule-of-thumb which can be used
9757 in such cases. When compiling for an i386/i486, GCC will
9758 allocate 8 bytes for the structure shown above. It decides to
9759 do this based upon one simple rule for bit-field allocation.
9760 GCC allocates each "containing object" for each bit-field at
9761 the first (i.e. lowest addressed) legitimate alignment boundary
9762 (based upon the required minimum alignment for the declared
9763 type of the field) which it can possibly use, subject to the
9764 condition that there is still enough available space remaining
9765 in the containing object (when allocated at the selected point)
9766 to fully accommodate all of the bits of the bit-field itself.
9768 This simple rule makes it obvious why GCC allocates 8 bytes for
9769 each object of the structure type shown above. When looking
9770 for a place to allocate the "containing object" for `field2',
9771 the compiler simply tries to allocate a 64-bit "containing
9772 object" at each successive 32-bit boundary (starting at zero)
9773 until it finds a place to allocate that 64- bit field such that
9774 at least 31 contiguous (and previously unallocated) bits remain
9775 within that selected 64 bit field. (As it turns out, for the
9776 example above, the compiler finds it is OK to allocate the
9777 "containing object" 64-bit field at bit-offset zero within the
9780 Here we attempt to work backwards from the limited set of facts
9781 we're given, and we try to deduce from those facts, where GCC
9782 must have believed that the containing object started (within
9783 the structure type). The value we deduce is then used (by the
9784 callers of this routine) to generate DW_AT_location and
9785 DW_AT_bit_offset attributes for fields (both bit-fields and, in
9786 the case of DW_AT_location, regular fields as well). */
9788 /* Figure out the bit-distance from the start of the structure to
9789 the "deepest" bit of the bit-field. */
9790 deepest_bitpos = bitpos_int + field_size_in_bits;
9792 /* This is the tricky part. Use some fancy footwork to deduce
9793 where the lowest addressed bit of the containing object must
9795 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9797 /* Round up to type_align by default. This works best for
9799 object_offset_in_bits
9800 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
9802 if (object_offset_in_bits > bitpos_int)
9804 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9806 /* Round up to decl_align instead. */
9807 object_offset_in_bits
9808 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
9813 object_offset_in_bits = bitpos_int;
9815 return object_offset_in_bits / BITS_PER_UNIT;
9818 /* The following routines define various Dwarf attributes and any data
9819 associated with them. */
9821 /* Add a location description attribute value to a DIE.
9823 This emits location attributes suitable for whole variables and
9824 whole parameters. Note that the location attributes for struct fields are
9825 generated by the routine `data_member_location_attribute' below. */
9828 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9829 dw_loc_descr_ref descr)
9832 add_AT_loc (die, attr_kind, descr);
9835 /* Attach the specialized form of location attribute used for data members of
9836 struct and union types. In the special case of a FIELD_DECL node which
9837 represents a bit-field, the "offset" part of this special location
9838 descriptor must indicate the distance in bytes from the lowest-addressed
9839 byte of the containing struct or union type to the lowest-addressed byte of
9840 the "containing object" for the bit-field. (See the `field_byte_offset'
9843 For any given bit-field, the "containing object" is a hypothetical object
9844 (of some integral or enum type) within which the given bit-field lives. The
9845 type of this hypothetical "containing object" is always the same as the
9846 declared type of the individual bit-field itself (for GCC anyway... the
9847 DWARF spec doesn't actually mandate this). Note that it is the size (in
9848 bytes) of the hypothetical "containing object" which will be given in the
9849 DW_AT_byte_size attribute for this bit-field. (See the
9850 `byte_size_attribute' function below.) It is also used when calculating the
9851 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9855 add_data_member_location_attribute (dw_die_ref die, tree decl)
9857 HOST_WIDE_INT offset;
9858 dw_loc_descr_ref loc_descr = 0;
9860 if (TREE_CODE (decl) == TREE_BINFO)
9862 /* We're working on the TAG_inheritance for a base class. */
9863 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9865 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9866 aren't at a fixed offset from all (sub)objects of the same
9867 type. We need to extract the appropriate offset from our
9868 vtable. The following dwarf expression means
9870 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9872 This is specific to the V3 ABI, of course. */
9874 dw_loc_descr_ref tmp;
9876 /* Make a copy of the object address. */
9877 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9878 add_loc_descr (&loc_descr, tmp);
9880 /* Extract the vtable address. */
9881 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9882 add_loc_descr (&loc_descr, tmp);
9884 /* Calculate the address of the offset. */
9885 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9886 gcc_assert (offset < 0);
9888 tmp = int_loc_descriptor (-offset);
9889 add_loc_descr (&loc_descr, tmp);
9890 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9891 add_loc_descr (&loc_descr, tmp);
9893 /* Extract the offset. */
9894 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9895 add_loc_descr (&loc_descr, tmp);
9897 /* Add it to the object address. */
9898 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9899 add_loc_descr (&loc_descr, tmp);
9902 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9905 offset = field_byte_offset (decl);
9909 enum dwarf_location_atom op;
9911 /* The DWARF2 standard says that we should assume that the structure
9912 address is already on the stack, so we can specify a structure field
9913 address by using DW_OP_plus_uconst. */
9915 #ifdef MIPS_DEBUGGING_INFO
9916 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9917 operator correctly. It works only if we leave the offset on the
9921 op = DW_OP_plus_uconst;
9924 loc_descr = new_loc_descr (op, offset, 0);
9927 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9930 /* Writes integer values to dw_vec_const array. */
9933 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9937 *dest++ = val & 0xff;
9943 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9945 static HOST_WIDE_INT
9946 extract_int (const unsigned char *src, unsigned int size)
9948 HOST_WIDE_INT val = 0;
9954 val |= *--src & 0xff;
9960 /* Writes floating point values to dw_vec_const array. */
9963 insert_float (rtx rtl, unsigned char *array)
9969 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9970 real_to_target (val, &rv, GET_MODE (rtl));
9972 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9973 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9975 insert_int (val[i], 4, array);
9980 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9981 does not have a "location" either in memory or in a register. These
9982 things can arise in GNU C when a constant is passed as an actual parameter
9983 to an inlined function. They can also arise in C++ where declared
9984 constants do not necessarily get memory "homes". */
9987 add_const_value_attribute (dw_die_ref die, rtx rtl)
9989 switch (GET_CODE (rtl))
9993 HOST_WIDE_INT val = INTVAL (rtl);
9996 add_AT_int (die, DW_AT_const_value, val);
9998 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10003 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10004 floating-point constant. A CONST_DOUBLE is used whenever the
10005 constant requires more than one word in order to be adequately
10006 represented. We output CONST_DOUBLEs as blocks. */
10008 enum machine_mode mode = GET_MODE (rtl);
10010 if (SCALAR_FLOAT_MODE_P (mode))
10012 unsigned int length = GET_MODE_SIZE (mode);
10013 unsigned char *array = ggc_alloc (length);
10015 insert_float (rtl, array);
10016 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10020 /* ??? We really should be using HOST_WIDE_INT throughout. */
10021 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10023 add_AT_long_long (die, DW_AT_const_value,
10024 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10031 enum machine_mode mode = GET_MODE (rtl);
10032 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10033 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10034 unsigned char *array = ggc_alloc (length * elt_size);
10038 switch (GET_MODE_CLASS (mode))
10040 case MODE_VECTOR_INT:
10041 for (i = 0, p = array; i < length; i++, p += elt_size)
10043 rtx elt = CONST_VECTOR_ELT (rtl, i);
10044 HOST_WIDE_INT lo, hi;
10046 switch (GET_CODE (elt))
10054 lo = CONST_DOUBLE_LOW (elt);
10055 hi = CONST_DOUBLE_HIGH (elt);
10059 gcc_unreachable ();
10062 if (elt_size <= sizeof (HOST_WIDE_INT))
10063 insert_int (lo, elt_size, p);
10066 unsigned char *p0 = p;
10067 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10069 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10070 if (WORDS_BIG_ENDIAN)
10075 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10076 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10081 case MODE_VECTOR_FLOAT:
10082 for (i = 0, p = array; i < length; i++, p += elt_size)
10084 rtx elt = CONST_VECTOR_ELT (rtl, i);
10085 insert_float (elt, p);
10090 gcc_unreachable ();
10093 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10098 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10104 add_AT_addr (die, DW_AT_const_value, rtl);
10105 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10109 /* In cases where an inlined instance of an inline function is passed
10110 the address of an `auto' variable (which is local to the caller) we
10111 can get a situation where the DECL_RTL of the artificial local
10112 variable (for the inlining) which acts as a stand-in for the
10113 corresponding formal parameter (of the inline function) will look
10114 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10115 exactly a compile-time constant expression, but it isn't the address
10116 of the (artificial) local variable either. Rather, it represents the
10117 *value* which the artificial local variable always has during its
10118 lifetime. We currently have no way to represent such quasi-constant
10119 values in Dwarf, so for now we just punt and generate nothing. */
10123 /* No other kinds of rtx should be possible here. */
10124 gcc_unreachable ();
10129 /* Determine whether the evaluation of EXPR references any variables
10130 or functions which aren't otherwise used (and therefore may not be
10133 reference_to_unused (tree * tp, int * walk_subtrees,
10134 void * data ATTRIBUTE_UNUSED)
10136 if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10137 *walk_subtrees = 0;
10139 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10140 && ! TREE_ASM_WRITTEN (*tp))
10142 else if (!flag_unit_at_a_time)
10144 else if (!cgraph_global_info_ready
10145 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10146 gcc_unreachable ();
10147 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10149 struct varpool_node *node = varpool_node (*tp);
10153 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10154 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10156 struct cgraph_node *node = cgraph_node (*tp);
10164 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10165 for use in a later add_const_value_attribute call. */
10168 rtl_for_decl_init (tree init, tree type)
10170 rtx rtl = NULL_RTX;
10172 /* If a variable is initialized with a string constant without embedded
10173 zeros, build CONST_STRING. */
10174 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10176 tree enttype = TREE_TYPE (type);
10177 tree domain = TYPE_DOMAIN (type);
10178 enum machine_mode mode = TYPE_MODE (enttype);
10180 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10182 && integer_zerop (TYPE_MIN_VALUE (domain))
10183 && compare_tree_int (TYPE_MAX_VALUE (domain),
10184 TREE_STRING_LENGTH (init) - 1) == 0
10185 && ((size_t) TREE_STRING_LENGTH (init)
10186 == strlen (TREE_STRING_POINTER (init)) + 1))
10187 rtl = gen_rtx_CONST_STRING (VOIDmode,
10188 ggc_strdup (TREE_STRING_POINTER (init)));
10190 /* Other aggregates, and complex values, could be represented using
10192 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10194 /* Vectors only work if their mode is supported by the target.
10195 FIXME: generic vectors ought to work too. */
10196 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10198 /* If the initializer is something that we know will expand into an
10199 immediate RTL constant, expand it now. We must be careful not to
10200 reference variables which won't be output. */
10201 else if (initializer_constant_valid_p (init, type)
10202 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10204 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10206 /* If expand_expr returns a MEM, it wasn't immediate. */
10207 gcc_assert (!rtl || !MEM_P (rtl));
10213 /* Generate RTL for the variable DECL to represent its location. */
10216 rtl_for_decl_location (tree decl)
10220 /* Here we have to decide where we are going to say the parameter "lives"
10221 (as far as the debugger is concerned). We only have a couple of
10222 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10224 DECL_RTL normally indicates where the parameter lives during most of the
10225 activation of the function. If optimization is enabled however, this
10226 could be either NULL or else a pseudo-reg. Both of those cases indicate
10227 that the parameter doesn't really live anywhere (as far as the code
10228 generation parts of GCC are concerned) during most of the function's
10229 activation. That will happen (for example) if the parameter is never
10230 referenced within the function.
10232 We could just generate a location descriptor here for all non-NULL
10233 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10234 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10235 where DECL_RTL is NULL or is a pseudo-reg.
10237 Note however that we can only get away with using DECL_INCOMING_RTL as
10238 a backup substitute for DECL_RTL in certain limited cases. In cases
10239 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10240 we can be sure that the parameter was passed using the same type as it is
10241 declared to have within the function, and that its DECL_INCOMING_RTL
10242 points us to a place where a value of that type is passed.
10244 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10245 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10246 because in these cases DECL_INCOMING_RTL points us to a value of some
10247 type which is *different* from the type of the parameter itself. Thus,
10248 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10249 such cases, the debugger would end up (for example) trying to fetch a
10250 `float' from a place which actually contains the first part of a
10251 `double'. That would lead to really incorrect and confusing
10252 output at debug-time.
10254 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10255 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10256 are a couple of exceptions however. On little-endian machines we can
10257 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10258 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10259 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10260 when (on a little-endian machine) a non-prototyped function has a
10261 parameter declared to be of type `short' or `char'. In such cases,
10262 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10263 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10264 passed `int' value. If the debugger then uses that address to fetch
10265 a `short' or a `char' (on a little-endian machine) the result will be
10266 the correct data, so we allow for such exceptional cases below.
10268 Note that our goal here is to describe the place where the given formal
10269 parameter lives during most of the function's activation (i.e. between the
10270 end of the prologue and the start of the epilogue). We'll do that as best
10271 as we can. Note however that if the given formal parameter is modified
10272 sometime during the execution of the function, then a stack backtrace (at
10273 debug-time) will show the function as having been called with the *new*
10274 value rather than the value which was originally passed in. This happens
10275 rarely enough that it is not a major problem, but it *is* a problem, and
10276 I'd like to fix it.
10278 A future version of dwarf2out.c may generate two additional attributes for
10279 any given DW_TAG_formal_parameter DIE which will describe the "passed
10280 type" and the "passed location" for the given formal parameter in addition
10281 to the attributes we now generate to indicate the "declared type" and the
10282 "active location" for each parameter. This additional set of attributes
10283 could be used by debuggers for stack backtraces. Separately, note that
10284 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10285 This happens (for example) for inlined-instances of inline function formal
10286 parameters which are never referenced. This really shouldn't be
10287 happening. All PARM_DECL nodes should get valid non-NULL
10288 DECL_INCOMING_RTL values. FIXME. */
10290 /* Use DECL_RTL as the "location" unless we find something better. */
10291 rtl = DECL_RTL_IF_SET (decl);
10293 /* When generating abstract instances, ignore everything except
10294 constants, symbols living in memory, and symbols living in
10295 fixed registers. */
10296 if (! reload_completed)
10299 && (CONSTANT_P (rtl)
10301 && CONSTANT_P (XEXP (rtl, 0)))
10303 && TREE_CODE (decl) == VAR_DECL
10304 && TREE_STATIC (decl))))
10306 rtl = targetm.delegitimize_address (rtl);
10311 else if (TREE_CODE (decl) == PARM_DECL)
10313 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10315 tree declared_type = TREE_TYPE (decl);
10316 tree passed_type = DECL_ARG_TYPE (decl);
10317 enum machine_mode dmode = TYPE_MODE (declared_type);
10318 enum machine_mode pmode = TYPE_MODE (passed_type);
10320 /* This decl represents a formal parameter which was optimized out.
10321 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10322 all cases where (rtl == NULL_RTX) just below. */
10323 if (dmode == pmode)
10324 rtl = DECL_INCOMING_RTL (decl);
10325 else if (SCALAR_INT_MODE_P (dmode)
10326 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10327 && DECL_INCOMING_RTL (decl))
10329 rtx inc = DECL_INCOMING_RTL (decl);
10332 else if (MEM_P (inc))
10334 if (BYTES_BIG_ENDIAN)
10335 rtl = adjust_address_nv (inc, dmode,
10336 GET_MODE_SIZE (pmode)
10337 - GET_MODE_SIZE (dmode));
10344 /* If the parm was passed in registers, but lives on the stack, then
10345 make a big endian correction if the mode of the type of the
10346 parameter is not the same as the mode of the rtl. */
10347 /* ??? This is the same series of checks that are made in dbxout.c before
10348 we reach the big endian correction code there. It isn't clear if all
10349 of these checks are necessary here, but keeping them all is the safe
10351 else if (MEM_P (rtl)
10352 && XEXP (rtl, 0) != const0_rtx
10353 && ! CONSTANT_P (XEXP (rtl, 0))
10354 /* Not passed in memory. */
10355 && !MEM_P (DECL_INCOMING_RTL (decl))
10356 /* Not passed by invisible reference. */
10357 && (!REG_P (XEXP (rtl, 0))
10358 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10359 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10360 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10361 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10364 /* Big endian correction check. */
10365 && BYTES_BIG_ENDIAN
10366 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10367 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10370 int offset = (UNITS_PER_WORD
10371 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10373 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10374 plus_constant (XEXP (rtl, 0), offset));
10377 else if (TREE_CODE (decl) == VAR_DECL
10380 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10381 && BYTES_BIG_ENDIAN)
10383 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10384 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10386 /* If a variable is declared "register" yet is smaller than
10387 a register, then if we store the variable to memory, it
10388 looks like we're storing a register-sized value, when in
10389 fact we are not. We need to adjust the offset of the
10390 storage location to reflect the actual value's bytes,
10391 else gdb will not be able to display it. */
10393 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10394 plus_constant (XEXP (rtl, 0), rsize-dsize));
10397 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10398 and will have been substituted directly into all expressions that use it.
10399 C does not have such a concept, but C++ and other languages do. */
10400 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10401 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10404 rtl = targetm.delegitimize_address (rtl);
10406 /* If we don't look past the constant pool, we risk emitting a
10407 reference to a constant pool entry that isn't referenced from
10408 code, and thus is not emitted. */
10410 rtl = avoid_constant_pool_reference (rtl);
10415 /* We need to figure out what section we should use as the base for the
10416 address ranges where a given location is valid.
10417 1. If this particular DECL has a section associated with it, use that.
10418 2. If this function has a section associated with it, use that.
10419 3. Otherwise, use the text section.
10420 XXX: If you split a variable across multiple sections, we won't notice. */
10422 static const char *
10423 secname_for_decl (tree decl)
10425 const char *secname;
10427 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10429 tree sectree = DECL_SECTION_NAME (decl);
10430 secname = TREE_STRING_POINTER (sectree);
10432 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10434 tree sectree = DECL_SECTION_NAME (current_function_decl);
10435 secname = TREE_STRING_POINTER (sectree);
10437 else if (cfun && in_cold_section_p)
10438 secname = cfun->cold_section_label;
10440 secname = text_section_label;
10445 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10446 data attribute for a variable or a parameter. We generate the
10447 DW_AT_const_value attribute only in those cases where the given variable
10448 or parameter does not have a true "location" either in memory or in a
10449 register. This can happen (for example) when a constant is passed as an
10450 actual argument in a call to an inline function. (It's possible that
10451 these things can crop up in other ways also.) Note that one type of
10452 constant value which can be passed into an inlined function is a constant
10453 pointer. This can happen for example if an actual argument in an inlined
10454 function call evaluates to a compile-time constant address. */
10457 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10458 enum dwarf_attribute attr)
10461 dw_loc_descr_ref descr;
10462 var_loc_list *loc_list;
10463 struct var_loc_node *node;
10464 if (TREE_CODE (decl) == ERROR_MARK)
10467 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10468 || TREE_CODE (decl) == RESULT_DECL);
10470 /* See if we possibly have multiple locations for this variable. */
10471 loc_list = lookup_decl_loc (decl);
10473 /* If it truly has multiple locations, the first and last node will
10475 if (loc_list && loc_list->first != loc_list->last)
10477 const char *endname, *secname;
10478 dw_loc_list_ref list;
10481 /* Now that we know what section we are using for a base,
10482 actually construct the list of locations.
10483 The first location information is what is passed to the
10484 function that creates the location list, and the remaining
10485 locations just get added on to that list.
10486 Note that we only know the start address for a location
10487 (IE location changes), so to build the range, we use
10488 the range [current location start, next location start].
10489 This means we have to special case the last node, and generate
10490 a range of [last location start, end of function label]. */
10492 node = loc_list->first;
10493 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10494 secname = secname_for_decl (decl);
10496 list = new_loc_list (loc_descriptor (varloc),
10497 node->label, node->next->label, secname, 1);
10500 for (; node->next; node = node->next)
10501 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10503 /* The variable has a location between NODE->LABEL and
10504 NODE->NEXT->LABEL. */
10505 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10506 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10507 node->label, node->next->label, secname);
10510 /* If the variable has a location at the last label
10511 it keeps its location until the end of function. */
10512 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10514 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10516 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10517 if (!current_function_decl)
10518 endname = text_end_label;
10521 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10522 current_function_funcdef_no);
10523 endname = ggc_strdup (label_id);
10525 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10526 node->label, endname, secname);
10529 /* Finally, add the location list to the DIE, and we are done. */
10530 add_AT_loc_list (die, attr, list);
10534 /* Try to get some constant RTL for this decl, and use that as the value of
10537 rtl = rtl_for_decl_location (decl);
10538 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10540 add_const_value_attribute (die, rtl);
10544 /* If we have tried to generate the location otherwise, and it
10545 didn't work out (we wouldn't be here if we did), and we have a one entry
10546 location list, try generating a location from that. */
10547 if (loc_list && loc_list->first)
10549 node = loc_list->first;
10550 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note));
10553 add_AT_location_description (die, attr, descr);
10558 /* We couldn't get any rtl, so try directly generating the location
10559 description from the tree. */
10560 descr = loc_descriptor_from_tree (decl);
10563 add_AT_location_description (die, attr, descr);
10566 /* None of that worked, so it must not really have a location;
10567 try adding a constant value attribute from the DECL_INITIAL. */
10568 tree_add_const_value_attribute (die, decl);
10571 /* If we don't have a copy of this variable in memory for some reason (such
10572 as a C++ member constant that doesn't have an out-of-line definition),
10573 we should tell the debugger about the constant value. */
10576 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10578 tree init = DECL_INITIAL (decl);
10579 tree type = TREE_TYPE (decl);
10582 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10587 rtl = rtl_for_decl_init (init, type);
10589 add_const_value_attribute (var_die, rtl);
10592 /* Convert the CFI instructions for the current function into a
10593 location list. This is used for DW_AT_frame_base when we targeting
10594 a dwarf2 consumer that does not support the dwarf3
10595 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10598 static dw_loc_list_ref
10599 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10602 dw_loc_list_ref list, *list_tail;
10604 dw_cfa_location last_cfa, next_cfa;
10605 const char *start_label, *last_label, *section;
10607 fde = &fde_table[fde_table_in_use - 1];
10609 section = secname_for_decl (current_function_decl);
10613 next_cfa.reg = INVALID_REGNUM;
10614 next_cfa.offset = 0;
10615 next_cfa.indirect = 0;
10616 next_cfa.base_offset = 0;
10618 start_label = fde->dw_fde_begin;
10620 /* ??? Bald assumption that the CIE opcode list does not contain
10621 advance opcodes. */
10622 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10623 lookup_cfa_1 (cfi, &next_cfa);
10625 last_cfa = next_cfa;
10626 last_label = start_label;
10628 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10629 switch (cfi->dw_cfi_opc)
10631 case DW_CFA_set_loc:
10632 case DW_CFA_advance_loc1:
10633 case DW_CFA_advance_loc2:
10634 case DW_CFA_advance_loc4:
10635 if (!cfa_equal_p (&last_cfa, &next_cfa))
10637 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10638 start_label, last_label, section,
10641 list_tail = &(*list_tail)->dw_loc_next;
10642 last_cfa = next_cfa;
10643 start_label = last_label;
10645 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10648 case DW_CFA_advance_loc:
10649 /* The encoding is complex enough that we should never emit this. */
10650 case DW_CFA_remember_state:
10651 case DW_CFA_restore_state:
10652 /* We don't handle these two in this function. It would be possible
10653 if it were to be required. */
10654 gcc_unreachable ();
10657 lookup_cfa_1 (cfi, &next_cfa);
10661 if (!cfa_equal_p (&last_cfa, &next_cfa))
10663 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10664 start_label, last_label, section,
10666 list_tail = &(*list_tail)->dw_loc_next;
10667 start_label = last_label;
10669 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
10670 start_label, fde->dw_fde_end, section,
10676 /* Compute a displacement from the "steady-state frame pointer" to the
10677 frame base (often the same as the CFA), and store it in
10678 frame_pointer_fb_offset. OFFSET is added to the displacement
10679 before the latter is negated. */
10682 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
10686 #ifdef FRAME_POINTER_CFA_OFFSET
10687 reg = frame_pointer_rtx;
10688 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
10690 reg = arg_pointer_rtx;
10691 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
10694 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10695 if (GET_CODE (elim) == PLUS)
10697 offset += INTVAL (XEXP (elim, 1));
10698 elim = XEXP (elim, 0);
10700 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10701 : stack_pointer_rtx));
10703 frame_pointer_fb_offset = -offset;
10706 /* Generate a DW_AT_name attribute given some string value to be included as
10707 the value of the attribute. */
10710 add_name_attribute (dw_die_ref die, const char *name_string)
10712 if (name_string != NULL && *name_string != 0)
10714 if (demangle_name_func)
10715 name_string = (*demangle_name_func) (name_string);
10717 add_AT_string (die, DW_AT_name, name_string);
10721 /* Generate a DW_AT_comp_dir attribute for DIE. */
10724 add_comp_dir_attribute (dw_die_ref die)
10726 const char *wd = get_src_pwd ();
10728 add_AT_string (die, DW_AT_comp_dir, wd);
10731 /* Given a tree node describing an array bound (either lower or upper) output
10732 a representation for that bound. */
10735 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10737 switch (TREE_CODE (bound))
10742 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10744 if (! host_integerp (bound, 0)
10745 || (bound_attr == DW_AT_lower_bound
10746 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10747 || (is_fortran () && integer_onep (bound)))))
10748 /* Use the default. */
10751 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10756 case NON_LVALUE_EXPR:
10757 case VIEW_CONVERT_EXPR:
10758 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10768 dw_die_ref decl_die = lookup_decl_die (bound);
10770 /* ??? Can this happen, or should the variable have been bound
10771 first? Probably it can, since I imagine that we try to create
10772 the types of parameters in the order in which they exist in
10773 the list, and won't have created a forward reference to a
10774 later parameter. */
10775 if (decl_die != NULL)
10776 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10782 /* Otherwise try to create a stack operation procedure to
10783 evaluate the value of the array bound. */
10785 dw_die_ref ctx, decl_die;
10786 dw_loc_descr_ref loc;
10788 loc = loc_descriptor_from_tree (bound);
10792 if (current_function_decl == 0)
10793 ctx = comp_unit_die;
10795 ctx = lookup_decl_die (current_function_decl);
10797 decl_die = new_die (DW_TAG_variable, ctx, bound);
10798 add_AT_flag (decl_die, DW_AT_artificial, 1);
10799 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10800 add_AT_loc (decl_die, DW_AT_location, loc);
10802 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10808 /* Note that the block of subscript information for an array type also
10809 includes information about the element type of type given array type. */
10812 add_subscript_info (dw_die_ref type_die, tree type)
10814 #ifndef MIPS_DEBUGGING_INFO
10815 unsigned dimension_number;
10818 dw_die_ref subrange_die;
10820 /* The GNU compilers represent multidimensional array types as sequences of
10821 one dimensional array types whose element types are themselves array
10822 types. Here we squish that down, so that each multidimensional array
10823 type gets only one array_type DIE in the Dwarf debugging info. The draft
10824 Dwarf specification say that we are allowed to do this kind of
10825 compression in C (because there is no difference between an array or
10826 arrays and a multidimensional array in C) but for other source languages
10827 (e.g. Ada) we probably shouldn't do this. */
10829 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10830 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10831 We work around this by disabling this feature. See also
10832 gen_array_type_die. */
10833 #ifndef MIPS_DEBUGGING_INFO
10834 for (dimension_number = 0;
10835 TREE_CODE (type) == ARRAY_TYPE;
10836 type = TREE_TYPE (type), dimension_number++)
10839 tree domain = TYPE_DOMAIN (type);
10841 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10842 and (in GNU C only) variable bounds. Handle all three forms
10844 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10847 /* We have an array type with specified bounds. */
10848 lower = TYPE_MIN_VALUE (domain);
10849 upper = TYPE_MAX_VALUE (domain);
10851 /* Define the index type. */
10852 if (TREE_TYPE (domain))
10854 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10855 TREE_TYPE field. We can't emit debug info for this
10856 because it is an unnamed integral type. */
10857 if (TREE_CODE (domain) == INTEGER_TYPE
10858 && TYPE_NAME (domain) == NULL_TREE
10859 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10860 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10863 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10867 /* ??? If upper is NULL, the array has unspecified length,
10868 but it does have a lower bound. This happens with Fortran
10870 Since the debugger is definitely going to need to know N
10871 to produce useful results, go ahead and output the lower
10872 bound solo, and hope the debugger can cope. */
10874 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10876 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10879 /* Otherwise we have an array type with an unspecified length. The
10880 DWARF-2 spec does not say how to handle this; let's just leave out the
10886 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10890 switch (TREE_CODE (tree_node))
10895 case ENUMERAL_TYPE:
10898 case QUAL_UNION_TYPE:
10899 size = int_size_in_bytes (tree_node);
10902 /* For a data member of a struct or union, the DW_AT_byte_size is
10903 generally given as the number of bytes normally allocated for an
10904 object of the *declared* type of the member itself. This is true
10905 even for bit-fields. */
10906 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10909 gcc_unreachable ();
10912 /* Note that `size' might be -1 when we get to this point. If it is, that
10913 indicates that the byte size of the entity in question is variable. We
10914 have no good way of expressing this fact in Dwarf at the present time,
10915 so just let the -1 pass on through. */
10916 add_AT_unsigned (die, DW_AT_byte_size, size);
10919 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10920 which specifies the distance in bits from the highest order bit of the
10921 "containing object" for the bit-field to the highest order bit of the
10924 For any given bit-field, the "containing object" is a hypothetical object
10925 (of some integral or enum type) within which the given bit-field lives. The
10926 type of this hypothetical "containing object" is always the same as the
10927 declared type of the individual bit-field itself. The determination of the
10928 exact location of the "containing object" for a bit-field is rather
10929 complicated. It's handled by the `field_byte_offset' function (above).
10931 Note that it is the size (in bytes) of the hypothetical "containing object"
10932 which will be given in the DW_AT_byte_size attribute for this bit-field.
10933 (See `byte_size_attribute' above). */
10936 add_bit_offset_attribute (dw_die_ref die, tree decl)
10938 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10939 tree type = DECL_BIT_FIELD_TYPE (decl);
10940 HOST_WIDE_INT bitpos_int;
10941 HOST_WIDE_INT highest_order_object_bit_offset;
10942 HOST_WIDE_INT highest_order_field_bit_offset;
10943 HOST_WIDE_INT unsigned bit_offset;
10945 /* Must be a field and a bit field. */
10946 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10948 /* We can't yet handle bit-fields whose offsets are variable, so if we
10949 encounter such things, just return without generating any attribute
10950 whatsoever. Likewise for variable or too large size. */
10951 if (! host_integerp (bit_position (decl), 0)
10952 || ! host_integerp (DECL_SIZE (decl), 1))
10955 bitpos_int = int_bit_position (decl);
10957 /* Note that the bit offset is always the distance (in bits) from the
10958 highest-order bit of the "containing object" to the highest-order bit of
10959 the bit-field itself. Since the "high-order end" of any object or field
10960 is different on big-endian and little-endian machines, the computation
10961 below must take account of these differences. */
10962 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10963 highest_order_field_bit_offset = bitpos_int;
10965 if (! BYTES_BIG_ENDIAN)
10967 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10968 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10972 = (! BYTES_BIG_ENDIAN
10973 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10974 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10976 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10979 /* For a FIELD_DECL node which represents a bit field, output an attribute
10980 which specifies the length in bits of the given field. */
10983 add_bit_size_attribute (dw_die_ref die, tree decl)
10985 /* Must be a field and a bit field. */
10986 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10987 && DECL_BIT_FIELD_TYPE (decl));
10989 if (host_integerp (DECL_SIZE (decl), 1))
10990 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10993 /* If the compiled language is ANSI C, then add a 'prototyped'
10994 attribute, if arg types are given for the parameters of a function. */
10997 add_prototyped_attribute (dw_die_ref die, tree func_type)
10999 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11000 && TYPE_ARG_TYPES (func_type) != NULL)
11001 add_AT_flag (die, DW_AT_prototyped, 1);
11004 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11005 by looking in either the type declaration or object declaration
11009 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11011 dw_die_ref origin_die = NULL;
11013 if (TREE_CODE (origin) != FUNCTION_DECL)
11015 /* We may have gotten separated from the block for the inlined
11016 function, if we're in an exception handler or some such; make
11017 sure that the abstract function has been written out.
11019 Doing this for nested functions is wrong, however; functions are
11020 distinct units, and our context might not even be inline. */
11024 fn = TYPE_STUB_DECL (fn);
11026 fn = decl_function_context (fn);
11028 dwarf2out_abstract_function (fn);
11031 if (DECL_P (origin))
11032 origin_die = lookup_decl_die (origin);
11033 else if (TYPE_P (origin))
11034 origin_die = lookup_type_die (origin);
11036 /* XXX: Functions that are never lowered don't always have correct block
11037 trees (in the case of java, they simply have no block tree, in some other
11038 languages). For these functions, there is nothing we can really do to
11039 output correct debug info for inlined functions in all cases. Rather
11040 than die, we'll just produce deficient debug info now, in that we will
11041 have variables without a proper abstract origin. In the future, when all
11042 functions are lowered, we should re-add a gcc_assert (origin_die)
11046 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11049 /* We do not currently support the pure_virtual attribute. */
11052 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11054 if (DECL_VINDEX (func_decl))
11056 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11058 if (host_integerp (DECL_VINDEX (func_decl), 0))
11059 add_AT_loc (die, DW_AT_vtable_elem_location,
11060 new_loc_descr (DW_OP_constu,
11061 tree_low_cst (DECL_VINDEX (func_decl), 0),
11064 /* GNU extension: Record what type this method came from originally. */
11065 if (debug_info_level > DINFO_LEVEL_TERSE)
11066 add_AT_die_ref (die, DW_AT_containing_type,
11067 lookup_type_die (DECL_CONTEXT (func_decl)));
11071 /* Add source coordinate attributes for the given decl. */
11074 add_src_coords_attributes (dw_die_ref die, tree decl)
11076 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11078 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11079 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11082 /* Add a DW_AT_name attribute and source coordinate attribute for the
11083 given decl, but only if it actually has a name. */
11086 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11090 decl_name = DECL_NAME (decl);
11091 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11093 add_name_attribute (die, dwarf2_name (decl, 0));
11094 if (! DECL_ARTIFICIAL (decl))
11095 add_src_coords_attributes (die, decl);
11097 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11098 && TREE_PUBLIC (decl)
11099 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11100 && !DECL_ABSTRACT (decl)
11101 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)))
11102 add_AT_string (die, DW_AT_MIPS_linkage_name,
11103 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11106 #ifdef VMS_DEBUGGING_INFO
11107 /* Get the function's name, as described by its RTL. This may be different
11108 from the DECL_NAME name used in the source file. */
11109 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11111 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11112 XEXP (DECL_RTL (decl), 0));
11113 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11118 /* Push a new declaration scope. */
11121 push_decl_scope (tree scope)
11123 VEC_safe_push (tree, gc, decl_scope_table, scope);
11126 /* Pop a declaration scope. */
11129 pop_decl_scope (void)
11131 VEC_pop (tree, decl_scope_table);
11134 /* Return the DIE for the scope that immediately contains this type.
11135 Non-named types get global scope. Named types nested in other
11136 types get their containing scope if it's open, or global scope
11137 otherwise. All other types (i.e. function-local named types) get
11138 the current active scope. */
11141 scope_die_for (tree t, dw_die_ref context_die)
11143 dw_die_ref scope_die = NULL;
11144 tree containing_scope;
11147 /* Non-types always go in the current scope. */
11148 gcc_assert (TYPE_P (t));
11150 containing_scope = TYPE_CONTEXT (t);
11152 /* Use the containing namespace if it was passed in (for a declaration). */
11153 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11155 if (context_die == lookup_decl_die (containing_scope))
11158 containing_scope = NULL_TREE;
11161 /* Ignore function type "scopes" from the C frontend. They mean that
11162 a tagged type is local to a parmlist of a function declarator, but
11163 that isn't useful to DWARF. */
11164 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11165 containing_scope = NULL_TREE;
11167 if (containing_scope == NULL_TREE)
11168 scope_die = comp_unit_die;
11169 else if (TYPE_P (containing_scope))
11171 /* For types, we can just look up the appropriate DIE. But
11172 first we check to see if we're in the middle of emitting it
11173 so we know where the new DIE should go. */
11174 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11175 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11180 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11181 || TREE_ASM_WRITTEN (containing_scope));
11183 /* If none of the current dies are suitable, we get file scope. */
11184 scope_die = comp_unit_die;
11187 scope_die = lookup_type_die (containing_scope);
11190 scope_die = context_die;
11195 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11198 local_scope_p (dw_die_ref context_die)
11200 for (; context_die; context_die = context_die->die_parent)
11201 if (context_die->die_tag == DW_TAG_inlined_subroutine
11202 || context_die->die_tag == DW_TAG_subprogram)
11208 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11209 whether or not to treat a DIE in this context as a declaration. */
11212 class_or_namespace_scope_p (dw_die_ref context_die)
11214 return (context_die
11215 && (context_die->die_tag == DW_TAG_structure_type
11216 || context_die->die_tag == DW_TAG_union_type
11217 || context_die->die_tag == DW_TAG_namespace));
11220 /* Many forms of DIEs require a "type description" attribute. This
11221 routine locates the proper "type descriptor" die for the type given
11222 by 'type', and adds a DW_AT_type attribute below the given die. */
11225 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11226 int decl_volatile, dw_die_ref context_die)
11228 enum tree_code code = TREE_CODE (type);
11229 dw_die_ref type_die = NULL;
11231 /* ??? If this type is an unnamed subrange type of an integral or
11232 floating-point type, use the inner type. This is because we have no
11233 support for unnamed types in base_type_die. This can happen if this is
11234 an Ada subrange type. Correct solution is emit a subrange type die. */
11235 if ((code == INTEGER_TYPE || code == REAL_TYPE)
11236 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11237 type = TREE_TYPE (type), code = TREE_CODE (type);
11239 if (code == ERROR_MARK
11240 /* Handle a special case. For functions whose return type is void, we
11241 generate *no* type attribute. (Note that no object may have type
11242 `void', so this only applies to function return types). */
11243 || code == VOID_TYPE)
11246 type_die = modified_type_die (type,
11247 decl_const || TYPE_READONLY (type),
11248 decl_volatile || TYPE_VOLATILE (type),
11251 if (type_die != NULL)
11252 add_AT_die_ref (object_die, DW_AT_type, type_die);
11255 /* Given an object die, add the calling convention attribute for the
11256 function call type. */
11258 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
11260 enum dwarf_calling_convention value = DW_CC_normal;
11262 value = targetm.dwarf_calling_convention (type);
11264 /* Only add the attribute if the backend requests it, and
11265 is not DW_CC_normal. */
11266 if (value && (value != DW_CC_normal))
11267 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11270 /* Given a tree pointer to a struct, class, union, or enum type node, return
11271 a pointer to the (string) tag name for the given type, or zero if the type
11272 was declared without a tag. */
11274 static const char *
11275 type_tag (tree type)
11277 const char *name = 0;
11279 if (TYPE_NAME (type) != 0)
11283 /* Find the IDENTIFIER_NODE for the type name. */
11284 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11285 t = TYPE_NAME (type);
11287 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11288 a TYPE_DECL node, regardless of whether or not a `typedef' was
11290 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11291 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11293 /* We want to be extra verbose. Don't call dwarf_name if
11294 DECL_NAME isn't set. The default hook for decl_printable_name
11295 doesn't like that, and in this context it's correct to return
11296 0, instead of "<anonymous>" or the like. */
11297 if (DECL_NAME (TYPE_NAME (type)))
11298 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11301 /* Now get the name as a string, or invent one. */
11302 if (!name && t != 0)
11303 name = IDENTIFIER_POINTER (t);
11306 return (name == 0 || *name == '\0') ? 0 : name;
11309 /* Return the type associated with a data member, make a special check
11310 for bit field types. */
11313 member_declared_type (tree member)
11315 return (DECL_BIT_FIELD_TYPE (member)
11316 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11319 /* Get the decl's label, as described by its RTL. This may be different
11320 from the DECL_NAME name used in the source file. */
11323 static const char *
11324 decl_start_label (tree decl)
11327 const char *fnname;
11329 x = DECL_RTL (decl);
11330 gcc_assert (MEM_P (x));
11333 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11335 fnname = XSTR (x, 0);
11340 /* These routines generate the internal representation of the DIE's for
11341 the compilation unit. Debugging information is collected by walking
11342 the declaration trees passed in from dwarf2out_decl(). */
11345 gen_array_type_die (tree type, dw_die_ref context_die)
11347 dw_die_ref scope_die = scope_die_for (type, context_die);
11348 dw_die_ref array_die;
11351 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11352 the inner array type comes before the outer array type. Thus we must
11353 call gen_type_die before we call new_die. See below also. */
11354 #ifdef MIPS_DEBUGGING_INFO
11355 gen_type_die (TREE_TYPE (type), context_die);
11358 array_die = new_die (DW_TAG_array_type, scope_die, type);
11359 add_name_attribute (array_die, type_tag (type));
11360 equate_type_number_to_die (type, array_die);
11362 if (TREE_CODE (type) == VECTOR_TYPE)
11364 /* The frontend feeds us a representation for the vector as a struct
11365 containing an array. Pull out the array type. */
11366 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11367 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11371 /* We default the array ordering. SDB will probably do
11372 the right things even if DW_AT_ordering is not present. It's not even
11373 an issue until we start to get into multidimensional arrays anyway. If
11374 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11375 then we'll have to put the DW_AT_ordering attribute back in. (But if
11376 and when we find out that we need to put these in, we will only do so
11377 for multidimensional arrays. */
11378 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11381 #ifdef MIPS_DEBUGGING_INFO
11382 /* The SGI compilers handle arrays of unknown bound by setting
11383 AT_declaration and not emitting any subrange DIEs. */
11384 if (! TYPE_DOMAIN (type))
11385 add_AT_flag (array_die, DW_AT_declaration, 1);
11388 add_subscript_info (array_die, type);
11390 /* Add representation of the type of the elements of this array type. */
11391 element_type = TREE_TYPE (type);
11393 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11394 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11395 We work around this by disabling this feature. See also
11396 add_subscript_info. */
11397 #ifndef MIPS_DEBUGGING_INFO
11398 while (TREE_CODE (element_type) == ARRAY_TYPE)
11399 element_type = TREE_TYPE (element_type);
11401 gen_type_die (element_type, context_die);
11404 add_type_attribute (array_die, element_type, 0, 0, context_die);
11406 if (get_AT (array_die, DW_AT_name))
11407 add_pubtype (type, array_die);
11412 gen_entry_point_die (tree decl, dw_die_ref context_die)
11414 tree origin = decl_ultimate_origin (decl);
11415 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11417 if (origin != NULL)
11418 add_abstract_origin_attribute (decl_die, origin);
11421 add_name_and_src_coords_attributes (decl_die, decl);
11422 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11423 0, 0, context_die);
11426 if (DECL_ABSTRACT (decl))
11427 equate_decl_number_to_die (decl, decl_die);
11429 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11433 /* Walk through the list of incomplete types again, trying once more to
11434 emit full debugging info for them. */
11437 retry_incomplete_types (void)
11441 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11442 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11445 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11448 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11450 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11452 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11453 be incomplete and such types are not marked. */
11454 add_abstract_origin_attribute (type_die, type);
11457 /* Generate a DIE to represent an inlined instance of a structure type. */
11460 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11462 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11464 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11465 be incomplete and such types are not marked. */
11466 add_abstract_origin_attribute (type_die, type);
11469 /* Generate a DIE to represent an inlined instance of a union type. */
11472 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11474 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11476 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11477 be incomplete and such types are not marked. */
11478 add_abstract_origin_attribute (type_die, type);
11481 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11482 include all of the information about the enumeration values also. Each
11483 enumerated type name/value is listed as a child of the enumerated type
11487 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11489 dw_die_ref type_die = lookup_type_die (type);
11491 if (type_die == NULL)
11493 type_die = new_die (DW_TAG_enumeration_type,
11494 scope_die_for (type, context_die), type);
11495 equate_type_number_to_die (type, type_die);
11496 add_name_attribute (type_die, type_tag (type));
11498 else if (! TYPE_SIZE (type))
11501 remove_AT (type_die, DW_AT_declaration);
11503 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11504 given enum type is incomplete, do not generate the DW_AT_byte_size
11505 attribute or the DW_AT_element_list attribute. */
11506 if (TYPE_SIZE (type))
11510 TREE_ASM_WRITTEN (type) = 1;
11511 add_byte_size_attribute (type_die, type);
11512 if (TYPE_STUB_DECL (type) != NULL_TREE)
11513 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11515 /* If the first reference to this type was as the return type of an
11516 inline function, then it may not have a parent. Fix this now. */
11517 if (type_die->die_parent == NULL)
11518 add_child_die (scope_die_for (type, context_die), type_die);
11520 for (link = TYPE_VALUES (type);
11521 link != NULL; link = TREE_CHAIN (link))
11523 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11524 tree value = TREE_VALUE (link);
11526 add_name_attribute (enum_die,
11527 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11529 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11530 /* DWARF2 does not provide a way of indicating whether or
11531 not enumeration constants are signed or unsigned. GDB
11532 always assumes the values are signed, so we output all
11533 values as if they were signed. That means that
11534 enumeration constants with very large unsigned values
11535 will appear to have negative values in the debugger. */
11536 add_AT_int (enum_die, DW_AT_const_value,
11537 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11541 add_AT_flag (type_die, DW_AT_declaration, 1);
11543 if (get_AT (type_die, DW_AT_name))
11544 add_pubtype (type, type_die);
11549 /* Generate a DIE to represent either a real live formal parameter decl or to
11550 represent just the type of some formal parameter position in some function
11553 Note that this routine is a bit unusual because its argument may be a
11554 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11555 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11556 node. If it's the former then this function is being called to output a
11557 DIE to represent a formal parameter object (or some inlining thereof). If
11558 it's the latter, then this function is only being called to output a
11559 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11560 argument type of some subprogram type. */
11563 gen_formal_parameter_die (tree node, dw_die_ref context_die)
11565 dw_die_ref parm_die
11566 = new_die (DW_TAG_formal_parameter, context_die, node);
11569 switch (TREE_CODE_CLASS (TREE_CODE (node)))
11571 case tcc_declaration:
11572 origin = decl_ultimate_origin (node);
11573 if (origin != NULL)
11574 add_abstract_origin_attribute (parm_die, origin);
11577 add_name_and_src_coords_attributes (parm_die, node);
11578 add_type_attribute (parm_die, TREE_TYPE (node),
11579 TREE_READONLY (node),
11580 TREE_THIS_VOLATILE (node),
11582 if (DECL_ARTIFICIAL (node))
11583 add_AT_flag (parm_die, DW_AT_artificial, 1);
11586 equate_decl_number_to_die (node, parm_die);
11587 if (! DECL_ABSTRACT (node))
11588 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11593 /* We were called with some kind of a ..._TYPE node. */
11594 add_type_attribute (parm_die, node, 0, 0, context_die);
11598 gcc_unreachable ();
11604 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11605 at the end of an (ANSI prototyped) formal parameters list. */
11608 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11610 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11613 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11614 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11615 parameters as specified in some function type specification (except for
11616 those which appear as part of a function *definition*). */
11619 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11622 tree formal_type = NULL;
11623 tree first_parm_type;
11626 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11628 arg = DECL_ARGUMENTS (function_or_method_type);
11629 function_or_method_type = TREE_TYPE (function_or_method_type);
11634 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11636 /* Make our first pass over the list of formal parameter types and output a
11637 DW_TAG_formal_parameter DIE for each one. */
11638 for (link = first_parm_type; link; )
11640 dw_die_ref parm_die;
11642 formal_type = TREE_VALUE (link);
11643 if (formal_type == void_type_node)
11646 /* Output a (nameless) DIE to represent the formal parameter itself. */
11647 parm_die = gen_formal_parameter_die (formal_type, context_die);
11648 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11649 && link == first_parm_type)
11650 || (arg && DECL_ARTIFICIAL (arg)))
11651 add_AT_flag (parm_die, DW_AT_artificial, 1);
11653 link = TREE_CHAIN (link);
11655 arg = TREE_CHAIN (arg);
11658 /* If this function type has an ellipsis, add a
11659 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11660 if (formal_type != void_type_node)
11661 gen_unspecified_parameters_die (function_or_method_type, context_die);
11663 /* Make our second (and final) pass over the list of formal parameter types
11664 and output DIEs to represent those types (as necessary). */
11665 for (link = TYPE_ARG_TYPES (function_or_method_type);
11666 link && TREE_VALUE (link);
11667 link = TREE_CHAIN (link))
11668 gen_type_die (TREE_VALUE (link), context_die);
11671 /* We want to generate the DIE for TYPE so that we can generate the
11672 die for MEMBER, which has been defined; we will need to refer back
11673 to the member declaration nested within TYPE. If we're trying to
11674 generate minimal debug info for TYPE, processing TYPE won't do the
11675 trick; we need to attach the member declaration by hand. */
11678 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11680 gen_type_die (type, context_die);
11682 /* If we're trying to avoid duplicate debug info, we may not have
11683 emitted the member decl for this function. Emit it now. */
11684 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11685 && ! lookup_decl_die (member))
11687 dw_die_ref type_die;
11688 gcc_assert (!decl_ultimate_origin (member));
11690 push_decl_scope (type);
11691 type_die = lookup_type_die (type);
11692 if (TREE_CODE (member) == FUNCTION_DECL)
11693 gen_subprogram_die (member, type_die);
11694 else if (TREE_CODE (member) == FIELD_DECL)
11696 /* Ignore the nameless fields that are used to skip bits but handle
11697 C++ anonymous unions and structs. */
11698 if (DECL_NAME (member) != NULL_TREE
11699 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
11700 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
11702 gen_type_die (member_declared_type (member), type_die);
11703 gen_field_die (member, type_die);
11707 gen_variable_die (member, type_die);
11713 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11714 may later generate inlined and/or out-of-line instances of. */
11717 dwarf2out_abstract_function (tree decl)
11719 dw_die_ref old_die;
11721 struct function *save_cfun;
11723 int was_abstract = DECL_ABSTRACT (decl);
11725 /* Make sure we have the actual abstract inline, not a clone. */
11726 decl = DECL_ORIGIN (decl);
11728 old_die = lookup_decl_die (decl);
11729 if (old_die && get_AT (old_die, DW_AT_inline))
11730 /* We've already generated the abstract instance. */
11733 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11734 we don't get confused by DECL_ABSTRACT. */
11735 if (debug_info_level > DINFO_LEVEL_TERSE)
11737 context = decl_class_context (decl);
11739 gen_type_die_for_member
11740 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11743 /* Pretend we've just finished compiling this function. */
11744 save_fn = current_function_decl;
11746 current_function_decl = decl;
11747 cfun = DECL_STRUCT_FUNCTION (decl);
11749 set_decl_abstract_flags (decl, 1);
11750 dwarf2out_decl (decl);
11751 if (! was_abstract)
11752 set_decl_abstract_flags (decl, 0);
11754 current_function_decl = save_fn;
11758 /* Helper function of premark_used_types() which gets called through
11759 htab_traverse_resize().
11761 Marks the DIE of a given type in *SLOT as perennial, so it never gets
11762 marked as unused by prune_unused_types. */
11764 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
11770 die = lookup_type_die (type);
11772 die->die_perennial_p = 1;
11776 /* Mark all members of used_types_hash as perennial. */
11778 premark_used_types (void)
11780 if (cfun && cfun->used_types_hash)
11781 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
11784 /* Generate a DIE to represent a declared function (either file-scope or
11788 gen_subprogram_die (tree decl, dw_die_ref context_die)
11790 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11791 tree origin = decl_ultimate_origin (decl);
11792 dw_die_ref subr_die;
11795 dw_die_ref old_die = lookup_decl_die (decl);
11796 int declaration = (current_function_decl != decl
11797 || class_or_namespace_scope_p (context_die));
11799 premark_used_types ();
11801 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11802 started to generate the abstract instance of an inline, decided to output
11803 its containing class, and proceeded to emit the declaration of the inline
11804 from the member list for the class. If so, DECLARATION takes priority;
11805 we'll get back to the abstract instance when done with the class. */
11807 /* The class-scope declaration DIE must be the primary DIE. */
11808 if (origin && declaration && class_or_namespace_scope_p (context_die))
11811 gcc_assert (!old_die);
11814 /* Now that the C++ front end lazily declares artificial member fns, we
11815 might need to retrofit the declaration into its class. */
11816 if (!declaration && !origin && !old_die
11817 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
11818 && !class_or_namespace_scope_p (context_die)
11819 && debug_info_level > DINFO_LEVEL_TERSE)
11820 old_die = force_decl_die (decl);
11822 if (origin != NULL)
11824 gcc_assert (!declaration || local_scope_p (context_die));
11826 /* Fixup die_parent for the abstract instance of a nested
11827 inline function. */
11828 if (old_die && old_die->die_parent == NULL)
11829 add_child_die (context_die, old_die);
11831 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11832 add_abstract_origin_attribute (subr_die, origin);
11836 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11837 struct dwarf_file_data * file_index = lookup_filename (s.file);
11839 if (!get_AT_flag (old_die, DW_AT_declaration)
11840 /* We can have a normal definition following an inline one in the
11841 case of redefinition of GNU C extern inlines.
11842 It seems reasonable to use AT_specification in this case. */
11843 && !get_AT (old_die, DW_AT_inline))
11845 /* Detect and ignore this case, where we are trying to output
11846 something we have already output. */
11850 /* If the definition comes from the same place as the declaration,
11851 maybe use the old DIE. We always want the DIE for this function
11852 that has the *_pc attributes to be under comp_unit_die so the
11853 debugger can find it. We also need to do this for abstract
11854 instances of inlines, since the spec requires the out-of-line copy
11855 to have the same parent. For local class methods, this doesn't
11856 apply; we just use the old DIE. */
11857 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11858 && (DECL_ARTIFICIAL (decl)
11859 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
11860 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11861 == (unsigned) s.line))))
11863 subr_die = old_die;
11865 /* Clear out the declaration attribute and the formal parameters.
11866 Do not remove all children, because it is possible that this
11867 declaration die was forced using force_decl_die(). In such
11868 cases die that forced declaration die (e.g. TAG_imported_module)
11869 is one of the children that we do not want to remove. */
11870 remove_AT (subr_die, DW_AT_declaration);
11871 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11875 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11876 add_AT_specification (subr_die, old_die);
11877 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
11878 add_AT_file (subr_die, DW_AT_decl_file, file_index);
11879 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
11880 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
11885 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11887 if (TREE_PUBLIC (decl))
11888 add_AT_flag (subr_die, DW_AT_external, 1);
11890 add_name_and_src_coords_attributes (subr_die, decl);
11891 if (debug_info_level > DINFO_LEVEL_TERSE)
11893 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11894 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11895 0, 0, context_die);
11898 add_pure_or_virtual_attribute (subr_die, decl);
11899 if (DECL_ARTIFICIAL (decl))
11900 add_AT_flag (subr_die, DW_AT_artificial, 1);
11902 if (TREE_PROTECTED (decl))
11903 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11904 else if (TREE_PRIVATE (decl))
11905 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11910 if (!old_die || !get_AT (old_die, DW_AT_inline))
11912 add_AT_flag (subr_die, DW_AT_declaration, 1);
11914 /* The first time we see a member function, it is in the context of
11915 the class to which it belongs. We make sure of this by emitting
11916 the class first. The next time is the definition, which is
11917 handled above. The two may come from the same source text.
11919 Note that force_decl_die() forces function declaration die. It is
11920 later reused to represent definition. */
11921 equate_decl_number_to_die (decl, subr_die);
11924 else if (DECL_ABSTRACT (decl))
11926 if (DECL_DECLARED_INLINE_P (decl))
11928 if (cgraph_function_possibly_inlined_p (decl))
11929 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11931 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11935 if (cgraph_function_possibly_inlined_p (decl))
11936 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11938 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11941 equate_decl_number_to_die (decl, subr_die);
11943 else if (!DECL_EXTERNAL (decl))
11945 HOST_WIDE_INT cfa_fb_offset;
11947 if (!old_die || !get_AT (old_die, DW_AT_inline))
11948 equate_decl_number_to_die (decl, subr_die);
11950 if (!flag_reorder_blocks_and_partition)
11952 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11953 current_function_funcdef_no);
11954 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11955 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11956 current_function_funcdef_no);
11957 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11959 add_pubname (decl, subr_die);
11960 add_arange (decl, subr_die);
11963 { /* Do nothing for now; maybe need to duplicate die, one for
11964 hot section and ond for cold section, then use the hot/cold
11965 section begin/end labels to generate the aranges... */
11967 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11968 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11969 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11970 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11972 add_pubname (decl, subr_die);
11973 add_arange (decl, subr_die);
11974 add_arange (decl, subr_die);
11978 #ifdef MIPS_DEBUGGING_INFO
11979 /* Add a reference to the FDE for this routine. */
11980 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11983 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
11985 /* We define the "frame base" as the function's CFA. This is more
11986 convenient for several reasons: (1) It's stable across the prologue
11987 and epilogue, which makes it better than just a frame pointer,
11988 (2) With dwarf3, there exists a one-byte encoding that allows us
11989 to reference the .debug_frame data by proxy, but failing that,
11990 (3) We can at least reuse the code inspection and interpretation
11991 code that determines the CFA position at various points in the
11993 /* ??? Use some command-line or configury switch to enable the use
11994 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11995 consumers that understand it; fall back to "pure" dwarf2 and
11996 convert the CFA data into a location list. */
11998 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
11999 if (list->dw_loc_next)
12000 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12002 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12005 /* Compute a displacement from the "steady-state frame pointer" to
12006 the CFA. The former is what all stack slots and argument slots
12007 will reference in the rtl; the later is what we've told the
12008 debugger about. We'll need to adjust all frame_base references
12009 by this displacement. */
12010 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12012 if (cfun->static_chain_decl)
12013 add_AT_location_description (subr_die, DW_AT_static_link,
12014 loc_descriptor_from_tree (cfun->static_chain_decl));
12017 /* Now output descriptions of the arguments for this function. This gets
12018 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12019 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12020 `...' at the end of the formal parameter list. In order to find out if
12021 there was a trailing ellipsis or not, we must instead look at the type
12022 associated with the FUNCTION_DECL. This will be a node of type
12023 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12024 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12025 an ellipsis at the end. */
12027 /* In the case where we are describing a mere function declaration, all we
12028 need to do here (and all we *can* do here) is to describe the *types* of
12029 its formal parameters. */
12030 if (debug_info_level <= DINFO_LEVEL_TERSE)
12032 else if (declaration)
12033 gen_formal_types_die (decl, subr_die);
12036 /* Generate DIEs to represent all known formal parameters. */
12037 tree arg_decls = DECL_ARGUMENTS (decl);
12040 /* When generating DIEs, generate the unspecified_parameters DIE
12041 instead if we come across the arg "__builtin_va_alist" */
12042 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12043 if (TREE_CODE (parm) == PARM_DECL)
12045 if (DECL_NAME (parm)
12046 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12047 "__builtin_va_alist"))
12048 gen_unspecified_parameters_die (parm, subr_die);
12050 gen_decl_die (parm, subr_die);
12053 /* Decide whether we need an unspecified_parameters DIE at the end.
12054 There are 2 more cases to do this for: 1) the ansi ... declaration -
12055 this is detectable when the end of the arg list is not a
12056 void_type_node 2) an unprototyped function declaration (not a
12057 definition). This just means that we have no info about the
12058 parameters at all. */
12059 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12060 if (fn_arg_types != NULL)
12062 /* This is the prototyped case, check for.... */
12063 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12064 gen_unspecified_parameters_die (decl, subr_die);
12066 else if (DECL_INITIAL (decl) == NULL_TREE)
12067 gen_unspecified_parameters_die (decl, subr_die);
12070 /* Output Dwarf info for all of the stuff within the body of the function
12071 (if it has one - it may be just a declaration). */
12072 outer_scope = DECL_INITIAL (decl);
12074 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12075 a function. This BLOCK actually represents the outermost binding contour
12076 for the function, i.e. the contour in which the function's formal
12077 parameters and labels get declared. Curiously, it appears that the front
12078 end doesn't actually put the PARM_DECL nodes for the current function onto
12079 the BLOCK_VARS list for this outer scope, but are strung off of the
12080 DECL_ARGUMENTS list for the function instead.
12082 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12083 the LABEL_DECL nodes for the function however, and we output DWARF info
12084 for those in decls_for_scope. Just within the `outer_scope' there will be
12085 a BLOCK node representing the function's outermost pair of curly braces,
12086 and any blocks used for the base and member initializers of a C++
12087 constructor function. */
12088 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12090 /* Emit a DW_TAG_variable DIE for a named return value. */
12091 if (DECL_NAME (DECL_RESULT (decl)))
12092 gen_decl_die (DECL_RESULT (decl), subr_die);
12094 current_function_has_inlines = 0;
12095 decls_for_scope (outer_scope, subr_die, 0);
12097 #if 0 && defined (MIPS_DEBUGGING_INFO)
12098 if (current_function_has_inlines)
12100 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12101 if (! comp_unit_has_inlines)
12103 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12104 comp_unit_has_inlines = 1;
12109 /* Add the calling convention attribute if requested. */
12110 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
12114 /* Generate a DIE to represent a declared data object. */
12117 gen_variable_die (tree decl, dw_die_ref context_die)
12119 tree origin = decl_ultimate_origin (decl);
12120 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
12122 dw_die_ref old_die = lookup_decl_die (decl);
12123 int declaration = (DECL_EXTERNAL (decl)
12124 /* If DECL is COMDAT and has not actually been
12125 emitted, we cannot take its address; there
12126 might end up being no definition anywhere in
12127 the program. For example, consider the C++
12131 struct S { static const int i = 7; };
12136 int f() { return S<int>::i; }
12138 Here, S<int>::i is not DECL_EXTERNAL, but no
12139 definition is required, so the compiler will
12140 not emit a definition. */
12141 || (TREE_CODE (decl) == VAR_DECL
12142 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12143 || class_or_namespace_scope_p (context_die));
12145 if (origin != NULL)
12146 add_abstract_origin_attribute (var_die, origin);
12148 /* Loop unrolling can create multiple blocks that refer to the same
12149 static variable, so we must test for the DW_AT_declaration flag.
12151 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12152 copy decls and set the DECL_ABSTRACT flag on them instead of
12155 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12157 ??? The declare_in_namespace support causes us to get two DIEs for one
12158 variable, both of which are declarations. We want to avoid considering
12159 one to be a specification, so we must test that this DIE is not a
12161 else if (old_die && TREE_STATIC (decl) && ! declaration
12162 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12164 /* This is a definition of a C++ class level static. */
12165 add_AT_specification (var_die, old_die);
12166 if (DECL_NAME (decl))
12168 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12169 struct dwarf_file_data * file_index = lookup_filename (s.file);
12171 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12172 add_AT_file (var_die, DW_AT_decl_file, file_index);
12174 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12175 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12180 add_name_and_src_coords_attributes (var_die, decl);
12181 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
12182 TREE_THIS_VOLATILE (decl), context_die);
12184 if (TREE_PUBLIC (decl))
12185 add_AT_flag (var_die, DW_AT_external, 1);
12187 if (DECL_ARTIFICIAL (decl))
12188 add_AT_flag (var_die, DW_AT_artificial, 1);
12190 if (TREE_PROTECTED (decl))
12191 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12192 else if (TREE_PRIVATE (decl))
12193 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12197 add_AT_flag (var_die, DW_AT_declaration, 1);
12199 if (DECL_ABSTRACT (decl) || declaration)
12200 equate_decl_number_to_die (decl, var_die);
12202 if (! declaration && ! DECL_ABSTRACT (decl))
12204 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12205 add_pubname (decl, var_die);
12208 tree_add_const_value_attribute (var_die, decl);
12211 /* Generate a DIE to represent a label identifier. */
12214 gen_label_die (tree decl, dw_die_ref context_die)
12216 tree origin = decl_ultimate_origin (decl);
12217 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12219 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12221 if (origin != NULL)
12222 add_abstract_origin_attribute (lbl_die, origin);
12224 add_name_and_src_coords_attributes (lbl_die, decl);
12226 if (DECL_ABSTRACT (decl))
12227 equate_decl_number_to_die (decl, lbl_die);
12230 insn = DECL_RTL_IF_SET (decl);
12232 /* Deleted labels are programmer specified labels which have been
12233 eliminated because of various optimizations. We still emit them
12234 here so that it is possible to put breakpoints on them. */
12238 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12240 /* When optimization is enabled (via -O) some parts of the compiler
12241 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12242 represent source-level labels which were explicitly declared by
12243 the user. This really shouldn't be happening though, so catch
12244 it if it ever does happen. */
12245 gcc_assert (!INSN_DELETED_P (insn));
12247 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12248 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12253 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12254 attributes to the DIE for a block STMT, to describe where the inlined
12255 function was called from. This is similar to add_src_coords_attributes. */
12258 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12260 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12262 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12263 add_AT_unsigned (die, DW_AT_call_line, s.line);
12267 /* If STMT's abstract origin is a function declaration and STMT's
12268 first subblock's abstract origin is the function's outermost block,
12269 then we're looking at the main entry point. */
12271 is_inlined_entry_point (tree stmt)
12275 if (!stmt || TREE_CODE (stmt) != BLOCK)
12278 decl = block_ultimate_origin (stmt);
12280 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12283 block = BLOCK_SUBBLOCKS (stmt);
12287 if (TREE_CODE (block) != BLOCK)
12290 block = block_ultimate_origin (block);
12293 return block == DECL_INITIAL (decl);
12296 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12297 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12300 add_high_low_attributes (tree stmt, dw_die_ref die)
12302 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12304 if (BLOCK_FRAGMENT_CHAIN (stmt))
12308 if (is_inlined_entry_point (stmt))
12310 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12311 BLOCK_NUMBER (stmt));
12312 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12315 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12317 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12320 add_ranges (chain);
12321 chain = BLOCK_FRAGMENT_CHAIN (chain);
12328 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12329 BLOCK_NUMBER (stmt));
12330 add_AT_lbl_id (die, DW_AT_low_pc, label);
12331 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12332 BLOCK_NUMBER (stmt));
12333 add_AT_lbl_id (die, DW_AT_high_pc, label);
12337 /* Generate a DIE for a lexical block. */
12340 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12342 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12344 if (! BLOCK_ABSTRACT (stmt))
12345 add_high_low_attributes (stmt, stmt_die);
12347 decls_for_scope (stmt, stmt_die, depth);
12350 /* Generate a DIE for an inlined subprogram. */
12353 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12355 tree decl = block_ultimate_origin (stmt);
12357 /* Emit info for the abstract instance first, if we haven't yet. We
12358 must emit this even if the block is abstract, otherwise when we
12359 emit the block below (or elsewhere), we may end up trying to emit
12360 a die whose origin die hasn't been emitted, and crashing. */
12361 dwarf2out_abstract_function (decl);
12363 if (! BLOCK_ABSTRACT (stmt))
12365 dw_die_ref subr_die
12366 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12368 add_abstract_origin_attribute (subr_die, decl);
12369 add_high_low_attributes (stmt, subr_die);
12370 add_call_src_coords_attributes (stmt, subr_die);
12372 decls_for_scope (stmt, subr_die, depth);
12373 current_function_has_inlines = 1;
12376 /* We may get here if we're the outer block of function A that was
12377 inlined into function B that was inlined into function C. When
12378 generating debugging info for C, dwarf2out_abstract_function(B)
12379 would mark all inlined blocks as abstract, including this one.
12380 So, we wouldn't (and shouldn't) expect labels to be generated
12381 for this one. Instead, just emit debugging info for
12382 declarations within the block. This is particularly important
12383 in the case of initializers of arguments passed from B to us:
12384 if they're statement expressions containing declarations, we
12385 wouldn't generate dies for their abstract variables, and then,
12386 when generating dies for the real variables, we'd die (pun
12388 gen_lexical_block_die (stmt, context_die, depth);
12391 /* Generate a DIE for a field in a record, or structure. */
12394 gen_field_die (tree decl, dw_die_ref context_die)
12396 dw_die_ref decl_die;
12398 if (TREE_TYPE (decl) == error_mark_node)
12401 decl_die = new_die (DW_TAG_member, context_die, decl);
12402 add_name_and_src_coords_attributes (decl_die, decl);
12403 add_type_attribute (decl_die, member_declared_type (decl),
12404 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12407 if (DECL_BIT_FIELD_TYPE (decl))
12409 add_byte_size_attribute (decl_die, decl);
12410 add_bit_size_attribute (decl_die, decl);
12411 add_bit_offset_attribute (decl_die, decl);
12414 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12415 add_data_member_location_attribute (decl_die, decl);
12417 if (DECL_ARTIFICIAL (decl))
12418 add_AT_flag (decl_die, DW_AT_artificial, 1);
12420 if (TREE_PROTECTED (decl))
12421 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12422 else if (TREE_PRIVATE (decl))
12423 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12425 /* Equate decl number to die, so that we can look up this decl later on. */
12426 equate_decl_number_to_die (decl, decl_die);
12430 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12431 Use modified_type_die instead.
12432 We keep this code here just in case these types of DIEs may be needed to
12433 represent certain things in other languages (e.g. Pascal) someday. */
12436 gen_pointer_type_die (tree type, dw_die_ref context_die)
12439 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12441 equate_type_number_to_die (type, ptr_die);
12442 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12443 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12446 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12447 Use modified_type_die instead.
12448 We keep this code here just in case these types of DIEs may be needed to
12449 represent certain things in other languages (e.g. Pascal) someday. */
12452 gen_reference_type_die (tree type, dw_die_ref context_die)
12455 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12457 equate_type_number_to_die (type, ref_die);
12458 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12459 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12463 /* Generate a DIE for a pointer to a member type. */
12466 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12469 = new_die (DW_TAG_ptr_to_member_type,
12470 scope_die_for (type, context_die), type);
12472 equate_type_number_to_die (type, ptr_die);
12473 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12474 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12475 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12478 /* Generate the DIE for the compilation unit. */
12481 gen_compile_unit_die (const char *filename)
12484 char producer[250];
12485 const char *language_string = lang_hooks.name;
12488 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12492 add_name_attribute (die, filename);
12493 /* Don't add cwd for <built-in>. */
12494 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
12495 add_comp_dir_attribute (die);
12498 sprintf (producer, "%s %s", language_string, version_string);
12500 #ifdef MIPS_DEBUGGING_INFO
12501 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12502 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12503 not appear in the producer string, the debugger reaches the conclusion
12504 that the object file is stripped and has no debugging information.
12505 To get the MIPS/SGI debugger to believe that there is debugging
12506 information in the object file, we add a -g to the producer string. */
12507 if (debug_info_level > DINFO_LEVEL_TERSE)
12508 strcat (producer, " -g");
12511 add_AT_string (die, DW_AT_producer, producer);
12513 if (strcmp (language_string, "GNU C++") == 0)
12514 language = DW_LANG_C_plus_plus;
12515 else if (strcmp (language_string, "GNU Ada") == 0)
12516 language = DW_LANG_Ada95;
12517 else if (strcmp (language_string, "GNU F77") == 0)
12518 language = DW_LANG_Fortran77;
12519 else if (strcmp (language_string, "GNU F95") == 0)
12520 language = DW_LANG_Fortran95;
12521 else if (strcmp (language_string, "GNU Pascal") == 0)
12522 language = DW_LANG_Pascal83;
12523 else if (strcmp (language_string, "GNU Java") == 0)
12524 language = DW_LANG_Java;
12525 else if (strcmp (language_string, "GNU Objective-C") == 0)
12526 language = DW_LANG_ObjC;
12527 else if (strcmp (language_string, "GNU Objective-C++") == 0)
12528 language = DW_LANG_ObjC_plus_plus;
12530 language = DW_LANG_C89;
12532 add_AT_unsigned (die, DW_AT_language, language);
12536 /* Generate the DIE for a base class. */
12539 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12541 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12543 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12544 add_data_member_location_attribute (die, binfo);
12546 if (BINFO_VIRTUAL_P (binfo))
12547 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12549 if (access == access_public_node)
12550 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12551 else if (access == access_protected_node)
12552 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
12555 /* Generate a DIE for a class member. */
12558 gen_member_die (tree type, dw_die_ref context_die)
12561 tree binfo = TYPE_BINFO (type);
12564 /* If this is not an incomplete type, output descriptions of each of its
12565 members. Note that as we output the DIEs necessary to represent the
12566 members of this record or union type, we will also be trying to output
12567 DIEs to represent the *types* of those members. However the `type'
12568 function (above) will specifically avoid generating type DIEs for member
12569 types *within* the list of member DIEs for this (containing) type except
12570 for those types (of members) which are explicitly marked as also being
12571 members of this (containing) type themselves. The g++ front- end can
12572 force any given type to be treated as a member of some other (containing)
12573 type by setting the TYPE_CONTEXT of the given (member) type to point to
12574 the TREE node representing the appropriate (containing) type. */
12576 /* First output info about the base classes. */
12579 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
12583 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
12584 gen_inheritance_die (base,
12585 (accesses ? VEC_index (tree, accesses, i)
12586 : access_public_node), context_die);
12589 /* Now output info about the data members and type members. */
12590 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
12592 /* If we thought we were generating minimal debug info for TYPE
12593 and then changed our minds, some of the member declarations
12594 may have already been defined. Don't define them again, but
12595 do put them in the right order. */
12597 child = lookup_decl_die (member);
12599 splice_child_die (context_die, child);
12601 gen_decl_die (member, context_die);
12604 /* Now output info about the function members (if any). */
12605 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
12607 /* Don't include clones in the member list. */
12608 if (DECL_ABSTRACT_ORIGIN (member))
12611 child = lookup_decl_die (member);
12613 splice_child_die (context_die, child);
12615 gen_decl_die (member, context_die);
12619 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12620 is set, we pretend that the type was never defined, so we only get the
12621 member DIEs needed by later specification DIEs. */
12624 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
12625 enum debug_info_usage usage)
12627 dw_die_ref type_die = lookup_type_die (type);
12628 dw_die_ref scope_die = 0;
12630 int complete = (TYPE_SIZE (type)
12631 && (! TYPE_STUB_DECL (type)
12632 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
12633 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
12634 complete = complete && should_emit_struct_debug (type, usage);
12636 if (type_die && ! complete)
12639 if (TYPE_CONTEXT (type) != NULL_TREE
12640 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12641 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
12644 scope_die = scope_die_for (type, context_die);
12646 if (! type_die || (nested && scope_die == comp_unit_die))
12647 /* First occurrence of type or toplevel definition of nested class. */
12649 dw_die_ref old_die = type_die;
12651 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
12652 ? DW_TAG_structure_type : DW_TAG_union_type,
12654 equate_type_number_to_die (type, type_die);
12656 add_AT_specification (type_die, old_die);
12658 add_name_attribute (type_die, type_tag (type));
12661 remove_AT (type_die, DW_AT_declaration);
12663 /* If this type has been completed, then give it a byte_size attribute and
12664 then give a list of members. */
12665 if (complete && !ns_decl)
12667 /* Prevent infinite recursion in cases where the type of some member of
12668 this type is expressed in terms of this type itself. */
12669 TREE_ASM_WRITTEN (type) = 1;
12670 add_byte_size_attribute (type_die, type);
12671 if (TYPE_STUB_DECL (type) != NULL_TREE)
12672 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12674 /* If the first reference to this type was as the return type of an
12675 inline function, then it may not have a parent. Fix this now. */
12676 if (type_die->die_parent == NULL)
12677 add_child_die (scope_die, type_die);
12679 push_decl_scope (type);
12680 gen_member_die (type, type_die);
12683 /* GNU extension: Record what type our vtable lives in. */
12684 if (TYPE_VFIELD (type))
12686 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
12688 gen_type_die (vtype, context_die);
12689 add_AT_die_ref (type_die, DW_AT_containing_type,
12690 lookup_type_die (vtype));
12695 add_AT_flag (type_die, DW_AT_declaration, 1);
12697 /* We don't need to do this for function-local types. */
12698 if (TYPE_STUB_DECL (type)
12699 && ! decl_function_context (TYPE_STUB_DECL (type)))
12700 VEC_safe_push (tree, gc, incomplete_types, type);
12703 if (get_AT (type_die, DW_AT_name))
12704 add_pubtype (type, type_die);
12707 /* Generate a DIE for a subroutine _type_. */
12710 gen_subroutine_type_die (tree type, dw_die_ref context_die)
12712 tree return_type = TREE_TYPE (type);
12713 dw_die_ref subr_die
12714 = new_die (DW_TAG_subroutine_type,
12715 scope_die_for (type, context_die), type);
12717 equate_type_number_to_die (type, subr_die);
12718 add_prototyped_attribute (subr_die, type);
12719 add_type_attribute (subr_die, return_type, 0, 0, context_die);
12720 gen_formal_types_die (type, subr_die);
12722 if (get_AT (subr_die, DW_AT_name))
12723 add_pubtype (type, subr_die);
12726 /* Generate a DIE for a type definition. */
12729 gen_typedef_die (tree decl, dw_die_ref context_die)
12731 dw_die_ref type_die;
12734 if (TREE_ASM_WRITTEN (decl))
12737 TREE_ASM_WRITTEN (decl) = 1;
12738 type_die = new_die (DW_TAG_typedef, context_die, decl);
12739 origin = decl_ultimate_origin (decl);
12740 if (origin != NULL)
12741 add_abstract_origin_attribute (type_die, origin);
12746 add_name_and_src_coords_attributes (type_die, decl);
12747 if (DECL_ORIGINAL_TYPE (decl))
12749 type = DECL_ORIGINAL_TYPE (decl);
12751 gcc_assert (type != TREE_TYPE (decl));
12752 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12755 type = TREE_TYPE (decl);
12757 add_type_attribute (type_die, type, TREE_READONLY (decl),
12758 TREE_THIS_VOLATILE (decl), context_die);
12761 if (DECL_ABSTRACT (decl))
12762 equate_decl_number_to_die (decl, type_die);
12764 if (get_AT (type_die, DW_AT_name))
12765 add_pubtype (decl, type_die);
12768 /* Generate a type description DIE. */
12771 gen_type_die_with_usage (tree type, dw_die_ref context_die,
12772 enum debug_info_usage usage)
12776 if (type == NULL_TREE || type == error_mark_node)
12779 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12780 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12782 if (TREE_ASM_WRITTEN (type))
12785 /* Prevent broken recursion; we can't hand off to the same type. */
12786 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12788 TREE_ASM_WRITTEN (type) = 1;
12789 gen_decl_die (TYPE_NAME (type), context_die);
12793 /* We are going to output a DIE to represent the unqualified version
12794 of this type (i.e. without any const or volatile qualifiers) so
12795 get the main variant (i.e. the unqualified version) of this type
12796 now. (Vectors are special because the debugging info is in the
12797 cloned type itself). */
12798 if (TREE_CODE (type) != VECTOR_TYPE)
12799 type = type_main_variant (type);
12801 if (TREE_ASM_WRITTEN (type))
12804 switch (TREE_CODE (type))
12810 case REFERENCE_TYPE:
12811 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12812 ensures that the gen_type_die recursion will terminate even if the
12813 type is recursive. Recursive types are possible in Ada. */
12814 /* ??? We could perhaps do this for all types before the switch
12816 TREE_ASM_WRITTEN (type) = 1;
12818 /* For these types, all that is required is that we output a DIE (or a
12819 set of DIEs) to represent the "basis" type. */
12820 gen_type_die_with_usage (TREE_TYPE (type), context_die,
12821 DINFO_USAGE_IND_USE);
12825 /* This code is used for C++ pointer-to-data-member types.
12826 Output a description of the relevant class type. */
12827 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
12828 DINFO_USAGE_IND_USE);
12830 /* Output a description of the type of the object pointed to. */
12831 gen_type_die_with_usage (TREE_TYPE (type), context_die,
12832 DINFO_USAGE_IND_USE);
12834 /* Now output a DIE to represent this pointer-to-data-member type
12836 gen_ptr_to_mbr_type_die (type, context_die);
12839 case FUNCTION_TYPE:
12840 /* Force out return type (in case it wasn't forced out already). */
12841 gen_type_die_with_usage (TREE_TYPE (type), context_die,
12842 DINFO_USAGE_DIR_USE);
12843 gen_subroutine_type_die (type, context_die);
12847 /* Force out return type (in case it wasn't forced out already). */
12848 gen_type_die_with_usage (TREE_TYPE (type), context_die,
12849 DINFO_USAGE_DIR_USE);
12850 gen_subroutine_type_die (type, context_die);
12854 gen_array_type_die (type, context_die);
12858 gen_array_type_die (type, context_die);
12861 case ENUMERAL_TYPE:
12864 case QUAL_UNION_TYPE:
12865 /* If this is a nested type whose containing class hasn't been written
12866 out yet, writing it out will cover this one, too. This does not apply
12867 to instantiations of member class templates; they need to be added to
12868 the containing class as they are generated. FIXME: This hurts the
12869 idea of combining type decls from multiple TUs, since we can't predict
12870 what set of template instantiations we'll get. */
12871 if (TYPE_CONTEXT (type)
12872 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12873 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12875 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
12877 if (TREE_ASM_WRITTEN (type))
12880 /* If that failed, attach ourselves to the stub. */
12881 push_decl_scope (TYPE_CONTEXT (type));
12882 context_die = lookup_type_die (TYPE_CONTEXT (type));
12887 declare_in_namespace (type, context_die);
12891 if (TREE_CODE (type) == ENUMERAL_TYPE)
12893 /* This might have been written out by the call to
12894 declare_in_namespace. */
12895 if (!TREE_ASM_WRITTEN (type))
12896 gen_enumeration_type_die (type, context_die);
12899 gen_struct_or_union_type_die (type, context_die, usage);
12904 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12905 it up if it is ever completed. gen_*_type_die will set it for us
12906 when appropriate. */
12914 /* No DIEs needed for fundamental types. */
12918 /* No Dwarf representation currently defined. */
12922 gcc_unreachable ();
12925 TREE_ASM_WRITTEN (type) = 1;
12929 gen_type_die (tree type, dw_die_ref context_die)
12931 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
12934 /* Generate a DIE for a tagged type instantiation. */
12937 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12939 if (type == NULL_TREE || type == error_mark_node)
12942 /* We are going to output a DIE to represent the unqualified version of
12943 this type (i.e. without any const or volatile qualifiers) so make sure
12944 that we have the main variant (i.e. the unqualified version) of this
12946 gcc_assert (type == type_main_variant (type));
12948 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12949 an instance of an unresolved type. */
12951 switch (TREE_CODE (type))
12956 case ENUMERAL_TYPE:
12957 gen_inlined_enumeration_type_die (type, context_die);
12961 gen_inlined_structure_type_die (type, context_die);
12965 case QUAL_UNION_TYPE:
12966 gen_inlined_union_type_die (type, context_die);
12970 gcc_unreachable ();
12974 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12975 things which are local to the given block. */
12978 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12980 int must_output_die = 0;
12983 enum tree_code origin_code;
12985 /* Ignore blocks that are NULL. */
12986 if (stmt == NULL_TREE)
12989 /* If the block is one fragment of a non-contiguous block, do not
12990 process the variables, since they will have been done by the
12991 origin block. Do process subblocks. */
12992 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12996 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12997 gen_block_die (sub, context_die, depth + 1);
13002 /* Determine the "ultimate origin" of this block. This block may be an
13003 inlined instance of an inlined instance of inline function, so we have
13004 to trace all of the way back through the origin chain to find out what
13005 sort of node actually served as the original seed for the creation of
13006 the current block. */
13007 origin = block_ultimate_origin (stmt);
13008 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13010 /* Determine if we need to output any Dwarf DIEs at all to represent this
13012 if (origin_code == FUNCTION_DECL)
13013 /* The outer scopes for inlinings *must* always be represented. We
13014 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13015 must_output_die = 1;
13018 /* In the case where the current block represents an inlining of the
13019 "body block" of an inline function, we must *NOT* output any DIE for
13020 this block because we have already output a DIE to represent the whole
13021 inlined function scope and the "body block" of any function doesn't
13022 really represent a different scope according to ANSI C rules. So we
13023 check here to make sure that this block does not represent a "body
13024 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13025 if (! is_body_block (origin ? origin : stmt))
13027 /* Determine if this block directly contains any "significant"
13028 local declarations which we will need to output DIEs for. */
13029 if (debug_info_level > DINFO_LEVEL_TERSE)
13030 /* We are not in terse mode so *any* local declaration counts
13031 as being a "significant" one. */
13032 must_output_die = (BLOCK_VARS (stmt) != NULL
13033 && (TREE_USED (stmt)
13034 || TREE_ASM_WRITTEN (stmt)
13035 || BLOCK_ABSTRACT (stmt)));
13037 /* We are in terse mode, so only local (nested) function
13038 definitions count as "significant" local declarations. */
13039 for (decl = BLOCK_VARS (stmt);
13040 decl != NULL; decl = TREE_CHAIN (decl))
13041 if (TREE_CODE (decl) == FUNCTION_DECL
13042 && DECL_INITIAL (decl))
13044 must_output_die = 1;
13050 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13051 DIE for any block which contains no significant local declarations at
13052 all. Rather, in such cases we just call `decls_for_scope' so that any
13053 needed Dwarf info for any sub-blocks will get properly generated. Note
13054 that in terse mode, our definition of what constitutes a "significant"
13055 local declaration gets restricted to include only inlined function
13056 instances and local (nested) function definitions. */
13057 if (must_output_die)
13059 if (origin_code == FUNCTION_DECL)
13060 gen_inlined_subroutine_die (stmt, context_die, depth);
13062 gen_lexical_block_die (stmt, context_die, depth);
13065 decls_for_scope (stmt, context_die, depth);
13068 /* Generate all of the decls declared within a given scope and (recursively)
13069 all of its sub-blocks. */
13072 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13077 /* Ignore NULL blocks. */
13078 if (stmt == NULL_TREE)
13081 if (TREE_USED (stmt))
13083 /* Output the DIEs to represent all of the data objects and typedefs
13084 declared directly within this block but not within any nested
13085 sub-blocks. Also, nested function and tag DIEs have been
13086 generated with a parent of NULL; fix that up now. */
13087 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13091 if (TREE_CODE (decl) == FUNCTION_DECL)
13092 die = lookup_decl_die (decl);
13093 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13094 die = lookup_type_die (TREE_TYPE (decl));
13098 if (die != NULL && die->die_parent == NULL)
13099 add_child_die (context_die, die);
13100 /* Do not produce debug information for static variables since
13101 these might be optimized out. We are called for these later
13102 in varpool_analyze_pending_decls. */
13103 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
13106 gen_decl_die (decl, context_die);
13110 /* If we're at -g1, we're not interested in subblocks. */
13111 if (debug_info_level <= DINFO_LEVEL_TERSE)
13114 /* Output the DIEs to represent all sub-blocks (and the items declared
13115 therein) of this block. */
13116 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13118 subblocks = BLOCK_CHAIN (subblocks))
13119 gen_block_die (subblocks, context_die, depth + 1);
13122 /* Is this a typedef we can avoid emitting? */
13125 is_redundant_typedef (tree decl)
13127 if (TYPE_DECL_IS_STUB (decl))
13130 if (DECL_ARTIFICIAL (decl)
13131 && DECL_CONTEXT (decl)
13132 && is_tagged_type (DECL_CONTEXT (decl))
13133 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13134 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13135 /* Also ignore the artificial member typedef for the class name. */
13141 /* Returns the DIE for decl. A DIE will always be returned. */
13144 force_decl_die (tree decl)
13146 dw_die_ref decl_die;
13147 unsigned saved_external_flag;
13148 tree save_fn = NULL_TREE;
13149 decl_die = lookup_decl_die (decl);
13152 dw_die_ref context_die;
13153 tree decl_context = DECL_CONTEXT (decl);
13156 /* Find die that represents this context. */
13157 if (TYPE_P (decl_context))
13158 context_die = force_type_die (decl_context);
13160 context_die = force_decl_die (decl_context);
13163 context_die = comp_unit_die;
13165 decl_die = lookup_decl_die (decl);
13169 switch (TREE_CODE (decl))
13171 case FUNCTION_DECL:
13172 /* Clear current_function_decl, so that gen_subprogram_die thinks
13173 that this is a declaration. At this point, we just want to force
13174 declaration die. */
13175 save_fn = current_function_decl;
13176 current_function_decl = NULL_TREE;
13177 gen_subprogram_die (decl, context_die);
13178 current_function_decl = save_fn;
13182 /* Set external flag to force declaration die. Restore it after
13183 gen_decl_die() call. */
13184 saved_external_flag = DECL_EXTERNAL (decl);
13185 DECL_EXTERNAL (decl) = 1;
13186 gen_decl_die (decl, context_die);
13187 DECL_EXTERNAL (decl) = saved_external_flag;
13190 case NAMESPACE_DECL:
13191 dwarf2out_decl (decl);
13195 gcc_unreachable ();
13198 /* We should be able to find the DIE now. */
13200 decl_die = lookup_decl_die (decl);
13201 gcc_assert (decl_die);
13207 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13208 always returned. */
13211 force_type_die (tree type)
13213 dw_die_ref type_die;
13215 type_die = lookup_type_die (type);
13218 dw_die_ref context_die;
13219 if (TYPE_CONTEXT (type))
13221 if (TYPE_P (TYPE_CONTEXT (type)))
13222 context_die = force_type_die (TYPE_CONTEXT (type));
13224 context_die = force_decl_die (TYPE_CONTEXT (type));
13227 context_die = comp_unit_die;
13229 type_die = lookup_type_die (type);
13232 gen_type_die (type, context_die);
13233 type_die = lookup_type_die (type);
13234 gcc_assert (type_die);
13239 /* Force out any required namespaces to be able to output DECL,
13240 and return the new context_die for it, if it's changed. */
13243 setup_namespace_context (tree thing, dw_die_ref context_die)
13245 tree context = (DECL_P (thing)
13246 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13247 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13248 /* Force out the namespace. */
13249 context_die = force_decl_die (context);
13251 return context_die;
13254 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13255 type) within its namespace, if appropriate.
13257 For compatibility with older debuggers, namespace DIEs only contain
13258 declarations; all definitions are emitted at CU scope. */
13261 declare_in_namespace (tree thing, dw_die_ref context_die)
13263 dw_die_ref ns_context;
13265 if (debug_info_level <= DINFO_LEVEL_TERSE)
13268 /* If this decl is from an inlined function, then don't try to emit it in its
13269 namespace, as we will get confused. It would have already been emitted
13270 when the abstract instance of the inline function was emitted anyways. */
13271 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13274 ns_context = setup_namespace_context (thing, context_die);
13276 if (ns_context != context_die)
13278 if (DECL_P (thing))
13279 gen_decl_die (thing, ns_context);
13281 gen_type_die (thing, ns_context);
13285 /* Generate a DIE for a namespace or namespace alias. */
13288 gen_namespace_die (tree decl)
13290 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13292 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13293 they are an alias of. */
13294 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13296 /* Output a real namespace. */
13297 dw_die_ref namespace_die
13298 = new_die (DW_TAG_namespace, context_die, decl);
13299 add_name_and_src_coords_attributes (namespace_die, decl);
13300 equate_decl_number_to_die (decl, namespace_die);
13304 /* Output a namespace alias. */
13306 /* Force out the namespace we are an alias of, if necessary. */
13307 dw_die_ref origin_die
13308 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13310 /* Now create the namespace alias DIE. */
13311 dw_die_ref namespace_die
13312 = new_die (DW_TAG_imported_declaration, context_die, decl);
13313 add_name_and_src_coords_attributes (namespace_die, decl);
13314 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13315 equate_decl_number_to_die (decl, namespace_die);
13319 /* Generate Dwarf debug information for a decl described by DECL. */
13322 gen_decl_die (tree decl, dw_die_ref context_die)
13326 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13329 switch (TREE_CODE (decl))
13335 /* The individual enumerators of an enum type get output when we output
13336 the Dwarf representation of the relevant enum type itself. */
13339 case FUNCTION_DECL:
13340 /* Don't output any DIEs to represent mere function declarations,
13341 unless they are class members or explicit block externs. */
13342 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13343 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13348 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13349 on local redeclarations of global functions. That seems broken. */
13350 if (current_function_decl != decl)
13351 /* This is only a declaration. */;
13354 /* If we're emitting a clone, emit info for the abstract instance. */
13355 if (DECL_ORIGIN (decl) != decl)
13356 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13358 /* If we're emitting an out-of-line copy of an inline function,
13359 emit info for the abstract instance and set up to refer to it. */
13360 else if (cgraph_function_possibly_inlined_p (decl)
13361 && ! DECL_ABSTRACT (decl)
13362 && ! class_or_namespace_scope_p (context_die)
13363 /* dwarf2out_abstract_function won't emit a die if this is just
13364 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13365 that case, because that works only if we have a die. */
13366 && DECL_INITIAL (decl) != NULL_TREE)
13368 dwarf2out_abstract_function (decl);
13369 set_decl_origin_self (decl);
13372 /* Otherwise we're emitting the primary DIE for this decl. */
13373 else if (debug_info_level > DINFO_LEVEL_TERSE)
13375 /* Before we describe the FUNCTION_DECL itself, make sure that we
13376 have described its return type. */
13377 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13379 /* And its virtual context. */
13380 if (DECL_VINDEX (decl) != NULL_TREE)
13381 gen_type_die (DECL_CONTEXT (decl), context_die);
13383 /* And its containing type. */
13384 origin = decl_class_context (decl);
13385 if (origin != NULL_TREE)
13386 gen_type_die_for_member (origin, decl, context_die);
13388 /* And its containing namespace. */
13389 declare_in_namespace (decl, context_die);
13392 /* Now output a DIE to represent the function itself. */
13393 gen_subprogram_die (decl, context_die);
13397 /* If we are in terse mode, don't generate any DIEs to represent any
13398 actual typedefs. */
13399 if (debug_info_level <= DINFO_LEVEL_TERSE)
13402 /* In the special case of a TYPE_DECL node representing the declaration
13403 of some type tag, if the given TYPE_DECL is marked as having been
13404 instantiated from some other (original) TYPE_DECL node (e.g. one which
13405 was generated within the original definition of an inline function) we
13406 have to generate a special (abbreviated) DW_TAG_structure_type,
13407 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13408 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
13410 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13414 if (is_redundant_typedef (decl))
13415 gen_type_die (TREE_TYPE (decl), context_die);
13417 /* Output a DIE to represent the typedef itself. */
13418 gen_typedef_die (decl, context_die);
13422 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13423 gen_label_die (decl, context_die);
13428 /* If we are in terse mode, don't generate any DIEs to represent any
13429 variable declarations or definitions. */
13430 if (debug_info_level <= DINFO_LEVEL_TERSE)
13433 /* Output any DIEs that are needed to specify the type of this data
13435 gen_type_die (TREE_TYPE (decl), context_die);
13437 /* And its containing type. */
13438 origin = decl_class_context (decl);
13439 if (origin != NULL_TREE)
13440 gen_type_die_for_member (origin, decl, context_die);
13442 /* And its containing namespace. */
13443 declare_in_namespace (decl, context_die);
13445 /* Now output the DIE to represent the data object itself. This gets
13446 complicated because of the possibility that the VAR_DECL really
13447 represents an inlined instance of a formal parameter for an inline
13449 origin = decl_ultimate_origin (decl);
13450 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13451 gen_formal_parameter_die (decl, context_die);
13453 gen_variable_die (decl, context_die);
13457 /* Ignore the nameless fields that are used to skip bits but handle C++
13458 anonymous unions and structs. */
13459 if (DECL_NAME (decl) != NULL_TREE
13460 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13461 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13463 gen_type_die (member_declared_type (decl), context_die);
13464 gen_field_die (decl, context_die);
13469 gen_type_die (TREE_TYPE (decl), context_die);
13470 gen_formal_parameter_die (decl, context_die);
13473 case NAMESPACE_DECL:
13474 gen_namespace_die (decl);
13478 /* Probably some frontend-internal decl. Assume we don't care. */
13479 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13484 /* Output debug information for global decl DECL. Called from toplev.c after
13485 compilation proper has finished. */
13488 dwarf2out_global_decl (tree decl)
13490 /* Output DWARF2 information for file-scope tentative data object
13491 declarations, file-scope (extern) function declarations (which had no
13492 corresponding body) and file-scope tagged type declarations and
13493 definitions which have not yet been forced out. */
13494 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
13495 dwarf2out_decl (decl);
13498 /* Output debug information for type decl DECL. Called from toplev.c
13499 and from language front ends (to record built-in types). */
13501 dwarf2out_type_decl (tree decl, int local)
13504 dwarf2out_decl (decl);
13507 /* Output debug information for imported module or decl. */
13510 dwarf2out_imported_module_or_decl (tree decl, tree context)
13512 dw_die_ref imported_die, at_import_die;
13513 dw_die_ref scope_die;
13514 expanded_location xloc;
13516 if (debug_info_level <= DINFO_LEVEL_TERSE)
13521 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13522 We need decl DIE for reference and scope die. First, get DIE for the decl
13525 /* Get the scope die for decl context. Use comp_unit_die for global module
13526 or decl. If die is not found for non globals, force new die. */
13528 scope_die = comp_unit_die;
13529 else if (TYPE_P (context))
13531 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
13533 scope_die = force_type_die (context);
13536 scope_die = force_decl_die (context);
13538 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13539 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
13541 if (is_base_type (TREE_TYPE (decl)))
13542 at_import_die = base_type_die (TREE_TYPE (decl));
13544 at_import_die = force_type_die (TREE_TYPE (decl));
13548 at_import_die = lookup_decl_die (decl);
13549 if (!at_import_die)
13551 /* If we're trying to avoid duplicate debug info, we may not have
13552 emitted the member decl for this field. Emit it now. */
13553 if (TREE_CODE (decl) == FIELD_DECL)
13555 tree type = DECL_CONTEXT (decl);
13556 dw_die_ref type_context_die;
13558 if (TYPE_CONTEXT (type))
13559 if (TYPE_P (TYPE_CONTEXT (type)))
13561 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
13562 DINFO_USAGE_DIR_USE))
13564 type_context_die = force_type_die (TYPE_CONTEXT (type));
13567 type_context_die = force_decl_die (TYPE_CONTEXT (type));
13569 type_context_die = comp_unit_die;
13570 gen_type_die_for_member (type, decl, type_context_die);
13572 at_import_die = force_decl_die (decl);
13576 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13577 if (TREE_CODE (decl) == NAMESPACE_DECL)
13578 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
13580 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
13582 xloc = expand_location (input_location);
13583 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
13584 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
13585 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
13588 /* Write the debugging output for DECL. */
13591 dwarf2out_decl (tree decl)
13593 dw_die_ref context_die = comp_unit_die;
13595 switch (TREE_CODE (decl))
13600 case FUNCTION_DECL:
13601 /* What we would really like to do here is to filter out all mere
13602 file-scope declarations of file-scope functions which are never
13603 referenced later within this translation unit (and keep all of ones
13604 that *are* referenced later on) but we aren't clairvoyant, so we have
13605 no idea which functions will be referenced in the future (i.e. later
13606 on within the current translation unit). So here we just ignore all
13607 file-scope function declarations which are not also definitions. If
13608 and when the debugger needs to know something about these functions,
13609 it will have to hunt around and find the DWARF information associated
13610 with the definition of the function.
13612 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13613 nodes represent definitions and which ones represent mere
13614 declarations. We have to check DECL_INITIAL instead. That's because
13615 the C front-end supports some weird semantics for "extern inline"
13616 function definitions. These can get inlined within the current
13617 translation unit (and thus, we need to generate Dwarf info for their
13618 abstract instances so that the Dwarf info for the concrete inlined
13619 instances can have something to refer to) but the compiler never
13620 generates any out-of-lines instances of such things (despite the fact
13621 that they *are* definitions).
13623 The important point is that the C front-end marks these "extern
13624 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13625 them anyway. Note that the C++ front-end also plays some similar games
13626 for inline function definitions appearing within include files which
13627 also contain `#pragma interface' pragmas. */
13628 if (DECL_INITIAL (decl) == NULL_TREE)
13631 /* If we're a nested function, initially use a parent of NULL; if we're
13632 a plain function, this will be fixed up in decls_for_scope. If
13633 we're a method, it will be ignored, since we already have a DIE. */
13634 if (decl_function_context (decl)
13635 /* But if we're in terse mode, we don't care about scope. */
13636 && debug_info_level > DINFO_LEVEL_TERSE)
13637 context_die = NULL;
13641 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13642 declaration and if the declaration was never even referenced from
13643 within this entire compilation unit. We suppress these DIEs in
13644 order to save space in the .debug section (by eliminating entries
13645 which are probably useless). Note that we must not suppress
13646 block-local extern declarations (whether used or not) because that
13647 would screw-up the debugger's name lookup mechanism and cause it to
13648 miss things which really ought to be in scope at a given point. */
13649 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
13652 /* For local statics lookup proper context die. */
13653 if (TREE_STATIC (decl) && decl_function_context (decl))
13654 context_die = lookup_decl_die (DECL_CONTEXT (decl));
13656 /* If we are in terse mode, don't generate any DIEs to represent any
13657 variable declarations or definitions. */
13658 if (debug_info_level <= DINFO_LEVEL_TERSE)
13662 case NAMESPACE_DECL:
13663 if (debug_info_level <= DINFO_LEVEL_TERSE)
13665 if (lookup_decl_die (decl) != NULL)
13670 /* Don't emit stubs for types unless they are needed by other DIEs. */
13671 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
13674 /* Don't bother trying to generate any DIEs to represent any of the
13675 normal built-in types for the language we are compiling. */
13676 if (DECL_IS_BUILTIN (decl))
13678 /* OK, we need to generate one for `bool' so GDB knows what type
13679 comparisons have. */
13681 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
13682 && ! DECL_IGNORED_P (decl))
13683 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
13688 /* If we are in terse mode, don't generate any DIEs for types. */
13689 if (debug_info_level <= DINFO_LEVEL_TERSE)
13692 /* If we're a function-scope tag, initially use a parent of NULL;
13693 this will be fixed up in decls_for_scope. */
13694 if (decl_function_context (decl))
13695 context_die = NULL;
13703 gen_decl_die (decl, context_die);
13706 /* Output a marker (i.e. a label) for the beginning of the generated code for
13707 a lexical block. */
13710 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
13711 unsigned int blocknum)
13713 switch_to_section (current_function_section ());
13714 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
13717 /* Output a marker (i.e. a label) for the end of the generated code for a
13721 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
13723 switch_to_section (current_function_section ());
13724 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
13727 /* Returns nonzero if it is appropriate not to emit any debugging
13728 information for BLOCK, because it doesn't contain any instructions.
13730 Don't allow this for blocks with nested functions or local classes
13731 as we would end up with orphans, and in the presence of scheduling
13732 we may end up calling them anyway. */
13735 dwarf2out_ignore_block (tree block)
13739 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
13740 if (TREE_CODE (decl) == FUNCTION_DECL
13741 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
13747 /* Hash table routines for file_hash. */
13750 file_table_eq (const void *p1_p, const void *p2_p)
13752 const struct dwarf_file_data * p1 = p1_p;
13753 const char * p2 = p2_p;
13754 return strcmp (p1->filename, p2) == 0;
13758 file_table_hash (const void *p_p)
13760 const struct dwarf_file_data * p = p_p;
13761 return htab_hash_string (p->filename);
13764 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13765 dwarf2out.c) and return its "index". The index of each (known) filename is
13766 just a unique number which is associated with only that one filename. We
13767 need such numbers for the sake of generating labels (in the .debug_sfnames
13768 section) and references to those files numbers (in the .debug_srcinfo
13769 and.debug_macinfo sections). If the filename given as an argument is not
13770 found in our current list, add it to the list and assign it the next
13771 available unique index number. In order to speed up searches, we remember
13772 the index of the filename was looked up last. This handles the majority of
13775 static struct dwarf_file_data *
13776 lookup_filename (const char *file_name)
13779 struct dwarf_file_data * created;
13781 /* Check to see if the file name that was searched on the previous
13782 call matches this file name. If so, return the index. */
13783 if (file_table_last_lookup
13784 && (file_name == file_table_last_lookup->filename
13785 || strcmp (file_table_last_lookup->filename, file_name) == 0))
13786 return file_table_last_lookup;
13788 /* Didn't match the previous lookup, search the table. */
13789 slot = htab_find_slot_with_hash (file_table, file_name,
13790 htab_hash_string (file_name), INSERT);
13794 created = ggc_alloc (sizeof (struct dwarf_file_data));
13795 created->filename = file_name;
13796 created->emitted_number = 0;
13801 /* If the assembler will construct the file table, then translate the compiler
13802 internal file table number into the assembler file table number, and emit
13803 a .file directive if we haven't already emitted one yet. The file table
13804 numbers are different because we prune debug info for unused variables and
13805 types, which may include filenames. */
13808 maybe_emit_file (struct dwarf_file_data * fd)
13810 if (! fd->emitted_number)
13812 if (last_emitted_file)
13813 fd->emitted_number = last_emitted_file->emitted_number + 1;
13815 fd->emitted_number = 1;
13816 last_emitted_file = fd;
13818 if (DWARF2_ASM_LINE_DEBUG_INFO)
13820 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
13821 output_quoted_string (asm_out_file, fd->filename);
13822 fputc ('\n', asm_out_file);
13826 return fd->emitted_number;
13829 /* Called by the final INSN scan whenever we see a var location. We
13830 use it to drop labels in the right places, and throw the location in
13831 our lookup table. */
13834 dwarf2out_var_location (rtx loc_note)
13836 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13837 struct var_loc_node *newloc;
13839 static rtx last_insn;
13840 static const char *last_label;
13843 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13845 prev_insn = PREV_INSN (loc_note);
13847 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13848 /* If the insn we processed last time is the previous insn
13849 and it is also a var location note, use the label we emitted
13851 if (last_insn != NULL_RTX
13852 && last_insn == prev_insn
13853 && NOTE_P (prev_insn)
13854 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
13856 newloc->label = last_label;
13860 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13861 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13863 newloc->label = ggc_strdup (loclabel);
13865 newloc->var_loc_note = loc_note;
13866 newloc->next = NULL;
13868 if (cfun && in_cold_section_p)
13869 newloc->section_label = cfun->cold_section_label;
13871 newloc->section_label = text_section_label;
13873 last_insn = loc_note;
13874 last_label = newloc->label;
13875 decl = NOTE_VAR_LOCATION_DECL (loc_note);
13876 add_var_loc_to_decl (decl, newloc);
13879 /* We need to reset the locations at the beginning of each
13880 function. We can't do this in the end_function hook, because the
13881 declarations that use the locations won't have been output when
13882 that hook is called. Also compute have_multiple_function_sections here. */
13885 dwarf2out_begin_function (tree fun)
13887 htab_empty (decl_loc_table);
13889 if (function_section (fun) != text_section)
13890 have_multiple_function_sections = true;
13893 /* Output a label to mark the beginning of a source code line entry
13894 and record information relating to this source line, in
13895 'line_info_table' for later output of the .debug_line section. */
13898 dwarf2out_source_line (unsigned int line, const char *filename)
13900 if (debug_info_level >= DINFO_LEVEL_NORMAL
13903 int file_num = maybe_emit_file (lookup_filename (filename));
13905 switch_to_section (current_function_section ());
13907 /* If requested, emit something human-readable. */
13908 if (flag_debug_asm)
13909 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13912 if (DWARF2_ASM_LINE_DEBUG_INFO)
13914 /* Emit the .loc directive understood by GNU as. */
13915 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13917 /* Indicate that line number info exists. */
13918 line_info_table_in_use++;
13920 else if (function_section (current_function_decl) != text_section)
13922 dw_separate_line_info_ref line_info;
13923 targetm.asm_out.internal_label (asm_out_file,
13924 SEPARATE_LINE_CODE_LABEL,
13925 separate_line_info_table_in_use);
13927 /* Expand the line info table if necessary. */
13928 if (separate_line_info_table_in_use
13929 == separate_line_info_table_allocated)
13931 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13932 separate_line_info_table
13933 = ggc_realloc (separate_line_info_table,
13934 separate_line_info_table_allocated
13935 * sizeof (dw_separate_line_info_entry));
13936 memset (separate_line_info_table
13937 + separate_line_info_table_in_use,
13939 (LINE_INFO_TABLE_INCREMENT
13940 * sizeof (dw_separate_line_info_entry)));
13943 /* Add the new entry at the end of the line_info_table. */
13945 = &separate_line_info_table[separate_line_info_table_in_use++];
13946 line_info->dw_file_num = file_num;
13947 line_info->dw_line_num = line;
13948 line_info->function = current_function_funcdef_no;
13952 dw_line_info_ref line_info;
13954 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13955 line_info_table_in_use);
13957 /* Expand the line info table if necessary. */
13958 if (line_info_table_in_use == line_info_table_allocated)
13960 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13962 = ggc_realloc (line_info_table,
13963 (line_info_table_allocated
13964 * sizeof (dw_line_info_entry)));
13965 memset (line_info_table + line_info_table_in_use, 0,
13966 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13969 /* Add the new entry at the end of the line_info_table. */
13970 line_info = &line_info_table[line_info_table_in_use++];
13971 line_info->dw_file_num = file_num;
13972 line_info->dw_line_num = line;
13977 /* Record the beginning of a new source file. */
13980 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13982 if (flag_eliminate_dwarf2_dups)
13984 /* Record the beginning of the file for break_out_includes. */
13985 dw_die_ref bincl_die;
13987 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13988 add_AT_string (bincl_die, DW_AT_name, filename);
13991 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13993 int file_num = maybe_emit_file (lookup_filename (filename));
13995 switch_to_section (debug_macinfo_section);
13996 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13997 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14000 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14004 /* Record the end of a source file. */
14007 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14009 if (flag_eliminate_dwarf2_dups)
14010 /* Record the end of the file for break_out_includes. */
14011 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14013 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14015 switch_to_section (debug_macinfo_section);
14016 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14020 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14021 the tail part of the directive line, i.e. the part which is past the
14022 initial whitespace, #, whitespace, directive-name, whitespace part. */
14025 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14026 const char *buffer ATTRIBUTE_UNUSED)
14028 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14030 switch_to_section (debug_macinfo_section);
14031 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14032 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14033 dw2_asm_output_nstring (buffer, -1, "The macro");
14037 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14038 the tail part of the directive line, i.e. the part which is past the
14039 initial whitespace, #, whitespace, directive-name, whitespace part. */
14042 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14043 const char *buffer ATTRIBUTE_UNUSED)
14045 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14047 switch_to_section (debug_macinfo_section);
14048 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14049 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14050 dw2_asm_output_nstring (buffer, -1, "The macro");
14054 /* Set up for Dwarf output at the start of compilation. */
14057 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14059 /* Allocate the file_table. */
14060 file_table = htab_create_ggc (50, file_table_hash,
14061 file_table_eq, NULL);
14063 /* Allocate the decl_die_table. */
14064 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14065 decl_die_table_eq, NULL);
14067 /* Allocate the decl_loc_table. */
14068 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14069 decl_loc_table_eq, NULL);
14071 /* Allocate the initial hunk of the decl_scope_table. */
14072 decl_scope_table = VEC_alloc (tree, gc, 256);
14074 /* Allocate the initial hunk of the abbrev_die_table. */
14075 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
14076 * sizeof (dw_die_ref));
14077 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14078 /* Zero-th entry is allocated, but unused. */
14079 abbrev_die_table_in_use = 1;
14081 /* Allocate the initial hunk of the line_info_table. */
14082 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
14083 * sizeof (dw_line_info_entry));
14084 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14086 /* Zero-th entry is allocated, but unused. */
14087 line_info_table_in_use = 1;
14089 /* Allocate the pubtypes and pubnames vectors. */
14090 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14091 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14093 /* Generate the initial DIE for the .debug section. Note that the (string)
14094 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14095 will (typically) be a relative pathname and that this pathname should be
14096 taken as being relative to the directory from which the compiler was
14097 invoked when the given (base) source file was compiled. We will fill
14098 in this value in dwarf2out_finish. */
14099 comp_unit_die = gen_compile_unit_die (NULL);
14101 incomplete_types = VEC_alloc (tree, gc, 64);
14103 used_rtx_array = VEC_alloc (rtx, gc, 32);
14105 debug_info_section = get_section (DEBUG_INFO_SECTION,
14106 SECTION_DEBUG, NULL);
14107 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14108 SECTION_DEBUG, NULL);
14109 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14110 SECTION_DEBUG, NULL);
14111 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14112 SECTION_DEBUG, NULL);
14113 debug_line_section = get_section (DEBUG_LINE_SECTION,
14114 SECTION_DEBUG, NULL);
14115 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14116 SECTION_DEBUG, NULL);
14117 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14118 SECTION_DEBUG, NULL);
14119 #ifdef DEBUG_PUBTYPES_SECTION
14120 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14121 SECTION_DEBUG, NULL);
14123 debug_str_section = get_section (DEBUG_STR_SECTION,
14124 DEBUG_STR_SECTION_FLAGS, NULL);
14125 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14126 SECTION_DEBUG, NULL);
14127 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14128 SECTION_DEBUG, NULL);
14130 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14131 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14132 DEBUG_ABBREV_SECTION_LABEL, 0);
14133 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14134 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14135 COLD_TEXT_SECTION_LABEL, 0);
14136 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14138 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14139 DEBUG_INFO_SECTION_LABEL, 0);
14140 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14141 DEBUG_LINE_SECTION_LABEL, 0);
14142 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14143 DEBUG_RANGES_SECTION_LABEL, 0);
14144 switch_to_section (debug_abbrev_section);
14145 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14146 switch_to_section (debug_info_section);
14147 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14148 switch_to_section (debug_line_section);
14149 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14151 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14153 switch_to_section (debug_macinfo_section);
14154 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14155 DEBUG_MACINFO_SECTION_LABEL, 0);
14156 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14159 switch_to_section (text_section);
14160 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14161 if (flag_reorder_blocks_and_partition)
14163 switch_to_section (unlikely_text_section ());
14164 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14168 /* A helper function for dwarf2out_finish called through
14169 ht_forall. Emit one queued .debug_str string. */
14172 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14174 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14176 if (node->form == DW_FORM_strp)
14178 switch_to_section (debug_str_section);
14179 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14180 assemble_string (node->str, strlen (node->str) + 1);
14186 #if ENABLE_ASSERT_CHECKING
14187 /* Verify that all marks are clear. */
14190 verify_marks_clear (dw_die_ref die)
14194 gcc_assert (! die->die_mark);
14195 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14197 #endif /* ENABLE_ASSERT_CHECKING */
14199 /* Clear the marks for a die and its children.
14200 Be cool if the mark isn't set. */
14203 prune_unmark_dies (dw_die_ref die)
14209 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14212 /* Given DIE that we're marking as used, find any other dies
14213 it references as attributes and mark them as used. */
14216 prune_unused_types_walk_attribs (dw_die_ref die)
14221 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14223 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14225 /* A reference to another DIE.
14226 Make sure that it will get emitted. */
14227 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14229 /* Set the string's refcount to 0 so that prune_unused_types_mark
14230 accounts properly for it. */
14231 if (AT_class (a) == dw_val_class_str)
14232 a->dw_attr_val.v.val_str->refcount = 0;
14237 /* Mark DIE as being used. If DOKIDS is true, then walk down
14238 to DIE's children. */
14241 prune_unused_types_mark (dw_die_ref die, int dokids)
14245 if (die->die_mark == 0)
14247 /* We haven't done this node yet. Mark it as used. */
14250 /* We also have to mark its parents as used.
14251 (But we don't want to mark our parents' kids due to this.) */
14252 if (die->die_parent)
14253 prune_unused_types_mark (die->die_parent, 0);
14255 /* Mark any referenced nodes. */
14256 prune_unused_types_walk_attribs (die);
14258 /* If this node is a specification,
14259 also mark the definition, if it exists. */
14260 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14261 prune_unused_types_mark (die->die_definition, 1);
14264 if (dokids && die->die_mark != 2)
14266 /* We need to walk the children, but haven't done so yet.
14267 Remember that we've walked the kids. */
14270 /* If this is an array type, we need to make sure our
14271 kids get marked, even if they're types. */
14272 if (die->die_tag == DW_TAG_array_type)
14273 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14275 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14280 /* Walk the tree DIE and mark types that we actually use. */
14283 prune_unused_types_walk (dw_die_ref die)
14287 /* Don't do anything if this node is already marked. */
14291 switch (die->die_tag)
14293 case DW_TAG_const_type:
14294 case DW_TAG_packed_type:
14295 case DW_TAG_pointer_type:
14296 case DW_TAG_reference_type:
14297 case DW_TAG_volatile_type:
14298 case DW_TAG_typedef:
14299 case DW_TAG_array_type:
14300 case DW_TAG_structure_type:
14301 case DW_TAG_union_type:
14302 case DW_TAG_class_type:
14303 case DW_TAG_friend:
14304 case DW_TAG_variant_part:
14305 case DW_TAG_enumeration_type:
14306 case DW_TAG_subroutine_type:
14307 case DW_TAG_string_type:
14308 case DW_TAG_set_type:
14309 case DW_TAG_subrange_type:
14310 case DW_TAG_ptr_to_member_type:
14311 case DW_TAG_file_type:
14312 if (die->die_perennial_p)
14315 /* It's a type node --- don't mark it. */
14319 /* Mark everything else. */
14325 /* Now, mark any dies referenced from here. */
14326 prune_unused_types_walk_attribs (die);
14328 /* Mark children. */
14329 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14332 /* Increment the string counts on strings referred to from DIE's
14336 prune_unused_types_update_strings (dw_die_ref die)
14341 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14342 if (AT_class (a) == dw_val_class_str)
14344 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
14346 /* Avoid unnecessarily putting strings that are used less than
14347 twice in the hash table. */
14349 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
14352 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
14353 htab_hash_string (s->str),
14355 gcc_assert (*slot == NULL);
14361 /* Remove from the tree DIE any dies that aren't marked. */
14364 prune_unused_types_prune (dw_die_ref die)
14368 gcc_assert (die->die_mark);
14369 prune_unused_types_update_strings (die);
14371 if (! die->die_child)
14374 c = die->die_child;
14376 dw_die_ref prev = c;
14377 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
14378 if (c == die->die_child)
14380 /* No marked children between 'prev' and the end of the list. */
14382 /* No marked children at all. */
14383 die->die_child = NULL;
14386 prev->die_sib = c->die_sib;
14387 die->die_child = prev;
14392 if (c != prev->die_sib)
14394 prune_unused_types_prune (c);
14395 } while (c != die->die_child);
14399 /* Remove dies representing declarations that we never use. */
14402 prune_unused_types (void)
14405 limbo_die_node *node;
14408 #if ENABLE_ASSERT_CHECKING
14409 /* All the marks should already be clear. */
14410 verify_marks_clear (comp_unit_die);
14411 for (node = limbo_die_list; node; node = node->next)
14412 verify_marks_clear (node->die);
14413 #endif /* ENABLE_ASSERT_CHECKING */
14415 /* Set the mark on nodes that are actually used. */
14416 prune_unused_types_walk (comp_unit_die);
14417 for (node = limbo_die_list; node; node = node->next)
14418 prune_unused_types_walk (node->die);
14420 /* Also set the mark on nodes referenced from the
14421 pubname_table or arange_table. */
14422 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
14423 prune_unused_types_mark (pub->die, 1);
14424 for (i = 0; i < arange_table_in_use; i++)
14425 prune_unused_types_mark (arange_table[i], 1);
14427 /* Get rid of nodes that aren't marked; and update the string counts. */
14428 if (debug_str_hash)
14429 htab_empty (debug_str_hash);
14430 prune_unused_types_prune (comp_unit_die);
14431 for (node = limbo_die_list; node; node = node->next)
14432 prune_unused_types_prune (node->die);
14434 /* Leave the marks clear. */
14435 prune_unmark_dies (comp_unit_die);
14436 for (node = limbo_die_list; node; node = node->next)
14437 prune_unmark_dies (node->die);
14440 /* Set the parameter to true if there are any relative pathnames in
14443 file_table_relative_p (void ** slot, void *param)
14446 struct dwarf_file_data *d = *slot;
14447 if (d->emitted_number && !IS_ABSOLUTE_PATH (d->filename))
14455 /* Output stuff that dwarf requires at the end of every file,
14456 and generate the DWARF-2 debugging info. */
14459 dwarf2out_finish (const char *filename)
14461 limbo_die_node *node, *next_node;
14462 dw_die_ref die = 0;
14464 /* Add the name for the main input file now. We delayed this from
14465 dwarf2out_init to avoid complications with PCH. */
14466 add_name_attribute (comp_unit_die, filename);
14467 if (!IS_ABSOLUTE_PATH (filename))
14468 add_comp_dir_attribute (comp_unit_die);
14469 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14472 htab_traverse (file_table, file_table_relative_p, &p);
14474 add_comp_dir_attribute (comp_unit_die);
14477 /* Traverse the limbo die list, and add parent/child links. The only
14478 dies without parents that should be here are concrete instances of
14479 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14480 For concrete instances, we can get the parent die from the abstract
14482 for (node = limbo_die_list; node; node = next_node)
14484 next_node = node->next;
14487 if (die->die_parent == NULL)
14489 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
14492 add_child_die (origin->die_parent, die);
14493 else if (die == comp_unit_die)
14495 else if (errorcount > 0 || sorrycount > 0)
14496 /* It's OK to be confused by errors in the input. */
14497 add_child_die (comp_unit_die, die);
14500 /* In certain situations, the lexical block containing a
14501 nested function can be optimized away, which results
14502 in the nested function die being orphaned. Likewise
14503 with the return type of that nested function. Force
14504 this to be a child of the containing function.
14506 It may happen that even the containing function got fully
14507 inlined and optimized out. In that case we are lost and
14508 assign the empty child. This should not be big issue as
14509 the function is likely unreachable too. */
14510 tree context = NULL_TREE;
14512 gcc_assert (node->created_for);
14514 if (DECL_P (node->created_for))
14515 context = DECL_CONTEXT (node->created_for);
14516 else if (TYPE_P (node->created_for))
14517 context = TYPE_CONTEXT (node->created_for);
14519 gcc_assert (context
14520 && (TREE_CODE (context) == FUNCTION_DECL
14521 || TREE_CODE (context) == NAMESPACE_DECL));
14523 origin = lookup_decl_die (context);
14525 add_child_die (origin, die);
14527 add_child_die (comp_unit_die, die);
14532 limbo_die_list = NULL;
14534 /* Walk through the list of incomplete types again, trying once more to
14535 emit full debugging info for them. */
14536 retry_incomplete_types ();
14538 if (flag_eliminate_unused_debug_types)
14539 prune_unused_types ();
14541 /* Generate separate CUs for each of the include files we've seen.
14542 They will go into limbo_die_list. */
14543 if (flag_eliminate_dwarf2_dups)
14544 break_out_includes (comp_unit_die);
14546 /* Traverse the DIE's and add add sibling attributes to those DIE's
14547 that have children. */
14548 add_sibling_attributes (comp_unit_die);
14549 for (node = limbo_die_list; node; node = node->next)
14550 add_sibling_attributes (node->die);
14552 /* Output a terminator label for the .text section. */
14553 switch_to_section (text_section);
14554 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
14555 if (flag_reorder_blocks_and_partition)
14557 switch_to_section (unlikely_text_section ());
14558 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
14561 /* We can only use the low/high_pc attributes if all of the code was
14563 if (!have_multiple_function_sections)
14565 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
14566 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
14569 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14570 "base address". Use zero so that these addresses become absolute. */
14571 else if (have_location_lists || ranges_table_in_use)
14572 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
14574 /* Output location list section if necessary. */
14575 if (have_location_lists)
14577 /* Output the location lists info. */
14578 switch_to_section (debug_loc_section);
14579 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
14580 DEBUG_LOC_SECTION_LABEL, 0);
14581 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
14582 output_location_lists (die);
14585 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14586 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
14587 debug_line_section_label);
14589 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14590 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
14592 /* Output all of the compilation units. We put the main one last so that
14593 the offsets are available to output_pubnames. */
14594 for (node = limbo_die_list; node; node = node->next)
14595 output_comp_unit (node->die, 0);
14597 output_comp_unit (comp_unit_die, 0);
14599 /* Output the abbreviation table. */
14600 switch_to_section (debug_abbrev_section);
14601 output_abbrev_section ();
14603 /* Output public names table if necessary. */
14604 if (!VEC_empty (pubname_entry, pubname_table))
14606 switch_to_section (debug_pubnames_section);
14607 output_pubnames (pubname_table);
14610 #ifdef DEBUG_PUBTYPES_SECTION
14611 /* Output public types table if necessary. */
14612 if (!VEC_empty (pubname_entry, pubtype_table))
14614 switch_to_section (debug_pubtypes_section);
14615 output_pubnames (pubtype_table);
14619 /* Output the address range information. We only put functions in the arange
14620 table, so don't write it out if we don't have any. */
14621 if (fde_table_in_use)
14623 switch_to_section (debug_aranges_section);
14627 /* Output ranges section if necessary. */
14628 if (ranges_table_in_use)
14630 switch_to_section (debug_ranges_section);
14631 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
14635 /* Output the source line correspondence table. We must do this
14636 even if there is no line information. Otherwise, on an empty
14637 translation unit, we will generate a present, but empty,
14638 .debug_info section. IRIX 6.5 `nm' will then complain when
14639 examining the file. This is done late so that any filenames
14640 used by the debug_info section are marked as 'used'. */
14641 if (! DWARF2_ASM_LINE_DEBUG_INFO)
14643 switch_to_section (debug_line_section);
14644 output_line_info ();
14647 /* Have to end the macro section. */
14648 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14650 switch_to_section (debug_macinfo_section);
14651 dw2_asm_output_data (1, 0, "End compilation unit");
14654 /* If we emitted any DW_FORM_strp form attribute, output the string
14656 if (debug_str_hash)
14657 htab_traverse (debug_str_hash, output_indirect_string, NULL);
14661 /* This should never be used, but its address is needed for comparisons. */
14662 const struct gcc_debug_hooks dwarf2_debug_hooks;
14664 #endif /* DWARF2_DEBUGGING_INFO */
14666 #include "gt-dwarf2out.h"