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 (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 (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 (rtx pattern)
1030 rtx src = SET_SRC (pattern);
1031 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 (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
2227 for (i = 0; i < fde_table_in_use; i++)
2228 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2229 && !fde_table[i].uses_eh_lsda
2230 && ! DECL_WEAK (fde_table[i].decl))
2231 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2232 for_eh, /* empty */ 1);
2234 /* If we don't have any functions we'll want to unwind out of, don't
2235 emit any EH unwind information. Note that if exceptions aren't
2236 enabled, we won't have collected nothrow information, and if we
2237 asked for asynchronous tables, we always want this info. */
2240 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2242 for (i = 0; i < fde_table_in_use; i++)
2243 if (fde_table[i].uses_eh_lsda)
2244 any_eh_needed = any_lsda_needed = true;
2245 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2246 any_eh_needed = true;
2247 else if (! fde_table[i].nothrow
2248 && ! fde_table[i].all_throwers_are_sibcalls)
2249 any_eh_needed = true;
2251 if (! any_eh_needed)
2255 /* We're going to be generating comments, so turn on app. */
2260 switch_to_eh_frame_section ();
2263 if (!debug_frame_section)
2264 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2265 SECTION_DEBUG, NULL);
2266 switch_to_section (debug_frame_section);
2269 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2270 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2272 /* Output the CIE. */
2273 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2274 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2275 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2276 dw2_asm_output_data (4, 0xffffffff,
2277 "Initial length escape value indicating 64-bit DWARF extension");
2278 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2279 "Length of Common Information Entry");
2280 ASM_OUTPUT_LABEL (asm_out_file, l1);
2282 /* Now that the CIE pointer is PC-relative for EH,
2283 use 0 to identify the CIE. */
2284 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2285 (for_eh ? 0 : DWARF_CIE_ID),
2286 "CIE Identifier Tag");
2288 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2290 augmentation[0] = 0;
2291 augmentation_size = 0;
2297 z Indicates that a uleb128 is present to size the
2298 augmentation section.
2299 L Indicates the encoding (and thus presence) of
2300 an LSDA pointer in the FDE augmentation.
2301 R Indicates a non-default pointer encoding for
2303 P Indicates the presence of an encoding + language
2304 personality routine in the CIE augmentation. */
2306 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2307 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2308 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2310 p = augmentation + 1;
2311 if (eh_personality_libfunc)
2314 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2315 assemble_external_libcall (eh_personality_libfunc);
2317 if (any_lsda_needed)
2320 augmentation_size += 1;
2322 if (fde_encoding != DW_EH_PE_absptr)
2325 augmentation_size += 1;
2327 if (p > augmentation + 1)
2329 augmentation[0] = 'z';
2333 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2334 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2336 int offset = ( 4 /* Length */
2338 + 1 /* CIE version */
2339 + strlen (augmentation) + 1 /* Augmentation */
2340 + size_of_uleb128 (1) /* Code alignment */
2341 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2343 + 1 /* Augmentation size */
2344 + 1 /* Personality encoding */ );
2345 int pad = -offset & (PTR_SIZE - 1);
2347 augmentation_size += pad;
2349 /* Augmentations should be small, so there's scarce need to
2350 iterate for a solution. Die if we exceed one uleb128 byte. */
2351 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2355 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2356 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2357 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2358 "CIE Data Alignment Factor");
2360 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2361 if (DW_CIE_VERSION == 1)
2362 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2364 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2366 if (augmentation[0])
2368 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2369 if (eh_personality_libfunc)
2371 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2372 eh_data_format_name (per_encoding));
2373 dw2_asm_output_encoded_addr_rtx (per_encoding,
2374 eh_personality_libfunc,
2378 if (any_lsda_needed)
2379 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2380 eh_data_format_name (lsda_encoding));
2382 if (fde_encoding != DW_EH_PE_absptr)
2383 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2384 eh_data_format_name (fde_encoding));
2387 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2388 output_cfi (cfi, NULL, for_eh);
2390 /* Pad the CIE out to an address sized boundary. */
2391 ASM_OUTPUT_ALIGN (asm_out_file,
2392 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2393 ASM_OUTPUT_LABEL (asm_out_file, l2);
2395 /* Loop through all of the FDE's. */
2396 for (i = 0; i < fde_table_in_use; i++)
2398 fde = &fde_table[i];
2400 /* Don't emit EH unwind info for leaf functions that don't need it. */
2401 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2402 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2403 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2404 && !fde->uses_eh_lsda)
2407 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2408 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2409 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2410 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2411 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2412 dw2_asm_output_data (4, 0xffffffff,
2413 "Initial length escape value indicating 64-bit DWARF extension");
2414 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2416 ASM_OUTPUT_LABEL (asm_out_file, l1);
2419 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2421 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2422 debug_frame_section, "FDE CIE offset");
2426 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2427 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2428 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2431 "FDE initial location");
2432 if (fde->dw_fde_switched_sections)
2434 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2435 fde->dw_fde_unlikely_section_label);
2436 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2437 fde->dw_fde_hot_section_label);
2438 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2439 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2440 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2441 "FDE initial location");
2442 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2443 fde->dw_fde_hot_section_end_label,
2444 fde->dw_fde_hot_section_label,
2445 "FDE address range");
2446 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2447 "FDE initial location");
2448 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2449 fde->dw_fde_unlikely_section_end_label,
2450 fde->dw_fde_unlikely_section_label,
2451 "FDE address range");
2454 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2455 fde->dw_fde_end, fde->dw_fde_begin,
2456 "FDE address range");
2460 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2461 "FDE initial location");
2462 if (fde->dw_fde_switched_sections)
2464 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2465 fde->dw_fde_hot_section_label,
2466 "FDE initial location");
2467 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2468 fde->dw_fde_hot_section_end_label,
2469 fde->dw_fde_hot_section_label,
2470 "FDE address range");
2471 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2472 fde->dw_fde_unlikely_section_label,
2473 "FDE initial location");
2474 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2475 fde->dw_fde_unlikely_section_end_label,
2476 fde->dw_fde_unlikely_section_label,
2477 "FDE address range");
2480 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2481 fde->dw_fde_end, fde->dw_fde_begin,
2482 "FDE address range");
2485 if (augmentation[0])
2487 if (any_lsda_needed)
2489 int size = size_of_encoded_value (lsda_encoding);
2491 if (lsda_encoding == DW_EH_PE_aligned)
2493 int offset = ( 4 /* Length */
2494 + 4 /* CIE offset */
2495 + 2 * size_of_encoded_value (fde_encoding)
2496 + 1 /* Augmentation size */ );
2497 int pad = -offset & (PTR_SIZE - 1);
2500 gcc_assert (size_of_uleb128 (size) == 1);
2503 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2505 if (fde->uses_eh_lsda)
2507 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2508 fde->funcdef_number);
2509 dw2_asm_output_encoded_addr_rtx (
2510 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2511 false, "Language Specific Data Area");
2515 if (lsda_encoding == DW_EH_PE_aligned)
2516 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2518 (size_of_encoded_value (lsda_encoding), 0,
2519 "Language Specific Data Area (none)");
2523 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2526 /* Loop through the Call Frame Instructions associated with
2528 fde->dw_fde_current_label = fde->dw_fde_begin;
2529 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2530 output_cfi (cfi, fde, for_eh);
2532 /* Pad the FDE out to an address sized boundary. */
2533 ASM_OUTPUT_ALIGN (asm_out_file,
2534 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2535 ASM_OUTPUT_LABEL (asm_out_file, l2);
2538 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2539 dw2_asm_output_data (4, 0, "End of Table");
2540 #ifdef MIPS_DEBUGGING_INFO
2541 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2542 get a value of 0. Putting .align 0 after the label fixes it. */
2543 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2546 /* Turn off app to make assembly quicker. */
2551 /* Output a marker (i.e. a label) for the beginning of a function, before
2555 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2556 const char *file ATTRIBUTE_UNUSED)
2558 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2562 current_function_func_begin_label = NULL;
2564 #ifdef TARGET_UNWIND_INFO
2565 /* ??? current_function_func_begin_label is also used by except.c
2566 for call-site information. We must emit this label if it might
2568 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2569 && ! dwarf2out_do_frame ())
2572 if (! dwarf2out_do_frame ())
2576 switch_to_section (function_section (current_function_decl));
2577 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2578 current_function_funcdef_no);
2579 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2580 current_function_funcdef_no);
2581 dup_label = xstrdup (label);
2582 current_function_func_begin_label = dup_label;
2584 #ifdef TARGET_UNWIND_INFO
2585 /* We can elide the fde allocation if we're not emitting debug info. */
2586 if (! dwarf2out_do_frame ())
2590 /* Expand the fde table if necessary. */
2591 if (fde_table_in_use == fde_table_allocated)
2593 fde_table_allocated += FDE_TABLE_INCREMENT;
2594 fde_table = ggc_realloc (fde_table,
2595 fde_table_allocated * sizeof (dw_fde_node));
2596 memset (fde_table + fde_table_in_use, 0,
2597 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2600 /* Record the FDE associated with this function. */
2601 current_funcdef_fde = fde_table_in_use;
2603 /* Add the new FDE at the end of the fde_table. */
2604 fde = &fde_table[fde_table_in_use++];
2605 fde->decl = current_function_decl;
2606 fde->dw_fde_begin = dup_label;
2607 fde->dw_fde_current_label = dup_label;
2608 fde->dw_fde_hot_section_label = NULL;
2609 fde->dw_fde_hot_section_end_label = NULL;
2610 fde->dw_fde_unlikely_section_label = NULL;
2611 fde->dw_fde_unlikely_section_end_label = NULL;
2612 fde->dw_fde_switched_sections = false;
2613 fde->dw_fde_end = NULL;
2614 fde->dw_fde_cfi = NULL;
2615 fde->funcdef_number = current_function_funcdef_no;
2616 fde->nothrow = TREE_NOTHROW (current_function_decl);
2617 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2618 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2620 args_size = old_args_size = 0;
2622 /* We only want to output line number information for the genuine dwarf2
2623 prologue case, not the eh frame case. */
2624 #ifdef DWARF2_DEBUGGING_INFO
2626 dwarf2out_source_line (line, file);
2630 /* Output a marker (i.e. a label) for the absolute end of the generated code
2631 for a function definition. This gets called *after* the epilogue code has
2635 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2636 const char *file ATTRIBUTE_UNUSED)
2639 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2641 /* Output a label to mark the endpoint of the code generated for this
2643 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2644 current_function_funcdef_no);
2645 ASM_OUTPUT_LABEL (asm_out_file, label);
2646 fde = &fde_table[fde_table_in_use - 1];
2647 fde->dw_fde_end = xstrdup (label);
2651 dwarf2out_frame_init (void)
2653 /* Allocate the initial hunk of the fde_table. */
2654 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2655 fde_table_allocated = FDE_TABLE_INCREMENT;
2656 fde_table_in_use = 0;
2658 /* Generate the CFA instructions common to all FDE's. Do it now for the
2659 sake of lookup_cfa. */
2661 /* On entry, the Canonical Frame Address is at SP. */
2662 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2664 #ifdef DWARF2_UNWIND_INFO
2665 if (DWARF2_UNWIND_INFO)
2666 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2671 dwarf2out_frame_finish (void)
2673 /* Output call frame information. */
2674 if (DWARF2_FRAME_INFO)
2675 output_call_frame_info (0);
2677 #ifndef TARGET_UNWIND_INFO
2678 /* Output another copy for the unwinder. */
2679 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2680 output_call_frame_info (1);
2685 /* And now, the subset of the debugging information support code necessary
2686 for emitting location expressions. */
2688 /* Data about a single source file. */
2689 struct dwarf_file_data GTY(())
2691 const char * filename;
2695 /* We need some way to distinguish DW_OP_addr with a direct symbol
2696 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2697 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2700 typedef struct dw_val_struct *dw_val_ref;
2701 typedef struct die_struct *dw_die_ref;
2702 typedef const struct die_struct *const_dw_die_ref;
2703 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2704 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2706 /* Each DIE may have a series of attribute/value pairs. Values
2707 can take on several forms. The forms that are used in this
2708 implementation are listed below. */
2713 dw_val_class_offset,
2715 dw_val_class_loc_list,
2716 dw_val_class_range_list,
2718 dw_val_class_unsigned_const,
2719 dw_val_class_long_long,
2722 dw_val_class_die_ref,
2723 dw_val_class_fde_ref,
2724 dw_val_class_lbl_id,
2725 dw_val_class_lineptr,
2727 dw_val_class_macptr,
2731 /* Describe a double word constant value. */
2732 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2734 typedef struct dw_long_long_struct GTY(())
2741 /* Describe a floating point constant value, or a vector constant value. */
2743 typedef struct dw_vec_struct GTY(())
2745 unsigned char * GTY((length ("%h.length"))) array;
2751 /* The dw_val_node describes an attribute's value, as it is
2752 represented internally. */
2754 typedef struct dw_val_struct GTY(())
2756 enum dw_val_class val_class;
2757 union dw_val_struct_union
2759 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2760 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2761 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2762 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2763 HOST_WIDE_INT GTY ((default)) val_int;
2764 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2765 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2766 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2767 struct dw_val_die_union
2771 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2772 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2773 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2774 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2775 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2776 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2778 GTY ((desc ("%1.val_class"))) v;
2782 /* Locations in memory are described using a sequence of stack machine
2785 typedef struct dw_loc_descr_struct GTY(())
2787 dw_loc_descr_ref dw_loc_next;
2788 enum dwarf_location_atom dw_loc_opc;
2789 dw_val_node dw_loc_oprnd1;
2790 dw_val_node dw_loc_oprnd2;
2795 /* Location lists are ranges + location descriptions for that range,
2796 so you can track variables that are in different places over
2797 their entire life. */
2798 typedef struct dw_loc_list_struct GTY(())
2800 dw_loc_list_ref dw_loc_next;
2801 const char *begin; /* Label for begin address of range */
2802 const char *end; /* Label for end address of range */
2803 char *ll_symbol; /* Label for beginning of location list.
2804 Only on head of list */
2805 const char *section; /* Section this loclist is relative to */
2806 dw_loc_descr_ref expr;
2809 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2811 static const char *dwarf_stack_op_name (unsigned);
2812 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2813 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2814 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2815 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2816 static unsigned long size_of_locs (dw_loc_descr_ref);
2817 static void output_loc_operands (dw_loc_descr_ref);
2818 static void output_loc_sequence (dw_loc_descr_ref);
2820 /* Convert a DWARF stack opcode into its string name. */
2823 dwarf_stack_op_name (unsigned int op)
2828 case INTERNAL_DW_OP_tls_addr:
2829 return "DW_OP_addr";
2831 return "DW_OP_deref";
2833 return "DW_OP_const1u";
2835 return "DW_OP_const1s";
2837 return "DW_OP_const2u";
2839 return "DW_OP_const2s";
2841 return "DW_OP_const4u";
2843 return "DW_OP_const4s";
2845 return "DW_OP_const8u";
2847 return "DW_OP_const8s";
2849 return "DW_OP_constu";
2851 return "DW_OP_consts";
2855 return "DW_OP_drop";
2857 return "DW_OP_over";
2859 return "DW_OP_pick";
2861 return "DW_OP_swap";
2865 return "DW_OP_xderef";
2873 return "DW_OP_minus";
2885 return "DW_OP_plus";
2886 case DW_OP_plus_uconst:
2887 return "DW_OP_plus_uconst";
2893 return "DW_OP_shra";
2911 return "DW_OP_skip";
2913 return "DW_OP_lit0";
2915 return "DW_OP_lit1";
2917 return "DW_OP_lit2";
2919 return "DW_OP_lit3";
2921 return "DW_OP_lit4";
2923 return "DW_OP_lit5";
2925 return "DW_OP_lit6";
2927 return "DW_OP_lit7";
2929 return "DW_OP_lit8";
2931 return "DW_OP_lit9";
2933 return "DW_OP_lit10";
2935 return "DW_OP_lit11";
2937 return "DW_OP_lit12";
2939 return "DW_OP_lit13";
2941 return "DW_OP_lit14";
2943 return "DW_OP_lit15";
2945 return "DW_OP_lit16";
2947 return "DW_OP_lit17";
2949 return "DW_OP_lit18";
2951 return "DW_OP_lit19";
2953 return "DW_OP_lit20";
2955 return "DW_OP_lit21";
2957 return "DW_OP_lit22";
2959 return "DW_OP_lit23";
2961 return "DW_OP_lit24";
2963 return "DW_OP_lit25";
2965 return "DW_OP_lit26";
2967 return "DW_OP_lit27";
2969 return "DW_OP_lit28";
2971 return "DW_OP_lit29";
2973 return "DW_OP_lit30";
2975 return "DW_OP_lit31";
2977 return "DW_OP_reg0";
2979 return "DW_OP_reg1";
2981 return "DW_OP_reg2";
2983 return "DW_OP_reg3";
2985 return "DW_OP_reg4";
2987 return "DW_OP_reg5";
2989 return "DW_OP_reg6";
2991 return "DW_OP_reg7";
2993 return "DW_OP_reg8";
2995 return "DW_OP_reg9";
2997 return "DW_OP_reg10";
2999 return "DW_OP_reg11";
3001 return "DW_OP_reg12";
3003 return "DW_OP_reg13";
3005 return "DW_OP_reg14";
3007 return "DW_OP_reg15";
3009 return "DW_OP_reg16";
3011 return "DW_OP_reg17";
3013 return "DW_OP_reg18";
3015 return "DW_OP_reg19";
3017 return "DW_OP_reg20";
3019 return "DW_OP_reg21";
3021 return "DW_OP_reg22";
3023 return "DW_OP_reg23";
3025 return "DW_OP_reg24";
3027 return "DW_OP_reg25";
3029 return "DW_OP_reg26";
3031 return "DW_OP_reg27";
3033 return "DW_OP_reg28";
3035 return "DW_OP_reg29";
3037 return "DW_OP_reg30";
3039 return "DW_OP_reg31";
3041 return "DW_OP_breg0";
3043 return "DW_OP_breg1";
3045 return "DW_OP_breg2";
3047 return "DW_OP_breg3";
3049 return "DW_OP_breg4";
3051 return "DW_OP_breg5";
3053 return "DW_OP_breg6";
3055 return "DW_OP_breg7";
3057 return "DW_OP_breg8";
3059 return "DW_OP_breg9";
3061 return "DW_OP_breg10";
3063 return "DW_OP_breg11";
3065 return "DW_OP_breg12";
3067 return "DW_OP_breg13";
3069 return "DW_OP_breg14";
3071 return "DW_OP_breg15";
3073 return "DW_OP_breg16";
3075 return "DW_OP_breg17";
3077 return "DW_OP_breg18";
3079 return "DW_OP_breg19";
3081 return "DW_OP_breg20";
3083 return "DW_OP_breg21";
3085 return "DW_OP_breg22";
3087 return "DW_OP_breg23";
3089 return "DW_OP_breg24";
3091 return "DW_OP_breg25";
3093 return "DW_OP_breg26";
3095 return "DW_OP_breg27";
3097 return "DW_OP_breg28";
3099 return "DW_OP_breg29";
3101 return "DW_OP_breg30";
3103 return "DW_OP_breg31";
3105 return "DW_OP_regx";
3107 return "DW_OP_fbreg";
3109 return "DW_OP_bregx";
3111 return "DW_OP_piece";
3112 case DW_OP_deref_size:
3113 return "DW_OP_deref_size";
3114 case DW_OP_xderef_size:
3115 return "DW_OP_xderef_size";
3118 case DW_OP_push_object_address:
3119 return "DW_OP_push_object_address";
3121 return "DW_OP_call2";
3123 return "DW_OP_call4";
3124 case DW_OP_call_ref:
3125 return "DW_OP_call_ref";
3126 case DW_OP_GNU_push_tls_address:
3127 return "DW_OP_GNU_push_tls_address";
3128 case DW_OP_GNU_uninit:
3129 return "DW_OP_GNU_uninit";
3131 return "OP_<unknown>";
3135 /* Return a pointer to a newly allocated location description. Location
3136 descriptions are simple expression terms that can be strung
3137 together to form more complicated location (address) descriptions. */
3139 static inline dw_loc_descr_ref
3140 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3141 unsigned HOST_WIDE_INT oprnd2)
3143 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3145 descr->dw_loc_opc = op;
3146 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3147 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3148 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3149 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3154 /* Add a location description term to a location description expression. */
3157 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3159 dw_loc_descr_ref *d;
3161 /* Find the end of the chain. */
3162 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3168 /* Return the size of a location descriptor. */
3170 static unsigned long
3171 size_of_loc_descr (dw_loc_descr_ref loc)
3173 unsigned long size = 1;
3175 switch (loc->dw_loc_opc)
3178 case INTERNAL_DW_OP_tls_addr:
3179 size += DWARF2_ADDR_SIZE;
3198 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3201 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3206 case DW_OP_plus_uconst:
3207 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3245 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3248 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3251 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3254 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3255 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3258 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3260 case DW_OP_deref_size:
3261 case DW_OP_xderef_size:
3270 case DW_OP_call_ref:
3271 size += DWARF2_ADDR_SIZE;
3280 /* Return the size of a series of location descriptors. */
3282 static unsigned long
3283 size_of_locs (dw_loc_descr_ref loc)
3288 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3289 field, to avoid writing to a PCH file. */
3290 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3292 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3294 size += size_of_loc_descr (l);
3299 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3301 l->dw_loc_addr = size;
3302 size += size_of_loc_descr (l);
3308 /* Output location description stack opcode's operands (if any). */
3311 output_loc_operands (dw_loc_descr_ref loc)
3313 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3314 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3316 switch (loc->dw_loc_opc)
3318 #ifdef DWARF2_DEBUGGING_INFO
3320 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3324 dw2_asm_output_data (2, val1->v.val_int, NULL);
3328 dw2_asm_output_data (4, val1->v.val_int, NULL);
3332 gcc_assert (HOST_BITS_PER_LONG >= 64);
3333 dw2_asm_output_data (8, val1->v.val_int, NULL);
3340 gcc_assert (val1->val_class == dw_val_class_loc);
3341 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3343 dw2_asm_output_data (2, offset, NULL);
3356 /* We currently don't make any attempt to make sure these are
3357 aligned properly like we do for the main unwind info, so
3358 don't support emitting things larger than a byte if we're
3359 only doing unwinding. */
3364 dw2_asm_output_data (1, val1->v.val_int, NULL);
3367 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3370 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3373 dw2_asm_output_data (1, val1->v.val_int, NULL);
3375 case DW_OP_plus_uconst:
3376 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3410 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3413 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3416 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3419 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3420 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3423 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3425 case DW_OP_deref_size:
3426 case DW_OP_xderef_size:
3427 dw2_asm_output_data (1, val1->v.val_int, NULL);
3430 case INTERNAL_DW_OP_tls_addr:
3431 if (targetm.asm_out.output_dwarf_dtprel)
3433 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3436 fputc ('\n', asm_out_file);
3443 /* Other codes have no operands. */
3448 /* Output a sequence of location operations. */
3451 output_loc_sequence (dw_loc_descr_ref loc)
3453 for (; loc != NULL; loc = loc->dw_loc_next)
3455 /* Output the opcode. */
3456 dw2_asm_output_data (1, loc->dw_loc_opc,
3457 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3459 /* Output the operand(s) (if any). */
3460 output_loc_operands (loc);
3464 /* This routine will generate the correct assembly data for a location
3465 description based on a cfi entry with a complex address. */
3468 output_cfa_loc (dw_cfi_ref cfi)
3470 dw_loc_descr_ref loc;
3473 /* Output the size of the block. */
3474 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3475 size = size_of_locs (loc);
3476 dw2_asm_output_data_uleb128 (size, NULL);
3478 /* Now output the operations themselves. */
3479 output_loc_sequence (loc);
3482 /* This function builds a dwarf location descriptor sequence from a
3483 dw_cfa_location, adding the given OFFSET to the result of the
3486 static struct dw_loc_descr_struct *
3487 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3489 struct dw_loc_descr_struct *head, *tmp;
3491 offset += cfa->offset;
3495 if (cfa->base_offset)
3498 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3500 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3502 else if (cfa->reg <= 31)
3503 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3505 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3507 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3508 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3509 add_loc_descr (&head, tmp);
3512 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3513 add_loc_descr (&head, tmp);
3520 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3522 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3523 else if (cfa->reg <= 31)
3524 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3526 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3532 /* This function fills in aa dw_cfa_location structure from a dwarf location
3533 descriptor sequence. */
3536 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3538 struct dw_loc_descr_struct *ptr;
3540 cfa->base_offset = 0;
3544 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3546 enum dwarf_location_atom op = ptr->dw_loc_opc;
3582 cfa->reg = op - DW_OP_reg0;
3585 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3619 cfa->reg = op - DW_OP_breg0;
3620 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3623 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3624 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3629 case DW_OP_plus_uconst:
3630 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3633 internal_error ("DW_LOC_OP %s not implemented",
3634 dwarf_stack_op_name (ptr->dw_loc_opc));
3638 #endif /* .debug_frame support */
3640 /* And now, the support for symbolic debugging information. */
3641 #ifdef DWARF2_DEBUGGING_INFO
3643 /* .debug_str support. */
3644 static int output_indirect_string (void **, void *);
3646 static void dwarf2out_init (const char *);
3647 static void dwarf2out_finish (const char *);
3648 static void dwarf2out_define (unsigned int, const char *);
3649 static void dwarf2out_undef (unsigned int, const char *);
3650 static void dwarf2out_start_source_file (unsigned, const char *);
3651 static void dwarf2out_end_source_file (unsigned);
3652 static void dwarf2out_begin_block (unsigned, unsigned);
3653 static void dwarf2out_end_block (unsigned, unsigned);
3654 static bool dwarf2out_ignore_block (tree);
3655 static void dwarf2out_global_decl (tree);
3656 static void dwarf2out_type_decl (tree, int);
3657 static void dwarf2out_imported_module_or_decl (tree, tree);
3658 static void dwarf2out_abstract_function (tree);
3659 static void dwarf2out_var_location (rtx);
3660 static void dwarf2out_begin_function (tree);
3661 static void dwarf2out_switch_text_section (void);
3663 /* The debug hooks structure. */
3665 const struct gcc_debug_hooks dwarf2_debug_hooks =
3671 dwarf2out_start_source_file,
3672 dwarf2out_end_source_file,
3673 dwarf2out_begin_block,
3674 dwarf2out_end_block,
3675 dwarf2out_ignore_block,
3676 dwarf2out_source_line,
3677 dwarf2out_begin_prologue,
3678 debug_nothing_int_charstar, /* end_prologue */
3679 dwarf2out_end_epilogue,
3680 dwarf2out_begin_function,
3681 debug_nothing_int, /* end_function */
3682 dwarf2out_decl, /* function_decl */
3683 dwarf2out_global_decl,
3684 dwarf2out_type_decl, /* type_decl */
3685 dwarf2out_imported_module_or_decl,
3686 debug_nothing_tree, /* deferred_inline_function */
3687 /* The DWARF 2 backend tries to reduce debugging bloat by not
3688 emitting the abstract description of inline functions until
3689 something tries to reference them. */
3690 dwarf2out_abstract_function, /* outlining_inline_function */
3691 debug_nothing_rtx, /* label */
3692 debug_nothing_int, /* handle_pch */
3693 dwarf2out_var_location,
3694 dwarf2out_switch_text_section,
3695 1 /* start_end_main_source_file */
3699 /* NOTE: In the comments in this file, many references are made to
3700 "Debugging Information Entries". This term is abbreviated as `DIE'
3701 throughout the remainder of this file. */
3703 /* An internal representation of the DWARF output is built, and then
3704 walked to generate the DWARF debugging info. The walk of the internal
3705 representation is done after the entire program has been compiled.
3706 The types below are used to describe the internal representation. */
3708 /* Various DIE's use offsets relative to the beginning of the
3709 .debug_info section to refer to each other. */
3711 typedef long int dw_offset;
3713 /* Define typedefs here to avoid circular dependencies. */
3715 typedef struct dw_attr_struct *dw_attr_ref;
3716 typedef struct dw_line_info_struct *dw_line_info_ref;
3717 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3718 typedef struct pubname_struct *pubname_ref;
3719 typedef struct dw_ranges_struct *dw_ranges_ref;
3720 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3722 /* Each entry in the line_info_table maintains the file and
3723 line number associated with the label generated for that
3724 entry. The label gives the PC value associated with
3725 the line number entry. */
3727 typedef struct dw_line_info_struct GTY(())
3729 unsigned long dw_file_num;
3730 unsigned long dw_line_num;
3734 /* Line information for functions in separate sections; each one gets its
3736 typedef struct dw_separate_line_info_struct GTY(())
3738 unsigned long dw_file_num;
3739 unsigned long dw_line_num;
3740 unsigned long function;
3742 dw_separate_line_info_entry;
3744 /* Each DIE attribute has a field specifying the attribute kind,
3745 a link to the next attribute in the chain, and an attribute value.
3746 Attributes are typically linked below the DIE they modify. */
3748 typedef struct dw_attr_struct GTY(())
3750 enum dwarf_attribute dw_attr;
3751 dw_val_node dw_attr_val;
3755 DEF_VEC_O(dw_attr_node);
3756 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3758 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3759 The children of each node form a circular list linked by
3760 die_sib. die_child points to the node *before* the "first" child node. */
3762 typedef struct die_struct GTY(())
3764 enum dwarf_tag die_tag;
3766 VEC(dw_attr_node,gc) * die_attr;
3767 dw_die_ref die_parent;
3768 dw_die_ref die_child;
3770 dw_die_ref die_definition; /* ref from a specification to its definition */
3771 dw_offset die_offset;
3772 unsigned long die_abbrev;
3774 /* Die is used and must not be pruned as unused. */
3775 int die_perennial_p;
3776 unsigned int decl_id;
3780 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3781 #define FOR_EACH_CHILD(die, c, expr) do { \
3782 c = die->die_child; \
3786 } while (c != die->die_child); \
3789 /* The pubname structure */
3791 typedef struct pubname_struct GTY(())
3798 DEF_VEC_O(pubname_entry);
3799 DEF_VEC_ALLOC_O(pubname_entry, gc);
3801 struct dw_ranges_struct GTY(())
3803 /* If this is positive, it's a block number, otherwise it's a
3804 bitwise-negated index into dw_ranges_by_label. */
3808 struct dw_ranges_by_label_struct GTY(())
3814 /* The limbo die list structure. */
3815 typedef struct limbo_die_struct GTY(())
3819 struct limbo_die_struct *next;
3823 /* How to start an assembler comment. */
3824 #ifndef ASM_COMMENT_START
3825 #define ASM_COMMENT_START ";#"
3828 /* Define a macro which returns nonzero for a TYPE_DECL which was
3829 implicitly generated for a tagged type.
3831 Note that unlike the gcc front end (which generates a NULL named
3832 TYPE_DECL node for each complete tagged type, each array type, and
3833 each function type node created) the g++ front end generates a
3834 _named_ TYPE_DECL node for each tagged type node created.
3835 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3836 generate a DW_TAG_typedef DIE for them. */
3838 #define TYPE_DECL_IS_STUB(decl) \
3839 (DECL_NAME (decl) == NULL_TREE \
3840 || (DECL_ARTIFICIAL (decl) \
3841 && is_tagged_type (TREE_TYPE (decl)) \
3842 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3843 /* This is necessary for stub decls that \
3844 appear in nested inline functions. */ \
3845 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3846 && (decl_ultimate_origin (decl) \
3847 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3849 /* Information concerning the compilation unit's programming
3850 language, and compiler version. */
3852 /* Fixed size portion of the DWARF compilation unit header. */
3853 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3854 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3856 /* Fixed size portion of public names info. */
3857 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3859 /* Fixed size portion of the address range info. */
3860 #define DWARF_ARANGES_HEADER_SIZE \
3861 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3862 DWARF2_ADDR_SIZE * 2) \
3863 - DWARF_INITIAL_LENGTH_SIZE)
3865 /* Size of padding portion in the address range info. It must be
3866 aligned to twice the pointer size. */
3867 #define DWARF_ARANGES_PAD_SIZE \
3868 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3869 DWARF2_ADDR_SIZE * 2) \
3870 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3872 /* Use assembler line directives if available. */
3873 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3874 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3875 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3877 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3881 /* Minimum line offset in a special line info. opcode.
3882 This value was chosen to give a reasonable range of values. */
3883 #define DWARF_LINE_BASE -10
3885 /* First special line opcode - leave room for the standard opcodes. */
3886 #define DWARF_LINE_OPCODE_BASE 10
3888 /* Range of line offsets in a special line info. opcode. */
3889 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3891 /* Flag that indicates the initial value of the is_stmt_start flag.
3892 In the present implementation, we do not mark any lines as
3893 the beginning of a source statement, because that information
3894 is not made available by the GCC front-end. */
3895 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3897 #ifdef DWARF2_DEBUGGING_INFO
3898 /* This location is used by calc_die_sizes() to keep track
3899 the offset of each DIE within the .debug_info section. */
3900 static unsigned long next_die_offset;
3903 /* Record the root of the DIE's built for the current compilation unit. */
3904 static GTY(()) dw_die_ref comp_unit_die;
3906 /* A list of DIEs with a NULL parent waiting to be relocated. */
3907 static GTY(()) limbo_die_node *limbo_die_list;
3909 /* Filenames referenced by this compilation unit. */
3910 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3912 /* A hash table of references to DIE's that describe declarations.
3913 The key is a DECL_UID() which is a unique number identifying each decl. */
3914 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3916 /* Node of the variable location list. */
3917 struct var_loc_node GTY ((chain_next ("%h.next")))
3919 rtx GTY (()) var_loc_note;
3920 const char * GTY (()) label;
3921 const char * GTY (()) section_label;
3922 struct var_loc_node * GTY (()) next;
3925 /* Variable location list. */
3926 struct var_loc_list_def GTY (())
3928 struct var_loc_node * GTY (()) first;
3930 /* Do not mark the last element of the chained list because
3931 it is marked through the chain. */
3932 struct var_loc_node * GTY ((skip ("%h"))) last;
3934 /* DECL_UID of the variable decl. */
3935 unsigned int decl_id;
3937 typedef struct var_loc_list_def var_loc_list;
3940 /* Table of decl location linked lists. */
3941 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3943 /* A pointer to the base of a list of references to DIE's that
3944 are uniquely identified by their tag, presence/absence of
3945 children DIE's, and list of attribute/value pairs. */
3946 static GTY((length ("abbrev_die_table_allocated")))
3947 dw_die_ref *abbrev_die_table;
3949 /* Number of elements currently allocated for abbrev_die_table. */
3950 static GTY(()) unsigned abbrev_die_table_allocated;
3952 /* Number of elements in type_die_table currently in use. */
3953 static GTY(()) unsigned abbrev_die_table_in_use;
3955 /* Size (in elements) of increments by which we may expand the
3956 abbrev_die_table. */
3957 #define ABBREV_DIE_TABLE_INCREMENT 256
3959 /* A pointer to the base of a table that contains line information
3960 for each source code line in .text in the compilation unit. */
3961 static GTY((length ("line_info_table_allocated")))
3962 dw_line_info_ref line_info_table;
3964 /* Number of elements currently allocated for line_info_table. */
3965 static GTY(()) unsigned line_info_table_allocated;
3967 /* Number of elements in line_info_table currently in use. */
3968 static GTY(()) unsigned line_info_table_in_use;
3970 /* True if the compilation unit places functions in more than one section. */
3971 static GTY(()) bool have_multiple_function_sections = false;
3973 /* A pointer to the base of a table that contains line information
3974 for each source code line outside of .text in the compilation unit. */
3975 static GTY ((length ("separate_line_info_table_allocated")))
3976 dw_separate_line_info_ref separate_line_info_table;
3978 /* Number of elements currently allocated for separate_line_info_table. */
3979 static GTY(()) unsigned separate_line_info_table_allocated;
3981 /* Number of elements in separate_line_info_table currently in use. */
3982 static GTY(()) unsigned separate_line_info_table_in_use;
3984 /* Size (in elements) of increments by which we may expand the
3986 #define LINE_INFO_TABLE_INCREMENT 1024
3988 /* A pointer to the base of a table that contains a list of publicly
3989 accessible names. */
3990 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3992 /* A pointer to the base of a table that contains a list of publicly
3993 accessible types. */
3994 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3996 /* Array of dies for which we should generate .debug_arange info. */
3997 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3999 /* Number of elements currently allocated for arange_table. */
4000 static GTY(()) unsigned arange_table_allocated;
4002 /* Number of elements in arange_table currently in use. */
4003 static GTY(()) unsigned arange_table_in_use;
4005 /* Size (in elements) of increments by which we may expand the
4007 #define ARANGE_TABLE_INCREMENT 64
4009 /* Array of dies for which we should generate .debug_ranges info. */
4010 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4012 /* Number of elements currently allocated for ranges_table. */
4013 static GTY(()) unsigned ranges_table_allocated;
4015 /* Number of elements in ranges_table currently in use. */
4016 static GTY(()) unsigned ranges_table_in_use;
4018 /* Array of pairs of labels referenced in ranges_table. */
4019 static GTY ((length ("ranges_by_label_allocated")))
4020 dw_ranges_by_label_ref ranges_by_label;
4022 /* Number of elements currently allocated for ranges_by_label. */
4023 static GTY(()) unsigned ranges_by_label_allocated;
4025 /* Number of elements in ranges_by_label currently in use. */
4026 static GTY(()) unsigned ranges_by_label_in_use;
4028 /* Size (in elements) of increments by which we may expand the
4030 #define RANGES_TABLE_INCREMENT 64
4032 /* Whether we have location lists that need outputting */
4033 static GTY(()) bool have_location_lists;
4035 /* Unique label counter. */
4036 static GTY(()) unsigned int loclabel_num;
4038 #ifdef DWARF2_DEBUGGING_INFO
4039 /* Record whether the function being analyzed contains inlined functions. */
4040 static int current_function_has_inlines;
4042 #if 0 && defined (MIPS_DEBUGGING_INFO)
4043 static int comp_unit_has_inlines;
4046 /* The last file entry emitted by maybe_emit_file(). */
4047 static GTY(()) struct dwarf_file_data * last_emitted_file;
4049 /* Number of internal labels generated by gen_internal_sym(). */
4050 static GTY(()) int label_num;
4052 /* Cached result of previous call to lookup_filename. */
4053 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4055 #ifdef DWARF2_DEBUGGING_INFO
4057 /* Offset from the "steady-state frame pointer" to the frame base,
4058 within the current function. */
4059 static HOST_WIDE_INT frame_pointer_fb_offset;
4061 /* Forward declarations for functions defined in this file. */
4063 static int is_pseudo_reg (rtx);
4064 static tree type_main_variant (tree);
4065 static int is_tagged_type (tree);
4066 static const char *dwarf_tag_name (unsigned);
4067 static const char *dwarf_attr_name (unsigned);
4068 static const char *dwarf_form_name (unsigned);
4069 static tree decl_ultimate_origin (tree);
4070 static tree block_ultimate_origin (tree);
4071 static tree decl_class_context (tree);
4072 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4073 static inline enum dw_val_class AT_class (dw_attr_ref);
4074 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4075 static inline unsigned AT_flag (dw_attr_ref);
4076 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4077 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4078 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4079 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4080 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4082 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4083 unsigned int, unsigned char *);
4084 static hashval_t debug_str_do_hash (const void *);
4085 static int debug_str_eq (const void *, const void *);
4086 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4087 static inline const char *AT_string (dw_attr_ref);
4088 static int AT_string_form (dw_attr_ref);
4089 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4090 static void add_AT_specification (dw_die_ref, dw_die_ref);
4091 static inline dw_die_ref AT_ref (dw_attr_ref);
4092 static inline int AT_ref_external (dw_attr_ref);
4093 static inline void set_AT_ref_external (dw_attr_ref, int);
4094 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4095 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4096 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4097 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4099 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4100 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4101 static inline rtx AT_addr (dw_attr_ref);
4102 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4103 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4104 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4105 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4106 unsigned HOST_WIDE_INT);
4107 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4109 static inline const char *AT_lbl (dw_attr_ref);
4110 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4111 static const char *get_AT_low_pc (dw_die_ref);
4112 static const char *get_AT_hi_pc (dw_die_ref);
4113 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4114 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4115 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4116 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4117 static bool is_c_family (void);
4118 static bool is_cxx (void);
4119 static bool is_java (void);
4120 static bool is_fortran (void);
4121 static bool is_ada (void);
4122 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4123 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4124 static void add_child_die (dw_die_ref, dw_die_ref);
4125 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4126 static dw_die_ref lookup_type_die (tree);
4127 static void equate_type_number_to_die (tree, dw_die_ref);
4128 static hashval_t decl_die_table_hash (const void *);
4129 static int decl_die_table_eq (const void *, const void *);
4130 static dw_die_ref lookup_decl_die (tree);
4131 static hashval_t decl_loc_table_hash (const void *);
4132 static int decl_loc_table_eq (const void *, const void *);
4133 static var_loc_list *lookup_decl_loc (tree);
4134 static void equate_decl_number_to_die (tree, dw_die_ref);
4135 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4136 static void print_spaces (FILE *);
4137 static void print_die (dw_die_ref, FILE *);
4138 static void print_dwarf_line_table (FILE *);
4139 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4140 static dw_die_ref pop_compile_unit (dw_die_ref);
4141 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4142 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4143 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4144 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4145 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
4146 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4147 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4148 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4149 static void compute_section_prefix (dw_die_ref);
4150 static int is_type_die (dw_die_ref);
4151 static int is_comdat_die (dw_die_ref);
4152 static int is_symbol_die (dw_die_ref);
4153 static void assign_symbol_names (dw_die_ref);
4154 static void break_out_includes (dw_die_ref);
4155 static hashval_t htab_cu_hash (const void *);
4156 static int htab_cu_eq (const void *, const void *);
4157 static void htab_cu_del (void *);
4158 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4159 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4160 static void add_sibling_attributes (dw_die_ref);
4161 static void build_abbrev_table (dw_die_ref);
4162 static void output_location_lists (dw_die_ref);
4163 static int constant_size (long unsigned);
4164 static unsigned long size_of_die (dw_die_ref);
4165 static void calc_die_sizes (dw_die_ref);
4166 static void mark_dies (dw_die_ref);
4167 static void unmark_dies (dw_die_ref);
4168 static void unmark_all_dies (dw_die_ref);
4169 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4170 static unsigned long size_of_aranges (void);
4171 static enum dwarf_form value_format (dw_attr_ref);
4172 static void output_value_format (dw_attr_ref);
4173 static void output_abbrev_section (void);
4174 static void output_die_symbol (dw_die_ref);
4175 static void output_die (dw_die_ref);
4176 static void output_compilation_unit_header (void);
4177 static void output_comp_unit (dw_die_ref, int);
4178 static const char *dwarf2_name (tree, int);
4179 static void add_pubname (tree, dw_die_ref);
4180 static void add_pubtype (tree, dw_die_ref);
4181 static void output_pubnames (VEC (pubname_entry,gc) *);
4182 static void add_arange (tree, dw_die_ref);
4183 static void output_aranges (void);
4184 static unsigned int add_ranges_num (int);
4185 static unsigned int add_ranges (tree);
4186 static unsigned int add_ranges_by_labels (const char *, const char *);
4187 static void output_ranges (void);
4188 static void output_line_info (void);
4189 static void output_file_names (void);
4190 static dw_die_ref base_type_die (tree);
4191 static int is_base_type (tree);
4192 static bool is_subrange_type (tree);
4193 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4194 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4195 static int type_is_enum (tree);
4196 static unsigned int dbx_reg_number (rtx);
4197 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4198 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4199 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4200 enum var_init_status);
4201 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4202 enum var_init_status);
4203 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4204 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4205 enum var_init_status);
4206 static int is_based_loc (rtx);
4207 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4208 enum var_init_status);
4209 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4210 enum var_init_status);
4211 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4212 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4213 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4214 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4215 static tree field_type (tree);
4216 static unsigned int simple_type_align_in_bits (tree);
4217 static unsigned int simple_decl_align_in_bits (tree);
4218 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
4219 static HOST_WIDE_INT field_byte_offset (tree);
4220 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4222 static void add_data_member_location_attribute (dw_die_ref, tree);
4223 static void add_const_value_attribute (dw_die_ref, rtx);
4224 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4225 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4226 static void insert_float (rtx, unsigned char *);
4227 static rtx rtl_for_decl_location (tree);
4228 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4229 enum dwarf_attribute);
4230 static void tree_add_const_value_attribute (dw_die_ref, tree);
4231 static void add_name_attribute (dw_die_ref, const char *);
4232 static void add_comp_dir_attribute (dw_die_ref);
4233 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4234 static void add_subscript_info (dw_die_ref, tree);
4235 static void add_byte_size_attribute (dw_die_ref, tree);
4236 static void add_bit_offset_attribute (dw_die_ref, tree);
4237 static void add_bit_size_attribute (dw_die_ref, tree);
4238 static void add_prototyped_attribute (dw_die_ref, tree);
4239 static void add_abstract_origin_attribute (dw_die_ref, tree);
4240 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4241 static void add_src_coords_attributes (dw_die_ref, tree);
4242 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4243 static void push_decl_scope (tree);
4244 static void pop_decl_scope (void);
4245 static dw_die_ref scope_die_for (tree, dw_die_ref);
4246 static inline int local_scope_p (dw_die_ref);
4247 static inline int class_or_namespace_scope_p (dw_die_ref);
4248 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4249 static void add_calling_convention_attribute (dw_die_ref, tree);
4250 static const char *type_tag (tree);
4251 static tree member_declared_type (tree);
4253 static const char *decl_start_label (tree);
4255 static void gen_array_type_die (tree, dw_die_ref);
4257 static void gen_entry_point_die (tree, dw_die_ref);
4259 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4260 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4261 static void gen_inlined_union_type_die (tree, dw_die_ref);
4262 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4263 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4264 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4265 static void gen_formal_types_die (tree, dw_die_ref);
4266 static void gen_subprogram_die (tree, dw_die_ref);
4267 static void gen_variable_die (tree, dw_die_ref);
4268 static void gen_label_die (tree, dw_die_ref);
4269 static void gen_lexical_block_die (tree, dw_die_ref, int);
4270 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4271 static void gen_field_die (tree, dw_die_ref);
4272 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4273 static dw_die_ref gen_compile_unit_die (const char *);
4274 static void gen_inheritance_die (tree, tree, dw_die_ref);
4275 static void gen_member_die (tree, dw_die_ref);
4276 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4277 enum debug_info_usage);
4278 static void gen_subroutine_type_die (tree, dw_die_ref);
4279 static void gen_typedef_die (tree, dw_die_ref);
4280 static void gen_type_die (tree, dw_die_ref);
4281 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4282 static void gen_block_die (tree, dw_die_ref, int);
4283 static void decls_for_scope (tree, dw_die_ref, int);
4284 static int is_redundant_typedef (tree);
4285 static void gen_namespace_die (tree);
4286 static void gen_decl_die (tree, dw_die_ref);
4287 static dw_die_ref force_decl_die (tree);
4288 static dw_die_ref force_type_die (tree);
4289 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4290 static void declare_in_namespace (tree, dw_die_ref);
4291 static struct dwarf_file_data * lookup_filename (const char *);
4292 static void retry_incomplete_types (void);
4293 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4294 static void splice_child_die (dw_die_ref, dw_die_ref);
4295 static int file_info_cmp (const void *, const void *);
4296 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4297 const char *, const char *, unsigned);
4298 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4299 const char *, const char *,
4301 static void output_loc_list (dw_loc_list_ref);
4302 static char *gen_internal_sym (const char *);
4304 static void prune_unmark_dies (dw_die_ref);
4305 static void prune_unused_types_mark (dw_die_ref, int);
4306 static void prune_unused_types_walk (dw_die_ref);
4307 static void prune_unused_types_walk_attribs (dw_die_ref);
4308 static void prune_unused_types_prune (dw_die_ref);
4309 static void prune_unused_types (void);
4310 static int maybe_emit_file (struct dwarf_file_data *fd);
4312 /* Section names used to hold DWARF debugging information. */
4313 #ifndef DEBUG_INFO_SECTION
4314 #define DEBUG_INFO_SECTION ".debug_info"
4316 #ifndef DEBUG_ABBREV_SECTION
4317 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4319 #ifndef DEBUG_ARANGES_SECTION
4320 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4322 #ifndef DEBUG_MACINFO_SECTION
4323 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4325 #ifndef DEBUG_LINE_SECTION
4326 #define DEBUG_LINE_SECTION ".debug_line"
4328 #ifndef DEBUG_LOC_SECTION
4329 #define DEBUG_LOC_SECTION ".debug_loc"
4331 #ifndef DEBUG_PUBNAMES_SECTION
4332 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4334 #ifndef DEBUG_STR_SECTION
4335 #define DEBUG_STR_SECTION ".debug_str"
4337 #ifndef DEBUG_RANGES_SECTION
4338 #define DEBUG_RANGES_SECTION ".debug_ranges"
4341 /* Standard ELF section names for compiled code and data. */
4342 #ifndef TEXT_SECTION_NAME
4343 #define TEXT_SECTION_NAME ".text"
4346 /* Section flags for .debug_str section. */
4347 #define DEBUG_STR_SECTION_FLAGS \
4348 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4349 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4352 /* Labels we insert at beginning sections we can reference instead of
4353 the section names themselves. */
4355 #ifndef TEXT_SECTION_LABEL
4356 #define TEXT_SECTION_LABEL "Ltext"
4358 #ifndef COLD_TEXT_SECTION_LABEL
4359 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4361 #ifndef DEBUG_LINE_SECTION_LABEL
4362 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4364 #ifndef DEBUG_INFO_SECTION_LABEL
4365 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4367 #ifndef DEBUG_ABBREV_SECTION_LABEL
4368 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4370 #ifndef DEBUG_LOC_SECTION_LABEL
4371 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4373 #ifndef DEBUG_RANGES_SECTION_LABEL
4374 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4376 #ifndef DEBUG_MACINFO_SECTION_LABEL
4377 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4380 /* Definitions of defaults for formats and names of various special
4381 (artificial) labels which may be generated within this file (when the -g
4382 options is used and DWARF2_DEBUGGING_INFO is in effect.
4383 If necessary, these may be overridden from within the tm.h file, but
4384 typically, overriding these defaults is unnecessary. */
4386 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4387 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4388 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4389 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4390 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4391 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4392 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4393 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4394 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4395 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4397 #ifndef TEXT_END_LABEL
4398 #define TEXT_END_LABEL "Letext"
4400 #ifndef COLD_END_LABEL
4401 #define COLD_END_LABEL "Letext_cold"
4403 #ifndef BLOCK_BEGIN_LABEL
4404 #define BLOCK_BEGIN_LABEL "LBB"
4406 #ifndef BLOCK_END_LABEL
4407 #define BLOCK_END_LABEL "LBE"
4409 #ifndef LINE_CODE_LABEL
4410 #define LINE_CODE_LABEL "LM"
4412 #ifndef SEPARATE_LINE_CODE_LABEL
4413 #define SEPARATE_LINE_CODE_LABEL "LSM"
4416 /* We allow a language front-end to designate a function that is to be
4417 called to "demangle" any name before it is put into a DIE. */
4419 static const char *(*demangle_name_func) (const char *);
4422 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4424 demangle_name_func = func;
4427 /* Test if rtl node points to a pseudo register. */
4430 is_pseudo_reg (rtx rtl)
4432 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4433 || (GET_CODE (rtl) == SUBREG
4434 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4437 /* Return a reference to a type, with its const and volatile qualifiers
4441 type_main_variant (tree type)
4443 type = TYPE_MAIN_VARIANT (type);
4445 /* ??? There really should be only one main variant among any group of
4446 variants of a given type (and all of the MAIN_VARIANT values for all
4447 members of the group should point to that one type) but sometimes the C
4448 front-end messes this up for array types, so we work around that bug
4450 if (TREE_CODE (type) == ARRAY_TYPE)
4451 while (type != TYPE_MAIN_VARIANT (type))
4452 type = TYPE_MAIN_VARIANT (type);
4457 /* Return nonzero if the given type node represents a tagged type. */
4460 is_tagged_type (tree type)
4462 enum tree_code code = TREE_CODE (type);
4464 return (code == RECORD_TYPE || code == UNION_TYPE
4465 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4468 /* Convert a DIE tag into its string name. */
4471 dwarf_tag_name (unsigned int tag)
4475 case DW_TAG_padding:
4476 return "DW_TAG_padding";
4477 case DW_TAG_array_type:
4478 return "DW_TAG_array_type";
4479 case DW_TAG_class_type:
4480 return "DW_TAG_class_type";
4481 case DW_TAG_entry_point:
4482 return "DW_TAG_entry_point";
4483 case DW_TAG_enumeration_type:
4484 return "DW_TAG_enumeration_type";
4485 case DW_TAG_formal_parameter:
4486 return "DW_TAG_formal_parameter";
4487 case DW_TAG_imported_declaration:
4488 return "DW_TAG_imported_declaration";
4490 return "DW_TAG_label";
4491 case DW_TAG_lexical_block:
4492 return "DW_TAG_lexical_block";
4494 return "DW_TAG_member";
4495 case DW_TAG_pointer_type:
4496 return "DW_TAG_pointer_type";
4497 case DW_TAG_reference_type:
4498 return "DW_TAG_reference_type";
4499 case DW_TAG_compile_unit:
4500 return "DW_TAG_compile_unit";
4501 case DW_TAG_string_type:
4502 return "DW_TAG_string_type";
4503 case DW_TAG_structure_type:
4504 return "DW_TAG_structure_type";
4505 case DW_TAG_subroutine_type:
4506 return "DW_TAG_subroutine_type";
4507 case DW_TAG_typedef:
4508 return "DW_TAG_typedef";
4509 case DW_TAG_union_type:
4510 return "DW_TAG_union_type";
4511 case DW_TAG_unspecified_parameters:
4512 return "DW_TAG_unspecified_parameters";
4513 case DW_TAG_variant:
4514 return "DW_TAG_variant";
4515 case DW_TAG_common_block:
4516 return "DW_TAG_common_block";
4517 case DW_TAG_common_inclusion:
4518 return "DW_TAG_common_inclusion";
4519 case DW_TAG_inheritance:
4520 return "DW_TAG_inheritance";
4521 case DW_TAG_inlined_subroutine:
4522 return "DW_TAG_inlined_subroutine";
4524 return "DW_TAG_module";
4525 case DW_TAG_ptr_to_member_type:
4526 return "DW_TAG_ptr_to_member_type";
4527 case DW_TAG_set_type:
4528 return "DW_TAG_set_type";
4529 case DW_TAG_subrange_type:
4530 return "DW_TAG_subrange_type";
4531 case DW_TAG_with_stmt:
4532 return "DW_TAG_with_stmt";
4533 case DW_TAG_access_declaration:
4534 return "DW_TAG_access_declaration";
4535 case DW_TAG_base_type:
4536 return "DW_TAG_base_type";
4537 case DW_TAG_catch_block:
4538 return "DW_TAG_catch_block";
4539 case DW_TAG_const_type:
4540 return "DW_TAG_const_type";
4541 case DW_TAG_constant:
4542 return "DW_TAG_constant";
4543 case DW_TAG_enumerator:
4544 return "DW_TAG_enumerator";
4545 case DW_TAG_file_type:
4546 return "DW_TAG_file_type";
4548 return "DW_TAG_friend";
4549 case DW_TAG_namelist:
4550 return "DW_TAG_namelist";
4551 case DW_TAG_namelist_item:
4552 return "DW_TAG_namelist_item";
4553 case DW_TAG_namespace:
4554 return "DW_TAG_namespace";
4555 case DW_TAG_packed_type:
4556 return "DW_TAG_packed_type";
4557 case DW_TAG_subprogram:
4558 return "DW_TAG_subprogram";
4559 case DW_TAG_template_type_param:
4560 return "DW_TAG_template_type_param";
4561 case DW_TAG_template_value_param:
4562 return "DW_TAG_template_value_param";
4563 case DW_TAG_thrown_type:
4564 return "DW_TAG_thrown_type";
4565 case DW_TAG_try_block:
4566 return "DW_TAG_try_block";
4567 case DW_TAG_variant_part:
4568 return "DW_TAG_variant_part";
4569 case DW_TAG_variable:
4570 return "DW_TAG_variable";
4571 case DW_TAG_volatile_type:
4572 return "DW_TAG_volatile_type";
4573 case DW_TAG_imported_module:
4574 return "DW_TAG_imported_module";
4575 case DW_TAG_MIPS_loop:
4576 return "DW_TAG_MIPS_loop";
4577 case DW_TAG_format_label:
4578 return "DW_TAG_format_label";
4579 case DW_TAG_function_template:
4580 return "DW_TAG_function_template";
4581 case DW_TAG_class_template:
4582 return "DW_TAG_class_template";
4583 case DW_TAG_GNU_BINCL:
4584 return "DW_TAG_GNU_BINCL";
4585 case DW_TAG_GNU_EINCL:
4586 return "DW_TAG_GNU_EINCL";
4588 return "DW_TAG_<unknown>";
4592 /* Convert a DWARF attribute code into its string name. */
4595 dwarf_attr_name (unsigned int attr)
4600 return "DW_AT_sibling";
4601 case DW_AT_location:
4602 return "DW_AT_location";
4604 return "DW_AT_name";
4605 case DW_AT_ordering:
4606 return "DW_AT_ordering";
4607 case DW_AT_subscr_data:
4608 return "DW_AT_subscr_data";
4609 case DW_AT_byte_size:
4610 return "DW_AT_byte_size";
4611 case DW_AT_bit_offset:
4612 return "DW_AT_bit_offset";
4613 case DW_AT_bit_size:
4614 return "DW_AT_bit_size";
4615 case DW_AT_element_list:
4616 return "DW_AT_element_list";
4617 case DW_AT_stmt_list:
4618 return "DW_AT_stmt_list";
4620 return "DW_AT_low_pc";
4622 return "DW_AT_high_pc";
4623 case DW_AT_language:
4624 return "DW_AT_language";
4626 return "DW_AT_member";
4628 return "DW_AT_discr";
4629 case DW_AT_discr_value:
4630 return "DW_AT_discr_value";
4631 case DW_AT_visibility:
4632 return "DW_AT_visibility";
4634 return "DW_AT_import";
4635 case DW_AT_string_length:
4636 return "DW_AT_string_length";
4637 case DW_AT_common_reference:
4638 return "DW_AT_common_reference";
4639 case DW_AT_comp_dir:
4640 return "DW_AT_comp_dir";
4641 case DW_AT_const_value:
4642 return "DW_AT_const_value";
4643 case DW_AT_containing_type:
4644 return "DW_AT_containing_type";
4645 case DW_AT_default_value:
4646 return "DW_AT_default_value";
4648 return "DW_AT_inline";
4649 case DW_AT_is_optional:
4650 return "DW_AT_is_optional";
4651 case DW_AT_lower_bound:
4652 return "DW_AT_lower_bound";
4653 case DW_AT_producer:
4654 return "DW_AT_producer";
4655 case DW_AT_prototyped:
4656 return "DW_AT_prototyped";
4657 case DW_AT_return_addr:
4658 return "DW_AT_return_addr";
4659 case DW_AT_start_scope:
4660 return "DW_AT_start_scope";
4661 case DW_AT_stride_size:
4662 return "DW_AT_stride_size";
4663 case DW_AT_upper_bound:
4664 return "DW_AT_upper_bound";
4665 case DW_AT_abstract_origin:
4666 return "DW_AT_abstract_origin";
4667 case DW_AT_accessibility:
4668 return "DW_AT_accessibility";
4669 case DW_AT_address_class:
4670 return "DW_AT_address_class";
4671 case DW_AT_artificial:
4672 return "DW_AT_artificial";
4673 case DW_AT_base_types:
4674 return "DW_AT_base_types";
4675 case DW_AT_calling_convention:
4676 return "DW_AT_calling_convention";
4678 return "DW_AT_count";
4679 case DW_AT_data_member_location:
4680 return "DW_AT_data_member_location";
4681 case DW_AT_decl_column:
4682 return "DW_AT_decl_column";
4683 case DW_AT_decl_file:
4684 return "DW_AT_decl_file";
4685 case DW_AT_decl_line:
4686 return "DW_AT_decl_line";
4687 case DW_AT_declaration:
4688 return "DW_AT_declaration";
4689 case DW_AT_discr_list:
4690 return "DW_AT_discr_list";
4691 case DW_AT_encoding:
4692 return "DW_AT_encoding";
4693 case DW_AT_external:
4694 return "DW_AT_external";
4695 case DW_AT_frame_base:
4696 return "DW_AT_frame_base";
4698 return "DW_AT_friend";
4699 case DW_AT_identifier_case:
4700 return "DW_AT_identifier_case";
4701 case DW_AT_macro_info:
4702 return "DW_AT_macro_info";
4703 case DW_AT_namelist_items:
4704 return "DW_AT_namelist_items";
4705 case DW_AT_priority:
4706 return "DW_AT_priority";
4708 return "DW_AT_segment";
4709 case DW_AT_specification:
4710 return "DW_AT_specification";
4711 case DW_AT_static_link:
4712 return "DW_AT_static_link";
4714 return "DW_AT_type";
4715 case DW_AT_use_location:
4716 return "DW_AT_use_location";
4717 case DW_AT_variable_parameter:
4718 return "DW_AT_variable_parameter";
4719 case DW_AT_virtuality:
4720 return "DW_AT_virtuality";
4721 case DW_AT_vtable_elem_location:
4722 return "DW_AT_vtable_elem_location";
4724 case DW_AT_allocated:
4725 return "DW_AT_allocated";
4726 case DW_AT_associated:
4727 return "DW_AT_associated";
4728 case DW_AT_data_location:
4729 return "DW_AT_data_location";
4731 return "DW_AT_stride";
4732 case DW_AT_entry_pc:
4733 return "DW_AT_entry_pc";
4734 case DW_AT_use_UTF8:
4735 return "DW_AT_use_UTF8";
4736 case DW_AT_extension:
4737 return "DW_AT_extension";
4739 return "DW_AT_ranges";
4740 case DW_AT_trampoline:
4741 return "DW_AT_trampoline";
4742 case DW_AT_call_column:
4743 return "DW_AT_call_column";
4744 case DW_AT_call_file:
4745 return "DW_AT_call_file";
4746 case DW_AT_call_line:
4747 return "DW_AT_call_line";
4749 case DW_AT_MIPS_fde:
4750 return "DW_AT_MIPS_fde";
4751 case DW_AT_MIPS_loop_begin:
4752 return "DW_AT_MIPS_loop_begin";
4753 case DW_AT_MIPS_tail_loop_begin:
4754 return "DW_AT_MIPS_tail_loop_begin";
4755 case DW_AT_MIPS_epilog_begin:
4756 return "DW_AT_MIPS_epilog_begin";
4757 case DW_AT_MIPS_loop_unroll_factor:
4758 return "DW_AT_MIPS_loop_unroll_factor";
4759 case DW_AT_MIPS_software_pipeline_depth:
4760 return "DW_AT_MIPS_software_pipeline_depth";
4761 case DW_AT_MIPS_linkage_name:
4762 return "DW_AT_MIPS_linkage_name";
4763 case DW_AT_MIPS_stride:
4764 return "DW_AT_MIPS_stride";
4765 case DW_AT_MIPS_abstract_name:
4766 return "DW_AT_MIPS_abstract_name";
4767 case DW_AT_MIPS_clone_origin:
4768 return "DW_AT_MIPS_clone_origin";
4769 case DW_AT_MIPS_has_inlines:
4770 return "DW_AT_MIPS_has_inlines";
4772 case DW_AT_sf_names:
4773 return "DW_AT_sf_names";
4774 case DW_AT_src_info:
4775 return "DW_AT_src_info";
4776 case DW_AT_mac_info:
4777 return "DW_AT_mac_info";
4778 case DW_AT_src_coords:
4779 return "DW_AT_src_coords";
4780 case DW_AT_body_begin:
4781 return "DW_AT_body_begin";
4782 case DW_AT_body_end:
4783 return "DW_AT_body_end";
4784 case DW_AT_GNU_vector:
4785 return "DW_AT_GNU_vector";
4787 case DW_AT_VMS_rtnbeg_pd_address:
4788 return "DW_AT_VMS_rtnbeg_pd_address";
4791 return "DW_AT_<unknown>";
4795 /* Convert a DWARF value form code into its string name. */
4798 dwarf_form_name (unsigned int form)
4803 return "DW_FORM_addr";
4804 case DW_FORM_block2:
4805 return "DW_FORM_block2";
4806 case DW_FORM_block4:
4807 return "DW_FORM_block4";
4809 return "DW_FORM_data2";
4811 return "DW_FORM_data4";
4813 return "DW_FORM_data8";
4814 case DW_FORM_string:
4815 return "DW_FORM_string";
4817 return "DW_FORM_block";
4818 case DW_FORM_block1:
4819 return "DW_FORM_block1";
4821 return "DW_FORM_data1";
4823 return "DW_FORM_flag";
4825 return "DW_FORM_sdata";
4827 return "DW_FORM_strp";
4829 return "DW_FORM_udata";
4830 case DW_FORM_ref_addr:
4831 return "DW_FORM_ref_addr";
4833 return "DW_FORM_ref1";
4835 return "DW_FORM_ref2";
4837 return "DW_FORM_ref4";
4839 return "DW_FORM_ref8";
4840 case DW_FORM_ref_udata:
4841 return "DW_FORM_ref_udata";
4842 case DW_FORM_indirect:
4843 return "DW_FORM_indirect";
4845 return "DW_FORM_<unknown>";
4849 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4850 instance of an inlined instance of a decl which is local to an inline
4851 function, so we have to trace all of the way back through the origin chain
4852 to find out what sort of node actually served as the original seed for the
4856 decl_ultimate_origin (tree decl)
4858 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4861 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4862 nodes in the function to point to themselves; ignore that if
4863 we're trying to output the abstract instance of this function. */
4864 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4867 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4868 most distant ancestor, this should never happen. */
4869 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4871 return DECL_ABSTRACT_ORIGIN (decl);
4874 /* Determine the "ultimate origin" of a block. The block may be an inlined
4875 instance of an inlined instance of a block which is local to an inline
4876 function, so we have to trace all of the way back through the origin chain
4877 to find out what sort of node actually served as the original seed for the
4881 block_ultimate_origin (tree block)
4883 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4885 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4886 nodes in the function to point to themselves; ignore that if
4887 we're trying to output the abstract instance of this function. */
4888 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4891 if (immediate_origin == NULL_TREE)
4896 tree lookahead = immediate_origin;
4900 ret_val = lookahead;
4901 lookahead = (TREE_CODE (ret_val) == BLOCK
4902 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4904 while (lookahead != NULL && lookahead != ret_val);
4906 /* The block's abstract origin chain may not be the *ultimate* origin of
4907 the block. It could lead to a DECL that has an abstract origin set.
4908 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4909 will give us if it has one). Note that DECL's abstract origins are
4910 supposed to be the most distant ancestor (or so decl_ultimate_origin
4911 claims), so we don't need to loop following the DECL origins. */
4912 if (DECL_P (ret_val))
4913 return DECL_ORIGIN (ret_val);
4919 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4920 of a virtual function may refer to a base class, so we check the 'this'
4924 decl_class_context (tree decl)
4926 tree context = NULL_TREE;
4928 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4929 context = DECL_CONTEXT (decl);
4931 context = TYPE_MAIN_VARIANT
4932 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4934 if (context && !TYPE_P (context))
4935 context = NULL_TREE;
4940 /* Add an attribute/value pair to a DIE. */
4943 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4945 /* Maybe this should be an assert? */
4949 if (die->die_attr == NULL)
4950 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4951 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4954 static inline enum dw_val_class
4955 AT_class (dw_attr_ref a)
4957 return a->dw_attr_val.val_class;
4960 /* Add a flag value attribute to a DIE. */
4963 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4967 attr.dw_attr = attr_kind;
4968 attr.dw_attr_val.val_class = dw_val_class_flag;
4969 attr.dw_attr_val.v.val_flag = flag;
4970 add_dwarf_attr (die, &attr);
4973 static inline unsigned
4974 AT_flag (dw_attr_ref a)
4976 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4977 return a->dw_attr_val.v.val_flag;
4980 /* Add a signed integer attribute value to a DIE. */
4983 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4987 attr.dw_attr = attr_kind;
4988 attr.dw_attr_val.val_class = dw_val_class_const;
4989 attr.dw_attr_val.v.val_int = int_val;
4990 add_dwarf_attr (die, &attr);
4993 static inline HOST_WIDE_INT
4994 AT_int (dw_attr_ref a)
4996 gcc_assert (a && AT_class (a) == dw_val_class_const);
4997 return a->dw_attr_val.v.val_int;
5000 /* Add an unsigned integer attribute value to a DIE. */
5003 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5004 unsigned HOST_WIDE_INT unsigned_val)
5008 attr.dw_attr = attr_kind;
5009 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5010 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5011 add_dwarf_attr (die, &attr);
5014 static inline unsigned HOST_WIDE_INT
5015 AT_unsigned (dw_attr_ref a)
5017 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5018 return a->dw_attr_val.v.val_unsigned;
5021 /* Add an unsigned double integer attribute value to a DIE. */
5024 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5025 long unsigned int val_hi, long unsigned int val_low)
5029 attr.dw_attr = attr_kind;
5030 attr.dw_attr_val.val_class = dw_val_class_long_long;
5031 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5032 attr.dw_attr_val.v.val_long_long.low = val_low;
5033 add_dwarf_attr (die, &attr);
5036 /* Add a floating point attribute value to a DIE and return it. */
5039 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5040 unsigned int length, unsigned int elt_size, unsigned char *array)
5044 attr.dw_attr = attr_kind;
5045 attr.dw_attr_val.val_class = dw_val_class_vec;
5046 attr.dw_attr_val.v.val_vec.length = length;
5047 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5048 attr.dw_attr_val.v.val_vec.array = array;
5049 add_dwarf_attr (die, &attr);
5052 /* Hash and equality functions for debug_str_hash. */
5055 debug_str_do_hash (const void *x)
5057 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5061 debug_str_eq (const void *x1, const void *x2)
5063 return strcmp ((((const struct indirect_string_node *)x1)->str),
5064 (const char *)x2) == 0;
5067 /* Add a string attribute value to a DIE. */
5070 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5073 struct indirect_string_node *node;
5076 if (! debug_str_hash)
5077 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5078 debug_str_eq, NULL);
5080 slot = htab_find_slot_with_hash (debug_str_hash, str,
5081 htab_hash_string (str), INSERT);
5084 node = (struct indirect_string_node *)
5085 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5086 node->str = ggc_strdup (str);
5090 node = (struct indirect_string_node *) *slot;
5094 attr.dw_attr = attr_kind;
5095 attr.dw_attr_val.val_class = dw_val_class_str;
5096 attr.dw_attr_val.v.val_str = node;
5097 add_dwarf_attr (die, &attr);
5100 static inline const char *
5101 AT_string (dw_attr_ref a)
5103 gcc_assert (a && AT_class (a) == dw_val_class_str);
5104 return a->dw_attr_val.v.val_str->str;
5107 /* Find out whether a string should be output inline in DIE
5108 or out-of-line in .debug_str section. */
5111 AT_string_form (dw_attr_ref a)
5113 struct indirect_string_node *node;
5117 gcc_assert (a && AT_class (a) == dw_val_class_str);
5119 node = a->dw_attr_val.v.val_str;
5123 len = strlen (node->str) + 1;
5125 /* If the string is shorter or equal to the size of the reference, it is
5126 always better to put it inline. */
5127 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5128 return node->form = DW_FORM_string;
5130 /* If we cannot expect the linker to merge strings in .debug_str
5131 section, only put it into .debug_str if it is worth even in this
5133 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5134 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5135 return node->form = DW_FORM_string;
5137 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5138 ++dw2_string_counter;
5139 node->label = xstrdup (label);
5141 return node->form = DW_FORM_strp;
5144 /* Add a DIE reference attribute value to a DIE. */
5147 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5151 attr.dw_attr = attr_kind;
5152 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5153 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5154 attr.dw_attr_val.v.val_die_ref.external = 0;
5155 add_dwarf_attr (die, &attr);
5158 /* Add an AT_specification attribute to a DIE, and also make the back
5159 pointer from the specification to the definition. */
5162 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5164 add_AT_die_ref (die, DW_AT_specification, targ_die);
5165 gcc_assert (!targ_die->die_definition);
5166 targ_die->die_definition = die;
5169 static inline dw_die_ref
5170 AT_ref (dw_attr_ref a)
5172 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5173 return a->dw_attr_val.v.val_die_ref.die;
5177 AT_ref_external (dw_attr_ref a)
5179 if (a && AT_class (a) == dw_val_class_die_ref)
5180 return a->dw_attr_val.v.val_die_ref.external;
5186 set_AT_ref_external (dw_attr_ref a, int i)
5188 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5189 a->dw_attr_val.v.val_die_ref.external = i;
5192 /* Add an FDE reference attribute value to a DIE. */
5195 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5199 attr.dw_attr = attr_kind;
5200 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5201 attr.dw_attr_val.v.val_fde_index = targ_fde;
5202 add_dwarf_attr (die, &attr);
5205 /* Add a location description attribute value to a DIE. */
5208 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5212 attr.dw_attr = attr_kind;
5213 attr.dw_attr_val.val_class = dw_val_class_loc;
5214 attr.dw_attr_val.v.val_loc = loc;
5215 add_dwarf_attr (die, &attr);
5218 static inline dw_loc_descr_ref
5219 AT_loc (dw_attr_ref a)
5221 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5222 return a->dw_attr_val.v.val_loc;
5226 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5230 attr.dw_attr = attr_kind;
5231 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5232 attr.dw_attr_val.v.val_loc_list = loc_list;
5233 add_dwarf_attr (die, &attr);
5234 have_location_lists = true;
5237 static inline dw_loc_list_ref
5238 AT_loc_list (dw_attr_ref a)
5240 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5241 return a->dw_attr_val.v.val_loc_list;
5244 /* Add an address constant attribute value to a DIE. */
5247 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5251 attr.dw_attr = attr_kind;
5252 attr.dw_attr_val.val_class = dw_val_class_addr;
5253 attr.dw_attr_val.v.val_addr = addr;
5254 add_dwarf_attr (die, &attr);
5257 /* Get the RTX from to an address DIE attribute. */
5260 AT_addr (dw_attr_ref a)
5262 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5263 return a->dw_attr_val.v.val_addr;
5266 /* Add a file attribute value to a DIE. */
5269 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5270 struct dwarf_file_data *fd)
5274 attr.dw_attr = attr_kind;
5275 attr.dw_attr_val.val_class = dw_val_class_file;
5276 attr.dw_attr_val.v.val_file = fd;
5277 add_dwarf_attr (die, &attr);
5280 /* Get the dwarf_file_data from a file DIE attribute. */
5282 static inline struct dwarf_file_data *
5283 AT_file (dw_attr_ref a)
5285 gcc_assert (a && AT_class (a) == dw_val_class_file);
5286 return a->dw_attr_val.v.val_file;
5289 /* Add a label identifier attribute value to a DIE. */
5292 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5296 attr.dw_attr = attr_kind;
5297 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5298 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5299 add_dwarf_attr (die, &attr);
5302 /* Add a section offset attribute value to a DIE, an offset into the
5303 debug_line section. */
5306 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5311 attr.dw_attr = attr_kind;
5312 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5313 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5314 add_dwarf_attr (die, &attr);
5317 /* Add a section offset attribute value to a DIE, an offset into the
5318 debug_macinfo section. */
5321 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5326 attr.dw_attr = attr_kind;
5327 attr.dw_attr_val.val_class = dw_val_class_macptr;
5328 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5329 add_dwarf_attr (die, &attr);
5332 /* Add an offset attribute value to a DIE. */
5335 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5336 unsigned HOST_WIDE_INT offset)
5340 attr.dw_attr = attr_kind;
5341 attr.dw_attr_val.val_class = dw_val_class_offset;
5342 attr.dw_attr_val.v.val_offset = offset;
5343 add_dwarf_attr (die, &attr);
5346 /* Add an range_list attribute value to a DIE. */
5349 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5350 long unsigned int offset)
5354 attr.dw_attr = attr_kind;
5355 attr.dw_attr_val.val_class = dw_val_class_range_list;
5356 attr.dw_attr_val.v.val_offset = offset;
5357 add_dwarf_attr (die, &attr);
5360 static inline const char *
5361 AT_lbl (dw_attr_ref a)
5363 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5364 || AT_class (a) == dw_val_class_lineptr
5365 || AT_class (a) == dw_val_class_macptr));
5366 return a->dw_attr_val.v.val_lbl_id;
5369 /* Get the attribute of type attr_kind. */
5372 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5376 dw_die_ref spec = NULL;
5381 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5382 if (a->dw_attr == attr_kind)
5384 else if (a->dw_attr == DW_AT_specification
5385 || a->dw_attr == DW_AT_abstract_origin)
5389 return get_AT (spec, attr_kind);
5394 /* Return the "low pc" attribute value, typically associated with a subprogram
5395 DIE. Return null if the "low pc" attribute is either not present, or if it
5396 cannot be represented as an assembler label identifier. */
5398 static inline const char *
5399 get_AT_low_pc (dw_die_ref die)
5401 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5403 return a ? AT_lbl (a) : NULL;
5406 /* Return the "high pc" attribute value, typically associated with a subprogram
5407 DIE. Return null if the "high 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_hi_pc (dw_die_ref die)
5413 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5415 return a ? AT_lbl (a) : NULL;
5418 /* Return the value of the string attribute designated by ATTR_KIND, or
5419 NULL if it is not present. */
5421 static inline const char *
5422 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5424 dw_attr_ref a = get_AT (die, attr_kind);
5426 return a ? AT_string (a) : NULL;
5429 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5430 if it is not present. */
5433 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5435 dw_attr_ref a = get_AT (die, attr_kind);
5437 return a ? AT_flag (a) : 0;
5440 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5441 if it is not present. */
5443 static inline unsigned
5444 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5446 dw_attr_ref a = get_AT (die, attr_kind);
5448 return a ? AT_unsigned (a) : 0;
5451 static inline dw_die_ref
5452 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5454 dw_attr_ref a = get_AT (die, attr_kind);
5456 return a ? AT_ref (a) : NULL;
5459 static inline struct dwarf_file_data *
5460 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5462 dw_attr_ref a = get_AT (die, attr_kind);
5464 return a ? AT_file (a) : NULL;
5467 /* Return TRUE if the language is C or C++. */
5472 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5474 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5475 || lang == DW_LANG_C99
5476 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5479 /* Return TRUE if the language is C++. */
5484 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5486 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5489 /* Return TRUE if the language is Fortran. */
5494 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5496 return (lang == DW_LANG_Fortran77
5497 || lang == DW_LANG_Fortran90
5498 || lang == DW_LANG_Fortran95);
5501 /* Return TRUE if the language is Java. */
5506 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5508 return lang == DW_LANG_Java;
5511 /* Return TRUE if the language is Ada. */
5516 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5518 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5521 /* Remove the specified attribute if present. */
5524 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5532 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5533 if (a->dw_attr == attr_kind)
5535 if (AT_class (a) == dw_val_class_str)
5536 if (a->dw_attr_val.v.val_str->refcount)
5537 a->dw_attr_val.v.val_str->refcount--;
5539 /* VEC_ordered_remove should help reduce the number of abbrevs
5541 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5546 /* Remove CHILD from its parent. PREV must have the property that
5547 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5550 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5552 gcc_assert (child->die_parent == prev->die_parent);
5553 gcc_assert (prev->die_sib == child);
5556 gcc_assert (child->die_parent->die_child == child);
5560 prev->die_sib = child->die_sib;
5561 if (child->die_parent->die_child == child)
5562 child->die_parent->die_child = prev;
5565 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5569 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5575 dw_die_ref prev = c;
5577 while (c->die_tag == tag)
5579 remove_child_with_prev (c, prev);
5580 /* Might have removed every child. */
5581 if (c == c->die_sib)
5585 } while (c != die->die_child);
5588 /* Add a CHILD_DIE as the last child of DIE. */
5591 add_child_die (dw_die_ref die, dw_die_ref child_die)
5593 /* FIXME this should probably be an assert. */
5594 if (! die || ! child_die)
5596 gcc_assert (die != child_die);
5598 child_die->die_parent = die;
5601 child_die->die_sib = die->die_child->die_sib;
5602 die->die_child->die_sib = child_die;
5605 child_die->die_sib = child_die;
5606 die->die_child = child_die;
5609 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5610 is the specification, to the end of PARENT's list of children.
5611 This is done by removing and re-adding it. */
5614 splice_child_die (dw_die_ref parent, dw_die_ref child)
5618 /* We want the declaration DIE from inside the class, not the
5619 specification DIE at toplevel. */
5620 if (child->die_parent != parent)
5622 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5628 gcc_assert (child->die_parent == parent
5629 || (child->die_parent
5630 == get_AT_ref (parent, DW_AT_specification)));
5632 for (p = child->die_parent->die_child; ; p = p->die_sib)
5633 if (p->die_sib == child)
5635 remove_child_with_prev (child, p);
5639 add_child_die (parent, child);
5642 /* Return a pointer to a newly created DIE node. */
5644 static inline dw_die_ref
5645 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5647 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5649 die->die_tag = tag_value;
5651 if (parent_die != NULL)
5652 add_child_die (parent_die, die);
5655 limbo_die_node *limbo_node;
5657 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5658 limbo_node->die = die;
5659 limbo_node->created_for = t;
5660 limbo_node->next = limbo_die_list;
5661 limbo_die_list = limbo_node;
5667 /* Return the DIE associated with the given type specifier. */
5669 static inline dw_die_ref
5670 lookup_type_die (tree type)
5672 return TYPE_SYMTAB_DIE (type);
5675 /* Equate a DIE to a given type specifier. */
5678 equate_type_number_to_die (tree type, dw_die_ref type_die)
5680 TYPE_SYMTAB_DIE (type) = type_die;
5683 /* Returns a hash value for X (which really is a die_struct). */
5686 decl_die_table_hash (const void *x)
5688 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5691 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5694 decl_die_table_eq (const void *x, const void *y)
5696 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5699 /* Return the DIE associated with a given declaration. */
5701 static inline dw_die_ref
5702 lookup_decl_die (tree decl)
5704 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5707 /* Returns a hash value for X (which really is a var_loc_list). */
5710 decl_loc_table_hash (const void *x)
5712 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5715 /* Return nonzero if decl_id of var_loc_list X is the same as
5719 decl_loc_table_eq (const void *x, const void *y)
5721 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5724 /* Return the var_loc list associated with a given declaration. */
5726 static inline var_loc_list *
5727 lookup_decl_loc (tree decl)
5729 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5732 /* Equate a DIE to a particular declaration. */
5735 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5737 unsigned int decl_id = DECL_UID (decl);
5740 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5742 decl_die->decl_id = decl_id;
5745 /* Add a variable location node to the linked list for DECL. */
5748 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5750 unsigned int decl_id = DECL_UID (decl);
5754 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5757 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5758 temp->decl_id = decl_id;
5766 /* If the current location is the same as the end of the list,
5767 and either both or neither of the locations is uninitialized,
5768 we have nothing to do. */
5769 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5770 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5771 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5772 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
5773 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5774 == VAR_INIT_STATUS_UNINITIALIZED)
5775 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
5776 == VAR_INIT_STATUS_UNINITIALIZED))))
5778 /* Add LOC to the end of list and update LAST. */
5779 temp->last->next = loc;
5783 /* Do not add empty location to the beginning of the list. */
5784 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5791 /* Keep track of the number of spaces used to indent the
5792 output of the debugging routines that print the structure of
5793 the DIE internal representation. */
5794 static int print_indent;
5796 /* Indent the line the number of spaces given by print_indent. */
5799 print_spaces (FILE *outfile)
5801 fprintf (outfile, "%*s", print_indent, "");
5804 /* Print the information associated with a given DIE, and its children.
5805 This routine is a debugging aid only. */
5808 print_die (dw_die_ref die, FILE *outfile)
5814 print_spaces (outfile);
5815 fprintf (outfile, "DIE %4ld: %s\n",
5816 die->die_offset, dwarf_tag_name (die->die_tag));
5817 print_spaces (outfile);
5818 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5819 fprintf (outfile, " offset: %ld\n", die->die_offset);
5821 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5823 print_spaces (outfile);
5824 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5826 switch (AT_class (a))
5828 case dw_val_class_addr:
5829 fprintf (outfile, "address");
5831 case dw_val_class_offset:
5832 fprintf (outfile, "offset");
5834 case dw_val_class_loc:
5835 fprintf (outfile, "location descriptor");
5837 case dw_val_class_loc_list:
5838 fprintf (outfile, "location list -> label:%s",
5839 AT_loc_list (a)->ll_symbol);
5841 case dw_val_class_range_list:
5842 fprintf (outfile, "range list");
5844 case dw_val_class_const:
5845 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5847 case dw_val_class_unsigned_const:
5848 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5850 case dw_val_class_long_long:
5851 fprintf (outfile, "constant (%lu,%lu)",
5852 a->dw_attr_val.v.val_long_long.hi,
5853 a->dw_attr_val.v.val_long_long.low);
5855 case dw_val_class_vec:
5856 fprintf (outfile, "floating-point or vector constant");
5858 case dw_val_class_flag:
5859 fprintf (outfile, "%u", AT_flag (a));
5861 case dw_val_class_die_ref:
5862 if (AT_ref (a) != NULL)
5864 if (AT_ref (a)->die_symbol)
5865 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5867 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5870 fprintf (outfile, "die -> <null>");
5872 case dw_val_class_lbl_id:
5873 case dw_val_class_lineptr:
5874 case dw_val_class_macptr:
5875 fprintf (outfile, "label: %s", AT_lbl (a));
5877 case dw_val_class_str:
5878 if (AT_string (a) != NULL)
5879 fprintf (outfile, "\"%s\"", AT_string (a));
5881 fprintf (outfile, "<null>");
5883 case dw_val_class_file:
5884 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5885 AT_file (a)->emitted_number);
5891 fprintf (outfile, "\n");
5894 if (die->die_child != NULL)
5897 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5900 if (print_indent == 0)
5901 fprintf (outfile, "\n");
5904 /* Print the contents of the source code line number correspondence table.
5905 This routine is a debugging aid only. */
5908 print_dwarf_line_table (FILE *outfile)
5911 dw_line_info_ref line_info;
5913 fprintf (outfile, "\n\nDWARF source line information\n");
5914 for (i = 1; i < line_info_table_in_use; i++)
5916 line_info = &line_info_table[i];
5917 fprintf (outfile, "%5d: %4ld %6ld\n", i,
5918 line_info->dw_file_num,
5919 line_info->dw_line_num);
5922 fprintf (outfile, "\n\n");
5925 /* Print the information collected for a given DIE. */
5928 debug_dwarf_die (dw_die_ref die)
5930 print_die (die, stderr);
5933 /* Print all DWARF information collected for the compilation unit.
5934 This routine is a debugging aid only. */
5940 print_die (comp_unit_die, stderr);
5941 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5942 print_dwarf_line_table (stderr);
5945 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5946 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5947 DIE that marks the start of the DIEs for this include file. */
5950 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5952 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5953 dw_die_ref new_unit = gen_compile_unit_die (filename);
5955 new_unit->die_sib = old_unit;
5959 /* Close an include-file CU and reopen the enclosing one. */
5962 pop_compile_unit (dw_die_ref old_unit)
5964 dw_die_ref new_unit = old_unit->die_sib;
5966 old_unit->die_sib = NULL;
5970 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5971 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5973 /* Calculate the checksum of a location expression. */
5976 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5978 CHECKSUM (loc->dw_loc_opc);
5979 CHECKSUM (loc->dw_loc_oprnd1);
5980 CHECKSUM (loc->dw_loc_oprnd2);
5983 /* Calculate the checksum of an attribute. */
5986 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5988 dw_loc_descr_ref loc;
5991 CHECKSUM (at->dw_attr);
5993 /* We don't care that this was compiled with a different compiler
5994 snapshot; if the output is the same, that's what matters. */
5995 if (at->dw_attr == DW_AT_producer)
5998 switch (AT_class (at))
6000 case dw_val_class_const:
6001 CHECKSUM (at->dw_attr_val.v.val_int);
6003 case dw_val_class_unsigned_const:
6004 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6006 case dw_val_class_long_long:
6007 CHECKSUM (at->dw_attr_val.v.val_long_long);
6009 case dw_val_class_vec:
6010 CHECKSUM (at->dw_attr_val.v.val_vec);
6012 case dw_val_class_flag:
6013 CHECKSUM (at->dw_attr_val.v.val_flag);
6015 case dw_val_class_str:
6016 CHECKSUM_STRING (AT_string (at));
6019 case dw_val_class_addr:
6021 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6022 CHECKSUM_STRING (XSTR (r, 0));
6025 case dw_val_class_offset:
6026 CHECKSUM (at->dw_attr_val.v.val_offset);
6029 case dw_val_class_loc:
6030 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6031 loc_checksum (loc, ctx);
6034 case dw_val_class_die_ref:
6035 die_checksum (AT_ref (at), ctx, mark);
6038 case dw_val_class_fde_ref:
6039 case dw_val_class_lbl_id:
6040 case dw_val_class_lineptr:
6041 case dw_val_class_macptr:
6044 case dw_val_class_file:
6045 CHECKSUM_STRING (AT_file (at)->filename);
6053 /* Calculate the checksum of a DIE. */
6056 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6062 /* To avoid infinite recursion. */
6065 CHECKSUM (die->die_mark);
6068 die->die_mark = ++(*mark);
6070 CHECKSUM (die->die_tag);
6072 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6073 attr_checksum (a, ctx, mark);
6075 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6079 #undef CHECKSUM_STRING
6081 /* Do the location expressions look same? */
6083 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6085 return loc1->dw_loc_opc == loc2->dw_loc_opc
6086 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6087 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6090 /* Do the values look the same? */
6092 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
6094 dw_loc_descr_ref loc1, loc2;
6097 if (v1->val_class != v2->val_class)
6100 switch (v1->val_class)
6102 case dw_val_class_const:
6103 return v1->v.val_int == v2->v.val_int;
6104 case dw_val_class_unsigned_const:
6105 return v1->v.val_unsigned == v2->v.val_unsigned;
6106 case dw_val_class_long_long:
6107 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6108 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6109 case dw_val_class_vec:
6110 if (v1->v.val_vec.length != v2->v.val_vec.length
6111 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6113 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6114 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6117 case dw_val_class_flag:
6118 return v1->v.val_flag == v2->v.val_flag;
6119 case dw_val_class_str:
6120 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6122 case dw_val_class_addr:
6123 r1 = v1->v.val_addr;
6124 r2 = v2->v.val_addr;
6125 if (GET_CODE (r1) != GET_CODE (r2))
6127 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6128 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6130 case dw_val_class_offset:
6131 return v1->v.val_offset == v2->v.val_offset;
6133 case dw_val_class_loc:
6134 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6136 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6137 if (!same_loc_p (loc1, loc2, mark))
6139 return !loc1 && !loc2;
6141 case dw_val_class_die_ref:
6142 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6144 case dw_val_class_fde_ref:
6145 case dw_val_class_lbl_id:
6146 case dw_val_class_lineptr:
6147 case dw_val_class_macptr:
6150 case dw_val_class_file:
6151 return v1->v.val_file == v2->v.val_file;
6158 /* Do the attributes look the same? */
6161 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6163 if (at1->dw_attr != at2->dw_attr)
6166 /* We don't care that this was compiled with a different compiler
6167 snapshot; if the output is the same, that's what matters. */
6168 if (at1->dw_attr == DW_AT_producer)
6171 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6174 /* Do the dies look the same? */
6177 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6183 /* To avoid infinite recursion. */
6185 return die1->die_mark == die2->die_mark;
6186 die1->die_mark = die2->die_mark = ++(*mark);
6188 if (die1->die_tag != die2->die_tag)
6191 if (VEC_length (dw_attr_node, die1->die_attr)
6192 != VEC_length (dw_attr_node, die2->die_attr))
6195 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6196 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6199 c1 = die1->die_child;
6200 c2 = die2->die_child;
6209 if (!same_die_p (c1, c2, mark))
6213 if (c1 == die1->die_child)
6215 if (c2 == die2->die_child)
6225 /* Do the dies look the same? Wrapper around same_die_p. */
6228 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6231 int ret = same_die_p (die1, die2, &mark);
6233 unmark_all_dies (die1);
6234 unmark_all_dies (die2);
6239 /* The prefix to attach to symbols on DIEs in the current comdat debug
6241 static char *comdat_symbol_id;
6243 /* The index of the current symbol within the current comdat CU. */
6244 static unsigned int comdat_symbol_number;
6246 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6247 children, and set comdat_symbol_id accordingly. */
6250 compute_section_prefix (dw_die_ref unit_die)
6252 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6253 const char *base = die_name ? lbasename (die_name) : "anonymous";
6254 char *name = alloca (strlen (base) + 64);
6257 unsigned char checksum[16];
6260 /* Compute the checksum of the DIE, then append part of it as hex digits to
6261 the name filename of the unit. */
6263 md5_init_ctx (&ctx);
6265 die_checksum (unit_die, &ctx, &mark);
6266 unmark_all_dies (unit_die);
6267 md5_finish_ctx (&ctx, checksum);
6269 sprintf (name, "%s.", base);
6270 clean_symbol_name (name);
6272 p = name + strlen (name);
6273 for (i = 0; i < 4; i++)
6275 sprintf (p, "%.2x", checksum[i]);
6279 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6280 comdat_symbol_number = 0;
6283 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6286 is_type_die (dw_die_ref die)
6288 switch (die->die_tag)
6290 case DW_TAG_array_type:
6291 case DW_TAG_class_type:
6292 case DW_TAG_enumeration_type:
6293 case DW_TAG_pointer_type:
6294 case DW_TAG_reference_type:
6295 case DW_TAG_string_type:
6296 case DW_TAG_structure_type:
6297 case DW_TAG_subroutine_type:
6298 case DW_TAG_union_type:
6299 case DW_TAG_ptr_to_member_type:
6300 case DW_TAG_set_type:
6301 case DW_TAG_subrange_type:
6302 case DW_TAG_base_type:
6303 case DW_TAG_const_type:
6304 case DW_TAG_file_type:
6305 case DW_TAG_packed_type:
6306 case DW_TAG_volatile_type:
6307 case DW_TAG_typedef:
6314 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6315 Basically, we want to choose the bits that are likely to be shared between
6316 compilations (types) and leave out the bits that are specific to individual
6317 compilations (functions). */
6320 is_comdat_die (dw_die_ref c)
6322 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6323 we do for stabs. The advantage is a greater likelihood of sharing between
6324 objects that don't include headers in the same order (and therefore would
6325 put the base types in a different comdat). jason 8/28/00 */
6327 if (c->die_tag == DW_TAG_base_type)
6330 if (c->die_tag == DW_TAG_pointer_type
6331 || c->die_tag == DW_TAG_reference_type
6332 || c->die_tag == DW_TAG_const_type
6333 || c->die_tag == DW_TAG_volatile_type)
6335 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6337 return t ? is_comdat_die (t) : 0;
6340 return is_type_die (c);
6343 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6344 compilation unit. */
6347 is_symbol_die (dw_die_ref c)
6349 return (is_type_die (c)
6350 || (get_AT (c, DW_AT_declaration)
6351 && !get_AT (c, DW_AT_specification))
6352 || c->die_tag == DW_TAG_namespace);
6356 gen_internal_sym (const char *prefix)
6360 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6361 return xstrdup (buf);
6364 /* Assign symbols to all worthy DIEs under DIE. */
6367 assign_symbol_names (dw_die_ref die)
6371 if (is_symbol_die (die))
6373 if (comdat_symbol_id)
6375 char *p = alloca (strlen (comdat_symbol_id) + 64);
6377 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6378 comdat_symbol_id, comdat_symbol_number++);
6379 die->die_symbol = xstrdup (p);
6382 die->die_symbol = gen_internal_sym ("LDIE");
6385 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6388 struct cu_hash_table_entry
6391 unsigned min_comdat_num, max_comdat_num;
6392 struct cu_hash_table_entry *next;
6395 /* Routines to manipulate hash table of CUs. */
6397 htab_cu_hash (const void *of)
6399 const struct cu_hash_table_entry *entry = of;
6401 return htab_hash_string (entry->cu->die_symbol);
6405 htab_cu_eq (const void *of1, const void *of2)
6407 const struct cu_hash_table_entry *entry1 = of1;
6408 const struct die_struct *entry2 = of2;
6410 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6414 htab_cu_del (void *what)
6416 struct cu_hash_table_entry *next, *entry = what;
6426 /* Check whether we have already seen this CU and set up SYM_NUM
6429 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6431 struct cu_hash_table_entry dummy;
6432 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6434 dummy.max_comdat_num = 0;
6436 slot = (struct cu_hash_table_entry **)
6437 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6441 for (; entry; last = entry, entry = entry->next)
6443 if (same_die_p_wrap (cu, entry->cu))
6449 *sym_num = entry->min_comdat_num;
6453 entry = XCNEW (struct cu_hash_table_entry);
6455 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6456 entry->next = *slot;
6462 /* Record SYM_NUM to record of CU in HTABLE. */
6464 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6466 struct cu_hash_table_entry **slot, *entry;
6468 slot = (struct cu_hash_table_entry **)
6469 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6473 entry->max_comdat_num = sym_num;
6476 /* Traverse the DIE (which is always comp_unit_die), and set up
6477 additional compilation units for each of the include files we see
6478 bracketed by BINCL/EINCL. */
6481 break_out_includes (dw_die_ref die)
6484 dw_die_ref unit = NULL;
6485 limbo_die_node *node, **pnode;
6486 htab_t cu_hash_table;
6490 dw_die_ref prev = c;
6492 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6493 || (unit && is_comdat_die (c)))
6495 dw_die_ref next = c->die_sib;
6497 /* This DIE is for a secondary CU; remove it from the main one. */
6498 remove_child_with_prev (c, prev);
6500 if (c->die_tag == DW_TAG_GNU_BINCL)
6501 unit = push_new_compile_unit (unit, c);
6502 else if (c->die_tag == DW_TAG_GNU_EINCL)
6503 unit = pop_compile_unit (unit);
6505 add_child_die (unit, c);
6507 if (c == die->die_child)
6510 } while (c != die->die_child);
6513 /* We can only use this in debugging, since the frontend doesn't check
6514 to make sure that we leave every include file we enter. */
6518 assign_symbol_names (die);
6519 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6520 for (node = limbo_die_list, pnode = &limbo_die_list;
6526 compute_section_prefix (node->die);
6527 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6528 &comdat_symbol_number);
6529 assign_symbol_names (node->die);
6531 *pnode = node->next;
6534 pnode = &node->next;
6535 record_comdat_symbol_number (node->die, cu_hash_table,
6536 comdat_symbol_number);
6539 htab_delete (cu_hash_table);
6542 /* Traverse the DIE and add a sibling attribute if it may have the
6543 effect of speeding up access to siblings. To save some space,
6544 avoid generating sibling attributes for DIE's without children. */
6547 add_sibling_attributes (dw_die_ref die)
6551 if (! die->die_child)
6554 if (die->die_parent && die != die->die_parent->die_child)
6555 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6557 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6560 /* Output all location lists for the DIE and its children. */
6563 output_location_lists (dw_die_ref die)
6569 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6570 if (AT_class (a) == dw_val_class_loc_list)
6571 output_loc_list (AT_loc_list (a));
6573 FOR_EACH_CHILD (die, c, output_location_lists (c));
6576 /* The format of each DIE (and its attribute value pairs) is encoded in an
6577 abbreviation table. This routine builds the abbreviation table and assigns
6578 a unique abbreviation id for each abbreviation entry. The children of each
6579 die are visited recursively. */
6582 build_abbrev_table (dw_die_ref die)
6584 unsigned long abbrev_id;
6585 unsigned int n_alloc;
6590 /* Scan the DIE references, and mark as external any that refer to
6591 DIEs from other CUs (i.e. those which are not marked). */
6592 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6593 if (AT_class (a) == dw_val_class_die_ref
6594 && AT_ref (a)->die_mark == 0)
6596 gcc_assert (AT_ref (a)->die_symbol);
6598 set_AT_ref_external (a, 1);
6601 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6603 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6604 dw_attr_ref die_a, abbrev_a;
6608 if (abbrev->die_tag != die->die_tag)
6610 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6613 if (VEC_length (dw_attr_node, abbrev->die_attr)
6614 != VEC_length (dw_attr_node, die->die_attr))
6617 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6619 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6620 if ((abbrev_a->dw_attr != die_a->dw_attr)
6621 || (value_format (abbrev_a) != value_format (die_a)))
6631 if (abbrev_id >= abbrev_die_table_in_use)
6633 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6635 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6636 abbrev_die_table = ggc_realloc (abbrev_die_table,
6637 sizeof (dw_die_ref) * n_alloc);
6639 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6640 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6641 abbrev_die_table_allocated = n_alloc;
6644 ++abbrev_die_table_in_use;
6645 abbrev_die_table[abbrev_id] = die;
6648 die->die_abbrev = abbrev_id;
6649 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6652 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6655 constant_size (long unsigned int value)
6662 log = floor_log2 (value);
6665 log = 1 << (floor_log2 (log) + 1);
6670 /* Return the size of a DIE as it is represented in the
6671 .debug_info section. */
6673 static unsigned long
6674 size_of_die (dw_die_ref die)
6676 unsigned long size = 0;
6680 size += size_of_uleb128 (die->die_abbrev);
6681 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6683 switch (AT_class (a))
6685 case dw_val_class_addr:
6686 size += DWARF2_ADDR_SIZE;
6688 case dw_val_class_offset:
6689 size += DWARF_OFFSET_SIZE;
6691 case dw_val_class_loc:
6693 unsigned long lsize = size_of_locs (AT_loc (a));
6696 size += constant_size (lsize);
6700 case dw_val_class_loc_list:
6701 size += DWARF_OFFSET_SIZE;
6703 case dw_val_class_range_list:
6704 size += DWARF_OFFSET_SIZE;
6706 case dw_val_class_const:
6707 size += size_of_sleb128 (AT_int (a));
6709 case dw_val_class_unsigned_const:
6710 size += constant_size (AT_unsigned (a));
6712 case dw_val_class_long_long:
6713 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6715 case dw_val_class_vec:
6716 size += 1 + (a->dw_attr_val.v.val_vec.length
6717 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6719 case dw_val_class_flag:
6722 case dw_val_class_die_ref:
6723 if (AT_ref_external (a))
6724 size += DWARF2_ADDR_SIZE;
6726 size += DWARF_OFFSET_SIZE;
6728 case dw_val_class_fde_ref:
6729 size += DWARF_OFFSET_SIZE;
6731 case dw_val_class_lbl_id:
6732 size += DWARF2_ADDR_SIZE;
6734 case dw_val_class_lineptr:
6735 case dw_val_class_macptr:
6736 size += DWARF_OFFSET_SIZE;
6738 case dw_val_class_str:
6739 if (AT_string_form (a) == DW_FORM_strp)
6740 size += DWARF_OFFSET_SIZE;
6742 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6744 case dw_val_class_file:
6745 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6755 /* Size the debugging information associated with a given DIE. Visits the
6756 DIE's children recursively. Updates the global variable next_die_offset, on
6757 each time through. Uses the current value of next_die_offset to update the
6758 die_offset field in each DIE. */
6761 calc_die_sizes (dw_die_ref die)
6765 die->die_offset = next_die_offset;
6766 next_die_offset += size_of_die (die);
6768 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6770 if (die->die_child != NULL)
6771 /* Count the null byte used to terminate sibling lists. */
6772 next_die_offset += 1;
6775 /* Set the marks for a die and its children. We do this so
6776 that we know whether or not a reference needs to use FORM_ref_addr; only
6777 DIEs in the same CU will be marked. We used to clear out the offset
6778 and use that as the flag, but ran into ordering problems. */
6781 mark_dies (dw_die_ref die)
6785 gcc_assert (!die->die_mark);
6788 FOR_EACH_CHILD (die, c, mark_dies (c));
6791 /* Clear the marks for a die and its children. */
6794 unmark_dies (dw_die_ref die)
6798 gcc_assert (die->die_mark);
6801 FOR_EACH_CHILD (die, c, unmark_dies (c));
6804 /* Clear the marks for a die, its children and referred dies. */
6807 unmark_all_dies (dw_die_ref die)
6817 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6819 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6820 if (AT_class (a) == dw_val_class_die_ref)
6821 unmark_all_dies (AT_ref (a));
6824 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6825 generated for the compilation unit. */
6827 static unsigned long
6828 size_of_pubnames (VEC (pubname_entry, gc) * names)
6834 size = DWARF_PUBNAMES_HEADER_SIZE;
6835 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6836 if (names != pubtype_table
6837 || p->die->die_offset != 0
6838 || !flag_eliminate_unused_debug_types)
6839 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6841 size += DWARF_OFFSET_SIZE;
6845 /* Return the size of the information in the .debug_aranges section. */
6847 static unsigned long
6848 size_of_aranges (void)
6852 size = DWARF_ARANGES_HEADER_SIZE;
6854 /* Count the address/length pair for this compilation unit. */
6855 size += 2 * DWARF2_ADDR_SIZE;
6856 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6858 /* Count the two zero words used to terminated the address range table. */
6859 size += 2 * DWARF2_ADDR_SIZE;
6863 /* Select the encoding of an attribute value. */
6865 static enum dwarf_form
6866 value_format (dw_attr_ref a)
6868 switch (a->dw_attr_val.val_class)
6870 case dw_val_class_addr:
6871 return DW_FORM_addr;
6872 case dw_val_class_range_list:
6873 case dw_val_class_offset:
6874 case dw_val_class_loc_list:
6875 switch (DWARF_OFFSET_SIZE)
6878 return DW_FORM_data4;
6880 return DW_FORM_data8;
6884 case dw_val_class_loc:
6885 switch (constant_size (size_of_locs (AT_loc (a))))
6888 return DW_FORM_block1;
6890 return DW_FORM_block2;
6894 case dw_val_class_const:
6895 return DW_FORM_sdata;
6896 case dw_val_class_unsigned_const:
6897 switch (constant_size (AT_unsigned (a)))
6900 return DW_FORM_data1;
6902 return DW_FORM_data2;
6904 return DW_FORM_data4;
6906 return DW_FORM_data8;
6910 case dw_val_class_long_long:
6911 return DW_FORM_block1;
6912 case dw_val_class_vec:
6913 return DW_FORM_block1;
6914 case dw_val_class_flag:
6915 return DW_FORM_flag;
6916 case dw_val_class_die_ref:
6917 if (AT_ref_external (a))
6918 return DW_FORM_ref_addr;
6921 case dw_val_class_fde_ref:
6922 return DW_FORM_data;
6923 case dw_val_class_lbl_id:
6924 return DW_FORM_addr;
6925 case dw_val_class_lineptr:
6926 case dw_val_class_macptr:
6927 return DW_FORM_data;
6928 case dw_val_class_str:
6929 return AT_string_form (a);
6930 case dw_val_class_file:
6931 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
6934 return DW_FORM_data1;
6936 return DW_FORM_data2;
6938 return DW_FORM_data4;
6948 /* Output the encoding of an attribute value. */
6951 output_value_format (dw_attr_ref a)
6953 enum dwarf_form form = value_format (a);
6955 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6958 /* Output the .debug_abbrev section which defines the DIE abbreviation
6962 output_abbrev_section (void)
6964 unsigned long abbrev_id;
6966 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6968 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6972 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6973 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6974 dwarf_tag_name (abbrev->die_tag));
6976 if (abbrev->die_child != NULL)
6977 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6979 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6981 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
6984 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6985 dwarf_attr_name (a_attr->dw_attr));
6986 output_value_format (a_attr);
6989 dw2_asm_output_data (1, 0, NULL);
6990 dw2_asm_output_data (1, 0, NULL);
6993 /* Terminate the table. */
6994 dw2_asm_output_data (1, 0, NULL);
6997 /* Output a symbol we can use to refer to this DIE from another CU. */
7000 output_die_symbol (dw_die_ref die)
7002 char *sym = die->die_symbol;
7007 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7008 /* We make these global, not weak; if the target doesn't support
7009 .linkonce, it doesn't support combining the sections, so debugging
7011 targetm.asm_out.globalize_label (asm_out_file, sym);
7013 ASM_OUTPUT_LABEL (asm_out_file, sym);
7016 /* Return a new location list, given the begin and end range, and the
7017 expression. gensym tells us whether to generate a new internal symbol for
7018 this location list node, which is done for the head of the list only. */
7020 static inline dw_loc_list_ref
7021 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7022 const char *section, unsigned int gensym)
7024 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
7026 retlist->begin = begin;
7028 retlist->expr = expr;
7029 retlist->section = section;
7031 retlist->ll_symbol = gen_internal_sym ("LLST");
7036 /* Add a location description expression to a location list. */
7039 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7040 const char *begin, const char *end,
7041 const char *section)
7045 /* Find the end of the chain. */
7046 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7049 /* Add a new location list node to the list. */
7050 *d = new_loc_list (descr, begin, end, section, 0);
7054 dwarf2out_switch_text_section (void)
7060 fde = &fde_table[fde_table_in_use - 1];
7061 fde->dw_fde_switched_sections = true;
7062 fde->dw_fde_hot_section_label = cfun->hot_section_label;
7063 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
7064 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
7065 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
7066 have_multiple_function_sections = true;
7068 /* Reset the current label on switching text sections, so that we
7069 don't attempt to advance_loc4 between labels in different sections. */
7070 fde->dw_fde_current_label = NULL;
7073 /* Output the location list given to us. */
7076 output_loc_list (dw_loc_list_ref list_head)
7078 dw_loc_list_ref curr = list_head;
7080 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7082 /* Walk the location list, and output each range + expression. */
7083 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7086 /* Don't output an entry that starts and ends at the same address. */
7087 if (strcmp (curr->begin, curr->end) == 0)
7089 if (!have_multiple_function_sections)
7091 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7092 "Location list begin address (%s)",
7093 list_head->ll_symbol);
7094 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7095 "Location list end address (%s)",
7096 list_head->ll_symbol);
7100 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7101 "Location list begin address (%s)",
7102 list_head->ll_symbol);
7103 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7104 "Location list end address (%s)",
7105 list_head->ll_symbol);
7107 size = size_of_locs (curr->expr);
7109 /* Output the block length for this list of location operations. */
7110 gcc_assert (size <= 0xffff);
7111 dw2_asm_output_data (2, size, "%s", "Location expression size");
7113 output_loc_sequence (curr->expr);
7116 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7117 "Location list terminator begin (%s)",
7118 list_head->ll_symbol);
7119 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7120 "Location list terminator end (%s)",
7121 list_head->ll_symbol);
7124 /* Output the DIE and its attributes. Called recursively to generate
7125 the definitions of each child DIE. */
7128 output_die (dw_die_ref die)
7135 /* If someone in another CU might refer to us, set up a symbol for
7136 them to point to. */
7137 if (die->die_symbol)
7138 output_die_symbol (die);
7140 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7141 (unsigned long)die->die_offset,
7142 dwarf_tag_name (die->die_tag));
7144 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7146 const char *name = dwarf_attr_name (a->dw_attr);
7148 switch (AT_class (a))
7150 case dw_val_class_addr:
7151 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7154 case dw_val_class_offset:
7155 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7159 case dw_val_class_range_list:
7161 char *p = strchr (ranges_section_label, '\0');
7163 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7164 a->dw_attr_val.v.val_offset);
7165 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7166 debug_ranges_section, "%s", name);
7171 case dw_val_class_loc:
7172 size = size_of_locs (AT_loc (a));
7174 /* Output the block length for this list of location operations. */
7175 dw2_asm_output_data (constant_size (size), size, "%s", name);
7177 output_loc_sequence (AT_loc (a));
7180 case dw_val_class_const:
7181 /* ??? It would be slightly more efficient to use a scheme like is
7182 used for unsigned constants below, but gdb 4.x does not sign
7183 extend. Gdb 5.x does sign extend. */
7184 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7187 case dw_val_class_unsigned_const:
7188 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7189 AT_unsigned (a), "%s", name);
7192 case dw_val_class_long_long:
7194 unsigned HOST_WIDE_INT first, second;
7196 dw2_asm_output_data (1,
7197 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7200 if (WORDS_BIG_ENDIAN)
7202 first = a->dw_attr_val.v.val_long_long.hi;
7203 second = a->dw_attr_val.v.val_long_long.low;
7207 first = a->dw_attr_val.v.val_long_long.low;
7208 second = a->dw_attr_val.v.val_long_long.hi;
7211 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7212 first, "long long constant");
7213 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7218 case dw_val_class_vec:
7220 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7221 unsigned int len = a->dw_attr_val.v.val_vec.length;
7225 dw2_asm_output_data (1, len * elt_size, "%s", name);
7226 if (elt_size > sizeof (HOST_WIDE_INT))
7231 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7234 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7235 "fp or vector constant word %u", i);
7239 case dw_val_class_flag:
7240 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7243 case dw_val_class_loc_list:
7245 char *sym = AT_loc_list (a)->ll_symbol;
7248 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7253 case dw_val_class_die_ref:
7254 if (AT_ref_external (a))
7256 char *sym = AT_ref (a)->die_symbol;
7259 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7264 gcc_assert (AT_ref (a)->die_offset);
7265 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7270 case dw_val_class_fde_ref:
7274 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7275 a->dw_attr_val.v.val_fde_index * 2);
7276 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7281 case dw_val_class_lbl_id:
7282 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7285 case dw_val_class_lineptr:
7286 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7287 debug_line_section, "%s", name);
7290 case dw_val_class_macptr:
7291 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7292 debug_macinfo_section, "%s", name);
7295 case dw_val_class_str:
7296 if (AT_string_form (a) == DW_FORM_strp)
7297 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7298 a->dw_attr_val.v.val_str->label,
7300 "%s: \"%s\"", name, AT_string (a));
7302 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7305 case dw_val_class_file:
7307 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7309 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7310 a->dw_attr_val.v.val_file->filename);
7319 FOR_EACH_CHILD (die, c, output_die (c));
7321 /* Add null byte to terminate sibling list. */
7322 if (die->die_child != NULL)
7323 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7324 (unsigned long) die->die_offset);
7327 /* Output the compilation unit that appears at the beginning of the
7328 .debug_info section, and precedes the DIE descriptions. */
7331 output_compilation_unit_header (void)
7333 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7334 dw2_asm_output_data (4, 0xffffffff,
7335 "Initial length escape value indicating 64-bit DWARF extension");
7336 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7337 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7338 "Length of Compilation Unit Info");
7339 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7340 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7341 debug_abbrev_section,
7342 "Offset Into Abbrev. Section");
7343 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7346 /* Output the compilation unit DIE and its children. */
7349 output_comp_unit (dw_die_ref die, int output_if_empty)
7351 const char *secname;
7354 /* Unless we are outputting main CU, we may throw away empty ones. */
7355 if (!output_if_empty && die->die_child == NULL)
7358 /* Even if there are no children of this DIE, we must output the information
7359 about the compilation unit. Otherwise, on an empty translation unit, we
7360 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7361 will then complain when examining the file. First mark all the DIEs in
7362 this CU so we know which get local refs. */
7365 build_abbrev_table (die);
7367 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7368 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7369 calc_die_sizes (die);
7371 oldsym = die->die_symbol;
7374 tmp = alloca (strlen (oldsym) + 24);
7376 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7378 die->die_symbol = NULL;
7379 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7382 switch_to_section (debug_info_section);
7384 /* Output debugging information. */
7385 output_compilation_unit_header ();
7388 /* Leave the marks on the main CU, so we can check them in
7393 die->die_symbol = oldsym;
7397 /* Return the DWARF2/3 pubname associated with a decl. */
7400 dwarf2_name (tree decl, int scope)
7402 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7405 /* Add a new entry to .debug_pubnames if appropriate. */
7408 add_pubname (tree decl, dw_die_ref die)
7412 if (! TREE_PUBLIC (decl))
7416 e.name = xstrdup (dwarf2_name (decl, 1));
7417 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7420 /* Add a new entry to .debug_pubtypes if appropriate. */
7423 add_pubtype (tree decl, dw_die_ref die)
7428 if ((TREE_PUBLIC (decl)
7429 || die->die_parent == comp_unit_die)
7430 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7435 if (TYPE_NAME (decl))
7437 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7438 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7439 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7440 && DECL_NAME (TYPE_NAME (decl)))
7441 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7443 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7447 e.name = xstrdup (dwarf2_name (decl, 1));
7449 /* If we don't have a name for the type, there's no point in adding
7451 if (e.name && e.name[0] != '\0')
7452 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7456 /* Output the public names table used to speed up access to externally
7457 visible names; or the public types table used to find type definitions. */
7460 output_pubnames (VEC (pubname_entry, gc) * names)
7463 unsigned long pubnames_length = size_of_pubnames (names);
7466 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7467 dw2_asm_output_data (4, 0xffffffff,
7468 "Initial length escape value indicating 64-bit DWARF extension");
7469 if (names == pubname_table)
7470 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7471 "Length of Public Names Info");
7473 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7474 "Length of Public Type Names Info");
7475 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7476 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7478 "Offset of Compilation Unit Info");
7479 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7480 "Compilation Unit Length");
7482 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7484 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7485 if (names == pubname_table)
7486 gcc_assert (pub->die->die_mark);
7488 if (names != pubtype_table
7489 || pub->die->die_offset != 0
7490 || !flag_eliminate_unused_debug_types)
7492 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7495 dw2_asm_output_nstring (pub->name, -1, "external name");
7499 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7502 /* Add a new entry to .debug_aranges if appropriate. */
7505 add_arange (tree decl, dw_die_ref die)
7507 if (! DECL_SECTION_NAME (decl))
7510 if (arange_table_in_use == arange_table_allocated)
7512 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7513 arange_table = ggc_realloc (arange_table,
7514 (arange_table_allocated
7515 * sizeof (dw_die_ref)));
7516 memset (arange_table + arange_table_in_use, 0,
7517 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7520 arange_table[arange_table_in_use++] = die;
7523 /* Output the information that goes into the .debug_aranges table.
7524 Namely, define the beginning and ending address range of the
7525 text section generated for this compilation unit. */
7528 output_aranges (void)
7531 unsigned long aranges_length = size_of_aranges ();
7533 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7534 dw2_asm_output_data (4, 0xffffffff,
7535 "Initial length escape value indicating 64-bit DWARF extension");
7536 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7537 "Length of Address Ranges Info");
7538 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7539 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7541 "Offset of Compilation Unit Info");
7542 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7543 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7545 /* We need to align to twice the pointer size here. */
7546 if (DWARF_ARANGES_PAD_SIZE)
7548 /* Pad using a 2 byte words so that padding is correct for any
7550 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7551 2 * DWARF2_ADDR_SIZE);
7552 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7553 dw2_asm_output_data (2, 0, NULL);
7556 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7557 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7558 text_section_label, "Length");
7559 if (flag_reorder_blocks_and_partition)
7561 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7563 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7564 cold_text_section_label, "Length");
7567 for (i = 0; i < arange_table_in_use; i++)
7569 dw_die_ref die = arange_table[i];
7571 /* We shouldn't see aranges for DIEs outside of the main CU. */
7572 gcc_assert (die->die_mark);
7574 if (die->die_tag == DW_TAG_subprogram)
7576 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7578 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7579 get_AT_low_pc (die), "Length");
7583 /* A static variable; extract the symbol from DW_AT_location.
7584 Note that this code isn't currently hit, as we only emit
7585 aranges for functions (jason 9/23/99). */
7586 dw_attr_ref a = get_AT (die, DW_AT_location);
7587 dw_loc_descr_ref loc;
7589 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7592 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7594 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7595 loc->dw_loc_oprnd1.v.val_addr, "Address");
7596 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7597 get_AT_unsigned (die, DW_AT_byte_size),
7602 /* Output the terminator words. */
7603 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7604 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7607 /* Add a new entry to .debug_ranges. Return the offset at which it
7611 add_ranges_num (int num)
7613 unsigned int in_use = ranges_table_in_use;
7615 if (in_use == ranges_table_allocated)
7617 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7619 = ggc_realloc (ranges_table, (ranges_table_allocated
7620 * sizeof (struct dw_ranges_struct)));
7621 memset (ranges_table + ranges_table_in_use, 0,
7622 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7625 ranges_table[in_use].num = num;
7626 ranges_table_in_use = in_use + 1;
7628 return in_use * 2 * DWARF2_ADDR_SIZE;
7631 /* Add a new entry to .debug_ranges corresponding to a block, or a
7632 range terminator if BLOCK is NULL. */
7635 add_ranges (tree block)
7637 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
7640 /* Add a new entry to .debug_ranges corresponding to a pair of
7644 add_ranges_by_labels (const char *begin, const char *end)
7646 unsigned int in_use = ranges_by_label_in_use;
7648 if (in_use == ranges_by_label_allocated)
7650 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
7652 = ggc_realloc (ranges_by_label,
7653 (ranges_by_label_allocated
7654 * sizeof (struct dw_ranges_by_label_struct)));
7655 memset (ranges_by_label + ranges_by_label_in_use, 0,
7656 RANGES_TABLE_INCREMENT
7657 * sizeof (struct dw_ranges_by_label_struct));
7660 ranges_by_label[in_use].begin = begin;
7661 ranges_by_label[in_use].end = end;
7662 ranges_by_label_in_use = in_use + 1;
7664 return add_ranges_num (-(int)in_use - 1);
7668 output_ranges (void)
7671 static const char *const start_fmt = "Offset 0x%x";
7672 const char *fmt = start_fmt;
7674 for (i = 0; i < ranges_table_in_use; i++)
7676 int block_num = ranges_table[i].num;
7680 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7681 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7683 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7684 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7686 /* If all code is in the text section, then the compilation
7687 unit base address defaults to DW_AT_low_pc, which is the
7688 base of the text section. */
7689 if (!have_multiple_function_sections)
7691 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7693 fmt, i * 2 * DWARF2_ADDR_SIZE);
7694 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7695 text_section_label, NULL);
7698 /* Otherwise, the compilation unit base address is zero,
7699 which allows us to use absolute addresses, and not worry
7700 about whether the target supports cross-section
7704 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7705 fmt, i * 2 * DWARF2_ADDR_SIZE);
7706 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7712 /* Negative block_num stands for an index into ranges_by_label. */
7713 else if (block_num < 0)
7715 int lab_idx = - block_num - 1;
7717 if (!have_multiple_function_sections)
7721 /* If we ever use add_ranges_by_labels () for a single
7722 function section, all we have to do is to take out
7724 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7725 ranges_by_label[lab_idx].begin,
7727 fmt, i * 2 * DWARF2_ADDR_SIZE);
7728 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7729 ranges_by_label[lab_idx].end,
7730 text_section_label, NULL);
7735 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7736 ranges_by_label[lab_idx].begin,
7737 fmt, i * 2 * DWARF2_ADDR_SIZE);
7738 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7739 ranges_by_label[lab_idx].end,
7745 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7746 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7752 /* Data structure containing information about input files. */
7755 const char *path; /* Complete file name. */
7756 const char *fname; /* File name part. */
7757 int length; /* Length of entire string. */
7758 struct dwarf_file_data * file_idx; /* Index in input file table. */
7759 int dir_idx; /* Index in directory table. */
7762 /* Data structure containing information about directories with source
7766 const char *path; /* Path including directory name. */
7767 int length; /* Path length. */
7768 int prefix; /* Index of directory entry which is a prefix. */
7769 int count; /* Number of files in this directory. */
7770 int dir_idx; /* Index of directory used as base. */
7773 /* Callback function for file_info comparison. We sort by looking at
7774 the directories in the path. */
7777 file_info_cmp (const void *p1, const void *p2)
7779 const struct file_info *s1 = p1;
7780 const struct file_info *s2 = p2;
7781 const unsigned char *cp1;
7782 const unsigned char *cp2;
7784 /* Take care of file names without directories. We need to make sure that
7785 we return consistent values to qsort since some will get confused if
7786 we return the same value when identical operands are passed in opposite
7787 orders. So if neither has a directory, return 0 and otherwise return
7788 1 or -1 depending on which one has the directory. */
7789 if ((s1->path == s1->fname || s2->path == s2->fname))
7790 return (s2->path == s2->fname) - (s1->path == s1->fname);
7792 cp1 = (const unsigned char *) s1->path;
7793 cp2 = (const unsigned char *) s2->path;
7799 /* Reached the end of the first path? If so, handle like above. */
7800 if ((cp1 == (const unsigned char *) s1->fname)
7801 || (cp2 == (const unsigned char *) s2->fname))
7802 return ((cp2 == (const unsigned char *) s2->fname)
7803 - (cp1 == (const unsigned char *) s1->fname));
7805 /* Character of current path component the same? */
7806 else if (*cp1 != *cp2)
7811 struct file_name_acquire_data
7813 struct file_info *files;
7818 /* Traversal function for the hash table. */
7821 file_name_acquire (void ** slot, void *data)
7823 struct file_name_acquire_data *fnad = data;
7824 struct dwarf_file_data *d = *slot;
7825 struct file_info *fi;
7828 gcc_assert (fnad->max_files >= d->emitted_number);
7830 if (! d->emitted_number)
7833 gcc_assert (fnad->max_files != fnad->used_files);
7835 fi = fnad->files + fnad->used_files++;
7837 /* Skip all leading "./". */
7839 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7842 /* Create a new array entry. */
7844 fi->length = strlen (f);
7847 /* Search for the file name part. */
7848 f = strrchr (f, DIR_SEPARATOR);
7849 #if defined (DIR_SEPARATOR_2)
7851 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7855 if (f == NULL || f < g)
7861 fi->fname = f == NULL ? fi->path : f + 1;
7865 /* Output the directory table and the file name table. We try to minimize
7866 the total amount of memory needed. A heuristic is used to avoid large
7867 slowdowns with many input files. */
7870 output_file_names (void)
7872 struct file_name_acquire_data fnad;
7874 struct file_info *files;
7875 struct dir_info *dirs;
7884 if (!last_emitted_file)
7886 dw2_asm_output_data (1, 0, "End directory table");
7887 dw2_asm_output_data (1, 0, "End file name table");
7891 numfiles = last_emitted_file->emitted_number;
7893 /* Allocate the various arrays we need. */
7894 files = alloca (numfiles * sizeof (struct file_info));
7895 dirs = alloca (numfiles * sizeof (struct dir_info));
7898 fnad.used_files = 0;
7899 fnad.max_files = numfiles;
7900 htab_traverse (file_table, file_name_acquire, &fnad);
7901 gcc_assert (fnad.used_files == fnad.max_files);
7903 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
7905 /* Find all the different directories used. */
7906 dirs[0].path = files[0].path;
7907 dirs[0].length = files[0].fname - files[0].path;
7908 dirs[0].prefix = -1;
7910 dirs[0].dir_idx = 0;
7911 files[0].dir_idx = 0;
7914 for (i = 1; i < numfiles; i++)
7915 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7916 && memcmp (dirs[ndirs - 1].path, files[i].path,
7917 dirs[ndirs - 1].length) == 0)
7919 /* Same directory as last entry. */
7920 files[i].dir_idx = ndirs - 1;
7921 ++dirs[ndirs - 1].count;
7927 /* This is a new directory. */
7928 dirs[ndirs].path = files[i].path;
7929 dirs[ndirs].length = files[i].fname - files[i].path;
7930 dirs[ndirs].count = 1;
7931 dirs[ndirs].dir_idx = ndirs;
7932 files[i].dir_idx = ndirs;
7934 /* Search for a prefix. */
7935 dirs[ndirs].prefix = -1;
7936 for (j = 0; j < ndirs; j++)
7937 if (dirs[j].length < dirs[ndirs].length
7938 && dirs[j].length > 1
7939 && (dirs[ndirs].prefix == -1
7940 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7941 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7942 dirs[ndirs].prefix = j;
7947 /* Now to the actual work. We have to find a subset of the directories which
7948 allow expressing the file name using references to the directory table
7949 with the least amount of characters. We do not do an exhaustive search
7950 where we would have to check out every combination of every single
7951 possible prefix. Instead we use a heuristic which provides nearly optimal
7952 results in most cases and never is much off. */
7953 saved = alloca (ndirs * sizeof (int));
7954 savehere = alloca (ndirs * sizeof (int));
7956 memset (saved, '\0', ndirs * sizeof (saved[0]));
7957 for (i = 0; i < ndirs; i++)
7962 /* We can always save some space for the current directory. But this
7963 does not mean it will be enough to justify adding the directory. */
7964 savehere[i] = dirs[i].length;
7965 total = (savehere[i] - saved[i]) * dirs[i].count;
7967 for (j = i + 1; j < ndirs; j++)
7970 if (saved[j] < dirs[i].length)
7972 /* Determine whether the dirs[i] path is a prefix of the
7977 while (k != -1 && k != (int) i)
7982 /* Yes it is. We can possibly save some memory by
7983 writing the filenames in dirs[j] relative to
7985 savehere[j] = dirs[i].length;
7986 total += (savehere[j] - saved[j]) * dirs[j].count;
7991 /* Check whether we can save enough to justify adding the dirs[i]
7993 if (total > dirs[i].length + 1)
7995 /* It's worthwhile adding. */
7996 for (j = i; j < ndirs; j++)
7997 if (savehere[j] > 0)
7999 /* Remember how much we saved for this directory so far. */
8000 saved[j] = savehere[j];
8002 /* Remember the prefix directory. */
8003 dirs[j].dir_idx = i;
8008 /* Emit the directory name table. */
8010 idx_offset = dirs[0].length > 0 ? 1 : 0;
8011 for (i = 1 - idx_offset; i < ndirs; i++)
8012 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8013 "Directory Entry: 0x%x", i + idx_offset);
8015 dw2_asm_output_data (1, 0, "End directory table");
8017 /* We have to emit them in the order of emitted_number since that's
8018 used in the debug info generation. To do this efficiently we
8019 generate a back-mapping of the indices first. */
8020 backmap = alloca (numfiles * sizeof (int));
8021 for (i = 0; i < numfiles; i++)
8022 backmap[files[i].file_idx->emitted_number - 1] = i;
8024 /* Now write all the file names. */
8025 for (i = 0; i < numfiles; i++)
8027 int file_idx = backmap[i];
8028 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8030 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8031 "File Entry: 0x%x", (unsigned) i + 1);
8033 /* Include directory index. */
8034 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8036 /* Modification time. */
8037 dw2_asm_output_data_uleb128 (0, NULL);
8039 /* File length in bytes. */
8040 dw2_asm_output_data_uleb128 (0, NULL);
8043 dw2_asm_output_data (1, 0, "End file name table");
8047 /* Output the source line number correspondence information. This
8048 information goes into the .debug_line section. */
8051 output_line_info (void)
8053 char l1[20], l2[20], p1[20], p2[20];
8054 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8055 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8058 unsigned long lt_index;
8059 unsigned long current_line;
8062 unsigned long current_file;
8063 unsigned long function;
8065 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8066 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8067 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8068 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8070 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8071 dw2_asm_output_data (4, 0xffffffff,
8072 "Initial length escape value indicating 64-bit DWARF extension");
8073 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8074 "Length of Source Line Info");
8075 ASM_OUTPUT_LABEL (asm_out_file, l1);
8077 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8078 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8079 ASM_OUTPUT_LABEL (asm_out_file, p1);
8081 /* Define the architecture-dependent minimum instruction length (in
8082 bytes). In this implementation of DWARF, this field is used for
8083 information purposes only. Since GCC generates assembly language,
8084 we have no a priori knowledge of how many instruction bytes are
8085 generated for each source line, and therefore can use only the
8086 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8087 commands. Accordingly, we fix this as `1', which is "correct
8088 enough" for all architectures, and don't let the target override. */
8089 dw2_asm_output_data (1, 1,
8090 "Minimum Instruction Length");
8092 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8093 "Default is_stmt_start flag");
8094 dw2_asm_output_data (1, DWARF_LINE_BASE,
8095 "Line Base Value (Special Opcodes)");
8096 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8097 "Line Range Value (Special Opcodes)");
8098 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8099 "Special Opcode Base");
8101 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8105 case DW_LNS_advance_pc:
8106 case DW_LNS_advance_line:
8107 case DW_LNS_set_file:
8108 case DW_LNS_set_column:
8109 case DW_LNS_fixed_advance_pc:
8117 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8121 /* Write out the information about the files we use. */
8122 output_file_names ();
8123 ASM_OUTPUT_LABEL (asm_out_file, p2);
8125 /* We used to set the address register to the first location in the text
8126 section here, but that didn't accomplish anything since we already
8127 have a line note for the opening brace of the first function. */
8129 /* Generate the line number to PC correspondence table, encoded as
8130 a series of state machine operations. */
8134 if (cfun && in_cold_section_p)
8135 strcpy (prev_line_label, cfun->cold_section_label);
8137 strcpy (prev_line_label, text_section_label);
8138 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8140 dw_line_info_ref line_info = &line_info_table[lt_index];
8143 /* Disable this optimization for now; GDB wants to see two line notes
8144 at the beginning of a function so it can find the end of the
8147 /* Don't emit anything for redundant notes. Just updating the
8148 address doesn't accomplish anything, because we already assume
8149 that anything after the last address is this line. */
8150 if (line_info->dw_line_num == current_line
8151 && line_info->dw_file_num == current_file)
8155 /* Emit debug info for the address of the current line.
8157 Unfortunately, we have little choice here currently, and must always
8158 use the most general form. GCC does not know the address delta
8159 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8160 attributes which will give an upper bound on the address range. We
8161 could perhaps use length attributes to determine when it is safe to
8162 use DW_LNS_fixed_advance_pc. */
8164 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8167 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8168 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8169 "DW_LNS_fixed_advance_pc");
8170 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8174 /* This can handle any delta. This takes
8175 4+DWARF2_ADDR_SIZE bytes. */
8176 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8177 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8178 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8179 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8182 strcpy (prev_line_label, line_label);
8184 /* Emit debug info for the source file of the current line, if
8185 different from the previous line. */
8186 if (line_info->dw_file_num != current_file)
8188 current_file = line_info->dw_file_num;
8189 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8190 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8193 /* Emit debug info for the current line number, choosing the encoding
8194 that uses the least amount of space. */
8195 if (line_info->dw_line_num != current_line)
8197 line_offset = line_info->dw_line_num - current_line;
8198 line_delta = line_offset - DWARF_LINE_BASE;
8199 current_line = line_info->dw_line_num;
8200 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8201 /* This can handle deltas from -10 to 234, using the current
8202 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8204 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8205 "line %lu", current_line);
8208 /* This can handle any delta. This takes at least 4 bytes,
8209 depending on the value being encoded. */
8210 dw2_asm_output_data (1, DW_LNS_advance_line,
8211 "advance to line %lu", current_line);
8212 dw2_asm_output_data_sleb128 (line_offset, NULL);
8213 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8217 /* We still need to start a new row, so output a copy insn. */
8218 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8221 /* Emit debug info for the address of the end of the function. */
8224 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8225 "DW_LNS_fixed_advance_pc");
8226 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8230 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8231 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8232 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8233 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8236 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8237 dw2_asm_output_data_uleb128 (1, NULL);
8238 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8243 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8245 dw_separate_line_info_ref line_info
8246 = &separate_line_info_table[lt_index];
8249 /* Don't emit anything for redundant notes. */
8250 if (line_info->dw_line_num == current_line
8251 && line_info->dw_file_num == current_file
8252 && line_info->function == function)
8256 /* Emit debug info for the address of the current line. If this is
8257 a new function, or the first line of a function, then we need
8258 to handle it differently. */
8259 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8261 if (function != line_info->function)
8263 function = line_info->function;
8265 /* Set the address register to the first line in the function. */
8266 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8267 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8268 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8269 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8273 /* ??? See the DW_LNS_advance_pc comment above. */
8276 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8277 "DW_LNS_fixed_advance_pc");
8278 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8282 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8283 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8284 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8285 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8289 strcpy (prev_line_label, line_label);
8291 /* Emit debug info for the source file of the current line, if
8292 different from the previous line. */
8293 if (line_info->dw_file_num != current_file)
8295 current_file = line_info->dw_file_num;
8296 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8297 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8300 /* Emit debug info for the current line number, choosing the encoding
8301 that uses the least amount of space. */
8302 if (line_info->dw_line_num != current_line)
8304 line_offset = line_info->dw_line_num - current_line;
8305 line_delta = line_offset - DWARF_LINE_BASE;
8306 current_line = line_info->dw_line_num;
8307 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8308 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8309 "line %lu", current_line);
8312 dw2_asm_output_data (1, DW_LNS_advance_line,
8313 "advance to line %lu", current_line);
8314 dw2_asm_output_data_sleb128 (line_offset, NULL);
8315 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8319 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8327 /* If we're done with a function, end its sequence. */
8328 if (lt_index == separate_line_info_table_in_use
8329 || separate_line_info_table[lt_index].function != function)
8334 /* Emit debug info for the address of the end of the function. */
8335 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8338 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8339 "DW_LNS_fixed_advance_pc");
8340 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8344 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8345 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8346 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8347 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8350 /* Output the marker for the end of this sequence. */
8351 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8352 dw2_asm_output_data_uleb128 (1, NULL);
8353 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8357 /* Output the marker for the end of the line number info. */
8358 ASM_OUTPUT_LABEL (asm_out_file, l2);
8361 /* Given a pointer to a tree node for some base type, return a pointer to
8362 a DIE that describes the given type.
8364 This routine must only be called for GCC type nodes that correspond to
8365 Dwarf base (fundamental) types. */
8368 base_type_die (tree type)
8370 dw_die_ref base_type_result;
8371 enum dwarf_type encoding;
8373 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8376 switch (TREE_CODE (type))
8379 if (TYPE_STRING_FLAG (type))
8381 if (TYPE_UNSIGNED (type))
8382 encoding = DW_ATE_unsigned_char;
8384 encoding = DW_ATE_signed_char;
8386 else if (TYPE_UNSIGNED (type))
8387 encoding = DW_ATE_unsigned;
8389 encoding = DW_ATE_signed;
8393 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8394 encoding = DW_ATE_decimal_float;
8396 encoding = DW_ATE_float;
8399 case FIXED_POINT_TYPE:
8400 if (TYPE_UNSIGNED (type))
8401 encoding = DW_ATE_signed_fixed;
8403 encoding = DW_ATE_unsigned_fixed;
8406 /* Dwarf2 doesn't know anything about complex ints, so use
8407 a user defined type for it. */
8409 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8410 encoding = DW_ATE_complex_float;
8412 encoding = DW_ATE_lo_user;
8416 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8417 encoding = DW_ATE_boolean;
8421 /* No other TREE_CODEs are Dwarf fundamental types. */
8425 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8427 /* This probably indicates a bug. */
8428 if (! TYPE_NAME (type))
8429 add_name_attribute (base_type_result, "__unknown__");
8431 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8432 int_size_in_bytes (type));
8433 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8435 return base_type_result;
8438 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8439 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8442 is_base_type (tree type)
8444 switch (TREE_CODE (type))
8450 case FIXED_POINT_TYPE:
8458 case QUAL_UNION_TYPE:
8463 case REFERENCE_TYPE:
8476 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8477 node, return the size in bits for the type if it is a constant, or else
8478 return the alignment for the type if the type's size is not constant, or
8479 else return BITS_PER_WORD if the type actually turns out to be an
8482 static inline unsigned HOST_WIDE_INT
8483 simple_type_size_in_bits (tree type)
8485 if (TREE_CODE (type) == ERROR_MARK)
8486 return BITS_PER_WORD;
8487 else if (TYPE_SIZE (type) == NULL_TREE)
8489 else if (host_integerp (TYPE_SIZE (type), 1))
8490 return tree_low_cst (TYPE_SIZE (type), 1);
8492 return TYPE_ALIGN (type);
8495 /* Return true if the debug information for the given type should be
8496 emitted as a subrange type. */
8499 is_subrange_type (tree type)
8501 tree subtype = TREE_TYPE (type);
8503 /* Subrange types are identified by the fact that they are integer
8504 types, and that they have a subtype which is either an integer type
8505 or an enumeral type. */
8507 if (TREE_CODE (type) != INTEGER_TYPE
8508 || subtype == NULL_TREE)
8511 if (TREE_CODE (subtype) != INTEGER_TYPE
8512 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8515 if (TREE_CODE (type) == TREE_CODE (subtype)
8516 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8517 && TYPE_MIN_VALUE (type) != NULL
8518 && TYPE_MIN_VALUE (subtype) != NULL
8519 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8520 && TYPE_MAX_VALUE (type) != NULL
8521 && TYPE_MAX_VALUE (subtype) != NULL
8522 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8524 /* The type and its subtype have the same representation. If in
8525 addition the two types also have the same name, then the given
8526 type is not a subrange type, but rather a plain base type. */
8527 /* FIXME: brobecker/2004-03-22:
8528 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8529 therefore be sufficient to check the TYPE_SIZE node pointers
8530 rather than checking the actual size. Unfortunately, we have
8531 found some cases, such as in the Ada "integer" type, where
8532 this is not the case. Until this problem is solved, we need to
8533 keep checking the actual size. */
8534 tree type_name = TYPE_NAME (type);
8535 tree subtype_name = TYPE_NAME (subtype);
8537 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8538 type_name = DECL_NAME (type_name);
8540 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8541 subtype_name = DECL_NAME (subtype_name);
8543 if (type_name == subtype_name)
8550 /* Given a pointer to a tree node for a subrange type, return a pointer
8551 to a DIE that describes the given type. */
8554 subrange_type_die (tree type, dw_die_ref context_die)
8556 dw_die_ref subrange_die;
8557 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8559 if (context_die == NULL)
8560 context_die = comp_unit_die;
8562 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8564 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8566 /* The size of the subrange type and its base type do not match,
8567 so we need to generate a size attribute for the subrange type. */
8568 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8571 if (TYPE_MIN_VALUE (type) != NULL)
8572 add_bound_info (subrange_die, DW_AT_lower_bound,
8573 TYPE_MIN_VALUE (type));
8574 if (TYPE_MAX_VALUE (type) != NULL)
8575 add_bound_info (subrange_die, DW_AT_upper_bound,
8576 TYPE_MAX_VALUE (type));
8578 return subrange_die;
8581 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8582 entry that chains various modifiers in front of the given type. */
8585 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8586 dw_die_ref context_die)
8588 enum tree_code code = TREE_CODE (type);
8589 dw_die_ref mod_type_die;
8590 dw_die_ref sub_die = NULL;
8591 tree item_type = NULL;
8592 tree qualified_type;
8595 if (code == ERROR_MARK)
8598 /* See if we already have the appropriately qualified variant of
8601 = get_qualified_type (type,
8602 ((is_const_type ? TYPE_QUAL_CONST : 0)
8603 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8605 /* If we do, then we can just use its DIE, if it exists. */
8608 mod_type_die = lookup_type_die (qualified_type);
8610 return mod_type_die;
8613 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8615 /* Handle C typedef types. */
8616 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8618 tree dtype = TREE_TYPE (name);
8620 if (qualified_type == dtype)
8622 /* For a named type, use the typedef. */
8623 gen_type_die (qualified_type, context_die);
8624 return lookup_type_die (qualified_type);
8626 else if (is_const_type < TYPE_READONLY (dtype)
8627 || is_volatile_type < TYPE_VOLATILE (dtype)
8628 || (is_const_type <= TYPE_READONLY (dtype)
8629 && is_volatile_type <= TYPE_VOLATILE (dtype)
8630 && DECL_ORIGINAL_TYPE (name) != type))
8631 /* cv-unqualified version of named type. Just use the unnamed
8632 type to which it refers. */
8633 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8634 is_const_type, is_volatile_type,
8636 /* Else cv-qualified version of named type; fall through. */
8641 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8642 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8644 else if (is_volatile_type)
8646 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8647 sub_die = modified_type_die (type, 0, 0, context_die);
8649 else if (code == POINTER_TYPE)
8651 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8652 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8653 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8654 item_type = TREE_TYPE (type);
8656 else if (code == REFERENCE_TYPE)
8658 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8659 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8660 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8661 item_type = TREE_TYPE (type);
8663 else if (is_subrange_type (type))
8665 mod_type_die = subrange_type_die (type, context_die);
8666 item_type = TREE_TYPE (type);
8668 else if (is_base_type (type))
8669 mod_type_die = base_type_die (type);
8672 gen_type_die (type, context_die);
8674 /* We have to get the type_main_variant here (and pass that to the
8675 `lookup_type_die' routine) because the ..._TYPE node we have
8676 might simply be a *copy* of some original type node (where the
8677 copy was created to help us keep track of typedef names) and
8678 that copy might have a different TYPE_UID from the original
8680 if (TREE_CODE (type) != VECTOR_TYPE)
8681 return lookup_type_die (type_main_variant (type));
8683 /* Vectors have the debugging information in the type,
8684 not the main variant. */
8685 return lookup_type_die (type);
8688 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8689 don't output a DW_TAG_typedef, since there isn't one in the
8690 user's program; just attach a DW_AT_name to the type. */
8692 && (TREE_CODE (name) != TYPE_DECL || TREE_TYPE (name) == qualified_type))
8694 if (TREE_CODE (name) == TYPE_DECL)
8695 /* Could just call add_name_and_src_coords_attributes here,
8696 but since this is a builtin type it doesn't have any
8697 useful source coordinates anyway. */
8698 name = DECL_NAME (name);
8699 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8703 equate_type_number_to_die (qualified_type, mod_type_die);
8706 /* We must do this after the equate_type_number_to_die call, in case
8707 this is a recursive type. This ensures that the modified_type_die
8708 recursion will terminate even if the type is recursive. Recursive
8709 types are possible in Ada. */
8710 sub_die = modified_type_die (item_type,
8711 TYPE_READONLY (item_type),
8712 TYPE_VOLATILE (item_type),
8715 if (sub_die != NULL)
8716 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8718 return mod_type_die;
8721 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8722 an enumerated type. */
8725 type_is_enum (tree type)
8727 return TREE_CODE (type) == ENUMERAL_TYPE;
8730 /* Return the DBX register number described by a given RTL node. */
8733 dbx_reg_number (rtx rtl)
8735 unsigned regno = REGNO (rtl);
8737 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8739 #ifdef LEAF_REG_REMAP
8740 if (current_function_uses_only_leaf_regs)
8742 int leaf_reg = LEAF_REG_REMAP (regno);
8744 regno = (unsigned) leaf_reg;
8748 return DBX_REGISTER_NUMBER (regno);
8751 /* Optionally add a DW_OP_piece term to a location description expression.
8752 DW_OP_piece is only added if the location description expression already
8753 doesn't end with DW_OP_piece. */
8756 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8758 dw_loc_descr_ref loc;
8760 if (*list_head != NULL)
8762 /* Find the end of the chain. */
8763 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8766 if (loc->dw_loc_opc != DW_OP_piece)
8767 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8771 /* Return a location descriptor that designates a machine register or
8772 zero if there is none. */
8774 static dw_loc_descr_ref
8775 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
8779 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8782 regs = targetm.dwarf_register_span (rtl);
8784 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8785 return multiple_reg_loc_descriptor (rtl, regs, initialized);
8787 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
8790 /* Return a location descriptor that designates a machine register for
8791 a given hard register number. */
8793 static dw_loc_descr_ref
8794 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
8796 dw_loc_descr_ref reg_loc_descr;
8798 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8800 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
8802 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8803 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8805 return reg_loc_descr;
8808 /* Given an RTL of a register, return a location descriptor that
8809 designates a value that spans more than one register. */
8811 static dw_loc_descr_ref
8812 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
8813 enum var_init_status initialized)
8817 dw_loc_descr_ref loc_result = NULL;
8820 #ifdef LEAF_REG_REMAP
8821 if (current_function_uses_only_leaf_regs)
8823 int leaf_reg = LEAF_REG_REMAP (reg);
8825 reg = (unsigned) leaf_reg;
8828 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8829 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8831 /* Simple, contiguous registers. */
8832 if (regs == NULL_RTX)
8834 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8841 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
8842 VAR_INIT_STATUS_INITIALIZED);
8843 add_loc_descr (&loc_result, t);
8844 add_loc_descr_op_piece (&loc_result, size);
8850 /* Now onto stupid register sets in non contiguous locations. */
8852 gcc_assert (GET_CODE (regs) == PARALLEL);
8854 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8857 for (i = 0; i < XVECLEN (regs, 0); ++i)
8861 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
8862 VAR_INIT_STATUS_INITIALIZED);
8863 add_loc_descr (&loc_result, t);
8864 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8865 add_loc_descr_op_piece (&loc_result, size);
8868 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8869 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8873 /* Return a location descriptor that designates a constant. */
8875 static dw_loc_descr_ref
8876 int_loc_descriptor (HOST_WIDE_INT i)
8878 enum dwarf_location_atom op;
8880 /* Pick the smallest representation of a constant, rather than just
8881 defaulting to the LEB encoding. */
8885 op = DW_OP_lit0 + i;
8888 else if (i <= 0xffff)
8890 else if (HOST_BITS_PER_WIDE_INT == 32
8900 else if (i >= -0x8000)
8902 else if (HOST_BITS_PER_WIDE_INT == 32
8903 || i >= -0x80000000)
8909 return new_loc_descr (op, i, 0);
8912 /* Return a location descriptor that designates a base+offset location. */
8914 static dw_loc_descr_ref
8915 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
8916 enum var_init_status initialized)
8919 dw_loc_descr_ref result;
8921 /* We only use "frame base" when we're sure we're talking about the
8922 post-prologue local stack frame. We do this by *not* running
8923 register elimination until this point, and recognizing the special
8924 argument pointer and soft frame pointer rtx's. */
8925 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8927 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8931 if (GET_CODE (elim) == PLUS)
8933 offset += INTVAL (XEXP (elim, 1));
8934 elim = XEXP (elim, 0);
8936 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8937 : stack_pointer_rtx));
8938 offset += frame_pointer_fb_offset;
8940 return new_loc_descr (DW_OP_fbreg, offset, 0);
8944 regno = dbx_reg_number (reg);
8946 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
8948 result = new_loc_descr (DW_OP_bregx, regno, offset);
8950 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8951 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8956 /* Return true if this RTL expression describes a base+offset calculation. */
8959 is_based_loc (rtx rtl)
8961 return (GET_CODE (rtl) == PLUS
8962 && ((REG_P (XEXP (rtl, 0))
8963 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8964 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8967 /* Return a descriptor that describes the concatenation of N locations
8968 used to form the address of a memory location. */
8970 static dw_loc_descr_ref
8971 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
8972 enum var_init_status initialized)
8975 dw_loc_descr_ref cc_loc_result = NULL;
8976 unsigned int n = XVECLEN (concatn, 0);
8978 for (i = 0; i < n; ++i)
8980 dw_loc_descr_ref ref;
8981 rtx x = XVECEXP (concatn, 0, i);
8983 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
8987 add_loc_descr (&cc_loc_result, ref);
8988 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
8991 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8992 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8994 return cc_loc_result;
8997 /* The following routine converts the RTL for a variable or parameter
8998 (resident in memory) into an equivalent Dwarf representation of a
8999 mechanism for getting the address of that same variable onto the top of a
9000 hypothetical "address evaluation" stack.
9002 When creating memory location descriptors, we are effectively transforming
9003 the RTL for a memory-resident object into its Dwarf postfix expression
9004 equivalent. This routine recursively descends an RTL tree, turning
9005 it into Dwarf postfix code as it goes.
9007 MODE is the mode of the memory reference, needed to handle some
9008 autoincrement addressing modes.
9010 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9011 location list for RTL.
9013 Return 0 if we can't represent the location. */
9015 static dw_loc_descr_ref
9016 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9017 enum var_init_status initialized)
9019 dw_loc_descr_ref mem_loc_result = NULL;
9020 enum dwarf_location_atom op;
9022 /* Note that for a dynamically sized array, the location we will generate a
9023 description of here will be the lowest numbered location which is
9024 actually within the array. That's *not* necessarily the same as the
9025 zeroth element of the array. */
9027 rtl = targetm.delegitimize_address (rtl);
9029 switch (GET_CODE (rtl))
9034 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9035 just fall into the SUBREG code. */
9037 /* ... fall through ... */
9040 /* The case of a subreg may arise when we have a local (register)
9041 variable or a formal (register) parameter which doesn't quite fill
9042 up an entire register. For now, just assume that it is
9043 legitimate to make the Dwarf info refer to the whole register which
9044 contains the given subreg. */
9045 rtl = XEXP (rtl, 0);
9047 /* ... fall through ... */
9050 /* Whenever a register number forms a part of the description of the
9051 method for calculating the (dynamic) address of a memory resident
9052 object, DWARF rules require the register number be referred to as
9053 a "base register". This distinction is not based in any way upon
9054 what category of register the hardware believes the given register
9055 belongs to. This is strictly DWARF terminology we're dealing with
9056 here. Note that in cases where the location of a memory-resident
9057 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9058 OP_CONST (0)) the actual DWARF location descriptor that we generate
9059 may just be OP_BASEREG (basereg). This may look deceptively like
9060 the object in question was allocated to a register (rather than in
9061 memory) so DWARF consumers need to be aware of the subtle
9062 distinction between OP_REG and OP_BASEREG. */
9063 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9064 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9068 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9069 VAR_INIT_STATUS_INITIALIZED);
9070 if (mem_loc_result != 0)
9071 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9075 rtl = XEXP (rtl, 1);
9077 /* ... fall through ... */
9080 /* Some ports can transform a symbol ref into a label ref, because
9081 the symbol ref is too far away and has to be dumped into a constant
9085 /* Alternatively, the symbol in the constant pool might be referenced
9086 by a different symbol. */
9087 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9090 rtx tmp = get_pool_constant_mark (rtl, &marked);
9092 if (GET_CODE (tmp) == SYMBOL_REF)
9095 if (CONSTANT_POOL_ADDRESS_P (tmp))
9096 get_pool_constant_mark (tmp, &marked);
9101 /* If all references to this pool constant were optimized away,
9102 it was not output and thus we can't represent it.
9103 FIXME: might try to use DW_OP_const_value here, though
9104 DW_OP_piece complicates it. */
9109 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9110 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9111 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9112 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9116 /* Extract the PLUS expression nested inside and fall into
9118 rtl = XEXP (rtl, 1);
9123 /* Turn these into a PLUS expression and fall into the PLUS code
9125 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9126 GEN_INT (GET_CODE (rtl) == PRE_INC
9127 ? GET_MODE_UNIT_SIZE (mode)
9128 : -GET_MODE_UNIT_SIZE (mode)));
9130 /* ... fall through ... */
9134 if (is_based_loc (rtl))
9135 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9136 INTVAL (XEXP (rtl, 1)),
9137 VAR_INIT_STATUS_INITIALIZED);
9140 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9141 VAR_INIT_STATUS_INITIALIZED);
9142 if (mem_loc_result == 0)
9145 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9146 && INTVAL (XEXP (rtl, 1)) >= 0)
9147 add_loc_descr (&mem_loc_result,
9148 new_loc_descr (DW_OP_plus_uconst,
9149 INTVAL (XEXP (rtl, 1)), 0));
9152 add_loc_descr (&mem_loc_result,
9153 mem_loc_descriptor (XEXP (rtl, 1), mode,
9154 VAR_INIT_STATUS_INITIALIZED));
9155 add_loc_descr (&mem_loc_result,
9156 new_loc_descr (DW_OP_plus, 0, 0));
9161 /* If a pseudo-reg is optimized away, it is possible for it to
9162 be replaced with a MEM containing a multiply or shift. */
9181 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9182 VAR_INIT_STATUS_INITIALIZED);
9183 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9184 VAR_INIT_STATUS_INITIALIZED);
9186 if (op0 == 0 || op1 == 0)
9189 mem_loc_result = op0;
9190 add_loc_descr (&mem_loc_result, op1);
9191 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9196 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9200 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9201 VAR_INIT_STATUS_INITIALIZED);
9208 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9209 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9211 return mem_loc_result;
9214 /* Return a descriptor that describes the concatenation of two locations.
9215 This is typically a complex variable. */
9217 static dw_loc_descr_ref
9218 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9220 dw_loc_descr_ref cc_loc_result = NULL;
9221 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9222 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9224 if (x0_ref == 0 || x1_ref == 0)
9227 cc_loc_result = x0_ref;
9228 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9230 add_loc_descr (&cc_loc_result, x1_ref);
9231 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9233 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9234 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9236 return cc_loc_result;
9239 /* Return a descriptor that describes the concatenation of N
9242 static dw_loc_descr_ref
9243 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9246 dw_loc_descr_ref cc_loc_result = NULL;
9247 unsigned int n = XVECLEN (concatn, 0);
9249 for (i = 0; i < n; ++i)
9251 dw_loc_descr_ref ref;
9252 rtx x = XVECEXP (concatn, 0, i);
9254 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9258 add_loc_descr (&cc_loc_result, ref);
9259 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9262 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9263 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9265 return cc_loc_result;
9268 /* Output a proper Dwarf location descriptor for a variable or parameter
9269 which is either allocated in a register or in a memory location. For a
9270 register, we just generate an OP_REG and the register number. For a
9271 memory location we provide a Dwarf postfix expression describing how to
9272 generate the (dynamic) address of the object onto the address stack.
9274 If we don't know how to describe it, return 0. */
9276 static dw_loc_descr_ref
9277 loc_descriptor (rtx rtl, enum var_init_status initialized)
9279 dw_loc_descr_ref loc_result = NULL;
9281 switch (GET_CODE (rtl))
9284 /* The case of a subreg may arise when we have a local (register)
9285 variable or a formal (register) parameter which doesn't quite fill
9286 up an entire register. For now, just assume that it is
9287 legitimate to make the Dwarf info refer to the whole register which
9288 contains the given subreg. */
9289 rtl = SUBREG_REG (rtl);
9291 /* ... fall through ... */
9294 loc_result = reg_loc_descriptor (rtl, initialized);
9298 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9303 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9308 loc_result = concatn_loc_descriptor (rtl, initialized);
9313 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9315 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9319 rtl = XEXP (rtl, 1);
9324 rtvec par_elems = XVEC (rtl, 0);
9325 int num_elem = GET_NUM_ELEM (par_elems);
9326 enum machine_mode mode;
9329 /* Create the first one, so we have something to add to. */
9330 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9332 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9333 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9334 for (i = 1; i < num_elem; i++)
9336 dw_loc_descr_ref temp;
9338 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9340 add_loc_descr (&loc_result, temp);
9341 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9342 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9354 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9355 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9356 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9357 top-level invocation, and we require the address of LOC; is 0 if we require
9358 the value of LOC. */
9360 static dw_loc_descr_ref
9361 loc_descriptor_from_tree_1 (tree loc, int want_address)
9363 dw_loc_descr_ref ret, ret1;
9364 int have_address = 0;
9365 enum dwarf_location_atom op;
9367 /* ??? Most of the time we do not take proper care for sign/zero
9368 extending the values properly. Hopefully this won't be a real
9371 switch (TREE_CODE (loc))
9376 case PLACEHOLDER_EXPR:
9377 /* This case involves extracting fields from an object to determine the
9378 position of other fields. We don't try to encode this here. The
9379 only user of this is Ada, which encodes the needed information using
9380 the names of types. */
9386 case PREINCREMENT_EXPR:
9387 case PREDECREMENT_EXPR:
9388 case POSTINCREMENT_EXPR:
9389 case POSTDECREMENT_EXPR:
9390 /* There are no opcodes for these operations. */
9394 /* If we already want an address, there's nothing we can do. */
9398 /* Otherwise, process the argument and look for the address. */
9399 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9402 if (DECL_THREAD_LOCAL_P (loc))
9406 /* If this is not defined, we have no way to emit the data. */
9407 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
9410 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9411 look up addresses of objects in the current module. */
9412 if (DECL_EXTERNAL (loc))
9415 rtl = rtl_for_decl_location (loc);
9416 if (rtl == NULL_RTX)
9421 rtl = XEXP (rtl, 0);
9422 if (! CONSTANT_P (rtl))
9425 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9426 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9427 ret->dw_loc_oprnd1.v.val_addr = rtl;
9429 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9430 add_loc_descr (&ret, ret1);
9438 if (DECL_HAS_VALUE_EXPR_P (loc))
9439 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9446 rtx rtl = rtl_for_decl_location (loc);
9448 if (rtl == NULL_RTX)
9450 else if (GET_CODE (rtl) == CONST_INT)
9452 HOST_WIDE_INT val = INTVAL (rtl);
9453 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9454 val &= GET_MODE_MASK (DECL_MODE (loc));
9455 ret = int_loc_descriptor (val);
9457 else if (GET_CODE (rtl) == CONST_STRING)
9459 else if (CONSTANT_P (rtl))
9461 ret = new_loc_descr (DW_OP_addr, 0, 0);
9462 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9463 ret->dw_loc_oprnd1.v.val_addr = rtl;
9467 enum machine_mode mode;
9469 /* Certain constructs can only be represented at top-level. */
9470 if (want_address == 2)
9471 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
9473 mode = GET_MODE (rtl);
9476 rtl = XEXP (rtl, 0);
9479 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9485 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9490 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9494 case NON_LVALUE_EXPR:
9495 case VIEW_CONVERT_EXPR:
9497 case GIMPLE_MODIFY_STMT:
9498 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0),
9504 case ARRAY_RANGE_REF:
9507 HOST_WIDE_INT bitsize, bitpos, bytepos;
9508 enum machine_mode mode;
9510 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9512 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9513 &unsignedp, &volatilep, false);
9518 ret = loc_descriptor_from_tree_1 (obj, 1);
9520 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9523 if (offset != NULL_TREE)
9525 /* Variable offset. */
9526 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9527 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9530 bytepos = bitpos / BITS_PER_UNIT;
9532 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9533 else if (bytepos < 0)
9535 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9536 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9544 if (host_integerp (loc, 0))
9545 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9552 /* Get an RTL for this, if something has been emitted. */
9553 rtx rtl = lookup_constant_def (loc);
9554 enum machine_mode mode;
9556 if (!rtl || !MEM_P (rtl))
9558 mode = GET_MODE (rtl);
9559 rtl = XEXP (rtl, 0);
9560 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9565 case TRUTH_AND_EXPR:
9566 case TRUTH_ANDIF_EXPR:
9571 case TRUTH_XOR_EXPR:
9577 case TRUTH_ORIF_EXPR:
9582 case FLOOR_DIV_EXPR:
9584 case ROUND_DIV_EXPR:
9585 case TRUNC_DIV_EXPR:
9593 case FLOOR_MOD_EXPR:
9595 case ROUND_MOD_EXPR:
9596 case TRUNC_MOD_EXPR:
9609 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9612 case POINTER_PLUS_EXPR:
9614 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9615 && host_integerp (TREE_OPERAND (loc, 1), 0))
9617 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9621 add_loc_descr (&ret,
9622 new_loc_descr (DW_OP_plus_uconst,
9623 tree_low_cst (TREE_OPERAND (loc, 1),
9633 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9640 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9647 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9654 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9669 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9670 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9671 if (ret == 0 || ret1 == 0)
9674 add_loc_descr (&ret, ret1);
9675 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9678 case TRUTH_NOT_EXPR:
9692 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9696 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9702 const enum tree_code code =
9703 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9705 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9706 build2 (code, integer_type_node,
9707 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9708 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9711 /* ... fall through ... */
9715 dw_loc_descr_ref lhs
9716 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9717 dw_loc_descr_ref rhs
9718 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9719 dw_loc_descr_ref bra_node, jump_node, tmp;
9721 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9722 if (ret == 0 || lhs == 0 || rhs == 0)
9725 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9726 add_loc_descr (&ret, bra_node);
9728 add_loc_descr (&ret, rhs);
9729 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9730 add_loc_descr (&ret, jump_node);
9732 add_loc_descr (&ret, lhs);
9733 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9734 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9736 /* ??? Need a node to point the skip at. Use a nop. */
9737 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9738 add_loc_descr (&ret, tmp);
9739 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9740 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9744 case FIX_TRUNC_EXPR:
9748 /* Leave front-end specific codes as simply unknown. This comes
9749 up, for instance, with the C STMT_EXPR. */
9750 if ((unsigned int) TREE_CODE (loc)
9751 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9754 #ifdef ENABLE_CHECKING
9755 /* Otherwise this is a generic code; we should just lists all of
9756 these explicitly. We forgot one. */
9759 /* In a release build, we want to degrade gracefully: better to
9760 generate incomplete debugging information than to crash. */
9765 /* Show if we can't fill the request for an address. */
9766 if (want_address && !have_address)
9769 /* If we've got an address and don't want one, dereference. */
9770 if (!want_address && have_address && ret)
9772 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9774 if (size > DWARF2_ADDR_SIZE || size == -1)
9776 else if (size == DWARF2_ADDR_SIZE)
9779 op = DW_OP_deref_size;
9781 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9787 static inline dw_loc_descr_ref
9788 loc_descriptor_from_tree (tree loc)
9790 return loc_descriptor_from_tree_1 (loc, 2);
9793 /* Given a value, round it up to the lowest multiple of `boundary'
9794 which is not less than the value itself. */
9796 static inline HOST_WIDE_INT
9797 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9799 return (((value + boundary - 1) / boundary) * boundary);
9802 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9803 pointer to the declared type for the relevant field variable, or return
9804 `integer_type_node' if the given node turns out to be an
9808 field_type (tree decl)
9812 if (TREE_CODE (decl) == ERROR_MARK)
9813 return integer_type_node;
9815 type = DECL_BIT_FIELD_TYPE (decl);
9816 if (type == NULL_TREE)
9817 type = TREE_TYPE (decl);
9822 /* Given a pointer to a tree node, return the alignment in bits for
9823 it, or else return BITS_PER_WORD if the node actually turns out to
9824 be an ERROR_MARK node. */
9826 static inline unsigned
9827 simple_type_align_in_bits (tree type)
9829 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9832 static inline unsigned
9833 simple_decl_align_in_bits (tree decl)
9835 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9838 /* Return the result of rounding T up to ALIGN. */
9840 static inline HOST_WIDE_INT
9841 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9843 /* We must be careful if T is negative because HOST_WIDE_INT can be
9844 either "above" or "below" unsigned int as per the C promotion
9845 rules, depending on the host, thus making the signedness of the
9846 direct multiplication and division unpredictable. */
9847 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9853 return (HOST_WIDE_INT) u;
9856 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9857 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9858 or return 0 if we are unable to determine what that offset is, either
9859 because the argument turns out to be a pointer to an ERROR_MARK node, or
9860 because the offset is actually variable. (We can't handle the latter case
9863 static HOST_WIDE_INT
9864 field_byte_offset (tree decl)
9866 HOST_WIDE_INT object_offset_in_bits;
9867 HOST_WIDE_INT bitpos_int;
9869 if (TREE_CODE (decl) == ERROR_MARK)
9872 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9874 /* We cannot yet cope with fields whose positions are variable, so
9875 for now, when we see such things, we simply return 0. Someday, we may
9876 be able to handle such cases, but it will be damn difficult. */
9877 if (! host_integerp (bit_position (decl), 0))
9880 bitpos_int = int_bit_position (decl);
9882 #ifdef PCC_BITFIELD_TYPE_MATTERS
9883 if (PCC_BITFIELD_TYPE_MATTERS)
9886 tree field_size_tree;
9887 HOST_WIDE_INT deepest_bitpos;
9888 unsigned HOST_WIDE_INT field_size_in_bits;
9889 unsigned int type_align_in_bits;
9890 unsigned int decl_align_in_bits;
9891 unsigned HOST_WIDE_INT type_size_in_bits;
9893 type = field_type (decl);
9894 field_size_tree = DECL_SIZE (decl);
9896 /* The size could be unspecified if there was an error, or for
9897 a flexible array member. */
9898 if (! field_size_tree)
9899 field_size_tree = bitsize_zero_node;
9901 /* If we don't know the size of the field, pretend it's a full word. */
9902 if (host_integerp (field_size_tree, 1))
9903 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9905 field_size_in_bits = BITS_PER_WORD;
9907 type_size_in_bits = simple_type_size_in_bits (type);
9908 type_align_in_bits = simple_type_align_in_bits (type);
9909 decl_align_in_bits = simple_decl_align_in_bits (decl);
9911 /* The GCC front-end doesn't make any attempt to keep track of the
9912 starting bit offset (relative to the start of the containing
9913 structure type) of the hypothetical "containing object" for a
9914 bit-field. Thus, when computing the byte offset value for the
9915 start of the "containing object" of a bit-field, we must deduce
9916 this information on our own. This can be rather tricky to do in
9917 some cases. For example, handling the following structure type
9918 definition when compiling for an i386/i486 target (which only
9919 aligns long long's to 32-bit boundaries) can be very tricky:
9921 struct S { int field1; long long field2:31; };
9923 Fortunately, there is a simple rule-of-thumb which can be used
9924 in such cases. When compiling for an i386/i486, GCC will
9925 allocate 8 bytes for the structure shown above. It decides to
9926 do this based upon one simple rule for bit-field allocation.
9927 GCC allocates each "containing object" for each bit-field at
9928 the first (i.e. lowest addressed) legitimate alignment boundary
9929 (based upon the required minimum alignment for the declared
9930 type of the field) which it can possibly use, subject to the
9931 condition that there is still enough available space remaining
9932 in the containing object (when allocated at the selected point)
9933 to fully accommodate all of the bits of the bit-field itself.
9935 This simple rule makes it obvious why GCC allocates 8 bytes for
9936 each object of the structure type shown above. When looking
9937 for a place to allocate the "containing object" for `field2',
9938 the compiler simply tries to allocate a 64-bit "containing
9939 object" at each successive 32-bit boundary (starting at zero)
9940 until it finds a place to allocate that 64- bit field such that
9941 at least 31 contiguous (and previously unallocated) bits remain
9942 within that selected 64 bit field. (As it turns out, for the
9943 example above, the compiler finds it is OK to allocate the
9944 "containing object" 64-bit field at bit-offset zero within the
9947 Here we attempt to work backwards from the limited set of facts
9948 we're given, and we try to deduce from those facts, where GCC
9949 must have believed that the containing object started (within
9950 the structure type). The value we deduce is then used (by the
9951 callers of this routine) to generate DW_AT_location and
9952 DW_AT_bit_offset attributes for fields (both bit-fields and, in
9953 the case of DW_AT_location, regular fields as well). */
9955 /* Figure out the bit-distance from the start of the structure to
9956 the "deepest" bit of the bit-field. */
9957 deepest_bitpos = bitpos_int + field_size_in_bits;
9959 /* This is the tricky part. Use some fancy footwork to deduce
9960 where the lowest addressed bit of the containing object must
9962 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9964 /* Round up to type_align by default. This works best for
9966 object_offset_in_bits
9967 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
9969 if (object_offset_in_bits > bitpos_int)
9971 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9973 /* Round up to decl_align instead. */
9974 object_offset_in_bits
9975 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
9980 object_offset_in_bits = bitpos_int;
9982 return object_offset_in_bits / BITS_PER_UNIT;
9985 /* The following routines define various Dwarf attributes and any data
9986 associated with them. */
9988 /* Add a location description attribute value to a DIE.
9990 This emits location attributes suitable for whole variables and
9991 whole parameters. Note that the location attributes for struct fields are
9992 generated by the routine `data_member_location_attribute' below. */
9995 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9996 dw_loc_descr_ref descr)
9999 add_AT_loc (die, attr_kind, descr);
10002 /* Attach the specialized form of location attribute used for data members of
10003 struct and union types. In the special case of a FIELD_DECL node which
10004 represents a bit-field, the "offset" part of this special location
10005 descriptor must indicate the distance in bytes from the lowest-addressed
10006 byte of the containing struct or union type to the lowest-addressed byte of
10007 the "containing object" for the bit-field. (See the `field_byte_offset'
10010 For any given bit-field, the "containing object" is a hypothetical object
10011 (of some integral or enum type) within which the given bit-field lives. The
10012 type of this hypothetical "containing object" is always the same as the
10013 declared type of the individual bit-field itself (for GCC anyway... the
10014 DWARF spec doesn't actually mandate this). Note that it is the size (in
10015 bytes) of the hypothetical "containing object" which will be given in the
10016 DW_AT_byte_size attribute for this bit-field. (See the
10017 `byte_size_attribute' function below.) It is also used when calculating the
10018 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10019 function below.) */
10022 add_data_member_location_attribute (dw_die_ref die, tree decl)
10024 HOST_WIDE_INT offset;
10025 dw_loc_descr_ref loc_descr = 0;
10027 if (TREE_CODE (decl) == TREE_BINFO)
10029 /* We're working on the TAG_inheritance for a base class. */
10030 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10032 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10033 aren't at a fixed offset from all (sub)objects of the same
10034 type. We need to extract the appropriate offset from our
10035 vtable. The following dwarf expression means
10037 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10039 This is specific to the V3 ABI, of course. */
10041 dw_loc_descr_ref tmp;
10043 /* Make a copy of the object address. */
10044 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10045 add_loc_descr (&loc_descr, tmp);
10047 /* Extract the vtable address. */
10048 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10049 add_loc_descr (&loc_descr, tmp);
10051 /* Calculate the address of the offset. */
10052 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10053 gcc_assert (offset < 0);
10055 tmp = int_loc_descriptor (-offset);
10056 add_loc_descr (&loc_descr, tmp);
10057 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10058 add_loc_descr (&loc_descr, tmp);
10060 /* Extract the offset. */
10061 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10062 add_loc_descr (&loc_descr, tmp);
10064 /* Add it to the object address. */
10065 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10066 add_loc_descr (&loc_descr, tmp);
10069 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10072 offset = field_byte_offset (decl);
10076 enum dwarf_location_atom op;
10078 /* The DWARF2 standard says that we should assume that the structure
10079 address is already on the stack, so we can specify a structure field
10080 address by using DW_OP_plus_uconst. */
10082 #ifdef MIPS_DEBUGGING_INFO
10083 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10084 operator correctly. It works only if we leave the offset on the
10088 op = DW_OP_plus_uconst;
10091 loc_descr = new_loc_descr (op, offset, 0);
10094 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10097 /* Writes integer values to dw_vec_const array. */
10100 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10104 *dest++ = val & 0xff;
10110 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10112 static HOST_WIDE_INT
10113 extract_int (const unsigned char *src, unsigned int size)
10115 HOST_WIDE_INT val = 0;
10121 val |= *--src & 0xff;
10127 /* Writes floating point values to dw_vec_const array. */
10130 insert_float (rtx rtl, unsigned char *array)
10132 REAL_VALUE_TYPE rv;
10136 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10137 real_to_target (val, &rv, GET_MODE (rtl));
10139 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10140 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10142 insert_int (val[i], 4, array);
10147 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10148 does not have a "location" either in memory or in a register. These
10149 things can arise in GNU C when a constant is passed as an actual parameter
10150 to an inlined function. They can also arise in C++ where declared
10151 constants do not necessarily get memory "homes". */
10154 add_const_value_attribute (dw_die_ref die, rtx rtl)
10156 switch (GET_CODE (rtl))
10160 HOST_WIDE_INT val = INTVAL (rtl);
10163 add_AT_int (die, DW_AT_const_value, val);
10165 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10170 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10171 floating-point constant. A CONST_DOUBLE is used whenever the
10172 constant requires more than one word in order to be adequately
10173 represented. We output CONST_DOUBLEs as blocks. */
10175 enum machine_mode mode = GET_MODE (rtl);
10177 if (SCALAR_FLOAT_MODE_P (mode))
10179 unsigned int length = GET_MODE_SIZE (mode);
10180 unsigned char *array = ggc_alloc (length);
10182 insert_float (rtl, array);
10183 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10187 /* ??? We really should be using HOST_WIDE_INT throughout. */
10188 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10190 add_AT_long_long (die, DW_AT_const_value,
10191 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10198 enum machine_mode mode = GET_MODE (rtl);
10199 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10200 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10201 unsigned char *array = ggc_alloc (length * elt_size);
10205 switch (GET_MODE_CLASS (mode))
10207 case MODE_VECTOR_INT:
10208 for (i = 0, p = array; i < length; i++, p += elt_size)
10210 rtx elt = CONST_VECTOR_ELT (rtl, i);
10211 HOST_WIDE_INT lo, hi;
10213 switch (GET_CODE (elt))
10221 lo = CONST_DOUBLE_LOW (elt);
10222 hi = CONST_DOUBLE_HIGH (elt);
10226 gcc_unreachable ();
10229 if (elt_size <= sizeof (HOST_WIDE_INT))
10230 insert_int (lo, elt_size, p);
10233 unsigned char *p0 = p;
10234 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10236 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10237 if (WORDS_BIG_ENDIAN)
10242 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10243 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10248 case MODE_VECTOR_FLOAT:
10249 for (i = 0, p = array; i < length; i++, p += elt_size)
10251 rtx elt = CONST_VECTOR_ELT (rtl, i);
10252 insert_float (elt, p);
10257 gcc_unreachable ();
10260 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10265 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10271 add_AT_addr (die, DW_AT_const_value, rtl);
10272 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10276 /* In cases where an inlined instance of an inline function is passed
10277 the address of an `auto' variable (which is local to the caller) we
10278 can get a situation where the DECL_RTL of the artificial local
10279 variable (for the inlining) which acts as a stand-in for the
10280 corresponding formal parameter (of the inline function) will look
10281 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10282 exactly a compile-time constant expression, but it isn't the address
10283 of the (artificial) local variable either. Rather, it represents the
10284 *value* which the artificial local variable always has during its
10285 lifetime. We currently have no way to represent such quasi-constant
10286 values in Dwarf, so for now we just punt and generate nothing. */
10290 /* No other kinds of rtx should be possible here. */
10291 gcc_unreachable ();
10296 /* Determine whether the evaluation of EXPR references any variables
10297 or functions which aren't otherwise used (and therefore may not be
10300 reference_to_unused (tree * tp, int * walk_subtrees,
10301 void * data ATTRIBUTE_UNUSED)
10303 if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10304 *walk_subtrees = 0;
10306 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10307 && ! TREE_ASM_WRITTEN (*tp))
10309 else if (!flag_unit_at_a_time)
10311 else if (!cgraph_global_info_ready
10312 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10313 gcc_unreachable ();
10314 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10316 struct varpool_node *node = varpool_node (*tp);
10320 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10321 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10323 struct cgraph_node *node = cgraph_node (*tp);
10331 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10332 for use in a later add_const_value_attribute call. */
10335 rtl_for_decl_init (tree init, tree type)
10337 rtx rtl = NULL_RTX;
10339 /* If a variable is initialized with a string constant without embedded
10340 zeros, build CONST_STRING. */
10341 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10343 tree enttype = TREE_TYPE (type);
10344 tree domain = TYPE_DOMAIN (type);
10345 enum machine_mode mode = TYPE_MODE (enttype);
10347 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10349 && integer_zerop (TYPE_MIN_VALUE (domain))
10350 && compare_tree_int (TYPE_MAX_VALUE (domain),
10351 TREE_STRING_LENGTH (init) - 1) == 0
10352 && ((size_t) TREE_STRING_LENGTH (init)
10353 == strlen (TREE_STRING_POINTER (init)) + 1))
10354 rtl = gen_rtx_CONST_STRING (VOIDmode,
10355 ggc_strdup (TREE_STRING_POINTER (init)));
10357 /* Other aggregates, and complex values, could be represented using
10359 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10361 /* Vectors only work if their mode is supported by the target.
10362 FIXME: generic vectors ought to work too. */
10363 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10365 /* If the initializer is something that we know will expand into an
10366 immediate RTL constant, expand it now. We must be careful not to
10367 reference variables which won't be output. */
10368 else if (initializer_constant_valid_p (init, type)
10369 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10371 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10373 /* If expand_expr returns a MEM, it wasn't immediate. */
10374 gcc_assert (!rtl || !MEM_P (rtl));
10380 /* Generate RTL for the variable DECL to represent its location. */
10383 rtl_for_decl_location (tree decl)
10387 /* Here we have to decide where we are going to say the parameter "lives"
10388 (as far as the debugger is concerned). We only have a couple of
10389 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10391 DECL_RTL normally indicates where the parameter lives during most of the
10392 activation of the function. If optimization is enabled however, this
10393 could be either NULL or else a pseudo-reg. Both of those cases indicate
10394 that the parameter doesn't really live anywhere (as far as the code
10395 generation parts of GCC are concerned) during most of the function's
10396 activation. That will happen (for example) if the parameter is never
10397 referenced within the function.
10399 We could just generate a location descriptor here for all non-NULL
10400 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10401 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10402 where DECL_RTL is NULL or is a pseudo-reg.
10404 Note however that we can only get away with using DECL_INCOMING_RTL as
10405 a backup substitute for DECL_RTL in certain limited cases. In cases
10406 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10407 we can be sure that the parameter was passed using the same type as it is
10408 declared to have within the function, and that its DECL_INCOMING_RTL
10409 points us to a place where a value of that type is passed.
10411 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10412 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10413 because in these cases DECL_INCOMING_RTL points us to a value of some
10414 type which is *different* from the type of the parameter itself. Thus,
10415 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10416 such cases, the debugger would end up (for example) trying to fetch a
10417 `float' from a place which actually contains the first part of a
10418 `double'. That would lead to really incorrect and confusing
10419 output at debug-time.
10421 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10422 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10423 are a couple of exceptions however. On little-endian machines we can
10424 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10425 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10426 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10427 when (on a little-endian machine) a non-prototyped function has a
10428 parameter declared to be of type `short' or `char'. In such cases,
10429 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10430 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10431 passed `int' value. If the debugger then uses that address to fetch
10432 a `short' or a `char' (on a little-endian machine) the result will be
10433 the correct data, so we allow for such exceptional cases below.
10435 Note that our goal here is to describe the place where the given formal
10436 parameter lives during most of the function's activation (i.e. between the
10437 end of the prologue and the start of the epilogue). We'll do that as best
10438 as we can. Note however that if the given formal parameter is modified
10439 sometime during the execution of the function, then a stack backtrace (at
10440 debug-time) will show the function as having been called with the *new*
10441 value rather than the value which was originally passed in. This happens
10442 rarely enough that it is not a major problem, but it *is* a problem, and
10443 I'd like to fix it.
10445 A future version of dwarf2out.c may generate two additional attributes for
10446 any given DW_TAG_formal_parameter DIE which will describe the "passed
10447 type" and the "passed location" for the given formal parameter in addition
10448 to the attributes we now generate to indicate the "declared type" and the
10449 "active location" for each parameter. This additional set of attributes
10450 could be used by debuggers for stack backtraces. Separately, note that
10451 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10452 This happens (for example) for inlined-instances of inline function formal
10453 parameters which are never referenced. This really shouldn't be
10454 happening. All PARM_DECL nodes should get valid non-NULL
10455 DECL_INCOMING_RTL values. FIXME. */
10457 /* Use DECL_RTL as the "location" unless we find something better. */
10458 rtl = DECL_RTL_IF_SET (decl);
10460 /* When generating abstract instances, ignore everything except
10461 constants, symbols living in memory, and symbols living in
10462 fixed registers. */
10463 if (! reload_completed)
10466 && (CONSTANT_P (rtl)
10468 && CONSTANT_P (XEXP (rtl, 0)))
10470 && TREE_CODE (decl) == VAR_DECL
10471 && TREE_STATIC (decl))))
10473 rtl = targetm.delegitimize_address (rtl);
10478 else if (TREE_CODE (decl) == PARM_DECL)
10480 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10482 tree declared_type = TREE_TYPE (decl);
10483 tree passed_type = DECL_ARG_TYPE (decl);
10484 enum machine_mode dmode = TYPE_MODE (declared_type);
10485 enum machine_mode pmode = TYPE_MODE (passed_type);
10487 /* This decl represents a formal parameter which was optimized out.
10488 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10489 all cases where (rtl == NULL_RTX) just below. */
10490 if (dmode == pmode)
10491 rtl = DECL_INCOMING_RTL (decl);
10492 else if (SCALAR_INT_MODE_P (dmode)
10493 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10494 && DECL_INCOMING_RTL (decl))
10496 rtx inc = DECL_INCOMING_RTL (decl);
10499 else if (MEM_P (inc))
10501 if (BYTES_BIG_ENDIAN)
10502 rtl = adjust_address_nv (inc, dmode,
10503 GET_MODE_SIZE (pmode)
10504 - GET_MODE_SIZE (dmode));
10511 /* If the parm was passed in registers, but lives on the stack, then
10512 make a big endian correction if the mode of the type of the
10513 parameter is not the same as the mode of the rtl. */
10514 /* ??? This is the same series of checks that are made in dbxout.c before
10515 we reach the big endian correction code there. It isn't clear if all
10516 of these checks are necessary here, but keeping them all is the safe
10518 else if (MEM_P (rtl)
10519 && XEXP (rtl, 0) != const0_rtx
10520 && ! CONSTANT_P (XEXP (rtl, 0))
10521 /* Not passed in memory. */
10522 && !MEM_P (DECL_INCOMING_RTL (decl))
10523 /* Not passed by invisible reference. */
10524 && (!REG_P (XEXP (rtl, 0))
10525 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10526 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10527 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10528 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10531 /* Big endian correction check. */
10532 && BYTES_BIG_ENDIAN
10533 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10534 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10537 int offset = (UNITS_PER_WORD
10538 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10540 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10541 plus_constant (XEXP (rtl, 0), offset));
10544 else if (TREE_CODE (decl) == VAR_DECL
10547 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10548 && BYTES_BIG_ENDIAN)
10550 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10551 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10553 /* If a variable is declared "register" yet is smaller than
10554 a register, then if we store the variable to memory, it
10555 looks like we're storing a register-sized value, when in
10556 fact we are not. We need to adjust the offset of the
10557 storage location to reflect the actual value's bytes,
10558 else gdb will not be able to display it. */
10560 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10561 plus_constant (XEXP (rtl, 0), rsize-dsize));
10564 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10565 and will have been substituted directly into all expressions that use it.
10566 C does not have such a concept, but C++ and other languages do. */
10567 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10568 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10571 rtl = targetm.delegitimize_address (rtl);
10573 /* If we don't look past the constant pool, we risk emitting a
10574 reference to a constant pool entry that isn't referenced from
10575 code, and thus is not emitted. */
10577 rtl = avoid_constant_pool_reference (rtl);
10582 /* We need to figure out what section we should use as the base for the
10583 address ranges where a given location is valid.
10584 1. If this particular DECL has a section associated with it, use that.
10585 2. If this function has a section associated with it, use that.
10586 3. Otherwise, use the text section.
10587 XXX: If you split a variable across multiple sections, we won't notice. */
10589 static const char *
10590 secname_for_decl (tree decl)
10592 const char *secname;
10594 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10596 tree sectree = DECL_SECTION_NAME (decl);
10597 secname = TREE_STRING_POINTER (sectree);
10599 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10601 tree sectree = DECL_SECTION_NAME (current_function_decl);
10602 secname = TREE_STRING_POINTER (sectree);
10604 else if (cfun && in_cold_section_p)
10605 secname = cfun->cold_section_label;
10607 secname = text_section_label;
10612 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10613 data attribute for a variable or a parameter. We generate the
10614 DW_AT_const_value attribute only in those cases where the given variable
10615 or parameter does not have a true "location" either in memory or in a
10616 register. This can happen (for example) when a constant is passed as an
10617 actual argument in a call to an inline function. (It's possible that
10618 these things can crop up in other ways also.) Note that one type of
10619 constant value which can be passed into an inlined function is a constant
10620 pointer. This can happen for example if an actual argument in an inlined
10621 function call evaluates to a compile-time constant address. */
10624 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10625 enum dwarf_attribute attr)
10628 dw_loc_descr_ref descr;
10629 var_loc_list *loc_list;
10630 struct var_loc_node *node;
10631 if (TREE_CODE (decl) == ERROR_MARK)
10634 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10635 || TREE_CODE (decl) == RESULT_DECL);
10637 /* See if we possibly have multiple locations for this variable. */
10638 loc_list = lookup_decl_loc (decl);
10640 /* If it truly has multiple locations, the first and last node will
10642 if (loc_list && loc_list->first != loc_list->last)
10644 const char *endname, *secname;
10645 dw_loc_list_ref list;
10647 enum var_init_status initialized;
10649 /* Now that we know what section we are using for a base,
10650 actually construct the list of locations.
10651 The first location information is what is passed to the
10652 function that creates the location list, and the remaining
10653 locations just get added on to that list.
10654 Note that we only know the start address for a location
10655 (IE location changes), so to build the range, we use
10656 the range [current location start, next location start].
10657 This means we have to special case the last node, and generate
10658 a range of [last location start, end of function label]. */
10660 node = loc_list->first;
10661 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10662 secname = secname_for_decl (decl);
10664 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
10665 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10667 initialized = VAR_INIT_STATUS_INITIALIZED;
10669 list = new_loc_list (loc_descriptor (varloc, initialized),
10670 node->label, node->next->label, secname, 1);
10673 for (; node->next; node = node->next)
10674 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10676 /* The variable has a location between NODE->LABEL and
10677 NODE->NEXT->LABEL. */
10678 enum var_init_status initialized =
10679 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10680 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10681 add_loc_descr_to_loc_list (&list,
10682 loc_descriptor (varloc, initialized),
10683 node->label, node->next->label, secname);
10686 /* If the variable has a location at the last label
10687 it keeps its location until the end of function. */
10688 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10690 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10691 enum var_init_status initialized =
10692 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10694 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10695 if (!current_function_decl)
10696 endname = text_end_label;
10699 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10700 current_function_funcdef_no);
10701 endname = ggc_strdup (label_id);
10703 add_loc_descr_to_loc_list (&list,
10704 loc_descriptor (varloc, initialized),
10705 node->label, endname, secname);
10708 /* Finally, add the location list to the DIE, and we are done. */
10709 add_AT_loc_list (die, attr, list);
10713 /* Try to get some constant RTL for this decl, and use that as the value of
10716 rtl = rtl_for_decl_location (decl);
10717 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10719 add_const_value_attribute (die, rtl);
10723 /* If we have tried to generate the location otherwise, and it
10724 didn't work out (we wouldn't be here if we did), and we have a one entry
10725 location list, try generating a location from that. */
10726 if (loc_list && loc_list->first)
10728 enum var_init_status status;
10729 node = loc_list->first;
10730 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10731 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
10734 add_AT_location_description (die, attr, descr);
10739 /* We couldn't get any rtl, so try directly generating the location
10740 description from the tree. */
10741 descr = loc_descriptor_from_tree (decl);
10744 add_AT_location_description (die, attr, descr);
10747 /* None of that worked, so it must not really have a location;
10748 try adding a constant value attribute from the DECL_INITIAL. */
10749 tree_add_const_value_attribute (die, decl);
10752 /* If we don't have a copy of this variable in memory for some reason (such
10753 as a C++ member constant that doesn't have an out-of-line definition),
10754 we should tell the debugger about the constant value. */
10757 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10759 tree init = DECL_INITIAL (decl);
10760 tree type = TREE_TYPE (decl);
10763 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10768 rtl = rtl_for_decl_init (init, type);
10770 add_const_value_attribute (var_die, rtl);
10773 /* Convert the CFI instructions for the current function into a
10774 location list. This is used for DW_AT_frame_base when we targeting
10775 a dwarf2 consumer that does not support the dwarf3
10776 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10779 static dw_loc_list_ref
10780 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10783 dw_loc_list_ref list, *list_tail;
10785 dw_cfa_location last_cfa, next_cfa;
10786 const char *start_label, *last_label, *section;
10788 fde = &fde_table[fde_table_in_use - 1];
10790 section = secname_for_decl (current_function_decl);
10794 next_cfa.reg = INVALID_REGNUM;
10795 next_cfa.offset = 0;
10796 next_cfa.indirect = 0;
10797 next_cfa.base_offset = 0;
10799 start_label = fde->dw_fde_begin;
10801 /* ??? Bald assumption that the CIE opcode list does not contain
10802 advance opcodes. */
10803 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10804 lookup_cfa_1 (cfi, &next_cfa);
10806 last_cfa = next_cfa;
10807 last_label = start_label;
10809 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10810 switch (cfi->dw_cfi_opc)
10812 case DW_CFA_set_loc:
10813 case DW_CFA_advance_loc1:
10814 case DW_CFA_advance_loc2:
10815 case DW_CFA_advance_loc4:
10816 if (!cfa_equal_p (&last_cfa, &next_cfa))
10818 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10819 start_label, last_label, section,
10822 list_tail = &(*list_tail)->dw_loc_next;
10823 last_cfa = next_cfa;
10824 start_label = last_label;
10826 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10829 case DW_CFA_advance_loc:
10830 /* The encoding is complex enough that we should never emit this. */
10831 case DW_CFA_remember_state:
10832 case DW_CFA_restore_state:
10833 /* We don't handle these two in this function. It would be possible
10834 if it were to be required. */
10835 gcc_unreachable ();
10838 lookup_cfa_1 (cfi, &next_cfa);
10842 if (!cfa_equal_p (&last_cfa, &next_cfa))
10844 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10845 start_label, last_label, section,
10847 list_tail = &(*list_tail)->dw_loc_next;
10848 start_label = last_label;
10850 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
10851 start_label, fde->dw_fde_end, section,
10857 /* Compute a displacement from the "steady-state frame pointer" to the
10858 frame base (often the same as the CFA), and store it in
10859 frame_pointer_fb_offset. OFFSET is added to the displacement
10860 before the latter is negated. */
10863 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
10867 #ifdef FRAME_POINTER_CFA_OFFSET
10868 reg = frame_pointer_rtx;
10869 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
10871 reg = arg_pointer_rtx;
10872 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
10875 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10876 if (GET_CODE (elim) == PLUS)
10878 offset += INTVAL (XEXP (elim, 1));
10879 elim = XEXP (elim, 0);
10881 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10882 : stack_pointer_rtx));
10884 frame_pointer_fb_offset = -offset;
10887 /* Generate a DW_AT_name attribute given some string value to be included as
10888 the value of the attribute. */
10891 add_name_attribute (dw_die_ref die, const char *name_string)
10893 if (name_string != NULL && *name_string != 0)
10895 if (demangle_name_func)
10896 name_string = (*demangle_name_func) (name_string);
10898 add_AT_string (die, DW_AT_name, name_string);
10902 /* Generate a DW_AT_comp_dir attribute for DIE. */
10905 add_comp_dir_attribute (dw_die_ref die)
10907 const char *wd = get_src_pwd ();
10909 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
10912 /* Given a tree node describing an array bound (either lower or upper) output
10913 a representation for that bound. */
10916 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10918 switch (TREE_CODE (bound))
10923 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10925 if (! host_integerp (bound, 0)
10926 || (bound_attr == DW_AT_lower_bound
10927 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10928 || (is_fortran () && integer_onep (bound)))))
10929 /* Use the default. */
10932 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10937 case NON_LVALUE_EXPR:
10938 case VIEW_CONVERT_EXPR:
10939 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10949 dw_die_ref decl_die = lookup_decl_die (bound);
10951 /* ??? Can this happen, or should the variable have been bound
10952 first? Probably it can, since I imagine that we try to create
10953 the types of parameters in the order in which they exist in
10954 the list, and won't have created a forward reference to a
10955 later parameter. */
10956 if (decl_die != NULL)
10957 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10963 /* Otherwise try to create a stack operation procedure to
10964 evaluate the value of the array bound. */
10966 dw_die_ref ctx, decl_die;
10967 dw_loc_descr_ref loc;
10969 loc = loc_descriptor_from_tree (bound);
10973 if (current_function_decl == 0)
10974 ctx = comp_unit_die;
10976 ctx = lookup_decl_die (current_function_decl);
10978 decl_die = new_die (DW_TAG_variable, ctx, bound);
10979 add_AT_flag (decl_die, DW_AT_artificial, 1);
10980 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10981 add_AT_loc (decl_die, DW_AT_location, loc);
10983 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10989 /* Note that the block of subscript information for an array type also
10990 includes information about the element type of type given array type. */
10993 add_subscript_info (dw_die_ref type_die, tree type)
10995 #ifndef MIPS_DEBUGGING_INFO
10996 unsigned dimension_number;
10999 dw_die_ref subrange_die;
11001 /* The GNU compilers represent multidimensional array types as sequences of
11002 one dimensional array types whose element types are themselves array
11003 types. Here we squish that down, so that each multidimensional array
11004 type gets only one array_type DIE in the Dwarf debugging info. The draft
11005 Dwarf specification say that we are allowed to do this kind of
11006 compression in C (because there is no difference between an array or
11007 arrays and a multidimensional array in C) but for other source languages
11008 (e.g. Ada) we probably shouldn't do this. */
11010 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11011 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11012 We work around this by disabling this feature. See also
11013 gen_array_type_die. */
11014 #ifndef MIPS_DEBUGGING_INFO
11015 for (dimension_number = 0;
11016 TREE_CODE (type) == ARRAY_TYPE;
11017 type = TREE_TYPE (type), dimension_number++)
11020 tree domain = TYPE_DOMAIN (type);
11022 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11023 and (in GNU C only) variable bounds. Handle all three forms
11025 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11028 /* We have an array type with specified bounds. */
11029 lower = TYPE_MIN_VALUE (domain);
11030 upper = TYPE_MAX_VALUE (domain);
11032 /* Define the index type. */
11033 if (TREE_TYPE (domain))
11035 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11036 TREE_TYPE field. We can't emit debug info for this
11037 because it is an unnamed integral type. */
11038 if (TREE_CODE (domain) == INTEGER_TYPE
11039 && TYPE_NAME (domain) == NULL_TREE
11040 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11041 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11044 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11048 /* ??? If upper is NULL, the array has unspecified length,
11049 but it does have a lower bound. This happens with Fortran
11051 Since the debugger is definitely going to need to know N
11052 to produce useful results, go ahead and output the lower
11053 bound solo, and hope the debugger can cope. */
11055 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11057 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11060 /* Otherwise we have an array type with an unspecified length. The
11061 DWARF-2 spec does not say how to handle this; let's just leave out the
11067 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11071 switch (TREE_CODE (tree_node))
11076 case ENUMERAL_TYPE:
11079 case QUAL_UNION_TYPE:
11080 size = int_size_in_bytes (tree_node);
11083 /* For a data member of a struct or union, the DW_AT_byte_size is
11084 generally given as the number of bytes normally allocated for an
11085 object of the *declared* type of the member itself. This is true
11086 even for bit-fields. */
11087 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11090 gcc_unreachable ();
11093 /* Note that `size' might be -1 when we get to this point. If it is, that
11094 indicates that the byte size of the entity in question is variable. We
11095 have no good way of expressing this fact in Dwarf at the present time,
11096 so just let the -1 pass on through. */
11097 add_AT_unsigned (die, DW_AT_byte_size, size);
11100 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11101 which specifies the distance in bits from the highest order bit of the
11102 "containing object" for the bit-field to the highest order bit of the
11105 For any given bit-field, the "containing object" is a hypothetical object
11106 (of some integral or enum type) within which the given bit-field lives. The
11107 type of this hypothetical "containing object" is always the same as the
11108 declared type of the individual bit-field itself. The determination of the
11109 exact location of the "containing object" for a bit-field is rather
11110 complicated. It's handled by the `field_byte_offset' function (above).
11112 Note that it is the size (in bytes) of the hypothetical "containing object"
11113 which will be given in the DW_AT_byte_size attribute for this bit-field.
11114 (See `byte_size_attribute' above). */
11117 add_bit_offset_attribute (dw_die_ref die, tree decl)
11119 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11120 tree type = DECL_BIT_FIELD_TYPE (decl);
11121 HOST_WIDE_INT bitpos_int;
11122 HOST_WIDE_INT highest_order_object_bit_offset;
11123 HOST_WIDE_INT highest_order_field_bit_offset;
11124 HOST_WIDE_INT unsigned bit_offset;
11126 /* Must be a field and a bit field. */
11127 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11129 /* We can't yet handle bit-fields whose offsets are variable, so if we
11130 encounter such things, just return without generating any attribute
11131 whatsoever. Likewise for variable or too large size. */
11132 if (! host_integerp (bit_position (decl), 0)
11133 || ! host_integerp (DECL_SIZE (decl), 1))
11136 bitpos_int = int_bit_position (decl);
11138 /* Note that the bit offset is always the distance (in bits) from the
11139 highest-order bit of the "containing object" to the highest-order bit of
11140 the bit-field itself. Since the "high-order end" of any object or field
11141 is different on big-endian and little-endian machines, the computation
11142 below must take account of these differences. */
11143 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11144 highest_order_field_bit_offset = bitpos_int;
11146 if (! BYTES_BIG_ENDIAN)
11148 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11149 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11153 = (! BYTES_BIG_ENDIAN
11154 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11155 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11157 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11160 /* For a FIELD_DECL node which represents a bit field, output an attribute
11161 which specifies the length in bits of the given field. */
11164 add_bit_size_attribute (dw_die_ref die, tree decl)
11166 /* Must be a field and a bit field. */
11167 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11168 && DECL_BIT_FIELD_TYPE (decl));
11170 if (host_integerp (DECL_SIZE (decl), 1))
11171 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11174 /* If the compiled language is ANSI C, then add a 'prototyped'
11175 attribute, if arg types are given for the parameters of a function. */
11178 add_prototyped_attribute (dw_die_ref die, tree func_type)
11180 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11181 && TYPE_ARG_TYPES (func_type) != NULL)
11182 add_AT_flag (die, DW_AT_prototyped, 1);
11185 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11186 by looking in either the type declaration or object declaration
11190 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11192 dw_die_ref origin_die = NULL;
11194 if (TREE_CODE (origin) != FUNCTION_DECL)
11196 /* We may have gotten separated from the block for the inlined
11197 function, if we're in an exception handler or some such; make
11198 sure that the abstract function has been written out.
11200 Doing this for nested functions is wrong, however; functions are
11201 distinct units, and our context might not even be inline. */
11205 fn = TYPE_STUB_DECL (fn);
11207 fn = decl_function_context (fn);
11209 dwarf2out_abstract_function (fn);
11212 if (DECL_P (origin))
11213 origin_die = lookup_decl_die (origin);
11214 else if (TYPE_P (origin))
11215 origin_die = lookup_type_die (origin);
11217 /* XXX: Functions that are never lowered don't always have correct block
11218 trees (in the case of java, they simply have no block tree, in some other
11219 languages). For these functions, there is nothing we can really do to
11220 output correct debug info for inlined functions in all cases. Rather
11221 than die, we'll just produce deficient debug info now, in that we will
11222 have variables without a proper abstract origin. In the future, when all
11223 functions are lowered, we should re-add a gcc_assert (origin_die)
11227 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11230 /* We do not currently support the pure_virtual attribute. */
11233 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11235 if (DECL_VINDEX (func_decl))
11237 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11239 if (host_integerp (DECL_VINDEX (func_decl), 0))
11240 add_AT_loc (die, DW_AT_vtable_elem_location,
11241 new_loc_descr (DW_OP_constu,
11242 tree_low_cst (DECL_VINDEX (func_decl), 0),
11245 /* GNU extension: Record what type this method came from originally. */
11246 if (debug_info_level > DINFO_LEVEL_TERSE)
11247 add_AT_die_ref (die, DW_AT_containing_type,
11248 lookup_type_die (DECL_CONTEXT (func_decl)));
11252 /* Add source coordinate attributes for the given decl. */
11255 add_src_coords_attributes (dw_die_ref die, tree decl)
11257 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11259 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11260 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11263 /* Add a DW_AT_name attribute and source coordinate attribute for the
11264 given decl, but only if it actually has a name. */
11267 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11271 decl_name = DECL_NAME (decl);
11272 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11274 add_name_attribute (die, dwarf2_name (decl, 0));
11275 if (! DECL_ARTIFICIAL (decl))
11276 add_src_coords_attributes (die, decl);
11278 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11279 && TREE_PUBLIC (decl)
11280 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11281 && !DECL_ABSTRACT (decl)
11282 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)))
11283 add_AT_string (die, DW_AT_MIPS_linkage_name,
11284 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11287 #ifdef VMS_DEBUGGING_INFO
11288 /* Get the function's name, as described by its RTL. This may be different
11289 from the DECL_NAME name used in the source file. */
11290 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11292 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11293 XEXP (DECL_RTL (decl), 0));
11294 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11299 /* Push a new declaration scope. */
11302 push_decl_scope (tree scope)
11304 VEC_safe_push (tree, gc, decl_scope_table, scope);
11307 /* Pop a declaration scope. */
11310 pop_decl_scope (void)
11312 VEC_pop (tree, decl_scope_table);
11315 /* Return the DIE for the scope that immediately contains this type.
11316 Non-named types get global scope. Named types nested in other
11317 types get their containing scope if it's open, or global scope
11318 otherwise. All other types (i.e. function-local named types) get
11319 the current active scope. */
11322 scope_die_for (tree t, dw_die_ref context_die)
11324 dw_die_ref scope_die = NULL;
11325 tree containing_scope;
11328 /* Non-types always go in the current scope. */
11329 gcc_assert (TYPE_P (t));
11331 containing_scope = TYPE_CONTEXT (t);
11333 /* Use the containing namespace if it was passed in (for a declaration). */
11334 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11336 if (context_die == lookup_decl_die (containing_scope))
11339 containing_scope = NULL_TREE;
11342 /* Ignore function type "scopes" from the C frontend. They mean that
11343 a tagged type is local to a parmlist of a function declarator, but
11344 that isn't useful to DWARF. */
11345 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11346 containing_scope = NULL_TREE;
11348 if (containing_scope == NULL_TREE)
11349 scope_die = comp_unit_die;
11350 else if (TYPE_P (containing_scope))
11352 /* For types, we can just look up the appropriate DIE. But
11353 first we check to see if we're in the middle of emitting it
11354 so we know where the new DIE should go. */
11355 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11356 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11361 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11362 || TREE_ASM_WRITTEN (containing_scope));
11364 /* If none of the current dies are suitable, we get file scope. */
11365 scope_die = comp_unit_die;
11368 scope_die = lookup_type_die (containing_scope);
11371 scope_die = context_die;
11376 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11379 local_scope_p (dw_die_ref context_die)
11381 for (; context_die; context_die = context_die->die_parent)
11382 if (context_die->die_tag == DW_TAG_inlined_subroutine
11383 || context_die->die_tag == DW_TAG_subprogram)
11389 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11390 whether or not to treat a DIE in this context as a declaration. */
11393 class_or_namespace_scope_p (dw_die_ref context_die)
11395 return (context_die
11396 && (context_die->die_tag == DW_TAG_structure_type
11397 || context_die->die_tag == DW_TAG_union_type
11398 || context_die->die_tag == DW_TAG_namespace));
11401 /* Many forms of DIEs require a "type description" attribute. This
11402 routine locates the proper "type descriptor" die for the type given
11403 by 'type', and adds a DW_AT_type attribute below the given die. */
11406 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11407 int decl_volatile, dw_die_ref context_die)
11409 enum tree_code code = TREE_CODE (type);
11410 dw_die_ref type_die = NULL;
11412 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11413 or fixed-point type, use the inner type. This is because we have no
11414 support for unnamed types in base_type_die. This can happen if this is
11415 an Ada subrange type. Correct solution is emit a subrange type die. */
11416 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
11417 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11418 type = TREE_TYPE (type), code = TREE_CODE (type);
11420 if (code == ERROR_MARK
11421 /* Handle a special case. For functions whose return type is void, we
11422 generate *no* type attribute. (Note that no object may have type
11423 `void', so this only applies to function return types). */
11424 || code == VOID_TYPE)
11427 type_die = modified_type_die (type,
11428 decl_const || TYPE_READONLY (type),
11429 decl_volatile || TYPE_VOLATILE (type),
11432 if (type_die != NULL)
11433 add_AT_die_ref (object_die, DW_AT_type, type_die);
11436 /* Given an object die, add the calling convention attribute for the
11437 function call type. */
11439 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
11441 enum dwarf_calling_convention value = DW_CC_normal;
11443 value = targetm.dwarf_calling_convention (type);
11445 /* Only add the attribute if the backend requests it, and
11446 is not DW_CC_normal. */
11447 if (value && (value != DW_CC_normal))
11448 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11451 /* Given a tree pointer to a struct, class, union, or enum type node, return
11452 a pointer to the (string) tag name for the given type, or zero if the type
11453 was declared without a tag. */
11455 static const char *
11456 type_tag (tree type)
11458 const char *name = 0;
11460 if (TYPE_NAME (type) != 0)
11464 /* Find the IDENTIFIER_NODE for the type name. */
11465 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11466 t = TYPE_NAME (type);
11468 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11469 a TYPE_DECL node, regardless of whether or not a `typedef' was
11471 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11472 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11474 /* We want to be extra verbose. Don't call dwarf_name if
11475 DECL_NAME isn't set. The default hook for decl_printable_name
11476 doesn't like that, and in this context it's correct to return
11477 0, instead of "<anonymous>" or the like. */
11478 if (DECL_NAME (TYPE_NAME (type)))
11479 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11482 /* Now get the name as a string, or invent one. */
11483 if (!name && t != 0)
11484 name = IDENTIFIER_POINTER (t);
11487 return (name == 0 || *name == '\0') ? 0 : name;
11490 /* Return the type associated with a data member, make a special check
11491 for bit field types. */
11494 member_declared_type (tree member)
11496 return (DECL_BIT_FIELD_TYPE (member)
11497 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11500 /* Get the decl's label, as described by its RTL. This may be different
11501 from the DECL_NAME name used in the source file. */
11504 static const char *
11505 decl_start_label (tree decl)
11508 const char *fnname;
11510 x = DECL_RTL (decl);
11511 gcc_assert (MEM_P (x));
11514 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11516 fnname = XSTR (x, 0);
11521 /* These routines generate the internal representation of the DIE's for
11522 the compilation unit. Debugging information is collected by walking
11523 the declaration trees passed in from dwarf2out_decl(). */
11526 gen_array_type_die (tree type, dw_die_ref context_die)
11528 dw_die_ref scope_die = scope_die_for (type, context_die);
11529 dw_die_ref array_die;
11532 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11533 the inner array type comes before the outer array type. Thus we must
11534 call gen_type_die before we call new_die. See below also. */
11535 #ifdef MIPS_DEBUGGING_INFO
11536 gen_type_die (TREE_TYPE (type), context_die);
11539 array_die = new_die (DW_TAG_array_type, scope_die, type);
11540 add_name_attribute (array_die, type_tag (type));
11541 equate_type_number_to_die (type, array_die);
11543 if (TREE_CODE (type) == VECTOR_TYPE)
11545 /* The frontend feeds us a representation for the vector as a struct
11546 containing an array. Pull out the array type. */
11547 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11548 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11552 /* We default the array ordering. SDB will probably do
11553 the right things even if DW_AT_ordering is not present. It's not even
11554 an issue until we start to get into multidimensional arrays anyway. If
11555 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11556 then we'll have to put the DW_AT_ordering attribute back in. (But if
11557 and when we find out that we need to put these in, we will only do so
11558 for multidimensional arrays. */
11559 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11562 #ifdef MIPS_DEBUGGING_INFO
11563 /* The SGI compilers handle arrays of unknown bound by setting
11564 AT_declaration and not emitting any subrange DIEs. */
11565 if (! TYPE_DOMAIN (type))
11566 add_AT_flag (array_die, DW_AT_declaration, 1);
11569 add_subscript_info (array_die, type);
11571 /* Add representation of the type of the elements of this array type. */
11572 element_type = TREE_TYPE (type);
11574 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11575 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11576 We work around this by disabling this feature. See also
11577 add_subscript_info. */
11578 #ifndef MIPS_DEBUGGING_INFO
11579 while (TREE_CODE (element_type) == ARRAY_TYPE)
11580 element_type = TREE_TYPE (element_type);
11582 gen_type_die (element_type, context_die);
11585 add_type_attribute (array_die, element_type, 0, 0, context_die);
11587 if (get_AT (array_die, DW_AT_name))
11588 add_pubtype (type, array_die);
11593 gen_entry_point_die (tree decl, dw_die_ref context_die)
11595 tree origin = decl_ultimate_origin (decl);
11596 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11598 if (origin != NULL)
11599 add_abstract_origin_attribute (decl_die, origin);
11602 add_name_and_src_coords_attributes (decl_die, decl);
11603 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11604 0, 0, context_die);
11607 if (DECL_ABSTRACT (decl))
11608 equate_decl_number_to_die (decl, decl_die);
11610 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11614 /* Walk through the list of incomplete types again, trying once more to
11615 emit full debugging info for them. */
11618 retry_incomplete_types (void)
11622 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11623 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11626 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11629 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11631 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11633 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11634 be incomplete and such types are not marked. */
11635 add_abstract_origin_attribute (type_die, type);
11638 /* Generate a DIE to represent an inlined instance of a structure type. */
11641 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11643 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11645 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11646 be incomplete and such types are not marked. */
11647 add_abstract_origin_attribute (type_die, type);
11650 /* Generate a DIE to represent an inlined instance of a union type. */
11653 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11655 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11657 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11658 be incomplete and such types are not marked. */
11659 add_abstract_origin_attribute (type_die, type);
11662 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11663 include all of the information about the enumeration values also. Each
11664 enumerated type name/value is listed as a child of the enumerated type
11668 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11670 dw_die_ref type_die = lookup_type_die (type);
11672 if (type_die == NULL)
11674 type_die = new_die (DW_TAG_enumeration_type,
11675 scope_die_for (type, context_die), type);
11676 equate_type_number_to_die (type, type_die);
11677 add_name_attribute (type_die, type_tag (type));
11679 else if (! TYPE_SIZE (type))
11682 remove_AT (type_die, DW_AT_declaration);
11684 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11685 given enum type is incomplete, do not generate the DW_AT_byte_size
11686 attribute or the DW_AT_element_list attribute. */
11687 if (TYPE_SIZE (type))
11691 TREE_ASM_WRITTEN (type) = 1;
11692 add_byte_size_attribute (type_die, type);
11693 if (TYPE_STUB_DECL (type) != NULL_TREE)
11694 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11696 /* If the first reference to this type was as the return type of an
11697 inline function, then it may not have a parent. Fix this now. */
11698 if (type_die->die_parent == NULL)
11699 add_child_die (scope_die_for (type, context_die), type_die);
11701 for (link = TYPE_VALUES (type);
11702 link != NULL; link = TREE_CHAIN (link))
11704 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11705 tree value = TREE_VALUE (link);
11707 add_name_attribute (enum_die,
11708 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11710 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11711 /* DWARF2 does not provide a way of indicating whether or
11712 not enumeration constants are signed or unsigned. GDB
11713 always assumes the values are signed, so we output all
11714 values as if they were signed. That means that
11715 enumeration constants with very large unsigned values
11716 will appear to have negative values in the debugger. */
11717 add_AT_int (enum_die, DW_AT_const_value,
11718 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11722 add_AT_flag (type_die, DW_AT_declaration, 1);
11724 if (get_AT (type_die, DW_AT_name))
11725 add_pubtype (type, type_die);
11730 /* Generate a DIE to represent either a real live formal parameter decl or to
11731 represent just the type of some formal parameter position in some function
11734 Note that this routine is a bit unusual because its argument may be a
11735 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11736 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11737 node. If it's the former then this function is being called to output a
11738 DIE to represent a formal parameter object (or some inlining thereof). If
11739 it's the latter, then this function is only being called to output a
11740 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11741 argument type of some subprogram type. */
11744 gen_formal_parameter_die (tree node, dw_die_ref context_die)
11746 dw_die_ref parm_die
11747 = new_die (DW_TAG_formal_parameter, context_die, node);
11750 switch (TREE_CODE_CLASS (TREE_CODE (node)))
11752 case tcc_declaration:
11753 origin = decl_ultimate_origin (node);
11754 if (origin != NULL)
11755 add_abstract_origin_attribute (parm_die, origin);
11758 add_name_and_src_coords_attributes (parm_die, node);
11759 add_type_attribute (parm_die, TREE_TYPE (node),
11760 TREE_READONLY (node),
11761 TREE_THIS_VOLATILE (node),
11763 if (DECL_ARTIFICIAL (node))
11764 add_AT_flag (parm_die, DW_AT_artificial, 1);
11767 equate_decl_number_to_die (node, parm_die);
11768 if (! DECL_ABSTRACT (node))
11769 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11774 /* We were called with some kind of a ..._TYPE node. */
11775 add_type_attribute (parm_die, node, 0, 0, context_die);
11779 gcc_unreachable ();
11785 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11786 at the end of an (ANSI prototyped) formal parameters list. */
11789 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11791 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11794 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11795 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11796 parameters as specified in some function type specification (except for
11797 those which appear as part of a function *definition*). */
11800 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11803 tree formal_type = NULL;
11804 tree first_parm_type;
11807 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11809 arg = DECL_ARGUMENTS (function_or_method_type);
11810 function_or_method_type = TREE_TYPE (function_or_method_type);
11815 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11817 /* Make our first pass over the list of formal parameter types and output a
11818 DW_TAG_formal_parameter DIE for each one. */
11819 for (link = first_parm_type; link; )
11821 dw_die_ref parm_die;
11823 formal_type = TREE_VALUE (link);
11824 if (formal_type == void_type_node)
11827 /* Output a (nameless) DIE to represent the formal parameter itself. */
11828 parm_die = gen_formal_parameter_die (formal_type, context_die);
11829 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11830 && link == first_parm_type)
11831 || (arg && DECL_ARTIFICIAL (arg)))
11832 add_AT_flag (parm_die, DW_AT_artificial, 1);
11834 link = TREE_CHAIN (link);
11836 arg = TREE_CHAIN (arg);
11839 /* If this function type has an ellipsis, add a
11840 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11841 if (formal_type != void_type_node)
11842 gen_unspecified_parameters_die (function_or_method_type, context_die);
11844 /* Make our second (and final) pass over the list of formal parameter types
11845 and output DIEs to represent those types (as necessary). */
11846 for (link = TYPE_ARG_TYPES (function_or_method_type);
11847 link && TREE_VALUE (link);
11848 link = TREE_CHAIN (link))
11849 gen_type_die (TREE_VALUE (link), context_die);
11852 /* We want to generate the DIE for TYPE so that we can generate the
11853 die for MEMBER, which has been defined; we will need to refer back
11854 to the member declaration nested within TYPE. If we're trying to
11855 generate minimal debug info for TYPE, processing TYPE won't do the
11856 trick; we need to attach the member declaration by hand. */
11859 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11861 gen_type_die (type, context_die);
11863 /* If we're trying to avoid duplicate debug info, we may not have
11864 emitted the member decl for this function. Emit it now. */
11865 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11866 && ! lookup_decl_die (member))
11868 dw_die_ref type_die;
11869 gcc_assert (!decl_ultimate_origin (member));
11871 push_decl_scope (type);
11872 type_die = lookup_type_die (type);
11873 if (TREE_CODE (member) == FUNCTION_DECL)
11874 gen_subprogram_die (member, type_die);
11875 else if (TREE_CODE (member) == FIELD_DECL)
11877 /* Ignore the nameless fields that are used to skip bits but handle
11878 C++ anonymous unions and structs. */
11879 if (DECL_NAME (member) != NULL_TREE
11880 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
11881 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
11883 gen_type_die (member_declared_type (member), type_die);
11884 gen_field_die (member, type_die);
11888 gen_variable_die (member, type_die);
11894 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11895 may later generate inlined and/or out-of-line instances of. */
11898 dwarf2out_abstract_function (tree decl)
11900 dw_die_ref old_die;
11902 struct function *save_cfun;
11904 int was_abstract = DECL_ABSTRACT (decl);
11906 /* Make sure we have the actual abstract inline, not a clone. */
11907 decl = DECL_ORIGIN (decl);
11909 old_die = lookup_decl_die (decl);
11910 if (old_die && get_AT (old_die, DW_AT_inline))
11911 /* We've already generated the abstract instance. */
11914 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11915 we don't get confused by DECL_ABSTRACT. */
11916 if (debug_info_level > DINFO_LEVEL_TERSE)
11918 context = decl_class_context (decl);
11920 gen_type_die_for_member
11921 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11924 /* Pretend we've just finished compiling this function. */
11925 save_fn = current_function_decl;
11927 current_function_decl = decl;
11928 cfun = DECL_STRUCT_FUNCTION (decl);
11930 set_decl_abstract_flags (decl, 1);
11931 dwarf2out_decl (decl);
11932 if (! was_abstract)
11933 set_decl_abstract_flags (decl, 0);
11935 current_function_decl = save_fn;
11939 /* Helper function of premark_used_types() which gets called through
11940 htab_traverse_resize().
11942 Marks the DIE of a given type in *SLOT as perennial, so it never gets
11943 marked as unused by prune_unused_types. */
11945 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
11951 die = lookup_type_die (type);
11953 die->die_perennial_p = 1;
11957 /* Mark all members of used_types_hash as perennial. */
11959 premark_used_types (void)
11961 if (cfun && cfun->used_types_hash)
11962 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
11965 /* Generate a DIE to represent a declared function (either file-scope or
11969 gen_subprogram_die (tree decl, dw_die_ref context_die)
11971 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11972 tree origin = decl_ultimate_origin (decl);
11973 dw_die_ref subr_die;
11976 dw_die_ref old_die = lookup_decl_die (decl);
11977 int declaration = (current_function_decl != decl
11978 || class_or_namespace_scope_p (context_die));
11980 premark_used_types ();
11982 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11983 started to generate the abstract instance of an inline, decided to output
11984 its containing class, and proceeded to emit the declaration of the inline
11985 from the member list for the class. If so, DECLARATION takes priority;
11986 we'll get back to the abstract instance when done with the class. */
11988 /* The class-scope declaration DIE must be the primary DIE. */
11989 if (origin && declaration && class_or_namespace_scope_p (context_die))
11992 gcc_assert (!old_die);
11995 /* Now that the C++ front end lazily declares artificial member fns, we
11996 might need to retrofit the declaration into its class. */
11997 if (!declaration && !origin && !old_die
11998 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
11999 && !class_or_namespace_scope_p (context_die)
12000 && debug_info_level > DINFO_LEVEL_TERSE)
12001 old_die = force_decl_die (decl);
12003 if (origin != NULL)
12005 gcc_assert (!declaration || local_scope_p (context_die));
12007 /* Fixup die_parent for the abstract instance of a nested
12008 inline function. */
12009 if (old_die && old_die->die_parent == NULL)
12010 add_child_die (context_die, old_die);
12012 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12013 add_abstract_origin_attribute (subr_die, origin);
12017 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12018 struct dwarf_file_data * file_index = lookup_filename (s.file);
12020 if (!get_AT_flag (old_die, DW_AT_declaration)
12021 /* We can have a normal definition following an inline one in the
12022 case of redefinition of GNU C extern inlines.
12023 It seems reasonable to use AT_specification in this case. */
12024 && !get_AT (old_die, DW_AT_inline))
12026 /* Detect and ignore this case, where we are trying to output
12027 something we have already output. */
12031 /* If the definition comes from the same place as the declaration,
12032 maybe use the old DIE. We always want the DIE for this function
12033 that has the *_pc attributes to be under comp_unit_die so the
12034 debugger can find it. We also need to do this for abstract
12035 instances of inlines, since the spec requires the out-of-line copy
12036 to have the same parent. For local class methods, this doesn't
12037 apply; we just use the old DIE. */
12038 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12039 && (DECL_ARTIFICIAL (decl)
12040 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12041 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12042 == (unsigned) s.line))))
12044 subr_die = old_die;
12046 /* Clear out the declaration attribute and the formal parameters.
12047 Do not remove all children, because it is possible that this
12048 declaration die was forced using force_decl_die(). In such
12049 cases die that forced declaration die (e.g. TAG_imported_module)
12050 is one of the children that we do not want to remove. */
12051 remove_AT (subr_die, DW_AT_declaration);
12052 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12056 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12057 add_AT_specification (subr_die, old_die);
12058 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12059 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12060 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12061 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12066 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12068 if (TREE_PUBLIC (decl))
12069 add_AT_flag (subr_die, DW_AT_external, 1);
12071 add_name_and_src_coords_attributes (subr_die, decl);
12072 if (debug_info_level > DINFO_LEVEL_TERSE)
12074 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12075 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12076 0, 0, context_die);
12079 add_pure_or_virtual_attribute (subr_die, decl);
12080 if (DECL_ARTIFICIAL (decl))
12081 add_AT_flag (subr_die, DW_AT_artificial, 1);
12083 if (TREE_PROTECTED (decl))
12084 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12085 else if (TREE_PRIVATE (decl))
12086 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12091 if (!old_die || !get_AT (old_die, DW_AT_inline))
12093 add_AT_flag (subr_die, DW_AT_declaration, 1);
12095 /* The first time we see a member function, it is in the context of
12096 the class to which it belongs. We make sure of this by emitting
12097 the class first. The next time is the definition, which is
12098 handled above. The two may come from the same source text.
12100 Note that force_decl_die() forces function declaration die. It is
12101 later reused to represent definition. */
12102 equate_decl_number_to_die (decl, subr_die);
12105 else if (DECL_ABSTRACT (decl))
12107 if (DECL_DECLARED_INLINE_P (decl))
12109 if (cgraph_function_possibly_inlined_p (decl))
12110 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12112 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12116 if (cgraph_function_possibly_inlined_p (decl))
12117 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12119 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12122 equate_decl_number_to_die (decl, subr_die);
12124 else if (!DECL_EXTERNAL (decl))
12126 HOST_WIDE_INT cfa_fb_offset;
12128 if (!old_die || !get_AT (old_die, DW_AT_inline))
12129 equate_decl_number_to_die (decl, subr_die);
12131 if (!flag_reorder_blocks_and_partition)
12133 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
12134 current_function_funcdef_no);
12135 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
12136 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12137 current_function_funcdef_no);
12138 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
12140 add_pubname (decl, subr_die);
12141 add_arange (decl, subr_die);
12144 { /* Do nothing for now; maybe need to duplicate die, one for
12145 hot section and ond for cold section, then use the hot/cold
12146 section begin/end labels to generate the aranges... */
12148 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12149 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12150 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12151 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12153 add_pubname (decl, subr_die);
12154 add_arange (decl, subr_die);
12155 add_arange (decl, subr_die);
12159 #ifdef MIPS_DEBUGGING_INFO
12160 /* Add a reference to the FDE for this routine. */
12161 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
12164 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
12166 /* We define the "frame base" as the function's CFA. This is more
12167 convenient for several reasons: (1) It's stable across the prologue
12168 and epilogue, which makes it better than just a frame pointer,
12169 (2) With dwarf3, there exists a one-byte encoding that allows us
12170 to reference the .debug_frame data by proxy, but failing that,
12171 (3) We can at least reuse the code inspection and interpretation
12172 code that determines the CFA position at various points in the
12174 /* ??? Use some command-line or configury switch to enable the use
12175 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12176 consumers that understand it; fall back to "pure" dwarf2 and
12177 convert the CFA data into a location list. */
12179 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
12180 if (list->dw_loc_next)
12181 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12183 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12186 /* Compute a displacement from the "steady-state frame pointer" to
12187 the CFA. The former is what all stack slots and argument slots
12188 will reference in the rtl; the later is what we've told the
12189 debugger about. We'll need to adjust all frame_base references
12190 by this displacement. */
12191 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12193 if (cfun->static_chain_decl)
12194 add_AT_location_description (subr_die, DW_AT_static_link,
12195 loc_descriptor_from_tree (cfun->static_chain_decl));
12198 /* Now output descriptions of the arguments for this function. This gets
12199 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12200 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12201 `...' at the end of the formal parameter list. In order to find out if
12202 there was a trailing ellipsis or not, we must instead look at the type
12203 associated with the FUNCTION_DECL. This will be a node of type
12204 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12205 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12206 an ellipsis at the end. */
12208 /* In the case where we are describing a mere function declaration, all we
12209 need to do here (and all we *can* do here) is to describe the *types* of
12210 its formal parameters. */
12211 if (debug_info_level <= DINFO_LEVEL_TERSE)
12213 else if (declaration)
12214 gen_formal_types_die (decl, subr_die);
12217 /* Generate DIEs to represent all known formal parameters. */
12218 tree arg_decls = DECL_ARGUMENTS (decl);
12221 /* When generating DIEs, generate the unspecified_parameters DIE
12222 instead if we come across the arg "__builtin_va_alist" */
12223 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12224 if (TREE_CODE (parm) == PARM_DECL)
12226 if (DECL_NAME (parm)
12227 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12228 "__builtin_va_alist"))
12229 gen_unspecified_parameters_die (parm, subr_die);
12231 gen_decl_die (parm, subr_die);
12234 /* Decide whether we need an unspecified_parameters DIE at the end.
12235 There are 2 more cases to do this for: 1) the ansi ... declaration -
12236 this is detectable when the end of the arg list is not a
12237 void_type_node 2) an unprototyped function declaration (not a
12238 definition). This just means that we have no info about the
12239 parameters at all. */
12240 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12241 if (fn_arg_types != NULL)
12243 /* This is the prototyped case, check for.... */
12244 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12245 gen_unspecified_parameters_die (decl, subr_die);
12247 else if (DECL_INITIAL (decl) == NULL_TREE)
12248 gen_unspecified_parameters_die (decl, subr_die);
12251 /* Output Dwarf info for all of the stuff within the body of the function
12252 (if it has one - it may be just a declaration). */
12253 outer_scope = DECL_INITIAL (decl);
12255 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12256 a function. This BLOCK actually represents the outermost binding contour
12257 for the function, i.e. the contour in which the function's formal
12258 parameters and labels get declared. Curiously, it appears that the front
12259 end doesn't actually put the PARM_DECL nodes for the current function onto
12260 the BLOCK_VARS list for this outer scope, but are strung off of the
12261 DECL_ARGUMENTS list for the function instead.
12263 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12264 the LABEL_DECL nodes for the function however, and we output DWARF info
12265 for those in decls_for_scope. Just within the `outer_scope' there will be
12266 a BLOCK node representing the function's outermost pair of curly braces,
12267 and any blocks used for the base and member initializers of a C++
12268 constructor function. */
12269 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12271 /* Emit a DW_TAG_variable DIE for a named return value. */
12272 if (DECL_NAME (DECL_RESULT (decl)))
12273 gen_decl_die (DECL_RESULT (decl), subr_die);
12275 current_function_has_inlines = 0;
12276 decls_for_scope (outer_scope, subr_die, 0);
12278 #if 0 && defined (MIPS_DEBUGGING_INFO)
12279 if (current_function_has_inlines)
12281 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12282 if (! comp_unit_has_inlines)
12284 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12285 comp_unit_has_inlines = 1;
12290 /* Add the calling convention attribute if requested. */
12291 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
12295 /* Generate a DIE to represent a declared data object. */
12298 gen_variable_die (tree decl, dw_die_ref context_die)
12300 tree origin = decl_ultimate_origin (decl);
12301 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
12303 dw_die_ref old_die = lookup_decl_die (decl);
12304 int declaration = (DECL_EXTERNAL (decl)
12305 /* If DECL is COMDAT and has not actually been
12306 emitted, we cannot take its address; there
12307 might end up being no definition anywhere in
12308 the program. For example, consider the C++
12312 struct S { static const int i = 7; };
12317 int f() { return S<int>::i; }
12319 Here, S<int>::i is not DECL_EXTERNAL, but no
12320 definition is required, so the compiler will
12321 not emit a definition. */
12322 || (TREE_CODE (decl) == VAR_DECL
12323 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12324 || class_or_namespace_scope_p (context_die));
12326 if (origin != NULL)
12327 add_abstract_origin_attribute (var_die, origin);
12329 /* Loop unrolling can create multiple blocks that refer to the same
12330 static variable, so we must test for the DW_AT_declaration flag.
12332 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12333 copy decls and set the DECL_ABSTRACT flag on them instead of
12336 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12338 ??? The declare_in_namespace support causes us to get two DIEs for one
12339 variable, both of which are declarations. We want to avoid considering
12340 one to be a specification, so we must test that this DIE is not a
12342 else if (old_die && TREE_STATIC (decl) && ! declaration
12343 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12345 /* This is a definition of a C++ class level static. */
12346 add_AT_specification (var_die, old_die);
12347 if (DECL_NAME (decl))
12349 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12350 struct dwarf_file_data * file_index = lookup_filename (s.file);
12352 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12353 add_AT_file (var_die, DW_AT_decl_file, file_index);
12355 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12356 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12361 add_name_and_src_coords_attributes (var_die, decl);
12362 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
12363 TREE_THIS_VOLATILE (decl), context_die);
12365 if (TREE_PUBLIC (decl))
12366 add_AT_flag (var_die, DW_AT_external, 1);
12368 if (DECL_ARTIFICIAL (decl))
12369 add_AT_flag (var_die, DW_AT_artificial, 1);
12371 if (TREE_PROTECTED (decl))
12372 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12373 else if (TREE_PRIVATE (decl))
12374 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12378 add_AT_flag (var_die, DW_AT_declaration, 1);
12380 if (DECL_ABSTRACT (decl) || declaration)
12381 equate_decl_number_to_die (decl, var_die);
12383 if (! declaration && ! DECL_ABSTRACT (decl))
12385 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12386 add_pubname (decl, var_die);
12389 tree_add_const_value_attribute (var_die, decl);
12392 /* Generate a DIE to represent a label identifier. */
12395 gen_label_die (tree decl, dw_die_ref context_die)
12397 tree origin = decl_ultimate_origin (decl);
12398 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12400 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12402 if (origin != NULL)
12403 add_abstract_origin_attribute (lbl_die, origin);
12405 add_name_and_src_coords_attributes (lbl_die, decl);
12407 if (DECL_ABSTRACT (decl))
12408 equate_decl_number_to_die (decl, lbl_die);
12411 insn = DECL_RTL_IF_SET (decl);
12413 /* Deleted labels are programmer specified labels which have been
12414 eliminated because of various optimizations. We still emit them
12415 here so that it is possible to put breakpoints on them. */
12419 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12421 /* When optimization is enabled (via -O) some parts of the compiler
12422 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12423 represent source-level labels which were explicitly declared by
12424 the user. This really shouldn't be happening though, so catch
12425 it if it ever does happen. */
12426 gcc_assert (!INSN_DELETED_P (insn));
12428 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12429 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12434 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12435 attributes to the DIE for a block STMT, to describe where the inlined
12436 function was called from. This is similar to add_src_coords_attributes. */
12439 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12441 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12443 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12444 add_AT_unsigned (die, DW_AT_call_line, s.line);
12448 /* If STMT's abstract origin is a function declaration and STMT's
12449 first subblock's abstract origin is the function's outermost block,
12450 then we're looking at the main entry point. */
12452 is_inlined_entry_point (tree stmt)
12456 if (!stmt || TREE_CODE (stmt) != BLOCK)
12459 decl = block_ultimate_origin (stmt);
12461 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12464 block = BLOCK_SUBBLOCKS (stmt);
12468 if (TREE_CODE (block) != BLOCK)
12471 block = block_ultimate_origin (block);
12474 return block == DECL_INITIAL (decl);
12477 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12478 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12481 add_high_low_attributes (tree stmt, dw_die_ref die)
12483 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12485 if (BLOCK_FRAGMENT_CHAIN (stmt))
12489 if (is_inlined_entry_point (stmt))
12491 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12492 BLOCK_NUMBER (stmt));
12493 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12496 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12498 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12501 add_ranges (chain);
12502 chain = BLOCK_FRAGMENT_CHAIN (chain);
12509 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12510 BLOCK_NUMBER (stmt));
12511 add_AT_lbl_id (die, DW_AT_low_pc, label);
12512 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12513 BLOCK_NUMBER (stmt));
12514 add_AT_lbl_id (die, DW_AT_high_pc, label);
12518 /* Generate a DIE for a lexical block. */
12521 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12523 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12525 if (! BLOCK_ABSTRACT (stmt))
12526 add_high_low_attributes (stmt, stmt_die);
12528 decls_for_scope (stmt, stmt_die, depth);
12531 /* Generate a DIE for an inlined subprogram. */
12534 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12536 tree decl = block_ultimate_origin (stmt);
12538 /* Emit info for the abstract instance first, if we haven't yet. We
12539 must emit this even if the block is abstract, otherwise when we
12540 emit the block below (or elsewhere), we may end up trying to emit
12541 a die whose origin die hasn't been emitted, and crashing. */
12542 dwarf2out_abstract_function (decl);
12544 if (! BLOCK_ABSTRACT (stmt))
12546 dw_die_ref subr_die
12547 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12549 add_abstract_origin_attribute (subr_die, decl);
12550 add_high_low_attributes (stmt, subr_die);
12551 add_call_src_coords_attributes (stmt, subr_die);
12553 decls_for_scope (stmt, subr_die, depth);
12554 current_function_has_inlines = 1;
12557 /* We may get here if we're the outer block of function A that was
12558 inlined into function B that was inlined into function C. When
12559 generating debugging info for C, dwarf2out_abstract_function(B)
12560 would mark all inlined blocks as abstract, including this one.
12561 So, we wouldn't (and shouldn't) expect labels to be generated
12562 for this one. Instead, just emit debugging info for
12563 declarations within the block. This is particularly important
12564 in the case of initializers of arguments passed from B to us:
12565 if they're statement expressions containing declarations, we
12566 wouldn't generate dies for their abstract variables, and then,
12567 when generating dies for the real variables, we'd die (pun
12569 gen_lexical_block_die (stmt, context_die, depth);
12572 /* Generate a DIE for a field in a record, or structure. */
12575 gen_field_die (tree decl, dw_die_ref context_die)
12577 dw_die_ref decl_die;
12579 if (TREE_TYPE (decl) == error_mark_node)
12582 decl_die = new_die (DW_TAG_member, context_die, decl);
12583 add_name_and_src_coords_attributes (decl_die, decl);
12584 add_type_attribute (decl_die, member_declared_type (decl),
12585 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12588 if (DECL_BIT_FIELD_TYPE (decl))
12590 add_byte_size_attribute (decl_die, decl);
12591 add_bit_size_attribute (decl_die, decl);
12592 add_bit_offset_attribute (decl_die, decl);
12595 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12596 add_data_member_location_attribute (decl_die, decl);
12598 if (DECL_ARTIFICIAL (decl))
12599 add_AT_flag (decl_die, DW_AT_artificial, 1);
12601 if (TREE_PROTECTED (decl))
12602 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12603 else if (TREE_PRIVATE (decl))
12604 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12606 /* Equate decl number to die, so that we can look up this decl later on. */
12607 equate_decl_number_to_die (decl, decl_die);
12611 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12612 Use modified_type_die instead.
12613 We keep this code here just in case these types of DIEs may be needed to
12614 represent certain things in other languages (e.g. Pascal) someday. */
12617 gen_pointer_type_die (tree type, dw_die_ref context_die)
12620 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12622 equate_type_number_to_die (type, ptr_die);
12623 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12624 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12627 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12628 Use modified_type_die instead.
12629 We keep this code here just in case these types of DIEs may be needed to
12630 represent certain things in other languages (e.g. Pascal) someday. */
12633 gen_reference_type_die (tree type, dw_die_ref context_die)
12636 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12638 equate_type_number_to_die (type, ref_die);
12639 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12640 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12644 /* Generate a DIE for a pointer to a member type. */
12647 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12650 = new_die (DW_TAG_ptr_to_member_type,
12651 scope_die_for (type, context_die), type);
12653 equate_type_number_to_die (type, ptr_die);
12654 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12655 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12656 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12659 /* Generate the DIE for the compilation unit. */
12662 gen_compile_unit_die (const char *filename)
12665 char producer[250];
12666 const char *language_string = lang_hooks.name;
12669 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12673 add_name_attribute (die, filename);
12674 /* Don't add cwd for <built-in>. */
12675 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
12676 add_comp_dir_attribute (die);
12679 sprintf (producer, "%s %s", language_string, version_string);
12681 #ifdef MIPS_DEBUGGING_INFO
12682 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12683 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12684 not appear in the producer string, the debugger reaches the conclusion
12685 that the object file is stripped and has no debugging information.
12686 To get the MIPS/SGI debugger to believe that there is debugging
12687 information in the object file, we add a -g to the producer string. */
12688 if (debug_info_level > DINFO_LEVEL_TERSE)
12689 strcat (producer, " -g");
12692 add_AT_string (die, DW_AT_producer, producer);
12694 if (strcmp (language_string, "GNU C++") == 0)
12695 language = DW_LANG_C_plus_plus;
12696 else if (strcmp (language_string, "GNU Ada") == 0)
12697 language = DW_LANG_Ada95;
12698 else if (strcmp (language_string, "GNU F77") == 0)
12699 language = DW_LANG_Fortran77;
12700 else if (strcmp (language_string, "GNU F95") == 0)
12701 language = DW_LANG_Fortran95;
12702 else if (strcmp (language_string, "GNU Pascal") == 0)
12703 language = DW_LANG_Pascal83;
12704 else if (strcmp (language_string, "GNU Java") == 0)
12705 language = DW_LANG_Java;
12706 else if (strcmp (language_string, "GNU Objective-C") == 0)
12707 language = DW_LANG_ObjC;
12708 else if (strcmp (language_string, "GNU Objective-C++") == 0)
12709 language = DW_LANG_ObjC_plus_plus;
12711 language = DW_LANG_C89;
12713 add_AT_unsigned (die, DW_AT_language, language);
12717 /* Generate the DIE for a base class. */
12720 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12722 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12724 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12725 add_data_member_location_attribute (die, binfo);
12727 if (BINFO_VIRTUAL_P (binfo))
12728 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12730 if (access == access_public_node)
12731 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12732 else if (access == access_protected_node)
12733 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
12736 /* Generate a DIE for a class member. */
12739 gen_member_die (tree type, dw_die_ref context_die)
12742 tree binfo = TYPE_BINFO (type);
12745 /* If this is not an incomplete type, output descriptions of each of its
12746 members. Note that as we output the DIEs necessary to represent the
12747 members of this record or union type, we will also be trying to output
12748 DIEs to represent the *types* of those members. However the `type'
12749 function (above) will specifically avoid generating type DIEs for member
12750 types *within* the list of member DIEs for this (containing) type except
12751 for those types (of members) which are explicitly marked as also being
12752 members of this (containing) type themselves. The g++ front- end can
12753 force any given type to be treated as a member of some other (containing)
12754 type by setting the TYPE_CONTEXT of the given (member) type to point to
12755 the TREE node representing the appropriate (containing) type. */
12757 /* First output info about the base classes. */
12760 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
12764 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
12765 gen_inheritance_die (base,
12766 (accesses ? VEC_index (tree, accesses, i)
12767 : access_public_node), context_die);
12770 /* Now output info about the data members and type members. */
12771 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
12773 /* If we thought we were generating minimal debug info for TYPE
12774 and then changed our minds, some of the member declarations
12775 may have already been defined. Don't define them again, but
12776 do put them in the right order. */
12778 child = lookup_decl_die (member);
12780 splice_child_die (context_die, child);
12782 gen_decl_die (member, context_die);
12785 /* Now output info about the function members (if any). */
12786 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
12788 /* Don't include clones in the member list. */
12789 if (DECL_ABSTRACT_ORIGIN (member))
12792 child = lookup_decl_die (member);
12794 splice_child_die (context_die, child);
12796 gen_decl_die (member, context_die);
12800 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12801 is set, we pretend that the type was never defined, so we only get the
12802 member DIEs needed by later specification DIEs. */
12805 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
12806 enum debug_info_usage usage)
12808 dw_die_ref type_die = lookup_type_die (type);
12809 dw_die_ref scope_die = 0;
12811 int complete = (TYPE_SIZE (type)
12812 && (! TYPE_STUB_DECL (type)
12813 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
12814 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
12815 complete = complete && should_emit_struct_debug (type, usage);
12817 if (type_die && ! complete)
12820 if (TYPE_CONTEXT (type) != NULL_TREE
12821 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12822 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
12825 scope_die = scope_die_for (type, context_die);
12827 if (! type_die || (nested && scope_die == comp_unit_die))
12828 /* First occurrence of type or toplevel definition of nested class. */
12830 dw_die_ref old_die = type_die;
12832 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
12833 ? DW_TAG_structure_type : DW_TAG_union_type,
12835 equate_type_number_to_die (type, type_die);
12837 add_AT_specification (type_die, old_die);
12839 add_name_attribute (type_die, type_tag (type));
12842 remove_AT (type_die, DW_AT_declaration);
12844 /* If this type has been completed, then give it a byte_size attribute and
12845 then give a list of members. */
12846 if (complete && !ns_decl)
12848 /* Prevent infinite recursion in cases where the type of some member of
12849 this type is expressed in terms of this type itself. */
12850 TREE_ASM_WRITTEN (type) = 1;
12851 add_byte_size_attribute (type_die, type);
12852 if (TYPE_STUB_DECL (type) != NULL_TREE)
12853 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12855 /* If the first reference to this type was as the return type of an
12856 inline function, then it may not have a parent. Fix this now. */
12857 if (type_die->die_parent == NULL)
12858 add_child_die (scope_die, type_die);
12860 push_decl_scope (type);
12861 gen_member_die (type, type_die);
12864 /* GNU extension: Record what type our vtable lives in. */
12865 if (TYPE_VFIELD (type))
12867 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
12869 gen_type_die (vtype, context_die);
12870 add_AT_die_ref (type_die, DW_AT_containing_type,
12871 lookup_type_die (vtype));
12876 add_AT_flag (type_die, DW_AT_declaration, 1);
12878 /* We don't need to do this for function-local types. */
12879 if (TYPE_STUB_DECL (type)
12880 && ! decl_function_context (TYPE_STUB_DECL (type)))
12881 VEC_safe_push (tree, gc, incomplete_types, type);
12884 if (get_AT (type_die, DW_AT_name))
12885 add_pubtype (type, type_die);
12888 /* Generate a DIE for a subroutine _type_. */
12891 gen_subroutine_type_die (tree type, dw_die_ref context_die)
12893 tree return_type = TREE_TYPE (type);
12894 dw_die_ref subr_die
12895 = new_die (DW_TAG_subroutine_type,
12896 scope_die_for (type, context_die), type);
12898 equate_type_number_to_die (type, subr_die);
12899 add_prototyped_attribute (subr_die, type);
12900 add_type_attribute (subr_die, return_type, 0, 0, context_die);
12901 gen_formal_types_die (type, subr_die);
12903 if (get_AT (subr_die, DW_AT_name))
12904 add_pubtype (type, subr_die);
12907 /* Generate a DIE for a type definition. */
12910 gen_typedef_die (tree decl, dw_die_ref context_die)
12912 dw_die_ref type_die;
12915 if (TREE_ASM_WRITTEN (decl))
12918 TREE_ASM_WRITTEN (decl) = 1;
12919 type_die = new_die (DW_TAG_typedef, context_die, decl);
12920 origin = decl_ultimate_origin (decl);
12921 if (origin != NULL)
12922 add_abstract_origin_attribute (type_die, origin);
12927 add_name_and_src_coords_attributes (type_die, decl);
12928 if (DECL_ORIGINAL_TYPE (decl))
12930 type = DECL_ORIGINAL_TYPE (decl);
12932 gcc_assert (type != TREE_TYPE (decl));
12933 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12936 type = TREE_TYPE (decl);
12938 add_type_attribute (type_die, type, TREE_READONLY (decl),
12939 TREE_THIS_VOLATILE (decl), context_die);
12942 if (DECL_ABSTRACT (decl))
12943 equate_decl_number_to_die (decl, type_die);
12945 if (get_AT (type_die, DW_AT_name))
12946 add_pubtype (decl, type_die);
12949 /* Generate a type description DIE. */
12952 gen_type_die_with_usage (tree type, dw_die_ref context_die,
12953 enum debug_info_usage usage)
12957 if (type == NULL_TREE || type == error_mark_node)
12960 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12961 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12963 if (TREE_ASM_WRITTEN (type))
12966 /* Prevent broken recursion; we can't hand off to the same type. */
12967 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12969 TREE_ASM_WRITTEN (type) = 1;
12970 gen_decl_die (TYPE_NAME (type), context_die);
12974 /* We are going to output a DIE to represent the unqualified version
12975 of this type (i.e. without any const or volatile qualifiers) so
12976 get the main variant (i.e. the unqualified version) of this type
12977 now. (Vectors are special because the debugging info is in the
12978 cloned type itself). */
12979 if (TREE_CODE (type) != VECTOR_TYPE)
12980 type = type_main_variant (type);
12982 if (TREE_ASM_WRITTEN (type))
12985 switch (TREE_CODE (type))
12991 case REFERENCE_TYPE:
12992 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12993 ensures that the gen_type_die recursion will terminate even if the
12994 type is recursive. Recursive types are possible in Ada. */
12995 /* ??? We could perhaps do this for all types before the switch
12997 TREE_ASM_WRITTEN (type) = 1;
12999 /* For these types, all that is required is that we output a DIE (or a
13000 set of DIEs) to represent the "basis" type. */
13001 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13002 DINFO_USAGE_IND_USE);
13006 /* This code is used for C++ pointer-to-data-member types.
13007 Output a description of the relevant class type. */
13008 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13009 DINFO_USAGE_IND_USE);
13011 /* Output a description of the type of the object pointed to. */
13012 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13013 DINFO_USAGE_IND_USE);
13015 /* Now output a DIE to represent this pointer-to-data-member type
13017 gen_ptr_to_mbr_type_die (type, context_die);
13020 case FUNCTION_TYPE:
13021 /* Force out return type (in case it wasn't forced out already). */
13022 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13023 DINFO_USAGE_DIR_USE);
13024 gen_subroutine_type_die (type, context_die);
13028 /* Force out return type (in case it wasn't forced out already). */
13029 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13030 DINFO_USAGE_DIR_USE);
13031 gen_subroutine_type_die (type, context_die);
13035 gen_array_type_die (type, context_die);
13039 gen_array_type_die (type, context_die);
13042 case ENUMERAL_TYPE:
13045 case QUAL_UNION_TYPE:
13046 /* If this is a nested type whose containing class hasn't been written
13047 out yet, writing it out will cover this one, too. This does not apply
13048 to instantiations of member class templates; they need to be added to
13049 the containing class as they are generated. FIXME: This hurts the
13050 idea of combining type decls from multiple TUs, since we can't predict
13051 what set of template instantiations we'll get. */
13052 if (TYPE_CONTEXT (type)
13053 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13054 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13056 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13058 if (TREE_ASM_WRITTEN (type))
13061 /* If that failed, attach ourselves to the stub. */
13062 push_decl_scope (TYPE_CONTEXT (type));
13063 context_die = lookup_type_die (TYPE_CONTEXT (type));
13068 declare_in_namespace (type, context_die);
13072 if (TREE_CODE (type) == ENUMERAL_TYPE)
13074 /* This might have been written out by the call to
13075 declare_in_namespace. */
13076 if (!TREE_ASM_WRITTEN (type))
13077 gen_enumeration_type_die (type, context_die);
13080 gen_struct_or_union_type_die (type, context_die, usage);
13085 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13086 it up if it is ever completed. gen_*_type_die will set it for us
13087 when appropriate. */
13093 case FIXED_POINT_TYPE:
13096 /* No DIEs needed for fundamental types. */
13100 /* No Dwarf representation currently defined. */
13104 gcc_unreachable ();
13107 TREE_ASM_WRITTEN (type) = 1;
13111 gen_type_die (tree type, dw_die_ref context_die)
13113 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
13116 /* Generate a DIE for a tagged type instantiation. */
13119 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
13121 if (type == NULL_TREE || type == error_mark_node)
13124 /* We are going to output a DIE to represent the unqualified version of
13125 this type (i.e. without any const or volatile qualifiers) so make sure
13126 that we have the main variant (i.e. the unqualified version) of this
13128 gcc_assert (type == type_main_variant (type));
13130 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13131 an instance of an unresolved type. */
13133 switch (TREE_CODE (type))
13138 case ENUMERAL_TYPE:
13139 gen_inlined_enumeration_type_die (type, context_die);
13143 gen_inlined_structure_type_die (type, context_die);
13147 case QUAL_UNION_TYPE:
13148 gen_inlined_union_type_die (type, context_die);
13152 gcc_unreachable ();
13156 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13157 things which are local to the given block. */
13160 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
13162 int must_output_die = 0;
13165 enum tree_code origin_code;
13167 /* Ignore blocks that are NULL. */
13168 if (stmt == NULL_TREE)
13171 /* If the block is one fragment of a non-contiguous block, do not
13172 process the variables, since they will have been done by the
13173 origin block. Do process subblocks. */
13174 if (BLOCK_FRAGMENT_ORIGIN (stmt))
13178 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
13179 gen_block_die (sub, context_die, depth + 1);
13184 /* Determine the "ultimate origin" of this block. This block may be an
13185 inlined instance of an inlined instance of inline function, so we have
13186 to trace all of the way back through the origin chain to find out what
13187 sort of node actually served as the original seed for the creation of
13188 the current block. */
13189 origin = block_ultimate_origin (stmt);
13190 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13192 /* Determine if we need to output any Dwarf DIEs at all to represent this
13194 if (origin_code == FUNCTION_DECL)
13195 /* The outer scopes for inlinings *must* always be represented. We
13196 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13197 must_output_die = 1;
13200 /* In the case where the current block represents an inlining of the
13201 "body block" of an inline function, we must *NOT* output any DIE for
13202 this block because we have already output a DIE to represent the whole
13203 inlined function scope and the "body block" of any function doesn't
13204 really represent a different scope according to ANSI C rules. So we
13205 check here to make sure that this block does not represent a "body
13206 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13207 if (! is_body_block (origin ? origin : stmt))
13209 /* Determine if this block directly contains any "significant"
13210 local declarations which we will need to output DIEs for. */
13211 if (debug_info_level > DINFO_LEVEL_TERSE)
13212 /* We are not in terse mode so *any* local declaration counts
13213 as being a "significant" one. */
13214 must_output_die = (BLOCK_VARS (stmt) != NULL
13215 && (TREE_USED (stmt)
13216 || TREE_ASM_WRITTEN (stmt)
13217 || BLOCK_ABSTRACT (stmt)));
13219 /* We are in terse mode, so only local (nested) function
13220 definitions count as "significant" local declarations. */
13221 for (decl = BLOCK_VARS (stmt);
13222 decl != NULL; decl = TREE_CHAIN (decl))
13223 if (TREE_CODE (decl) == FUNCTION_DECL
13224 && DECL_INITIAL (decl))
13226 must_output_die = 1;
13232 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13233 DIE for any block which contains no significant local declarations at
13234 all. Rather, in such cases we just call `decls_for_scope' so that any
13235 needed Dwarf info for any sub-blocks will get properly generated. Note
13236 that in terse mode, our definition of what constitutes a "significant"
13237 local declaration gets restricted to include only inlined function
13238 instances and local (nested) function definitions. */
13239 if (must_output_die)
13241 if (origin_code == FUNCTION_DECL)
13242 gen_inlined_subroutine_die (stmt, context_die, depth);
13244 gen_lexical_block_die (stmt, context_die, depth);
13247 decls_for_scope (stmt, context_die, depth);
13250 /* Generate all of the decls declared within a given scope and (recursively)
13251 all of its sub-blocks. */
13254 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13259 /* Ignore NULL blocks. */
13260 if (stmt == NULL_TREE)
13263 if (TREE_USED (stmt))
13265 /* Output the DIEs to represent all of the data objects and typedefs
13266 declared directly within this block but not within any nested
13267 sub-blocks. Also, nested function and tag DIEs have been
13268 generated with a parent of NULL; fix that up now. */
13269 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13273 if (TREE_CODE (decl) == FUNCTION_DECL)
13274 die = lookup_decl_die (decl);
13275 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13276 die = lookup_type_die (TREE_TYPE (decl));
13280 if (die != NULL && die->die_parent == NULL)
13281 add_child_die (context_die, die);
13282 /* Do not produce debug information for static variables since
13283 these might be optimized out. We are called for these later
13284 in varpool_analyze_pending_decls. */
13285 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
13288 gen_decl_die (decl, context_die);
13292 /* If we're at -g1, we're not interested in subblocks. */
13293 if (debug_info_level <= DINFO_LEVEL_TERSE)
13296 /* Output the DIEs to represent all sub-blocks (and the items declared
13297 therein) of this block. */
13298 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13300 subblocks = BLOCK_CHAIN (subblocks))
13301 gen_block_die (subblocks, context_die, depth + 1);
13304 /* Is this a typedef we can avoid emitting? */
13307 is_redundant_typedef (tree decl)
13309 if (TYPE_DECL_IS_STUB (decl))
13312 if (DECL_ARTIFICIAL (decl)
13313 && DECL_CONTEXT (decl)
13314 && is_tagged_type (DECL_CONTEXT (decl))
13315 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13316 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13317 /* Also ignore the artificial member typedef for the class name. */
13323 /* Returns the DIE for decl. A DIE will always be returned. */
13326 force_decl_die (tree decl)
13328 dw_die_ref decl_die;
13329 unsigned saved_external_flag;
13330 tree save_fn = NULL_TREE;
13331 decl_die = lookup_decl_die (decl);
13334 dw_die_ref context_die;
13335 tree decl_context = DECL_CONTEXT (decl);
13338 /* Find die that represents this context. */
13339 if (TYPE_P (decl_context))
13340 context_die = force_type_die (decl_context);
13342 context_die = force_decl_die (decl_context);
13345 context_die = comp_unit_die;
13347 decl_die = lookup_decl_die (decl);
13351 switch (TREE_CODE (decl))
13353 case FUNCTION_DECL:
13354 /* Clear current_function_decl, so that gen_subprogram_die thinks
13355 that this is a declaration. At this point, we just want to force
13356 declaration die. */
13357 save_fn = current_function_decl;
13358 current_function_decl = NULL_TREE;
13359 gen_subprogram_die (decl, context_die);
13360 current_function_decl = save_fn;
13364 /* Set external flag to force declaration die. Restore it after
13365 gen_decl_die() call. */
13366 saved_external_flag = DECL_EXTERNAL (decl);
13367 DECL_EXTERNAL (decl) = 1;
13368 gen_decl_die (decl, context_die);
13369 DECL_EXTERNAL (decl) = saved_external_flag;
13372 case NAMESPACE_DECL:
13373 dwarf2out_decl (decl);
13377 gcc_unreachable ();
13380 /* We should be able to find the DIE now. */
13382 decl_die = lookup_decl_die (decl);
13383 gcc_assert (decl_die);
13389 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13390 always returned. */
13393 force_type_die (tree type)
13395 dw_die_ref type_die;
13397 type_die = lookup_type_die (type);
13400 dw_die_ref context_die;
13401 if (TYPE_CONTEXT (type))
13403 if (TYPE_P (TYPE_CONTEXT (type)))
13404 context_die = force_type_die (TYPE_CONTEXT (type));
13406 context_die = force_decl_die (TYPE_CONTEXT (type));
13409 context_die = comp_unit_die;
13411 type_die = lookup_type_die (type);
13414 gen_type_die (type, context_die);
13415 type_die = lookup_type_die (type);
13416 gcc_assert (type_die);
13421 /* Force out any required namespaces to be able to output DECL,
13422 and return the new context_die for it, if it's changed. */
13425 setup_namespace_context (tree thing, dw_die_ref context_die)
13427 tree context = (DECL_P (thing)
13428 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13429 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13430 /* Force out the namespace. */
13431 context_die = force_decl_die (context);
13433 return context_die;
13436 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13437 type) within its namespace, if appropriate.
13439 For compatibility with older debuggers, namespace DIEs only contain
13440 declarations; all definitions are emitted at CU scope. */
13443 declare_in_namespace (tree thing, dw_die_ref context_die)
13445 dw_die_ref ns_context;
13447 if (debug_info_level <= DINFO_LEVEL_TERSE)
13450 /* If this decl is from an inlined function, then don't try to emit it in its
13451 namespace, as we will get confused. It would have already been emitted
13452 when the abstract instance of the inline function was emitted anyways. */
13453 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13456 ns_context = setup_namespace_context (thing, context_die);
13458 if (ns_context != context_die)
13460 if (DECL_P (thing))
13461 gen_decl_die (thing, ns_context);
13463 gen_type_die (thing, ns_context);
13467 /* Generate a DIE for a namespace or namespace alias. */
13470 gen_namespace_die (tree decl)
13472 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13474 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13475 they are an alias of. */
13476 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13478 /* Output a real namespace. */
13479 dw_die_ref namespace_die
13480 = new_die (DW_TAG_namespace, context_die, decl);
13481 add_name_and_src_coords_attributes (namespace_die, decl);
13482 equate_decl_number_to_die (decl, namespace_die);
13486 /* Output a namespace alias. */
13488 /* Force out the namespace we are an alias of, if necessary. */
13489 dw_die_ref origin_die
13490 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13492 /* Now create the namespace alias DIE. */
13493 dw_die_ref namespace_die
13494 = new_die (DW_TAG_imported_declaration, context_die, decl);
13495 add_name_and_src_coords_attributes (namespace_die, decl);
13496 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13497 equate_decl_number_to_die (decl, namespace_die);
13501 /* Generate Dwarf debug information for a decl described by DECL. */
13504 gen_decl_die (tree decl, dw_die_ref context_die)
13508 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13511 switch (TREE_CODE (decl))
13517 /* The individual enumerators of an enum type get output when we output
13518 the Dwarf representation of the relevant enum type itself. */
13521 case FUNCTION_DECL:
13522 /* Don't output any DIEs to represent mere function declarations,
13523 unless they are class members or explicit block externs. */
13524 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13525 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13530 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13531 on local redeclarations of global functions. That seems broken. */
13532 if (current_function_decl != decl)
13533 /* This is only a declaration. */;
13536 /* If we're emitting a clone, emit info for the abstract instance. */
13537 if (DECL_ORIGIN (decl) != decl)
13538 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13540 /* If we're emitting an out-of-line copy of an inline function,
13541 emit info for the abstract instance and set up to refer to it. */
13542 else if (cgraph_function_possibly_inlined_p (decl)
13543 && ! DECL_ABSTRACT (decl)
13544 && ! class_or_namespace_scope_p (context_die)
13545 /* dwarf2out_abstract_function won't emit a die if this is just
13546 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13547 that case, because that works only if we have a die. */
13548 && DECL_INITIAL (decl) != NULL_TREE)
13550 dwarf2out_abstract_function (decl);
13551 set_decl_origin_self (decl);
13554 /* Otherwise we're emitting the primary DIE for this decl. */
13555 else if (debug_info_level > DINFO_LEVEL_TERSE)
13557 /* Before we describe the FUNCTION_DECL itself, make sure that we
13558 have described its return type. */
13559 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13561 /* And its virtual context. */
13562 if (DECL_VINDEX (decl) != NULL_TREE)
13563 gen_type_die (DECL_CONTEXT (decl), context_die);
13565 /* And its containing type. */
13566 origin = decl_class_context (decl);
13567 if (origin != NULL_TREE)
13568 gen_type_die_for_member (origin, decl, context_die);
13570 /* And its containing namespace. */
13571 declare_in_namespace (decl, context_die);
13574 /* Now output a DIE to represent the function itself. */
13575 gen_subprogram_die (decl, context_die);
13579 /* If we are in terse mode, don't generate any DIEs to represent any
13580 actual typedefs. */
13581 if (debug_info_level <= DINFO_LEVEL_TERSE)
13584 /* In the special case of a TYPE_DECL node representing the declaration
13585 of some type tag, if the given TYPE_DECL is marked as having been
13586 instantiated from some other (original) TYPE_DECL node (e.g. one which
13587 was generated within the original definition of an inline function) we
13588 have to generate a special (abbreviated) DW_TAG_structure_type,
13589 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13590 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
13592 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13596 if (is_redundant_typedef (decl))
13597 gen_type_die (TREE_TYPE (decl), context_die);
13599 /* Output a DIE to represent the typedef itself. */
13600 gen_typedef_die (decl, context_die);
13604 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13605 gen_label_die (decl, context_die);
13610 /* If we are in terse mode, don't generate any DIEs to represent any
13611 variable declarations or definitions. */
13612 if (debug_info_level <= DINFO_LEVEL_TERSE)
13615 /* Output any DIEs that are needed to specify the type of this data
13617 gen_type_die (TREE_TYPE (decl), context_die);
13619 /* And its containing type. */
13620 origin = decl_class_context (decl);
13621 if (origin != NULL_TREE)
13622 gen_type_die_for_member (origin, decl, context_die);
13624 /* And its containing namespace. */
13625 declare_in_namespace (decl, context_die);
13627 /* Now output the DIE to represent the data object itself. This gets
13628 complicated because of the possibility that the VAR_DECL really
13629 represents an inlined instance of a formal parameter for an inline
13631 origin = decl_ultimate_origin (decl);
13632 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13633 gen_formal_parameter_die (decl, context_die);
13635 gen_variable_die (decl, context_die);
13639 /* Ignore the nameless fields that are used to skip bits but handle C++
13640 anonymous unions and structs. */
13641 if (DECL_NAME (decl) != NULL_TREE
13642 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13643 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13645 gen_type_die (member_declared_type (decl), context_die);
13646 gen_field_die (decl, context_die);
13651 gen_type_die (TREE_TYPE (decl), context_die);
13652 gen_formal_parameter_die (decl, context_die);
13655 case NAMESPACE_DECL:
13656 gen_namespace_die (decl);
13660 /* Probably some frontend-internal decl. Assume we don't care. */
13661 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13666 /* Output debug information for global decl DECL. Called from toplev.c after
13667 compilation proper has finished. */
13670 dwarf2out_global_decl (tree decl)
13672 /* Output DWARF2 information for file-scope tentative data object
13673 declarations, file-scope (extern) function declarations (which had no
13674 corresponding body) and file-scope tagged type declarations and
13675 definitions which have not yet been forced out. */
13676 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
13677 dwarf2out_decl (decl);
13680 /* Output debug information for type decl DECL. Called from toplev.c
13681 and from language front ends (to record built-in types). */
13683 dwarf2out_type_decl (tree decl, int local)
13686 dwarf2out_decl (decl);
13689 /* Output debug information for imported module or decl. */
13692 dwarf2out_imported_module_or_decl (tree decl, tree context)
13694 dw_die_ref imported_die, at_import_die;
13695 dw_die_ref scope_die;
13696 expanded_location xloc;
13698 if (debug_info_level <= DINFO_LEVEL_TERSE)
13703 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13704 We need decl DIE for reference and scope die. First, get DIE for the decl
13707 /* Get the scope die for decl context. Use comp_unit_die for global module
13708 or decl. If die is not found for non globals, force new die. */
13710 scope_die = comp_unit_die;
13711 else if (TYPE_P (context))
13713 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
13715 scope_die = force_type_die (context);
13718 scope_die = force_decl_die (context);
13720 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13721 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
13723 if (is_base_type (TREE_TYPE (decl)))
13724 at_import_die = base_type_die (TREE_TYPE (decl));
13726 at_import_die = force_type_die (TREE_TYPE (decl));
13730 at_import_die = lookup_decl_die (decl);
13731 if (!at_import_die)
13733 /* If we're trying to avoid duplicate debug info, we may not have
13734 emitted the member decl for this field. Emit it now. */
13735 if (TREE_CODE (decl) == FIELD_DECL)
13737 tree type = DECL_CONTEXT (decl);
13738 dw_die_ref type_context_die;
13740 if (TYPE_CONTEXT (type))
13741 if (TYPE_P (TYPE_CONTEXT (type)))
13743 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
13744 DINFO_USAGE_DIR_USE))
13746 type_context_die = force_type_die (TYPE_CONTEXT (type));
13749 type_context_die = force_decl_die (TYPE_CONTEXT (type));
13751 type_context_die = comp_unit_die;
13752 gen_type_die_for_member (type, decl, type_context_die);
13754 at_import_die = force_decl_die (decl);
13758 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13759 if (TREE_CODE (decl) == NAMESPACE_DECL)
13760 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
13762 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
13764 xloc = expand_location (input_location);
13765 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
13766 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
13767 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
13770 /* Write the debugging output for DECL. */
13773 dwarf2out_decl (tree decl)
13775 dw_die_ref context_die = comp_unit_die;
13777 switch (TREE_CODE (decl))
13782 case FUNCTION_DECL:
13783 /* What we would really like to do here is to filter out all mere
13784 file-scope declarations of file-scope functions which are never
13785 referenced later within this translation unit (and keep all of ones
13786 that *are* referenced later on) but we aren't clairvoyant, so we have
13787 no idea which functions will be referenced in the future (i.e. later
13788 on within the current translation unit). So here we just ignore all
13789 file-scope function declarations which are not also definitions. If
13790 and when the debugger needs to know something about these functions,
13791 it will have to hunt around and find the DWARF information associated
13792 with the definition of the function.
13794 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13795 nodes represent definitions and which ones represent mere
13796 declarations. We have to check DECL_INITIAL instead. That's because
13797 the C front-end supports some weird semantics for "extern inline"
13798 function definitions. These can get inlined within the current
13799 translation unit (and thus, we need to generate Dwarf info for their
13800 abstract instances so that the Dwarf info for the concrete inlined
13801 instances can have something to refer to) but the compiler never
13802 generates any out-of-lines instances of such things (despite the fact
13803 that they *are* definitions).
13805 The important point is that the C front-end marks these "extern
13806 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13807 them anyway. Note that the C++ front-end also plays some similar games
13808 for inline function definitions appearing within include files which
13809 also contain `#pragma interface' pragmas. */
13810 if (DECL_INITIAL (decl) == NULL_TREE)
13813 /* If we're a nested function, initially use a parent of NULL; if we're
13814 a plain function, this will be fixed up in decls_for_scope. If
13815 we're a method, it will be ignored, since we already have a DIE. */
13816 if (decl_function_context (decl)
13817 /* But if we're in terse mode, we don't care about scope. */
13818 && debug_info_level > DINFO_LEVEL_TERSE)
13819 context_die = NULL;
13823 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13824 declaration and if the declaration was never even referenced from
13825 within this entire compilation unit. We suppress these DIEs in
13826 order to save space in the .debug section (by eliminating entries
13827 which are probably useless). Note that we must not suppress
13828 block-local extern declarations (whether used or not) because that
13829 would screw-up the debugger's name lookup mechanism and cause it to
13830 miss things which really ought to be in scope at a given point. */
13831 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
13834 /* For local statics lookup proper context die. */
13835 if (TREE_STATIC (decl) && decl_function_context (decl))
13836 context_die = lookup_decl_die (DECL_CONTEXT (decl));
13838 /* If we are in terse mode, don't generate any DIEs to represent any
13839 variable declarations or definitions. */
13840 if (debug_info_level <= DINFO_LEVEL_TERSE)
13844 case NAMESPACE_DECL:
13845 if (debug_info_level <= DINFO_LEVEL_TERSE)
13847 if (lookup_decl_die (decl) != NULL)
13852 /* Don't emit stubs for types unless they are needed by other DIEs. */
13853 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
13856 /* Don't bother trying to generate any DIEs to represent any of the
13857 normal built-in types for the language we are compiling. */
13858 if (DECL_IS_BUILTIN (decl))
13860 /* OK, we need to generate one for `bool' so GDB knows what type
13861 comparisons have. */
13863 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
13864 && ! DECL_IGNORED_P (decl))
13865 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
13870 /* If we are in terse mode, don't generate any DIEs for types. */
13871 if (debug_info_level <= DINFO_LEVEL_TERSE)
13874 /* If we're a function-scope tag, initially use a parent of NULL;
13875 this will be fixed up in decls_for_scope. */
13876 if (decl_function_context (decl))
13877 context_die = NULL;
13885 gen_decl_die (decl, context_die);
13888 /* Output a marker (i.e. a label) for the beginning of the generated code for
13889 a lexical block. */
13892 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
13893 unsigned int blocknum)
13895 switch_to_section (current_function_section ());
13896 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
13899 /* Output a marker (i.e. a label) for the end of the generated code for a
13903 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
13905 switch_to_section (current_function_section ());
13906 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
13909 /* Returns nonzero if it is appropriate not to emit any debugging
13910 information for BLOCK, because it doesn't contain any instructions.
13912 Don't allow this for blocks with nested functions or local classes
13913 as we would end up with orphans, and in the presence of scheduling
13914 we may end up calling them anyway. */
13917 dwarf2out_ignore_block (tree block)
13921 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
13922 if (TREE_CODE (decl) == FUNCTION_DECL
13923 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
13929 /* Hash table routines for file_hash. */
13932 file_table_eq (const void *p1_p, const void *p2_p)
13934 const struct dwarf_file_data * p1 = p1_p;
13935 const char * p2 = p2_p;
13936 return strcmp (p1->filename, p2) == 0;
13940 file_table_hash (const void *p_p)
13942 const struct dwarf_file_data * p = p_p;
13943 return htab_hash_string (p->filename);
13946 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13947 dwarf2out.c) and return its "index". The index of each (known) filename is
13948 just a unique number which is associated with only that one filename. We
13949 need such numbers for the sake of generating labels (in the .debug_sfnames
13950 section) and references to those files numbers (in the .debug_srcinfo
13951 and.debug_macinfo sections). If the filename given as an argument is not
13952 found in our current list, add it to the list and assign it the next
13953 available unique index number. In order to speed up searches, we remember
13954 the index of the filename was looked up last. This handles the majority of
13957 static struct dwarf_file_data *
13958 lookup_filename (const char *file_name)
13961 struct dwarf_file_data * created;
13963 /* Check to see if the file name that was searched on the previous
13964 call matches this file name. If so, return the index. */
13965 if (file_table_last_lookup
13966 && (file_name == file_table_last_lookup->filename
13967 || strcmp (file_table_last_lookup->filename, file_name) == 0))
13968 return file_table_last_lookup;
13970 /* Didn't match the previous lookup, search the table. */
13971 slot = htab_find_slot_with_hash (file_table, file_name,
13972 htab_hash_string (file_name), INSERT);
13976 created = ggc_alloc (sizeof (struct dwarf_file_data));
13977 created->filename = file_name;
13978 created->emitted_number = 0;
13983 /* If the assembler will construct the file table, then translate the compiler
13984 internal file table number into the assembler file table number, and emit
13985 a .file directive if we haven't already emitted one yet. The file table
13986 numbers are different because we prune debug info for unused variables and
13987 types, which may include filenames. */
13990 maybe_emit_file (struct dwarf_file_data * fd)
13992 if (! fd->emitted_number)
13994 if (last_emitted_file)
13995 fd->emitted_number = last_emitted_file->emitted_number + 1;
13997 fd->emitted_number = 1;
13998 last_emitted_file = fd;
14000 if (DWARF2_ASM_LINE_DEBUG_INFO)
14002 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14003 output_quoted_string (asm_out_file,
14004 remap_debug_filename (fd->filename));
14005 fputc ('\n', asm_out_file);
14009 return fd->emitted_number;
14012 /* Called by the final INSN scan whenever we see a var location. We
14013 use it to drop labels in the right places, and throw the location in
14014 our lookup table. */
14017 dwarf2out_var_location (rtx loc_note)
14019 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14020 struct var_loc_node *newloc;
14022 static rtx last_insn;
14023 static const char *last_label;
14026 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14028 prev_insn = PREV_INSN (loc_note);
14030 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
14031 /* If the insn we processed last time is the previous insn
14032 and it is also a var location note, use the label we emitted
14034 if (last_insn != NULL_RTX
14035 && last_insn == prev_insn
14036 && NOTE_P (prev_insn)
14037 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14039 newloc->label = last_label;
14043 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14044 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14046 newloc->label = ggc_strdup (loclabel);
14048 newloc->var_loc_note = loc_note;
14049 newloc->next = NULL;
14051 if (cfun && in_cold_section_p)
14052 newloc->section_label = cfun->cold_section_label;
14054 newloc->section_label = text_section_label;
14056 last_insn = loc_note;
14057 last_label = newloc->label;
14058 decl = NOTE_VAR_LOCATION_DECL (loc_note);
14059 add_var_loc_to_decl (decl, newloc);
14062 /* We need to reset the locations at the beginning of each
14063 function. We can't do this in the end_function hook, because the
14064 declarations that use the locations won't have been output when
14065 that hook is called. Also compute have_multiple_function_sections here. */
14068 dwarf2out_begin_function (tree fun)
14070 htab_empty (decl_loc_table);
14072 if (function_section (fun) != text_section)
14073 have_multiple_function_sections = true;
14076 /* Output a label to mark the beginning of a source code line entry
14077 and record information relating to this source line, in
14078 'line_info_table' for later output of the .debug_line section. */
14081 dwarf2out_source_line (unsigned int line, const char *filename)
14083 if (debug_info_level >= DINFO_LEVEL_NORMAL
14086 int file_num = maybe_emit_file (lookup_filename (filename));
14088 switch_to_section (current_function_section ());
14090 /* If requested, emit something human-readable. */
14091 if (flag_debug_asm)
14092 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
14095 if (DWARF2_ASM_LINE_DEBUG_INFO)
14097 /* Emit the .loc directive understood by GNU as. */
14098 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
14100 /* Indicate that line number info exists. */
14101 line_info_table_in_use++;
14103 else if (function_section (current_function_decl) != text_section)
14105 dw_separate_line_info_ref line_info;
14106 targetm.asm_out.internal_label (asm_out_file,
14107 SEPARATE_LINE_CODE_LABEL,
14108 separate_line_info_table_in_use);
14110 /* Expand the line info table if necessary. */
14111 if (separate_line_info_table_in_use
14112 == separate_line_info_table_allocated)
14114 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14115 separate_line_info_table
14116 = ggc_realloc (separate_line_info_table,
14117 separate_line_info_table_allocated
14118 * sizeof (dw_separate_line_info_entry));
14119 memset (separate_line_info_table
14120 + separate_line_info_table_in_use,
14122 (LINE_INFO_TABLE_INCREMENT
14123 * sizeof (dw_separate_line_info_entry)));
14126 /* Add the new entry at the end of the line_info_table. */
14128 = &separate_line_info_table[separate_line_info_table_in_use++];
14129 line_info->dw_file_num = file_num;
14130 line_info->dw_line_num = line;
14131 line_info->function = current_function_funcdef_no;
14135 dw_line_info_ref line_info;
14137 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
14138 line_info_table_in_use);
14140 /* Expand the line info table if necessary. */
14141 if (line_info_table_in_use == line_info_table_allocated)
14143 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14145 = ggc_realloc (line_info_table,
14146 (line_info_table_allocated
14147 * sizeof (dw_line_info_entry)));
14148 memset (line_info_table + line_info_table_in_use, 0,
14149 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
14152 /* Add the new entry at the end of the line_info_table. */
14153 line_info = &line_info_table[line_info_table_in_use++];
14154 line_info->dw_file_num = file_num;
14155 line_info->dw_line_num = line;
14160 /* Record the beginning of a new source file. */
14163 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
14165 if (flag_eliminate_dwarf2_dups)
14167 /* Record the beginning of the file for break_out_includes. */
14168 dw_die_ref bincl_die;
14170 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
14171 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
14174 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14176 int file_num = maybe_emit_file (lookup_filename (filename));
14178 switch_to_section (debug_macinfo_section);
14179 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
14180 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14183 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14187 /* Record the end of a source file. */
14190 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14192 if (flag_eliminate_dwarf2_dups)
14193 /* Record the end of the file for break_out_includes. */
14194 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14196 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14198 switch_to_section (debug_macinfo_section);
14199 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14203 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14204 the tail part of the directive line, i.e. the part which is past the
14205 initial whitespace, #, whitespace, directive-name, whitespace part. */
14208 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14209 const char *buffer ATTRIBUTE_UNUSED)
14211 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14213 switch_to_section (debug_macinfo_section);
14214 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14215 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14216 dw2_asm_output_nstring (buffer, -1, "The macro");
14220 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14221 the tail part of the directive line, i.e. the part which is past the
14222 initial whitespace, #, whitespace, directive-name, whitespace part. */
14225 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14226 const char *buffer ATTRIBUTE_UNUSED)
14228 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14230 switch_to_section (debug_macinfo_section);
14231 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14232 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14233 dw2_asm_output_nstring (buffer, -1, "The macro");
14237 /* Set up for Dwarf output at the start of compilation. */
14240 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14242 /* Allocate the file_table. */
14243 file_table = htab_create_ggc (50, file_table_hash,
14244 file_table_eq, NULL);
14246 /* Allocate the decl_die_table. */
14247 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14248 decl_die_table_eq, NULL);
14250 /* Allocate the decl_loc_table. */
14251 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14252 decl_loc_table_eq, NULL);
14254 /* Allocate the initial hunk of the decl_scope_table. */
14255 decl_scope_table = VEC_alloc (tree, gc, 256);
14257 /* Allocate the initial hunk of the abbrev_die_table. */
14258 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
14259 * sizeof (dw_die_ref));
14260 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14261 /* Zero-th entry is allocated, but unused. */
14262 abbrev_die_table_in_use = 1;
14264 /* Allocate the initial hunk of the line_info_table. */
14265 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
14266 * sizeof (dw_line_info_entry));
14267 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14269 /* Zero-th entry is allocated, but unused. */
14270 line_info_table_in_use = 1;
14272 /* Allocate the pubtypes and pubnames vectors. */
14273 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14274 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14276 /* Generate the initial DIE for the .debug section. Note that the (string)
14277 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14278 will (typically) be a relative pathname and that this pathname should be
14279 taken as being relative to the directory from which the compiler was
14280 invoked when the given (base) source file was compiled. We will fill
14281 in this value in dwarf2out_finish. */
14282 comp_unit_die = gen_compile_unit_die (NULL);
14284 incomplete_types = VEC_alloc (tree, gc, 64);
14286 used_rtx_array = VEC_alloc (rtx, gc, 32);
14288 debug_info_section = get_section (DEBUG_INFO_SECTION,
14289 SECTION_DEBUG, NULL);
14290 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14291 SECTION_DEBUG, NULL);
14292 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14293 SECTION_DEBUG, NULL);
14294 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14295 SECTION_DEBUG, NULL);
14296 debug_line_section = get_section (DEBUG_LINE_SECTION,
14297 SECTION_DEBUG, NULL);
14298 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14299 SECTION_DEBUG, NULL);
14300 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14301 SECTION_DEBUG, NULL);
14302 #ifdef DEBUG_PUBTYPES_SECTION
14303 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14304 SECTION_DEBUG, NULL);
14306 debug_str_section = get_section (DEBUG_STR_SECTION,
14307 DEBUG_STR_SECTION_FLAGS, NULL);
14308 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14309 SECTION_DEBUG, NULL);
14310 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14311 SECTION_DEBUG, NULL);
14313 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14314 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14315 DEBUG_ABBREV_SECTION_LABEL, 0);
14316 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14317 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14318 COLD_TEXT_SECTION_LABEL, 0);
14319 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14321 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14322 DEBUG_INFO_SECTION_LABEL, 0);
14323 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14324 DEBUG_LINE_SECTION_LABEL, 0);
14325 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14326 DEBUG_RANGES_SECTION_LABEL, 0);
14327 switch_to_section (debug_abbrev_section);
14328 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14329 switch_to_section (debug_info_section);
14330 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14331 switch_to_section (debug_line_section);
14332 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14334 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14336 switch_to_section (debug_macinfo_section);
14337 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14338 DEBUG_MACINFO_SECTION_LABEL, 0);
14339 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14342 switch_to_section (text_section);
14343 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14344 if (flag_reorder_blocks_and_partition)
14346 switch_to_section (unlikely_text_section ());
14347 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14351 /* A helper function for dwarf2out_finish called through
14352 ht_forall. Emit one queued .debug_str string. */
14355 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14357 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14359 if (node->form == DW_FORM_strp)
14361 switch_to_section (debug_str_section);
14362 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14363 assemble_string (node->str, strlen (node->str) + 1);
14369 #if ENABLE_ASSERT_CHECKING
14370 /* Verify that all marks are clear. */
14373 verify_marks_clear (dw_die_ref die)
14377 gcc_assert (! die->die_mark);
14378 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14380 #endif /* ENABLE_ASSERT_CHECKING */
14382 /* Clear the marks for a die and its children.
14383 Be cool if the mark isn't set. */
14386 prune_unmark_dies (dw_die_ref die)
14392 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14395 /* Given DIE that we're marking as used, find any other dies
14396 it references as attributes and mark them as used. */
14399 prune_unused_types_walk_attribs (dw_die_ref die)
14404 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14406 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14408 /* A reference to another DIE.
14409 Make sure that it will get emitted. */
14410 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14412 /* Set the string's refcount to 0 so that prune_unused_types_mark
14413 accounts properly for it. */
14414 if (AT_class (a) == dw_val_class_str)
14415 a->dw_attr_val.v.val_str->refcount = 0;
14420 /* Mark DIE as being used. If DOKIDS is true, then walk down
14421 to DIE's children. */
14424 prune_unused_types_mark (dw_die_ref die, int dokids)
14428 if (die->die_mark == 0)
14430 /* We haven't done this node yet. Mark it as used. */
14433 /* We also have to mark its parents as used.
14434 (But we don't want to mark our parents' kids due to this.) */
14435 if (die->die_parent)
14436 prune_unused_types_mark (die->die_parent, 0);
14438 /* Mark any referenced nodes. */
14439 prune_unused_types_walk_attribs (die);
14441 /* If this node is a specification,
14442 also mark the definition, if it exists. */
14443 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14444 prune_unused_types_mark (die->die_definition, 1);
14447 if (dokids && die->die_mark != 2)
14449 /* We need to walk the children, but haven't done so yet.
14450 Remember that we've walked the kids. */
14453 /* If this is an array type, we need to make sure our
14454 kids get marked, even if they're types. */
14455 if (die->die_tag == DW_TAG_array_type)
14456 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14458 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14463 /* Walk the tree DIE and mark types that we actually use. */
14466 prune_unused_types_walk (dw_die_ref die)
14470 /* Don't do anything if this node is already marked. */
14474 switch (die->die_tag)
14476 case DW_TAG_const_type:
14477 case DW_TAG_packed_type:
14478 case DW_TAG_pointer_type:
14479 case DW_TAG_reference_type:
14480 case DW_TAG_volatile_type:
14481 case DW_TAG_typedef:
14482 case DW_TAG_array_type:
14483 case DW_TAG_structure_type:
14484 case DW_TAG_union_type:
14485 case DW_TAG_class_type:
14486 case DW_TAG_friend:
14487 case DW_TAG_variant_part:
14488 case DW_TAG_enumeration_type:
14489 case DW_TAG_subroutine_type:
14490 case DW_TAG_string_type:
14491 case DW_TAG_set_type:
14492 case DW_TAG_subrange_type:
14493 case DW_TAG_ptr_to_member_type:
14494 case DW_TAG_file_type:
14495 if (die->die_perennial_p)
14498 /* It's a type node --- don't mark it. */
14502 /* Mark everything else. */
14508 /* Now, mark any dies referenced from here. */
14509 prune_unused_types_walk_attribs (die);
14511 /* Mark children. */
14512 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14515 /* Increment the string counts on strings referred to from DIE's
14519 prune_unused_types_update_strings (dw_die_ref die)
14524 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14525 if (AT_class (a) == dw_val_class_str)
14527 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
14529 /* Avoid unnecessarily putting strings that are used less than
14530 twice in the hash table. */
14532 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
14535 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
14536 htab_hash_string (s->str),
14538 gcc_assert (*slot == NULL);
14544 /* Remove from the tree DIE any dies that aren't marked. */
14547 prune_unused_types_prune (dw_die_ref die)
14551 gcc_assert (die->die_mark);
14552 prune_unused_types_update_strings (die);
14554 if (! die->die_child)
14557 c = die->die_child;
14559 dw_die_ref prev = c;
14560 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
14561 if (c == die->die_child)
14563 /* No marked children between 'prev' and the end of the list. */
14565 /* No marked children at all. */
14566 die->die_child = NULL;
14569 prev->die_sib = c->die_sib;
14570 die->die_child = prev;
14575 if (c != prev->die_sib)
14577 prune_unused_types_prune (c);
14578 } while (c != die->die_child);
14582 /* Remove dies representing declarations that we never use. */
14585 prune_unused_types (void)
14588 limbo_die_node *node;
14591 #if ENABLE_ASSERT_CHECKING
14592 /* All the marks should already be clear. */
14593 verify_marks_clear (comp_unit_die);
14594 for (node = limbo_die_list; node; node = node->next)
14595 verify_marks_clear (node->die);
14596 #endif /* ENABLE_ASSERT_CHECKING */
14598 /* Set the mark on nodes that are actually used. */
14599 prune_unused_types_walk (comp_unit_die);
14600 for (node = limbo_die_list; node; node = node->next)
14601 prune_unused_types_walk (node->die);
14603 /* Also set the mark on nodes referenced from the
14604 pubname_table or arange_table. */
14605 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
14606 prune_unused_types_mark (pub->die, 1);
14607 for (i = 0; i < arange_table_in_use; i++)
14608 prune_unused_types_mark (arange_table[i], 1);
14610 /* Get rid of nodes that aren't marked; and update the string counts. */
14611 if (debug_str_hash)
14612 htab_empty (debug_str_hash);
14613 prune_unused_types_prune (comp_unit_die);
14614 for (node = limbo_die_list; node; node = node->next)
14615 prune_unused_types_prune (node->die);
14617 /* Leave the marks clear. */
14618 prune_unmark_dies (comp_unit_die);
14619 for (node = limbo_die_list; node; node = node->next)
14620 prune_unmark_dies (node->die);
14623 /* Set the parameter to true if there are any relative pathnames in
14626 file_table_relative_p (void ** slot, void *param)
14629 struct dwarf_file_data *d = *slot;
14630 if (!IS_ABSOLUTE_PATH (d->filename))
14638 /* Output stuff that dwarf requires at the end of every file,
14639 and generate the DWARF-2 debugging info. */
14642 dwarf2out_finish (const char *filename)
14644 limbo_die_node *node, *next_node;
14645 dw_die_ref die = 0;
14647 /* Add the name for the main input file now. We delayed this from
14648 dwarf2out_init to avoid complications with PCH. */
14649 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
14650 if (!IS_ABSOLUTE_PATH (filename))
14651 add_comp_dir_attribute (comp_unit_die);
14652 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14655 htab_traverse (file_table, file_table_relative_p, &p);
14657 add_comp_dir_attribute (comp_unit_die);
14660 /* Traverse the limbo die list, and add parent/child links. The only
14661 dies without parents that should be here are concrete instances of
14662 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14663 For concrete instances, we can get the parent die from the abstract
14665 for (node = limbo_die_list; node; node = next_node)
14667 next_node = node->next;
14670 if (die->die_parent == NULL)
14672 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
14675 add_child_die (origin->die_parent, die);
14676 else if (die == comp_unit_die)
14678 else if (errorcount > 0 || sorrycount > 0)
14679 /* It's OK to be confused by errors in the input. */
14680 add_child_die (comp_unit_die, die);
14683 /* In certain situations, the lexical block containing a
14684 nested function can be optimized away, which results
14685 in the nested function die being orphaned. Likewise
14686 with the return type of that nested function. Force
14687 this to be a child of the containing function.
14689 It may happen that even the containing function got fully
14690 inlined and optimized out. In that case we are lost and
14691 assign the empty child. This should not be big issue as
14692 the function is likely unreachable too. */
14693 tree context = NULL_TREE;
14695 gcc_assert (node->created_for);
14697 if (DECL_P (node->created_for))
14698 context = DECL_CONTEXT (node->created_for);
14699 else if (TYPE_P (node->created_for))
14700 context = TYPE_CONTEXT (node->created_for);
14702 gcc_assert (context
14703 && (TREE_CODE (context) == FUNCTION_DECL
14704 || TREE_CODE (context) == NAMESPACE_DECL));
14706 origin = lookup_decl_die (context);
14708 add_child_die (origin, die);
14710 add_child_die (comp_unit_die, die);
14715 limbo_die_list = NULL;
14717 /* Walk through the list of incomplete types again, trying once more to
14718 emit full debugging info for them. */
14719 retry_incomplete_types ();
14721 if (flag_eliminate_unused_debug_types)
14722 prune_unused_types ();
14724 /* Generate separate CUs for each of the include files we've seen.
14725 They will go into limbo_die_list. */
14726 if (flag_eliminate_dwarf2_dups)
14727 break_out_includes (comp_unit_die);
14729 /* Traverse the DIE's and add add sibling attributes to those DIE's
14730 that have children. */
14731 add_sibling_attributes (comp_unit_die);
14732 for (node = limbo_die_list; node; node = node->next)
14733 add_sibling_attributes (node->die);
14735 /* Output a terminator label for the .text section. */
14736 switch_to_section (text_section);
14737 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
14738 if (flag_reorder_blocks_and_partition)
14740 switch_to_section (unlikely_text_section ());
14741 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
14744 /* We can only use the low/high_pc attributes if all of the code was
14746 if (!have_multiple_function_sections)
14748 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
14749 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
14754 unsigned fde_idx = 0;
14756 /* We need to give .debug_loc and .debug_ranges an appropriate
14757 "base address". Use zero so that these addresses become
14758 absolute. Historically, we've emitted the unexpected
14759 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
14760 Emit both to give time for other tools to adapt. */
14761 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
14762 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
14764 add_AT_range_list (comp_unit_die, DW_AT_ranges,
14765 add_ranges_by_labels (text_section_label,
14767 if (flag_reorder_blocks_and_partition)
14768 add_ranges_by_labels (cold_text_section_label,
14771 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
14773 dw_fde_ref fde = &fde_table[fde_idx];
14775 if (fde->dw_fde_switched_sections)
14777 add_ranges_by_labels (fde->dw_fde_hot_section_label,
14778 fde->dw_fde_hot_section_end_label);
14779 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
14780 fde->dw_fde_unlikely_section_end_label);
14783 add_ranges_by_labels (fde->dw_fde_begin,
14790 /* Output location list section if necessary. */
14791 if (have_location_lists)
14793 /* Output the location lists info. */
14794 switch_to_section (debug_loc_section);
14795 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
14796 DEBUG_LOC_SECTION_LABEL, 0);
14797 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
14798 output_location_lists (die);
14801 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14802 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
14803 debug_line_section_label);
14805 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14806 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
14808 /* Output all of the compilation units. We put the main one last so that
14809 the offsets are available to output_pubnames. */
14810 for (node = limbo_die_list; node; node = node->next)
14811 output_comp_unit (node->die, 0);
14813 output_comp_unit (comp_unit_die, 0);
14815 /* Output the abbreviation table. */
14816 switch_to_section (debug_abbrev_section);
14817 output_abbrev_section ();
14819 /* Output public names table if necessary. */
14820 if (!VEC_empty (pubname_entry, pubname_table))
14822 switch_to_section (debug_pubnames_section);
14823 output_pubnames (pubname_table);
14826 #ifdef DEBUG_PUBTYPES_SECTION
14827 /* Output public types table if necessary. */
14828 if (!VEC_empty (pubname_entry, pubtype_table))
14830 switch_to_section (debug_pubtypes_section);
14831 output_pubnames (pubtype_table);
14835 /* Output the address range information. We only put functions in the arange
14836 table, so don't write it out if we don't have any. */
14837 if (fde_table_in_use)
14839 switch_to_section (debug_aranges_section);
14843 /* Output ranges section if necessary. */
14844 if (ranges_table_in_use)
14846 switch_to_section (debug_ranges_section);
14847 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
14851 /* Output the source line correspondence table. We must do this
14852 even if there is no line information. Otherwise, on an empty
14853 translation unit, we will generate a present, but empty,
14854 .debug_info section. IRIX 6.5 `nm' will then complain when
14855 examining the file. This is done late so that any filenames
14856 used by the debug_info section are marked as 'used'. */
14857 if (! DWARF2_ASM_LINE_DEBUG_INFO)
14859 switch_to_section (debug_line_section);
14860 output_line_info ();
14863 /* Have to end the macro section. */
14864 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14866 switch_to_section (debug_macinfo_section);
14867 dw2_asm_output_data (1, 0, "End compilation unit");
14870 /* If we emitted any DW_FORM_strp form attribute, output the string
14872 if (debug_str_hash)
14873 htab_traverse (debug_str_hash, output_indirect_string, NULL);
14877 /* This should never be used, but its address is needed for comparisons. */
14878 const struct gcc_debug_hooks dwarf2_debug_hooks;
14880 #endif /* DWARF2_DEBUGGING_INFO */
14882 #include "gt-dwarf2out.h"