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 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx,gc) *used_rtx_array;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree,gc) *incomplete_types;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree,gc) *decl_scope_table;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section *debug_info_section;
157 static GTY(()) section *debug_abbrev_section;
158 static GTY(()) section *debug_aranges_section;
159 static GTY(()) section *debug_macinfo_section;
160 static GTY(()) section *debug_line_section;
161 static GTY(()) section *debug_loc_section;
162 static GTY(()) section *debug_pubnames_section;
163 static GTY(()) section *debug_pubtypes_section;
164 static GTY(()) section *debug_str_section;
165 static GTY(()) section *debug_ranges_section;
166 static GTY(()) section *debug_frame_section;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct *dw_cfi_ref;
174 typedef struct dw_fde_struct *dw_fde_ref;
175 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type {
184 dw_cfi_oprnd_reg_num,
190 typedef union dw_cfi_oprnd_struct GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
193 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
195 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
199 typedef struct dw_cfi_struct GTY(())
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc GTY(())
217 HOST_WIDE_INT offset;
218 HOST_WIDE_INT base_offset;
220 int indirect; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct GTY(())
232 const char *dw_fde_begin;
233 const char *dw_fde_current_label;
234 const char *dw_fde_end;
235 const char *dw_fde_hot_section_label;
236 const char *dw_fde_hot_section_end_label;
237 const char *dw_fde_unlikely_section_label;
238 const char *dw_fde_unlikely_section_end_label;
239 bool dw_fde_switched_sections;
240 dw_cfi_ref dw_fde_cfi;
241 unsigned funcdef_number;
242 unsigned all_throwers_are_sibcalls : 1;
243 unsigned nothrow : 1;
244 unsigned uses_eh_lsda : 1;
248 /* Maximum size (in bytes) of an artificially generated label. */
249 #define MAX_ARTIFICIAL_LABEL_BYTES 30
251 /* The size of addresses as they appear in the Dwarf 2 data.
252 Some architectures use word addresses to refer to code locations,
253 but Dwarf 2 info always uses byte addresses. On such machines,
254 Dwarf 2 addresses need to be larger than the architecture's
256 #ifndef DWARF2_ADDR_SIZE
257 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
260 /* The size in bytes of a DWARF field indicating an offset or length
261 relative to a debug info section, specified to be 4 bytes in the
262 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
265 #ifndef DWARF_OFFSET_SIZE
266 #define DWARF_OFFSET_SIZE 4
269 /* According to the (draft) DWARF 3 specification, the initial length
270 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
271 bytes are 0xffffffff, followed by the length stored in the next 8
274 However, the SGI/MIPS ABI uses an initial length which is equal to
275 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
277 #ifndef DWARF_INITIAL_LENGTH_SIZE
278 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
281 #define DWARF_VERSION 2
283 /* Round SIZE up to the nearest BOUNDARY. */
284 #define DWARF_ROUND(SIZE,BOUNDARY) \
285 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
287 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
288 #ifndef DWARF_CIE_DATA_ALIGNMENT
289 #ifdef STACK_GROWS_DOWNWARD
290 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
292 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
296 /* CIE identifier. */
297 #if HOST_BITS_PER_WIDE_INT >= 64
298 #define DWARF_CIE_ID \
299 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
301 #define DWARF_CIE_ID DW_CIE_ID
304 /* A pointer to the base of a table that contains frame description
305 information for each routine. */
306 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
308 /* Number of elements currently allocated for fde_table. */
309 static GTY(()) unsigned fde_table_allocated;
311 /* Number of elements in fde_table currently in use. */
312 static GTY(()) unsigned fde_table_in_use;
314 /* Size (in elements) of increments by which we may expand the
316 #define FDE_TABLE_INCREMENT 256
318 /* A list of call frame insns for the CIE. */
319 static GTY(()) dw_cfi_ref cie_cfi_head;
321 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326 static unsigned current_funcdef_fde;
329 struct indirect_string_node GTY(())
332 unsigned int refcount;
337 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
339 static GTY(()) int dw2_string_counter;
340 static GTY(()) unsigned long dwarf2out_cfi_label_num;
342 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
344 /* Forward declarations for functions defined in this file. */
346 static char *stripattributes (const char *);
347 static const char *dwarf_cfi_name (unsigned);
348 static dw_cfi_ref new_cfi (void);
349 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
350 static void add_fde_cfi (const char *, dw_cfi_ref);
351 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
352 static void lookup_cfa (dw_cfa_location *);
353 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
354 #ifdef DWARF2_UNWIND_INFO
355 static void initial_return_save (rtx);
357 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
358 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
359 static void output_call_frame_info (int);
360 static void dwarf2out_stack_adjust (rtx, bool);
361 static void flush_queued_reg_saves (void);
362 static bool clobbers_queued_reg_save (const_rtx);
363 static void dwarf2out_frame_debug_expr (rtx, const char *);
365 /* Support for complex CFA locations. */
366 static void output_cfa_loc (dw_cfi_ref);
367 static void get_cfa_from_loc_descr (dw_cfa_location *,
368 struct dw_loc_descr_struct *);
369 static struct dw_loc_descr_struct *build_cfa_loc
370 (dw_cfa_location *, HOST_WIDE_INT);
371 static void def_cfa_1 (const char *, dw_cfa_location *);
373 /* How to start an assembler comment. */
374 #ifndef ASM_COMMENT_START
375 #define ASM_COMMENT_START ";#"
378 /* Data and reference forms for relocatable data. */
379 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
380 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
382 #ifndef DEBUG_FRAME_SECTION
383 #define DEBUG_FRAME_SECTION ".debug_frame"
386 #ifndef FUNC_BEGIN_LABEL
387 #define FUNC_BEGIN_LABEL "LFB"
390 #ifndef FUNC_END_LABEL
391 #define FUNC_END_LABEL "LFE"
394 #ifndef FRAME_BEGIN_LABEL
395 #define FRAME_BEGIN_LABEL "Lframe"
397 #define CIE_AFTER_SIZE_LABEL "LSCIE"
398 #define CIE_END_LABEL "LECIE"
399 #define FDE_LABEL "LSFDE"
400 #define FDE_AFTER_SIZE_LABEL "LASFDE"
401 #define FDE_END_LABEL "LEFDE"
402 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
403 #define LINE_NUMBER_END_LABEL "LELT"
404 #define LN_PROLOG_AS_LABEL "LASLTP"
405 #define LN_PROLOG_END_LABEL "LELTP"
406 #define DIE_LABEL_PREFIX "DW"
408 /* The DWARF 2 CFA column which tracks the return address. Normally this
409 is the column for PC, or the first column after all of the hard
411 #ifndef DWARF_FRAME_RETURN_COLUMN
413 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
415 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
419 /* The mapping from gcc register number to DWARF 2 CFA column number. By
420 default, we just provide columns for all registers. */
421 #ifndef DWARF_FRAME_REGNUM
422 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
425 /* Hook used by __throw. */
428 expand_builtin_dwarf_sp_column (void)
430 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
431 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
434 /* Return a pointer to a copy of the section string name S with all
435 attributes stripped off, and an asterisk prepended (for assemble_name). */
438 stripattributes (const char *s)
440 char *stripped = XNEWVEC (char, strlen (s) + 2);
445 while (*s && *s != ',')
452 /* MEM is a memory reference for the register size table, each element of
453 which has mode MODE. Initialize column C as a return address column. */
456 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
458 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
459 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
460 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
463 /* Generate code to initialize the register size table. */
466 expand_builtin_init_dwarf_reg_sizes (tree address)
469 enum machine_mode mode = TYPE_MODE (char_type_node);
470 rtx addr = expand_normal (address);
471 rtx mem = gen_rtx_MEM (BLKmode, addr);
472 bool wrote_return_column = false;
474 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
476 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
478 if (rnum < DWARF_FRAME_REGISTERS)
480 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
481 enum machine_mode save_mode = reg_raw_mode[i];
484 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
485 save_mode = choose_hard_reg_mode (i, 1, true);
486 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
488 if (save_mode == VOIDmode)
490 wrote_return_column = true;
492 size = GET_MODE_SIZE (save_mode);
496 emit_move_insn (adjust_address (mem, mode, offset),
497 gen_int_mode (size, mode));
501 if (!wrote_return_column)
502 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
504 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
505 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
508 targetm.init_dwarf_reg_sizes_extra (address);
511 /* Convert a DWARF call frame info. operation to its string name */
514 dwarf_cfi_name (unsigned int cfi_opc)
518 case DW_CFA_advance_loc:
519 return "DW_CFA_advance_loc";
521 return "DW_CFA_offset";
523 return "DW_CFA_restore";
527 return "DW_CFA_set_loc";
528 case DW_CFA_advance_loc1:
529 return "DW_CFA_advance_loc1";
530 case DW_CFA_advance_loc2:
531 return "DW_CFA_advance_loc2";
532 case DW_CFA_advance_loc4:
533 return "DW_CFA_advance_loc4";
534 case DW_CFA_offset_extended:
535 return "DW_CFA_offset_extended";
536 case DW_CFA_restore_extended:
537 return "DW_CFA_restore_extended";
538 case DW_CFA_undefined:
539 return "DW_CFA_undefined";
540 case DW_CFA_same_value:
541 return "DW_CFA_same_value";
542 case DW_CFA_register:
543 return "DW_CFA_register";
544 case DW_CFA_remember_state:
545 return "DW_CFA_remember_state";
546 case DW_CFA_restore_state:
547 return "DW_CFA_restore_state";
549 return "DW_CFA_def_cfa";
550 case DW_CFA_def_cfa_register:
551 return "DW_CFA_def_cfa_register";
552 case DW_CFA_def_cfa_offset:
553 return "DW_CFA_def_cfa_offset";
556 case DW_CFA_def_cfa_expression:
557 return "DW_CFA_def_cfa_expression";
558 case DW_CFA_expression:
559 return "DW_CFA_expression";
560 case DW_CFA_offset_extended_sf:
561 return "DW_CFA_offset_extended_sf";
562 case DW_CFA_def_cfa_sf:
563 return "DW_CFA_def_cfa_sf";
564 case DW_CFA_def_cfa_offset_sf:
565 return "DW_CFA_def_cfa_offset_sf";
567 /* SGI/MIPS specific */
568 case DW_CFA_MIPS_advance_loc8:
569 return "DW_CFA_MIPS_advance_loc8";
572 case DW_CFA_GNU_window_save:
573 return "DW_CFA_GNU_window_save";
574 case DW_CFA_GNU_args_size:
575 return "DW_CFA_GNU_args_size";
576 case DW_CFA_GNU_negative_offset_extended:
577 return "DW_CFA_GNU_negative_offset_extended";
580 return "DW_CFA_<unknown>";
584 /* Return a pointer to a newly allocated Call Frame Instruction. */
586 static inline dw_cfi_ref
589 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
591 cfi->dw_cfi_next = NULL;
592 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
593 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
598 /* Add a Call Frame Instruction to list of instructions. */
601 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
605 /* Find the end of the chain. */
606 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
612 /* Generate a new label for the CFI info to refer to. */
615 dwarf2out_cfi_label (void)
617 static char label[20];
619 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
620 ASM_OUTPUT_LABEL (asm_out_file, label);
624 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
625 or to the CIE if LABEL is NULL. */
628 add_fde_cfi (const char *label, dw_cfi_ref cfi)
632 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
635 label = dwarf2out_cfi_label ();
637 if (fde->dw_fde_current_label == NULL
638 || strcmp (label, fde->dw_fde_current_label) != 0)
642 label = xstrdup (label);
644 /* Set the location counter to the new label. */
646 /* If we have a current label, advance from there, otherwise
647 set the location directly using set_loc. */
648 xcfi->dw_cfi_opc = fde->dw_fde_current_label
649 ? DW_CFA_advance_loc4
651 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
652 add_cfi (&fde->dw_fde_cfi, xcfi);
654 fde->dw_fde_current_label = label;
657 add_cfi (&fde->dw_fde_cfi, cfi);
661 add_cfi (&cie_cfi_head, cfi);
664 /* Subroutine of lookup_cfa. */
667 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
669 switch (cfi->dw_cfi_opc)
671 case DW_CFA_def_cfa_offset:
672 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
674 case DW_CFA_def_cfa_offset_sf:
676 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
678 case DW_CFA_def_cfa_register:
679 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
682 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
683 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
685 case DW_CFA_def_cfa_sf:
686 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
688 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
690 case DW_CFA_def_cfa_expression:
691 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
698 /* Find the previous value for the CFA. */
701 lookup_cfa (dw_cfa_location *loc)
705 loc->reg = INVALID_REGNUM;
708 loc->base_offset = 0;
710 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
711 lookup_cfa_1 (cfi, loc);
713 if (fde_table_in_use)
715 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
716 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
717 lookup_cfa_1 (cfi, loc);
721 /* The current rule for calculating the DWARF2 canonical frame address. */
722 static dw_cfa_location cfa;
724 /* The register used for saving registers to the stack, and its offset
726 static dw_cfa_location cfa_store;
728 /* The running total of the size of arguments pushed onto the stack. */
729 static HOST_WIDE_INT args_size;
731 /* The last args_size we actually output. */
732 static HOST_WIDE_INT old_args_size;
734 /* Entry point to update the canonical frame address (CFA).
735 LABEL is passed to add_fde_cfi. The value of CFA is now to be
736 calculated from REG+OFFSET. */
739 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
746 def_cfa_1 (label, &loc);
749 /* Determine if two dw_cfa_location structures define the same data. */
752 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
754 return (loc1->reg == loc2->reg
755 && loc1->offset == loc2->offset
756 && loc1->indirect == loc2->indirect
757 && (loc1->indirect == 0
758 || loc1->base_offset == loc2->base_offset));
761 /* This routine does the actual work. The CFA is now calculated from
762 the dw_cfa_location structure. */
765 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
768 dw_cfa_location old_cfa, loc;
773 if (cfa_store.reg == loc.reg && loc.indirect == 0)
774 cfa_store.offset = loc.offset;
776 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
777 lookup_cfa (&old_cfa);
779 /* If nothing changed, no need to issue any call frame instructions. */
780 if (cfa_equal_p (&loc, &old_cfa))
785 if (loc.reg == old_cfa.reg && !loc.indirect)
787 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
788 the CFA register did not change but the offset did. */
791 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
792 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
794 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
795 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
799 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
800 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
804 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
805 else if (loc.offset == old_cfa.offset
806 && old_cfa.reg != INVALID_REGNUM
809 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
810 indicating the CFA register has changed to <register> but the
811 offset has not changed. */
812 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
813 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
817 else if (loc.indirect == 0)
819 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
820 indicating the CFA register has changed to <register> with
821 the specified offset. */
824 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
825 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
827 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
828 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
833 cfi->dw_cfi_opc = DW_CFA_def_cfa;
834 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
835 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
840 /* Construct a DW_CFA_def_cfa_expression instruction to
841 calculate the CFA using a full location expression since no
842 register-offset pair is available. */
843 struct dw_loc_descr_struct *loc_list;
845 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
846 loc_list = build_cfa_loc (&loc, 0);
847 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
850 add_fde_cfi (label, cfi);
853 /* Add the CFI for saving a register. REG is the CFA column number.
854 LABEL is passed to add_fde_cfi.
855 If SREG is -1, the register is saved at OFFSET from the CFA;
856 otherwise it is saved in SREG. */
859 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
861 dw_cfi_ref cfi = new_cfi ();
863 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
865 if (sreg == INVALID_REGNUM)
868 /* The register number won't fit in 6 bits, so we have to use
870 cfi->dw_cfi_opc = DW_CFA_offset_extended;
872 cfi->dw_cfi_opc = DW_CFA_offset;
874 #ifdef ENABLE_CHECKING
876 /* If we get an offset that is not a multiple of
877 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
878 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
880 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
882 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
885 offset /= DWARF_CIE_DATA_ALIGNMENT;
887 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
889 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
891 else if (sreg == reg)
892 cfi->dw_cfi_opc = DW_CFA_same_value;
895 cfi->dw_cfi_opc = DW_CFA_register;
896 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
899 add_fde_cfi (label, cfi);
902 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
903 This CFI tells the unwinder that it needs to restore the window registers
904 from the previous frame's window save area.
906 ??? Perhaps we should note in the CIE where windows are saved (instead of
907 assuming 0(cfa)) and what registers are in the window. */
910 dwarf2out_window_save (const char *label)
912 dw_cfi_ref cfi = new_cfi ();
914 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
915 add_fde_cfi (label, cfi);
918 /* Add a CFI to update the running total of the size of arguments
919 pushed onto the stack. */
922 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
926 if (size == old_args_size)
929 old_args_size = size;
932 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
933 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
934 add_fde_cfi (label, cfi);
937 /* Entry point for saving a register to the stack. REG is the GCC register
938 number. LABEL and OFFSET are passed to reg_save. */
941 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
943 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
946 /* Entry point for saving the return address in the stack.
947 LABEL and OFFSET are passed to reg_save. */
950 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
952 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
955 /* Entry point for saving the return address in a register.
956 LABEL and SREG are passed to reg_save. */
959 dwarf2out_return_reg (const char *label, unsigned int sreg)
961 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
964 #ifdef DWARF2_UNWIND_INFO
965 /* Record the initial position of the return address. RTL is
966 INCOMING_RETURN_ADDR_RTX. */
969 initial_return_save (rtx rtl)
971 unsigned int reg = INVALID_REGNUM;
972 HOST_WIDE_INT offset = 0;
974 switch (GET_CODE (rtl))
977 /* RA is in a register. */
978 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
982 /* RA is on the stack. */
984 switch (GET_CODE (rtl))
987 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
992 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
993 offset = INTVAL (XEXP (rtl, 1));
997 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
998 offset = -INTVAL (XEXP (rtl, 1));
1008 /* The return address is at some offset from any value we can
1009 actually load. For instance, on the SPARC it is in %i7+8. Just
1010 ignore the offset for now; it doesn't matter for unwinding frames. */
1011 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1012 initial_return_save (XEXP (rtl, 0));
1019 if (reg != DWARF_FRAME_RETURN_COLUMN)
1020 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1024 /* Given a SET, calculate the amount of stack adjustment it
1027 static HOST_WIDE_INT
1028 stack_adjust_offset (const_rtx pattern)
1030 const_rtx src = SET_SRC (pattern);
1031 const_rtx dest = SET_DEST (pattern);
1032 HOST_WIDE_INT offset = 0;
1035 if (dest == stack_pointer_rtx)
1037 /* (set (reg sp) (plus (reg sp) (const_int))) */
1038 code = GET_CODE (src);
1039 if (! (code == PLUS || code == MINUS)
1040 || XEXP (src, 0) != stack_pointer_rtx
1041 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1044 offset = INTVAL (XEXP (src, 1));
1048 else if (MEM_P (dest))
1050 /* (set (mem (pre_dec (reg sp))) (foo)) */
1051 src = XEXP (dest, 0);
1052 code = GET_CODE (src);
1058 if (XEXP (src, 0) == stack_pointer_rtx)
1060 rtx val = XEXP (XEXP (src, 1), 1);
1061 /* We handle only adjustments by constant amount. */
1062 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1063 && GET_CODE (val) == CONST_INT);
1064 offset = -INTVAL (val);
1071 if (XEXP (src, 0) == stack_pointer_rtx)
1073 offset = GET_MODE_SIZE (GET_MODE (dest));
1080 if (XEXP (src, 0) == stack_pointer_rtx)
1082 offset = -GET_MODE_SIZE (GET_MODE (dest));
1097 /* Check INSN to see if it looks like a push or a stack adjustment, and
1098 make a note of it if it does. EH uses this information to find out how
1099 much extra space it needs to pop off the stack. */
1102 dwarf2out_stack_adjust (rtx insn, bool after_p)
1104 HOST_WIDE_INT offset;
1108 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1109 with this function. Proper support would require all frame-related
1110 insns to be marked, and to be able to handle saving state around
1111 epilogues textually in the middle of the function. */
1112 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1115 /* If only calls can throw, and we have a frame pointer,
1116 save up adjustments until we see the CALL_INSN. */
1117 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1119 if (CALL_P (insn) && !after_p)
1121 /* Extract the size of the args from the CALL rtx itself. */
1122 insn = PATTERN (insn);
1123 if (GET_CODE (insn) == PARALLEL)
1124 insn = XVECEXP (insn, 0, 0);
1125 if (GET_CODE (insn) == SET)
1126 insn = SET_SRC (insn);
1127 gcc_assert (GET_CODE (insn) == CALL);
1128 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1133 if (CALL_P (insn) && !after_p)
1135 if (!flag_asynchronous_unwind_tables)
1136 dwarf2out_args_size ("", args_size);
1139 else if (BARRIER_P (insn))
1141 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1142 the compiler will have already emitted a stack adjustment, but
1143 doesn't bother for calls to noreturn functions. */
1144 #ifdef STACK_GROWS_DOWNWARD
1145 offset = -args_size;
1150 else if (GET_CODE (PATTERN (insn)) == SET)
1151 offset = stack_adjust_offset (PATTERN (insn));
1152 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1153 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1155 /* There may be stack adjustments inside compound insns. Search
1157 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1158 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1159 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1167 if (cfa.reg == STACK_POINTER_REGNUM)
1168 cfa.offset += offset;
1170 #ifndef STACK_GROWS_DOWNWARD
1174 args_size += offset;
1178 label = dwarf2out_cfi_label ();
1179 def_cfa_1 (label, &cfa);
1180 if (flag_asynchronous_unwind_tables)
1181 dwarf2out_args_size (label, args_size);
1186 /* We delay emitting a register save until either (a) we reach the end
1187 of the prologue or (b) the register is clobbered. This clusters
1188 register saves so that there are fewer pc advances. */
1190 struct queued_reg_save GTY(())
1192 struct queued_reg_save *next;
1194 HOST_WIDE_INT cfa_offset;
1198 static GTY(()) struct queued_reg_save *queued_reg_saves;
1200 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1201 struct reg_saved_in_data GTY(()) {
1206 /* A list of registers saved in other registers.
1207 The list intentionally has a small maximum capacity of 4; if your
1208 port needs more than that, you might consider implementing a
1209 more efficient data structure. */
1210 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1211 static GTY(()) size_t num_regs_saved_in_regs;
1213 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1214 static const char *last_reg_save_label;
1216 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1217 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1220 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1222 struct queued_reg_save *q;
1224 /* Duplicates waste space, but it's also necessary to remove them
1225 for correctness, since the queue gets output in reverse
1227 for (q = queued_reg_saves; q != NULL; q = q->next)
1228 if (REGNO (q->reg) == REGNO (reg))
1233 q = ggc_alloc (sizeof (*q));
1234 q->next = queued_reg_saves;
1235 queued_reg_saves = q;
1239 q->cfa_offset = offset;
1240 q->saved_reg = sreg;
1242 last_reg_save_label = label;
1245 /* Output all the entries in QUEUED_REG_SAVES. */
1248 flush_queued_reg_saves (void)
1250 struct queued_reg_save *q;
1252 for (q = queued_reg_saves; q; q = q->next)
1255 unsigned int reg, sreg;
1257 for (i = 0; i < num_regs_saved_in_regs; i++)
1258 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1260 if (q->saved_reg && i == num_regs_saved_in_regs)
1262 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1263 num_regs_saved_in_regs++;
1265 if (i != num_regs_saved_in_regs)
1267 regs_saved_in_regs[i].orig_reg = q->reg;
1268 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1271 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1273 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1275 sreg = INVALID_REGNUM;
1276 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1279 queued_reg_saves = NULL;
1280 last_reg_save_label = NULL;
1283 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1284 location for? Or, does it clobber a register which we've previously
1285 said that some other register is saved in, and for which we now
1286 have a new location for? */
1289 clobbers_queued_reg_save (const_rtx insn)
1291 struct queued_reg_save *q;
1293 for (q = queued_reg_saves; q; q = q->next)
1296 if (modified_in_p (q->reg, insn))
1298 for (i = 0; i < num_regs_saved_in_regs; i++)
1299 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1300 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1307 /* Entry point for saving the first register into the second. */
1310 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1313 unsigned int regno, sregno;
1315 for (i = 0; i < num_regs_saved_in_regs; i++)
1316 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1318 if (i == num_regs_saved_in_regs)
1320 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1321 num_regs_saved_in_regs++;
1323 regs_saved_in_regs[i].orig_reg = reg;
1324 regs_saved_in_regs[i].saved_in_reg = sreg;
1326 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1327 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1328 reg_save (label, regno, sregno, 0);
1331 /* What register, if any, is currently saved in REG? */
1334 reg_saved_in (rtx reg)
1336 unsigned int regn = REGNO (reg);
1338 struct queued_reg_save *q;
1340 for (q = queued_reg_saves; q; q = q->next)
1341 if (q->saved_reg && regn == REGNO (q->saved_reg))
1344 for (i = 0; i < num_regs_saved_in_regs; i++)
1345 if (regs_saved_in_regs[i].saved_in_reg
1346 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1347 return regs_saved_in_regs[i].orig_reg;
1353 /* A temporary register holding an integral value used in adjusting SP
1354 or setting up the store_reg. The "offset" field holds the integer
1355 value, not an offset. */
1356 static dw_cfa_location cfa_temp;
1358 /* Record call frame debugging information for an expression EXPR,
1359 which either sets SP or FP (adjusting how we calculate the frame
1360 address) or saves a register to the stack or another register.
1361 LABEL indicates the address of EXPR.
1363 This function encodes a state machine mapping rtxes to actions on
1364 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1365 users need not read the source code.
1367 The High-Level Picture
1369 Changes in the register we use to calculate the CFA: Currently we
1370 assume that if you copy the CFA register into another register, we
1371 should take the other one as the new CFA register; this seems to
1372 work pretty well. If it's wrong for some target, it's simple
1373 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1375 Changes in the register we use for saving registers to the stack:
1376 This is usually SP, but not always. Again, we deduce that if you
1377 copy SP into another register (and SP is not the CFA register),
1378 then the new register is the one we will be using for register
1379 saves. This also seems to work.
1381 Register saves: There's not much guesswork about this one; if
1382 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1383 register save, and the register used to calculate the destination
1384 had better be the one we think we're using for this purpose.
1385 It's also assumed that a copy from a call-saved register to another
1386 register is saving that register if RTX_FRAME_RELATED_P is set on
1387 that instruction. If the copy is from a call-saved register to
1388 the *same* register, that means that the register is now the same
1389 value as in the caller.
1391 Except: If the register being saved is the CFA register, and the
1392 offset is nonzero, we are saving the CFA, so we assume we have to
1393 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1394 the intent is to save the value of SP from the previous frame.
1396 In addition, if a register has previously been saved to a different
1399 Invariants / Summaries of Rules
1401 cfa current rule for calculating the CFA. It usually
1402 consists of a register and an offset.
1403 cfa_store register used by prologue code to save things to the stack
1404 cfa_store.offset is the offset from the value of
1405 cfa_store.reg to the actual CFA
1406 cfa_temp register holding an integral value. cfa_temp.offset
1407 stores the value, which will be used to adjust the
1408 stack pointer. cfa_temp is also used like cfa_store,
1409 to track stores to the stack via fp or a temp reg.
1411 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1412 with cfa.reg as the first operand changes the cfa.reg and its
1413 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1416 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1417 expression yielding a constant. This sets cfa_temp.reg
1418 and cfa_temp.offset.
1420 Rule 5: Create a new register cfa_store used to save items to the
1423 Rules 10-14: Save a register to the stack. Define offset as the
1424 difference of the original location and cfa_store's
1425 location (or cfa_temp's location if cfa_temp is used).
1429 "{a,b}" indicates a choice of a xor b.
1430 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1433 (set <reg1> <reg2>:cfa.reg)
1434 effects: cfa.reg = <reg1>
1435 cfa.offset unchanged
1436 cfa_temp.reg = <reg1>
1437 cfa_temp.offset = cfa.offset
1440 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1441 {<const_int>,<reg>:cfa_temp.reg}))
1442 effects: cfa.reg = sp if fp used
1443 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1444 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1445 if cfa_store.reg==sp
1448 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1449 effects: cfa.reg = fp
1450 cfa_offset += +/- <const_int>
1453 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1454 constraints: <reg1> != fp
1456 effects: cfa.reg = <reg1>
1457 cfa_temp.reg = <reg1>
1458 cfa_temp.offset = cfa.offset
1461 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1462 constraints: <reg1> != fp
1464 effects: cfa_store.reg = <reg1>
1465 cfa_store.offset = cfa.offset - cfa_temp.offset
1468 (set <reg> <const_int>)
1469 effects: cfa_temp.reg = <reg>
1470 cfa_temp.offset = <const_int>
1473 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1474 effects: cfa_temp.reg = <reg1>
1475 cfa_temp.offset |= <const_int>
1478 (set <reg> (high <exp>))
1482 (set <reg> (lo_sum <exp> <const_int>))
1483 effects: cfa_temp.reg = <reg>
1484 cfa_temp.offset = <const_int>
1487 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1488 effects: cfa_store.offset -= <const_int>
1489 cfa.offset = cfa_store.offset if cfa.reg == sp
1491 cfa.base_offset = -cfa_store.offset
1494 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1495 effects: cfa_store.offset += -/+ mode_size(mem)
1496 cfa.offset = cfa_store.offset if cfa.reg == sp
1498 cfa.base_offset = -cfa_store.offset
1501 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1504 effects: cfa.reg = <reg1>
1505 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1508 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1509 effects: cfa.reg = <reg1>
1510 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1513 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1514 effects: cfa.reg = <reg1>
1515 cfa.base_offset = -cfa_temp.offset
1516 cfa_temp.offset -= mode_size(mem)
1519 (set <reg> {unspec, unspec_volatile})
1520 effects: target-dependent */
1523 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1526 HOST_WIDE_INT offset;
1528 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1529 the PARALLEL independently. The first element is always processed if
1530 it is a SET. This is for backward compatibility. Other elements
1531 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1532 flag is set in them. */
1533 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1536 int limit = XVECLEN (expr, 0);
1539 /* PARALLELs have strict read-modify-write semantics, so we
1540 ought to evaluate every rvalue before changing any lvalue.
1541 It's cumbersome to do that in general, but there's an
1542 easy approximation that is enough for all current users:
1543 handle register saves before register assignments. */
1544 if (GET_CODE (expr) == PARALLEL)
1545 for (par_index = 0; par_index < limit; par_index++)
1547 elem = XVECEXP (expr, 0, par_index);
1548 if (GET_CODE (elem) == SET
1549 && MEM_P (SET_DEST (elem))
1550 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1551 dwarf2out_frame_debug_expr (elem, label);
1554 for (par_index = 0; par_index < limit; par_index++)
1556 elem = XVECEXP (expr, 0, par_index);
1557 if (GET_CODE (elem) == SET
1558 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1559 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1560 dwarf2out_frame_debug_expr (elem, label);
1565 gcc_assert (GET_CODE (expr) == SET);
1567 src = SET_SRC (expr);
1568 dest = SET_DEST (expr);
1572 rtx rsi = reg_saved_in (src);
1577 switch (GET_CODE (dest))
1580 switch (GET_CODE (src))
1582 /* Setting FP from SP. */
1584 if (cfa.reg == (unsigned) REGNO (src))
1587 /* Update the CFA rule wrt SP or FP. Make sure src is
1588 relative to the current CFA register.
1590 We used to require that dest be either SP or FP, but the
1591 ARM copies SP to a temporary register, and from there to
1592 FP. So we just rely on the backends to only set
1593 RTX_FRAME_RELATED_P on appropriate insns. */
1594 cfa.reg = REGNO (dest);
1595 cfa_temp.reg = cfa.reg;
1596 cfa_temp.offset = cfa.offset;
1600 /* Saving a register in a register. */
1601 gcc_assert (!fixed_regs [REGNO (dest)]
1602 /* For the SPARC and its register window. */
1603 || (DWARF_FRAME_REGNUM (REGNO (src))
1604 == DWARF_FRAME_RETURN_COLUMN));
1605 queue_reg_save (label, src, dest, 0);
1612 if (dest == stack_pointer_rtx)
1616 switch (GET_CODE (XEXP (src, 1)))
1619 offset = INTVAL (XEXP (src, 1));
1622 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1624 offset = cfa_temp.offset;
1630 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1632 /* Restoring SP from FP in the epilogue. */
1633 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1634 cfa.reg = STACK_POINTER_REGNUM;
1636 else if (GET_CODE (src) == LO_SUM)
1637 /* Assume we've set the source reg of the LO_SUM from sp. */
1640 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1642 if (GET_CODE (src) != MINUS)
1644 if (cfa.reg == STACK_POINTER_REGNUM)
1645 cfa.offset += offset;
1646 if (cfa_store.reg == STACK_POINTER_REGNUM)
1647 cfa_store.offset += offset;
1649 else if (dest == hard_frame_pointer_rtx)
1652 /* Either setting the FP from an offset of the SP,
1653 or adjusting the FP */
1654 gcc_assert (frame_pointer_needed);
1656 gcc_assert (REG_P (XEXP (src, 0))
1657 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1658 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1659 offset = INTVAL (XEXP (src, 1));
1660 if (GET_CODE (src) != MINUS)
1662 cfa.offset += offset;
1663 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1667 gcc_assert (GET_CODE (src) != MINUS);
1670 if (REG_P (XEXP (src, 0))
1671 && REGNO (XEXP (src, 0)) == cfa.reg
1672 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1674 /* Setting a temporary CFA register that will be copied
1675 into the FP later on. */
1676 offset = - INTVAL (XEXP (src, 1));
1677 cfa.offset += offset;
1678 cfa.reg = REGNO (dest);
1679 /* Or used to save regs to the stack. */
1680 cfa_temp.reg = cfa.reg;
1681 cfa_temp.offset = cfa.offset;
1685 else if (REG_P (XEXP (src, 0))
1686 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1687 && XEXP (src, 1) == stack_pointer_rtx)
1689 /* Setting a scratch register that we will use instead
1690 of SP for saving registers to the stack. */
1691 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1692 cfa_store.reg = REGNO (dest);
1693 cfa_store.offset = cfa.offset - cfa_temp.offset;
1697 else if (GET_CODE (src) == LO_SUM
1698 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1700 cfa_temp.reg = REGNO (dest);
1701 cfa_temp.offset = INTVAL (XEXP (src, 1));
1710 cfa_temp.reg = REGNO (dest);
1711 cfa_temp.offset = INTVAL (src);
1716 gcc_assert (REG_P (XEXP (src, 0))
1717 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1718 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1720 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1721 cfa_temp.reg = REGNO (dest);
1722 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1725 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1726 which will fill in all of the bits. */
1733 case UNSPEC_VOLATILE:
1734 gcc_assert (targetm.dwarf_handle_frame_unspec);
1735 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1742 def_cfa_1 (label, &cfa);
1746 gcc_assert (REG_P (src));
1748 /* Saving a register to the stack. Make sure dest is relative to the
1750 switch (GET_CODE (XEXP (dest, 0)))
1755 /* We can't handle variable size modifications. */
1756 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1758 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1760 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1761 && cfa_store.reg == STACK_POINTER_REGNUM);
1763 cfa_store.offset += offset;
1764 if (cfa.reg == STACK_POINTER_REGNUM)
1765 cfa.offset = cfa_store.offset;
1767 offset = -cfa_store.offset;
1773 offset = GET_MODE_SIZE (GET_MODE (dest));
1774 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1777 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1778 && cfa_store.reg == STACK_POINTER_REGNUM);
1780 cfa_store.offset += offset;
1781 if (cfa.reg == STACK_POINTER_REGNUM)
1782 cfa.offset = cfa_store.offset;
1784 offset = -cfa_store.offset;
1788 /* With an offset. */
1795 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1796 && REG_P (XEXP (XEXP (dest, 0), 0)));
1797 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1798 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1801 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1803 if (cfa_store.reg == (unsigned) regno)
1804 offset -= cfa_store.offset;
1807 gcc_assert (cfa_temp.reg == (unsigned) regno);
1808 offset -= cfa_temp.offset;
1814 /* Without an offset. */
1817 int regno = REGNO (XEXP (dest, 0));
1819 if (cfa_store.reg == (unsigned) regno)
1820 offset = -cfa_store.offset;
1823 gcc_assert (cfa_temp.reg == (unsigned) regno);
1824 offset = -cfa_temp.offset;
1831 gcc_assert (cfa_temp.reg
1832 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1833 offset = -cfa_temp.offset;
1834 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1841 if (REGNO (src) != STACK_POINTER_REGNUM
1842 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1843 && (unsigned) REGNO (src) == cfa.reg)
1845 /* We're storing the current CFA reg into the stack. */
1847 if (cfa.offset == 0)
1849 /* If the source register is exactly the CFA, assume
1850 we're saving SP like any other register; this happens
1852 def_cfa_1 (label, &cfa);
1853 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1858 /* Otherwise, we'll need to look in the stack to
1859 calculate the CFA. */
1860 rtx x = XEXP (dest, 0);
1864 gcc_assert (REG_P (x));
1866 cfa.reg = REGNO (x);
1867 cfa.base_offset = offset;
1869 def_cfa_1 (label, &cfa);
1874 def_cfa_1 (label, &cfa);
1875 queue_reg_save (label, src, NULL_RTX, offset);
1883 /* Record call frame debugging information for INSN, which either
1884 sets SP or FP (adjusting how we calculate the frame address) or saves a
1885 register to the stack. If INSN is NULL_RTX, initialize our state.
1887 If AFTER_P is false, we're being called before the insn is emitted,
1888 otherwise after. Call instructions get invoked twice. */
1891 dwarf2out_frame_debug (rtx insn, bool after_p)
1896 if (insn == NULL_RTX)
1900 /* Flush any queued register saves. */
1901 flush_queued_reg_saves ();
1903 /* Set up state for generating call frame debug info. */
1906 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1908 cfa.reg = STACK_POINTER_REGNUM;
1911 cfa_temp.offset = 0;
1913 for (i = 0; i < num_regs_saved_in_regs; i++)
1915 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1916 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1918 num_regs_saved_in_regs = 0;
1922 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1923 flush_queued_reg_saves ();
1925 if (! RTX_FRAME_RELATED_P (insn))
1927 if (!ACCUMULATE_OUTGOING_ARGS)
1928 dwarf2out_stack_adjust (insn, after_p);
1932 label = dwarf2out_cfi_label ();
1933 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1935 insn = XEXP (src, 0);
1937 insn = PATTERN (insn);
1939 dwarf2out_frame_debug_expr (insn, label);
1944 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1945 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1946 (enum dwarf_call_frame_info cfi);
1948 static enum dw_cfi_oprnd_type
1949 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1954 case DW_CFA_GNU_window_save:
1955 return dw_cfi_oprnd_unused;
1957 case DW_CFA_set_loc:
1958 case DW_CFA_advance_loc1:
1959 case DW_CFA_advance_loc2:
1960 case DW_CFA_advance_loc4:
1961 case DW_CFA_MIPS_advance_loc8:
1962 return dw_cfi_oprnd_addr;
1965 case DW_CFA_offset_extended:
1966 case DW_CFA_def_cfa:
1967 case DW_CFA_offset_extended_sf:
1968 case DW_CFA_def_cfa_sf:
1969 case DW_CFA_restore_extended:
1970 case DW_CFA_undefined:
1971 case DW_CFA_same_value:
1972 case DW_CFA_def_cfa_register:
1973 case DW_CFA_register:
1974 return dw_cfi_oprnd_reg_num;
1976 case DW_CFA_def_cfa_offset:
1977 case DW_CFA_GNU_args_size:
1978 case DW_CFA_def_cfa_offset_sf:
1979 return dw_cfi_oprnd_offset;
1981 case DW_CFA_def_cfa_expression:
1982 case DW_CFA_expression:
1983 return dw_cfi_oprnd_loc;
1990 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1991 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1992 (enum dwarf_call_frame_info cfi);
1994 static enum dw_cfi_oprnd_type
1995 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1999 case DW_CFA_def_cfa:
2000 case DW_CFA_def_cfa_sf:
2002 case DW_CFA_offset_extended_sf:
2003 case DW_CFA_offset_extended:
2004 return dw_cfi_oprnd_offset;
2006 case DW_CFA_register:
2007 return dw_cfi_oprnd_reg_num;
2010 return dw_cfi_oprnd_unused;
2014 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2016 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2017 switch to the data section instead, and write out a synthetic label
2021 switch_to_eh_frame_section (void)
2025 #ifdef EH_FRAME_SECTION_NAME
2026 if (eh_frame_section == 0)
2030 if (EH_TABLES_CAN_BE_READ_ONLY)
2036 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2038 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2040 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2042 flags = ((! flag_pic
2043 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2044 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2045 && (per_encoding & 0x70) != DW_EH_PE_absptr
2046 && (per_encoding & 0x70) != DW_EH_PE_aligned
2047 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2048 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2049 ? 0 : SECTION_WRITE);
2052 flags = SECTION_WRITE;
2053 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2057 if (eh_frame_section)
2058 switch_to_section (eh_frame_section);
2061 /* We have no special eh_frame section. Put the information in
2062 the data section and emit special labels to guide collect2. */
2063 switch_to_section (data_section);
2064 label = get_file_function_name ("F");
2065 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2066 targetm.asm_out.globalize_label (asm_out_file,
2067 IDENTIFIER_POINTER (label));
2068 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2072 /* Output a Call Frame Information opcode and its operand(s). */
2075 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2078 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2079 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2080 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2081 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2082 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2083 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2085 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2086 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2087 "DW_CFA_offset, column 0x%lx", r);
2088 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2090 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2092 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2093 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2094 "DW_CFA_restore, column 0x%lx", r);
2098 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2099 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2101 switch (cfi->dw_cfi_opc)
2103 case DW_CFA_set_loc:
2105 dw2_asm_output_encoded_addr_rtx (
2106 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2107 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2110 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2111 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2112 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2115 case DW_CFA_advance_loc1:
2116 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2117 fde->dw_fde_current_label, NULL);
2118 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2121 case DW_CFA_advance_loc2:
2122 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2123 fde->dw_fde_current_label, NULL);
2124 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2127 case DW_CFA_advance_loc4:
2128 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2129 fde->dw_fde_current_label, NULL);
2130 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2133 case DW_CFA_MIPS_advance_loc8:
2134 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2135 fde->dw_fde_current_label, NULL);
2136 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2139 case DW_CFA_offset_extended:
2140 case DW_CFA_def_cfa:
2141 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2142 dw2_asm_output_data_uleb128 (r, NULL);
2143 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2146 case DW_CFA_offset_extended_sf:
2147 case DW_CFA_def_cfa_sf:
2148 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2149 dw2_asm_output_data_uleb128 (r, NULL);
2150 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2153 case DW_CFA_restore_extended:
2154 case DW_CFA_undefined:
2155 case DW_CFA_same_value:
2156 case DW_CFA_def_cfa_register:
2157 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2158 dw2_asm_output_data_uleb128 (r, NULL);
2161 case DW_CFA_register:
2162 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2163 dw2_asm_output_data_uleb128 (r, NULL);
2164 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2165 dw2_asm_output_data_uleb128 (r, NULL);
2168 case DW_CFA_def_cfa_offset:
2169 case DW_CFA_GNU_args_size:
2170 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2173 case DW_CFA_def_cfa_offset_sf:
2174 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2177 case DW_CFA_GNU_window_save:
2180 case DW_CFA_def_cfa_expression:
2181 case DW_CFA_expression:
2182 output_cfa_loc (cfi);
2185 case DW_CFA_GNU_negative_offset_extended:
2186 /* Obsoleted by DW_CFA_offset_extended_sf. */
2195 /* Output the call frame information used to record information
2196 that relates to calculating the frame pointer, and records the
2197 location of saved registers. */
2200 output_call_frame_info (int for_eh)
2205 char l1[20], l2[20], section_start_label[20];
2206 bool any_lsda_needed = false;
2207 char augmentation[6];
2208 int augmentation_size;
2209 int fde_encoding = DW_EH_PE_absptr;
2210 int per_encoding = DW_EH_PE_absptr;
2211 int lsda_encoding = DW_EH_PE_absptr;
2214 /* Don't emit a CIE if there won't be any FDEs. */
2215 if (fde_table_in_use == 0)
2218 /* If we make FDEs linkonce, we may have to emit an empty label for
2219 an FDE that wouldn't otherwise be emitted. We want to avoid
2220 having an FDE kept around when the function it refers to is
2221 discarded. Example where this matters: a primary function
2222 template in C++ requires EH information, but an explicit
2223 specialization doesn't. */
2224 if (TARGET_USES_WEAK_UNWIND_INFO
2225 && ! flag_asynchronous_unwind_tables
2228 for (i = 0; i < fde_table_in_use; i++)
2229 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2230 && !fde_table[i].uses_eh_lsda
2231 && ! DECL_WEAK (fde_table[i].decl))
2232 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2233 for_eh, /* empty */ 1);
2235 /* If we don't have any functions we'll want to unwind out of, don't
2236 emit any EH unwind information. Note that if exceptions aren't
2237 enabled, we won't have collected nothrow information, and if we
2238 asked for asynchronous tables, we always want this info. */
2241 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2243 for (i = 0; i < fde_table_in_use; i++)
2244 if (fde_table[i].uses_eh_lsda)
2245 any_eh_needed = any_lsda_needed = true;
2246 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2247 any_eh_needed = true;
2248 else if (! fde_table[i].nothrow
2249 && ! fde_table[i].all_throwers_are_sibcalls)
2250 any_eh_needed = true;
2252 if (! any_eh_needed)
2256 /* We're going to be generating comments, so turn on app. */
2261 switch_to_eh_frame_section ();
2264 if (!debug_frame_section)
2265 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2266 SECTION_DEBUG, NULL);
2267 switch_to_section (debug_frame_section);
2270 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2271 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2273 /* Output the CIE. */
2274 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2275 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2276 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2277 dw2_asm_output_data (4, 0xffffffff,
2278 "Initial length escape value indicating 64-bit DWARF extension");
2279 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2280 "Length of Common Information Entry");
2281 ASM_OUTPUT_LABEL (asm_out_file, l1);
2283 /* Now that the CIE pointer is PC-relative for EH,
2284 use 0 to identify the CIE. */
2285 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2286 (for_eh ? 0 : DWARF_CIE_ID),
2287 "CIE Identifier Tag");
2289 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2291 augmentation[0] = 0;
2292 augmentation_size = 0;
2298 z Indicates that a uleb128 is present to size the
2299 augmentation section.
2300 L Indicates the encoding (and thus presence) of
2301 an LSDA pointer in the FDE augmentation.
2302 R Indicates a non-default pointer encoding for
2304 P Indicates the presence of an encoding + language
2305 personality routine in the CIE augmentation. */
2307 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2308 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2309 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2311 p = augmentation + 1;
2312 if (eh_personality_libfunc)
2315 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2316 assemble_external_libcall (eh_personality_libfunc);
2318 if (any_lsda_needed)
2321 augmentation_size += 1;
2323 if (fde_encoding != DW_EH_PE_absptr)
2326 augmentation_size += 1;
2328 if (p > augmentation + 1)
2330 augmentation[0] = 'z';
2334 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2335 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2337 int offset = ( 4 /* Length */
2339 + 1 /* CIE version */
2340 + strlen (augmentation) + 1 /* Augmentation */
2341 + size_of_uleb128 (1) /* Code alignment */
2342 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2344 + 1 /* Augmentation size */
2345 + 1 /* Personality encoding */ );
2346 int pad = -offset & (PTR_SIZE - 1);
2348 augmentation_size += pad;
2350 /* Augmentations should be small, so there's scarce need to
2351 iterate for a solution. Die if we exceed one uleb128 byte. */
2352 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2356 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2357 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2358 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2359 "CIE Data Alignment Factor");
2361 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2362 if (DW_CIE_VERSION == 1)
2363 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2365 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2367 if (augmentation[0])
2369 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2370 if (eh_personality_libfunc)
2372 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2373 eh_data_format_name (per_encoding));
2374 dw2_asm_output_encoded_addr_rtx (per_encoding,
2375 eh_personality_libfunc,
2379 if (any_lsda_needed)
2380 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2381 eh_data_format_name (lsda_encoding));
2383 if (fde_encoding != DW_EH_PE_absptr)
2384 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2385 eh_data_format_name (fde_encoding));
2388 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2389 output_cfi (cfi, NULL, for_eh);
2391 /* Pad the CIE out to an address sized boundary. */
2392 ASM_OUTPUT_ALIGN (asm_out_file,
2393 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2394 ASM_OUTPUT_LABEL (asm_out_file, l2);
2396 /* Loop through all of the FDE's. */
2397 for (i = 0; i < fde_table_in_use; i++)
2399 fde = &fde_table[i];
2401 /* Don't emit EH unwind info for leaf functions that don't need it. */
2402 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2403 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2404 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2405 && !fde->uses_eh_lsda)
2408 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2409 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2410 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2411 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2412 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2413 dw2_asm_output_data (4, 0xffffffff,
2414 "Initial length escape value indicating 64-bit DWARF extension");
2415 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2417 ASM_OUTPUT_LABEL (asm_out_file, l1);
2420 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2422 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2423 debug_frame_section, "FDE CIE offset");
2427 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2428 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2429 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2432 "FDE initial location");
2433 if (fde->dw_fde_switched_sections)
2435 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2436 fde->dw_fde_unlikely_section_label);
2437 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2438 fde->dw_fde_hot_section_label);
2439 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2440 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2441 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2442 "FDE initial location");
2443 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2444 fde->dw_fde_hot_section_end_label,
2445 fde->dw_fde_hot_section_label,
2446 "FDE address range");
2447 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2448 "FDE initial location");
2449 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2450 fde->dw_fde_unlikely_section_end_label,
2451 fde->dw_fde_unlikely_section_label,
2452 "FDE address range");
2455 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2456 fde->dw_fde_end, fde->dw_fde_begin,
2457 "FDE address range");
2461 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2462 "FDE initial location");
2463 if (fde->dw_fde_switched_sections)
2465 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2466 fde->dw_fde_hot_section_label,
2467 "FDE initial location");
2468 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2469 fde->dw_fde_hot_section_end_label,
2470 fde->dw_fde_hot_section_label,
2471 "FDE address range");
2472 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2473 fde->dw_fde_unlikely_section_label,
2474 "FDE initial location");
2475 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2476 fde->dw_fde_unlikely_section_end_label,
2477 fde->dw_fde_unlikely_section_label,
2478 "FDE address range");
2481 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2482 fde->dw_fde_end, fde->dw_fde_begin,
2483 "FDE address range");
2486 if (augmentation[0])
2488 if (any_lsda_needed)
2490 int size = size_of_encoded_value (lsda_encoding);
2492 if (lsda_encoding == DW_EH_PE_aligned)
2494 int offset = ( 4 /* Length */
2495 + 4 /* CIE offset */
2496 + 2 * size_of_encoded_value (fde_encoding)
2497 + 1 /* Augmentation size */ );
2498 int pad = -offset & (PTR_SIZE - 1);
2501 gcc_assert (size_of_uleb128 (size) == 1);
2504 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2506 if (fde->uses_eh_lsda)
2508 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2509 fde->funcdef_number);
2510 dw2_asm_output_encoded_addr_rtx (
2511 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2512 false, "Language Specific Data Area");
2516 if (lsda_encoding == DW_EH_PE_aligned)
2517 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2519 (size_of_encoded_value (lsda_encoding), 0,
2520 "Language Specific Data Area (none)");
2524 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2527 /* Loop through the Call Frame Instructions associated with
2529 fde->dw_fde_current_label = fde->dw_fde_begin;
2530 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2531 output_cfi (cfi, fde, for_eh);
2533 /* Pad the FDE out to an address sized boundary. */
2534 ASM_OUTPUT_ALIGN (asm_out_file,
2535 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2536 ASM_OUTPUT_LABEL (asm_out_file, l2);
2539 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2540 dw2_asm_output_data (4, 0, "End of Table");
2541 #ifdef MIPS_DEBUGGING_INFO
2542 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2543 get a value of 0. Putting .align 0 after the label fixes it. */
2544 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2547 /* Turn off app to make assembly quicker. */
2552 /* Output a marker (i.e. a label) for the beginning of a function, before
2556 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2557 const char *file ATTRIBUTE_UNUSED)
2559 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2563 current_function_func_begin_label = NULL;
2565 #ifdef TARGET_UNWIND_INFO
2566 /* ??? current_function_func_begin_label is also used by except.c
2567 for call-site information. We must emit this label if it might
2569 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2570 && ! dwarf2out_do_frame ())
2573 if (! dwarf2out_do_frame ())
2577 switch_to_section (function_section (current_function_decl));
2578 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2579 current_function_funcdef_no);
2580 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2581 current_function_funcdef_no);
2582 dup_label = xstrdup (label);
2583 current_function_func_begin_label = dup_label;
2585 #ifdef TARGET_UNWIND_INFO
2586 /* We can elide the fde allocation if we're not emitting debug info. */
2587 if (! dwarf2out_do_frame ())
2591 /* Expand the fde table if necessary. */
2592 if (fde_table_in_use == fde_table_allocated)
2594 fde_table_allocated += FDE_TABLE_INCREMENT;
2595 fde_table = ggc_realloc (fde_table,
2596 fde_table_allocated * sizeof (dw_fde_node));
2597 memset (fde_table + fde_table_in_use, 0,
2598 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2601 /* Record the FDE associated with this function. */
2602 current_funcdef_fde = fde_table_in_use;
2604 /* Add the new FDE at the end of the fde_table. */
2605 fde = &fde_table[fde_table_in_use++];
2606 fde->decl = current_function_decl;
2607 fde->dw_fde_begin = dup_label;
2608 fde->dw_fde_current_label = dup_label;
2609 fde->dw_fde_hot_section_label = NULL;
2610 fde->dw_fde_hot_section_end_label = NULL;
2611 fde->dw_fde_unlikely_section_label = NULL;
2612 fde->dw_fde_unlikely_section_end_label = NULL;
2613 fde->dw_fde_switched_sections = false;
2614 fde->dw_fde_end = NULL;
2615 fde->dw_fde_cfi = NULL;
2616 fde->funcdef_number = current_function_funcdef_no;
2617 fde->nothrow = TREE_NOTHROW (current_function_decl);
2618 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2619 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2621 args_size = old_args_size = 0;
2623 /* We only want to output line number information for the genuine dwarf2
2624 prologue case, not the eh frame case. */
2625 #ifdef DWARF2_DEBUGGING_INFO
2627 dwarf2out_source_line (line, file);
2631 /* Output a marker (i.e. a label) for the absolute end of the generated code
2632 for a function definition. This gets called *after* the epilogue code has
2636 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2637 const char *file ATTRIBUTE_UNUSED)
2640 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2642 /* Output a label to mark the endpoint of the code generated for this
2644 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2645 current_function_funcdef_no);
2646 ASM_OUTPUT_LABEL (asm_out_file, label);
2647 fde = &fde_table[fde_table_in_use - 1];
2648 fde->dw_fde_end = xstrdup (label);
2652 dwarf2out_frame_init (void)
2654 /* Allocate the initial hunk of the fde_table. */
2655 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2656 fde_table_allocated = FDE_TABLE_INCREMENT;
2657 fde_table_in_use = 0;
2659 /* Generate the CFA instructions common to all FDE's. Do it now for the
2660 sake of lookup_cfa. */
2662 /* On entry, the Canonical Frame Address is at SP. */
2663 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2665 #ifdef DWARF2_UNWIND_INFO
2666 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2667 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2672 dwarf2out_frame_finish (void)
2674 /* Output call frame information. */
2675 if (DWARF2_FRAME_INFO)
2676 output_call_frame_info (0);
2678 #ifndef TARGET_UNWIND_INFO
2679 /* Output another copy for the unwinder. */
2680 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2681 output_call_frame_info (1);
2686 /* And now, the subset of the debugging information support code necessary
2687 for emitting location expressions. */
2689 /* Data about a single source file. */
2690 struct dwarf_file_data GTY(())
2692 const char * filename;
2696 /* We need some way to distinguish DW_OP_addr with a direct symbol
2697 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2698 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2701 typedef struct dw_val_struct *dw_val_ref;
2702 typedef struct die_struct *dw_die_ref;
2703 typedef const struct die_struct *const_dw_die_ref;
2704 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2705 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2707 /* Each DIE may have a series of attribute/value pairs. Values
2708 can take on several forms. The forms that are used in this
2709 implementation are listed below. */
2714 dw_val_class_offset,
2716 dw_val_class_loc_list,
2717 dw_val_class_range_list,
2719 dw_val_class_unsigned_const,
2720 dw_val_class_long_long,
2723 dw_val_class_die_ref,
2724 dw_val_class_fde_ref,
2725 dw_val_class_lbl_id,
2726 dw_val_class_lineptr,
2728 dw_val_class_macptr,
2732 /* Describe a double word constant value. */
2733 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2735 typedef struct dw_long_long_struct GTY(())
2742 /* Describe a floating point constant value, or a vector constant value. */
2744 typedef struct dw_vec_struct GTY(())
2746 unsigned char * GTY((length ("%h.length"))) array;
2752 /* The dw_val_node describes an attribute's value, as it is
2753 represented internally. */
2755 typedef struct dw_val_struct GTY(())
2757 enum dw_val_class val_class;
2758 union dw_val_struct_union
2760 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2761 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2762 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2763 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2764 HOST_WIDE_INT GTY ((default)) val_int;
2765 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2766 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2767 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2768 struct dw_val_die_union
2772 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2773 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2774 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2775 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2776 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2777 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2779 GTY ((desc ("%1.val_class"))) v;
2783 /* Locations in memory are described using a sequence of stack machine
2786 typedef struct dw_loc_descr_struct GTY(())
2788 dw_loc_descr_ref dw_loc_next;
2789 enum dwarf_location_atom dw_loc_opc;
2790 dw_val_node dw_loc_oprnd1;
2791 dw_val_node dw_loc_oprnd2;
2796 /* Location lists are ranges + location descriptions for that range,
2797 so you can track variables that are in different places over
2798 their entire life. */
2799 typedef struct dw_loc_list_struct GTY(())
2801 dw_loc_list_ref dw_loc_next;
2802 const char *begin; /* Label for begin address of range */
2803 const char *end; /* Label for end address of range */
2804 char *ll_symbol; /* Label for beginning of location list.
2805 Only on head of list */
2806 const char *section; /* Section this loclist is relative to */
2807 dw_loc_descr_ref expr;
2810 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2812 static const char *dwarf_stack_op_name (unsigned);
2813 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2814 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2815 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2816 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2817 static unsigned long size_of_locs (dw_loc_descr_ref);
2818 static void output_loc_operands (dw_loc_descr_ref);
2819 static void output_loc_sequence (dw_loc_descr_ref);
2821 /* Convert a DWARF stack opcode into its string name. */
2824 dwarf_stack_op_name (unsigned int op)
2829 case INTERNAL_DW_OP_tls_addr:
2830 return "DW_OP_addr";
2832 return "DW_OP_deref";
2834 return "DW_OP_const1u";
2836 return "DW_OP_const1s";
2838 return "DW_OP_const2u";
2840 return "DW_OP_const2s";
2842 return "DW_OP_const4u";
2844 return "DW_OP_const4s";
2846 return "DW_OP_const8u";
2848 return "DW_OP_const8s";
2850 return "DW_OP_constu";
2852 return "DW_OP_consts";
2856 return "DW_OP_drop";
2858 return "DW_OP_over";
2860 return "DW_OP_pick";
2862 return "DW_OP_swap";
2866 return "DW_OP_xderef";
2874 return "DW_OP_minus";
2886 return "DW_OP_plus";
2887 case DW_OP_plus_uconst:
2888 return "DW_OP_plus_uconst";
2894 return "DW_OP_shra";
2912 return "DW_OP_skip";
2914 return "DW_OP_lit0";
2916 return "DW_OP_lit1";
2918 return "DW_OP_lit2";
2920 return "DW_OP_lit3";
2922 return "DW_OP_lit4";
2924 return "DW_OP_lit5";
2926 return "DW_OP_lit6";
2928 return "DW_OP_lit7";
2930 return "DW_OP_lit8";
2932 return "DW_OP_lit9";
2934 return "DW_OP_lit10";
2936 return "DW_OP_lit11";
2938 return "DW_OP_lit12";
2940 return "DW_OP_lit13";
2942 return "DW_OP_lit14";
2944 return "DW_OP_lit15";
2946 return "DW_OP_lit16";
2948 return "DW_OP_lit17";
2950 return "DW_OP_lit18";
2952 return "DW_OP_lit19";
2954 return "DW_OP_lit20";
2956 return "DW_OP_lit21";
2958 return "DW_OP_lit22";
2960 return "DW_OP_lit23";
2962 return "DW_OP_lit24";
2964 return "DW_OP_lit25";
2966 return "DW_OP_lit26";
2968 return "DW_OP_lit27";
2970 return "DW_OP_lit28";
2972 return "DW_OP_lit29";
2974 return "DW_OP_lit30";
2976 return "DW_OP_lit31";
2978 return "DW_OP_reg0";
2980 return "DW_OP_reg1";
2982 return "DW_OP_reg2";
2984 return "DW_OP_reg3";
2986 return "DW_OP_reg4";
2988 return "DW_OP_reg5";
2990 return "DW_OP_reg6";
2992 return "DW_OP_reg7";
2994 return "DW_OP_reg8";
2996 return "DW_OP_reg9";
2998 return "DW_OP_reg10";
3000 return "DW_OP_reg11";
3002 return "DW_OP_reg12";
3004 return "DW_OP_reg13";
3006 return "DW_OP_reg14";
3008 return "DW_OP_reg15";
3010 return "DW_OP_reg16";
3012 return "DW_OP_reg17";
3014 return "DW_OP_reg18";
3016 return "DW_OP_reg19";
3018 return "DW_OP_reg20";
3020 return "DW_OP_reg21";
3022 return "DW_OP_reg22";
3024 return "DW_OP_reg23";
3026 return "DW_OP_reg24";
3028 return "DW_OP_reg25";
3030 return "DW_OP_reg26";
3032 return "DW_OP_reg27";
3034 return "DW_OP_reg28";
3036 return "DW_OP_reg29";
3038 return "DW_OP_reg30";
3040 return "DW_OP_reg31";
3042 return "DW_OP_breg0";
3044 return "DW_OP_breg1";
3046 return "DW_OP_breg2";
3048 return "DW_OP_breg3";
3050 return "DW_OP_breg4";
3052 return "DW_OP_breg5";
3054 return "DW_OP_breg6";
3056 return "DW_OP_breg7";
3058 return "DW_OP_breg8";
3060 return "DW_OP_breg9";
3062 return "DW_OP_breg10";
3064 return "DW_OP_breg11";
3066 return "DW_OP_breg12";
3068 return "DW_OP_breg13";
3070 return "DW_OP_breg14";
3072 return "DW_OP_breg15";
3074 return "DW_OP_breg16";
3076 return "DW_OP_breg17";
3078 return "DW_OP_breg18";
3080 return "DW_OP_breg19";
3082 return "DW_OP_breg20";
3084 return "DW_OP_breg21";
3086 return "DW_OP_breg22";
3088 return "DW_OP_breg23";
3090 return "DW_OP_breg24";
3092 return "DW_OP_breg25";
3094 return "DW_OP_breg26";
3096 return "DW_OP_breg27";
3098 return "DW_OP_breg28";
3100 return "DW_OP_breg29";
3102 return "DW_OP_breg30";
3104 return "DW_OP_breg31";
3106 return "DW_OP_regx";
3108 return "DW_OP_fbreg";
3110 return "DW_OP_bregx";
3112 return "DW_OP_piece";
3113 case DW_OP_deref_size:
3114 return "DW_OP_deref_size";
3115 case DW_OP_xderef_size:
3116 return "DW_OP_xderef_size";
3119 case DW_OP_push_object_address:
3120 return "DW_OP_push_object_address";
3122 return "DW_OP_call2";
3124 return "DW_OP_call4";
3125 case DW_OP_call_ref:
3126 return "DW_OP_call_ref";
3127 case DW_OP_GNU_push_tls_address:
3128 return "DW_OP_GNU_push_tls_address";
3129 case DW_OP_GNU_uninit:
3130 return "DW_OP_GNU_uninit";
3132 return "OP_<unknown>";
3136 /* Return a pointer to a newly allocated location description. Location
3137 descriptions are simple expression terms that can be strung
3138 together to form more complicated location (address) descriptions. */
3140 static inline dw_loc_descr_ref
3141 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3142 unsigned HOST_WIDE_INT oprnd2)
3144 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3146 descr->dw_loc_opc = op;
3147 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3148 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3149 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3150 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3155 /* Add a location description term to a location description expression. */
3158 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3160 dw_loc_descr_ref *d;
3162 /* Find the end of the chain. */
3163 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3169 /* Return the size of a location descriptor. */
3171 static unsigned long
3172 size_of_loc_descr (dw_loc_descr_ref loc)
3174 unsigned long size = 1;
3176 switch (loc->dw_loc_opc)
3179 case INTERNAL_DW_OP_tls_addr:
3180 size += DWARF2_ADDR_SIZE;
3199 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3202 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3207 case DW_OP_plus_uconst:
3208 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3246 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3249 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3252 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3255 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3256 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3259 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3261 case DW_OP_deref_size:
3262 case DW_OP_xderef_size:
3271 case DW_OP_call_ref:
3272 size += DWARF2_ADDR_SIZE;
3281 /* Return the size of a series of location descriptors. */
3283 static unsigned long
3284 size_of_locs (dw_loc_descr_ref loc)
3289 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3290 field, to avoid writing to a PCH file. */
3291 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3293 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3295 size += size_of_loc_descr (l);
3300 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3302 l->dw_loc_addr = size;
3303 size += size_of_loc_descr (l);
3309 /* Output location description stack opcode's operands (if any). */
3312 output_loc_operands (dw_loc_descr_ref loc)
3314 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3315 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3317 switch (loc->dw_loc_opc)
3319 #ifdef DWARF2_DEBUGGING_INFO
3321 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3325 dw2_asm_output_data (2, val1->v.val_int, NULL);
3329 dw2_asm_output_data (4, val1->v.val_int, NULL);
3333 gcc_assert (HOST_BITS_PER_LONG >= 64);
3334 dw2_asm_output_data (8, val1->v.val_int, NULL);
3341 gcc_assert (val1->val_class == dw_val_class_loc);
3342 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3344 dw2_asm_output_data (2, offset, NULL);
3357 /* We currently don't make any attempt to make sure these are
3358 aligned properly like we do for the main unwind info, so
3359 don't support emitting things larger than a byte if we're
3360 only doing unwinding. */
3365 dw2_asm_output_data (1, val1->v.val_int, NULL);
3368 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3371 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3374 dw2_asm_output_data (1, val1->v.val_int, NULL);
3376 case DW_OP_plus_uconst:
3377 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3411 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3414 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3417 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3420 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3421 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3424 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3426 case DW_OP_deref_size:
3427 case DW_OP_xderef_size:
3428 dw2_asm_output_data (1, val1->v.val_int, NULL);
3431 case INTERNAL_DW_OP_tls_addr:
3432 if (targetm.asm_out.output_dwarf_dtprel)
3434 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3437 fputc ('\n', asm_out_file);
3444 /* Other codes have no operands. */
3449 /* Output a sequence of location operations. */
3452 output_loc_sequence (dw_loc_descr_ref loc)
3454 for (; loc != NULL; loc = loc->dw_loc_next)
3456 /* Output the opcode. */
3457 dw2_asm_output_data (1, loc->dw_loc_opc,
3458 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3460 /* Output the operand(s) (if any). */
3461 output_loc_operands (loc);
3465 /* This routine will generate the correct assembly data for a location
3466 description based on a cfi entry with a complex address. */
3469 output_cfa_loc (dw_cfi_ref cfi)
3471 dw_loc_descr_ref loc;
3474 /* Output the size of the block. */
3475 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3476 size = size_of_locs (loc);
3477 dw2_asm_output_data_uleb128 (size, NULL);
3479 /* Now output the operations themselves. */
3480 output_loc_sequence (loc);
3483 /* This function builds a dwarf location descriptor sequence from a
3484 dw_cfa_location, adding the given OFFSET to the result of the
3487 static struct dw_loc_descr_struct *
3488 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3490 struct dw_loc_descr_struct *head, *tmp;
3492 offset += cfa->offset;
3496 if (cfa->base_offset)
3499 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3501 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3503 else if (cfa->reg <= 31)
3504 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3506 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3508 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3509 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3510 add_loc_descr (&head, tmp);
3513 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3514 add_loc_descr (&head, tmp);
3521 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3523 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3524 else if (cfa->reg <= 31)
3525 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3527 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3533 /* This function fills in aa dw_cfa_location structure from a dwarf location
3534 descriptor sequence. */
3537 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3539 struct dw_loc_descr_struct *ptr;
3541 cfa->base_offset = 0;
3545 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3547 enum dwarf_location_atom op = ptr->dw_loc_opc;
3583 cfa->reg = op - DW_OP_reg0;
3586 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3620 cfa->reg = op - DW_OP_breg0;
3621 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3624 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3625 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3630 case DW_OP_plus_uconst:
3631 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3634 internal_error ("DW_LOC_OP %s not implemented",
3635 dwarf_stack_op_name (ptr->dw_loc_opc));
3639 #endif /* .debug_frame support */
3641 /* And now, the support for symbolic debugging information. */
3642 #ifdef DWARF2_DEBUGGING_INFO
3644 /* .debug_str support. */
3645 static int output_indirect_string (void **, void *);
3647 static void dwarf2out_init (const char *);
3648 static void dwarf2out_finish (const char *);
3649 static void dwarf2out_define (unsigned int, const char *);
3650 static void dwarf2out_undef (unsigned int, const char *);
3651 static void dwarf2out_start_source_file (unsigned, const char *);
3652 static void dwarf2out_end_source_file (unsigned);
3653 static void dwarf2out_begin_block (unsigned, unsigned);
3654 static void dwarf2out_end_block (unsigned, unsigned);
3655 static bool dwarf2out_ignore_block (const_tree);
3656 static void dwarf2out_global_decl (tree);
3657 static void dwarf2out_type_decl (tree, int);
3658 static void dwarf2out_imported_module_or_decl (tree, tree);
3659 static void dwarf2out_abstract_function (tree);
3660 static void dwarf2out_var_location (rtx);
3661 static void dwarf2out_begin_function (tree);
3662 static void dwarf2out_switch_text_section (void);
3664 /* The debug hooks structure. */
3666 const struct gcc_debug_hooks dwarf2_debug_hooks =
3672 dwarf2out_start_source_file,
3673 dwarf2out_end_source_file,
3674 dwarf2out_begin_block,
3675 dwarf2out_end_block,
3676 dwarf2out_ignore_block,
3677 dwarf2out_source_line,
3678 dwarf2out_begin_prologue,
3679 debug_nothing_int_charstar, /* end_prologue */
3680 dwarf2out_end_epilogue,
3681 dwarf2out_begin_function,
3682 debug_nothing_int, /* end_function */
3683 dwarf2out_decl, /* function_decl */
3684 dwarf2out_global_decl,
3685 dwarf2out_type_decl, /* type_decl */
3686 dwarf2out_imported_module_or_decl,
3687 debug_nothing_tree, /* deferred_inline_function */
3688 /* The DWARF 2 backend tries to reduce debugging bloat by not
3689 emitting the abstract description of inline functions until
3690 something tries to reference them. */
3691 dwarf2out_abstract_function, /* outlining_inline_function */
3692 debug_nothing_rtx, /* label */
3693 debug_nothing_int, /* handle_pch */
3694 dwarf2out_var_location,
3695 dwarf2out_switch_text_section,
3696 1 /* start_end_main_source_file */
3700 /* NOTE: In the comments in this file, many references are made to
3701 "Debugging Information Entries". This term is abbreviated as `DIE'
3702 throughout the remainder of this file. */
3704 /* An internal representation of the DWARF output is built, and then
3705 walked to generate the DWARF debugging info. The walk of the internal
3706 representation is done after the entire program has been compiled.
3707 The types below are used to describe the internal representation. */
3709 /* Various DIE's use offsets relative to the beginning of the
3710 .debug_info section to refer to each other. */
3712 typedef long int dw_offset;
3714 /* Define typedefs here to avoid circular dependencies. */
3716 typedef struct dw_attr_struct *dw_attr_ref;
3717 typedef struct dw_line_info_struct *dw_line_info_ref;
3718 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3719 typedef struct pubname_struct *pubname_ref;
3720 typedef struct dw_ranges_struct *dw_ranges_ref;
3721 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3723 /* Each entry in the line_info_table maintains the file and
3724 line number associated with the label generated for that
3725 entry. The label gives the PC value associated with
3726 the line number entry. */
3728 typedef struct dw_line_info_struct GTY(())
3730 unsigned long dw_file_num;
3731 unsigned long dw_line_num;
3735 /* Line information for functions in separate sections; each one gets its
3737 typedef struct dw_separate_line_info_struct GTY(())
3739 unsigned long dw_file_num;
3740 unsigned long dw_line_num;
3741 unsigned long function;
3743 dw_separate_line_info_entry;
3745 /* Each DIE attribute has a field specifying the attribute kind,
3746 a link to the next attribute in the chain, and an attribute value.
3747 Attributes are typically linked below the DIE they modify. */
3749 typedef struct dw_attr_struct GTY(())
3751 enum dwarf_attribute dw_attr;
3752 dw_val_node dw_attr_val;
3756 DEF_VEC_O(dw_attr_node);
3757 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3759 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3760 The children of each node form a circular list linked by
3761 die_sib. die_child points to the node *before* the "first" child node. */
3763 typedef struct die_struct GTY(())
3765 enum dwarf_tag die_tag;
3767 VEC(dw_attr_node,gc) * die_attr;
3768 dw_die_ref die_parent;
3769 dw_die_ref die_child;
3771 dw_die_ref die_definition; /* ref from a specification to its definition */
3772 dw_offset die_offset;
3773 unsigned long die_abbrev;
3775 /* Die is used and must not be pruned as unused. */
3776 int die_perennial_p;
3777 unsigned int decl_id;
3781 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3782 #define FOR_EACH_CHILD(die, c, expr) do { \
3783 c = die->die_child; \
3787 } while (c != die->die_child); \
3790 /* The pubname structure */
3792 typedef struct pubname_struct GTY(())
3799 DEF_VEC_O(pubname_entry);
3800 DEF_VEC_ALLOC_O(pubname_entry, gc);
3802 struct dw_ranges_struct GTY(())
3804 /* If this is positive, it's a block number, otherwise it's a
3805 bitwise-negated index into dw_ranges_by_label. */
3809 struct dw_ranges_by_label_struct GTY(())
3815 /* The limbo die list structure. */
3816 typedef struct limbo_die_struct GTY(())
3820 struct limbo_die_struct *next;
3824 /* How to start an assembler comment. */
3825 #ifndef ASM_COMMENT_START
3826 #define ASM_COMMENT_START ";#"
3829 /* Define a macro which returns nonzero for a TYPE_DECL which was
3830 implicitly generated for a tagged type.
3832 Note that unlike the gcc front end (which generates a NULL named
3833 TYPE_DECL node for each complete tagged type, each array type, and
3834 each function type node created) the g++ front end generates a
3835 _named_ TYPE_DECL node for each tagged type node created.
3836 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3837 generate a DW_TAG_typedef DIE for them. */
3839 #define TYPE_DECL_IS_STUB(decl) \
3840 (DECL_NAME (decl) == NULL_TREE \
3841 || (DECL_ARTIFICIAL (decl) \
3842 && is_tagged_type (TREE_TYPE (decl)) \
3843 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3844 /* This is necessary for stub decls that \
3845 appear in nested inline functions. */ \
3846 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3847 && (decl_ultimate_origin (decl) \
3848 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3850 /* Information concerning the compilation unit's programming
3851 language, and compiler version. */
3853 /* Fixed size portion of the DWARF compilation unit header. */
3854 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3855 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3857 /* Fixed size portion of public names info. */
3858 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3860 /* Fixed size portion of the address range info. */
3861 #define DWARF_ARANGES_HEADER_SIZE \
3862 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3863 DWARF2_ADDR_SIZE * 2) \
3864 - DWARF_INITIAL_LENGTH_SIZE)
3866 /* Size of padding portion in the address range info. It must be
3867 aligned to twice the pointer size. */
3868 #define DWARF_ARANGES_PAD_SIZE \
3869 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3870 DWARF2_ADDR_SIZE * 2) \
3871 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3873 /* Use assembler line directives if available. */
3874 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3875 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3876 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3878 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3882 /* Minimum line offset in a special line info. opcode.
3883 This value was chosen to give a reasonable range of values. */
3884 #define DWARF_LINE_BASE -10
3886 /* First special line opcode - leave room for the standard opcodes. */
3887 #define DWARF_LINE_OPCODE_BASE 10
3889 /* Range of line offsets in a special line info. opcode. */
3890 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3892 /* Flag that indicates the initial value of the is_stmt_start flag.
3893 In the present implementation, we do not mark any lines as
3894 the beginning of a source statement, because that information
3895 is not made available by the GCC front-end. */
3896 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3898 #ifdef DWARF2_DEBUGGING_INFO
3899 /* This location is used by calc_die_sizes() to keep track
3900 the offset of each DIE within the .debug_info section. */
3901 static unsigned long next_die_offset;
3904 /* Record the root of the DIE's built for the current compilation unit. */
3905 static GTY(()) dw_die_ref comp_unit_die;
3907 /* A list of DIEs with a NULL parent waiting to be relocated. */
3908 static GTY(()) limbo_die_node *limbo_die_list;
3910 /* Filenames referenced by this compilation unit. */
3911 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3913 /* A hash table of references to DIE's that describe declarations.
3914 The key is a DECL_UID() which is a unique number identifying each decl. */
3915 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3917 /* Node of the variable location list. */
3918 struct var_loc_node GTY ((chain_next ("%h.next")))
3920 rtx GTY (()) var_loc_note;
3921 const char * GTY (()) label;
3922 const char * GTY (()) section_label;
3923 struct var_loc_node * GTY (()) next;
3926 /* Variable location list. */
3927 struct var_loc_list_def GTY (())
3929 struct var_loc_node * GTY (()) first;
3931 /* Do not mark the last element of the chained list because
3932 it is marked through the chain. */
3933 struct var_loc_node * GTY ((skip ("%h"))) last;
3935 /* DECL_UID of the variable decl. */
3936 unsigned int decl_id;
3938 typedef struct var_loc_list_def var_loc_list;
3941 /* Table of decl location linked lists. */
3942 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3944 /* A pointer to the base of a list of references to DIE's that
3945 are uniquely identified by their tag, presence/absence of
3946 children DIE's, and list of attribute/value pairs. */
3947 static GTY((length ("abbrev_die_table_allocated")))
3948 dw_die_ref *abbrev_die_table;
3950 /* Number of elements currently allocated for abbrev_die_table. */
3951 static GTY(()) unsigned abbrev_die_table_allocated;
3953 /* Number of elements in type_die_table currently in use. */
3954 static GTY(()) unsigned abbrev_die_table_in_use;
3956 /* Size (in elements) of increments by which we may expand the
3957 abbrev_die_table. */
3958 #define ABBREV_DIE_TABLE_INCREMENT 256
3960 /* A pointer to the base of a table that contains line information
3961 for each source code line in .text in the compilation unit. */
3962 static GTY((length ("line_info_table_allocated")))
3963 dw_line_info_ref line_info_table;
3965 /* Number of elements currently allocated for line_info_table. */
3966 static GTY(()) unsigned line_info_table_allocated;
3968 /* Number of elements in line_info_table currently in use. */
3969 static GTY(()) unsigned line_info_table_in_use;
3971 /* True if the compilation unit places functions in more than one section. */
3972 static GTY(()) bool have_multiple_function_sections = false;
3974 /* A pointer to the base of a table that contains line information
3975 for each source code line outside of .text in the compilation unit. */
3976 static GTY ((length ("separate_line_info_table_allocated")))
3977 dw_separate_line_info_ref separate_line_info_table;
3979 /* Number of elements currently allocated for separate_line_info_table. */
3980 static GTY(()) unsigned separate_line_info_table_allocated;
3982 /* Number of elements in separate_line_info_table currently in use. */
3983 static GTY(()) unsigned separate_line_info_table_in_use;
3985 /* Size (in elements) of increments by which we may expand the
3987 #define LINE_INFO_TABLE_INCREMENT 1024
3989 /* A pointer to the base of a table that contains a list of publicly
3990 accessible names. */
3991 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3993 /* A pointer to the base of a table that contains a list of publicly
3994 accessible types. */
3995 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3997 /* Array of dies for which we should generate .debug_arange info. */
3998 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4000 /* Number of elements currently allocated for arange_table. */
4001 static GTY(()) unsigned arange_table_allocated;
4003 /* Number of elements in arange_table currently in use. */
4004 static GTY(()) unsigned arange_table_in_use;
4006 /* Size (in elements) of increments by which we may expand the
4008 #define ARANGE_TABLE_INCREMENT 64
4010 /* Array of dies for which we should generate .debug_ranges info. */
4011 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4013 /* Number of elements currently allocated for ranges_table. */
4014 static GTY(()) unsigned ranges_table_allocated;
4016 /* Number of elements in ranges_table currently in use. */
4017 static GTY(()) unsigned ranges_table_in_use;
4019 /* Array of pairs of labels referenced in ranges_table. */
4020 static GTY ((length ("ranges_by_label_allocated")))
4021 dw_ranges_by_label_ref ranges_by_label;
4023 /* Number of elements currently allocated for ranges_by_label. */
4024 static GTY(()) unsigned ranges_by_label_allocated;
4026 /* Number of elements in ranges_by_label currently in use. */
4027 static GTY(()) unsigned ranges_by_label_in_use;
4029 /* Size (in elements) of increments by which we may expand the
4031 #define RANGES_TABLE_INCREMENT 64
4033 /* Whether we have location lists that need outputting */
4034 static GTY(()) bool have_location_lists;
4036 /* Unique label counter. */
4037 static GTY(()) unsigned int loclabel_num;
4039 #ifdef DWARF2_DEBUGGING_INFO
4040 /* Record whether the function being analyzed contains inlined functions. */
4041 static int current_function_has_inlines;
4043 #if 0 && defined (MIPS_DEBUGGING_INFO)
4044 static int comp_unit_has_inlines;
4047 /* The last file entry emitted by maybe_emit_file(). */
4048 static GTY(()) struct dwarf_file_data * last_emitted_file;
4050 /* Number of internal labels generated by gen_internal_sym(). */
4051 static GTY(()) int label_num;
4053 /* Cached result of previous call to lookup_filename. */
4054 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4056 /* Whether the default text and cold text sections have been used at
4059 static GTY(()) bool text_section_used = false;
4060 static GTY(()) bool cold_text_section_used = false;
4062 /* The default cold text section. */
4063 static GTY(()) section *cold_text_section;
4065 #ifdef DWARF2_DEBUGGING_INFO
4067 /* Offset from the "steady-state frame pointer" to the frame base,
4068 within the current function. */
4069 static HOST_WIDE_INT frame_pointer_fb_offset;
4071 /* Forward declarations for functions defined in this file. */
4073 static int is_pseudo_reg (const_rtx);
4074 static tree type_main_variant (tree);
4075 static int is_tagged_type (const_tree);
4076 static const char *dwarf_tag_name (unsigned);
4077 static const char *dwarf_attr_name (unsigned);
4078 static const char *dwarf_form_name (unsigned);
4079 static tree decl_ultimate_origin (const_tree);
4080 static tree block_ultimate_origin (const_tree);
4081 static tree decl_class_context (tree);
4082 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4083 static inline enum dw_val_class AT_class (dw_attr_ref);
4084 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4085 static inline unsigned AT_flag (dw_attr_ref);
4086 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4087 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4088 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4089 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4090 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4092 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4093 unsigned int, unsigned char *);
4094 static hashval_t debug_str_do_hash (const void *);
4095 static int debug_str_eq (const void *, const void *);
4096 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4097 static inline const char *AT_string (dw_attr_ref);
4098 static int AT_string_form (dw_attr_ref);
4099 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4100 static void add_AT_specification (dw_die_ref, dw_die_ref);
4101 static inline dw_die_ref AT_ref (dw_attr_ref);
4102 static inline int AT_ref_external (dw_attr_ref);
4103 static inline void set_AT_ref_external (dw_attr_ref, int);
4104 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4105 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4106 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4107 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4109 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4110 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4111 static inline rtx AT_addr (dw_attr_ref);
4112 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4113 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4114 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4115 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4116 unsigned HOST_WIDE_INT);
4117 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4119 static inline const char *AT_lbl (dw_attr_ref);
4120 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4121 static const char *get_AT_low_pc (dw_die_ref);
4122 static const char *get_AT_hi_pc (dw_die_ref);
4123 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4124 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4125 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4126 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4127 static bool is_c_family (void);
4128 static bool is_cxx (void);
4129 static bool is_java (void);
4130 static bool is_fortran (void);
4131 static bool is_ada (void);
4132 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4133 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4134 static void add_child_die (dw_die_ref, dw_die_ref);
4135 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4136 static dw_die_ref lookup_type_die (tree);
4137 static void equate_type_number_to_die (tree, dw_die_ref);
4138 static hashval_t decl_die_table_hash (const void *);
4139 static int decl_die_table_eq (const void *, const void *);
4140 static dw_die_ref lookup_decl_die (tree);
4141 static hashval_t decl_loc_table_hash (const void *);
4142 static int decl_loc_table_eq (const void *, const void *);
4143 static var_loc_list *lookup_decl_loc (const_tree);
4144 static void equate_decl_number_to_die (tree, dw_die_ref);
4145 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4146 static void print_spaces (FILE *);
4147 static void print_die (dw_die_ref, FILE *);
4148 static void print_dwarf_line_table (FILE *);
4149 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4150 static dw_die_ref pop_compile_unit (dw_die_ref);
4151 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4152 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4153 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4154 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4155 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4156 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4157 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4158 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4159 static void compute_section_prefix (dw_die_ref);
4160 static int is_type_die (dw_die_ref);
4161 static int is_comdat_die (dw_die_ref);
4162 static int is_symbol_die (dw_die_ref);
4163 static void assign_symbol_names (dw_die_ref);
4164 static void break_out_includes (dw_die_ref);
4165 static hashval_t htab_cu_hash (const void *);
4166 static int htab_cu_eq (const void *, const void *);
4167 static void htab_cu_del (void *);
4168 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4169 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4170 static void add_sibling_attributes (dw_die_ref);
4171 static void build_abbrev_table (dw_die_ref);
4172 static void output_location_lists (dw_die_ref);
4173 static int constant_size (long unsigned);
4174 static unsigned long size_of_die (dw_die_ref);
4175 static void calc_die_sizes (dw_die_ref);
4176 static void mark_dies (dw_die_ref);
4177 static void unmark_dies (dw_die_ref);
4178 static void unmark_all_dies (dw_die_ref);
4179 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4180 static unsigned long size_of_aranges (void);
4181 static enum dwarf_form value_format (dw_attr_ref);
4182 static void output_value_format (dw_attr_ref);
4183 static void output_abbrev_section (void);
4184 static void output_die_symbol (dw_die_ref);
4185 static void output_die (dw_die_ref);
4186 static void output_compilation_unit_header (void);
4187 static void output_comp_unit (dw_die_ref, int);
4188 static const char *dwarf2_name (tree, int);
4189 static void add_pubname (tree, dw_die_ref);
4190 static void add_pubtype (tree, dw_die_ref);
4191 static void output_pubnames (VEC (pubname_entry,gc) *);
4192 static void add_arange (tree, dw_die_ref);
4193 static void output_aranges (void);
4194 static unsigned int add_ranges_num (int);
4195 static unsigned int add_ranges (const_tree);
4196 static unsigned int add_ranges_by_labels (const char *, const char *);
4197 static void output_ranges (void);
4198 static void output_line_info (void);
4199 static void output_file_names (void);
4200 static dw_die_ref base_type_die (tree);
4201 static int is_base_type (tree);
4202 static bool is_subrange_type (const_tree);
4203 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4204 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4205 static int type_is_enum (const_tree);
4206 static unsigned int dbx_reg_number (const_rtx);
4207 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4208 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4209 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4210 enum var_init_status);
4211 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4212 enum var_init_status);
4213 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4214 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4215 enum var_init_status);
4216 static int is_based_loc (const_rtx);
4217 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4218 enum var_init_status);
4219 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4220 enum var_init_status);
4221 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4222 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4223 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4224 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4225 static tree field_type (const_tree);
4226 static unsigned int simple_type_align_in_bits (const_tree);
4227 static unsigned int simple_decl_align_in_bits (const_tree);
4228 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
4229 static HOST_WIDE_INT field_byte_offset (const_tree);
4230 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4232 static void add_data_member_location_attribute (dw_die_ref, tree);
4233 static void add_const_value_attribute (dw_die_ref, rtx);
4234 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4235 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4236 static void insert_float (const_rtx, unsigned char *);
4237 static rtx rtl_for_decl_location (tree);
4238 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4239 enum dwarf_attribute);
4240 static void tree_add_const_value_attribute (dw_die_ref, tree);
4241 static void add_name_attribute (dw_die_ref, const char *);
4242 static void add_comp_dir_attribute (dw_die_ref);
4243 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4244 static void add_subscript_info (dw_die_ref, tree);
4245 static void add_byte_size_attribute (dw_die_ref, tree);
4246 static void add_bit_offset_attribute (dw_die_ref, tree);
4247 static void add_bit_size_attribute (dw_die_ref, tree);
4248 static void add_prototyped_attribute (dw_die_ref, tree);
4249 static void add_abstract_origin_attribute (dw_die_ref, tree);
4250 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4251 static void add_src_coords_attributes (dw_die_ref, tree);
4252 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4253 static void push_decl_scope (tree);
4254 static void pop_decl_scope (void);
4255 static dw_die_ref scope_die_for (tree, dw_die_ref);
4256 static inline int local_scope_p (dw_die_ref);
4257 static inline int class_or_namespace_scope_p (dw_die_ref);
4258 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4259 static void add_calling_convention_attribute (dw_die_ref, tree);
4260 static const char *type_tag (const_tree);
4261 static tree member_declared_type (const_tree);
4263 static const char *decl_start_label (tree);
4265 static void gen_array_type_die (tree, dw_die_ref);
4266 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4268 static void gen_entry_point_die (tree, dw_die_ref);
4270 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4271 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4272 static void gen_inlined_union_type_die (tree, dw_die_ref);
4273 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4274 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4275 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4276 static void gen_formal_types_die (tree, dw_die_ref);
4277 static void gen_subprogram_die (tree, dw_die_ref);
4278 static void gen_variable_die (tree, dw_die_ref);
4279 static void gen_label_die (tree, dw_die_ref);
4280 static void gen_lexical_block_die (tree, dw_die_ref, int);
4281 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4282 static void gen_field_die (tree, dw_die_ref);
4283 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4284 static dw_die_ref gen_compile_unit_die (const char *);
4285 static void gen_inheritance_die (tree, tree, dw_die_ref);
4286 static void gen_member_die (tree, dw_die_ref);
4287 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4288 enum debug_info_usage);
4289 static void gen_subroutine_type_die (tree, dw_die_ref);
4290 static void gen_typedef_die (tree, dw_die_ref);
4291 static void gen_type_die (tree, dw_die_ref);
4292 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4293 static void gen_block_die (tree, dw_die_ref, int);
4294 static void decls_for_scope (tree, dw_die_ref, int);
4295 static int is_redundant_typedef (const_tree);
4296 static void gen_namespace_die (tree);
4297 static void gen_decl_die (tree, dw_die_ref);
4298 static dw_die_ref force_decl_die (tree);
4299 static dw_die_ref force_type_die (tree);
4300 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4301 static void declare_in_namespace (tree, dw_die_ref);
4302 static struct dwarf_file_data * lookup_filename (const char *);
4303 static void retry_incomplete_types (void);
4304 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4305 static void splice_child_die (dw_die_ref, dw_die_ref);
4306 static int file_info_cmp (const void *, const void *);
4307 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4308 const char *, const char *, unsigned);
4309 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4310 const char *, const char *,
4312 static void output_loc_list (dw_loc_list_ref);
4313 static char *gen_internal_sym (const char *);
4315 static void prune_unmark_dies (dw_die_ref);
4316 static void prune_unused_types_mark (dw_die_ref, int);
4317 static void prune_unused_types_walk (dw_die_ref);
4318 static void prune_unused_types_walk_attribs (dw_die_ref);
4319 static void prune_unused_types_prune (dw_die_ref);
4320 static void prune_unused_types (void);
4321 static int maybe_emit_file (struct dwarf_file_data *fd);
4323 /* Section names used to hold DWARF debugging information. */
4324 #ifndef DEBUG_INFO_SECTION
4325 #define DEBUG_INFO_SECTION ".debug_info"
4327 #ifndef DEBUG_ABBREV_SECTION
4328 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4330 #ifndef DEBUG_ARANGES_SECTION
4331 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4333 #ifndef DEBUG_MACINFO_SECTION
4334 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4336 #ifndef DEBUG_LINE_SECTION
4337 #define DEBUG_LINE_SECTION ".debug_line"
4339 #ifndef DEBUG_LOC_SECTION
4340 #define DEBUG_LOC_SECTION ".debug_loc"
4342 #ifndef DEBUG_PUBNAMES_SECTION
4343 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4345 #ifndef DEBUG_STR_SECTION
4346 #define DEBUG_STR_SECTION ".debug_str"
4348 #ifndef DEBUG_RANGES_SECTION
4349 #define DEBUG_RANGES_SECTION ".debug_ranges"
4352 /* Standard ELF section names for compiled code and data. */
4353 #ifndef TEXT_SECTION_NAME
4354 #define TEXT_SECTION_NAME ".text"
4357 /* Section flags for .debug_str section. */
4358 #define DEBUG_STR_SECTION_FLAGS \
4359 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4360 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4363 /* Labels we insert at beginning sections we can reference instead of
4364 the section names themselves. */
4366 #ifndef TEXT_SECTION_LABEL
4367 #define TEXT_SECTION_LABEL "Ltext"
4369 #ifndef COLD_TEXT_SECTION_LABEL
4370 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4372 #ifndef DEBUG_LINE_SECTION_LABEL
4373 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4375 #ifndef DEBUG_INFO_SECTION_LABEL
4376 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4378 #ifndef DEBUG_ABBREV_SECTION_LABEL
4379 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4381 #ifndef DEBUG_LOC_SECTION_LABEL
4382 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4384 #ifndef DEBUG_RANGES_SECTION_LABEL
4385 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4387 #ifndef DEBUG_MACINFO_SECTION_LABEL
4388 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4391 /* Definitions of defaults for formats and names of various special
4392 (artificial) labels which may be generated within this file (when the -g
4393 options is used and DWARF2_DEBUGGING_INFO is in effect.
4394 If necessary, these may be overridden from within the tm.h file, but
4395 typically, overriding these defaults is unnecessary. */
4397 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4398 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4399 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4400 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4401 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4402 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4403 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4404 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4405 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4406 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4408 #ifndef TEXT_END_LABEL
4409 #define TEXT_END_LABEL "Letext"
4411 #ifndef COLD_END_LABEL
4412 #define COLD_END_LABEL "Letext_cold"
4414 #ifndef BLOCK_BEGIN_LABEL
4415 #define BLOCK_BEGIN_LABEL "LBB"
4417 #ifndef BLOCK_END_LABEL
4418 #define BLOCK_END_LABEL "LBE"
4420 #ifndef LINE_CODE_LABEL
4421 #define LINE_CODE_LABEL "LM"
4423 #ifndef SEPARATE_LINE_CODE_LABEL
4424 #define SEPARATE_LINE_CODE_LABEL "LSM"
4428 /* We allow a language front-end to designate a function that is to be
4429 called to "demangle" any name before it is put into a DIE. */
4431 static const char *(*demangle_name_func) (const char *);
4434 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4436 demangle_name_func = func;
4439 /* Test if rtl node points to a pseudo register. */
4442 is_pseudo_reg (const_rtx rtl)
4444 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4445 || (GET_CODE (rtl) == SUBREG
4446 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4449 /* Return a reference to a type, with its const and volatile qualifiers
4453 type_main_variant (tree type)
4455 type = TYPE_MAIN_VARIANT (type);
4457 /* ??? There really should be only one main variant among any group of
4458 variants of a given type (and all of the MAIN_VARIANT values for all
4459 members of the group should point to that one type) but sometimes the C
4460 front-end messes this up for array types, so we work around that bug
4462 if (TREE_CODE (type) == ARRAY_TYPE)
4463 while (type != TYPE_MAIN_VARIANT (type))
4464 type = TYPE_MAIN_VARIANT (type);
4469 /* Return nonzero if the given type node represents a tagged type. */
4472 is_tagged_type (const_tree type)
4474 enum tree_code code = TREE_CODE (type);
4476 return (code == RECORD_TYPE || code == UNION_TYPE
4477 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4480 /* Convert a DIE tag into its string name. */
4483 dwarf_tag_name (unsigned int tag)
4487 case DW_TAG_padding:
4488 return "DW_TAG_padding";
4489 case DW_TAG_array_type:
4490 return "DW_TAG_array_type";
4491 case DW_TAG_class_type:
4492 return "DW_TAG_class_type";
4493 case DW_TAG_entry_point:
4494 return "DW_TAG_entry_point";
4495 case DW_TAG_enumeration_type:
4496 return "DW_TAG_enumeration_type";
4497 case DW_TAG_formal_parameter:
4498 return "DW_TAG_formal_parameter";
4499 case DW_TAG_imported_declaration:
4500 return "DW_TAG_imported_declaration";
4502 return "DW_TAG_label";
4503 case DW_TAG_lexical_block:
4504 return "DW_TAG_lexical_block";
4506 return "DW_TAG_member";
4507 case DW_TAG_pointer_type:
4508 return "DW_TAG_pointer_type";
4509 case DW_TAG_reference_type:
4510 return "DW_TAG_reference_type";
4511 case DW_TAG_compile_unit:
4512 return "DW_TAG_compile_unit";
4513 case DW_TAG_string_type:
4514 return "DW_TAG_string_type";
4515 case DW_TAG_structure_type:
4516 return "DW_TAG_structure_type";
4517 case DW_TAG_subroutine_type:
4518 return "DW_TAG_subroutine_type";
4519 case DW_TAG_typedef:
4520 return "DW_TAG_typedef";
4521 case DW_TAG_union_type:
4522 return "DW_TAG_union_type";
4523 case DW_TAG_unspecified_parameters:
4524 return "DW_TAG_unspecified_parameters";
4525 case DW_TAG_variant:
4526 return "DW_TAG_variant";
4527 case DW_TAG_common_block:
4528 return "DW_TAG_common_block";
4529 case DW_TAG_common_inclusion:
4530 return "DW_TAG_common_inclusion";
4531 case DW_TAG_inheritance:
4532 return "DW_TAG_inheritance";
4533 case DW_TAG_inlined_subroutine:
4534 return "DW_TAG_inlined_subroutine";
4536 return "DW_TAG_module";
4537 case DW_TAG_ptr_to_member_type:
4538 return "DW_TAG_ptr_to_member_type";
4539 case DW_TAG_set_type:
4540 return "DW_TAG_set_type";
4541 case DW_TAG_subrange_type:
4542 return "DW_TAG_subrange_type";
4543 case DW_TAG_with_stmt:
4544 return "DW_TAG_with_stmt";
4545 case DW_TAG_access_declaration:
4546 return "DW_TAG_access_declaration";
4547 case DW_TAG_base_type:
4548 return "DW_TAG_base_type";
4549 case DW_TAG_catch_block:
4550 return "DW_TAG_catch_block";
4551 case DW_TAG_const_type:
4552 return "DW_TAG_const_type";
4553 case DW_TAG_constant:
4554 return "DW_TAG_constant";
4555 case DW_TAG_enumerator:
4556 return "DW_TAG_enumerator";
4557 case DW_TAG_file_type:
4558 return "DW_TAG_file_type";
4560 return "DW_TAG_friend";
4561 case DW_TAG_namelist:
4562 return "DW_TAG_namelist";
4563 case DW_TAG_namelist_item:
4564 return "DW_TAG_namelist_item";
4565 case DW_TAG_namespace:
4566 return "DW_TAG_namespace";
4567 case DW_TAG_packed_type:
4568 return "DW_TAG_packed_type";
4569 case DW_TAG_subprogram:
4570 return "DW_TAG_subprogram";
4571 case DW_TAG_template_type_param:
4572 return "DW_TAG_template_type_param";
4573 case DW_TAG_template_value_param:
4574 return "DW_TAG_template_value_param";
4575 case DW_TAG_thrown_type:
4576 return "DW_TAG_thrown_type";
4577 case DW_TAG_try_block:
4578 return "DW_TAG_try_block";
4579 case DW_TAG_variant_part:
4580 return "DW_TAG_variant_part";
4581 case DW_TAG_variable:
4582 return "DW_TAG_variable";
4583 case DW_TAG_volatile_type:
4584 return "DW_TAG_volatile_type";
4585 case DW_TAG_imported_module:
4586 return "DW_TAG_imported_module";
4587 case DW_TAG_MIPS_loop:
4588 return "DW_TAG_MIPS_loop";
4589 case DW_TAG_format_label:
4590 return "DW_TAG_format_label";
4591 case DW_TAG_function_template:
4592 return "DW_TAG_function_template";
4593 case DW_TAG_class_template:
4594 return "DW_TAG_class_template";
4595 case DW_TAG_GNU_BINCL:
4596 return "DW_TAG_GNU_BINCL";
4597 case DW_TAG_GNU_EINCL:
4598 return "DW_TAG_GNU_EINCL";
4600 return "DW_TAG_<unknown>";
4604 /* Convert a DWARF attribute code into its string name. */
4607 dwarf_attr_name (unsigned int attr)
4612 return "DW_AT_sibling";
4613 case DW_AT_location:
4614 return "DW_AT_location";
4616 return "DW_AT_name";
4617 case DW_AT_ordering:
4618 return "DW_AT_ordering";
4619 case DW_AT_subscr_data:
4620 return "DW_AT_subscr_data";
4621 case DW_AT_byte_size:
4622 return "DW_AT_byte_size";
4623 case DW_AT_bit_offset:
4624 return "DW_AT_bit_offset";
4625 case DW_AT_bit_size:
4626 return "DW_AT_bit_size";
4627 case DW_AT_element_list:
4628 return "DW_AT_element_list";
4629 case DW_AT_stmt_list:
4630 return "DW_AT_stmt_list";
4632 return "DW_AT_low_pc";
4634 return "DW_AT_high_pc";
4635 case DW_AT_language:
4636 return "DW_AT_language";
4638 return "DW_AT_member";
4640 return "DW_AT_discr";
4641 case DW_AT_discr_value:
4642 return "DW_AT_discr_value";
4643 case DW_AT_visibility:
4644 return "DW_AT_visibility";
4646 return "DW_AT_import";
4647 case DW_AT_string_length:
4648 return "DW_AT_string_length";
4649 case DW_AT_common_reference:
4650 return "DW_AT_common_reference";
4651 case DW_AT_comp_dir:
4652 return "DW_AT_comp_dir";
4653 case DW_AT_const_value:
4654 return "DW_AT_const_value";
4655 case DW_AT_containing_type:
4656 return "DW_AT_containing_type";
4657 case DW_AT_default_value:
4658 return "DW_AT_default_value";
4660 return "DW_AT_inline";
4661 case DW_AT_is_optional:
4662 return "DW_AT_is_optional";
4663 case DW_AT_lower_bound:
4664 return "DW_AT_lower_bound";
4665 case DW_AT_producer:
4666 return "DW_AT_producer";
4667 case DW_AT_prototyped:
4668 return "DW_AT_prototyped";
4669 case DW_AT_return_addr:
4670 return "DW_AT_return_addr";
4671 case DW_AT_start_scope:
4672 return "DW_AT_start_scope";
4673 case DW_AT_bit_stride:
4674 return "DW_AT_bit_stride";
4675 case DW_AT_upper_bound:
4676 return "DW_AT_upper_bound";
4677 case DW_AT_abstract_origin:
4678 return "DW_AT_abstract_origin";
4679 case DW_AT_accessibility:
4680 return "DW_AT_accessibility";
4681 case DW_AT_address_class:
4682 return "DW_AT_address_class";
4683 case DW_AT_artificial:
4684 return "DW_AT_artificial";
4685 case DW_AT_base_types:
4686 return "DW_AT_base_types";
4687 case DW_AT_calling_convention:
4688 return "DW_AT_calling_convention";
4690 return "DW_AT_count";
4691 case DW_AT_data_member_location:
4692 return "DW_AT_data_member_location";
4693 case DW_AT_decl_column:
4694 return "DW_AT_decl_column";
4695 case DW_AT_decl_file:
4696 return "DW_AT_decl_file";
4697 case DW_AT_decl_line:
4698 return "DW_AT_decl_line";
4699 case DW_AT_declaration:
4700 return "DW_AT_declaration";
4701 case DW_AT_discr_list:
4702 return "DW_AT_discr_list";
4703 case DW_AT_encoding:
4704 return "DW_AT_encoding";
4705 case DW_AT_external:
4706 return "DW_AT_external";
4707 case DW_AT_frame_base:
4708 return "DW_AT_frame_base";
4710 return "DW_AT_friend";
4711 case DW_AT_identifier_case:
4712 return "DW_AT_identifier_case";
4713 case DW_AT_macro_info:
4714 return "DW_AT_macro_info";
4715 case DW_AT_namelist_items:
4716 return "DW_AT_namelist_items";
4717 case DW_AT_priority:
4718 return "DW_AT_priority";
4720 return "DW_AT_segment";
4721 case DW_AT_specification:
4722 return "DW_AT_specification";
4723 case DW_AT_static_link:
4724 return "DW_AT_static_link";
4726 return "DW_AT_type";
4727 case DW_AT_use_location:
4728 return "DW_AT_use_location";
4729 case DW_AT_variable_parameter:
4730 return "DW_AT_variable_parameter";
4731 case DW_AT_virtuality:
4732 return "DW_AT_virtuality";
4733 case DW_AT_vtable_elem_location:
4734 return "DW_AT_vtable_elem_location";
4736 case DW_AT_allocated:
4737 return "DW_AT_allocated";
4738 case DW_AT_associated:
4739 return "DW_AT_associated";
4740 case DW_AT_data_location:
4741 return "DW_AT_data_location";
4742 case DW_AT_byte_stride:
4743 return "DW_AT_byte_stride";
4744 case DW_AT_entry_pc:
4745 return "DW_AT_entry_pc";
4746 case DW_AT_use_UTF8:
4747 return "DW_AT_use_UTF8";
4748 case DW_AT_extension:
4749 return "DW_AT_extension";
4751 return "DW_AT_ranges";
4752 case DW_AT_trampoline:
4753 return "DW_AT_trampoline";
4754 case DW_AT_call_column:
4755 return "DW_AT_call_column";
4756 case DW_AT_call_file:
4757 return "DW_AT_call_file";
4758 case DW_AT_call_line:
4759 return "DW_AT_call_line";
4761 case DW_AT_MIPS_fde:
4762 return "DW_AT_MIPS_fde";
4763 case DW_AT_MIPS_loop_begin:
4764 return "DW_AT_MIPS_loop_begin";
4765 case DW_AT_MIPS_tail_loop_begin:
4766 return "DW_AT_MIPS_tail_loop_begin";
4767 case DW_AT_MIPS_epilog_begin:
4768 return "DW_AT_MIPS_epilog_begin";
4769 case DW_AT_MIPS_loop_unroll_factor:
4770 return "DW_AT_MIPS_loop_unroll_factor";
4771 case DW_AT_MIPS_software_pipeline_depth:
4772 return "DW_AT_MIPS_software_pipeline_depth";
4773 case DW_AT_MIPS_linkage_name:
4774 return "DW_AT_MIPS_linkage_name";
4775 case DW_AT_MIPS_stride:
4776 return "DW_AT_MIPS_stride";
4777 case DW_AT_MIPS_abstract_name:
4778 return "DW_AT_MIPS_abstract_name";
4779 case DW_AT_MIPS_clone_origin:
4780 return "DW_AT_MIPS_clone_origin";
4781 case DW_AT_MIPS_has_inlines:
4782 return "DW_AT_MIPS_has_inlines";
4784 case DW_AT_sf_names:
4785 return "DW_AT_sf_names";
4786 case DW_AT_src_info:
4787 return "DW_AT_src_info";
4788 case DW_AT_mac_info:
4789 return "DW_AT_mac_info";
4790 case DW_AT_src_coords:
4791 return "DW_AT_src_coords";
4792 case DW_AT_body_begin:
4793 return "DW_AT_body_begin";
4794 case DW_AT_body_end:
4795 return "DW_AT_body_end";
4796 case DW_AT_GNU_vector:
4797 return "DW_AT_GNU_vector";
4799 case DW_AT_VMS_rtnbeg_pd_address:
4800 return "DW_AT_VMS_rtnbeg_pd_address";
4803 return "DW_AT_<unknown>";
4807 /* Convert a DWARF value form code into its string name. */
4810 dwarf_form_name (unsigned int form)
4815 return "DW_FORM_addr";
4816 case DW_FORM_block2:
4817 return "DW_FORM_block2";
4818 case DW_FORM_block4:
4819 return "DW_FORM_block4";
4821 return "DW_FORM_data2";
4823 return "DW_FORM_data4";
4825 return "DW_FORM_data8";
4826 case DW_FORM_string:
4827 return "DW_FORM_string";
4829 return "DW_FORM_block";
4830 case DW_FORM_block1:
4831 return "DW_FORM_block1";
4833 return "DW_FORM_data1";
4835 return "DW_FORM_flag";
4837 return "DW_FORM_sdata";
4839 return "DW_FORM_strp";
4841 return "DW_FORM_udata";
4842 case DW_FORM_ref_addr:
4843 return "DW_FORM_ref_addr";
4845 return "DW_FORM_ref1";
4847 return "DW_FORM_ref2";
4849 return "DW_FORM_ref4";
4851 return "DW_FORM_ref8";
4852 case DW_FORM_ref_udata:
4853 return "DW_FORM_ref_udata";
4854 case DW_FORM_indirect:
4855 return "DW_FORM_indirect";
4857 return "DW_FORM_<unknown>";
4861 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4862 instance of an inlined instance of a decl which is local to an inline
4863 function, so we have to trace all of the way back through the origin chain
4864 to find out what sort of node actually served as the original seed for the
4868 decl_ultimate_origin (const_tree decl)
4870 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4873 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4874 nodes in the function to point to themselves; ignore that if
4875 we're trying to output the abstract instance of this function. */
4876 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4879 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4880 most distant ancestor, this should never happen. */
4881 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4883 return DECL_ABSTRACT_ORIGIN (decl);
4886 /* Determine the "ultimate origin" of a block. The block may be an inlined
4887 instance of an inlined instance of a block which is local to an inline
4888 function, so we have to trace all of the way back through the origin chain
4889 to find out what sort of node actually served as the original seed for the
4893 block_ultimate_origin (const_tree block)
4895 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4897 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4898 nodes in the function to point to themselves; ignore that if
4899 we're trying to output the abstract instance of this function. */
4900 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4903 if (immediate_origin == NULL_TREE)
4908 tree lookahead = immediate_origin;
4912 ret_val = lookahead;
4913 lookahead = (TREE_CODE (ret_val) == BLOCK
4914 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4916 while (lookahead != NULL && lookahead != ret_val);
4918 /* The block's abstract origin chain may not be the *ultimate* origin of
4919 the block. It could lead to a DECL that has an abstract origin set.
4920 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4921 will give us if it has one). Note that DECL's abstract origins are
4922 supposed to be the most distant ancestor (or so decl_ultimate_origin
4923 claims), so we don't need to loop following the DECL origins. */
4924 if (DECL_P (ret_val))
4925 return DECL_ORIGIN (ret_val);
4931 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4932 of a virtual function may refer to a base class, so we check the 'this'
4936 decl_class_context (tree decl)
4938 tree context = NULL_TREE;
4940 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4941 context = DECL_CONTEXT (decl);
4943 context = TYPE_MAIN_VARIANT
4944 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4946 if (context && !TYPE_P (context))
4947 context = NULL_TREE;
4952 /* Add an attribute/value pair to a DIE. */
4955 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4957 /* Maybe this should be an assert? */
4961 if (die->die_attr == NULL)
4962 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4963 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4966 static inline enum dw_val_class
4967 AT_class (dw_attr_ref a)
4969 return a->dw_attr_val.val_class;
4972 /* Add a flag value attribute to a DIE. */
4975 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4979 attr.dw_attr = attr_kind;
4980 attr.dw_attr_val.val_class = dw_val_class_flag;
4981 attr.dw_attr_val.v.val_flag = flag;
4982 add_dwarf_attr (die, &attr);
4985 static inline unsigned
4986 AT_flag (dw_attr_ref a)
4988 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4989 return a->dw_attr_val.v.val_flag;
4992 /* Add a signed integer attribute value to a DIE. */
4995 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4999 attr.dw_attr = attr_kind;
5000 attr.dw_attr_val.val_class = dw_val_class_const;
5001 attr.dw_attr_val.v.val_int = int_val;
5002 add_dwarf_attr (die, &attr);
5005 static inline HOST_WIDE_INT
5006 AT_int (dw_attr_ref a)
5008 gcc_assert (a && AT_class (a) == dw_val_class_const);
5009 return a->dw_attr_val.v.val_int;
5012 /* Add an unsigned integer attribute value to a DIE. */
5015 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5016 unsigned HOST_WIDE_INT unsigned_val)
5020 attr.dw_attr = attr_kind;
5021 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5022 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5023 add_dwarf_attr (die, &attr);
5026 static inline unsigned HOST_WIDE_INT
5027 AT_unsigned (dw_attr_ref a)
5029 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5030 return a->dw_attr_val.v.val_unsigned;
5033 /* Add an unsigned double integer attribute value to a DIE. */
5036 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5037 long unsigned int val_hi, long unsigned int val_low)
5041 attr.dw_attr = attr_kind;
5042 attr.dw_attr_val.val_class = dw_val_class_long_long;
5043 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5044 attr.dw_attr_val.v.val_long_long.low = val_low;
5045 add_dwarf_attr (die, &attr);
5048 /* Add a floating point attribute value to a DIE and return it. */
5051 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5052 unsigned int length, unsigned int elt_size, unsigned char *array)
5056 attr.dw_attr = attr_kind;
5057 attr.dw_attr_val.val_class = dw_val_class_vec;
5058 attr.dw_attr_val.v.val_vec.length = length;
5059 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5060 attr.dw_attr_val.v.val_vec.array = array;
5061 add_dwarf_attr (die, &attr);
5064 /* Hash and equality functions for debug_str_hash. */
5067 debug_str_do_hash (const void *x)
5069 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5073 debug_str_eq (const void *x1, const void *x2)
5075 return strcmp ((((const struct indirect_string_node *)x1)->str),
5076 (const char *)x2) == 0;
5079 /* Add a string attribute value to a DIE. */
5082 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5085 struct indirect_string_node *node;
5088 if (! debug_str_hash)
5089 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5090 debug_str_eq, NULL);
5092 slot = htab_find_slot_with_hash (debug_str_hash, str,
5093 htab_hash_string (str), INSERT);
5096 node = (struct indirect_string_node *)
5097 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5098 node->str = ggc_strdup (str);
5102 node = (struct indirect_string_node *) *slot;
5106 attr.dw_attr = attr_kind;
5107 attr.dw_attr_val.val_class = dw_val_class_str;
5108 attr.dw_attr_val.v.val_str = node;
5109 add_dwarf_attr (die, &attr);
5112 static inline const char *
5113 AT_string (dw_attr_ref a)
5115 gcc_assert (a && AT_class (a) == dw_val_class_str);
5116 return a->dw_attr_val.v.val_str->str;
5119 /* Find out whether a string should be output inline in DIE
5120 or out-of-line in .debug_str section. */
5123 AT_string_form (dw_attr_ref a)
5125 struct indirect_string_node *node;
5129 gcc_assert (a && AT_class (a) == dw_val_class_str);
5131 node = a->dw_attr_val.v.val_str;
5135 len = strlen (node->str) + 1;
5137 /* If the string is shorter or equal to the size of the reference, it is
5138 always better to put it inline. */
5139 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5140 return node->form = DW_FORM_string;
5142 /* If we cannot expect the linker to merge strings in .debug_str
5143 section, only put it into .debug_str if it is worth even in this
5145 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5146 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5147 return node->form = DW_FORM_string;
5149 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5150 ++dw2_string_counter;
5151 node->label = xstrdup (label);
5153 return node->form = DW_FORM_strp;
5156 /* Add a DIE reference attribute value to a DIE. */
5159 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5163 attr.dw_attr = attr_kind;
5164 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5165 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5166 attr.dw_attr_val.v.val_die_ref.external = 0;
5167 add_dwarf_attr (die, &attr);
5170 /* Add an AT_specification attribute to a DIE, and also make the back
5171 pointer from the specification to the definition. */
5174 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5176 add_AT_die_ref (die, DW_AT_specification, targ_die);
5177 gcc_assert (!targ_die->die_definition);
5178 targ_die->die_definition = die;
5181 static inline dw_die_ref
5182 AT_ref (dw_attr_ref a)
5184 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5185 return a->dw_attr_val.v.val_die_ref.die;
5189 AT_ref_external (dw_attr_ref a)
5191 if (a && AT_class (a) == dw_val_class_die_ref)
5192 return a->dw_attr_val.v.val_die_ref.external;
5198 set_AT_ref_external (dw_attr_ref a, int i)
5200 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5201 a->dw_attr_val.v.val_die_ref.external = i;
5204 /* Add an FDE reference attribute value to a DIE. */
5207 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5211 attr.dw_attr = attr_kind;
5212 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5213 attr.dw_attr_val.v.val_fde_index = targ_fde;
5214 add_dwarf_attr (die, &attr);
5217 /* Add a location description attribute value to a DIE. */
5220 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5224 attr.dw_attr = attr_kind;
5225 attr.dw_attr_val.val_class = dw_val_class_loc;
5226 attr.dw_attr_val.v.val_loc = loc;
5227 add_dwarf_attr (die, &attr);
5230 static inline dw_loc_descr_ref
5231 AT_loc (dw_attr_ref a)
5233 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5234 return a->dw_attr_val.v.val_loc;
5238 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5242 attr.dw_attr = attr_kind;
5243 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5244 attr.dw_attr_val.v.val_loc_list = loc_list;
5245 add_dwarf_attr (die, &attr);
5246 have_location_lists = true;
5249 static inline dw_loc_list_ref
5250 AT_loc_list (dw_attr_ref a)
5252 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5253 return a->dw_attr_val.v.val_loc_list;
5256 /* Add an address constant attribute value to a DIE. */
5259 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5263 attr.dw_attr = attr_kind;
5264 attr.dw_attr_val.val_class = dw_val_class_addr;
5265 attr.dw_attr_val.v.val_addr = addr;
5266 add_dwarf_attr (die, &attr);
5269 /* Get the RTX from to an address DIE attribute. */
5272 AT_addr (dw_attr_ref a)
5274 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5275 return a->dw_attr_val.v.val_addr;
5278 /* Add a file attribute value to a DIE. */
5281 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5282 struct dwarf_file_data *fd)
5286 attr.dw_attr = attr_kind;
5287 attr.dw_attr_val.val_class = dw_val_class_file;
5288 attr.dw_attr_val.v.val_file = fd;
5289 add_dwarf_attr (die, &attr);
5292 /* Get the dwarf_file_data from a file DIE attribute. */
5294 static inline struct dwarf_file_data *
5295 AT_file (dw_attr_ref a)
5297 gcc_assert (a && AT_class (a) == dw_val_class_file);
5298 return a->dw_attr_val.v.val_file;
5301 /* Add a label identifier attribute value to a DIE. */
5304 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5308 attr.dw_attr = attr_kind;
5309 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5310 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5311 add_dwarf_attr (die, &attr);
5314 /* Add a section offset attribute value to a DIE, an offset into the
5315 debug_line section. */
5318 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5323 attr.dw_attr = attr_kind;
5324 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5325 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5326 add_dwarf_attr (die, &attr);
5329 /* Add a section offset attribute value to a DIE, an offset into the
5330 debug_macinfo section. */
5333 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5338 attr.dw_attr = attr_kind;
5339 attr.dw_attr_val.val_class = dw_val_class_macptr;
5340 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5341 add_dwarf_attr (die, &attr);
5344 /* Add an offset attribute value to a DIE. */
5347 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5348 unsigned HOST_WIDE_INT offset)
5352 attr.dw_attr = attr_kind;
5353 attr.dw_attr_val.val_class = dw_val_class_offset;
5354 attr.dw_attr_val.v.val_offset = offset;
5355 add_dwarf_attr (die, &attr);
5358 /* Add an range_list attribute value to a DIE. */
5361 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5362 long unsigned int offset)
5366 attr.dw_attr = attr_kind;
5367 attr.dw_attr_val.val_class = dw_val_class_range_list;
5368 attr.dw_attr_val.v.val_offset = offset;
5369 add_dwarf_attr (die, &attr);
5372 static inline const char *
5373 AT_lbl (dw_attr_ref a)
5375 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5376 || AT_class (a) == dw_val_class_lineptr
5377 || AT_class (a) == dw_val_class_macptr));
5378 return a->dw_attr_val.v.val_lbl_id;
5381 /* Get the attribute of type attr_kind. */
5384 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5388 dw_die_ref spec = NULL;
5393 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5394 if (a->dw_attr == attr_kind)
5396 else if (a->dw_attr == DW_AT_specification
5397 || a->dw_attr == DW_AT_abstract_origin)
5401 return get_AT (spec, attr_kind);
5406 /* Return the "low pc" attribute value, typically associated with a subprogram
5407 DIE. Return null if the "low pc" attribute is either not present, or if it
5408 cannot be represented as an assembler label identifier. */
5410 static inline const char *
5411 get_AT_low_pc (dw_die_ref die)
5413 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5415 return a ? AT_lbl (a) : NULL;
5418 /* Return the "high pc" attribute value, typically associated with a subprogram
5419 DIE. Return null if the "high pc" attribute is either not present, or if it
5420 cannot be represented as an assembler label identifier. */
5422 static inline const char *
5423 get_AT_hi_pc (dw_die_ref die)
5425 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5427 return a ? AT_lbl (a) : NULL;
5430 /* Return the value of the string attribute designated by ATTR_KIND, or
5431 NULL if it is not present. */
5433 static inline const char *
5434 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5436 dw_attr_ref a = get_AT (die, attr_kind);
5438 return a ? AT_string (a) : NULL;
5441 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5442 if it is not present. */
5445 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5447 dw_attr_ref a = get_AT (die, attr_kind);
5449 return a ? AT_flag (a) : 0;
5452 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5453 if it is not present. */
5455 static inline unsigned
5456 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5458 dw_attr_ref a = get_AT (die, attr_kind);
5460 return a ? AT_unsigned (a) : 0;
5463 static inline dw_die_ref
5464 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5466 dw_attr_ref a = get_AT (die, attr_kind);
5468 return a ? AT_ref (a) : NULL;
5471 static inline struct dwarf_file_data *
5472 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5474 dw_attr_ref a = get_AT (die, attr_kind);
5476 return a ? AT_file (a) : NULL;
5479 /* Return TRUE if the language is C or C++. */
5484 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5486 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5487 || lang == DW_LANG_C99
5488 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5491 /* Return TRUE if the language is C++. */
5496 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5498 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5501 /* Return TRUE if the language is Fortran. */
5506 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5508 return (lang == DW_LANG_Fortran77
5509 || lang == DW_LANG_Fortran90
5510 || lang == DW_LANG_Fortran95);
5513 /* Return TRUE if the language is Java. */
5518 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5520 return lang == DW_LANG_Java;
5523 /* Return TRUE if the language is Ada. */
5528 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5530 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5533 /* Remove the specified attribute if present. */
5536 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5544 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5545 if (a->dw_attr == attr_kind)
5547 if (AT_class (a) == dw_val_class_str)
5548 if (a->dw_attr_val.v.val_str->refcount)
5549 a->dw_attr_val.v.val_str->refcount--;
5551 /* VEC_ordered_remove should help reduce the number of abbrevs
5553 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5558 /* Remove CHILD from its parent. PREV must have the property that
5559 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5562 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5564 gcc_assert (child->die_parent == prev->die_parent);
5565 gcc_assert (prev->die_sib == child);
5568 gcc_assert (child->die_parent->die_child == child);
5572 prev->die_sib = child->die_sib;
5573 if (child->die_parent->die_child == child)
5574 child->die_parent->die_child = prev;
5577 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5581 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5587 dw_die_ref prev = c;
5589 while (c->die_tag == tag)
5591 remove_child_with_prev (c, prev);
5592 /* Might have removed every child. */
5593 if (c == c->die_sib)
5597 } while (c != die->die_child);
5600 /* Add a CHILD_DIE as the last child of DIE. */
5603 add_child_die (dw_die_ref die, dw_die_ref child_die)
5605 /* FIXME this should probably be an assert. */
5606 if (! die || ! child_die)
5608 gcc_assert (die != child_die);
5610 child_die->die_parent = die;
5613 child_die->die_sib = die->die_child->die_sib;
5614 die->die_child->die_sib = child_die;
5617 child_die->die_sib = child_die;
5618 die->die_child = child_die;
5621 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5622 is the specification, to the end of PARENT's list of children.
5623 This is done by removing and re-adding it. */
5626 splice_child_die (dw_die_ref parent, dw_die_ref child)
5630 /* We want the declaration DIE from inside the class, not the
5631 specification DIE at toplevel. */
5632 if (child->die_parent != parent)
5634 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5640 gcc_assert (child->die_parent == parent
5641 || (child->die_parent
5642 == get_AT_ref (parent, DW_AT_specification)));
5644 for (p = child->die_parent->die_child; ; p = p->die_sib)
5645 if (p->die_sib == child)
5647 remove_child_with_prev (child, p);
5651 add_child_die (parent, child);
5654 /* Return a pointer to a newly created DIE node. */
5656 static inline dw_die_ref
5657 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5659 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5661 die->die_tag = tag_value;
5663 if (parent_die != NULL)
5664 add_child_die (parent_die, die);
5667 limbo_die_node *limbo_node;
5669 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5670 limbo_node->die = die;
5671 limbo_node->created_for = t;
5672 limbo_node->next = limbo_die_list;
5673 limbo_die_list = limbo_node;
5679 /* Return the DIE associated with the given type specifier. */
5681 static inline dw_die_ref
5682 lookup_type_die (tree type)
5684 return TYPE_SYMTAB_DIE (type);
5687 /* Equate a DIE to a given type specifier. */
5690 equate_type_number_to_die (tree type, dw_die_ref type_die)
5692 TYPE_SYMTAB_DIE (type) = type_die;
5695 /* Returns a hash value for X (which really is a die_struct). */
5698 decl_die_table_hash (const void *x)
5700 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5703 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5706 decl_die_table_eq (const void *x, const void *y)
5708 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5711 /* Return the DIE associated with a given declaration. */
5713 static inline dw_die_ref
5714 lookup_decl_die (tree decl)
5716 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5719 /* Returns a hash value for X (which really is a var_loc_list). */
5722 decl_loc_table_hash (const void *x)
5724 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5727 /* Return nonzero if decl_id of var_loc_list X is the same as
5731 decl_loc_table_eq (const void *x, const void *y)
5733 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5736 /* Return the var_loc list associated with a given declaration. */
5738 static inline var_loc_list *
5739 lookup_decl_loc (const_tree decl)
5741 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5744 /* Equate a DIE to a particular declaration. */
5747 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5749 unsigned int decl_id = DECL_UID (decl);
5752 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5754 decl_die->decl_id = decl_id;
5757 /* Add a variable location node to the linked list for DECL. */
5760 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5762 unsigned int decl_id = DECL_UID (decl);
5766 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5769 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5770 temp->decl_id = decl_id;
5778 /* If the current location is the same as the end of the list,
5779 and either both or neither of the locations is uninitialized,
5780 we have nothing to do. */
5781 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5782 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5783 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5784 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
5785 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5786 == VAR_INIT_STATUS_UNINITIALIZED)
5787 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
5788 == VAR_INIT_STATUS_UNINITIALIZED))))
5790 /* Add LOC to the end of list and update LAST. */
5791 temp->last->next = loc;
5795 /* Do not add empty location to the beginning of the list. */
5796 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5803 /* Keep track of the number of spaces used to indent the
5804 output of the debugging routines that print the structure of
5805 the DIE internal representation. */
5806 static int print_indent;
5808 /* Indent the line the number of spaces given by print_indent. */
5811 print_spaces (FILE *outfile)
5813 fprintf (outfile, "%*s", print_indent, "");
5816 /* Print the information associated with a given DIE, and its children.
5817 This routine is a debugging aid only. */
5820 print_die (dw_die_ref die, FILE *outfile)
5826 print_spaces (outfile);
5827 fprintf (outfile, "DIE %4ld: %s\n",
5828 die->die_offset, dwarf_tag_name (die->die_tag));
5829 print_spaces (outfile);
5830 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5831 fprintf (outfile, " offset: %ld\n", die->die_offset);
5833 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5835 print_spaces (outfile);
5836 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5838 switch (AT_class (a))
5840 case dw_val_class_addr:
5841 fprintf (outfile, "address");
5843 case dw_val_class_offset:
5844 fprintf (outfile, "offset");
5846 case dw_val_class_loc:
5847 fprintf (outfile, "location descriptor");
5849 case dw_val_class_loc_list:
5850 fprintf (outfile, "location list -> label:%s",
5851 AT_loc_list (a)->ll_symbol);
5853 case dw_val_class_range_list:
5854 fprintf (outfile, "range list");
5856 case dw_val_class_const:
5857 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5859 case dw_val_class_unsigned_const:
5860 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5862 case dw_val_class_long_long:
5863 fprintf (outfile, "constant (%lu,%lu)",
5864 a->dw_attr_val.v.val_long_long.hi,
5865 a->dw_attr_val.v.val_long_long.low);
5867 case dw_val_class_vec:
5868 fprintf (outfile, "floating-point or vector constant");
5870 case dw_val_class_flag:
5871 fprintf (outfile, "%u", AT_flag (a));
5873 case dw_val_class_die_ref:
5874 if (AT_ref (a) != NULL)
5876 if (AT_ref (a)->die_symbol)
5877 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5879 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5882 fprintf (outfile, "die -> <null>");
5884 case dw_val_class_lbl_id:
5885 case dw_val_class_lineptr:
5886 case dw_val_class_macptr:
5887 fprintf (outfile, "label: %s", AT_lbl (a));
5889 case dw_val_class_str:
5890 if (AT_string (a) != NULL)
5891 fprintf (outfile, "\"%s\"", AT_string (a));
5893 fprintf (outfile, "<null>");
5895 case dw_val_class_file:
5896 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5897 AT_file (a)->emitted_number);
5903 fprintf (outfile, "\n");
5906 if (die->die_child != NULL)
5909 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5912 if (print_indent == 0)
5913 fprintf (outfile, "\n");
5916 /* Print the contents of the source code line number correspondence table.
5917 This routine is a debugging aid only. */
5920 print_dwarf_line_table (FILE *outfile)
5923 dw_line_info_ref line_info;
5925 fprintf (outfile, "\n\nDWARF source line information\n");
5926 for (i = 1; i < line_info_table_in_use; i++)
5928 line_info = &line_info_table[i];
5929 fprintf (outfile, "%5d: %4ld %6ld\n", i,
5930 line_info->dw_file_num,
5931 line_info->dw_line_num);
5934 fprintf (outfile, "\n\n");
5937 /* Print the information collected for a given DIE. */
5940 debug_dwarf_die (dw_die_ref die)
5942 print_die (die, stderr);
5945 /* Print all DWARF information collected for the compilation unit.
5946 This routine is a debugging aid only. */
5952 print_die (comp_unit_die, stderr);
5953 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5954 print_dwarf_line_table (stderr);
5957 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5958 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5959 DIE that marks the start of the DIEs for this include file. */
5962 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5964 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5965 dw_die_ref new_unit = gen_compile_unit_die (filename);
5967 new_unit->die_sib = old_unit;
5971 /* Close an include-file CU and reopen the enclosing one. */
5974 pop_compile_unit (dw_die_ref old_unit)
5976 dw_die_ref new_unit = old_unit->die_sib;
5978 old_unit->die_sib = NULL;
5982 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5983 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5985 /* Calculate the checksum of a location expression. */
5988 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5990 CHECKSUM (loc->dw_loc_opc);
5991 CHECKSUM (loc->dw_loc_oprnd1);
5992 CHECKSUM (loc->dw_loc_oprnd2);
5995 /* Calculate the checksum of an attribute. */
5998 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6000 dw_loc_descr_ref loc;
6003 CHECKSUM (at->dw_attr);
6005 /* We don't care that this was compiled with a different compiler
6006 snapshot; if the output is the same, that's what matters. */
6007 if (at->dw_attr == DW_AT_producer)
6010 switch (AT_class (at))
6012 case dw_val_class_const:
6013 CHECKSUM (at->dw_attr_val.v.val_int);
6015 case dw_val_class_unsigned_const:
6016 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6018 case dw_val_class_long_long:
6019 CHECKSUM (at->dw_attr_val.v.val_long_long);
6021 case dw_val_class_vec:
6022 CHECKSUM (at->dw_attr_val.v.val_vec);
6024 case dw_val_class_flag:
6025 CHECKSUM (at->dw_attr_val.v.val_flag);
6027 case dw_val_class_str:
6028 CHECKSUM_STRING (AT_string (at));
6031 case dw_val_class_addr:
6033 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6034 CHECKSUM_STRING (XSTR (r, 0));
6037 case dw_val_class_offset:
6038 CHECKSUM (at->dw_attr_val.v.val_offset);
6041 case dw_val_class_loc:
6042 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6043 loc_checksum (loc, ctx);
6046 case dw_val_class_die_ref:
6047 die_checksum (AT_ref (at), ctx, mark);
6050 case dw_val_class_fde_ref:
6051 case dw_val_class_lbl_id:
6052 case dw_val_class_lineptr:
6053 case dw_val_class_macptr:
6056 case dw_val_class_file:
6057 CHECKSUM_STRING (AT_file (at)->filename);
6065 /* Calculate the checksum of a DIE. */
6068 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6074 /* To avoid infinite recursion. */
6077 CHECKSUM (die->die_mark);
6080 die->die_mark = ++(*mark);
6082 CHECKSUM (die->die_tag);
6084 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6085 attr_checksum (a, ctx, mark);
6087 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6091 #undef CHECKSUM_STRING
6093 /* Do the location expressions look same? */
6095 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6097 return loc1->dw_loc_opc == loc2->dw_loc_opc
6098 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6099 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6102 /* Do the values look the same? */
6104 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6106 dw_loc_descr_ref loc1, loc2;
6109 if (v1->val_class != v2->val_class)
6112 switch (v1->val_class)
6114 case dw_val_class_const:
6115 return v1->v.val_int == v2->v.val_int;
6116 case dw_val_class_unsigned_const:
6117 return v1->v.val_unsigned == v2->v.val_unsigned;
6118 case dw_val_class_long_long:
6119 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6120 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6121 case dw_val_class_vec:
6122 if (v1->v.val_vec.length != v2->v.val_vec.length
6123 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6125 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6126 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6129 case dw_val_class_flag:
6130 return v1->v.val_flag == v2->v.val_flag;
6131 case dw_val_class_str:
6132 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6134 case dw_val_class_addr:
6135 r1 = v1->v.val_addr;
6136 r2 = v2->v.val_addr;
6137 if (GET_CODE (r1) != GET_CODE (r2))
6139 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6140 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6142 case dw_val_class_offset:
6143 return v1->v.val_offset == v2->v.val_offset;
6145 case dw_val_class_loc:
6146 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6148 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6149 if (!same_loc_p (loc1, loc2, mark))
6151 return !loc1 && !loc2;
6153 case dw_val_class_die_ref:
6154 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6156 case dw_val_class_fde_ref:
6157 case dw_val_class_lbl_id:
6158 case dw_val_class_lineptr:
6159 case dw_val_class_macptr:
6162 case dw_val_class_file:
6163 return v1->v.val_file == v2->v.val_file;
6170 /* Do the attributes look the same? */
6173 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6175 if (at1->dw_attr != at2->dw_attr)
6178 /* We don't care that this was compiled with a different compiler
6179 snapshot; if the output is the same, that's what matters. */
6180 if (at1->dw_attr == DW_AT_producer)
6183 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6186 /* Do the dies look the same? */
6189 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6195 /* To avoid infinite recursion. */
6197 return die1->die_mark == die2->die_mark;
6198 die1->die_mark = die2->die_mark = ++(*mark);
6200 if (die1->die_tag != die2->die_tag)
6203 if (VEC_length (dw_attr_node, die1->die_attr)
6204 != VEC_length (dw_attr_node, die2->die_attr))
6207 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6208 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6211 c1 = die1->die_child;
6212 c2 = die2->die_child;
6221 if (!same_die_p (c1, c2, mark))
6225 if (c1 == die1->die_child)
6227 if (c2 == die2->die_child)
6237 /* Do the dies look the same? Wrapper around same_die_p. */
6240 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6243 int ret = same_die_p (die1, die2, &mark);
6245 unmark_all_dies (die1);
6246 unmark_all_dies (die2);
6251 /* The prefix to attach to symbols on DIEs in the current comdat debug
6253 static char *comdat_symbol_id;
6255 /* The index of the current symbol within the current comdat CU. */
6256 static unsigned int comdat_symbol_number;
6258 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6259 children, and set comdat_symbol_id accordingly. */
6262 compute_section_prefix (dw_die_ref unit_die)
6264 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6265 const char *base = die_name ? lbasename (die_name) : "anonymous";
6266 char *name = alloca (strlen (base) + 64);
6269 unsigned char checksum[16];
6272 /* Compute the checksum of the DIE, then append part of it as hex digits to
6273 the name filename of the unit. */
6275 md5_init_ctx (&ctx);
6277 die_checksum (unit_die, &ctx, &mark);
6278 unmark_all_dies (unit_die);
6279 md5_finish_ctx (&ctx, checksum);
6281 sprintf (name, "%s.", base);
6282 clean_symbol_name (name);
6284 p = name + strlen (name);
6285 for (i = 0; i < 4; i++)
6287 sprintf (p, "%.2x", checksum[i]);
6291 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6292 comdat_symbol_number = 0;
6295 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6298 is_type_die (dw_die_ref die)
6300 switch (die->die_tag)
6302 case DW_TAG_array_type:
6303 case DW_TAG_class_type:
6304 case DW_TAG_enumeration_type:
6305 case DW_TAG_pointer_type:
6306 case DW_TAG_reference_type:
6307 case DW_TAG_string_type:
6308 case DW_TAG_structure_type:
6309 case DW_TAG_subroutine_type:
6310 case DW_TAG_union_type:
6311 case DW_TAG_ptr_to_member_type:
6312 case DW_TAG_set_type:
6313 case DW_TAG_subrange_type:
6314 case DW_TAG_base_type:
6315 case DW_TAG_const_type:
6316 case DW_TAG_file_type:
6317 case DW_TAG_packed_type:
6318 case DW_TAG_volatile_type:
6319 case DW_TAG_typedef:
6326 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6327 Basically, we want to choose the bits that are likely to be shared between
6328 compilations (types) and leave out the bits that are specific to individual
6329 compilations (functions). */
6332 is_comdat_die (dw_die_ref c)
6334 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6335 we do for stabs. The advantage is a greater likelihood of sharing between
6336 objects that don't include headers in the same order (and therefore would
6337 put the base types in a different comdat). jason 8/28/00 */
6339 if (c->die_tag == DW_TAG_base_type)
6342 if (c->die_tag == DW_TAG_pointer_type
6343 || c->die_tag == DW_TAG_reference_type
6344 || c->die_tag == DW_TAG_const_type
6345 || c->die_tag == DW_TAG_volatile_type)
6347 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6349 return t ? is_comdat_die (t) : 0;
6352 return is_type_die (c);
6355 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6356 compilation unit. */
6359 is_symbol_die (dw_die_ref c)
6361 return (is_type_die (c)
6362 || (get_AT (c, DW_AT_declaration)
6363 && !get_AT (c, DW_AT_specification))
6364 || c->die_tag == DW_TAG_namespace);
6368 gen_internal_sym (const char *prefix)
6372 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6373 return xstrdup (buf);
6376 /* Assign symbols to all worthy DIEs under DIE. */
6379 assign_symbol_names (dw_die_ref die)
6383 if (is_symbol_die (die))
6385 if (comdat_symbol_id)
6387 char *p = alloca (strlen (comdat_symbol_id) + 64);
6389 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6390 comdat_symbol_id, comdat_symbol_number++);
6391 die->die_symbol = xstrdup (p);
6394 die->die_symbol = gen_internal_sym ("LDIE");
6397 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6400 struct cu_hash_table_entry
6403 unsigned min_comdat_num, max_comdat_num;
6404 struct cu_hash_table_entry *next;
6407 /* Routines to manipulate hash table of CUs. */
6409 htab_cu_hash (const void *of)
6411 const struct cu_hash_table_entry *entry = of;
6413 return htab_hash_string (entry->cu->die_symbol);
6417 htab_cu_eq (const void *of1, const void *of2)
6419 const struct cu_hash_table_entry *entry1 = of1;
6420 const struct die_struct *entry2 = of2;
6422 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6426 htab_cu_del (void *what)
6428 struct cu_hash_table_entry *next, *entry = what;
6438 /* Check whether we have already seen this CU and set up SYM_NUM
6441 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6443 struct cu_hash_table_entry dummy;
6444 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6446 dummy.max_comdat_num = 0;
6448 slot = (struct cu_hash_table_entry **)
6449 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6453 for (; entry; last = entry, entry = entry->next)
6455 if (same_die_p_wrap (cu, entry->cu))
6461 *sym_num = entry->min_comdat_num;
6465 entry = XCNEW (struct cu_hash_table_entry);
6467 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6468 entry->next = *slot;
6474 /* Record SYM_NUM to record of CU in HTABLE. */
6476 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6478 struct cu_hash_table_entry **slot, *entry;
6480 slot = (struct cu_hash_table_entry **)
6481 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6485 entry->max_comdat_num = sym_num;
6488 /* Traverse the DIE (which is always comp_unit_die), and set up
6489 additional compilation units for each of the include files we see
6490 bracketed by BINCL/EINCL. */
6493 break_out_includes (dw_die_ref die)
6496 dw_die_ref unit = NULL;
6497 limbo_die_node *node, **pnode;
6498 htab_t cu_hash_table;
6502 dw_die_ref prev = c;
6504 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6505 || (unit && is_comdat_die (c)))
6507 dw_die_ref next = c->die_sib;
6509 /* This DIE is for a secondary CU; remove it from the main one. */
6510 remove_child_with_prev (c, prev);
6512 if (c->die_tag == DW_TAG_GNU_BINCL)
6513 unit = push_new_compile_unit (unit, c);
6514 else if (c->die_tag == DW_TAG_GNU_EINCL)
6515 unit = pop_compile_unit (unit);
6517 add_child_die (unit, c);
6519 if (c == die->die_child)
6522 } while (c != die->die_child);
6525 /* We can only use this in debugging, since the frontend doesn't check
6526 to make sure that we leave every include file we enter. */
6530 assign_symbol_names (die);
6531 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6532 for (node = limbo_die_list, pnode = &limbo_die_list;
6538 compute_section_prefix (node->die);
6539 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6540 &comdat_symbol_number);
6541 assign_symbol_names (node->die);
6543 *pnode = node->next;
6546 pnode = &node->next;
6547 record_comdat_symbol_number (node->die, cu_hash_table,
6548 comdat_symbol_number);
6551 htab_delete (cu_hash_table);
6554 /* Traverse the DIE and add a sibling attribute if it may have the
6555 effect of speeding up access to siblings. To save some space,
6556 avoid generating sibling attributes for DIE's without children. */
6559 add_sibling_attributes (dw_die_ref die)
6563 if (! die->die_child)
6566 if (die->die_parent && die != die->die_parent->die_child)
6567 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6569 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6572 /* Output all location lists for the DIE and its children. */
6575 output_location_lists (dw_die_ref die)
6581 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6582 if (AT_class (a) == dw_val_class_loc_list)
6583 output_loc_list (AT_loc_list (a));
6585 FOR_EACH_CHILD (die, c, output_location_lists (c));
6588 /* The format of each DIE (and its attribute value pairs) is encoded in an
6589 abbreviation table. This routine builds the abbreviation table and assigns
6590 a unique abbreviation id for each abbreviation entry. The children of each
6591 die are visited recursively. */
6594 build_abbrev_table (dw_die_ref die)
6596 unsigned long abbrev_id;
6597 unsigned int n_alloc;
6602 /* Scan the DIE references, and mark as external any that refer to
6603 DIEs from other CUs (i.e. those which are not marked). */
6604 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6605 if (AT_class (a) == dw_val_class_die_ref
6606 && AT_ref (a)->die_mark == 0)
6608 gcc_assert (AT_ref (a)->die_symbol);
6610 set_AT_ref_external (a, 1);
6613 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6615 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6616 dw_attr_ref die_a, abbrev_a;
6620 if (abbrev->die_tag != die->die_tag)
6622 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6625 if (VEC_length (dw_attr_node, abbrev->die_attr)
6626 != VEC_length (dw_attr_node, die->die_attr))
6629 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6631 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6632 if ((abbrev_a->dw_attr != die_a->dw_attr)
6633 || (value_format (abbrev_a) != value_format (die_a)))
6643 if (abbrev_id >= abbrev_die_table_in_use)
6645 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6647 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6648 abbrev_die_table = ggc_realloc (abbrev_die_table,
6649 sizeof (dw_die_ref) * n_alloc);
6651 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6652 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6653 abbrev_die_table_allocated = n_alloc;
6656 ++abbrev_die_table_in_use;
6657 abbrev_die_table[abbrev_id] = die;
6660 die->die_abbrev = abbrev_id;
6661 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6664 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6667 constant_size (long unsigned int value)
6674 log = floor_log2 (value);
6677 log = 1 << (floor_log2 (log) + 1);
6682 /* Return the size of a DIE as it is represented in the
6683 .debug_info section. */
6685 static unsigned long
6686 size_of_die (dw_die_ref die)
6688 unsigned long size = 0;
6692 size += size_of_uleb128 (die->die_abbrev);
6693 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6695 switch (AT_class (a))
6697 case dw_val_class_addr:
6698 size += DWARF2_ADDR_SIZE;
6700 case dw_val_class_offset:
6701 size += DWARF_OFFSET_SIZE;
6703 case dw_val_class_loc:
6705 unsigned long lsize = size_of_locs (AT_loc (a));
6708 size += constant_size (lsize);
6712 case dw_val_class_loc_list:
6713 size += DWARF_OFFSET_SIZE;
6715 case dw_val_class_range_list:
6716 size += DWARF_OFFSET_SIZE;
6718 case dw_val_class_const:
6719 size += size_of_sleb128 (AT_int (a));
6721 case dw_val_class_unsigned_const:
6722 size += constant_size (AT_unsigned (a));
6724 case dw_val_class_long_long:
6725 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6727 case dw_val_class_vec:
6728 size += 1 + (a->dw_attr_val.v.val_vec.length
6729 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6731 case dw_val_class_flag:
6734 case dw_val_class_die_ref:
6735 if (AT_ref_external (a))
6736 size += DWARF2_ADDR_SIZE;
6738 size += DWARF_OFFSET_SIZE;
6740 case dw_val_class_fde_ref:
6741 size += DWARF_OFFSET_SIZE;
6743 case dw_val_class_lbl_id:
6744 size += DWARF2_ADDR_SIZE;
6746 case dw_val_class_lineptr:
6747 case dw_val_class_macptr:
6748 size += DWARF_OFFSET_SIZE;
6750 case dw_val_class_str:
6751 if (AT_string_form (a) == DW_FORM_strp)
6752 size += DWARF_OFFSET_SIZE;
6754 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6756 case dw_val_class_file:
6757 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6767 /* Size the debugging information associated with a given DIE. Visits the
6768 DIE's children recursively. Updates the global variable next_die_offset, on
6769 each time through. Uses the current value of next_die_offset to update the
6770 die_offset field in each DIE. */
6773 calc_die_sizes (dw_die_ref die)
6777 die->die_offset = next_die_offset;
6778 next_die_offset += size_of_die (die);
6780 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6782 if (die->die_child != NULL)
6783 /* Count the null byte used to terminate sibling lists. */
6784 next_die_offset += 1;
6787 /* Set the marks for a die and its children. We do this so
6788 that we know whether or not a reference needs to use FORM_ref_addr; only
6789 DIEs in the same CU will be marked. We used to clear out the offset
6790 and use that as the flag, but ran into ordering problems. */
6793 mark_dies (dw_die_ref die)
6797 gcc_assert (!die->die_mark);
6800 FOR_EACH_CHILD (die, c, mark_dies (c));
6803 /* Clear the marks for a die and its children. */
6806 unmark_dies (dw_die_ref die)
6810 gcc_assert (die->die_mark);
6813 FOR_EACH_CHILD (die, c, unmark_dies (c));
6816 /* Clear the marks for a die, its children and referred dies. */
6819 unmark_all_dies (dw_die_ref die)
6829 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6831 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6832 if (AT_class (a) == dw_val_class_die_ref)
6833 unmark_all_dies (AT_ref (a));
6836 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6837 generated for the compilation unit. */
6839 static unsigned long
6840 size_of_pubnames (VEC (pubname_entry, gc) * names)
6846 size = DWARF_PUBNAMES_HEADER_SIZE;
6847 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6848 if (names != pubtype_table
6849 || p->die->die_offset != 0
6850 || !flag_eliminate_unused_debug_types)
6851 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6853 size += DWARF_OFFSET_SIZE;
6857 /* Return the size of the information in the .debug_aranges section. */
6859 static unsigned long
6860 size_of_aranges (void)
6864 size = DWARF_ARANGES_HEADER_SIZE;
6866 /* Count the address/length pair for this compilation unit. */
6867 if (text_section_used)
6868 size += 2 * DWARF2_ADDR_SIZE;
6869 if (cold_text_section_used)
6870 size += 2 * DWARF2_ADDR_SIZE;
6871 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6873 /* Count the two zero words used to terminated the address range table. */
6874 size += 2 * DWARF2_ADDR_SIZE;
6878 /* Select the encoding of an attribute value. */
6880 static enum dwarf_form
6881 value_format (dw_attr_ref a)
6883 switch (a->dw_attr_val.val_class)
6885 case dw_val_class_addr:
6886 return DW_FORM_addr;
6887 case dw_val_class_range_list:
6888 case dw_val_class_offset:
6889 case dw_val_class_loc_list:
6890 switch (DWARF_OFFSET_SIZE)
6893 return DW_FORM_data4;
6895 return DW_FORM_data8;
6899 case dw_val_class_loc:
6900 switch (constant_size (size_of_locs (AT_loc (a))))
6903 return DW_FORM_block1;
6905 return DW_FORM_block2;
6909 case dw_val_class_const:
6910 return DW_FORM_sdata;
6911 case dw_val_class_unsigned_const:
6912 switch (constant_size (AT_unsigned (a)))
6915 return DW_FORM_data1;
6917 return DW_FORM_data2;
6919 return DW_FORM_data4;
6921 return DW_FORM_data8;
6925 case dw_val_class_long_long:
6926 return DW_FORM_block1;
6927 case dw_val_class_vec:
6928 return DW_FORM_block1;
6929 case dw_val_class_flag:
6930 return DW_FORM_flag;
6931 case dw_val_class_die_ref:
6932 if (AT_ref_external (a))
6933 return DW_FORM_ref_addr;
6936 case dw_val_class_fde_ref:
6937 return DW_FORM_data;
6938 case dw_val_class_lbl_id:
6939 return DW_FORM_addr;
6940 case dw_val_class_lineptr:
6941 case dw_val_class_macptr:
6942 return DW_FORM_data;
6943 case dw_val_class_str:
6944 return AT_string_form (a);
6945 case dw_val_class_file:
6946 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
6949 return DW_FORM_data1;
6951 return DW_FORM_data2;
6953 return DW_FORM_data4;
6963 /* Output the encoding of an attribute value. */
6966 output_value_format (dw_attr_ref a)
6968 enum dwarf_form form = value_format (a);
6970 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6973 /* Output the .debug_abbrev section which defines the DIE abbreviation
6977 output_abbrev_section (void)
6979 unsigned long abbrev_id;
6981 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6983 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6987 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6988 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6989 dwarf_tag_name (abbrev->die_tag));
6991 if (abbrev->die_child != NULL)
6992 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6994 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6996 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
6999 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7000 dwarf_attr_name (a_attr->dw_attr));
7001 output_value_format (a_attr);
7004 dw2_asm_output_data (1, 0, NULL);
7005 dw2_asm_output_data (1, 0, NULL);
7008 /* Terminate the table. */
7009 dw2_asm_output_data (1, 0, NULL);
7012 /* Output a symbol we can use to refer to this DIE from another CU. */
7015 output_die_symbol (dw_die_ref die)
7017 char *sym = die->die_symbol;
7022 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7023 /* We make these global, not weak; if the target doesn't support
7024 .linkonce, it doesn't support combining the sections, so debugging
7026 targetm.asm_out.globalize_label (asm_out_file, sym);
7028 ASM_OUTPUT_LABEL (asm_out_file, sym);
7031 /* Return a new location list, given the begin and end range, and the
7032 expression. gensym tells us whether to generate a new internal symbol for
7033 this location list node, which is done for the head of the list only. */
7035 static inline dw_loc_list_ref
7036 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7037 const char *section, unsigned int gensym)
7039 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
7041 retlist->begin = begin;
7043 retlist->expr = expr;
7044 retlist->section = section;
7046 retlist->ll_symbol = gen_internal_sym ("LLST");
7051 /* Add a location description expression to a location list. */
7054 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7055 const char *begin, const char *end,
7056 const char *section)
7060 /* Find the end of the chain. */
7061 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7064 /* Add a new location list node to the list. */
7065 *d = new_loc_list (descr, begin, end, section, 0);
7068 /* Note that the current function section is being used for code. */
7071 dwarf2out_note_section_used (void)
7073 section *sec = current_function_section ();
7074 if (sec == text_section)
7075 text_section_used = true;
7076 else if (sec == cold_text_section)
7077 cold_text_section_used = true;
7081 dwarf2out_switch_text_section (void)
7087 fde = &fde_table[fde_table_in_use - 1];
7088 fde->dw_fde_switched_sections = true;
7089 fde->dw_fde_hot_section_label = cfun->hot_section_label;
7090 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
7091 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
7092 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
7093 have_multiple_function_sections = true;
7095 /* Reset the current label on switching text sections, so that we
7096 don't attempt to advance_loc4 between labels in different sections. */
7097 fde->dw_fde_current_label = NULL;
7099 dwarf2out_note_section_used ();
7102 /* Output the location list given to us. */
7105 output_loc_list (dw_loc_list_ref list_head)
7107 dw_loc_list_ref curr = list_head;
7109 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7111 /* Walk the location list, and output each range + expression. */
7112 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7115 /* Don't output an entry that starts and ends at the same address. */
7116 if (strcmp (curr->begin, curr->end) == 0)
7118 if (!have_multiple_function_sections)
7120 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7121 "Location list begin address (%s)",
7122 list_head->ll_symbol);
7123 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7124 "Location list end address (%s)",
7125 list_head->ll_symbol);
7129 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7130 "Location list begin address (%s)",
7131 list_head->ll_symbol);
7132 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7133 "Location list end address (%s)",
7134 list_head->ll_symbol);
7136 size = size_of_locs (curr->expr);
7138 /* Output the block length for this list of location operations. */
7139 gcc_assert (size <= 0xffff);
7140 dw2_asm_output_data (2, size, "%s", "Location expression size");
7142 output_loc_sequence (curr->expr);
7145 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7146 "Location list terminator begin (%s)",
7147 list_head->ll_symbol);
7148 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7149 "Location list terminator end (%s)",
7150 list_head->ll_symbol);
7153 /* Output the DIE and its attributes. Called recursively to generate
7154 the definitions of each child DIE. */
7157 output_die (dw_die_ref die)
7164 /* If someone in another CU might refer to us, set up a symbol for
7165 them to point to. */
7166 if (die->die_symbol)
7167 output_die_symbol (die);
7169 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7170 (unsigned long)die->die_offset,
7171 dwarf_tag_name (die->die_tag));
7173 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7175 const char *name = dwarf_attr_name (a->dw_attr);
7177 switch (AT_class (a))
7179 case dw_val_class_addr:
7180 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7183 case dw_val_class_offset:
7184 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7188 case dw_val_class_range_list:
7190 char *p = strchr (ranges_section_label, '\0');
7192 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7193 a->dw_attr_val.v.val_offset);
7194 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7195 debug_ranges_section, "%s", name);
7200 case dw_val_class_loc:
7201 size = size_of_locs (AT_loc (a));
7203 /* Output the block length for this list of location operations. */
7204 dw2_asm_output_data (constant_size (size), size, "%s", name);
7206 output_loc_sequence (AT_loc (a));
7209 case dw_val_class_const:
7210 /* ??? It would be slightly more efficient to use a scheme like is
7211 used for unsigned constants below, but gdb 4.x does not sign
7212 extend. Gdb 5.x does sign extend. */
7213 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7216 case dw_val_class_unsigned_const:
7217 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7218 AT_unsigned (a), "%s", name);
7221 case dw_val_class_long_long:
7223 unsigned HOST_WIDE_INT first, second;
7225 dw2_asm_output_data (1,
7226 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7229 if (WORDS_BIG_ENDIAN)
7231 first = a->dw_attr_val.v.val_long_long.hi;
7232 second = a->dw_attr_val.v.val_long_long.low;
7236 first = a->dw_attr_val.v.val_long_long.low;
7237 second = a->dw_attr_val.v.val_long_long.hi;
7240 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7241 first, "long long constant");
7242 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7247 case dw_val_class_vec:
7249 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7250 unsigned int len = a->dw_attr_val.v.val_vec.length;
7254 dw2_asm_output_data (1, len * elt_size, "%s", name);
7255 if (elt_size > sizeof (HOST_WIDE_INT))
7260 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7263 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7264 "fp or vector constant word %u", i);
7268 case dw_val_class_flag:
7269 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7272 case dw_val_class_loc_list:
7274 char *sym = AT_loc_list (a)->ll_symbol;
7277 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7282 case dw_val_class_die_ref:
7283 if (AT_ref_external (a))
7285 char *sym = AT_ref (a)->die_symbol;
7288 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7293 gcc_assert (AT_ref (a)->die_offset);
7294 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7299 case dw_val_class_fde_ref:
7303 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7304 a->dw_attr_val.v.val_fde_index * 2);
7305 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7310 case dw_val_class_lbl_id:
7311 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7314 case dw_val_class_lineptr:
7315 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7316 debug_line_section, "%s", name);
7319 case dw_val_class_macptr:
7320 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7321 debug_macinfo_section, "%s", name);
7324 case dw_val_class_str:
7325 if (AT_string_form (a) == DW_FORM_strp)
7326 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7327 a->dw_attr_val.v.val_str->label,
7329 "%s: \"%s\"", name, AT_string (a));
7331 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7334 case dw_val_class_file:
7336 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7338 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7339 a->dw_attr_val.v.val_file->filename);
7348 FOR_EACH_CHILD (die, c, output_die (c));
7350 /* Add null byte to terminate sibling list. */
7351 if (die->die_child != NULL)
7352 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7353 (unsigned long) die->die_offset);
7356 /* Output the compilation unit that appears at the beginning of the
7357 .debug_info section, and precedes the DIE descriptions. */
7360 output_compilation_unit_header (void)
7362 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7363 dw2_asm_output_data (4, 0xffffffff,
7364 "Initial length escape value indicating 64-bit DWARF extension");
7365 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7366 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7367 "Length of Compilation Unit Info");
7368 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7369 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7370 debug_abbrev_section,
7371 "Offset Into Abbrev. Section");
7372 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7375 /* Output the compilation unit DIE and its children. */
7378 output_comp_unit (dw_die_ref die, int output_if_empty)
7380 const char *secname;
7383 /* Unless we are outputting main CU, we may throw away empty ones. */
7384 if (!output_if_empty && die->die_child == NULL)
7387 /* Even if there are no children of this DIE, we must output the information
7388 about the compilation unit. Otherwise, on an empty translation unit, we
7389 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7390 will then complain when examining the file. First mark all the DIEs in
7391 this CU so we know which get local refs. */
7394 build_abbrev_table (die);
7396 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7397 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7398 calc_die_sizes (die);
7400 oldsym = die->die_symbol;
7403 tmp = alloca (strlen (oldsym) + 24);
7405 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7407 die->die_symbol = NULL;
7408 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7411 switch_to_section (debug_info_section);
7413 /* Output debugging information. */
7414 output_compilation_unit_header ();
7417 /* Leave the marks on the main CU, so we can check them in
7422 die->die_symbol = oldsym;
7426 /* Return the DWARF2/3 pubname associated with a decl. */
7429 dwarf2_name (tree decl, int scope)
7431 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7434 /* Add a new entry to .debug_pubnames if appropriate. */
7437 add_pubname (tree decl, dw_die_ref die)
7441 if (! TREE_PUBLIC (decl))
7445 e.name = xstrdup (dwarf2_name (decl, 1));
7446 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7449 /* Add a new entry to .debug_pubtypes if appropriate. */
7452 add_pubtype (tree decl, dw_die_ref die)
7457 if ((TREE_PUBLIC (decl)
7458 || die->die_parent == comp_unit_die)
7459 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7464 if (TYPE_NAME (decl))
7466 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7467 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7468 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7469 && DECL_NAME (TYPE_NAME (decl)))
7470 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7472 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7476 e.name = xstrdup (dwarf2_name (decl, 1));
7478 /* If we don't have a name for the type, there's no point in adding
7480 if (e.name && e.name[0] != '\0')
7481 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7485 /* Output the public names table used to speed up access to externally
7486 visible names; or the public types table used to find type definitions. */
7489 output_pubnames (VEC (pubname_entry, gc) * names)
7492 unsigned long pubnames_length = size_of_pubnames (names);
7495 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7496 dw2_asm_output_data (4, 0xffffffff,
7497 "Initial length escape value indicating 64-bit DWARF extension");
7498 if (names == pubname_table)
7499 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7500 "Length of Public Names Info");
7502 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7503 "Length of Public Type Names Info");
7504 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7505 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7507 "Offset of Compilation Unit Info");
7508 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7509 "Compilation Unit Length");
7511 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7513 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7514 if (names == pubname_table)
7515 gcc_assert (pub->die->die_mark);
7517 if (names != pubtype_table
7518 || pub->die->die_offset != 0
7519 || !flag_eliminate_unused_debug_types)
7521 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7524 dw2_asm_output_nstring (pub->name, -1, "external name");
7528 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7531 /* Add a new entry to .debug_aranges if appropriate. */
7534 add_arange (tree decl, dw_die_ref die)
7536 if (! DECL_SECTION_NAME (decl))
7539 if (arange_table_in_use == arange_table_allocated)
7541 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7542 arange_table = ggc_realloc (arange_table,
7543 (arange_table_allocated
7544 * sizeof (dw_die_ref)));
7545 memset (arange_table + arange_table_in_use, 0,
7546 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7549 arange_table[arange_table_in_use++] = die;
7552 /* Output the information that goes into the .debug_aranges table.
7553 Namely, define the beginning and ending address range of the
7554 text section generated for this compilation unit. */
7557 output_aranges (void)
7560 unsigned long aranges_length = size_of_aranges ();
7562 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7563 dw2_asm_output_data (4, 0xffffffff,
7564 "Initial length escape value indicating 64-bit DWARF extension");
7565 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7566 "Length of Address Ranges Info");
7567 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7568 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7570 "Offset of Compilation Unit Info");
7571 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7572 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7574 /* We need to align to twice the pointer size here. */
7575 if (DWARF_ARANGES_PAD_SIZE)
7577 /* Pad using a 2 byte words so that padding is correct for any
7579 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7580 2 * DWARF2_ADDR_SIZE);
7581 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7582 dw2_asm_output_data (2, 0, NULL);
7585 /* It is necessary not to output these entries if the sections were
7586 not used; if the sections were not used, the length will be 0 and
7587 the address may end up as 0 if the section is discarded by ld
7588 --gc-sections, leaving an invalid (0, 0) entry that can be
7589 confused with the terminator. */
7590 if (text_section_used)
7592 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7593 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7594 text_section_label, "Length");
7596 if (cold_text_section_used)
7598 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7600 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7601 cold_text_section_label, "Length");
7604 for (i = 0; i < arange_table_in_use; i++)
7606 dw_die_ref die = arange_table[i];
7608 /* We shouldn't see aranges for DIEs outside of the main CU. */
7609 gcc_assert (die->die_mark);
7611 if (die->die_tag == DW_TAG_subprogram)
7613 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7615 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7616 get_AT_low_pc (die), "Length");
7620 /* A static variable; extract the symbol from DW_AT_location.
7621 Note that this code isn't currently hit, as we only emit
7622 aranges for functions (jason 9/23/99). */
7623 dw_attr_ref a = get_AT (die, DW_AT_location);
7624 dw_loc_descr_ref loc;
7626 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7629 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7631 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7632 loc->dw_loc_oprnd1.v.val_addr, "Address");
7633 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7634 get_AT_unsigned (die, DW_AT_byte_size),
7639 /* Output the terminator words. */
7640 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7641 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7644 /* Add a new entry to .debug_ranges. Return the offset at which it
7648 add_ranges_num (int num)
7650 unsigned int in_use = ranges_table_in_use;
7652 if (in_use == ranges_table_allocated)
7654 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7656 = ggc_realloc (ranges_table, (ranges_table_allocated
7657 * sizeof (struct dw_ranges_struct)));
7658 memset (ranges_table + ranges_table_in_use, 0,
7659 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7662 ranges_table[in_use].num = num;
7663 ranges_table_in_use = in_use + 1;
7665 return in_use * 2 * DWARF2_ADDR_SIZE;
7668 /* Add a new entry to .debug_ranges corresponding to a block, or a
7669 range terminator if BLOCK is NULL. */
7672 add_ranges (const_tree block)
7674 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
7677 /* Add a new entry to .debug_ranges corresponding to a pair of
7681 add_ranges_by_labels (const char *begin, const char *end)
7683 unsigned int in_use = ranges_by_label_in_use;
7685 if (in_use == ranges_by_label_allocated)
7687 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
7689 = ggc_realloc (ranges_by_label,
7690 (ranges_by_label_allocated
7691 * sizeof (struct dw_ranges_by_label_struct)));
7692 memset (ranges_by_label + ranges_by_label_in_use, 0,
7693 RANGES_TABLE_INCREMENT
7694 * sizeof (struct dw_ranges_by_label_struct));
7697 ranges_by_label[in_use].begin = begin;
7698 ranges_by_label[in_use].end = end;
7699 ranges_by_label_in_use = in_use + 1;
7701 return add_ranges_num (-(int)in_use - 1);
7705 output_ranges (void)
7708 static const char *const start_fmt = "Offset 0x%x";
7709 const char *fmt = start_fmt;
7711 for (i = 0; i < ranges_table_in_use; i++)
7713 int block_num = ranges_table[i].num;
7717 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7718 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7720 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7721 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7723 /* If all code is in the text section, then the compilation
7724 unit base address defaults to DW_AT_low_pc, which is the
7725 base of the text section. */
7726 if (!have_multiple_function_sections)
7728 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7730 fmt, i * 2 * DWARF2_ADDR_SIZE);
7731 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7732 text_section_label, NULL);
7735 /* Otherwise, the compilation unit base address is zero,
7736 which allows us to use absolute addresses, and not worry
7737 about whether the target supports cross-section
7741 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7742 fmt, i * 2 * DWARF2_ADDR_SIZE);
7743 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7749 /* Negative block_num stands for an index into ranges_by_label. */
7750 else if (block_num < 0)
7752 int lab_idx = - block_num - 1;
7754 if (!have_multiple_function_sections)
7758 /* If we ever use add_ranges_by_labels () for a single
7759 function section, all we have to do is to take out
7761 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7762 ranges_by_label[lab_idx].begin,
7764 fmt, i * 2 * DWARF2_ADDR_SIZE);
7765 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7766 ranges_by_label[lab_idx].end,
7767 text_section_label, NULL);
7772 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7773 ranges_by_label[lab_idx].begin,
7774 fmt, i * 2 * DWARF2_ADDR_SIZE);
7775 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7776 ranges_by_label[lab_idx].end,
7782 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7783 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7789 /* Data structure containing information about input files. */
7792 const char *path; /* Complete file name. */
7793 const char *fname; /* File name part. */
7794 int length; /* Length of entire string. */
7795 struct dwarf_file_data * file_idx; /* Index in input file table. */
7796 int dir_idx; /* Index in directory table. */
7799 /* Data structure containing information about directories with source
7803 const char *path; /* Path including directory name. */
7804 int length; /* Path length. */
7805 int prefix; /* Index of directory entry which is a prefix. */
7806 int count; /* Number of files in this directory. */
7807 int dir_idx; /* Index of directory used as base. */
7810 /* Callback function for file_info comparison. We sort by looking at
7811 the directories in the path. */
7814 file_info_cmp (const void *p1, const void *p2)
7816 const struct file_info *s1 = p1;
7817 const struct file_info *s2 = p2;
7818 const unsigned char *cp1;
7819 const unsigned char *cp2;
7821 /* Take care of file names without directories. We need to make sure that
7822 we return consistent values to qsort since some will get confused if
7823 we return the same value when identical operands are passed in opposite
7824 orders. So if neither has a directory, return 0 and otherwise return
7825 1 or -1 depending on which one has the directory. */
7826 if ((s1->path == s1->fname || s2->path == s2->fname))
7827 return (s2->path == s2->fname) - (s1->path == s1->fname);
7829 cp1 = (const unsigned char *) s1->path;
7830 cp2 = (const unsigned char *) s2->path;
7836 /* Reached the end of the first path? If so, handle like above. */
7837 if ((cp1 == (const unsigned char *) s1->fname)
7838 || (cp2 == (const unsigned char *) s2->fname))
7839 return ((cp2 == (const unsigned char *) s2->fname)
7840 - (cp1 == (const unsigned char *) s1->fname));
7842 /* Character of current path component the same? */
7843 else if (*cp1 != *cp2)
7848 struct file_name_acquire_data
7850 struct file_info *files;
7855 /* Traversal function for the hash table. */
7858 file_name_acquire (void ** slot, void *data)
7860 struct file_name_acquire_data *fnad = data;
7861 struct dwarf_file_data *d = *slot;
7862 struct file_info *fi;
7865 gcc_assert (fnad->max_files >= d->emitted_number);
7867 if (! d->emitted_number)
7870 gcc_assert (fnad->max_files != fnad->used_files);
7872 fi = fnad->files + fnad->used_files++;
7874 /* Skip all leading "./". */
7876 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7879 /* Create a new array entry. */
7881 fi->length = strlen (f);
7884 /* Search for the file name part. */
7885 f = strrchr (f, DIR_SEPARATOR);
7886 #if defined (DIR_SEPARATOR_2)
7888 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7892 if (f == NULL || f < g)
7898 fi->fname = f == NULL ? fi->path : f + 1;
7902 /* Output the directory table and the file name table. We try to minimize
7903 the total amount of memory needed. A heuristic is used to avoid large
7904 slowdowns with many input files. */
7907 output_file_names (void)
7909 struct file_name_acquire_data fnad;
7911 struct file_info *files;
7912 struct dir_info *dirs;
7921 if (!last_emitted_file)
7923 dw2_asm_output_data (1, 0, "End directory table");
7924 dw2_asm_output_data (1, 0, "End file name table");
7928 numfiles = last_emitted_file->emitted_number;
7930 /* Allocate the various arrays we need. */
7931 files = alloca (numfiles * sizeof (struct file_info));
7932 dirs = alloca (numfiles * sizeof (struct dir_info));
7935 fnad.used_files = 0;
7936 fnad.max_files = numfiles;
7937 htab_traverse (file_table, file_name_acquire, &fnad);
7938 gcc_assert (fnad.used_files == fnad.max_files);
7940 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
7942 /* Find all the different directories used. */
7943 dirs[0].path = files[0].path;
7944 dirs[0].length = files[0].fname - files[0].path;
7945 dirs[0].prefix = -1;
7947 dirs[0].dir_idx = 0;
7948 files[0].dir_idx = 0;
7951 for (i = 1; i < numfiles; i++)
7952 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7953 && memcmp (dirs[ndirs - 1].path, files[i].path,
7954 dirs[ndirs - 1].length) == 0)
7956 /* Same directory as last entry. */
7957 files[i].dir_idx = ndirs - 1;
7958 ++dirs[ndirs - 1].count;
7964 /* This is a new directory. */
7965 dirs[ndirs].path = files[i].path;
7966 dirs[ndirs].length = files[i].fname - files[i].path;
7967 dirs[ndirs].count = 1;
7968 dirs[ndirs].dir_idx = ndirs;
7969 files[i].dir_idx = ndirs;
7971 /* Search for a prefix. */
7972 dirs[ndirs].prefix = -1;
7973 for (j = 0; j < ndirs; j++)
7974 if (dirs[j].length < dirs[ndirs].length
7975 && dirs[j].length > 1
7976 && (dirs[ndirs].prefix == -1
7977 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7978 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7979 dirs[ndirs].prefix = j;
7984 /* Now to the actual work. We have to find a subset of the directories which
7985 allow expressing the file name using references to the directory table
7986 with the least amount of characters. We do not do an exhaustive search
7987 where we would have to check out every combination of every single
7988 possible prefix. Instead we use a heuristic which provides nearly optimal
7989 results in most cases and never is much off. */
7990 saved = alloca (ndirs * sizeof (int));
7991 savehere = alloca (ndirs * sizeof (int));
7993 memset (saved, '\0', ndirs * sizeof (saved[0]));
7994 for (i = 0; i < ndirs; i++)
7999 /* We can always save some space for the current directory. But this
8000 does not mean it will be enough to justify adding the directory. */
8001 savehere[i] = dirs[i].length;
8002 total = (savehere[i] - saved[i]) * dirs[i].count;
8004 for (j = i + 1; j < ndirs; j++)
8007 if (saved[j] < dirs[i].length)
8009 /* Determine whether the dirs[i] path is a prefix of the
8014 while (k != -1 && k != (int) i)
8019 /* Yes it is. We can possibly save some memory by
8020 writing the filenames in dirs[j] relative to
8022 savehere[j] = dirs[i].length;
8023 total += (savehere[j] - saved[j]) * dirs[j].count;
8028 /* Check whether we can save enough to justify adding the dirs[i]
8030 if (total > dirs[i].length + 1)
8032 /* It's worthwhile adding. */
8033 for (j = i; j < ndirs; j++)
8034 if (savehere[j] > 0)
8036 /* Remember how much we saved for this directory so far. */
8037 saved[j] = savehere[j];
8039 /* Remember the prefix directory. */
8040 dirs[j].dir_idx = i;
8045 /* Emit the directory name table. */
8047 idx_offset = dirs[0].length > 0 ? 1 : 0;
8048 for (i = 1 - idx_offset; i < ndirs; i++)
8049 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8050 "Directory Entry: 0x%x", i + idx_offset);
8052 dw2_asm_output_data (1, 0, "End directory table");
8054 /* We have to emit them in the order of emitted_number since that's
8055 used in the debug info generation. To do this efficiently we
8056 generate a back-mapping of the indices first. */
8057 backmap = alloca (numfiles * sizeof (int));
8058 for (i = 0; i < numfiles; i++)
8059 backmap[files[i].file_idx->emitted_number - 1] = i;
8061 /* Now write all the file names. */
8062 for (i = 0; i < numfiles; i++)
8064 int file_idx = backmap[i];
8065 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8067 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8068 "File Entry: 0x%x", (unsigned) i + 1);
8070 /* Include directory index. */
8071 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8073 /* Modification time. */
8074 dw2_asm_output_data_uleb128 (0, NULL);
8076 /* File length in bytes. */
8077 dw2_asm_output_data_uleb128 (0, NULL);
8080 dw2_asm_output_data (1, 0, "End file name table");
8084 /* Output the source line number correspondence information. This
8085 information goes into the .debug_line section. */
8088 output_line_info (void)
8090 char l1[20], l2[20], p1[20], p2[20];
8091 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8092 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8095 unsigned long lt_index;
8096 unsigned long current_line;
8099 unsigned long current_file;
8100 unsigned long function;
8102 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8103 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8104 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8105 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8107 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8108 dw2_asm_output_data (4, 0xffffffff,
8109 "Initial length escape value indicating 64-bit DWARF extension");
8110 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8111 "Length of Source Line Info");
8112 ASM_OUTPUT_LABEL (asm_out_file, l1);
8114 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8115 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8116 ASM_OUTPUT_LABEL (asm_out_file, p1);
8118 /* Define the architecture-dependent minimum instruction length (in
8119 bytes). In this implementation of DWARF, this field is used for
8120 information purposes only. Since GCC generates assembly language,
8121 we have no a priori knowledge of how many instruction bytes are
8122 generated for each source line, and therefore can use only the
8123 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8124 commands. Accordingly, we fix this as `1', which is "correct
8125 enough" for all architectures, and don't let the target override. */
8126 dw2_asm_output_data (1, 1,
8127 "Minimum Instruction Length");
8129 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8130 "Default is_stmt_start flag");
8131 dw2_asm_output_data (1, DWARF_LINE_BASE,
8132 "Line Base Value (Special Opcodes)");
8133 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8134 "Line Range Value (Special Opcodes)");
8135 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8136 "Special Opcode Base");
8138 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8142 case DW_LNS_advance_pc:
8143 case DW_LNS_advance_line:
8144 case DW_LNS_set_file:
8145 case DW_LNS_set_column:
8146 case DW_LNS_fixed_advance_pc:
8154 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8158 /* Write out the information about the files we use. */
8159 output_file_names ();
8160 ASM_OUTPUT_LABEL (asm_out_file, p2);
8162 /* We used to set the address register to the first location in the text
8163 section here, but that didn't accomplish anything since we already
8164 have a line note for the opening brace of the first function. */
8166 /* Generate the line number to PC correspondence table, encoded as
8167 a series of state machine operations. */
8171 if (cfun && in_cold_section_p)
8172 strcpy (prev_line_label, cfun->cold_section_label);
8174 strcpy (prev_line_label, text_section_label);
8175 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8177 dw_line_info_ref line_info = &line_info_table[lt_index];
8180 /* Disable this optimization for now; GDB wants to see two line notes
8181 at the beginning of a function so it can find the end of the
8184 /* Don't emit anything for redundant notes. Just updating the
8185 address doesn't accomplish anything, because we already assume
8186 that anything after the last address is this line. */
8187 if (line_info->dw_line_num == current_line
8188 && line_info->dw_file_num == current_file)
8192 /* Emit debug info for the address of the current line.
8194 Unfortunately, we have little choice here currently, and must always
8195 use the most general form. GCC does not know the address delta
8196 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8197 attributes which will give an upper bound on the address range. We
8198 could perhaps use length attributes to determine when it is safe to
8199 use DW_LNS_fixed_advance_pc. */
8201 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8204 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8205 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8206 "DW_LNS_fixed_advance_pc");
8207 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8211 /* This can handle any delta. This takes
8212 4+DWARF2_ADDR_SIZE bytes. */
8213 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8214 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8215 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8216 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8219 strcpy (prev_line_label, line_label);
8221 /* Emit debug info for the source file of the current line, if
8222 different from the previous line. */
8223 if (line_info->dw_file_num != current_file)
8225 current_file = line_info->dw_file_num;
8226 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8227 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8230 /* Emit debug info for the current line number, choosing the encoding
8231 that uses the least amount of space. */
8232 if (line_info->dw_line_num != current_line)
8234 line_offset = line_info->dw_line_num - current_line;
8235 line_delta = line_offset - DWARF_LINE_BASE;
8236 current_line = line_info->dw_line_num;
8237 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8238 /* This can handle deltas from -10 to 234, using the current
8239 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8241 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8242 "line %lu", current_line);
8245 /* This can handle any delta. This takes at least 4 bytes,
8246 depending on the value being encoded. */
8247 dw2_asm_output_data (1, DW_LNS_advance_line,
8248 "advance to line %lu", current_line);
8249 dw2_asm_output_data_sleb128 (line_offset, NULL);
8250 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8254 /* We still need to start a new row, so output a copy insn. */
8255 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8258 /* Emit debug info for the address of the end of the function. */
8261 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8262 "DW_LNS_fixed_advance_pc");
8263 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8267 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8268 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8269 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8270 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8273 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8274 dw2_asm_output_data_uleb128 (1, NULL);
8275 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8280 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8282 dw_separate_line_info_ref line_info
8283 = &separate_line_info_table[lt_index];
8286 /* Don't emit anything for redundant notes. */
8287 if (line_info->dw_line_num == current_line
8288 && line_info->dw_file_num == current_file
8289 && line_info->function == function)
8293 /* Emit debug info for the address of the current line. If this is
8294 a new function, or the first line of a function, then we need
8295 to handle it differently. */
8296 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8298 if (function != line_info->function)
8300 function = line_info->function;
8302 /* Set the address register to the first line in the function. */
8303 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8304 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8305 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8306 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8310 /* ??? See the DW_LNS_advance_pc comment above. */
8313 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8314 "DW_LNS_fixed_advance_pc");
8315 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8319 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8320 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8321 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8322 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8326 strcpy (prev_line_label, line_label);
8328 /* Emit debug info for the source file of the current line, if
8329 different from the previous line. */
8330 if (line_info->dw_file_num != current_file)
8332 current_file = line_info->dw_file_num;
8333 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8334 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8337 /* Emit debug info for the current line number, choosing the encoding
8338 that uses the least amount of space. */
8339 if (line_info->dw_line_num != current_line)
8341 line_offset = line_info->dw_line_num - current_line;
8342 line_delta = line_offset - DWARF_LINE_BASE;
8343 current_line = line_info->dw_line_num;
8344 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8345 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8346 "line %lu", current_line);
8349 dw2_asm_output_data (1, DW_LNS_advance_line,
8350 "advance to line %lu", current_line);
8351 dw2_asm_output_data_sleb128 (line_offset, NULL);
8352 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8356 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8364 /* If we're done with a function, end its sequence. */
8365 if (lt_index == separate_line_info_table_in_use
8366 || separate_line_info_table[lt_index].function != function)
8371 /* Emit debug info for the address of the end of the function. */
8372 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8375 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8376 "DW_LNS_fixed_advance_pc");
8377 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8381 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8382 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8383 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8384 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8387 /* Output the marker for the end of this sequence. */
8388 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8389 dw2_asm_output_data_uleb128 (1, NULL);
8390 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8394 /* Output the marker for the end of the line number info. */
8395 ASM_OUTPUT_LABEL (asm_out_file, l2);
8398 /* Given a pointer to a tree node for some base type, return a pointer to
8399 a DIE that describes the given type.
8401 This routine must only be called for GCC type nodes that correspond to
8402 Dwarf base (fundamental) types. */
8405 base_type_die (tree type)
8407 dw_die_ref base_type_result;
8408 enum dwarf_type encoding;
8410 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8413 switch (TREE_CODE (type))
8416 if (TYPE_STRING_FLAG (type))
8418 if (TYPE_UNSIGNED (type))
8419 encoding = DW_ATE_unsigned_char;
8421 encoding = DW_ATE_signed_char;
8423 else if (TYPE_UNSIGNED (type))
8424 encoding = DW_ATE_unsigned;
8426 encoding = DW_ATE_signed;
8430 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8431 encoding = DW_ATE_decimal_float;
8433 encoding = DW_ATE_float;
8436 case FIXED_POINT_TYPE:
8437 if (TYPE_UNSIGNED (type))
8438 encoding = DW_ATE_unsigned_fixed;
8440 encoding = DW_ATE_signed_fixed;
8443 /* Dwarf2 doesn't know anything about complex ints, so use
8444 a user defined type for it. */
8446 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8447 encoding = DW_ATE_complex_float;
8449 encoding = DW_ATE_lo_user;
8453 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8454 encoding = DW_ATE_boolean;
8458 /* No other TREE_CODEs are Dwarf fundamental types. */
8462 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8464 /* This probably indicates a bug. */
8465 if (! TYPE_NAME (type))
8466 add_name_attribute (base_type_result, "__unknown__");
8468 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8469 int_size_in_bytes (type));
8470 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8472 return base_type_result;
8475 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8476 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8479 is_base_type (tree type)
8481 switch (TREE_CODE (type))
8487 case FIXED_POINT_TYPE:
8495 case QUAL_UNION_TYPE:
8500 case REFERENCE_TYPE:
8513 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8514 node, return the size in bits for the type if it is a constant, or else
8515 return the alignment for the type if the type's size is not constant, or
8516 else return BITS_PER_WORD if the type actually turns out to be an
8519 static inline unsigned HOST_WIDE_INT
8520 simple_type_size_in_bits (const_tree type)
8522 if (TREE_CODE (type) == ERROR_MARK)
8523 return BITS_PER_WORD;
8524 else if (TYPE_SIZE (type) == NULL_TREE)
8526 else if (host_integerp (TYPE_SIZE (type), 1))
8527 return tree_low_cst (TYPE_SIZE (type), 1);
8529 return TYPE_ALIGN (type);
8532 /* Return true if the debug information for the given type should be
8533 emitted as a subrange type. */
8536 is_subrange_type (const_tree type)
8538 tree subtype = TREE_TYPE (type);
8540 /* Subrange types are identified by the fact that they are integer
8541 types, and that they have a subtype which is either an integer type
8542 or an enumeral type. */
8544 if (TREE_CODE (type) != INTEGER_TYPE
8545 || subtype == NULL_TREE)
8548 if (TREE_CODE (subtype) != INTEGER_TYPE
8549 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8552 if (TREE_CODE (type) == TREE_CODE (subtype)
8553 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8554 && TYPE_MIN_VALUE (type) != NULL
8555 && TYPE_MIN_VALUE (subtype) != NULL
8556 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8557 && TYPE_MAX_VALUE (type) != NULL
8558 && TYPE_MAX_VALUE (subtype) != NULL
8559 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8561 /* The type and its subtype have the same representation. If in
8562 addition the two types also have the same name, then the given
8563 type is not a subrange type, but rather a plain base type. */
8564 /* FIXME: brobecker/2004-03-22:
8565 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8566 therefore be sufficient to check the TYPE_SIZE node pointers
8567 rather than checking the actual size. Unfortunately, we have
8568 found some cases, such as in the Ada "integer" type, where
8569 this is not the case. Until this problem is solved, we need to
8570 keep checking the actual size. */
8571 tree type_name = TYPE_NAME (type);
8572 tree subtype_name = TYPE_NAME (subtype);
8574 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8575 type_name = DECL_NAME (type_name);
8577 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8578 subtype_name = DECL_NAME (subtype_name);
8580 if (type_name == subtype_name)
8587 /* Given a pointer to a tree node for a subrange type, return a pointer
8588 to a DIE that describes the given type. */
8591 subrange_type_die (tree type, dw_die_ref context_die)
8593 dw_die_ref subrange_die;
8594 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8596 if (context_die == NULL)
8597 context_die = comp_unit_die;
8599 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8601 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8603 /* The size of the subrange type and its base type do not match,
8604 so we need to generate a size attribute for the subrange type. */
8605 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8608 if (TYPE_MIN_VALUE (type) != NULL)
8609 add_bound_info (subrange_die, DW_AT_lower_bound,
8610 TYPE_MIN_VALUE (type));
8611 if (TYPE_MAX_VALUE (type) != NULL)
8612 add_bound_info (subrange_die, DW_AT_upper_bound,
8613 TYPE_MAX_VALUE (type));
8615 return subrange_die;
8618 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8619 entry that chains various modifiers in front of the given type. */
8622 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8623 dw_die_ref context_die)
8625 enum tree_code code = TREE_CODE (type);
8626 dw_die_ref mod_type_die;
8627 dw_die_ref sub_die = NULL;
8628 tree item_type = NULL;
8629 tree qualified_type;
8632 if (code == ERROR_MARK)
8635 /* See if we already have the appropriately qualified variant of
8638 = get_qualified_type (type,
8639 ((is_const_type ? TYPE_QUAL_CONST : 0)
8640 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8642 /* If we do, then we can just use its DIE, if it exists. */
8645 mod_type_die = lookup_type_die (qualified_type);
8647 return mod_type_die;
8650 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8652 /* Handle C typedef types. */
8653 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8655 tree dtype = TREE_TYPE (name);
8657 if (qualified_type == dtype)
8659 /* For a named type, use the typedef. */
8660 gen_type_die (qualified_type, context_die);
8661 return lookup_type_die (qualified_type);
8663 else if (is_const_type < TYPE_READONLY (dtype)
8664 || is_volatile_type < TYPE_VOLATILE (dtype)
8665 || (is_const_type <= TYPE_READONLY (dtype)
8666 && is_volatile_type <= TYPE_VOLATILE (dtype)
8667 && DECL_ORIGINAL_TYPE (name) != type))
8668 /* cv-unqualified version of named type. Just use the unnamed
8669 type to which it refers. */
8670 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8671 is_const_type, is_volatile_type,
8673 /* Else cv-qualified version of named type; fall through. */
8678 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8679 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8681 else if (is_volatile_type)
8683 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8684 sub_die = modified_type_die (type, 0, 0, context_die);
8686 else if (code == POINTER_TYPE)
8688 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8689 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8690 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8691 item_type = TREE_TYPE (type);
8693 else if (code == REFERENCE_TYPE)
8695 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8696 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8697 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8698 item_type = TREE_TYPE (type);
8700 else if (is_subrange_type (type))
8702 mod_type_die = subrange_type_die (type, context_die);
8703 item_type = TREE_TYPE (type);
8705 else if (is_base_type (type))
8706 mod_type_die = base_type_die (type);
8709 gen_type_die (type, context_die);
8711 /* We have to get the type_main_variant here (and pass that to the
8712 `lookup_type_die' routine) because the ..._TYPE node we have
8713 might simply be a *copy* of some original type node (where the
8714 copy was created to help us keep track of typedef names) and
8715 that copy might have a different TYPE_UID from the original
8717 if (TREE_CODE (type) != VECTOR_TYPE)
8718 return lookup_type_die (type_main_variant (type));
8720 /* Vectors have the debugging information in the type,
8721 not the main variant. */
8722 return lookup_type_die (type);
8725 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8726 don't output a DW_TAG_typedef, since there isn't one in the
8727 user's program; just attach a DW_AT_name to the type. */
8729 && (TREE_CODE (name) != TYPE_DECL
8730 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
8732 if (TREE_CODE (name) == TYPE_DECL)
8733 /* Could just call add_name_and_src_coords_attributes here,
8734 but since this is a builtin type it doesn't have any
8735 useful source coordinates anyway. */
8736 name = DECL_NAME (name);
8737 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8741 equate_type_number_to_die (qualified_type, mod_type_die);
8744 /* We must do this after the equate_type_number_to_die call, in case
8745 this is a recursive type. This ensures that the modified_type_die
8746 recursion will terminate even if the type is recursive. Recursive
8747 types are possible in Ada. */
8748 sub_die = modified_type_die (item_type,
8749 TYPE_READONLY (item_type),
8750 TYPE_VOLATILE (item_type),
8753 if (sub_die != NULL)
8754 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8756 return mod_type_die;
8759 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8760 an enumerated type. */
8763 type_is_enum (const_tree type)
8765 return TREE_CODE (type) == ENUMERAL_TYPE;
8768 /* Return the DBX register number described by a given RTL node. */
8771 dbx_reg_number (const_rtx rtl)
8773 unsigned regno = REGNO (rtl);
8775 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8777 #ifdef LEAF_REG_REMAP
8778 if (current_function_uses_only_leaf_regs)
8780 int leaf_reg = LEAF_REG_REMAP (regno);
8782 regno = (unsigned) leaf_reg;
8786 return DBX_REGISTER_NUMBER (regno);
8789 /* Optionally add a DW_OP_piece term to a location description expression.
8790 DW_OP_piece is only added if the location description expression already
8791 doesn't end with DW_OP_piece. */
8794 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8796 dw_loc_descr_ref loc;
8798 if (*list_head != NULL)
8800 /* Find the end of the chain. */
8801 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8804 if (loc->dw_loc_opc != DW_OP_piece)
8805 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8809 /* Return a location descriptor that designates a machine register or
8810 zero if there is none. */
8812 static dw_loc_descr_ref
8813 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
8817 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8820 regs = targetm.dwarf_register_span (rtl);
8822 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8823 return multiple_reg_loc_descriptor (rtl, regs, initialized);
8825 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
8828 /* Return a location descriptor that designates a machine register for
8829 a given hard register number. */
8831 static dw_loc_descr_ref
8832 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
8834 dw_loc_descr_ref reg_loc_descr;
8836 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8838 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
8840 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8841 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8843 return reg_loc_descr;
8846 /* Given an RTL of a register, return a location descriptor that
8847 designates a value that spans more than one register. */
8849 static dw_loc_descr_ref
8850 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
8851 enum var_init_status initialized)
8855 dw_loc_descr_ref loc_result = NULL;
8858 #ifdef LEAF_REG_REMAP
8859 if (current_function_uses_only_leaf_regs)
8861 int leaf_reg = LEAF_REG_REMAP (reg);
8863 reg = (unsigned) leaf_reg;
8866 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8867 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8869 /* Simple, contiguous registers. */
8870 if (regs == NULL_RTX)
8872 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8879 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
8880 VAR_INIT_STATUS_INITIALIZED);
8881 add_loc_descr (&loc_result, t);
8882 add_loc_descr_op_piece (&loc_result, size);
8888 /* Now onto stupid register sets in non contiguous locations. */
8890 gcc_assert (GET_CODE (regs) == PARALLEL);
8892 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8895 for (i = 0; i < XVECLEN (regs, 0); ++i)
8899 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
8900 VAR_INIT_STATUS_INITIALIZED);
8901 add_loc_descr (&loc_result, t);
8902 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8903 add_loc_descr_op_piece (&loc_result, size);
8906 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8907 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8911 /* Return a location descriptor that designates a constant. */
8913 static dw_loc_descr_ref
8914 int_loc_descriptor (HOST_WIDE_INT i)
8916 enum dwarf_location_atom op;
8918 /* Pick the smallest representation of a constant, rather than just
8919 defaulting to the LEB encoding. */
8923 op = DW_OP_lit0 + i;
8926 else if (i <= 0xffff)
8928 else if (HOST_BITS_PER_WIDE_INT == 32
8938 else if (i >= -0x8000)
8940 else if (HOST_BITS_PER_WIDE_INT == 32
8941 || i >= -0x80000000)
8947 return new_loc_descr (op, i, 0);
8950 /* Return a location descriptor that designates a base+offset location. */
8952 static dw_loc_descr_ref
8953 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
8954 enum var_init_status initialized)
8957 dw_loc_descr_ref result;
8959 /* We only use "frame base" when we're sure we're talking about the
8960 post-prologue local stack frame. We do this by *not* running
8961 register elimination until this point, and recognizing the special
8962 argument pointer and soft frame pointer rtx's. */
8963 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8965 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8969 if (GET_CODE (elim) == PLUS)
8971 offset += INTVAL (XEXP (elim, 1));
8972 elim = XEXP (elim, 0);
8974 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8975 : stack_pointer_rtx));
8976 offset += frame_pointer_fb_offset;
8978 return new_loc_descr (DW_OP_fbreg, offset, 0);
8982 regno = dbx_reg_number (reg);
8984 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
8986 result = new_loc_descr (DW_OP_bregx, regno, offset);
8988 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8989 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8994 /* Return true if this RTL expression describes a base+offset calculation. */
8997 is_based_loc (const_rtx rtl)
8999 return (GET_CODE (rtl) == PLUS
9000 && ((REG_P (XEXP (rtl, 0))
9001 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9002 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9005 /* Return a descriptor that describes the concatenation of N locations
9006 used to form the address of a memory location. */
9008 static dw_loc_descr_ref
9009 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9010 enum var_init_status initialized)
9013 dw_loc_descr_ref cc_loc_result = NULL;
9014 unsigned int n = XVECLEN (concatn, 0);
9016 for (i = 0; i < n; ++i)
9018 dw_loc_descr_ref ref;
9019 rtx x = XVECEXP (concatn, 0, i);
9021 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9025 add_loc_descr (&cc_loc_result, ref);
9026 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9029 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9030 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9032 return cc_loc_result;
9035 /* The following routine converts the RTL for a variable or parameter
9036 (resident in memory) into an equivalent Dwarf representation of a
9037 mechanism for getting the address of that same variable onto the top of a
9038 hypothetical "address evaluation" stack.
9040 When creating memory location descriptors, we are effectively transforming
9041 the RTL for a memory-resident object into its Dwarf postfix expression
9042 equivalent. This routine recursively descends an RTL tree, turning
9043 it into Dwarf postfix code as it goes.
9045 MODE is the mode of the memory reference, needed to handle some
9046 autoincrement addressing modes.
9048 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9049 location list for RTL.
9051 Return 0 if we can't represent the location. */
9053 static dw_loc_descr_ref
9054 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9055 enum var_init_status initialized)
9057 dw_loc_descr_ref mem_loc_result = NULL;
9058 enum dwarf_location_atom op;
9060 /* Note that for a dynamically sized array, the location we will generate a
9061 description of here will be the lowest numbered location which is
9062 actually within the array. That's *not* necessarily the same as the
9063 zeroth element of the array. */
9065 rtl = targetm.delegitimize_address (rtl);
9067 switch (GET_CODE (rtl))
9072 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9073 just fall into the SUBREG code. */
9075 /* ... fall through ... */
9078 /* The case of a subreg may arise when we have a local (register)
9079 variable or a formal (register) parameter which doesn't quite fill
9080 up an entire register. For now, just assume that it is
9081 legitimate to make the Dwarf info refer to the whole register which
9082 contains the given subreg. */
9083 rtl = XEXP (rtl, 0);
9085 /* ... fall through ... */
9088 /* Whenever a register number forms a part of the description of the
9089 method for calculating the (dynamic) address of a memory resident
9090 object, DWARF rules require the register number be referred to as
9091 a "base register". This distinction is not based in any way upon
9092 what category of register the hardware believes the given register
9093 belongs to. This is strictly DWARF terminology we're dealing with
9094 here. Note that in cases where the location of a memory-resident
9095 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9096 OP_CONST (0)) the actual DWARF location descriptor that we generate
9097 may just be OP_BASEREG (basereg). This may look deceptively like
9098 the object in question was allocated to a register (rather than in
9099 memory) so DWARF consumers need to be aware of the subtle
9100 distinction between OP_REG and OP_BASEREG. */
9101 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9102 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9106 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9107 VAR_INIT_STATUS_INITIALIZED);
9108 if (mem_loc_result != 0)
9109 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9113 rtl = XEXP (rtl, 1);
9115 /* ... fall through ... */
9118 /* Some ports can transform a symbol ref into a label ref, because
9119 the symbol ref is too far away and has to be dumped into a constant
9123 /* Alternatively, the symbol in the constant pool might be referenced
9124 by a different symbol. */
9125 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9128 rtx tmp = get_pool_constant_mark (rtl, &marked);
9130 if (GET_CODE (tmp) == SYMBOL_REF)
9133 if (CONSTANT_POOL_ADDRESS_P (tmp))
9134 get_pool_constant_mark (tmp, &marked);
9139 /* If all references to this pool constant were optimized away,
9140 it was not output and thus we can't represent it.
9141 FIXME: might try to use DW_OP_const_value here, though
9142 DW_OP_piece complicates it. */
9147 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9148 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9149 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9150 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9154 /* Extract the PLUS expression nested inside and fall into
9156 rtl = XEXP (rtl, 1);
9161 /* Turn these into a PLUS expression and fall into the PLUS code
9163 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9164 GEN_INT (GET_CODE (rtl) == PRE_INC
9165 ? GET_MODE_UNIT_SIZE (mode)
9166 : -GET_MODE_UNIT_SIZE (mode)));
9168 /* ... fall through ... */
9172 if (is_based_loc (rtl))
9173 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9174 INTVAL (XEXP (rtl, 1)),
9175 VAR_INIT_STATUS_INITIALIZED);
9178 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9179 VAR_INIT_STATUS_INITIALIZED);
9180 if (mem_loc_result == 0)
9183 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9184 && INTVAL (XEXP (rtl, 1)) >= 0)
9185 add_loc_descr (&mem_loc_result,
9186 new_loc_descr (DW_OP_plus_uconst,
9187 INTVAL (XEXP (rtl, 1)), 0));
9190 add_loc_descr (&mem_loc_result,
9191 mem_loc_descriptor (XEXP (rtl, 1), mode,
9192 VAR_INIT_STATUS_INITIALIZED));
9193 add_loc_descr (&mem_loc_result,
9194 new_loc_descr (DW_OP_plus, 0, 0));
9199 /* If a pseudo-reg is optimized away, it is possible for it to
9200 be replaced with a MEM containing a multiply or shift. */
9219 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9220 VAR_INIT_STATUS_INITIALIZED);
9221 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9222 VAR_INIT_STATUS_INITIALIZED);
9224 if (op0 == 0 || op1 == 0)
9227 mem_loc_result = op0;
9228 add_loc_descr (&mem_loc_result, op1);
9229 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9234 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9238 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9239 VAR_INIT_STATUS_INITIALIZED);
9246 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9247 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9249 return mem_loc_result;
9252 /* Return a descriptor that describes the concatenation of two locations.
9253 This is typically a complex variable. */
9255 static dw_loc_descr_ref
9256 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9258 dw_loc_descr_ref cc_loc_result = NULL;
9259 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9260 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9262 if (x0_ref == 0 || x1_ref == 0)
9265 cc_loc_result = x0_ref;
9266 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9268 add_loc_descr (&cc_loc_result, x1_ref);
9269 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9271 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9272 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9274 return cc_loc_result;
9277 /* Return a descriptor that describes the concatenation of N
9280 static dw_loc_descr_ref
9281 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9284 dw_loc_descr_ref cc_loc_result = NULL;
9285 unsigned int n = XVECLEN (concatn, 0);
9287 for (i = 0; i < n; ++i)
9289 dw_loc_descr_ref ref;
9290 rtx x = XVECEXP (concatn, 0, i);
9292 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9296 add_loc_descr (&cc_loc_result, ref);
9297 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9300 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9301 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9303 return cc_loc_result;
9306 /* Output a proper Dwarf location descriptor for a variable or parameter
9307 which is either allocated in a register or in a memory location. For a
9308 register, we just generate an OP_REG and the register number. For a
9309 memory location we provide a Dwarf postfix expression describing how to
9310 generate the (dynamic) address of the object onto the address stack.
9312 If we don't know how to describe it, return 0. */
9314 static dw_loc_descr_ref
9315 loc_descriptor (rtx rtl, enum var_init_status initialized)
9317 dw_loc_descr_ref loc_result = NULL;
9319 switch (GET_CODE (rtl))
9322 /* The case of a subreg may arise when we have a local (register)
9323 variable or a formal (register) parameter which doesn't quite fill
9324 up an entire register. For now, just assume that it is
9325 legitimate to make the Dwarf info refer to the whole register which
9326 contains the given subreg. */
9327 rtl = SUBREG_REG (rtl);
9329 /* ... fall through ... */
9332 loc_result = reg_loc_descriptor (rtl, initialized);
9336 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9341 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9346 loc_result = concatn_loc_descriptor (rtl, initialized);
9351 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9353 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9357 rtl = XEXP (rtl, 1);
9362 rtvec par_elems = XVEC (rtl, 0);
9363 int num_elem = GET_NUM_ELEM (par_elems);
9364 enum machine_mode mode;
9367 /* Create the first one, so we have something to add to. */
9368 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9370 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9371 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9372 for (i = 1; i < num_elem; i++)
9374 dw_loc_descr_ref temp;
9376 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9378 add_loc_descr (&loc_result, temp);
9379 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9380 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9392 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9393 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9394 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9395 top-level invocation, and we require the address of LOC; is 0 if we require
9396 the value of LOC. */
9398 static dw_loc_descr_ref
9399 loc_descriptor_from_tree_1 (tree loc, int want_address)
9401 dw_loc_descr_ref ret, ret1;
9402 int have_address = 0;
9403 enum dwarf_location_atom op;
9405 /* ??? Most of the time we do not take proper care for sign/zero
9406 extending the values properly. Hopefully this won't be a real
9409 switch (TREE_CODE (loc))
9414 case PLACEHOLDER_EXPR:
9415 /* This case involves extracting fields from an object to determine the
9416 position of other fields. We don't try to encode this here. The
9417 only user of this is Ada, which encodes the needed information using
9418 the names of types. */
9424 case PREINCREMENT_EXPR:
9425 case PREDECREMENT_EXPR:
9426 case POSTINCREMENT_EXPR:
9427 case POSTDECREMENT_EXPR:
9428 /* There are no opcodes for these operations. */
9432 /* If we already want an address, there's nothing we can do. */
9436 /* Otherwise, process the argument and look for the address. */
9437 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9440 if (DECL_THREAD_LOCAL_P (loc))
9444 /* If this is not defined, we have no way to emit the data. */
9445 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
9448 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9449 look up addresses of objects in the current module. */
9450 if (DECL_EXTERNAL (loc))
9453 rtl = rtl_for_decl_location (loc);
9454 if (rtl == NULL_RTX)
9459 rtl = XEXP (rtl, 0);
9460 if (! CONSTANT_P (rtl))
9463 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9464 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9465 ret->dw_loc_oprnd1.v.val_addr = rtl;
9467 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9468 add_loc_descr (&ret, ret1);
9476 if (DECL_HAS_VALUE_EXPR_P (loc))
9477 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9484 rtx rtl = rtl_for_decl_location (loc);
9486 if (rtl == NULL_RTX)
9488 else if (GET_CODE (rtl) == CONST_INT)
9490 HOST_WIDE_INT val = INTVAL (rtl);
9491 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9492 val &= GET_MODE_MASK (DECL_MODE (loc));
9493 ret = int_loc_descriptor (val);
9495 else if (GET_CODE (rtl) == CONST_STRING)
9497 else if (CONSTANT_P (rtl))
9499 ret = new_loc_descr (DW_OP_addr, 0, 0);
9500 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9501 ret->dw_loc_oprnd1.v.val_addr = rtl;
9505 enum machine_mode mode;
9507 /* Certain constructs can only be represented at top-level. */
9508 if (want_address == 2)
9509 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
9511 mode = GET_MODE (rtl);
9514 rtl = XEXP (rtl, 0);
9517 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9523 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9528 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9532 case NON_LVALUE_EXPR:
9533 case VIEW_CONVERT_EXPR:
9535 case GIMPLE_MODIFY_STMT:
9536 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0),
9542 case ARRAY_RANGE_REF:
9545 HOST_WIDE_INT bitsize, bitpos, bytepos;
9546 enum machine_mode mode;
9548 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9550 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9551 &unsignedp, &volatilep, false);
9556 ret = loc_descriptor_from_tree_1 (obj, 1);
9558 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9561 if (offset != NULL_TREE)
9563 /* Variable offset. */
9564 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9565 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9568 bytepos = bitpos / BITS_PER_UNIT;
9570 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9571 else if (bytepos < 0)
9573 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9574 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9582 if (host_integerp (loc, 0))
9583 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9590 /* Get an RTL for this, if something has been emitted. */
9591 rtx rtl = lookup_constant_def (loc);
9592 enum machine_mode mode;
9594 if (!rtl || !MEM_P (rtl))
9596 mode = GET_MODE (rtl);
9597 rtl = XEXP (rtl, 0);
9598 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9603 case TRUTH_AND_EXPR:
9604 case TRUTH_ANDIF_EXPR:
9609 case TRUTH_XOR_EXPR:
9615 case TRUTH_ORIF_EXPR:
9620 case FLOOR_DIV_EXPR:
9622 case ROUND_DIV_EXPR:
9623 case TRUNC_DIV_EXPR:
9631 case FLOOR_MOD_EXPR:
9633 case ROUND_MOD_EXPR:
9634 case TRUNC_MOD_EXPR:
9647 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9650 case POINTER_PLUS_EXPR:
9652 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9653 && host_integerp (TREE_OPERAND (loc, 1), 0))
9655 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9659 add_loc_descr (&ret,
9660 new_loc_descr (DW_OP_plus_uconst,
9661 tree_low_cst (TREE_OPERAND (loc, 1),
9671 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9678 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9685 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9692 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9707 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9708 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9709 if (ret == 0 || ret1 == 0)
9712 add_loc_descr (&ret, ret1);
9713 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9716 case TRUTH_NOT_EXPR:
9730 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9734 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9740 const enum tree_code code =
9741 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9743 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9744 build2 (code, integer_type_node,
9745 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9746 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9749 /* ... fall through ... */
9753 dw_loc_descr_ref lhs
9754 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9755 dw_loc_descr_ref rhs
9756 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9757 dw_loc_descr_ref bra_node, jump_node, tmp;
9759 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9760 if (ret == 0 || lhs == 0 || rhs == 0)
9763 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9764 add_loc_descr (&ret, bra_node);
9766 add_loc_descr (&ret, rhs);
9767 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9768 add_loc_descr (&ret, jump_node);
9770 add_loc_descr (&ret, lhs);
9771 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9772 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9774 /* ??? Need a node to point the skip at. Use a nop. */
9775 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9776 add_loc_descr (&ret, tmp);
9777 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9778 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9782 case FIX_TRUNC_EXPR:
9786 /* Leave front-end specific codes as simply unknown. This comes
9787 up, for instance, with the C STMT_EXPR. */
9788 if ((unsigned int) TREE_CODE (loc)
9789 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9792 #ifdef ENABLE_CHECKING
9793 /* Otherwise this is a generic code; we should just lists all of
9794 these explicitly. We forgot one. */
9797 /* In a release build, we want to degrade gracefully: better to
9798 generate incomplete debugging information than to crash. */
9803 /* Show if we can't fill the request for an address. */
9804 if (want_address && !have_address)
9807 /* If we've got an address and don't want one, dereference. */
9808 if (!want_address && have_address && ret)
9810 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9812 if (size > DWARF2_ADDR_SIZE || size == -1)
9814 else if (size == DWARF2_ADDR_SIZE)
9817 op = DW_OP_deref_size;
9819 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9825 static inline dw_loc_descr_ref
9826 loc_descriptor_from_tree (tree loc)
9828 return loc_descriptor_from_tree_1 (loc, 2);
9831 /* Given a value, round it up to the lowest multiple of `boundary'
9832 which is not less than the value itself. */
9834 static inline HOST_WIDE_INT
9835 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9837 return (((value + boundary - 1) / boundary) * boundary);
9840 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9841 pointer to the declared type for the relevant field variable, or return
9842 `integer_type_node' if the given node turns out to be an
9846 field_type (const_tree decl)
9850 if (TREE_CODE (decl) == ERROR_MARK)
9851 return integer_type_node;
9853 type = DECL_BIT_FIELD_TYPE (decl);
9854 if (type == NULL_TREE)
9855 type = TREE_TYPE (decl);
9860 /* Given a pointer to a tree node, return the alignment in bits for
9861 it, or else return BITS_PER_WORD if the node actually turns out to
9862 be an ERROR_MARK node. */
9864 static inline unsigned
9865 simple_type_align_in_bits (const_tree type)
9867 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9870 static inline unsigned
9871 simple_decl_align_in_bits (const_tree decl)
9873 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9876 /* Return the result of rounding T up to ALIGN. */
9878 static inline HOST_WIDE_INT
9879 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9881 /* We must be careful if T is negative because HOST_WIDE_INT can be
9882 either "above" or "below" unsigned int as per the C promotion
9883 rules, depending on the host, thus making the signedness of the
9884 direct multiplication and division unpredictable. */
9885 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9891 return (HOST_WIDE_INT) u;
9894 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9895 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9896 or return 0 if we are unable to determine what that offset is, either
9897 because the argument turns out to be a pointer to an ERROR_MARK node, or
9898 because the offset is actually variable. (We can't handle the latter case
9901 static HOST_WIDE_INT
9902 field_byte_offset (const_tree decl)
9904 HOST_WIDE_INT object_offset_in_bits;
9905 HOST_WIDE_INT bitpos_int;
9907 if (TREE_CODE (decl) == ERROR_MARK)
9910 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9912 /* We cannot yet cope with fields whose positions are variable, so
9913 for now, when we see such things, we simply return 0. Someday, we may
9914 be able to handle such cases, but it will be damn difficult. */
9915 if (! host_integerp (bit_position (decl), 0))
9918 bitpos_int = int_bit_position (decl);
9920 #ifdef PCC_BITFIELD_TYPE_MATTERS
9921 if (PCC_BITFIELD_TYPE_MATTERS)
9924 tree field_size_tree;
9925 HOST_WIDE_INT deepest_bitpos;
9926 unsigned HOST_WIDE_INT field_size_in_bits;
9927 unsigned int type_align_in_bits;
9928 unsigned int decl_align_in_bits;
9929 unsigned HOST_WIDE_INT type_size_in_bits;
9931 type = field_type (decl);
9932 field_size_tree = DECL_SIZE (decl);
9934 /* The size could be unspecified if there was an error, or for
9935 a flexible array member. */
9936 if (! field_size_tree)
9937 field_size_tree = bitsize_zero_node;
9939 /* If we don't know the size of the field, pretend it's a full word. */
9940 if (host_integerp (field_size_tree, 1))
9941 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9943 field_size_in_bits = BITS_PER_WORD;
9945 type_size_in_bits = simple_type_size_in_bits (type);
9946 type_align_in_bits = simple_type_align_in_bits (type);
9947 decl_align_in_bits = simple_decl_align_in_bits (decl);
9949 /* The GCC front-end doesn't make any attempt to keep track of the
9950 starting bit offset (relative to the start of the containing
9951 structure type) of the hypothetical "containing object" for a
9952 bit-field. Thus, when computing the byte offset value for the
9953 start of the "containing object" of a bit-field, we must deduce
9954 this information on our own. This can be rather tricky to do in
9955 some cases. For example, handling the following structure type
9956 definition when compiling for an i386/i486 target (which only
9957 aligns long long's to 32-bit boundaries) can be very tricky:
9959 struct S { int field1; long long field2:31; };
9961 Fortunately, there is a simple rule-of-thumb which can be used
9962 in such cases. When compiling for an i386/i486, GCC will
9963 allocate 8 bytes for the structure shown above. It decides to
9964 do this based upon one simple rule for bit-field allocation.
9965 GCC allocates each "containing object" for each bit-field at
9966 the first (i.e. lowest addressed) legitimate alignment boundary
9967 (based upon the required minimum alignment for the declared
9968 type of the field) which it can possibly use, subject to the
9969 condition that there is still enough available space remaining
9970 in the containing object (when allocated at the selected point)
9971 to fully accommodate all of the bits of the bit-field itself.
9973 This simple rule makes it obvious why GCC allocates 8 bytes for
9974 each object of the structure type shown above. When looking
9975 for a place to allocate the "containing object" for `field2',
9976 the compiler simply tries to allocate a 64-bit "containing
9977 object" at each successive 32-bit boundary (starting at zero)
9978 until it finds a place to allocate that 64- bit field such that
9979 at least 31 contiguous (and previously unallocated) bits remain
9980 within that selected 64 bit field. (As it turns out, for the
9981 example above, the compiler finds it is OK to allocate the
9982 "containing object" 64-bit field at bit-offset zero within the
9985 Here we attempt to work backwards from the limited set of facts
9986 we're given, and we try to deduce from those facts, where GCC
9987 must have believed that the containing object started (within
9988 the structure type). The value we deduce is then used (by the
9989 callers of this routine) to generate DW_AT_location and
9990 DW_AT_bit_offset attributes for fields (both bit-fields and, in
9991 the case of DW_AT_location, regular fields as well). */
9993 /* Figure out the bit-distance from the start of the structure to
9994 the "deepest" bit of the bit-field. */
9995 deepest_bitpos = bitpos_int + field_size_in_bits;
9997 /* This is the tricky part. Use some fancy footwork to deduce
9998 where the lowest addressed bit of the containing object must
10000 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10002 /* Round up to type_align by default. This works best for
10004 object_offset_in_bits
10005 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10007 if (object_offset_in_bits > bitpos_int)
10009 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10011 /* Round up to decl_align instead. */
10012 object_offset_in_bits
10013 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10018 object_offset_in_bits = bitpos_int;
10020 return object_offset_in_bits / BITS_PER_UNIT;
10023 /* The following routines define various Dwarf attributes and any data
10024 associated with them. */
10026 /* Add a location description attribute value to a DIE.
10028 This emits location attributes suitable for whole variables and
10029 whole parameters. Note that the location attributes for struct fields are
10030 generated by the routine `data_member_location_attribute' below. */
10033 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10034 dw_loc_descr_ref descr)
10037 add_AT_loc (die, attr_kind, descr);
10040 /* Attach the specialized form of location attribute used for data members of
10041 struct and union types. In the special case of a FIELD_DECL node which
10042 represents a bit-field, the "offset" part of this special location
10043 descriptor must indicate the distance in bytes from the lowest-addressed
10044 byte of the containing struct or union type to the lowest-addressed byte of
10045 the "containing object" for the bit-field. (See the `field_byte_offset'
10048 For any given bit-field, the "containing object" is a hypothetical object
10049 (of some integral or enum type) within which the given bit-field lives. The
10050 type of this hypothetical "containing object" is always the same as the
10051 declared type of the individual bit-field itself (for GCC anyway... the
10052 DWARF spec doesn't actually mandate this). Note that it is the size (in
10053 bytes) of the hypothetical "containing object" which will be given in the
10054 DW_AT_byte_size attribute for this bit-field. (See the
10055 `byte_size_attribute' function below.) It is also used when calculating the
10056 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10057 function below.) */
10060 add_data_member_location_attribute (dw_die_ref die, tree decl)
10062 HOST_WIDE_INT offset;
10063 dw_loc_descr_ref loc_descr = 0;
10065 if (TREE_CODE (decl) == TREE_BINFO)
10067 /* We're working on the TAG_inheritance for a base class. */
10068 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10070 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10071 aren't at a fixed offset from all (sub)objects of the same
10072 type. We need to extract the appropriate offset from our
10073 vtable. The following dwarf expression means
10075 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10077 This is specific to the V3 ABI, of course. */
10079 dw_loc_descr_ref tmp;
10081 /* Make a copy of the object address. */
10082 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10083 add_loc_descr (&loc_descr, tmp);
10085 /* Extract the vtable address. */
10086 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10087 add_loc_descr (&loc_descr, tmp);
10089 /* Calculate the address of the offset. */
10090 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10091 gcc_assert (offset < 0);
10093 tmp = int_loc_descriptor (-offset);
10094 add_loc_descr (&loc_descr, tmp);
10095 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10096 add_loc_descr (&loc_descr, tmp);
10098 /* Extract the offset. */
10099 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10100 add_loc_descr (&loc_descr, tmp);
10102 /* Add it to the object address. */
10103 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10104 add_loc_descr (&loc_descr, tmp);
10107 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10110 offset = field_byte_offset (decl);
10114 enum dwarf_location_atom op;
10116 /* The DWARF2 standard says that we should assume that the structure
10117 address is already on the stack, so we can specify a structure field
10118 address by using DW_OP_plus_uconst. */
10120 #ifdef MIPS_DEBUGGING_INFO
10121 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10122 operator correctly. It works only if we leave the offset on the
10126 op = DW_OP_plus_uconst;
10129 loc_descr = new_loc_descr (op, offset, 0);
10132 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10135 /* Writes integer values to dw_vec_const array. */
10138 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10142 *dest++ = val & 0xff;
10148 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10150 static HOST_WIDE_INT
10151 extract_int (const unsigned char *src, unsigned int size)
10153 HOST_WIDE_INT val = 0;
10159 val |= *--src & 0xff;
10165 /* Writes floating point values to dw_vec_const array. */
10168 insert_float (const_rtx rtl, unsigned char *array)
10170 REAL_VALUE_TYPE rv;
10174 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10175 real_to_target (val, &rv, GET_MODE (rtl));
10177 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10178 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10180 insert_int (val[i], 4, array);
10185 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10186 does not have a "location" either in memory or in a register. These
10187 things can arise in GNU C when a constant is passed as an actual parameter
10188 to an inlined function. They can also arise in C++ where declared
10189 constants do not necessarily get memory "homes". */
10192 add_const_value_attribute (dw_die_ref die, rtx rtl)
10194 switch (GET_CODE (rtl))
10198 HOST_WIDE_INT val = INTVAL (rtl);
10201 add_AT_int (die, DW_AT_const_value, val);
10203 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10208 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10209 floating-point constant. A CONST_DOUBLE is used whenever the
10210 constant requires more than one word in order to be adequately
10211 represented. We output CONST_DOUBLEs as blocks. */
10213 enum machine_mode mode = GET_MODE (rtl);
10215 if (SCALAR_FLOAT_MODE_P (mode))
10217 unsigned int length = GET_MODE_SIZE (mode);
10218 unsigned char *array = ggc_alloc (length);
10220 insert_float (rtl, array);
10221 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10225 /* ??? We really should be using HOST_WIDE_INT throughout. */
10226 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10228 add_AT_long_long (die, DW_AT_const_value,
10229 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10236 enum machine_mode mode = GET_MODE (rtl);
10237 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10238 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10239 unsigned char *array = ggc_alloc (length * elt_size);
10243 switch (GET_MODE_CLASS (mode))
10245 case MODE_VECTOR_INT:
10246 for (i = 0, p = array; i < length; i++, p += elt_size)
10248 rtx elt = CONST_VECTOR_ELT (rtl, i);
10249 HOST_WIDE_INT lo, hi;
10251 switch (GET_CODE (elt))
10259 lo = CONST_DOUBLE_LOW (elt);
10260 hi = CONST_DOUBLE_HIGH (elt);
10264 gcc_unreachable ();
10267 if (elt_size <= sizeof (HOST_WIDE_INT))
10268 insert_int (lo, elt_size, p);
10271 unsigned char *p0 = p;
10272 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10274 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10275 if (WORDS_BIG_ENDIAN)
10280 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10281 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10286 case MODE_VECTOR_FLOAT:
10287 for (i = 0, p = array; i < length; i++, p += elt_size)
10289 rtx elt = CONST_VECTOR_ELT (rtl, i);
10290 insert_float (elt, p);
10295 gcc_unreachable ();
10298 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10303 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10309 add_AT_addr (die, DW_AT_const_value, rtl);
10310 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10314 /* In cases where an inlined instance of an inline function is passed
10315 the address of an `auto' variable (which is local to the caller) we
10316 can get a situation where the DECL_RTL of the artificial local
10317 variable (for the inlining) which acts as a stand-in for the
10318 corresponding formal parameter (of the inline function) will look
10319 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10320 exactly a compile-time constant expression, but it isn't the address
10321 of the (artificial) local variable either. Rather, it represents the
10322 *value* which the artificial local variable always has during its
10323 lifetime. We currently have no way to represent such quasi-constant
10324 values in Dwarf, so for now we just punt and generate nothing. */
10328 /* No other kinds of rtx should be possible here. */
10329 gcc_unreachable ();
10334 /* Determine whether the evaluation of EXPR references any variables
10335 or functions which aren't otherwise used (and therefore may not be
10338 reference_to_unused (tree * tp, int * walk_subtrees,
10339 void * data ATTRIBUTE_UNUSED)
10341 if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10342 *walk_subtrees = 0;
10344 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10345 && ! TREE_ASM_WRITTEN (*tp))
10347 else if (!flag_unit_at_a_time)
10349 /* ??? The C++ FE emits debug information for using decls, so
10350 putting gcc_unreachable here falls over. See PR31899. For now
10351 be conservative. */
10352 else if (!cgraph_global_info_ready
10353 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10355 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10357 struct varpool_node *node = varpool_node (*tp);
10361 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10362 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10364 struct cgraph_node *node = cgraph_node (*tp);
10372 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10373 for use in a later add_const_value_attribute call. */
10376 rtl_for_decl_init (tree init, tree type)
10378 rtx rtl = NULL_RTX;
10380 /* If a variable is initialized with a string constant without embedded
10381 zeros, build CONST_STRING. */
10382 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10384 tree enttype = TREE_TYPE (type);
10385 tree domain = TYPE_DOMAIN (type);
10386 enum machine_mode mode = TYPE_MODE (enttype);
10388 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10390 && integer_zerop (TYPE_MIN_VALUE (domain))
10391 && compare_tree_int (TYPE_MAX_VALUE (domain),
10392 TREE_STRING_LENGTH (init) - 1) == 0
10393 && ((size_t) TREE_STRING_LENGTH (init)
10394 == strlen (TREE_STRING_POINTER (init)) + 1))
10395 rtl = gen_rtx_CONST_STRING (VOIDmode,
10396 ggc_strdup (TREE_STRING_POINTER (init)));
10398 /* Other aggregates, and complex values, could be represented using
10400 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10402 /* Vectors only work if their mode is supported by the target.
10403 FIXME: generic vectors ought to work too. */
10404 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10406 /* If the initializer is something that we know will expand into an
10407 immediate RTL constant, expand it now. We must be careful not to
10408 reference variables which won't be output. */
10409 else if (initializer_constant_valid_p (init, type)
10410 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10412 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10414 if (TREE_CODE (type) == VECTOR_TYPE)
10415 switch (TREE_CODE (init))
10420 if (TREE_CONSTANT (init))
10422 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
10423 bool constant_p = true;
10425 unsigned HOST_WIDE_INT ix;
10427 /* Even when ctor is constant, it might contain non-*_CST
10428 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10429 belong into VECTOR_CST nodes. */
10430 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
10431 if (!CONSTANT_CLASS_P (value))
10433 constant_p = false;
10439 init = build_vector_from_ctor (type, elts);
10449 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10451 /* If expand_expr returns a MEM, it wasn't immediate. */
10452 gcc_assert (!rtl || !MEM_P (rtl));
10458 /* Generate RTL for the variable DECL to represent its location. */
10461 rtl_for_decl_location (tree decl)
10465 /* Here we have to decide where we are going to say the parameter "lives"
10466 (as far as the debugger is concerned). We only have a couple of
10467 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10469 DECL_RTL normally indicates where the parameter lives during most of the
10470 activation of the function. If optimization is enabled however, this
10471 could be either NULL or else a pseudo-reg. Both of those cases indicate
10472 that the parameter doesn't really live anywhere (as far as the code
10473 generation parts of GCC are concerned) during most of the function's
10474 activation. That will happen (for example) if the parameter is never
10475 referenced within the function.
10477 We could just generate a location descriptor here for all non-NULL
10478 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10479 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10480 where DECL_RTL is NULL or is a pseudo-reg.
10482 Note however that we can only get away with using DECL_INCOMING_RTL as
10483 a backup substitute for DECL_RTL in certain limited cases. In cases
10484 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10485 we can be sure that the parameter was passed using the same type as it is
10486 declared to have within the function, and that its DECL_INCOMING_RTL
10487 points us to a place where a value of that type is passed.
10489 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10490 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10491 because in these cases DECL_INCOMING_RTL points us to a value of some
10492 type which is *different* from the type of the parameter itself. Thus,
10493 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10494 such cases, the debugger would end up (for example) trying to fetch a
10495 `float' from a place which actually contains the first part of a
10496 `double'. That would lead to really incorrect and confusing
10497 output at debug-time.
10499 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10500 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10501 are a couple of exceptions however. On little-endian machines we can
10502 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10503 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10504 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10505 when (on a little-endian machine) a non-prototyped function has a
10506 parameter declared to be of type `short' or `char'. In such cases,
10507 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10508 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10509 passed `int' value. If the debugger then uses that address to fetch
10510 a `short' or a `char' (on a little-endian machine) the result will be
10511 the correct data, so we allow for such exceptional cases below.
10513 Note that our goal here is to describe the place where the given formal
10514 parameter lives during most of the function's activation (i.e. between the
10515 end of the prologue and the start of the epilogue). We'll do that as best
10516 as we can. Note however that if the given formal parameter is modified
10517 sometime during the execution of the function, then a stack backtrace (at
10518 debug-time) will show the function as having been called with the *new*
10519 value rather than the value which was originally passed in. This happens
10520 rarely enough that it is not a major problem, but it *is* a problem, and
10521 I'd like to fix it.
10523 A future version of dwarf2out.c may generate two additional attributes for
10524 any given DW_TAG_formal_parameter DIE which will describe the "passed
10525 type" and the "passed location" for the given formal parameter in addition
10526 to the attributes we now generate to indicate the "declared type" and the
10527 "active location" for each parameter. This additional set of attributes
10528 could be used by debuggers for stack backtraces. Separately, note that
10529 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10530 This happens (for example) for inlined-instances of inline function formal
10531 parameters which are never referenced. This really shouldn't be
10532 happening. All PARM_DECL nodes should get valid non-NULL
10533 DECL_INCOMING_RTL values. FIXME. */
10535 /* Use DECL_RTL as the "location" unless we find something better. */
10536 rtl = DECL_RTL_IF_SET (decl);
10538 /* When generating abstract instances, ignore everything except
10539 constants, symbols living in memory, and symbols living in
10540 fixed registers. */
10541 if (! reload_completed)
10544 && (CONSTANT_P (rtl)
10546 && CONSTANT_P (XEXP (rtl, 0)))
10548 && TREE_CODE (decl) == VAR_DECL
10549 && TREE_STATIC (decl))))
10551 rtl = targetm.delegitimize_address (rtl);
10556 else if (TREE_CODE (decl) == PARM_DECL)
10558 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10560 tree declared_type = TREE_TYPE (decl);
10561 tree passed_type = DECL_ARG_TYPE (decl);
10562 enum machine_mode dmode = TYPE_MODE (declared_type);
10563 enum machine_mode pmode = TYPE_MODE (passed_type);
10565 /* This decl represents a formal parameter which was optimized out.
10566 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10567 all cases where (rtl == NULL_RTX) just below. */
10568 if (dmode == pmode)
10569 rtl = DECL_INCOMING_RTL (decl);
10570 else if (SCALAR_INT_MODE_P (dmode)
10571 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10572 && DECL_INCOMING_RTL (decl))
10574 rtx inc = DECL_INCOMING_RTL (decl);
10577 else if (MEM_P (inc))
10579 if (BYTES_BIG_ENDIAN)
10580 rtl = adjust_address_nv (inc, dmode,
10581 GET_MODE_SIZE (pmode)
10582 - GET_MODE_SIZE (dmode));
10589 /* If the parm was passed in registers, but lives on the stack, then
10590 make a big endian correction if the mode of the type of the
10591 parameter is not the same as the mode of the rtl. */
10592 /* ??? This is the same series of checks that are made in dbxout.c before
10593 we reach the big endian correction code there. It isn't clear if all
10594 of these checks are necessary here, but keeping them all is the safe
10596 else if (MEM_P (rtl)
10597 && XEXP (rtl, 0) != const0_rtx
10598 && ! CONSTANT_P (XEXP (rtl, 0))
10599 /* Not passed in memory. */
10600 && !MEM_P (DECL_INCOMING_RTL (decl))
10601 /* Not passed by invisible reference. */
10602 && (!REG_P (XEXP (rtl, 0))
10603 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10604 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10605 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10606 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10609 /* Big endian correction check. */
10610 && BYTES_BIG_ENDIAN
10611 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10612 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10615 int offset = (UNITS_PER_WORD
10616 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10618 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10619 plus_constant (XEXP (rtl, 0), offset));
10622 else if (TREE_CODE (decl) == VAR_DECL
10625 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10626 && BYTES_BIG_ENDIAN)
10628 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10629 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10631 /* If a variable is declared "register" yet is smaller than
10632 a register, then if we store the variable to memory, it
10633 looks like we're storing a register-sized value, when in
10634 fact we are not. We need to adjust the offset of the
10635 storage location to reflect the actual value's bytes,
10636 else gdb will not be able to display it. */
10638 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10639 plus_constant (XEXP (rtl, 0), rsize-dsize));
10642 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10643 and will have been substituted directly into all expressions that use it.
10644 C does not have such a concept, but C++ and other languages do. */
10645 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10646 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10649 rtl = targetm.delegitimize_address (rtl);
10651 /* If we don't look past the constant pool, we risk emitting a
10652 reference to a constant pool entry that isn't referenced from
10653 code, and thus is not emitted. */
10655 rtl = avoid_constant_pool_reference (rtl);
10660 /* We need to figure out what section we should use as the base for the
10661 address ranges where a given location is valid.
10662 1. If this particular DECL has a section associated with it, use that.
10663 2. If this function has a section associated with it, use that.
10664 3. Otherwise, use the text section.
10665 XXX: If you split a variable across multiple sections, we won't notice. */
10667 static const char *
10668 secname_for_decl (const_tree decl)
10670 const char *secname;
10672 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10674 tree sectree = DECL_SECTION_NAME (decl);
10675 secname = TREE_STRING_POINTER (sectree);
10677 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10679 tree sectree = DECL_SECTION_NAME (current_function_decl);
10680 secname = TREE_STRING_POINTER (sectree);
10682 else if (cfun && in_cold_section_p)
10683 secname = cfun->cold_section_label;
10685 secname = text_section_label;
10690 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10691 data attribute for a variable or a parameter. We generate the
10692 DW_AT_const_value attribute only in those cases where the given variable
10693 or parameter does not have a true "location" either in memory or in a
10694 register. This can happen (for example) when a constant is passed as an
10695 actual argument in a call to an inline function. (It's possible that
10696 these things can crop up in other ways also.) Note that one type of
10697 constant value which can be passed into an inlined function is a constant
10698 pointer. This can happen for example if an actual argument in an inlined
10699 function call evaluates to a compile-time constant address. */
10702 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10703 enum dwarf_attribute attr)
10706 dw_loc_descr_ref descr;
10707 var_loc_list *loc_list;
10708 struct var_loc_node *node;
10709 if (TREE_CODE (decl) == ERROR_MARK)
10712 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10713 || TREE_CODE (decl) == RESULT_DECL);
10715 /* See if we possibly have multiple locations for this variable. */
10716 loc_list = lookup_decl_loc (decl);
10718 /* If it truly has multiple locations, the first and last node will
10720 if (loc_list && loc_list->first != loc_list->last)
10722 const char *endname, *secname;
10723 dw_loc_list_ref list;
10725 enum var_init_status initialized;
10727 /* Now that we know what section we are using for a base,
10728 actually construct the list of locations.
10729 The first location information is what is passed to the
10730 function that creates the location list, and the remaining
10731 locations just get added on to that list.
10732 Note that we only know the start address for a location
10733 (IE location changes), so to build the range, we use
10734 the range [current location start, next location start].
10735 This means we have to special case the last node, and generate
10736 a range of [last location start, end of function label]. */
10738 node = loc_list->first;
10739 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10740 secname = secname_for_decl (decl);
10742 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
10743 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10745 initialized = VAR_INIT_STATUS_INITIALIZED;
10747 list = new_loc_list (loc_descriptor (varloc, initialized),
10748 node->label, node->next->label, secname, 1);
10751 for (; node->next; node = node->next)
10752 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10754 /* The variable has a location between NODE->LABEL and
10755 NODE->NEXT->LABEL. */
10756 enum var_init_status initialized =
10757 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10758 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10759 add_loc_descr_to_loc_list (&list,
10760 loc_descriptor (varloc, initialized),
10761 node->label, node->next->label, secname);
10764 /* If the variable has a location at the last label
10765 it keeps its location until the end of function. */
10766 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10768 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10769 enum var_init_status initialized =
10770 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10772 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10773 if (!current_function_decl)
10774 endname = text_end_label;
10777 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10778 current_function_funcdef_no);
10779 endname = ggc_strdup (label_id);
10781 add_loc_descr_to_loc_list (&list,
10782 loc_descriptor (varloc, initialized),
10783 node->label, endname, secname);
10786 /* Finally, add the location list to the DIE, and we are done. */
10787 add_AT_loc_list (die, attr, list);
10791 /* Try to get some constant RTL for this decl, and use that as the value of
10794 rtl = rtl_for_decl_location (decl);
10795 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10797 add_const_value_attribute (die, rtl);
10801 /* If we have tried to generate the location otherwise, and it
10802 didn't work out (we wouldn't be here if we did), and we have a one entry
10803 location list, try generating a location from that. */
10804 if (loc_list && loc_list->first)
10806 enum var_init_status status;
10807 node = loc_list->first;
10808 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10809 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
10812 add_AT_location_description (die, attr, descr);
10817 /* We couldn't get any rtl, so try directly generating the location
10818 description from the tree. */
10819 descr = loc_descriptor_from_tree (decl);
10822 add_AT_location_description (die, attr, descr);
10825 /* None of that worked, so it must not really have a location;
10826 try adding a constant value attribute from the DECL_INITIAL. */
10827 tree_add_const_value_attribute (die, decl);
10830 /* If we don't have a copy of this variable in memory for some reason (such
10831 as a C++ member constant that doesn't have an out-of-line definition),
10832 we should tell the debugger about the constant value. */
10835 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10837 tree init = DECL_INITIAL (decl);
10838 tree type = TREE_TYPE (decl);
10841 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10846 rtl = rtl_for_decl_init (init, type);
10848 add_const_value_attribute (var_die, rtl);
10851 /* Convert the CFI instructions for the current function into a
10852 location list. This is used for DW_AT_frame_base when we targeting
10853 a dwarf2 consumer that does not support the dwarf3
10854 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10857 static dw_loc_list_ref
10858 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10861 dw_loc_list_ref list, *list_tail;
10863 dw_cfa_location last_cfa, next_cfa;
10864 const char *start_label, *last_label, *section;
10866 fde = &fde_table[fde_table_in_use - 1];
10868 section = secname_for_decl (current_function_decl);
10872 next_cfa.reg = INVALID_REGNUM;
10873 next_cfa.offset = 0;
10874 next_cfa.indirect = 0;
10875 next_cfa.base_offset = 0;
10877 start_label = fde->dw_fde_begin;
10879 /* ??? Bald assumption that the CIE opcode list does not contain
10880 advance opcodes. */
10881 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10882 lookup_cfa_1 (cfi, &next_cfa);
10884 last_cfa = next_cfa;
10885 last_label = start_label;
10887 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10888 switch (cfi->dw_cfi_opc)
10890 case DW_CFA_set_loc:
10891 case DW_CFA_advance_loc1:
10892 case DW_CFA_advance_loc2:
10893 case DW_CFA_advance_loc4:
10894 if (!cfa_equal_p (&last_cfa, &next_cfa))
10896 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10897 start_label, last_label, section,
10900 list_tail = &(*list_tail)->dw_loc_next;
10901 last_cfa = next_cfa;
10902 start_label = last_label;
10904 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10907 case DW_CFA_advance_loc:
10908 /* The encoding is complex enough that we should never emit this. */
10909 case DW_CFA_remember_state:
10910 case DW_CFA_restore_state:
10911 /* We don't handle these two in this function. It would be possible
10912 if it were to be required. */
10913 gcc_unreachable ();
10916 lookup_cfa_1 (cfi, &next_cfa);
10920 if (!cfa_equal_p (&last_cfa, &next_cfa))
10922 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10923 start_label, last_label, section,
10925 list_tail = &(*list_tail)->dw_loc_next;
10926 start_label = last_label;
10928 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
10929 start_label, fde->dw_fde_end, section,
10935 /* Compute a displacement from the "steady-state frame pointer" to the
10936 frame base (often the same as the CFA), and store it in
10937 frame_pointer_fb_offset. OFFSET is added to the displacement
10938 before the latter is negated. */
10941 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
10945 #ifdef FRAME_POINTER_CFA_OFFSET
10946 reg = frame_pointer_rtx;
10947 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
10949 reg = arg_pointer_rtx;
10950 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
10953 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10954 if (GET_CODE (elim) == PLUS)
10956 offset += INTVAL (XEXP (elim, 1));
10957 elim = XEXP (elim, 0);
10959 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10960 : stack_pointer_rtx));
10962 frame_pointer_fb_offset = -offset;
10965 /* Generate a DW_AT_name attribute given some string value to be included as
10966 the value of the attribute. */
10969 add_name_attribute (dw_die_ref die, const char *name_string)
10971 if (name_string != NULL && *name_string != 0)
10973 if (demangle_name_func)
10974 name_string = (*demangle_name_func) (name_string);
10976 add_AT_string (die, DW_AT_name, name_string);
10980 /* Generate a DW_AT_comp_dir attribute for DIE. */
10983 add_comp_dir_attribute (dw_die_ref die)
10985 const char *wd = get_src_pwd ();
10987 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
10990 /* Given a tree node describing an array bound (either lower or upper) output
10991 a representation for that bound. */
10994 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10996 switch (TREE_CODE (bound))
11001 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11003 if (! host_integerp (bound, 0)
11004 || (bound_attr == DW_AT_lower_bound
11005 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11006 || (is_fortran () && integer_onep (bound)))))
11007 /* Use the default. */
11010 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11015 case NON_LVALUE_EXPR:
11016 case VIEW_CONVERT_EXPR:
11017 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11027 dw_die_ref decl_die = lookup_decl_die (bound);
11029 /* ??? Can this happen, or should the variable have been bound
11030 first? Probably it can, since I imagine that we try to create
11031 the types of parameters in the order in which they exist in
11032 the list, and won't have created a forward reference to a
11033 later parameter. */
11034 if (decl_die != NULL)
11035 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11041 /* Otherwise try to create a stack operation procedure to
11042 evaluate the value of the array bound. */
11044 dw_die_ref ctx, decl_die;
11045 dw_loc_descr_ref loc;
11047 loc = loc_descriptor_from_tree (bound);
11051 if (current_function_decl == 0)
11052 ctx = comp_unit_die;
11054 ctx = lookup_decl_die (current_function_decl);
11056 decl_die = new_die (DW_TAG_variable, ctx, bound);
11057 add_AT_flag (decl_die, DW_AT_artificial, 1);
11058 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11059 add_AT_loc (decl_die, DW_AT_location, loc);
11061 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11067 /* Note that the block of subscript information for an array type also
11068 includes information about the element type of type given array type. */
11071 add_subscript_info (dw_die_ref type_die, tree type)
11073 #ifndef MIPS_DEBUGGING_INFO
11074 unsigned dimension_number;
11077 dw_die_ref subrange_die;
11079 /* The GNU compilers represent multidimensional array types as sequences of
11080 one dimensional array types whose element types are themselves array
11081 types. Here we squish that down, so that each multidimensional array
11082 type gets only one array_type DIE in the Dwarf debugging info. The draft
11083 Dwarf specification say that we are allowed to do this kind of
11084 compression in C (because there is no difference between an array or
11085 arrays and a multidimensional array in C) but for other source languages
11086 (e.g. Ada) we probably shouldn't do this. */
11088 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11089 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11090 We work around this by disabling this feature. See also
11091 gen_array_type_die. */
11092 #ifndef MIPS_DEBUGGING_INFO
11093 for (dimension_number = 0;
11094 TREE_CODE (type) == ARRAY_TYPE;
11095 type = TREE_TYPE (type), dimension_number++)
11098 tree domain = TYPE_DOMAIN (type);
11100 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11101 and (in GNU C only) variable bounds. Handle all three forms
11103 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11106 /* We have an array type with specified bounds. */
11107 lower = TYPE_MIN_VALUE (domain);
11108 upper = TYPE_MAX_VALUE (domain);
11110 /* Define the index type. */
11111 if (TREE_TYPE (domain))
11113 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11114 TREE_TYPE field. We can't emit debug info for this
11115 because it is an unnamed integral type. */
11116 if (TREE_CODE (domain) == INTEGER_TYPE
11117 && TYPE_NAME (domain) == NULL_TREE
11118 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11119 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11122 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11126 /* ??? If upper is NULL, the array has unspecified length,
11127 but it does have a lower bound. This happens with Fortran
11129 Since the debugger is definitely going to need to know N
11130 to produce useful results, go ahead and output the lower
11131 bound solo, and hope the debugger can cope. */
11133 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11135 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11138 /* Otherwise we have an array type with an unspecified length. The
11139 DWARF-2 spec does not say how to handle this; let's just leave out the
11145 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11149 switch (TREE_CODE (tree_node))
11154 case ENUMERAL_TYPE:
11157 case QUAL_UNION_TYPE:
11158 size = int_size_in_bytes (tree_node);
11161 /* For a data member of a struct or union, the DW_AT_byte_size is
11162 generally given as the number of bytes normally allocated for an
11163 object of the *declared* type of the member itself. This is true
11164 even for bit-fields. */
11165 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11168 gcc_unreachable ();
11171 /* Note that `size' might be -1 when we get to this point. If it is, that
11172 indicates that the byte size of the entity in question is variable. We
11173 have no good way of expressing this fact in Dwarf at the present time,
11174 so just let the -1 pass on through. */
11175 add_AT_unsigned (die, DW_AT_byte_size, size);
11178 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11179 which specifies the distance in bits from the highest order bit of the
11180 "containing object" for the bit-field to the highest order bit of the
11183 For any given bit-field, the "containing object" is a hypothetical object
11184 (of some integral or enum type) within which the given bit-field lives. The
11185 type of this hypothetical "containing object" is always the same as the
11186 declared type of the individual bit-field itself. The determination of the
11187 exact location of the "containing object" for a bit-field is rather
11188 complicated. It's handled by the `field_byte_offset' function (above).
11190 Note that it is the size (in bytes) of the hypothetical "containing object"
11191 which will be given in the DW_AT_byte_size attribute for this bit-field.
11192 (See `byte_size_attribute' above). */
11195 add_bit_offset_attribute (dw_die_ref die, tree decl)
11197 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11198 tree type = DECL_BIT_FIELD_TYPE (decl);
11199 HOST_WIDE_INT bitpos_int;
11200 HOST_WIDE_INT highest_order_object_bit_offset;
11201 HOST_WIDE_INT highest_order_field_bit_offset;
11202 HOST_WIDE_INT unsigned bit_offset;
11204 /* Must be a field and a bit field. */
11205 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11207 /* We can't yet handle bit-fields whose offsets are variable, so if we
11208 encounter such things, just return without generating any attribute
11209 whatsoever. Likewise for variable or too large size. */
11210 if (! host_integerp (bit_position (decl), 0)
11211 || ! host_integerp (DECL_SIZE (decl), 1))
11214 bitpos_int = int_bit_position (decl);
11216 /* Note that the bit offset is always the distance (in bits) from the
11217 highest-order bit of the "containing object" to the highest-order bit of
11218 the bit-field itself. Since the "high-order end" of any object or field
11219 is different on big-endian and little-endian machines, the computation
11220 below must take account of these differences. */
11221 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11222 highest_order_field_bit_offset = bitpos_int;
11224 if (! BYTES_BIG_ENDIAN)
11226 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11227 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11231 = (! BYTES_BIG_ENDIAN
11232 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11233 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11235 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11238 /* For a FIELD_DECL node which represents a bit field, output an attribute
11239 which specifies the length in bits of the given field. */
11242 add_bit_size_attribute (dw_die_ref die, tree decl)
11244 /* Must be a field and a bit field. */
11245 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11246 && DECL_BIT_FIELD_TYPE (decl));
11248 if (host_integerp (DECL_SIZE (decl), 1))
11249 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11252 /* If the compiled language is ANSI C, then add a 'prototyped'
11253 attribute, if arg types are given for the parameters of a function. */
11256 add_prototyped_attribute (dw_die_ref die, tree func_type)
11258 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11259 && TYPE_ARG_TYPES (func_type) != NULL)
11260 add_AT_flag (die, DW_AT_prototyped, 1);
11263 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11264 by looking in either the type declaration or object declaration
11268 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11270 dw_die_ref origin_die = NULL;
11272 if (TREE_CODE (origin) != FUNCTION_DECL)
11274 /* We may have gotten separated from the block for the inlined
11275 function, if we're in an exception handler or some such; make
11276 sure that the abstract function has been written out.
11278 Doing this for nested functions is wrong, however; functions are
11279 distinct units, and our context might not even be inline. */
11283 fn = TYPE_STUB_DECL (fn);
11285 fn = decl_function_context (fn);
11287 dwarf2out_abstract_function (fn);
11290 if (DECL_P (origin))
11291 origin_die = lookup_decl_die (origin);
11292 else if (TYPE_P (origin))
11293 origin_die = lookup_type_die (origin);
11295 /* XXX: Functions that are never lowered don't always have correct block
11296 trees (in the case of java, they simply have no block tree, in some other
11297 languages). For these functions, there is nothing we can really do to
11298 output correct debug info for inlined functions in all cases. Rather
11299 than die, we'll just produce deficient debug info now, in that we will
11300 have variables without a proper abstract origin. In the future, when all
11301 functions are lowered, we should re-add a gcc_assert (origin_die)
11305 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11308 /* We do not currently support the pure_virtual attribute. */
11311 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11313 if (DECL_VINDEX (func_decl))
11315 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11317 if (host_integerp (DECL_VINDEX (func_decl), 0))
11318 add_AT_loc (die, DW_AT_vtable_elem_location,
11319 new_loc_descr (DW_OP_constu,
11320 tree_low_cst (DECL_VINDEX (func_decl), 0),
11323 /* GNU extension: Record what type this method came from originally. */
11324 if (debug_info_level > DINFO_LEVEL_TERSE)
11325 add_AT_die_ref (die, DW_AT_containing_type,
11326 lookup_type_die (DECL_CONTEXT (func_decl)));
11330 /* Add source coordinate attributes for the given decl. */
11333 add_src_coords_attributes (dw_die_ref die, tree decl)
11335 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11337 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11338 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11341 /* Add a DW_AT_name attribute and source coordinate attribute for the
11342 given decl, but only if it actually has a name. */
11345 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11349 decl_name = DECL_NAME (decl);
11350 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11352 add_name_attribute (die, dwarf2_name (decl, 0));
11353 if (! DECL_ARTIFICIAL (decl))
11354 add_src_coords_attributes (die, decl);
11356 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11357 && TREE_PUBLIC (decl)
11358 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11359 && !DECL_ABSTRACT (decl)
11360 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
11362 add_AT_string (die, DW_AT_MIPS_linkage_name,
11363 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11366 #ifdef VMS_DEBUGGING_INFO
11367 /* Get the function's name, as described by its RTL. This may be different
11368 from the DECL_NAME name used in the source file. */
11369 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11371 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11372 XEXP (DECL_RTL (decl), 0));
11373 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11378 /* Push a new declaration scope. */
11381 push_decl_scope (tree scope)
11383 VEC_safe_push (tree, gc, decl_scope_table, scope);
11386 /* Pop a declaration scope. */
11389 pop_decl_scope (void)
11391 VEC_pop (tree, decl_scope_table);
11394 /* Return the DIE for the scope that immediately contains this type.
11395 Non-named types get global scope. Named types nested in other
11396 types get their containing scope if it's open, or global scope
11397 otherwise. All other types (i.e. function-local named types) get
11398 the current active scope. */
11401 scope_die_for (tree t, dw_die_ref context_die)
11403 dw_die_ref scope_die = NULL;
11404 tree containing_scope;
11407 /* Non-types always go in the current scope. */
11408 gcc_assert (TYPE_P (t));
11410 containing_scope = TYPE_CONTEXT (t);
11412 /* Use the containing namespace if it was passed in (for a declaration). */
11413 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11415 if (context_die == lookup_decl_die (containing_scope))
11418 containing_scope = NULL_TREE;
11421 /* Ignore function type "scopes" from the C frontend. They mean that
11422 a tagged type is local to a parmlist of a function declarator, but
11423 that isn't useful to DWARF. */
11424 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11425 containing_scope = NULL_TREE;
11427 if (containing_scope == NULL_TREE)
11428 scope_die = comp_unit_die;
11429 else if (TYPE_P (containing_scope))
11431 /* For types, we can just look up the appropriate DIE. But
11432 first we check to see if we're in the middle of emitting it
11433 so we know where the new DIE should go. */
11434 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11435 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11440 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11441 || TREE_ASM_WRITTEN (containing_scope));
11443 /* If none of the current dies are suitable, we get file scope. */
11444 scope_die = comp_unit_die;
11447 scope_die = lookup_type_die (containing_scope);
11450 scope_die = context_die;
11455 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11458 local_scope_p (dw_die_ref context_die)
11460 for (; context_die; context_die = context_die->die_parent)
11461 if (context_die->die_tag == DW_TAG_inlined_subroutine
11462 || context_die->die_tag == DW_TAG_subprogram)
11468 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11469 whether or not to treat a DIE in this context as a declaration. */
11472 class_or_namespace_scope_p (dw_die_ref context_die)
11474 return (context_die
11475 && (context_die->die_tag == DW_TAG_structure_type
11476 || context_die->die_tag == DW_TAG_union_type
11477 || context_die->die_tag == DW_TAG_namespace));
11480 /* Many forms of DIEs require a "type description" attribute. This
11481 routine locates the proper "type descriptor" die for the type given
11482 by 'type', and adds a DW_AT_type attribute below the given die. */
11485 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11486 int decl_volatile, dw_die_ref context_die)
11488 enum tree_code code = TREE_CODE (type);
11489 dw_die_ref type_die = NULL;
11491 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11492 or fixed-point type, use the inner type. This is because we have no
11493 support for unnamed types in base_type_die. This can happen if this is
11494 an Ada subrange type. Correct solution is emit a subrange type die. */
11495 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
11496 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11497 type = TREE_TYPE (type), code = TREE_CODE (type);
11499 if (code == ERROR_MARK
11500 /* Handle a special case. For functions whose return type is void, we
11501 generate *no* type attribute. (Note that no object may have type
11502 `void', so this only applies to function return types). */
11503 || code == VOID_TYPE)
11506 type_die = modified_type_die (type,
11507 decl_const || TYPE_READONLY (type),
11508 decl_volatile || TYPE_VOLATILE (type),
11511 if (type_die != NULL)
11512 add_AT_die_ref (object_die, DW_AT_type, type_die);
11515 /* Given an object die, add the calling convention attribute for the
11516 function call type. */
11518 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
11520 enum dwarf_calling_convention value = DW_CC_normal;
11522 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
11524 /* DWARF doesn't provide a way to identify a program's source-level
11525 entry point. DW_AT_calling_convention attributes are only meant
11526 to describe functions' calling conventions. However, lacking a
11527 better way to signal the Fortran main program, we use this for the
11528 time being, following existing custom. */
11530 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
11531 value = DW_CC_program;
11533 /* Only add the attribute if the backend requests it, and
11534 is not DW_CC_normal. */
11535 if (value && (value != DW_CC_normal))
11536 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11539 /* Given a tree pointer to a struct, class, union, or enum type node, return
11540 a pointer to the (string) tag name for the given type, or zero if the type
11541 was declared without a tag. */
11543 static const char *
11544 type_tag (const_tree type)
11546 const char *name = 0;
11548 if (TYPE_NAME (type) != 0)
11552 /* Find the IDENTIFIER_NODE for the type name. */
11553 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11554 t = TYPE_NAME (type);
11556 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11557 a TYPE_DECL node, regardless of whether or not a `typedef' was
11559 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11560 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11562 /* We want to be extra verbose. Don't call dwarf_name if
11563 DECL_NAME isn't set. The default hook for decl_printable_name
11564 doesn't like that, and in this context it's correct to return
11565 0, instead of "<anonymous>" or the like. */
11566 if (DECL_NAME (TYPE_NAME (type)))
11567 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11570 /* Now get the name as a string, or invent one. */
11571 if (!name && t != 0)
11572 name = IDENTIFIER_POINTER (t);
11575 return (name == 0 || *name == '\0') ? 0 : name;
11578 /* Return the type associated with a data member, make a special check
11579 for bit field types. */
11582 member_declared_type (const_tree member)
11584 return (DECL_BIT_FIELD_TYPE (member)
11585 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11588 /* Get the decl's label, as described by its RTL. This may be different
11589 from the DECL_NAME name used in the source file. */
11592 static const char *
11593 decl_start_label (tree decl)
11596 const char *fnname;
11598 x = DECL_RTL (decl);
11599 gcc_assert (MEM_P (x));
11602 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11604 fnname = XSTR (x, 0);
11609 /* These routines generate the internal representation of the DIE's for
11610 the compilation unit. Debugging information is collected by walking
11611 the declaration trees passed in from dwarf2out_decl(). */
11614 gen_array_type_die (tree type, dw_die_ref context_die)
11616 dw_die_ref scope_die = scope_die_for (type, context_die);
11617 dw_die_ref array_die;
11620 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11621 the inner array type comes before the outer array type. Thus we must
11622 call gen_type_die before we call new_die. See below also. */
11623 #ifdef MIPS_DEBUGGING_INFO
11624 gen_type_die (TREE_TYPE (type), context_die);
11627 array_die = new_die (DW_TAG_array_type, scope_die, type);
11628 add_name_attribute (array_die, type_tag (type));
11629 equate_type_number_to_die (type, array_die);
11631 if (TREE_CODE (type) == VECTOR_TYPE)
11633 /* The frontend feeds us a representation for the vector as a struct
11634 containing an array. Pull out the array type. */
11635 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11636 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11639 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11641 && TREE_CODE (type) == ARRAY_TYPE
11642 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
11643 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11646 /* We default the array ordering. SDB will probably do
11647 the right things even if DW_AT_ordering is not present. It's not even
11648 an issue until we start to get into multidimensional arrays anyway. If
11649 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11650 then we'll have to put the DW_AT_ordering attribute back in. (But if
11651 and when we find out that we need to put these in, we will only do so
11652 for multidimensional arrays. */
11653 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11656 #ifdef MIPS_DEBUGGING_INFO
11657 /* The SGI compilers handle arrays of unknown bound by setting
11658 AT_declaration and not emitting any subrange DIEs. */
11659 if (! TYPE_DOMAIN (type))
11660 add_AT_flag (array_die, DW_AT_declaration, 1);
11663 add_subscript_info (array_die, type);
11665 /* Add representation of the type of the elements of this array type. */
11666 element_type = TREE_TYPE (type);
11668 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11669 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11670 We work around this by disabling this feature. See also
11671 add_subscript_info. */
11672 #ifndef MIPS_DEBUGGING_INFO
11673 while (TREE_CODE (element_type) == ARRAY_TYPE)
11674 element_type = TREE_TYPE (element_type);
11676 gen_type_die (element_type, context_die);
11679 add_type_attribute (array_die, element_type, 0, 0, context_die);
11681 if (get_AT (array_die, DW_AT_name))
11682 add_pubtype (type, array_die);
11685 static dw_loc_descr_ref
11686 descr_info_loc (tree val, tree base_decl)
11688 HOST_WIDE_INT size;
11689 dw_loc_descr_ref loc, loc2;
11690 enum dwarf_location_atom op;
11692 if (val == base_decl)
11693 return new_loc_descr (DW_OP_push_object_address, 0, 0);
11695 switch (TREE_CODE (val))
11699 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11701 if (host_integerp (val, 0))
11702 return int_loc_descriptor (tree_low_cst (val, 0));
11705 size = int_size_in_bytes (TREE_TYPE (val));
11708 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11711 if (size == DWARF2_ADDR_SIZE)
11712 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
11714 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
11716 case POINTER_PLUS_EXPR:
11718 if (host_integerp (TREE_OPERAND (val, 1), 1)
11719 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
11722 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11725 add_loc_descr (&loc,
11726 new_loc_descr (DW_OP_plus_uconst,
11727 tree_low_cst (TREE_OPERAND (val, 1),
11734 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11737 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
11740 add_loc_descr (&loc, loc2);
11741 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
11763 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
11764 tree val, tree base_decl)
11766 dw_loc_descr_ref loc;
11768 if (host_integerp (val, 0))
11770 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
11774 loc = descr_info_loc (val, base_decl);
11778 add_AT_loc (die, attr, loc);
11781 /* This routine generates DIE for array with hidden descriptor, details
11782 are filled into *info by a langhook. */
11785 gen_descr_array_type_die (tree type, struct array_descr_info *info,
11786 dw_die_ref context_die)
11788 dw_die_ref scope_die = scope_die_for (type, context_die);
11789 dw_die_ref array_die;
11792 array_die = new_die (DW_TAG_array_type, scope_die, type);
11793 add_name_attribute (array_die, type_tag (type));
11794 equate_type_number_to_die (type, array_die);
11796 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11798 && info->ndimensions >= 2)
11799 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11801 if (info->data_location)
11802 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
11804 if (info->associated)
11805 add_descr_info_field (array_die, DW_AT_associated, info->associated,
11807 if (info->allocated)
11808 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
11811 for (dim = 0; dim < info->ndimensions; dim++)
11813 dw_die_ref subrange_die
11814 = new_die (DW_TAG_subrange_type, array_die, NULL);
11816 if (info->dimen[dim].lower_bound)
11818 /* If it is the default value, omit it. */
11819 if ((is_c_family () || is_java ())
11820 && integer_zerop (info->dimen[dim].lower_bound))
11822 else if (is_fortran ()
11823 && integer_onep (info->dimen[dim].lower_bound))
11826 add_descr_info_field (subrange_die, DW_AT_lower_bound,
11827 info->dimen[dim].lower_bound,
11830 if (info->dimen[dim].upper_bound)
11831 add_descr_info_field (subrange_die, DW_AT_upper_bound,
11832 info->dimen[dim].upper_bound,
11834 if (info->dimen[dim].stride)
11835 add_descr_info_field (subrange_die, DW_AT_byte_stride,
11836 info->dimen[dim].stride,
11840 gen_type_die (info->element_type, context_die);
11841 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
11843 if (get_AT (array_die, DW_AT_name))
11844 add_pubtype (type, array_die);
11849 gen_entry_point_die (tree decl, dw_die_ref context_die)
11851 tree origin = decl_ultimate_origin (decl);
11852 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11854 if (origin != NULL)
11855 add_abstract_origin_attribute (decl_die, origin);
11858 add_name_and_src_coords_attributes (decl_die, decl);
11859 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11860 0, 0, context_die);
11863 if (DECL_ABSTRACT (decl))
11864 equate_decl_number_to_die (decl, decl_die);
11866 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11870 /* Walk through the list of incomplete types again, trying once more to
11871 emit full debugging info for them. */
11874 retry_incomplete_types (void)
11878 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11879 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11882 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11885 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11887 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11889 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11890 be incomplete and such types are not marked. */
11891 add_abstract_origin_attribute (type_die, type);
11894 /* Generate a DIE to represent an inlined instance of a structure type. */
11897 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11899 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11901 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11902 be incomplete and such types are not marked. */
11903 add_abstract_origin_attribute (type_die, type);
11906 /* Generate a DIE to represent an inlined instance of a union type. */
11909 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11911 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11913 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11914 be incomplete and such types are not marked. */
11915 add_abstract_origin_attribute (type_die, type);
11918 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11919 include all of the information about the enumeration values also. Each
11920 enumerated type name/value is listed as a child of the enumerated type
11924 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11926 dw_die_ref type_die = lookup_type_die (type);
11928 if (type_die == NULL)
11930 type_die = new_die (DW_TAG_enumeration_type,
11931 scope_die_for (type, context_die), type);
11932 equate_type_number_to_die (type, type_die);
11933 add_name_attribute (type_die, type_tag (type));
11935 else if (! TYPE_SIZE (type))
11938 remove_AT (type_die, DW_AT_declaration);
11940 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11941 given enum type is incomplete, do not generate the DW_AT_byte_size
11942 attribute or the DW_AT_element_list attribute. */
11943 if (TYPE_SIZE (type))
11947 TREE_ASM_WRITTEN (type) = 1;
11948 add_byte_size_attribute (type_die, type);
11949 if (TYPE_STUB_DECL (type) != NULL_TREE)
11950 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11952 /* If the first reference to this type was as the return type of an
11953 inline function, then it may not have a parent. Fix this now. */
11954 if (type_die->die_parent == NULL)
11955 add_child_die (scope_die_for (type, context_die), type_die);
11957 for (link = TYPE_VALUES (type);
11958 link != NULL; link = TREE_CHAIN (link))
11960 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11961 tree value = TREE_VALUE (link);
11963 add_name_attribute (enum_die,
11964 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11966 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11967 /* DWARF2 does not provide a way of indicating whether or
11968 not enumeration constants are signed or unsigned. GDB
11969 always assumes the values are signed, so we output all
11970 values as if they were signed. That means that
11971 enumeration constants with very large unsigned values
11972 will appear to have negative values in the debugger. */
11973 add_AT_int (enum_die, DW_AT_const_value,
11974 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11978 add_AT_flag (type_die, DW_AT_declaration, 1);
11980 if (get_AT (type_die, DW_AT_name))
11981 add_pubtype (type, type_die);
11986 /* Generate a DIE to represent either a real live formal parameter decl or to
11987 represent just the type of some formal parameter position in some function
11990 Note that this routine is a bit unusual because its argument may be a
11991 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11992 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11993 node. If it's the former then this function is being called to output a
11994 DIE to represent a formal parameter object (or some inlining thereof). If
11995 it's the latter, then this function is only being called to output a
11996 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11997 argument type of some subprogram type. */
12000 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12002 dw_die_ref parm_die
12003 = new_die (DW_TAG_formal_parameter, context_die, node);
12006 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12008 case tcc_declaration:
12009 origin = decl_ultimate_origin (node);
12010 if (origin != NULL)
12011 add_abstract_origin_attribute (parm_die, origin);
12014 tree type = TREE_TYPE (node);
12015 add_name_and_src_coords_attributes (parm_die, node);
12016 if (DECL_BY_REFERENCE (node))
12017 type = TREE_TYPE (type);
12018 add_type_attribute (parm_die, type,
12019 TREE_READONLY (node),
12020 TREE_THIS_VOLATILE (node),
12022 if (DECL_ARTIFICIAL (node))
12023 add_AT_flag (parm_die, DW_AT_artificial, 1);
12026 equate_decl_number_to_die (node, parm_die);
12027 if (! DECL_ABSTRACT (node))
12028 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12033 /* We were called with some kind of a ..._TYPE node. */
12034 add_type_attribute (parm_die, node, 0, 0, context_die);
12038 gcc_unreachable ();
12044 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12045 at the end of an (ANSI prototyped) formal parameters list. */
12048 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12050 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12053 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12054 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12055 parameters as specified in some function type specification (except for
12056 those which appear as part of a function *definition*). */
12059 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12062 tree formal_type = NULL;
12063 tree first_parm_type;
12066 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12068 arg = DECL_ARGUMENTS (function_or_method_type);
12069 function_or_method_type = TREE_TYPE (function_or_method_type);
12074 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
12076 /* Make our first pass over the list of formal parameter types and output a
12077 DW_TAG_formal_parameter DIE for each one. */
12078 for (link = first_parm_type; link; )
12080 dw_die_ref parm_die;
12082 formal_type = TREE_VALUE (link);
12083 if (formal_type == void_type_node)
12086 /* Output a (nameless) DIE to represent the formal parameter itself. */
12087 parm_die = gen_formal_parameter_die (formal_type, context_die);
12088 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
12089 && link == first_parm_type)
12090 || (arg && DECL_ARTIFICIAL (arg)))
12091 add_AT_flag (parm_die, DW_AT_artificial, 1);
12093 link = TREE_CHAIN (link);
12095 arg = TREE_CHAIN (arg);
12098 /* If this function type has an ellipsis, add a
12099 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12100 if (formal_type != void_type_node)
12101 gen_unspecified_parameters_die (function_or_method_type, context_die);
12103 /* Make our second (and final) pass over the list of formal parameter types
12104 and output DIEs to represent those types (as necessary). */
12105 for (link = TYPE_ARG_TYPES (function_or_method_type);
12106 link && TREE_VALUE (link);
12107 link = TREE_CHAIN (link))
12108 gen_type_die (TREE_VALUE (link), context_die);
12111 /* We want to generate the DIE for TYPE so that we can generate the
12112 die for MEMBER, which has been defined; we will need to refer back
12113 to the member declaration nested within TYPE. If we're trying to
12114 generate minimal debug info for TYPE, processing TYPE won't do the
12115 trick; we need to attach the member declaration by hand. */
12118 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
12120 gen_type_die (type, context_die);
12122 /* If we're trying to avoid duplicate debug info, we may not have
12123 emitted the member decl for this function. Emit it now. */
12124 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
12125 && ! lookup_decl_die (member))
12127 dw_die_ref type_die;
12128 gcc_assert (!decl_ultimate_origin (member));
12130 push_decl_scope (type);
12131 type_die = lookup_type_die (type);
12132 if (TREE_CODE (member) == FUNCTION_DECL)
12133 gen_subprogram_die (member, type_die);
12134 else if (TREE_CODE (member) == FIELD_DECL)
12136 /* Ignore the nameless fields that are used to skip bits but handle
12137 C++ anonymous unions and structs. */
12138 if (DECL_NAME (member) != NULL_TREE
12139 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
12140 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
12142 gen_type_die (member_declared_type (member), type_die);
12143 gen_field_die (member, type_die);
12147 gen_variable_die (member, type_die);
12153 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12154 may later generate inlined and/or out-of-line instances of. */
12157 dwarf2out_abstract_function (tree decl)
12159 dw_die_ref old_die;
12162 int was_abstract = DECL_ABSTRACT (decl);
12164 /* Make sure we have the actual abstract inline, not a clone. */
12165 decl = DECL_ORIGIN (decl);
12167 old_die = lookup_decl_die (decl);
12168 if (old_die && get_AT (old_die, DW_AT_inline))
12169 /* We've already generated the abstract instance. */
12172 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12173 we don't get confused by DECL_ABSTRACT. */
12174 if (debug_info_level > DINFO_LEVEL_TERSE)
12176 context = decl_class_context (decl);
12178 gen_type_die_for_member
12179 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
12182 /* Pretend we've just finished compiling this function. */
12183 save_fn = current_function_decl;
12184 current_function_decl = decl;
12185 push_cfun (DECL_STRUCT_FUNCTION (decl));
12187 set_decl_abstract_flags (decl, 1);
12188 dwarf2out_decl (decl);
12189 if (! was_abstract)
12190 set_decl_abstract_flags (decl, 0);
12192 current_function_decl = save_fn;
12196 /* Helper function of premark_used_types() which gets called through
12197 htab_traverse_resize().
12199 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12200 marked as unused by prune_unused_types. */
12202 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
12208 die = lookup_type_die (type);
12210 die->die_perennial_p = 1;
12214 /* Mark all members of used_types_hash as perennial. */
12216 premark_used_types (void)
12218 if (cfun && cfun->used_types_hash)
12219 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
12222 /* Generate a DIE to represent a declared function (either file-scope or
12226 gen_subprogram_die (tree decl, dw_die_ref context_die)
12228 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12229 tree origin = decl_ultimate_origin (decl);
12230 dw_die_ref subr_die;
12233 dw_die_ref old_die = lookup_decl_die (decl);
12234 int declaration = (current_function_decl != decl
12235 || class_or_namespace_scope_p (context_die));
12237 premark_used_types ();
12239 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12240 started to generate the abstract instance of an inline, decided to output
12241 its containing class, and proceeded to emit the declaration of the inline
12242 from the member list for the class. If so, DECLARATION takes priority;
12243 we'll get back to the abstract instance when done with the class. */
12245 /* The class-scope declaration DIE must be the primary DIE. */
12246 if (origin && declaration && class_or_namespace_scope_p (context_die))
12249 gcc_assert (!old_die);
12252 /* Now that the C++ front end lazily declares artificial member fns, we
12253 might need to retrofit the declaration into its class. */
12254 if (!declaration && !origin && !old_die
12255 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
12256 && !class_or_namespace_scope_p (context_die)
12257 && debug_info_level > DINFO_LEVEL_TERSE)
12258 old_die = force_decl_die (decl);
12260 if (origin != NULL)
12262 gcc_assert (!declaration || local_scope_p (context_die));
12264 /* Fixup die_parent for the abstract instance of a nested
12265 inline function. */
12266 if (old_die && old_die->die_parent == NULL)
12267 add_child_die (context_die, old_die);
12269 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12270 add_abstract_origin_attribute (subr_die, origin);
12274 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12275 struct dwarf_file_data * file_index = lookup_filename (s.file);
12277 if (!get_AT_flag (old_die, DW_AT_declaration)
12278 /* We can have a normal definition following an inline one in the
12279 case of redefinition of GNU C extern inlines.
12280 It seems reasonable to use AT_specification in this case. */
12281 && !get_AT (old_die, DW_AT_inline))
12283 /* Detect and ignore this case, where we are trying to output
12284 something we have already output. */
12288 /* If the definition comes from the same place as the declaration,
12289 maybe use the old DIE. We always want the DIE for this function
12290 that has the *_pc attributes to be under comp_unit_die so the
12291 debugger can find it. We also need to do this for abstract
12292 instances of inlines, since the spec requires the out-of-line copy
12293 to have the same parent. For local class methods, this doesn't
12294 apply; we just use the old DIE. */
12295 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12296 && (DECL_ARTIFICIAL (decl)
12297 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12298 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12299 == (unsigned) s.line))))
12301 subr_die = old_die;
12303 /* Clear out the declaration attribute and the formal parameters.
12304 Do not remove all children, because it is possible that this
12305 declaration die was forced using force_decl_die(). In such
12306 cases die that forced declaration die (e.g. TAG_imported_module)
12307 is one of the children that we do not want to remove. */
12308 remove_AT (subr_die, DW_AT_declaration);
12309 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12313 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12314 add_AT_specification (subr_die, old_die);
12315 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12316 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12317 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12318 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12323 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12325 if (TREE_PUBLIC (decl))
12326 add_AT_flag (subr_die, DW_AT_external, 1);
12328 add_name_and_src_coords_attributes (subr_die, decl);
12329 if (debug_info_level > DINFO_LEVEL_TERSE)
12331 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12332 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12333 0, 0, context_die);
12336 add_pure_or_virtual_attribute (subr_die, decl);
12337 if (DECL_ARTIFICIAL (decl))
12338 add_AT_flag (subr_die, DW_AT_artificial, 1);
12340 if (TREE_PROTECTED (decl))
12341 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12342 else if (TREE_PRIVATE (decl))
12343 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12348 if (!old_die || !get_AT (old_die, DW_AT_inline))
12350 add_AT_flag (subr_die, DW_AT_declaration, 1);
12352 /* The first time we see a member function, it is in the context of
12353 the class to which it belongs. We make sure of this by emitting
12354 the class first. The next time is the definition, which is
12355 handled above. The two may come from the same source text.
12357 Note that force_decl_die() forces function declaration die. It is
12358 later reused to represent definition. */
12359 equate_decl_number_to_die (decl, subr_die);
12362 else if (DECL_ABSTRACT (decl))
12364 if (DECL_DECLARED_INLINE_P (decl))
12366 if (cgraph_function_possibly_inlined_p (decl))
12367 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12369 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12373 if (cgraph_function_possibly_inlined_p (decl))
12374 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12376 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12379 if (DECL_DECLARED_INLINE_P (decl)
12380 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
12381 add_AT_flag (subr_die, DW_AT_artificial, 1);
12383 equate_decl_number_to_die (decl, subr_die);
12385 else if (!DECL_EXTERNAL (decl))
12387 HOST_WIDE_INT cfa_fb_offset;
12389 if (!old_die || !get_AT (old_die, DW_AT_inline))
12390 equate_decl_number_to_die (decl, subr_die);
12392 if (!flag_reorder_blocks_and_partition)
12394 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
12395 current_function_funcdef_no);
12396 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
12397 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12398 current_function_funcdef_no);
12399 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
12401 add_pubname (decl, subr_die);
12402 add_arange (decl, subr_die);
12405 { /* Do nothing for now; maybe need to duplicate die, one for
12406 hot section and ond for cold section, then use the hot/cold
12407 section begin/end labels to generate the aranges... */
12409 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12410 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12411 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12412 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12414 add_pubname (decl, subr_die);
12415 add_arange (decl, subr_die);
12416 add_arange (decl, subr_die);
12420 #ifdef MIPS_DEBUGGING_INFO
12421 /* Add a reference to the FDE for this routine. */
12422 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
12425 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
12427 /* We define the "frame base" as the function's CFA. This is more
12428 convenient for several reasons: (1) It's stable across the prologue
12429 and epilogue, which makes it better than just a frame pointer,
12430 (2) With dwarf3, there exists a one-byte encoding that allows us
12431 to reference the .debug_frame data by proxy, but failing that,
12432 (3) We can at least reuse the code inspection and interpretation
12433 code that determines the CFA position at various points in the
12435 /* ??? Use some command-line or configury switch to enable the use
12436 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12437 consumers that understand it; fall back to "pure" dwarf2 and
12438 convert the CFA data into a location list. */
12440 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
12441 if (list->dw_loc_next)
12442 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12444 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12447 /* Compute a displacement from the "steady-state frame pointer" to
12448 the CFA. The former is what all stack slots and argument slots
12449 will reference in the rtl; the later is what we've told the
12450 debugger about. We'll need to adjust all frame_base references
12451 by this displacement. */
12452 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12454 if (cfun->static_chain_decl)
12455 add_AT_location_description (subr_die, DW_AT_static_link,
12456 loc_descriptor_from_tree (cfun->static_chain_decl));
12459 /* Now output descriptions of the arguments for this function. This gets
12460 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12461 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12462 `...' at the end of the formal parameter list. In order to find out if
12463 there was a trailing ellipsis or not, we must instead look at the type
12464 associated with the FUNCTION_DECL. This will be a node of type
12465 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12466 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12467 an ellipsis at the end. */
12469 /* In the case where we are describing a mere function declaration, all we
12470 need to do here (and all we *can* do here) is to describe the *types* of
12471 its formal parameters. */
12472 if (debug_info_level <= DINFO_LEVEL_TERSE)
12474 else if (declaration)
12475 gen_formal_types_die (decl, subr_die);
12478 /* Generate DIEs to represent all known formal parameters. */
12479 tree arg_decls = DECL_ARGUMENTS (decl);
12482 /* When generating DIEs, generate the unspecified_parameters DIE
12483 instead if we come across the arg "__builtin_va_alist" */
12484 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12485 if (TREE_CODE (parm) == PARM_DECL)
12487 if (DECL_NAME (parm)
12488 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12489 "__builtin_va_alist"))
12490 gen_unspecified_parameters_die (parm, subr_die);
12492 gen_decl_die (parm, subr_die);
12495 /* Decide whether we need an unspecified_parameters DIE at the end.
12496 There are 2 more cases to do this for: 1) the ansi ... declaration -
12497 this is detectable when the end of the arg list is not a
12498 void_type_node 2) an unprototyped function declaration (not a
12499 definition). This just means that we have no info about the
12500 parameters at all. */
12501 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12502 if (fn_arg_types != NULL)
12504 /* This is the prototyped case, check for.... */
12505 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12506 gen_unspecified_parameters_die (decl, subr_die);
12508 else if (DECL_INITIAL (decl) == NULL_TREE)
12509 gen_unspecified_parameters_die (decl, subr_die);
12512 /* Output Dwarf info for all of the stuff within the body of the function
12513 (if it has one - it may be just a declaration). */
12514 outer_scope = DECL_INITIAL (decl);
12516 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12517 a function. This BLOCK actually represents the outermost binding contour
12518 for the function, i.e. the contour in which the function's formal
12519 parameters and labels get declared. Curiously, it appears that the front
12520 end doesn't actually put the PARM_DECL nodes for the current function onto
12521 the BLOCK_VARS list for this outer scope, but are strung off of the
12522 DECL_ARGUMENTS list for the function instead.
12524 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12525 the LABEL_DECL nodes for the function however, and we output DWARF info
12526 for those in decls_for_scope. Just within the `outer_scope' there will be
12527 a BLOCK node representing the function's outermost pair of curly braces,
12528 and any blocks used for the base and member initializers of a C++
12529 constructor function. */
12530 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12532 /* Emit a DW_TAG_variable DIE for a named return value. */
12533 if (DECL_NAME (DECL_RESULT (decl)))
12534 gen_decl_die (DECL_RESULT (decl), subr_die);
12536 current_function_has_inlines = 0;
12537 decls_for_scope (outer_scope, subr_die, 0);
12539 #if 0 && defined (MIPS_DEBUGGING_INFO)
12540 if (current_function_has_inlines)
12542 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12543 if (! comp_unit_has_inlines)
12545 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12546 comp_unit_has_inlines = 1;
12551 /* Add the calling convention attribute if requested. */
12552 add_calling_convention_attribute (subr_die, decl);
12556 /* Generate a DIE to represent a declared data object. */
12559 gen_variable_die (tree decl, dw_die_ref context_die)
12561 tree origin = decl_ultimate_origin (decl);
12562 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
12564 dw_die_ref old_die = lookup_decl_die (decl);
12565 int declaration = (DECL_EXTERNAL (decl)
12566 /* If DECL is COMDAT and has not actually been
12567 emitted, we cannot take its address; there
12568 might end up being no definition anywhere in
12569 the program. For example, consider the C++
12573 struct S { static const int i = 7; };
12578 int f() { return S<int>::i; }
12580 Here, S<int>::i is not DECL_EXTERNAL, but no
12581 definition is required, so the compiler will
12582 not emit a definition. */
12583 || (TREE_CODE (decl) == VAR_DECL
12584 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12585 || class_or_namespace_scope_p (context_die));
12587 if (origin != NULL)
12588 add_abstract_origin_attribute (var_die, origin);
12590 /* Loop unrolling can create multiple blocks that refer to the same
12591 static variable, so we must test for the DW_AT_declaration flag.
12593 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12594 copy decls and set the DECL_ABSTRACT flag on them instead of
12597 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12599 ??? The declare_in_namespace support causes us to get two DIEs for one
12600 variable, both of which are declarations. We want to avoid considering
12601 one to be a specification, so we must test that this DIE is not a
12603 else if (old_die && TREE_STATIC (decl) && ! declaration
12604 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12606 /* This is a definition of a C++ class level static. */
12607 add_AT_specification (var_die, old_die);
12608 if (DECL_NAME (decl))
12610 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12611 struct dwarf_file_data * file_index = lookup_filename (s.file);
12613 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12614 add_AT_file (var_die, DW_AT_decl_file, file_index);
12616 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12617 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12622 tree type = TREE_TYPE (decl);
12623 if ((TREE_CODE (decl) == PARM_DECL
12624 || TREE_CODE (decl) == RESULT_DECL)
12625 && DECL_BY_REFERENCE (decl))
12626 type = TREE_TYPE (type);
12628 add_name_and_src_coords_attributes (var_die, decl);
12629 add_type_attribute (var_die, type, TREE_READONLY (decl),
12630 TREE_THIS_VOLATILE (decl), context_die);
12632 if (TREE_PUBLIC (decl))
12633 add_AT_flag (var_die, DW_AT_external, 1);
12635 if (DECL_ARTIFICIAL (decl))
12636 add_AT_flag (var_die, DW_AT_artificial, 1);
12638 if (TREE_PROTECTED (decl))
12639 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12640 else if (TREE_PRIVATE (decl))
12641 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12645 add_AT_flag (var_die, DW_AT_declaration, 1);
12647 if (DECL_ABSTRACT (decl) || declaration)
12648 equate_decl_number_to_die (decl, var_die);
12650 if (! declaration && ! DECL_ABSTRACT (decl))
12652 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12653 add_pubname (decl, var_die);
12656 tree_add_const_value_attribute (var_die, decl);
12659 /* Generate a DIE to represent a label identifier. */
12662 gen_label_die (tree decl, dw_die_ref context_die)
12664 tree origin = decl_ultimate_origin (decl);
12665 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12667 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12669 if (origin != NULL)
12670 add_abstract_origin_attribute (lbl_die, origin);
12672 add_name_and_src_coords_attributes (lbl_die, decl);
12674 if (DECL_ABSTRACT (decl))
12675 equate_decl_number_to_die (decl, lbl_die);
12678 insn = DECL_RTL_IF_SET (decl);
12680 /* Deleted labels are programmer specified labels which have been
12681 eliminated because of various optimizations. We still emit them
12682 here so that it is possible to put breakpoints on them. */
12686 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12688 /* When optimization is enabled (via -O) some parts of the compiler
12689 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12690 represent source-level labels which were explicitly declared by
12691 the user. This really shouldn't be happening though, so catch
12692 it if it ever does happen. */
12693 gcc_assert (!INSN_DELETED_P (insn));
12695 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12696 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12701 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12702 attributes to the DIE for a block STMT, to describe where the inlined
12703 function was called from. This is similar to add_src_coords_attributes. */
12706 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12708 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12710 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12711 add_AT_unsigned (die, DW_AT_call_line, s.line);
12715 /* If STMT's abstract origin is a function declaration and STMT's
12716 first subblock's abstract origin is the function's outermost block,
12717 then we're looking at the main entry point. */
12719 is_inlined_entry_point (const_tree stmt)
12723 if (!stmt || TREE_CODE (stmt) != BLOCK)
12726 decl = block_ultimate_origin (stmt);
12728 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12731 block = BLOCK_SUBBLOCKS (stmt);
12735 if (TREE_CODE (block) != BLOCK)
12738 block = block_ultimate_origin (block);
12741 return block == DECL_INITIAL (decl);
12744 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12745 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12748 add_high_low_attributes (tree stmt, dw_die_ref die)
12750 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12752 if (BLOCK_FRAGMENT_CHAIN (stmt))
12756 if (is_inlined_entry_point (stmt))
12758 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12759 BLOCK_NUMBER (stmt));
12760 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12763 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12765 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12768 add_ranges (chain);
12769 chain = BLOCK_FRAGMENT_CHAIN (chain);
12776 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12777 BLOCK_NUMBER (stmt));
12778 add_AT_lbl_id (die, DW_AT_low_pc, label);
12779 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12780 BLOCK_NUMBER (stmt));
12781 add_AT_lbl_id (die, DW_AT_high_pc, label);
12785 /* Generate a DIE for a lexical block. */
12788 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12790 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12792 if (! BLOCK_ABSTRACT (stmt))
12793 add_high_low_attributes (stmt, stmt_die);
12795 decls_for_scope (stmt, stmt_die, depth);
12798 /* Generate a DIE for an inlined subprogram. */
12801 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12803 tree decl = block_ultimate_origin (stmt);
12805 /* Emit info for the abstract instance first, if we haven't yet. We
12806 must emit this even if the block is abstract, otherwise when we
12807 emit the block below (or elsewhere), we may end up trying to emit
12808 a die whose origin die hasn't been emitted, and crashing. */
12809 dwarf2out_abstract_function (decl);
12811 if (! BLOCK_ABSTRACT (stmt))
12813 dw_die_ref subr_die
12814 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12816 add_abstract_origin_attribute (subr_die, decl);
12817 add_high_low_attributes (stmt, subr_die);
12818 add_call_src_coords_attributes (stmt, subr_die);
12820 decls_for_scope (stmt, subr_die, depth);
12821 current_function_has_inlines = 1;
12824 /* We may get here if we're the outer block of function A that was
12825 inlined into function B that was inlined into function C. When
12826 generating debugging info for C, dwarf2out_abstract_function(B)
12827 would mark all inlined blocks as abstract, including this one.
12828 So, we wouldn't (and shouldn't) expect labels to be generated
12829 for this one. Instead, just emit debugging info for
12830 declarations within the block. This is particularly important
12831 in the case of initializers of arguments passed from B to us:
12832 if they're statement expressions containing declarations, we
12833 wouldn't generate dies for their abstract variables, and then,
12834 when generating dies for the real variables, we'd die (pun
12836 gen_lexical_block_die (stmt, context_die, depth);
12839 /* Generate a DIE for a field in a record, or structure. */
12842 gen_field_die (tree decl, dw_die_ref context_die)
12844 dw_die_ref decl_die;
12846 if (TREE_TYPE (decl) == error_mark_node)
12849 decl_die = new_die (DW_TAG_member, context_die, decl);
12850 add_name_and_src_coords_attributes (decl_die, decl);
12851 add_type_attribute (decl_die, member_declared_type (decl),
12852 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12855 if (DECL_BIT_FIELD_TYPE (decl))
12857 add_byte_size_attribute (decl_die, decl);
12858 add_bit_size_attribute (decl_die, decl);
12859 add_bit_offset_attribute (decl_die, decl);
12862 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12863 add_data_member_location_attribute (decl_die, decl);
12865 if (DECL_ARTIFICIAL (decl))
12866 add_AT_flag (decl_die, DW_AT_artificial, 1);
12868 if (TREE_PROTECTED (decl))
12869 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12870 else if (TREE_PRIVATE (decl))
12871 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12873 /* Equate decl number to die, so that we can look up this decl later on. */
12874 equate_decl_number_to_die (decl, decl_die);
12878 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12879 Use modified_type_die instead.
12880 We keep this code here just in case these types of DIEs may be needed to
12881 represent certain things in other languages (e.g. Pascal) someday. */
12884 gen_pointer_type_die (tree type, dw_die_ref context_die)
12887 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12889 equate_type_number_to_die (type, ptr_die);
12890 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12891 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12894 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12895 Use modified_type_die instead.
12896 We keep this code here just in case these types of DIEs may be needed to
12897 represent certain things in other languages (e.g. Pascal) someday. */
12900 gen_reference_type_die (tree type, dw_die_ref context_die)
12903 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12905 equate_type_number_to_die (type, ref_die);
12906 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12907 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12911 /* Generate a DIE for a pointer to a member type. */
12914 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12917 = new_die (DW_TAG_ptr_to_member_type,
12918 scope_die_for (type, context_die), type);
12920 equate_type_number_to_die (type, ptr_die);
12921 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12922 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12923 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12926 /* Generate the DIE for the compilation unit. */
12929 gen_compile_unit_die (const char *filename)
12932 char producer[250];
12933 const char *language_string = lang_hooks.name;
12936 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12940 add_name_attribute (die, filename);
12941 /* Don't add cwd for <built-in>. */
12942 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
12943 add_comp_dir_attribute (die);
12946 sprintf (producer, "%s %s", language_string, version_string);
12948 #ifdef MIPS_DEBUGGING_INFO
12949 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12950 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12951 not appear in the producer string, the debugger reaches the conclusion
12952 that the object file is stripped and has no debugging information.
12953 To get the MIPS/SGI debugger to believe that there is debugging
12954 information in the object file, we add a -g to the producer string. */
12955 if (debug_info_level > DINFO_LEVEL_TERSE)
12956 strcat (producer, " -g");
12959 add_AT_string (die, DW_AT_producer, producer);
12961 if (strcmp (language_string, "GNU C++") == 0)
12962 language = DW_LANG_C_plus_plus;
12963 else if (strcmp (language_string, "GNU Ada") == 0)
12964 language = DW_LANG_Ada95;
12965 else if (strcmp (language_string, "GNU F77") == 0)
12966 language = DW_LANG_Fortran77;
12967 else if (strcmp (language_string, "GNU F95") == 0)
12968 language = DW_LANG_Fortran95;
12969 else if (strcmp (language_string, "GNU Pascal") == 0)
12970 language = DW_LANG_Pascal83;
12971 else if (strcmp (language_string, "GNU Java") == 0)
12972 language = DW_LANG_Java;
12973 else if (strcmp (language_string, "GNU Objective-C") == 0)
12974 language = DW_LANG_ObjC;
12975 else if (strcmp (language_string, "GNU Objective-C++") == 0)
12976 language = DW_LANG_ObjC_plus_plus;
12978 language = DW_LANG_C89;
12980 add_AT_unsigned (die, DW_AT_language, language);
12984 /* Generate the DIE for a base class. */
12987 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12989 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12991 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12992 add_data_member_location_attribute (die, binfo);
12994 if (BINFO_VIRTUAL_P (binfo))
12995 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12997 if (access == access_public_node)
12998 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12999 else if (access == access_protected_node)
13000 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13003 /* Generate a DIE for a class member. */
13006 gen_member_die (tree type, dw_die_ref context_die)
13009 tree binfo = TYPE_BINFO (type);
13012 /* If this is not an incomplete type, output descriptions of each of its
13013 members. Note that as we output the DIEs necessary to represent the
13014 members of this record or union type, we will also be trying to output
13015 DIEs to represent the *types* of those members. However the `type'
13016 function (above) will specifically avoid generating type DIEs for member
13017 types *within* the list of member DIEs for this (containing) type except
13018 for those types (of members) which are explicitly marked as also being
13019 members of this (containing) type themselves. The g++ front- end can
13020 force any given type to be treated as a member of some other (containing)
13021 type by setting the TYPE_CONTEXT of the given (member) type to point to
13022 the TREE node representing the appropriate (containing) type. */
13024 /* First output info about the base classes. */
13027 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13031 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13032 gen_inheritance_die (base,
13033 (accesses ? VEC_index (tree, accesses, i)
13034 : access_public_node), context_die);
13037 /* Now output info about the data members and type members. */
13038 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
13040 /* If we thought we were generating minimal debug info for TYPE
13041 and then changed our minds, some of the member declarations
13042 may have already been defined. Don't define them again, but
13043 do put them in the right order. */
13045 child = lookup_decl_die (member);
13047 splice_child_die (context_die, child);
13049 gen_decl_die (member, context_die);
13052 /* Now output info about the function members (if any). */
13053 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
13055 /* Don't include clones in the member list. */
13056 if (DECL_ABSTRACT_ORIGIN (member))
13059 child = lookup_decl_die (member);
13061 splice_child_die (context_die, child);
13063 gen_decl_die (member, context_die);
13067 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13068 is set, we pretend that the type was never defined, so we only get the
13069 member DIEs needed by later specification DIEs. */
13072 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
13073 enum debug_info_usage usage)
13075 dw_die_ref type_die = lookup_type_die (type);
13076 dw_die_ref scope_die = 0;
13078 int complete = (TYPE_SIZE (type)
13079 && (! TYPE_STUB_DECL (type)
13080 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
13081 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
13082 complete = complete && should_emit_struct_debug (type, usage);
13084 if (type_die && ! complete)
13087 if (TYPE_CONTEXT (type) != NULL_TREE
13088 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13089 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
13092 scope_die = scope_die_for (type, context_die);
13094 if (! type_die || (nested && scope_die == comp_unit_die))
13095 /* First occurrence of type or toplevel definition of nested class. */
13097 dw_die_ref old_die = type_die;
13099 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
13100 ? DW_TAG_structure_type : DW_TAG_union_type,
13102 equate_type_number_to_die (type, type_die);
13104 add_AT_specification (type_die, old_die);
13106 add_name_attribute (type_die, type_tag (type));
13109 remove_AT (type_die, DW_AT_declaration);
13111 /* If this type has been completed, then give it a byte_size attribute and
13112 then give a list of members. */
13113 if (complete && !ns_decl)
13115 /* Prevent infinite recursion in cases where the type of some member of
13116 this type is expressed in terms of this type itself. */
13117 TREE_ASM_WRITTEN (type) = 1;
13118 add_byte_size_attribute (type_die, type);
13119 if (TYPE_STUB_DECL (type) != NULL_TREE)
13120 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13122 /* If the first reference to this type was as the return type of an
13123 inline function, then it may not have a parent. Fix this now. */
13124 if (type_die->die_parent == NULL)
13125 add_child_die (scope_die, type_die);
13127 push_decl_scope (type);
13128 gen_member_die (type, type_die);
13131 /* GNU extension: Record what type our vtable lives in. */
13132 if (TYPE_VFIELD (type))
13134 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
13136 gen_type_die (vtype, context_die);
13137 add_AT_die_ref (type_die, DW_AT_containing_type,
13138 lookup_type_die (vtype));
13143 add_AT_flag (type_die, DW_AT_declaration, 1);
13145 /* We don't need to do this for function-local types. */
13146 if (TYPE_STUB_DECL (type)
13147 && ! decl_function_context (TYPE_STUB_DECL (type)))
13148 VEC_safe_push (tree, gc, incomplete_types, type);
13151 if (get_AT (type_die, DW_AT_name))
13152 add_pubtype (type, type_die);
13155 /* Generate a DIE for a subroutine _type_. */
13158 gen_subroutine_type_die (tree type, dw_die_ref context_die)
13160 tree return_type = TREE_TYPE (type);
13161 dw_die_ref subr_die
13162 = new_die (DW_TAG_subroutine_type,
13163 scope_die_for (type, context_die), type);
13165 equate_type_number_to_die (type, subr_die);
13166 add_prototyped_attribute (subr_die, type);
13167 add_type_attribute (subr_die, return_type, 0, 0, context_die);
13168 gen_formal_types_die (type, subr_die);
13170 if (get_AT (subr_die, DW_AT_name))
13171 add_pubtype (type, subr_die);
13174 /* Generate a DIE for a type definition. */
13177 gen_typedef_die (tree decl, dw_die_ref context_die)
13179 dw_die_ref type_die;
13182 if (TREE_ASM_WRITTEN (decl))
13185 TREE_ASM_WRITTEN (decl) = 1;
13186 type_die = new_die (DW_TAG_typedef, context_die, decl);
13187 origin = decl_ultimate_origin (decl);
13188 if (origin != NULL)
13189 add_abstract_origin_attribute (type_die, origin);
13194 add_name_and_src_coords_attributes (type_die, decl);
13195 if (DECL_ORIGINAL_TYPE (decl))
13197 type = DECL_ORIGINAL_TYPE (decl);
13199 gcc_assert (type != TREE_TYPE (decl));
13200 equate_type_number_to_die (TREE_TYPE (decl), type_die);
13203 type = TREE_TYPE (decl);
13205 add_type_attribute (type_die, type, TREE_READONLY (decl),
13206 TREE_THIS_VOLATILE (decl), context_die);
13209 if (DECL_ABSTRACT (decl))
13210 equate_decl_number_to_die (decl, type_die);
13212 if (get_AT (type_die, DW_AT_name))
13213 add_pubtype (decl, type_die);
13216 /* Generate a type description DIE. */
13219 gen_type_die_with_usage (tree type, dw_die_ref context_die,
13220 enum debug_info_usage usage)
13223 struct array_descr_info info;
13225 if (type == NULL_TREE || type == error_mark_node)
13228 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13229 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
13231 if (TREE_ASM_WRITTEN (type))
13234 /* Prevent broken recursion; we can't hand off to the same type. */
13235 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
13237 TREE_ASM_WRITTEN (type) = 1;
13238 gen_decl_die (TYPE_NAME (type), context_die);
13242 /* If this is an array type with hidden descriptor, handle it first. */
13243 if (!TREE_ASM_WRITTEN (type)
13244 && lang_hooks.types.get_array_descr_info
13245 && lang_hooks.types.get_array_descr_info (type, &info))
13247 gen_descr_array_type_die (type, &info, context_die);
13248 TREE_ASM_WRITTEN (type) = 1;
13252 /* We are going to output a DIE to represent the unqualified version
13253 of this type (i.e. without any const or volatile qualifiers) so
13254 get the main variant (i.e. the unqualified version) of this type
13255 now. (Vectors are special because the debugging info is in the
13256 cloned type itself). */
13257 if (TREE_CODE (type) != VECTOR_TYPE)
13258 type = type_main_variant (type);
13260 if (TREE_ASM_WRITTEN (type))
13263 switch (TREE_CODE (type))
13269 case REFERENCE_TYPE:
13270 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13271 ensures that the gen_type_die recursion will terminate even if the
13272 type is recursive. Recursive types are possible in Ada. */
13273 /* ??? We could perhaps do this for all types before the switch
13275 TREE_ASM_WRITTEN (type) = 1;
13277 /* For these types, all that is required is that we output a DIE (or a
13278 set of DIEs) to represent the "basis" type. */
13279 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13280 DINFO_USAGE_IND_USE);
13284 /* This code is used for C++ pointer-to-data-member types.
13285 Output a description of the relevant class type. */
13286 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13287 DINFO_USAGE_IND_USE);
13289 /* Output a description of the type of the object pointed to. */
13290 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13291 DINFO_USAGE_IND_USE);
13293 /* Now output a DIE to represent this pointer-to-data-member type
13295 gen_ptr_to_mbr_type_die (type, context_die);
13298 case FUNCTION_TYPE:
13299 /* Force out return type (in case it wasn't forced out already). */
13300 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13301 DINFO_USAGE_DIR_USE);
13302 gen_subroutine_type_die (type, context_die);
13306 /* Force out return type (in case it wasn't forced out already). */
13307 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13308 DINFO_USAGE_DIR_USE);
13309 gen_subroutine_type_die (type, context_die);
13313 gen_array_type_die (type, context_die);
13317 gen_array_type_die (type, context_die);
13320 case ENUMERAL_TYPE:
13323 case QUAL_UNION_TYPE:
13324 /* If this is a nested type whose containing class hasn't been written
13325 out yet, writing it out will cover this one, too. This does not apply
13326 to instantiations of member class templates; they need to be added to
13327 the containing class as they are generated. FIXME: This hurts the
13328 idea of combining type decls from multiple TUs, since we can't predict
13329 what set of template instantiations we'll get. */
13330 if (TYPE_CONTEXT (type)
13331 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13332 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13334 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13336 if (TREE_ASM_WRITTEN (type))
13339 /* If that failed, attach ourselves to the stub. */
13340 push_decl_scope (TYPE_CONTEXT (type));
13341 context_die = lookup_type_die (TYPE_CONTEXT (type));
13346 declare_in_namespace (type, context_die);
13350 if (TREE_CODE (type) == ENUMERAL_TYPE)
13352 /* This might have been written out by the call to
13353 declare_in_namespace. */
13354 if (!TREE_ASM_WRITTEN (type))
13355 gen_enumeration_type_die (type, context_die);
13358 gen_struct_or_union_type_die (type, context_die, usage);
13363 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13364 it up if it is ever completed. gen_*_type_die will set it for us
13365 when appropriate. */
13371 case FIXED_POINT_TYPE:
13374 /* No DIEs needed for fundamental types. */
13378 /* No Dwarf representation currently defined. */
13382 gcc_unreachable ();
13385 TREE_ASM_WRITTEN (type) = 1;
13389 gen_type_die (tree type, dw_die_ref context_die)
13391 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
13394 /* Generate a DIE for a tagged type instantiation. */
13397 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
13399 if (type == NULL_TREE || type == error_mark_node)
13402 /* We are going to output a DIE to represent the unqualified version of
13403 this type (i.e. without any const or volatile qualifiers) so make sure
13404 that we have the main variant (i.e. the unqualified version) of this
13406 gcc_assert (type == type_main_variant (type));
13408 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13409 an instance of an unresolved type. */
13411 switch (TREE_CODE (type))
13416 case ENUMERAL_TYPE:
13417 gen_inlined_enumeration_type_die (type, context_die);
13421 gen_inlined_structure_type_die (type, context_die);
13425 case QUAL_UNION_TYPE:
13426 gen_inlined_union_type_die (type, context_die);
13430 gcc_unreachable ();
13434 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13435 things which are local to the given block. */
13438 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
13440 int must_output_die = 0;
13443 enum tree_code origin_code;
13445 /* Ignore blocks that are NULL. */
13446 if (stmt == NULL_TREE)
13449 /* If the block is one fragment of a non-contiguous block, do not
13450 process the variables, since they will have been done by the
13451 origin block. Do process subblocks. */
13452 if (BLOCK_FRAGMENT_ORIGIN (stmt))
13456 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
13457 gen_block_die (sub, context_die, depth + 1);
13462 /* Determine the "ultimate origin" of this block. This block may be an
13463 inlined instance of an inlined instance of inline function, so we have
13464 to trace all of the way back through the origin chain to find out what
13465 sort of node actually served as the original seed for the creation of
13466 the current block. */
13467 origin = block_ultimate_origin (stmt);
13468 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13470 /* Determine if we need to output any Dwarf DIEs at all to represent this
13472 if (origin_code == FUNCTION_DECL)
13473 /* The outer scopes for inlinings *must* always be represented. We
13474 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13475 must_output_die = 1;
13478 /* In the case where the current block represents an inlining of the
13479 "body block" of an inline function, we must *NOT* output any DIE for
13480 this block because we have already output a DIE to represent the whole
13481 inlined function scope and the "body block" of any function doesn't
13482 really represent a different scope according to ANSI C rules. So we
13483 check here to make sure that this block does not represent a "body
13484 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13485 if (! is_body_block (origin ? origin : stmt))
13487 /* Determine if this block directly contains any "significant"
13488 local declarations which we will need to output DIEs for. */
13489 if (debug_info_level > DINFO_LEVEL_TERSE)
13490 /* We are not in terse mode so *any* local declaration counts
13491 as being a "significant" one. */
13492 must_output_die = (BLOCK_VARS (stmt) != NULL
13493 && (TREE_USED (stmt)
13494 || TREE_ASM_WRITTEN (stmt)
13495 || BLOCK_ABSTRACT (stmt)));
13497 /* We are in terse mode, so only local (nested) function
13498 definitions count as "significant" local declarations. */
13499 for (decl = BLOCK_VARS (stmt);
13500 decl != NULL; decl = TREE_CHAIN (decl))
13501 if (TREE_CODE (decl) == FUNCTION_DECL
13502 && DECL_INITIAL (decl))
13504 must_output_die = 1;
13510 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13511 DIE for any block which contains no significant local declarations at
13512 all. Rather, in such cases we just call `decls_for_scope' so that any
13513 needed Dwarf info for any sub-blocks will get properly generated. Note
13514 that in terse mode, our definition of what constitutes a "significant"
13515 local declaration gets restricted to include only inlined function
13516 instances and local (nested) function definitions. */
13517 if (must_output_die)
13519 if (origin_code == FUNCTION_DECL)
13520 gen_inlined_subroutine_die (stmt, context_die, depth);
13522 gen_lexical_block_die (stmt, context_die, depth);
13525 decls_for_scope (stmt, context_die, depth);
13528 /* Generate all of the decls declared within a given scope and (recursively)
13529 all of its sub-blocks. */
13532 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13537 /* Ignore NULL blocks. */
13538 if (stmt == NULL_TREE)
13541 if (TREE_USED (stmt))
13543 /* Output the DIEs to represent all of the data objects and typedefs
13544 declared directly within this block but not within any nested
13545 sub-blocks. Also, nested function and tag DIEs have been
13546 generated with a parent of NULL; fix that up now. */
13547 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13551 if (TREE_CODE (decl) == FUNCTION_DECL)
13552 die = lookup_decl_die (decl);
13553 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13554 die = lookup_type_die (TREE_TYPE (decl));
13558 if (die != NULL && die->die_parent == NULL)
13559 add_child_die (context_die, die);
13560 /* Do not produce debug information for static variables since
13561 these might be optimized out. We are called for these later
13562 in varpool_analyze_pending_decls. */
13563 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
13566 gen_decl_die (decl, context_die);
13570 /* If we're at -g1, we're not interested in subblocks. */
13571 if (debug_info_level <= DINFO_LEVEL_TERSE)
13574 /* Output the DIEs to represent all sub-blocks (and the items declared
13575 therein) of this block. */
13576 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13578 subblocks = BLOCK_CHAIN (subblocks))
13579 gen_block_die (subblocks, context_die, depth + 1);
13582 /* Is this a typedef we can avoid emitting? */
13585 is_redundant_typedef (const_tree decl)
13587 if (TYPE_DECL_IS_STUB (decl))
13590 if (DECL_ARTIFICIAL (decl)
13591 && DECL_CONTEXT (decl)
13592 && is_tagged_type (DECL_CONTEXT (decl))
13593 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13594 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13595 /* Also ignore the artificial member typedef for the class name. */
13601 /* Returns the DIE for decl. A DIE will always be returned. */
13604 force_decl_die (tree decl)
13606 dw_die_ref decl_die;
13607 unsigned saved_external_flag;
13608 tree save_fn = NULL_TREE;
13609 decl_die = lookup_decl_die (decl);
13612 dw_die_ref context_die;
13613 tree decl_context = DECL_CONTEXT (decl);
13616 /* Find die that represents this context. */
13617 if (TYPE_P (decl_context))
13618 context_die = force_type_die (decl_context);
13620 context_die = force_decl_die (decl_context);
13623 context_die = comp_unit_die;
13625 decl_die = lookup_decl_die (decl);
13629 switch (TREE_CODE (decl))
13631 case FUNCTION_DECL:
13632 /* Clear current_function_decl, so that gen_subprogram_die thinks
13633 that this is a declaration. At this point, we just want to force
13634 declaration die. */
13635 save_fn = current_function_decl;
13636 current_function_decl = NULL_TREE;
13637 gen_subprogram_die (decl, context_die);
13638 current_function_decl = save_fn;
13642 /* Set external flag to force declaration die. Restore it after
13643 gen_decl_die() call. */
13644 saved_external_flag = DECL_EXTERNAL (decl);
13645 DECL_EXTERNAL (decl) = 1;
13646 gen_decl_die (decl, context_die);
13647 DECL_EXTERNAL (decl) = saved_external_flag;
13650 case NAMESPACE_DECL:
13651 dwarf2out_decl (decl);
13655 gcc_unreachable ();
13658 /* We should be able to find the DIE now. */
13660 decl_die = lookup_decl_die (decl);
13661 gcc_assert (decl_die);
13667 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13668 always returned. */
13671 force_type_die (tree type)
13673 dw_die_ref type_die;
13675 type_die = lookup_type_die (type);
13678 dw_die_ref context_die;
13679 if (TYPE_CONTEXT (type))
13681 if (TYPE_P (TYPE_CONTEXT (type)))
13682 context_die = force_type_die (TYPE_CONTEXT (type));
13684 context_die = force_decl_die (TYPE_CONTEXT (type));
13687 context_die = comp_unit_die;
13689 type_die = lookup_type_die (type);
13692 gen_type_die (type, context_die);
13693 type_die = lookup_type_die (type);
13694 gcc_assert (type_die);
13699 /* Force out any required namespaces to be able to output DECL,
13700 and return the new context_die for it, if it's changed. */
13703 setup_namespace_context (tree thing, dw_die_ref context_die)
13705 tree context = (DECL_P (thing)
13706 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13707 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13708 /* Force out the namespace. */
13709 context_die = force_decl_die (context);
13711 return context_die;
13714 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13715 type) within its namespace, if appropriate.
13717 For compatibility with older debuggers, namespace DIEs only contain
13718 declarations; all definitions are emitted at CU scope. */
13721 declare_in_namespace (tree thing, dw_die_ref context_die)
13723 dw_die_ref ns_context;
13725 if (debug_info_level <= DINFO_LEVEL_TERSE)
13728 /* If this decl is from an inlined function, then don't try to emit it in its
13729 namespace, as we will get confused. It would have already been emitted
13730 when the abstract instance of the inline function was emitted anyways. */
13731 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13734 ns_context = setup_namespace_context (thing, context_die);
13736 if (ns_context != context_die)
13738 if (DECL_P (thing))
13739 gen_decl_die (thing, ns_context);
13741 gen_type_die (thing, ns_context);
13745 /* Generate a DIE for a namespace or namespace alias. */
13748 gen_namespace_die (tree decl)
13750 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13752 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13753 they are an alias of. */
13754 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13756 /* Output a real namespace. */
13757 dw_die_ref namespace_die
13758 = new_die (DW_TAG_namespace, context_die, decl);
13759 add_name_and_src_coords_attributes (namespace_die, decl);
13760 equate_decl_number_to_die (decl, namespace_die);
13764 /* Output a namespace alias. */
13766 /* Force out the namespace we are an alias of, if necessary. */
13767 dw_die_ref origin_die
13768 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13770 /* Now create the namespace alias DIE. */
13771 dw_die_ref namespace_die
13772 = new_die (DW_TAG_imported_declaration, context_die, decl);
13773 add_name_and_src_coords_attributes (namespace_die, decl);
13774 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13775 equate_decl_number_to_die (decl, namespace_die);
13779 /* Generate Dwarf debug information for a decl described by DECL. */
13782 gen_decl_die (tree decl, dw_die_ref context_die)
13786 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13789 switch (TREE_CODE (decl))
13795 /* The individual enumerators of an enum type get output when we output
13796 the Dwarf representation of the relevant enum type itself. */
13799 case FUNCTION_DECL:
13800 /* Don't output any DIEs to represent mere function declarations,
13801 unless they are class members or explicit block externs. */
13802 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13803 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13808 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13809 on local redeclarations of global functions. That seems broken. */
13810 if (current_function_decl != decl)
13811 /* This is only a declaration. */;
13814 /* If we're emitting a clone, emit info for the abstract instance. */
13815 if (DECL_ORIGIN (decl) != decl)
13816 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13818 /* If we're emitting an out-of-line copy of an inline function,
13819 emit info for the abstract instance and set up to refer to it. */
13820 else if (cgraph_function_possibly_inlined_p (decl)
13821 && ! DECL_ABSTRACT (decl)
13822 && ! class_or_namespace_scope_p (context_die)
13823 /* dwarf2out_abstract_function won't emit a die if this is just
13824 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13825 that case, because that works only if we have a die. */
13826 && DECL_INITIAL (decl) != NULL_TREE)
13828 dwarf2out_abstract_function (decl);
13829 set_decl_origin_self (decl);
13832 /* Otherwise we're emitting the primary DIE for this decl. */
13833 else if (debug_info_level > DINFO_LEVEL_TERSE)
13835 /* Before we describe the FUNCTION_DECL itself, make sure that we
13836 have described its return type. */
13837 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13839 /* And its virtual context. */
13840 if (DECL_VINDEX (decl) != NULL_TREE)
13841 gen_type_die (DECL_CONTEXT (decl), context_die);
13843 /* And its containing type. */
13844 origin = decl_class_context (decl);
13845 if (origin != NULL_TREE)
13846 gen_type_die_for_member (origin, decl, context_die);
13848 /* And its containing namespace. */
13849 declare_in_namespace (decl, context_die);
13852 /* Now output a DIE to represent the function itself. */
13853 gen_subprogram_die (decl, context_die);
13857 /* If we are in terse mode, don't generate any DIEs to represent any
13858 actual typedefs. */
13859 if (debug_info_level <= DINFO_LEVEL_TERSE)
13862 /* In the special case of a TYPE_DECL node representing the declaration
13863 of some type tag, if the given TYPE_DECL is marked as having been
13864 instantiated from some other (original) TYPE_DECL node (e.g. one which
13865 was generated within the original definition of an inline function) we
13866 have to generate a special (abbreviated) DW_TAG_structure_type,
13867 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13868 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
13869 && is_tagged_type (TREE_TYPE (decl)))
13871 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13875 if (is_redundant_typedef (decl))
13876 gen_type_die (TREE_TYPE (decl), context_die);
13878 /* Output a DIE to represent the typedef itself. */
13879 gen_typedef_die (decl, context_die);
13883 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13884 gen_label_die (decl, context_die);
13889 /* If we are in terse mode, don't generate any DIEs to represent any
13890 variable declarations or definitions. */
13891 if (debug_info_level <= DINFO_LEVEL_TERSE)
13894 /* Output any DIEs that are needed to specify the type of this data
13896 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
13897 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13899 gen_type_die (TREE_TYPE (decl), context_die);
13901 /* And its containing type. */
13902 origin = decl_class_context (decl);
13903 if (origin != NULL_TREE)
13904 gen_type_die_for_member (origin, decl, context_die);
13906 /* And its containing namespace. */
13907 declare_in_namespace (decl, context_die);
13909 /* Now output the DIE to represent the data object itself. This gets
13910 complicated because of the possibility that the VAR_DECL really
13911 represents an inlined instance of a formal parameter for an inline
13913 origin = decl_ultimate_origin (decl);
13914 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13915 gen_formal_parameter_die (decl, context_die);
13917 gen_variable_die (decl, context_die);
13921 /* Ignore the nameless fields that are used to skip bits but handle C++
13922 anonymous unions and structs. */
13923 if (DECL_NAME (decl) != NULL_TREE
13924 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13925 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13927 gen_type_die (member_declared_type (decl), context_die);
13928 gen_field_die (decl, context_die);
13933 if (DECL_BY_REFERENCE (decl))
13934 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13936 gen_type_die (TREE_TYPE (decl), context_die);
13937 gen_formal_parameter_die (decl, context_die);
13940 case NAMESPACE_DECL:
13941 gen_namespace_die (decl);
13945 /* Probably some frontend-internal decl. Assume we don't care. */
13946 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13951 /* Output debug information for global decl DECL. Called from toplev.c after
13952 compilation proper has finished. */
13955 dwarf2out_global_decl (tree decl)
13957 /* Output DWARF2 information for file-scope tentative data object
13958 declarations, file-scope (extern) function declarations (which had no
13959 corresponding body) and file-scope tagged type declarations and
13960 definitions which have not yet been forced out. */
13961 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
13962 dwarf2out_decl (decl);
13965 /* Output debug information for type decl DECL. Called from toplev.c
13966 and from language front ends (to record built-in types). */
13968 dwarf2out_type_decl (tree decl, int local)
13971 dwarf2out_decl (decl);
13974 /* Output debug information for imported module or decl. */
13977 dwarf2out_imported_module_or_decl (tree decl, tree context)
13979 dw_die_ref imported_die, at_import_die;
13980 dw_die_ref scope_die;
13981 expanded_location xloc;
13983 if (debug_info_level <= DINFO_LEVEL_TERSE)
13988 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13989 We need decl DIE for reference and scope die. First, get DIE for the decl
13992 /* Get the scope die for decl context. Use comp_unit_die for global module
13993 or decl. If die is not found for non globals, force new die. */
13995 scope_die = comp_unit_die;
13996 else if (TYPE_P (context))
13998 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14000 scope_die = force_type_die (context);
14003 scope_die = force_decl_die (context);
14005 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14006 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14008 if (is_base_type (TREE_TYPE (decl)))
14009 at_import_die = base_type_die (TREE_TYPE (decl));
14011 at_import_die = force_type_die (TREE_TYPE (decl));
14015 at_import_die = lookup_decl_die (decl);
14016 if (!at_import_die)
14018 /* If we're trying to avoid duplicate debug info, we may not have
14019 emitted the member decl for this field. Emit it now. */
14020 if (TREE_CODE (decl) == FIELD_DECL)
14022 tree type = DECL_CONTEXT (decl);
14023 dw_die_ref type_context_die;
14025 if (TYPE_CONTEXT (type))
14026 if (TYPE_P (TYPE_CONTEXT (type)))
14028 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
14029 DINFO_USAGE_DIR_USE))
14031 type_context_die = force_type_die (TYPE_CONTEXT (type));
14034 type_context_die = force_decl_die (TYPE_CONTEXT (type));
14036 type_context_die = comp_unit_die;
14037 gen_type_die_for_member (type, decl, type_context_die);
14039 at_import_die = force_decl_die (decl);
14043 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14044 if (TREE_CODE (decl) == NAMESPACE_DECL)
14045 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
14047 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
14049 xloc = expand_location (input_location);
14050 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
14051 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
14052 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
14055 /* Write the debugging output for DECL. */
14058 dwarf2out_decl (tree decl)
14060 dw_die_ref context_die = comp_unit_die;
14062 switch (TREE_CODE (decl))
14067 case FUNCTION_DECL:
14068 /* What we would really like to do here is to filter out all mere
14069 file-scope declarations of file-scope functions which are never
14070 referenced later within this translation unit (and keep all of ones
14071 that *are* referenced later on) but we aren't clairvoyant, so we have
14072 no idea which functions will be referenced in the future (i.e. later
14073 on within the current translation unit). So here we just ignore all
14074 file-scope function declarations which are not also definitions. If
14075 and when the debugger needs to know something about these functions,
14076 it will have to hunt around and find the DWARF information associated
14077 with the definition of the function.
14079 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14080 nodes represent definitions and which ones represent mere
14081 declarations. We have to check DECL_INITIAL instead. That's because
14082 the C front-end supports some weird semantics for "extern inline"
14083 function definitions. These can get inlined within the current
14084 translation unit (and thus, we need to generate Dwarf info for their
14085 abstract instances so that the Dwarf info for the concrete inlined
14086 instances can have something to refer to) but the compiler never
14087 generates any out-of-lines instances of such things (despite the fact
14088 that they *are* definitions).
14090 The important point is that the C front-end marks these "extern
14091 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14092 them anyway. Note that the C++ front-end also plays some similar games
14093 for inline function definitions appearing within include files which
14094 also contain `#pragma interface' pragmas. */
14095 if (DECL_INITIAL (decl) == NULL_TREE)
14098 /* If we're a nested function, initially use a parent of NULL; if we're
14099 a plain function, this will be fixed up in decls_for_scope. If
14100 we're a method, it will be ignored, since we already have a DIE. */
14101 if (decl_function_context (decl)
14102 /* But if we're in terse mode, we don't care about scope. */
14103 && debug_info_level > DINFO_LEVEL_TERSE)
14104 context_die = NULL;
14108 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14109 declaration and if the declaration was never even referenced from
14110 within this entire compilation unit. We suppress these DIEs in
14111 order to save space in the .debug section (by eliminating entries
14112 which are probably useless). Note that we must not suppress
14113 block-local extern declarations (whether used or not) because that
14114 would screw-up the debugger's name lookup mechanism and cause it to
14115 miss things which really ought to be in scope at a given point. */
14116 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
14119 /* For local statics lookup proper context die. */
14120 if (TREE_STATIC (decl) && decl_function_context (decl))
14121 context_die = lookup_decl_die (DECL_CONTEXT (decl));
14123 /* If we are in terse mode, don't generate any DIEs to represent any
14124 variable declarations or definitions. */
14125 if (debug_info_level <= DINFO_LEVEL_TERSE)
14129 case NAMESPACE_DECL:
14130 if (debug_info_level <= DINFO_LEVEL_TERSE)
14132 if (lookup_decl_die (decl) != NULL)
14137 /* Don't emit stubs for types unless they are needed by other DIEs. */
14138 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
14141 /* Don't bother trying to generate any DIEs to represent any of the
14142 normal built-in types for the language we are compiling. */
14143 if (DECL_IS_BUILTIN (decl))
14145 /* OK, we need to generate one for `bool' so GDB knows what type
14146 comparisons have. */
14148 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
14149 && ! DECL_IGNORED_P (decl))
14150 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
14155 /* If we are in terse mode, don't generate any DIEs for types. */
14156 if (debug_info_level <= DINFO_LEVEL_TERSE)
14159 /* If we're a function-scope tag, initially use a parent of NULL;
14160 this will be fixed up in decls_for_scope. */
14161 if (decl_function_context (decl))
14162 context_die = NULL;
14170 gen_decl_die (decl, context_die);
14173 /* Output a marker (i.e. a label) for the beginning of the generated code for
14174 a lexical block. */
14177 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
14178 unsigned int blocknum)
14180 switch_to_section (current_function_section ());
14181 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
14184 /* Output a marker (i.e. a label) for the end of the generated code for a
14188 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
14190 switch_to_section (current_function_section ());
14191 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
14194 /* Returns nonzero if it is appropriate not to emit any debugging
14195 information for BLOCK, because it doesn't contain any instructions.
14197 Don't allow this for blocks with nested functions or local classes
14198 as we would end up with orphans, and in the presence of scheduling
14199 we may end up calling them anyway. */
14202 dwarf2out_ignore_block (const_tree block)
14206 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
14207 if (TREE_CODE (decl) == FUNCTION_DECL
14208 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
14214 /* Hash table routines for file_hash. */
14217 file_table_eq (const void *p1_p, const void *p2_p)
14219 const struct dwarf_file_data * p1 = p1_p;
14220 const char * p2 = p2_p;
14221 return strcmp (p1->filename, p2) == 0;
14225 file_table_hash (const void *p_p)
14227 const struct dwarf_file_data * p = p_p;
14228 return htab_hash_string (p->filename);
14231 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14232 dwarf2out.c) and return its "index". The index of each (known) filename is
14233 just a unique number which is associated with only that one filename. We
14234 need such numbers for the sake of generating labels (in the .debug_sfnames
14235 section) and references to those files numbers (in the .debug_srcinfo
14236 and.debug_macinfo sections). If the filename given as an argument is not
14237 found in our current list, add it to the list and assign it the next
14238 available unique index number. In order to speed up searches, we remember
14239 the index of the filename was looked up last. This handles the majority of
14242 static struct dwarf_file_data *
14243 lookup_filename (const char *file_name)
14246 struct dwarf_file_data * created;
14248 /* Check to see if the file name that was searched on the previous
14249 call matches this file name. If so, return the index. */
14250 if (file_table_last_lookup
14251 && (file_name == file_table_last_lookup->filename
14252 || strcmp (file_table_last_lookup->filename, file_name) == 0))
14253 return file_table_last_lookup;
14255 /* Didn't match the previous lookup, search the table. */
14256 slot = htab_find_slot_with_hash (file_table, file_name,
14257 htab_hash_string (file_name), INSERT);
14261 created = ggc_alloc (sizeof (struct dwarf_file_data));
14262 created->filename = file_name;
14263 created->emitted_number = 0;
14268 /* If the assembler will construct the file table, then translate the compiler
14269 internal file table number into the assembler file table number, and emit
14270 a .file directive if we haven't already emitted one yet. The file table
14271 numbers are different because we prune debug info for unused variables and
14272 types, which may include filenames. */
14275 maybe_emit_file (struct dwarf_file_data * fd)
14277 if (! fd->emitted_number)
14279 if (last_emitted_file)
14280 fd->emitted_number = last_emitted_file->emitted_number + 1;
14282 fd->emitted_number = 1;
14283 last_emitted_file = fd;
14285 if (DWARF2_ASM_LINE_DEBUG_INFO)
14287 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14288 output_quoted_string (asm_out_file,
14289 remap_debug_filename (fd->filename));
14290 fputc ('\n', asm_out_file);
14294 return fd->emitted_number;
14297 /* Called by the final INSN scan whenever we see a var location. We
14298 use it to drop labels in the right places, and throw the location in
14299 our lookup table. */
14302 dwarf2out_var_location (rtx loc_note)
14304 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14305 struct var_loc_node *newloc;
14307 static rtx last_insn;
14308 static const char *last_label;
14311 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14313 prev_insn = PREV_INSN (loc_note);
14315 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
14316 /* If the insn we processed last time is the previous insn
14317 and it is also a var location note, use the label we emitted
14319 if (last_insn != NULL_RTX
14320 && last_insn == prev_insn
14321 && NOTE_P (prev_insn)
14322 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14324 newloc->label = last_label;
14328 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14329 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14331 newloc->label = ggc_strdup (loclabel);
14333 newloc->var_loc_note = loc_note;
14334 newloc->next = NULL;
14336 if (cfun && in_cold_section_p)
14337 newloc->section_label = cfun->cold_section_label;
14339 newloc->section_label = text_section_label;
14341 last_insn = loc_note;
14342 last_label = newloc->label;
14343 decl = NOTE_VAR_LOCATION_DECL (loc_note);
14344 add_var_loc_to_decl (decl, newloc);
14347 /* We need to reset the locations at the beginning of each
14348 function. We can't do this in the end_function hook, because the
14349 declarations that use the locations won't have been output when
14350 that hook is called. Also compute have_multiple_function_sections here. */
14353 dwarf2out_begin_function (tree fun)
14355 htab_empty (decl_loc_table);
14357 if (function_section (fun) != text_section)
14358 have_multiple_function_sections = true;
14360 dwarf2out_note_section_used ();
14363 /* Output a label to mark the beginning of a source code line entry
14364 and record information relating to this source line, in
14365 'line_info_table' for later output of the .debug_line section. */
14368 dwarf2out_source_line (unsigned int line, const char *filename)
14370 if (debug_info_level >= DINFO_LEVEL_NORMAL
14373 int file_num = maybe_emit_file (lookup_filename (filename));
14375 switch_to_section (current_function_section ());
14377 /* If requested, emit something human-readable. */
14378 if (flag_debug_asm)
14379 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
14382 if (DWARF2_ASM_LINE_DEBUG_INFO)
14384 /* Emit the .loc directive understood by GNU as. */
14385 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
14387 /* Indicate that line number info exists. */
14388 line_info_table_in_use++;
14390 else if (function_section (current_function_decl) != text_section)
14392 dw_separate_line_info_ref line_info;
14393 targetm.asm_out.internal_label (asm_out_file,
14394 SEPARATE_LINE_CODE_LABEL,
14395 separate_line_info_table_in_use);
14397 /* Expand the line info table if necessary. */
14398 if (separate_line_info_table_in_use
14399 == separate_line_info_table_allocated)
14401 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14402 separate_line_info_table
14403 = ggc_realloc (separate_line_info_table,
14404 separate_line_info_table_allocated
14405 * sizeof (dw_separate_line_info_entry));
14406 memset (separate_line_info_table
14407 + separate_line_info_table_in_use,
14409 (LINE_INFO_TABLE_INCREMENT
14410 * sizeof (dw_separate_line_info_entry)));
14413 /* Add the new entry at the end of the line_info_table. */
14415 = &separate_line_info_table[separate_line_info_table_in_use++];
14416 line_info->dw_file_num = file_num;
14417 line_info->dw_line_num = line;
14418 line_info->function = current_function_funcdef_no;
14422 dw_line_info_ref line_info;
14424 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
14425 line_info_table_in_use);
14427 /* Expand the line info table if necessary. */
14428 if (line_info_table_in_use == line_info_table_allocated)
14430 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14432 = ggc_realloc (line_info_table,
14433 (line_info_table_allocated
14434 * sizeof (dw_line_info_entry)));
14435 memset (line_info_table + line_info_table_in_use, 0,
14436 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
14439 /* Add the new entry at the end of the line_info_table. */
14440 line_info = &line_info_table[line_info_table_in_use++];
14441 line_info->dw_file_num = file_num;
14442 line_info->dw_line_num = line;
14447 /* Record the beginning of a new source file. */
14450 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
14452 if (flag_eliminate_dwarf2_dups)
14454 /* Record the beginning of the file for break_out_includes. */
14455 dw_die_ref bincl_die;
14457 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
14458 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
14461 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14463 int file_num = maybe_emit_file (lookup_filename (filename));
14465 switch_to_section (debug_macinfo_section);
14466 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
14467 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14470 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14474 /* Record the end of a source file. */
14477 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14479 if (flag_eliminate_dwarf2_dups)
14480 /* Record the end of the file for break_out_includes. */
14481 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14483 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14485 switch_to_section (debug_macinfo_section);
14486 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14490 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14491 the tail part of the directive line, i.e. the part which is past the
14492 initial whitespace, #, whitespace, directive-name, whitespace part. */
14495 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14496 const char *buffer ATTRIBUTE_UNUSED)
14498 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14500 switch_to_section (debug_macinfo_section);
14501 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14502 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14503 dw2_asm_output_nstring (buffer, -1, "The macro");
14507 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14508 the tail part of the directive line, i.e. the part which is past the
14509 initial whitespace, #, whitespace, directive-name, whitespace part. */
14512 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14513 const char *buffer ATTRIBUTE_UNUSED)
14515 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14517 switch_to_section (debug_macinfo_section);
14518 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14519 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14520 dw2_asm_output_nstring (buffer, -1, "The macro");
14524 /* Set up for Dwarf output at the start of compilation. */
14527 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14529 /* Allocate the file_table. */
14530 file_table = htab_create_ggc (50, file_table_hash,
14531 file_table_eq, NULL);
14533 /* Allocate the decl_die_table. */
14534 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14535 decl_die_table_eq, NULL);
14537 /* Allocate the decl_loc_table. */
14538 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14539 decl_loc_table_eq, NULL);
14541 /* Allocate the initial hunk of the decl_scope_table. */
14542 decl_scope_table = VEC_alloc (tree, gc, 256);
14544 /* Allocate the initial hunk of the abbrev_die_table. */
14545 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
14546 * sizeof (dw_die_ref));
14547 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14548 /* Zero-th entry is allocated, but unused. */
14549 abbrev_die_table_in_use = 1;
14551 /* Allocate the initial hunk of the line_info_table. */
14552 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
14553 * sizeof (dw_line_info_entry));
14554 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14556 /* Zero-th entry is allocated, but unused. */
14557 line_info_table_in_use = 1;
14559 /* Allocate the pubtypes and pubnames vectors. */
14560 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14561 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14563 /* Generate the initial DIE for the .debug section. Note that the (string)
14564 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14565 will (typically) be a relative pathname and that this pathname should be
14566 taken as being relative to the directory from which the compiler was
14567 invoked when the given (base) source file was compiled. We will fill
14568 in this value in dwarf2out_finish. */
14569 comp_unit_die = gen_compile_unit_die (NULL);
14571 incomplete_types = VEC_alloc (tree, gc, 64);
14573 used_rtx_array = VEC_alloc (rtx, gc, 32);
14575 debug_info_section = get_section (DEBUG_INFO_SECTION,
14576 SECTION_DEBUG, NULL);
14577 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14578 SECTION_DEBUG, NULL);
14579 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14580 SECTION_DEBUG, NULL);
14581 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14582 SECTION_DEBUG, NULL);
14583 debug_line_section = get_section (DEBUG_LINE_SECTION,
14584 SECTION_DEBUG, NULL);
14585 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14586 SECTION_DEBUG, NULL);
14587 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14588 SECTION_DEBUG, NULL);
14589 #ifdef DEBUG_PUBTYPES_SECTION
14590 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14591 SECTION_DEBUG, NULL);
14593 debug_str_section = get_section (DEBUG_STR_SECTION,
14594 DEBUG_STR_SECTION_FLAGS, NULL);
14595 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14596 SECTION_DEBUG, NULL);
14597 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14598 SECTION_DEBUG, NULL);
14600 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14601 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14602 DEBUG_ABBREV_SECTION_LABEL, 0);
14603 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14604 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14605 COLD_TEXT_SECTION_LABEL, 0);
14606 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14608 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14609 DEBUG_INFO_SECTION_LABEL, 0);
14610 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14611 DEBUG_LINE_SECTION_LABEL, 0);
14612 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14613 DEBUG_RANGES_SECTION_LABEL, 0);
14614 switch_to_section (debug_abbrev_section);
14615 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14616 switch_to_section (debug_info_section);
14617 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14618 switch_to_section (debug_line_section);
14619 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14621 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14623 switch_to_section (debug_macinfo_section);
14624 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14625 DEBUG_MACINFO_SECTION_LABEL, 0);
14626 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14629 switch_to_section (text_section);
14630 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14631 if (flag_reorder_blocks_and_partition)
14633 cold_text_section = unlikely_text_section ();
14634 switch_to_section (cold_text_section);
14635 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14639 /* A helper function for dwarf2out_finish called through
14640 ht_forall. Emit one queued .debug_str string. */
14643 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14645 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14647 if (node->form == DW_FORM_strp)
14649 switch_to_section (debug_str_section);
14650 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14651 assemble_string (node->str, strlen (node->str) + 1);
14657 #if ENABLE_ASSERT_CHECKING
14658 /* Verify that all marks are clear. */
14661 verify_marks_clear (dw_die_ref die)
14665 gcc_assert (! die->die_mark);
14666 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14668 #endif /* ENABLE_ASSERT_CHECKING */
14670 /* Clear the marks for a die and its children.
14671 Be cool if the mark isn't set. */
14674 prune_unmark_dies (dw_die_ref die)
14680 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14683 /* Given DIE that we're marking as used, find any other dies
14684 it references as attributes and mark them as used. */
14687 prune_unused_types_walk_attribs (dw_die_ref die)
14692 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14694 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14696 /* A reference to another DIE.
14697 Make sure that it will get emitted. */
14698 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14700 /* Set the string's refcount to 0 so that prune_unused_types_mark
14701 accounts properly for it. */
14702 if (AT_class (a) == dw_val_class_str)
14703 a->dw_attr_val.v.val_str->refcount = 0;
14708 /* Mark DIE as being used. If DOKIDS is true, then walk down
14709 to DIE's children. */
14712 prune_unused_types_mark (dw_die_ref die, int dokids)
14716 if (die->die_mark == 0)
14718 /* We haven't done this node yet. Mark it as used. */
14721 /* We also have to mark its parents as used.
14722 (But we don't want to mark our parents' kids due to this.) */
14723 if (die->die_parent)
14724 prune_unused_types_mark (die->die_parent, 0);
14726 /* Mark any referenced nodes. */
14727 prune_unused_types_walk_attribs (die);
14729 /* If this node is a specification,
14730 also mark the definition, if it exists. */
14731 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14732 prune_unused_types_mark (die->die_definition, 1);
14735 if (dokids && die->die_mark != 2)
14737 /* We need to walk the children, but haven't done so yet.
14738 Remember that we've walked the kids. */
14741 /* If this is an array type, we need to make sure our
14742 kids get marked, even if they're types. */
14743 if (die->die_tag == DW_TAG_array_type)
14744 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14746 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14751 /* Walk the tree DIE and mark types that we actually use. */
14754 prune_unused_types_walk (dw_die_ref die)
14758 /* Don't do anything if this node is already marked. */
14762 switch (die->die_tag)
14764 case DW_TAG_const_type:
14765 case DW_TAG_packed_type:
14766 case DW_TAG_pointer_type:
14767 case DW_TAG_reference_type:
14768 case DW_TAG_volatile_type:
14769 case DW_TAG_typedef:
14770 case DW_TAG_array_type:
14771 case DW_TAG_structure_type:
14772 case DW_TAG_union_type:
14773 case DW_TAG_class_type:
14774 case DW_TAG_friend:
14775 case DW_TAG_variant_part:
14776 case DW_TAG_enumeration_type:
14777 case DW_TAG_subroutine_type:
14778 case DW_TAG_string_type:
14779 case DW_TAG_set_type:
14780 case DW_TAG_subrange_type:
14781 case DW_TAG_ptr_to_member_type:
14782 case DW_TAG_file_type:
14783 if (die->die_perennial_p)
14786 /* It's a type node --- don't mark it. */
14790 /* Mark everything else. */
14796 /* Now, mark any dies referenced from here. */
14797 prune_unused_types_walk_attribs (die);
14799 /* Mark children. */
14800 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14803 /* Increment the string counts on strings referred to from DIE's
14807 prune_unused_types_update_strings (dw_die_ref die)
14812 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14813 if (AT_class (a) == dw_val_class_str)
14815 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
14817 /* Avoid unnecessarily putting strings that are used less than
14818 twice in the hash table. */
14820 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
14823 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
14824 htab_hash_string (s->str),
14826 gcc_assert (*slot == NULL);
14832 /* Remove from the tree DIE any dies that aren't marked. */
14835 prune_unused_types_prune (dw_die_ref die)
14839 gcc_assert (die->die_mark);
14840 prune_unused_types_update_strings (die);
14842 if (! die->die_child)
14845 c = die->die_child;
14847 dw_die_ref prev = c;
14848 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
14849 if (c == die->die_child)
14851 /* No marked children between 'prev' and the end of the list. */
14853 /* No marked children at all. */
14854 die->die_child = NULL;
14857 prev->die_sib = c->die_sib;
14858 die->die_child = prev;
14863 if (c != prev->die_sib)
14865 prune_unused_types_prune (c);
14866 } while (c != die->die_child);
14870 /* Remove dies representing declarations that we never use. */
14873 prune_unused_types (void)
14876 limbo_die_node *node;
14879 #if ENABLE_ASSERT_CHECKING
14880 /* All the marks should already be clear. */
14881 verify_marks_clear (comp_unit_die);
14882 for (node = limbo_die_list; node; node = node->next)
14883 verify_marks_clear (node->die);
14884 #endif /* ENABLE_ASSERT_CHECKING */
14886 /* Set the mark on nodes that are actually used. */
14887 prune_unused_types_walk (comp_unit_die);
14888 for (node = limbo_die_list; node; node = node->next)
14889 prune_unused_types_walk (node->die);
14891 /* Also set the mark on nodes referenced from the
14892 pubname_table or arange_table. */
14893 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
14894 prune_unused_types_mark (pub->die, 1);
14895 for (i = 0; i < arange_table_in_use; i++)
14896 prune_unused_types_mark (arange_table[i], 1);
14898 /* Get rid of nodes that aren't marked; and update the string counts. */
14899 if (debug_str_hash)
14900 htab_empty (debug_str_hash);
14901 prune_unused_types_prune (comp_unit_die);
14902 for (node = limbo_die_list; node; node = node->next)
14903 prune_unused_types_prune (node->die);
14905 /* Leave the marks clear. */
14906 prune_unmark_dies (comp_unit_die);
14907 for (node = limbo_die_list; node; node = node->next)
14908 prune_unmark_dies (node->die);
14911 /* Set the parameter to true if there are any relative pathnames in
14914 file_table_relative_p (void ** slot, void *param)
14917 struct dwarf_file_data *d = *slot;
14918 if (!IS_ABSOLUTE_PATH (d->filename))
14926 /* Output stuff that dwarf requires at the end of every file,
14927 and generate the DWARF-2 debugging info. */
14930 dwarf2out_finish (const char *filename)
14932 limbo_die_node *node, *next_node;
14933 dw_die_ref die = 0;
14935 /* Add the name for the main input file now. We delayed this from
14936 dwarf2out_init to avoid complications with PCH. */
14937 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
14938 if (!IS_ABSOLUTE_PATH (filename))
14939 add_comp_dir_attribute (comp_unit_die);
14940 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14943 htab_traverse (file_table, file_table_relative_p, &p);
14945 add_comp_dir_attribute (comp_unit_die);
14948 /* Traverse the limbo die list, and add parent/child links. The only
14949 dies without parents that should be here are concrete instances of
14950 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14951 For concrete instances, we can get the parent die from the abstract
14953 for (node = limbo_die_list; node; node = next_node)
14955 next_node = node->next;
14958 if (die->die_parent == NULL)
14960 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
14963 add_child_die (origin->die_parent, die);
14964 else if (die == comp_unit_die)
14966 else if (errorcount > 0 || sorrycount > 0)
14967 /* It's OK to be confused by errors in the input. */
14968 add_child_die (comp_unit_die, die);
14971 /* In certain situations, the lexical block containing a
14972 nested function can be optimized away, which results
14973 in the nested function die being orphaned. Likewise
14974 with the return type of that nested function. Force
14975 this to be a child of the containing function.
14977 It may happen that even the containing function got fully
14978 inlined and optimized out. In that case we are lost and
14979 assign the empty child. This should not be big issue as
14980 the function is likely unreachable too. */
14981 tree context = NULL_TREE;
14983 gcc_assert (node->created_for);
14985 if (DECL_P (node->created_for))
14986 context = DECL_CONTEXT (node->created_for);
14987 else if (TYPE_P (node->created_for))
14988 context = TYPE_CONTEXT (node->created_for);
14990 gcc_assert (context
14991 && (TREE_CODE (context) == FUNCTION_DECL
14992 || TREE_CODE (context) == NAMESPACE_DECL));
14994 origin = lookup_decl_die (context);
14996 add_child_die (origin, die);
14998 add_child_die (comp_unit_die, die);
15003 limbo_die_list = NULL;
15005 /* Walk through the list of incomplete types again, trying once more to
15006 emit full debugging info for them. */
15007 retry_incomplete_types ();
15009 if (flag_eliminate_unused_debug_types)
15010 prune_unused_types ();
15012 /* Generate separate CUs for each of the include files we've seen.
15013 They will go into limbo_die_list. */
15014 if (flag_eliminate_dwarf2_dups)
15015 break_out_includes (comp_unit_die);
15017 /* Traverse the DIE's and add add sibling attributes to those DIE's
15018 that have children. */
15019 add_sibling_attributes (comp_unit_die);
15020 for (node = limbo_die_list; node; node = node->next)
15021 add_sibling_attributes (node->die);
15023 /* Output a terminator label for the .text section. */
15024 switch_to_section (text_section);
15025 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
15026 if (flag_reorder_blocks_and_partition)
15028 switch_to_section (unlikely_text_section ());
15029 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
15032 /* We can only use the low/high_pc attributes if all of the code was
15034 if (!have_multiple_function_sections)
15036 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
15037 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
15042 unsigned fde_idx = 0;
15044 /* We need to give .debug_loc and .debug_ranges an appropriate
15045 "base address". Use zero so that these addresses become
15046 absolute. Historically, we've emitted the unexpected
15047 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15048 Emit both to give time for other tools to adapt. */
15049 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
15050 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
15052 add_AT_range_list (comp_unit_die, DW_AT_ranges,
15053 add_ranges_by_labels (text_section_label,
15055 if (flag_reorder_blocks_and_partition)
15056 add_ranges_by_labels (cold_text_section_label,
15059 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
15061 dw_fde_ref fde = &fde_table[fde_idx];
15063 if (fde->dw_fde_switched_sections)
15065 add_ranges_by_labels (fde->dw_fde_hot_section_label,
15066 fde->dw_fde_hot_section_end_label);
15067 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
15068 fde->dw_fde_unlikely_section_end_label);
15071 add_ranges_by_labels (fde->dw_fde_begin,
15078 /* Output location list section if necessary. */
15079 if (have_location_lists)
15081 /* Output the location lists info. */
15082 switch_to_section (debug_loc_section);
15083 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
15084 DEBUG_LOC_SECTION_LABEL, 0);
15085 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
15086 output_location_lists (die);
15089 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15090 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
15091 debug_line_section_label);
15093 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15094 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
15096 /* Output all of the compilation units. We put the main one last so that
15097 the offsets are available to output_pubnames. */
15098 for (node = limbo_die_list; node; node = node->next)
15099 output_comp_unit (node->die, 0);
15101 output_comp_unit (comp_unit_die, 0);
15103 /* Output the abbreviation table. */
15104 switch_to_section (debug_abbrev_section);
15105 output_abbrev_section ();
15107 /* Output public names table if necessary. */
15108 if (!VEC_empty (pubname_entry, pubname_table))
15110 switch_to_section (debug_pubnames_section);
15111 output_pubnames (pubname_table);
15114 #ifdef DEBUG_PUBTYPES_SECTION
15115 /* Output public types table if necessary. */
15116 if (!VEC_empty (pubname_entry, pubtype_table))
15118 switch_to_section (debug_pubtypes_section);
15119 output_pubnames (pubtype_table);
15123 /* Output the address range information. We only put functions in the arange
15124 table, so don't write it out if we don't have any. */
15125 if (fde_table_in_use)
15127 switch_to_section (debug_aranges_section);
15131 /* Output ranges section if necessary. */
15132 if (ranges_table_in_use)
15134 switch_to_section (debug_ranges_section);
15135 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
15139 /* Output the source line correspondence table. We must do this
15140 even if there is no line information. Otherwise, on an empty
15141 translation unit, we will generate a present, but empty,
15142 .debug_info section. IRIX 6.5 `nm' will then complain when
15143 examining the file. This is done late so that any filenames
15144 used by the debug_info section are marked as 'used'. */
15145 if (! DWARF2_ASM_LINE_DEBUG_INFO)
15147 switch_to_section (debug_line_section);
15148 output_line_info ();
15151 /* Have to end the macro section. */
15152 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15154 switch_to_section (debug_macinfo_section);
15155 dw2_asm_output_data (1, 0, "End compilation unit");
15158 /* If we emitted any DW_FORM_strp form attribute, output the string
15160 if (debug_str_hash)
15161 htab_traverse (debug_str_hash, output_indirect_string, NULL);
15165 /* This should never be used, but its address is needed for comparisons. */
15166 const struct gcc_debug_hooks dwarf2_debug_hooks;
15168 #endif /* DWARF2_DEBUGGING_INFO */
15170 #include "gt-dwarf2out.h"