1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* 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 /* Get the current fde_table entry we should use. */
320 static inline dw_fde_ref
323 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
326 /* A list of call frame insns for the CIE. */
327 static GTY(()) dw_cfi_ref cie_cfi_head;
329 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
330 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
331 attribute that accelerates the lookup of the FDE associated
332 with the subprogram. This variable holds the table index of the FDE
333 associated with the current function (body) definition. */
334 static unsigned current_funcdef_fde;
337 struct indirect_string_node GTY(())
340 unsigned int refcount;
345 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
347 static GTY(()) int dw2_string_counter;
348 static GTY(()) unsigned long dwarf2out_cfi_label_num;
350 /* True if the compilation unit places functions in more than one section. */
351 static GTY(()) bool have_multiple_function_sections = false;
353 /* Whether the default text and cold text sections have been used at all. */
355 static GTY(()) bool text_section_used = false;
356 static GTY(()) bool cold_text_section_used = false;
358 /* The default cold text section. */
359 static GTY(()) section *cold_text_section;
361 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
363 /* Forward declarations for functions defined in this file. */
365 static char *stripattributes (const char *);
366 static const char *dwarf_cfi_name (unsigned);
367 static dw_cfi_ref new_cfi (void);
368 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
369 static void add_fde_cfi (const char *, dw_cfi_ref);
370 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
371 static void lookup_cfa (dw_cfa_location *);
372 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
373 #ifdef DWARF2_UNWIND_INFO
374 static void initial_return_save (rtx);
376 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
377 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
378 static void output_call_frame_info (int);
379 static void dwarf2out_note_section_used (void);
380 static void dwarf2out_stack_adjust (rtx, bool);
381 static void flush_queued_reg_saves (void);
382 static bool clobbers_queued_reg_save (const_rtx);
383 static void dwarf2out_frame_debug_expr (rtx, const char *);
385 /* Support for complex CFA locations. */
386 static void output_cfa_loc (dw_cfi_ref);
387 static void get_cfa_from_loc_descr (dw_cfa_location *,
388 struct dw_loc_descr_struct *);
389 static struct dw_loc_descr_struct *build_cfa_loc
390 (dw_cfa_location *, HOST_WIDE_INT);
391 static void def_cfa_1 (const char *, dw_cfa_location *);
393 /* How to start an assembler comment. */
394 #ifndef ASM_COMMENT_START
395 #define ASM_COMMENT_START ";#"
398 /* Data and reference forms for relocatable data. */
399 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
400 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
402 #ifndef DEBUG_FRAME_SECTION
403 #define DEBUG_FRAME_SECTION ".debug_frame"
406 #ifndef FUNC_BEGIN_LABEL
407 #define FUNC_BEGIN_LABEL "LFB"
410 #ifndef FUNC_END_LABEL
411 #define FUNC_END_LABEL "LFE"
414 #ifndef FRAME_BEGIN_LABEL
415 #define FRAME_BEGIN_LABEL "Lframe"
417 #define CIE_AFTER_SIZE_LABEL "LSCIE"
418 #define CIE_END_LABEL "LECIE"
419 #define FDE_LABEL "LSFDE"
420 #define FDE_AFTER_SIZE_LABEL "LASFDE"
421 #define FDE_END_LABEL "LEFDE"
422 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
423 #define LINE_NUMBER_END_LABEL "LELT"
424 #define LN_PROLOG_AS_LABEL "LASLTP"
425 #define LN_PROLOG_END_LABEL "LELTP"
426 #define DIE_LABEL_PREFIX "DW"
428 /* The DWARF 2 CFA column which tracks the return address. Normally this
429 is the column for PC, or the first column after all of the hard
431 #ifndef DWARF_FRAME_RETURN_COLUMN
433 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
435 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
439 /* The mapping from gcc register number to DWARF 2 CFA column number. By
440 default, we just provide columns for all registers. */
441 #ifndef DWARF_FRAME_REGNUM
442 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
445 /* Hook used by __throw. */
448 expand_builtin_dwarf_sp_column (void)
450 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
451 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
454 /* Return a pointer to a copy of the section string name S with all
455 attributes stripped off, and an asterisk prepended (for assemble_name). */
458 stripattributes (const char *s)
460 char *stripped = XNEWVEC (char, strlen (s) + 2);
465 while (*s && *s != ',')
472 /* MEM is a memory reference for the register size table, each element of
473 which has mode MODE. Initialize column C as a return address column. */
476 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
478 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
479 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
480 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
483 /* Generate code to initialize the register size table. */
486 expand_builtin_init_dwarf_reg_sizes (tree address)
489 enum machine_mode mode = TYPE_MODE (char_type_node);
490 rtx addr = expand_normal (address);
491 rtx mem = gen_rtx_MEM (BLKmode, addr);
492 bool wrote_return_column = false;
494 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
496 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
498 if (rnum < DWARF_FRAME_REGISTERS)
500 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
501 enum machine_mode save_mode = reg_raw_mode[i];
504 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
505 save_mode = choose_hard_reg_mode (i, 1, true);
506 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
508 if (save_mode == VOIDmode)
510 wrote_return_column = true;
512 size = GET_MODE_SIZE (save_mode);
516 emit_move_insn (adjust_address (mem, mode, offset),
517 gen_int_mode (size, mode));
521 if (!wrote_return_column)
522 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
524 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
525 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
528 targetm.init_dwarf_reg_sizes_extra (address);
531 /* Convert a DWARF call frame info. operation to its string name */
534 dwarf_cfi_name (unsigned int cfi_opc)
538 case DW_CFA_advance_loc:
539 return "DW_CFA_advance_loc";
541 return "DW_CFA_offset";
543 return "DW_CFA_restore";
547 return "DW_CFA_set_loc";
548 case DW_CFA_advance_loc1:
549 return "DW_CFA_advance_loc1";
550 case DW_CFA_advance_loc2:
551 return "DW_CFA_advance_loc2";
552 case DW_CFA_advance_loc4:
553 return "DW_CFA_advance_loc4";
554 case DW_CFA_offset_extended:
555 return "DW_CFA_offset_extended";
556 case DW_CFA_restore_extended:
557 return "DW_CFA_restore_extended";
558 case DW_CFA_undefined:
559 return "DW_CFA_undefined";
560 case DW_CFA_same_value:
561 return "DW_CFA_same_value";
562 case DW_CFA_register:
563 return "DW_CFA_register";
564 case DW_CFA_remember_state:
565 return "DW_CFA_remember_state";
566 case DW_CFA_restore_state:
567 return "DW_CFA_restore_state";
569 return "DW_CFA_def_cfa";
570 case DW_CFA_def_cfa_register:
571 return "DW_CFA_def_cfa_register";
572 case DW_CFA_def_cfa_offset:
573 return "DW_CFA_def_cfa_offset";
576 case DW_CFA_def_cfa_expression:
577 return "DW_CFA_def_cfa_expression";
578 case DW_CFA_expression:
579 return "DW_CFA_expression";
580 case DW_CFA_offset_extended_sf:
581 return "DW_CFA_offset_extended_sf";
582 case DW_CFA_def_cfa_sf:
583 return "DW_CFA_def_cfa_sf";
584 case DW_CFA_def_cfa_offset_sf:
585 return "DW_CFA_def_cfa_offset_sf";
587 /* SGI/MIPS specific */
588 case DW_CFA_MIPS_advance_loc8:
589 return "DW_CFA_MIPS_advance_loc8";
592 case DW_CFA_GNU_window_save:
593 return "DW_CFA_GNU_window_save";
594 case DW_CFA_GNU_args_size:
595 return "DW_CFA_GNU_args_size";
596 case DW_CFA_GNU_negative_offset_extended:
597 return "DW_CFA_GNU_negative_offset_extended";
600 return "DW_CFA_<unknown>";
604 /* Return a pointer to a newly allocated Call Frame Instruction. */
606 static inline dw_cfi_ref
609 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
611 cfi->dw_cfi_next = NULL;
612 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
613 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
618 /* Add a Call Frame Instruction to list of instructions. */
621 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
625 /* Find the end of the chain. */
626 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
632 /* Generate a new label for the CFI info to refer to. */
635 dwarf2out_cfi_label (void)
637 static char label[20];
639 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
640 ASM_OUTPUT_LABEL (asm_out_file, label);
644 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
645 or to the CIE if LABEL is NULL. */
648 add_fde_cfi (const char *label, dw_cfi_ref cfi)
652 dw_fde_ref fde = current_fde ();
654 gcc_assert (fde != NULL);
657 label = dwarf2out_cfi_label ();
659 if (fde->dw_fde_current_label == NULL
660 || strcmp (label, fde->dw_fde_current_label) != 0)
664 label = xstrdup (label);
666 /* Set the location counter to the new label. */
668 /* If we have a current label, advance from there, otherwise
669 set the location directly using set_loc. */
670 xcfi->dw_cfi_opc = fde->dw_fde_current_label
671 ? DW_CFA_advance_loc4
673 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
674 add_cfi (&fde->dw_fde_cfi, xcfi);
676 fde->dw_fde_current_label = label;
679 add_cfi (&fde->dw_fde_cfi, cfi);
683 add_cfi (&cie_cfi_head, cfi);
686 /* Subroutine of lookup_cfa. */
689 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
691 switch (cfi->dw_cfi_opc)
693 case DW_CFA_def_cfa_offset:
694 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
696 case DW_CFA_def_cfa_offset_sf:
698 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
700 case DW_CFA_def_cfa_register:
701 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
704 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
705 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
707 case DW_CFA_def_cfa_sf:
708 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
710 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
712 case DW_CFA_def_cfa_expression:
713 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
720 /* Find the previous value for the CFA. */
723 lookup_cfa (dw_cfa_location *loc)
728 loc->reg = INVALID_REGNUM;
731 loc->base_offset = 0;
733 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
734 lookup_cfa_1 (cfi, loc);
736 fde = current_fde ();
738 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
739 lookup_cfa_1 (cfi, loc);
742 /* The current rule for calculating the DWARF2 canonical frame address. */
743 static dw_cfa_location cfa;
745 /* The register used for saving registers to the stack, and its offset
747 static dw_cfa_location cfa_store;
749 /* The running total of the size of arguments pushed onto the stack. */
750 static HOST_WIDE_INT args_size;
752 /* The last args_size we actually output. */
753 static HOST_WIDE_INT old_args_size;
755 /* Entry point to update the canonical frame address (CFA).
756 LABEL is passed to add_fde_cfi. The value of CFA is now to be
757 calculated from REG+OFFSET. */
760 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
767 def_cfa_1 (label, &loc);
770 /* Determine if two dw_cfa_location structures define the same data. */
773 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
775 return (loc1->reg == loc2->reg
776 && loc1->offset == loc2->offset
777 && loc1->indirect == loc2->indirect
778 && (loc1->indirect == 0
779 || loc1->base_offset == loc2->base_offset));
782 /* This routine does the actual work. The CFA is now calculated from
783 the dw_cfa_location structure. */
786 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
789 dw_cfa_location old_cfa, loc;
794 if (cfa_store.reg == loc.reg && loc.indirect == 0)
795 cfa_store.offset = loc.offset;
797 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
798 lookup_cfa (&old_cfa);
800 /* If nothing changed, no need to issue any call frame instructions. */
801 if (cfa_equal_p (&loc, &old_cfa))
806 if (loc.reg == old_cfa.reg && !loc.indirect)
808 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
809 the CFA register did not change but the offset did. */
812 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
813 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
815 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
816 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
820 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
821 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
825 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
826 else if (loc.offset == old_cfa.offset
827 && old_cfa.reg != INVALID_REGNUM
830 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
831 indicating the CFA register has changed to <register> but the
832 offset has not changed. */
833 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
834 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
838 else if (loc.indirect == 0)
840 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
841 indicating the CFA register has changed to <register> with
842 the specified offset. */
845 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
846 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
848 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
849 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
850 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
854 cfi->dw_cfi_opc = DW_CFA_def_cfa;
855 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
856 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
861 /* Construct a DW_CFA_def_cfa_expression instruction to
862 calculate the CFA using a full location expression since no
863 register-offset pair is available. */
864 struct dw_loc_descr_struct *loc_list;
866 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
867 loc_list = build_cfa_loc (&loc, 0);
868 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
871 add_fde_cfi (label, cfi);
874 /* Add the CFI for saving a register. REG is the CFA column number.
875 LABEL is passed to add_fde_cfi.
876 If SREG is -1, the register is saved at OFFSET from the CFA;
877 otherwise it is saved in SREG. */
880 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
882 dw_cfi_ref cfi = new_cfi ();
884 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
886 if (sreg == INVALID_REGNUM)
889 /* The register number won't fit in 6 bits, so we have to use
891 cfi->dw_cfi_opc = DW_CFA_offset_extended;
893 cfi->dw_cfi_opc = DW_CFA_offset;
895 #ifdef ENABLE_CHECKING
897 /* If we get an offset that is not a multiple of
898 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
899 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
901 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
903 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
906 offset /= DWARF_CIE_DATA_ALIGNMENT;
908 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
910 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
912 else if (sreg == reg)
913 cfi->dw_cfi_opc = DW_CFA_same_value;
916 cfi->dw_cfi_opc = DW_CFA_register;
917 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
920 add_fde_cfi (label, cfi);
923 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
924 This CFI tells the unwinder that it needs to restore the window registers
925 from the previous frame's window save area.
927 ??? Perhaps we should note in the CIE where windows are saved (instead of
928 assuming 0(cfa)) and what registers are in the window. */
931 dwarf2out_window_save (const char *label)
933 dw_cfi_ref cfi = new_cfi ();
935 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
936 add_fde_cfi (label, cfi);
939 /* Add a CFI to update the running total of the size of arguments
940 pushed onto the stack. */
943 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
947 if (size == old_args_size)
950 old_args_size = size;
953 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
954 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
955 add_fde_cfi (label, cfi);
958 /* Entry point for saving a register to the stack. REG is the GCC register
959 number. LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
964 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
967 /* Entry point for saving the return address in the stack.
968 LABEL and OFFSET are passed to reg_save. */
971 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
973 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
976 /* Entry point for saving the return address in a register.
977 LABEL and SREG are passed to reg_save. */
980 dwarf2out_return_reg (const char *label, unsigned int sreg)
982 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
985 #ifdef DWARF2_UNWIND_INFO
986 /* Record the initial position of the return address. RTL is
987 INCOMING_RETURN_ADDR_RTX. */
990 initial_return_save (rtx rtl)
992 unsigned int reg = INVALID_REGNUM;
993 HOST_WIDE_INT offset = 0;
995 switch (GET_CODE (rtl))
998 /* RA is in a register. */
999 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1003 /* RA is on the stack. */
1004 rtl = XEXP (rtl, 0);
1005 switch (GET_CODE (rtl))
1008 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1013 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1014 offset = INTVAL (XEXP (rtl, 1));
1018 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1019 offset = -INTVAL (XEXP (rtl, 1));
1029 /* The return address is at some offset from any value we can
1030 actually load. For instance, on the SPARC it is in %i7+8. Just
1031 ignore the offset for now; it doesn't matter for unwinding frames. */
1032 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1033 initial_return_save (XEXP (rtl, 0));
1040 if (reg != DWARF_FRAME_RETURN_COLUMN)
1041 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1045 /* Given a SET, calculate the amount of stack adjustment it
1048 static HOST_WIDE_INT
1049 stack_adjust_offset (const_rtx pattern)
1051 const_rtx src = SET_SRC (pattern);
1052 const_rtx dest = SET_DEST (pattern);
1053 HOST_WIDE_INT offset = 0;
1056 if (dest == stack_pointer_rtx)
1058 /* (set (reg sp) (plus (reg sp) (const_int))) */
1059 code = GET_CODE (src);
1060 if (! (code == PLUS || code == MINUS)
1061 || XEXP (src, 0) != stack_pointer_rtx
1062 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1065 offset = INTVAL (XEXP (src, 1));
1069 else if (MEM_P (dest))
1071 /* (set (mem (pre_dec (reg sp))) (foo)) */
1072 src = XEXP (dest, 0);
1073 code = GET_CODE (src);
1079 if (XEXP (src, 0) == stack_pointer_rtx)
1081 rtx val = XEXP (XEXP (src, 1), 1);
1082 /* We handle only adjustments by constant amount. */
1083 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1084 && GET_CODE (val) == CONST_INT);
1085 offset = -INTVAL (val);
1092 if (XEXP (src, 0) == stack_pointer_rtx)
1094 offset = GET_MODE_SIZE (GET_MODE (dest));
1101 if (XEXP (src, 0) == stack_pointer_rtx)
1103 offset = -GET_MODE_SIZE (GET_MODE (dest));
1118 /* Check INSN to see if it looks like a push or a stack adjustment, and
1119 make a note of it if it does. EH uses this information to find out how
1120 much extra space it needs to pop off the stack. */
1123 dwarf2out_stack_adjust (rtx insn, bool after_p)
1125 HOST_WIDE_INT offset;
1129 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1130 with this function. Proper support would require all frame-related
1131 insns to be marked, and to be able to handle saving state around
1132 epilogues textually in the middle of the function. */
1133 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1136 /* If only calls can throw, and we have a frame pointer,
1137 save up adjustments until we see the CALL_INSN. */
1138 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1140 if (CALL_P (insn) && !after_p)
1142 /* Extract the size of the args from the CALL rtx itself. */
1143 insn = PATTERN (insn);
1144 if (GET_CODE (insn) == PARALLEL)
1145 insn = XVECEXP (insn, 0, 0);
1146 if (GET_CODE (insn) == SET)
1147 insn = SET_SRC (insn);
1148 gcc_assert (GET_CODE (insn) == CALL);
1149 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1154 if (CALL_P (insn) && !after_p)
1156 if (!flag_asynchronous_unwind_tables)
1157 dwarf2out_args_size ("", args_size);
1160 else if (BARRIER_P (insn))
1162 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1163 the compiler will have already emitted a stack adjustment, but
1164 doesn't bother for calls to noreturn functions. */
1165 #ifdef STACK_GROWS_DOWNWARD
1166 offset = -args_size;
1171 else if (GET_CODE (PATTERN (insn)) == SET)
1172 offset = stack_adjust_offset (PATTERN (insn));
1173 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1174 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1176 /* There may be stack adjustments inside compound insns. Search
1178 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1179 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1180 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1188 if (cfa.reg == STACK_POINTER_REGNUM)
1189 cfa.offset += offset;
1191 #ifndef STACK_GROWS_DOWNWARD
1195 args_size += offset;
1199 label = dwarf2out_cfi_label ();
1200 def_cfa_1 (label, &cfa);
1201 if (flag_asynchronous_unwind_tables)
1202 dwarf2out_args_size (label, args_size);
1207 /* We delay emitting a register save until either (a) we reach the end
1208 of the prologue or (b) the register is clobbered. This clusters
1209 register saves so that there are fewer pc advances. */
1211 struct queued_reg_save GTY(())
1213 struct queued_reg_save *next;
1215 HOST_WIDE_INT cfa_offset;
1219 static GTY(()) struct queued_reg_save *queued_reg_saves;
1221 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1222 struct reg_saved_in_data GTY(()) {
1227 /* A list of registers saved in other registers.
1228 The list intentionally has a small maximum capacity of 4; if your
1229 port needs more than that, you might consider implementing a
1230 more efficient data structure. */
1231 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1232 static GTY(()) size_t num_regs_saved_in_regs;
1234 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1235 static const char *last_reg_save_label;
1237 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1238 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1241 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1243 struct queued_reg_save *q;
1245 /* Duplicates waste space, but it's also necessary to remove them
1246 for correctness, since the queue gets output in reverse
1248 for (q = queued_reg_saves; q != NULL; q = q->next)
1249 if (REGNO (q->reg) == REGNO (reg))
1254 q = GGC_NEW (struct queued_reg_save);
1255 q->next = queued_reg_saves;
1256 queued_reg_saves = q;
1260 q->cfa_offset = offset;
1261 q->saved_reg = sreg;
1263 last_reg_save_label = label;
1266 /* Output all the entries in QUEUED_REG_SAVES. */
1269 flush_queued_reg_saves (void)
1271 struct queued_reg_save *q;
1273 for (q = queued_reg_saves; q; q = q->next)
1276 unsigned int reg, sreg;
1278 for (i = 0; i < num_regs_saved_in_regs; i++)
1279 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1281 if (q->saved_reg && i == num_regs_saved_in_regs)
1283 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1284 num_regs_saved_in_regs++;
1286 if (i != num_regs_saved_in_regs)
1288 regs_saved_in_regs[i].orig_reg = q->reg;
1289 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1292 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1294 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1296 sreg = INVALID_REGNUM;
1297 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1300 queued_reg_saves = NULL;
1301 last_reg_save_label = NULL;
1304 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1305 location for? Or, does it clobber a register which we've previously
1306 said that some other register is saved in, and for which we now
1307 have a new location for? */
1310 clobbers_queued_reg_save (const_rtx insn)
1312 struct queued_reg_save *q;
1314 for (q = queued_reg_saves; q; q = q->next)
1317 if (modified_in_p (q->reg, insn))
1319 for (i = 0; i < num_regs_saved_in_regs; i++)
1320 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1321 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1328 /* Entry point for saving the first register into the second. */
1331 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1334 unsigned int regno, sregno;
1336 for (i = 0; i < num_regs_saved_in_regs; i++)
1337 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1339 if (i == num_regs_saved_in_regs)
1341 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1342 num_regs_saved_in_regs++;
1344 regs_saved_in_regs[i].orig_reg = reg;
1345 regs_saved_in_regs[i].saved_in_reg = sreg;
1347 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1348 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1349 reg_save (label, regno, sregno, 0);
1352 /* What register, if any, is currently saved in REG? */
1355 reg_saved_in (rtx reg)
1357 unsigned int regn = REGNO (reg);
1359 struct queued_reg_save *q;
1361 for (q = queued_reg_saves; q; q = q->next)
1362 if (q->saved_reg && regn == REGNO (q->saved_reg))
1365 for (i = 0; i < num_regs_saved_in_regs; i++)
1366 if (regs_saved_in_regs[i].saved_in_reg
1367 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1368 return regs_saved_in_regs[i].orig_reg;
1374 /* A temporary register holding an integral value used in adjusting SP
1375 or setting up the store_reg. The "offset" field holds the integer
1376 value, not an offset. */
1377 static dw_cfa_location cfa_temp;
1379 /* Record call frame debugging information for an expression EXPR,
1380 which either sets SP or FP (adjusting how we calculate the frame
1381 address) or saves a register to the stack or another register.
1382 LABEL indicates the address of EXPR.
1384 This function encodes a state machine mapping rtxes to actions on
1385 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1386 users need not read the source code.
1388 The High-Level Picture
1390 Changes in the register we use to calculate the CFA: Currently we
1391 assume that if you copy the CFA register into another register, we
1392 should take the other one as the new CFA register; this seems to
1393 work pretty well. If it's wrong for some target, it's simple
1394 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1396 Changes in the register we use for saving registers to the stack:
1397 This is usually SP, but not always. Again, we deduce that if you
1398 copy SP into another register (and SP is not the CFA register),
1399 then the new register is the one we will be using for register
1400 saves. This also seems to work.
1402 Register saves: There's not much guesswork about this one; if
1403 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1404 register save, and the register used to calculate the destination
1405 had better be the one we think we're using for this purpose.
1406 It's also assumed that a copy from a call-saved register to another
1407 register is saving that register if RTX_FRAME_RELATED_P is set on
1408 that instruction. If the copy is from a call-saved register to
1409 the *same* register, that means that the register is now the same
1410 value as in the caller.
1412 Except: If the register being saved is the CFA register, and the
1413 offset is nonzero, we are saving the CFA, so we assume we have to
1414 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1415 the intent is to save the value of SP from the previous frame.
1417 In addition, if a register has previously been saved to a different
1420 Invariants / Summaries of Rules
1422 cfa current rule for calculating the CFA. It usually
1423 consists of a register and an offset.
1424 cfa_store register used by prologue code to save things to the stack
1425 cfa_store.offset is the offset from the value of
1426 cfa_store.reg to the actual CFA
1427 cfa_temp register holding an integral value. cfa_temp.offset
1428 stores the value, which will be used to adjust the
1429 stack pointer. cfa_temp is also used like cfa_store,
1430 to track stores to the stack via fp or a temp reg.
1432 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1433 with cfa.reg as the first operand changes the cfa.reg and its
1434 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1437 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1438 expression yielding a constant. This sets cfa_temp.reg
1439 and cfa_temp.offset.
1441 Rule 5: Create a new register cfa_store used to save items to the
1444 Rules 10-14: Save a register to the stack. Define offset as the
1445 difference of the original location and cfa_store's
1446 location (or cfa_temp's location if cfa_temp is used).
1450 "{a,b}" indicates a choice of a xor b.
1451 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1454 (set <reg1> <reg2>:cfa.reg)
1455 effects: cfa.reg = <reg1>
1456 cfa.offset unchanged
1457 cfa_temp.reg = <reg1>
1458 cfa_temp.offset = cfa.offset
1461 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1462 {<const_int>,<reg>:cfa_temp.reg}))
1463 effects: cfa.reg = sp if fp used
1464 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1465 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1466 if cfa_store.reg==sp
1469 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1470 effects: cfa.reg = fp
1471 cfa_offset += +/- <const_int>
1474 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1475 constraints: <reg1> != fp
1477 effects: cfa.reg = <reg1>
1478 cfa_temp.reg = <reg1>
1479 cfa_temp.offset = cfa.offset
1482 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1483 constraints: <reg1> != fp
1485 effects: cfa_store.reg = <reg1>
1486 cfa_store.offset = cfa.offset - cfa_temp.offset
1489 (set <reg> <const_int>)
1490 effects: cfa_temp.reg = <reg>
1491 cfa_temp.offset = <const_int>
1494 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1495 effects: cfa_temp.reg = <reg1>
1496 cfa_temp.offset |= <const_int>
1499 (set <reg> (high <exp>))
1503 (set <reg> (lo_sum <exp> <const_int>))
1504 effects: cfa_temp.reg = <reg>
1505 cfa_temp.offset = <const_int>
1508 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1509 effects: cfa_store.offset -= <const_int>
1510 cfa.offset = cfa_store.offset if cfa.reg == sp
1512 cfa.base_offset = -cfa_store.offset
1515 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1516 effects: cfa_store.offset += -/+ mode_size(mem)
1517 cfa.offset = cfa_store.offset if cfa.reg == sp
1519 cfa.base_offset = -cfa_store.offset
1522 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1525 effects: cfa.reg = <reg1>
1526 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1529 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1530 effects: cfa.reg = <reg1>
1531 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1534 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1535 effects: cfa.reg = <reg1>
1536 cfa.base_offset = -cfa_temp.offset
1537 cfa_temp.offset -= mode_size(mem)
1540 (set <reg> {unspec, unspec_volatile})
1541 effects: target-dependent */
1544 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1546 rtx src, dest, span;
1547 HOST_WIDE_INT offset;
1549 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1550 the PARALLEL independently. The first element is always processed if
1551 it is a SET. This is for backward compatibility. Other elements
1552 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1553 flag is set in them. */
1554 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1557 int limit = XVECLEN (expr, 0);
1560 /* PARALLELs have strict read-modify-write semantics, so we
1561 ought to evaluate every rvalue before changing any lvalue.
1562 It's cumbersome to do that in general, but there's an
1563 easy approximation that is enough for all current users:
1564 handle register saves before register assignments. */
1565 if (GET_CODE (expr) == PARALLEL)
1566 for (par_index = 0; par_index < limit; par_index++)
1568 elem = XVECEXP (expr, 0, par_index);
1569 if (GET_CODE (elem) == SET
1570 && MEM_P (SET_DEST (elem))
1571 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1572 dwarf2out_frame_debug_expr (elem, label);
1575 for (par_index = 0; par_index < limit; par_index++)
1577 elem = XVECEXP (expr, 0, par_index);
1578 if (GET_CODE (elem) == SET
1579 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1580 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1581 dwarf2out_frame_debug_expr (elem, label);
1582 else if (GET_CODE (elem) == SET
1584 && !RTX_FRAME_RELATED_P (elem))
1586 /* Stack adjustment combining might combine some post-prologue
1587 stack adjustment into a prologue stack adjustment. */
1588 HOST_WIDE_INT offset = stack_adjust_offset (elem);
1592 if (cfa.reg == STACK_POINTER_REGNUM)
1593 cfa.offset += offset;
1595 #ifndef STACK_GROWS_DOWNWARD
1599 args_size += offset;
1603 def_cfa_1 (label, &cfa);
1604 if (flag_asynchronous_unwind_tables)
1605 dwarf2out_args_size (label, args_size);
1612 gcc_assert (GET_CODE (expr) == SET);
1614 src = SET_SRC (expr);
1615 dest = SET_DEST (expr);
1619 rtx rsi = reg_saved_in (src);
1624 switch (GET_CODE (dest))
1627 switch (GET_CODE (src))
1629 /* Setting FP from SP. */
1631 if (cfa.reg == (unsigned) REGNO (src))
1634 /* Update the CFA rule wrt SP or FP. Make sure src is
1635 relative to the current CFA register.
1637 We used to require that dest be either SP or FP, but the
1638 ARM copies SP to a temporary register, and from there to
1639 FP. So we just rely on the backends to only set
1640 RTX_FRAME_RELATED_P on appropriate insns. */
1641 cfa.reg = REGNO (dest);
1642 cfa_temp.reg = cfa.reg;
1643 cfa_temp.offset = cfa.offset;
1647 /* Saving a register in a register. */
1648 gcc_assert (!fixed_regs [REGNO (dest)]
1649 /* For the SPARC and its register window. */
1650 || (DWARF_FRAME_REGNUM (REGNO (src))
1651 == DWARF_FRAME_RETURN_COLUMN));
1652 queue_reg_save (label, src, dest, 0);
1659 if (dest == stack_pointer_rtx)
1663 switch (GET_CODE (XEXP (src, 1)))
1666 offset = INTVAL (XEXP (src, 1));
1669 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1671 offset = cfa_temp.offset;
1677 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1679 /* Restoring SP from FP in the epilogue. */
1680 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1681 cfa.reg = STACK_POINTER_REGNUM;
1683 else if (GET_CODE (src) == LO_SUM)
1684 /* Assume we've set the source reg of the LO_SUM from sp. */
1687 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1689 if (GET_CODE (src) != MINUS)
1691 if (cfa.reg == STACK_POINTER_REGNUM)
1692 cfa.offset += offset;
1693 if (cfa_store.reg == STACK_POINTER_REGNUM)
1694 cfa_store.offset += offset;
1696 else if (dest == hard_frame_pointer_rtx)
1699 /* Either setting the FP from an offset of the SP,
1700 or adjusting the FP */
1701 gcc_assert (frame_pointer_needed);
1703 gcc_assert (REG_P (XEXP (src, 0))
1704 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1705 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1706 offset = INTVAL (XEXP (src, 1));
1707 if (GET_CODE (src) != MINUS)
1709 cfa.offset += offset;
1710 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1714 gcc_assert (GET_CODE (src) != MINUS);
1717 if (REG_P (XEXP (src, 0))
1718 && REGNO (XEXP (src, 0)) == cfa.reg
1719 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1721 /* Setting a temporary CFA register that will be copied
1722 into the FP later on. */
1723 offset = - INTVAL (XEXP (src, 1));
1724 cfa.offset += offset;
1725 cfa.reg = REGNO (dest);
1726 /* Or used to save regs to the stack. */
1727 cfa_temp.reg = cfa.reg;
1728 cfa_temp.offset = cfa.offset;
1732 else if (REG_P (XEXP (src, 0))
1733 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1734 && XEXP (src, 1) == stack_pointer_rtx)
1736 /* Setting a scratch register that we will use instead
1737 of SP for saving registers to the stack. */
1738 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1739 cfa_store.reg = REGNO (dest);
1740 cfa_store.offset = cfa.offset - cfa_temp.offset;
1744 else if (GET_CODE (src) == LO_SUM
1745 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1747 cfa_temp.reg = REGNO (dest);
1748 cfa_temp.offset = INTVAL (XEXP (src, 1));
1757 cfa_temp.reg = REGNO (dest);
1758 cfa_temp.offset = INTVAL (src);
1763 gcc_assert (REG_P (XEXP (src, 0))
1764 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1765 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1767 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1768 cfa_temp.reg = REGNO (dest);
1769 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1772 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1773 which will fill in all of the bits. */
1780 case UNSPEC_VOLATILE:
1781 gcc_assert (targetm.dwarf_handle_frame_unspec);
1782 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1789 def_cfa_1 (label, &cfa);
1793 gcc_assert (REG_P (src));
1795 /* Saving a register to the stack. Make sure dest is relative to the
1797 switch (GET_CODE (XEXP (dest, 0)))
1802 /* We can't handle variable size modifications. */
1803 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1805 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1807 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1808 && cfa_store.reg == STACK_POINTER_REGNUM);
1810 cfa_store.offset += offset;
1811 if (cfa.reg == STACK_POINTER_REGNUM)
1812 cfa.offset = cfa_store.offset;
1814 offset = -cfa_store.offset;
1820 offset = GET_MODE_SIZE (GET_MODE (dest));
1821 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1824 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1825 && cfa_store.reg == STACK_POINTER_REGNUM);
1827 cfa_store.offset += offset;
1828 if (cfa.reg == STACK_POINTER_REGNUM)
1829 cfa.offset = cfa_store.offset;
1831 offset = -cfa_store.offset;
1835 /* With an offset. */
1842 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1843 && REG_P (XEXP (XEXP (dest, 0), 0)));
1844 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1845 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1848 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1850 if (cfa_store.reg == (unsigned) regno)
1851 offset -= cfa_store.offset;
1854 gcc_assert (cfa_temp.reg == (unsigned) regno);
1855 offset -= cfa_temp.offset;
1861 /* Without an offset. */
1864 int regno = REGNO (XEXP (dest, 0));
1866 if (cfa_store.reg == (unsigned) regno)
1867 offset = -cfa_store.offset;
1870 gcc_assert (cfa_temp.reg == (unsigned) regno);
1871 offset = -cfa_temp.offset;
1878 gcc_assert (cfa_temp.reg
1879 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1880 offset = -cfa_temp.offset;
1881 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1888 if (REGNO (src) != STACK_POINTER_REGNUM
1889 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1890 && (unsigned) REGNO (src) == cfa.reg)
1892 /* We're storing the current CFA reg into the stack. */
1894 if (cfa.offset == 0)
1896 /* If the source register is exactly the CFA, assume
1897 we're saving SP like any other register; this happens
1899 def_cfa_1 (label, &cfa);
1900 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1905 /* Otherwise, we'll need to look in the stack to
1906 calculate the CFA. */
1907 rtx x = XEXP (dest, 0);
1911 gcc_assert (REG_P (x));
1913 cfa.reg = REGNO (x);
1914 cfa.base_offset = offset;
1916 def_cfa_1 (label, &cfa);
1921 def_cfa_1 (label, &cfa);
1923 span = targetm.dwarf_register_span (src);
1926 queue_reg_save (label, src, NULL_RTX, offset);
1929 /* We have a PARALLEL describing where the contents of SRC
1930 live. Queue register saves for each piece of the
1934 HOST_WIDE_INT span_offset = offset;
1936 gcc_assert (GET_CODE (span) == PARALLEL);
1938 limit = XVECLEN (span, 0);
1939 for (par_index = 0; par_index < limit; par_index++)
1941 rtx elem = XVECEXP (span, 0, par_index);
1943 queue_reg_save (label, elem, NULL_RTX, span_offset);
1944 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1955 /* Record call frame debugging information for INSN, which either
1956 sets SP or FP (adjusting how we calculate the frame address) or saves a
1957 register to the stack. If INSN is NULL_RTX, initialize our state.
1959 If AFTER_P is false, we're being called before the insn is emitted,
1960 otherwise after. Call instructions get invoked twice. */
1963 dwarf2out_frame_debug (rtx insn, bool after_p)
1968 if (insn == NULL_RTX)
1972 /* Flush any queued register saves. */
1973 flush_queued_reg_saves ();
1975 /* Set up state for generating call frame debug info. */
1978 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1980 cfa.reg = STACK_POINTER_REGNUM;
1983 cfa_temp.offset = 0;
1985 for (i = 0; i < num_regs_saved_in_regs; i++)
1987 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1988 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1990 num_regs_saved_in_regs = 0;
1994 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1995 flush_queued_reg_saves ();
1997 if (! RTX_FRAME_RELATED_P (insn))
1999 if (!ACCUMULATE_OUTGOING_ARGS)
2000 dwarf2out_stack_adjust (insn, after_p);
2004 label = dwarf2out_cfi_label ();
2005 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2007 insn = XEXP (src, 0);
2009 insn = PATTERN (insn);
2011 dwarf2out_frame_debug_expr (insn, label);
2016 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2017 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2018 (enum dwarf_call_frame_info cfi);
2020 static enum dw_cfi_oprnd_type
2021 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2026 case DW_CFA_GNU_window_save:
2027 return dw_cfi_oprnd_unused;
2029 case DW_CFA_set_loc:
2030 case DW_CFA_advance_loc1:
2031 case DW_CFA_advance_loc2:
2032 case DW_CFA_advance_loc4:
2033 case DW_CFA_MIPS_advance_loc8:
2034 return dw_cfi_oprnd_addr;
2037 case DW_CFA_offset_extended:
2038 case DW_CFA_def_cfa:
2039 case DW_CFA_offset_extended_sf:
2040 case DW_CFA_def_cfa_sf:
2041 case DW_CFA_restore_extended:
2042 case DW_CFA_undefined:
2043 case DW_CFA_same_value:
2044 case DW_CFA_def_cfa_register:
2045 case DW_CFA_register:
2046 return dw_cfi_oprnd_reg_num;
2048 case DW_CFA_def_cfa_offset:
2049 case DW_CFA_GNU_args_size:
2050 case DW_CFA_def_cfa_offset_sf:
2051 return dw_cfi_oprnd_offset;
2053 case DW_CFA_def_cfa_expression:
2054 case DW_CFA_expression:
2055 return dw_cfi_oprnd_loc;
2062 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2063 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2064 (enum dwarf_call_frame_info cfi);
2066 static enum dw_cfi_oprnd_type
2067 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2071 case DW_CFA_def_cfa:
2072 case DW_CFA_def_cfa_sf:
2074 case DW_CFA_offset_extended_sf:
2075 case DW_CFA_offset_extended:
2076 return dw_cfi_oprnd_offset;
2078 case DW_CFA_register:
2079 return dw_cfi_oprnd_reg_num;
2082 return dw_cfi_oprnd_unused;
2086 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2088 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2089 switch to the data section instead, and write out a synthetic label
2093 switch_to_eh_frame_section (void)
2097 #ifdef EH_FRAME_SECTION_NAME
2098 if (eh_frame_section == 0)
2102 if (EH_TABLES_CAN_BE_READ_ONLY)
2108 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2110 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2112 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2114 flags = ((! flag_pic
2115 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2116 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2117 && (per_encoding & 0x70) != DW_EH_PE_absptr
2118 && (per_encoding & 0x70) != DW_EH_PE_aligned
2119 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2120 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2121 ? 0 : SECTION_WRITE);
2124 flags = SECTION_WRITE;
2125 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2129 if (eh_frame_section)
2130 switch_to_section (eh_frame_section);
2133 /* We have no special eh_frame section. Put the information in
2134 the data section and emit special labels to guide collect2. */
2135 switch_to_section (data_section);
2136 label = get_file_function_name ("F");
2137 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2138 targetm.asm_out.globalize_label (asm_out_file,
2139 IDENTIFIER_POINTER (label));
2140 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2144 /* Output a Call Frame Information opcode and its operand(s). */
2147 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2150 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2151 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2152 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2153 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2154 ((unsigned HOST_WIDE_INT)
2155 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2156 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2158 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2159 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2160 "DW_CFA_offset, column 0x%lx", r);
2161 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2163 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2165 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2166 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2167 "DW_CFA_restore, column 0x%lx", r);
2171 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2172 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2174 switch (cfi->dw_cfi_opc)
2176 case DW_CFA_set_loc:
2178 dw2_asm_output_encoded_addr_rtx (
2179 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2180 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2183 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2184 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2185 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2188 case DW_CFA_advance_loc1:
2189 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2190 fde->dw_fde_current_label, NULL);
2191 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2194 case DW_CFA_advance_loc2:
2195 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2196 fde->dw_fde_current_label, NULL);
2197 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2200 case DW_CFA_advance_loc4:
2201 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2202 fde->dw_fde_current_label, NULL);
2203 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2206 case DW_CFA_MIPS_advance_loc8:
2207 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2208 fde->dw_fde_current_label, NULL);
2209 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2212 case DW_CFA_offset_extended:
2213 case DW_CFA_def_cfa:
2214 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2215 dw2_asm_output_data_uleb128 (r, NULL);
2216 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2219 case DW_CFA_offset_extended_sf:
2220 case DW_CFA_def_cfa_sf:
2221 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2222 dw2_asm_output_data_uleb128 (r, NULL);
2223 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2226 case DW_CFA_restore_extended:
2227 case DW_CFA_undefined:
2228 case DW_CFA_same_value:
2229 case DW_CFA_def_cfa_register:
2230 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2231 dw2_asm_output_data_uleb128 (r, NULL);
2234 case DW_CFA_register:
2235 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2236 dw2_asm_output_data_uleb128 (r, NULL);
2237 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2238 dw2_asm_output_data_uleb128 (r, NULL);
2241 case DW_CFA_def_cfa_offset:
2242 case DW_CFA_GNU_args_size:
2243 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2246 case DW_CFA_def_cfa_offset_sf:
2247 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2250 case DW_CFA_GNU_window_save:
2253 case DW_CFA_def_cfa_expression:
2254 case DW_CFA_expression:
2255 output_cfa_loc (cfi);
2258 case DW_CFA_GNU_negative_offset_extended:
2259 /* Obsoleted by DW_CFA_offset_extended_sf. */
2268 /* Output the call frame information used to record information
2269 that relates to calculating the frame pointer, and records the
2270 location of saved registers. */
2273 output_call_frame_info (int for_eh)
2278 char l1[20], l2[20], section_start_label[20];
2279 bool any_lsda_needed = false;
2280 char augmentation[6];
2281 int augmentation_size;
2282 int fde_encoding = DW_EH_PE_absptr;
2283 int per_encoding = DW_EH_PE_absptr;
2284 int lsda_encoding = DW_EH_PE_absptr;
2287 /* Don't emit a CIE if there won't be any FDEs. */
2288 if (fde_table_in_use == 0)
2291 /* If we make FDEs linkonce, we may have to emit an empty label for
2292 an FDE that wouldn't otherwise be emitted. We want to avoid
2293 having an FDE kept around when the function it refers to is
2294 discarded. Example where this matters: a primary function
2295 template in C++ requires EH information, but an explicit
2296 specialization doesn't. */
2297 if (TARGET_USES_WEAK_UNWIND_INFO
2298 && ! flag_asynchronous_unwind_tables
2301 for (i = 0; i < fde_table_in_use; i++)
2302 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2303 && !fde_table[i].uses_eh_lsda
2304 && ! DECL_WEAK (fde_table[i].decl))
2305 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2306 for_eh, /* empty */ 1);
2308 /* If we don't have any functions we'll want to unwind out of, don't
2309 emit any EH unwind information. Note that if exceptions aren't
2310 enabled, we won't have collected nothrow information, and if we
2311 asked for asynchronous tables, we always want this info. */
2314 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2316 for (i = 0; i < fde_table_in_use; i++)
2317 if (fde_table[i].uses_eh_lsda)
2318 any_eh_needed = any_lsda_needed = true;
2319 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2320 any_eh_needed = true;
2321 else if (! fde_table[i].nothrow
2322 && ! fde_table[i].all_throwers_are_sibcalls)
2323 any_eh_needed = true;
2325 if (! any_eh_needed)
2329 /* We're going to be generating comments, so turn on app. */
2334 switch_to_eh_frame_section ();
2337 if (!debug_frame_section)
2338 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2339 SECTION_DEBUG, NULL);
2340 switch_to_section (debug_frame_section);
2343 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2344 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2346 /* Output the CIE. */
2347 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2348 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2349 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2350 dw2_asm_output_data (4, 0xffffffff,
2351 "Initial length escape value indicating 64-bit DWARF extension");
2352 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2353 "Length of Common Information Entry");
2354 ASM_OUTPUT_LABEL (asm_out_file, l1);
2356 /* Now that the CIE pointer is PC-relative for EH,
2357 use 0 to identify the CIE. */
2358 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2359 (for_eh ? 0 : DWARF_CIE_ID),
2360 "CIE Identifier Tag");
2362 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2364 augmentation[0] = 0;
2365 augmentation_size = 0;
2371 z Indicates that a uleb128 is present to size the
2372 augmentation section.
2373 L Indicates the encoding (and thus presence) of
2374 an LSDA pointer in the FDE augmentation.
2375 R Indicates a non-default pointer encoding for
2377 P Indicates the presence of an encoding + language
2378 personality routine in the CIE augmentation. */
2380 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2381 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2382 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2384 p = augmentation + 1;
2385 if (eh_personality_libfunc)
2388 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2389 assemble_external_libcall (eh_personality_libfunc);
2391 if (any_lsda_needed)
2394 augmentation_size += 1;
2396 if (fde_encoding != DW_EH_PE_absptr)
2399 augmentation_size += 1;
2401 if (p > augmentation + 1)
2403 augmentation[0] = 'z';
2407 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2408 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2410 int offset = ( 4 /* Length */
2412 + 1 /* CIE version */
2413 + strlen (augmentation) + 1 /* Augmentation */
2414 + size_of_uleb128 (1) /* Code alignment */
2415 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2417 + 1 /* Augmentation size */
2418 + 1 /* Personality encoding */ );
2419 int pad = -offset & (PTR_SIZE - 1);
2421 augmentation_size += pad;
2423 /* Augmentations should be small, so there's scarce need to
2424 iterate for a solution. Die if we exceed one uleb128 byte. */
2425 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2429 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2430 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2431 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2432 "CIE Data Alignment Factor");
2434 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2435 if (DW_CIE_VERSION == 1)
2436 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2438 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2440 if (augmentation[0])
2442 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2443 if (eh_personality_libfunc)
2445 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2446 eh_data_format_name (per_encoding));
2447 dw2_asm_output_encoded_addr_rtx (per_encoding,
2448 eh_personality_libfunc,
2452 if (any_lsda_needed)
2453 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2454 eh_data_format_name (lsda_encoding));
2456 if (fde_encoding != DW_EH_PE_absptr)
2457 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2458 eh_data_format_name (fde_encoding));
2461 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2462 output_cfi (cfi, NULL, for_eh);
2464 /* Pad the CIE out to an address sized boundary. */
2465 ASM_OUTPUT_ALIGN (asm_out_file,
2466 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2467 ASM_OUTPUT_LABEL (asm_out_file, l2);
2469 /* Loop through all of the FDE's. */
2470 for (i = 0; i < fde_table_in_use; i++)
2472 fde = &fde_table[i];
2474 /* Don't emit EH unwind info for leaf functions that don't need it. */
2475 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2476 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2477 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2478 && !fde->uses_eh_lsda)
2481 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2482 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2483 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2484 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2485 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2486 dw2_asm_output_data (4, 0xffffffff,
2487 "Initial length escape value indicating 64-bit DWARF extension");
2488 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2490 ASM_OUTPUT_LABEL (asm_out_file, l1);
2493 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2495 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2496 debug_frame_section, "FDE CIE offset");
2500 if (fde->dw_fde_switched_sections)
2502 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2503 fde->dw_fde_unlikely_section_label);
2504 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2505 fde->dw_fde_hot_section_label);
2506 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2507 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2508 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2509 "FDE initial location");
2510 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2511 fde->dw_fde_hot_section_end_label,
2512 fde->dw_fde_hot_section_label,
2513 "FDE address range");
2514 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2515 "FDE initial location");
2516 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2517 fde->dw_fde_unlikely_section_end_label,
2518 fde->dw_fde_unlikely_section_label,
2519 "FDE address range");
2523 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2524 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2525 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2528 "FDE initial location");
2529 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2530 fde->dw_fde_end, fde->dw_fde_begin,
2531 "FDE address range");
2536 if (fde->dw_fde_switched_sections)
2538 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2539 fde->dw_fde_hot_section_label,
2540 "FDE initial location");
2541 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2542 fde->dw_fde_hot_section_end_label,
2543 fde->dw_fde_hot_section_label,
2544 "FDE address range");
2545 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2546 fde->dw_fde_unlikely_section_label,
2547 "FDE initial location");
2548 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2549 fde->dw_fde_unlikely_section_end_label,
2550 fde->dw_fde_unlikely_section_label,
2551 "FDE address range");
2555 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2556 "FDE initial location");
2557 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2558 fde->dw_fde_end, fde->dw_fde_begin,
2559 "FDE address range");
2563 if (augmentation[0])
2565 if (any_lsda_needed)
2567 int size = size_of_encoded_value (lsda_encoding);
2569 if (lsda_encoding == DW_EH_PE_aligned)
2571 int offset = ( 4 /* Length */
2572 + 4 /* CIE offset */
2573 + 2 * size_of_encoded_value (fde_encoding)
2574 + 1 /* Augmentation size */ );
2575 int pad = -offset & (PTR_SIZE - 1);
2578 gcc_assert (size_of_uleb128 (size) == 1);
2581 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2583 if (fde->uses_eh_lsda)
2585 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2586 fde->funcdef_number);
2587 dw2_asm_output_encoded_addr_rtx (
2588 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2589 false, "Language Specific Data Area");
2593 if (lsda_encoding == DW_EH_PE_aligned)
2594 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2596 (size_of_encoded_value (lsda_encoding), 0,
2597 "Language Specific Data Area (none)");
2601 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2604 /* Loop through the Call Frame Instructions associated with
2606 fde->dw_fde_current_label = fde->dw_fde_begin;
2607 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2608 output_cfi (cfi, fde, for_eh);
2610 /* Pad the FDE out to an address sized boundary. */
2611 ASM_OUTPUT_ALIGN (asm_out_file,
2612 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2613 ASM_OUTPUT_LABEL (asm_out_file, l2);
2616 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2617 dw2_asm_output_data (4, 0, "End of Table");
2618 #ifdef MIPS_DEBUGGING_INFO
2619 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2620 get a value of 0. Putting .align 0 after the label fixes it. */
2621 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2624 /* Turn off app to make assembly quicker. */
2629 /* Output a marker (i.e. a label) for the beginning of a function, before
2633 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2634 const char *file ATTRIBUTE_UNUSED)
2636 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2640 current_function_func_begin_label = NULL;
2642 #ifdef TARGET_UNWIND_INFO
2643 /* ??? current_function_func_begin_label is also used by except.c
2644 for call-site information. We must emit this label if it might
2646 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2647 && ! dwarf2out_do_frame ())
2650 if (! dwarf2out_do_frame ())
2654 switch_to_section (function_section (current_function_decl));
2655 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2656 current_function_funcdef_no);
2657 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2658 current_function_funcdef_no);
2659 dup_label = xstrdup (label);
2660 current_function_func_begin_label = dup_label;
2662 #ifdef TARGET_UNWIND_INFO
2663 /* We can elide the fde allocation if we're not emitting debug info. */
2664 if (! dwarf2out_do_frame ())
2668 /* Expand the fde table if necessary. */
2669 if (fde_table_in_use == fde_table_allocated)
2671 fde_table_allocated += FDE_TABLE_INCREMENT;
2672 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
2673 memset (fde_table + fde_table_in_use, 0,
2674 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2677 /* Record the FDE associated with this function. */
2678 current_funcdef_fde = fde_table_in_use;
2680 /* Add the new FDE at the end of the fde_table. */
2681 fde = &fde_table[fde_table_in_use++];
2682 fde->decl = current_function_decl;
2683 fde->dw_fde_begin = dup_label;
2684 fde->dw_fde_current_label = dup_label;
2685 fde->dw_fde_hot_section_label = NULL;
2686 fde->dw_fde_hot_section_end_label = NULL;
2687 fde->dw_fde_unlikely_section_label = NULL;
2688 fde->dw_fde_unlikely_section_end_label = NULL;
2689 fde->dw_fde_switched_sections = false;
2690 fde->dw_fde_end = NULL;
2691 fde->dw_fde_cfi = NULL;
2692 fde->funcdef_number = current_function_funcdef_no;
2693 fde->nothrow = TREE_NOTHROW (current_function_decl);
2694 fde->uses_eh_lsda = crtl->uses_eh_lsda;
2695 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
2697 args_size = old_args_size = 0;
2699 /* We only want to output line number information for the genuine dwarf2
2700 prologue case, not the eh frame case. */
2701 #ifdef DWARF2_DEBUGGING_INFO
2703 dwarf2out_source_line (line, file);
2707 /* Output a marker (i.e. a label) for the absolute end of the generated code
2708 for a function definition. This gets called *after* the epilogue code has
2712 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2713 const char *file ATTRIBUTE_UNUSED)
2716 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2718 /* Output a label to mark the endpoint of the code generated for this
2720 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2721 current_function_funcdef_no);
2722 ASM_OUTPUT_LABEL (asm_out_file, label);
2723 fde = current_fde ();
2724 gcc_assert (fde != NULL);
2725 fde->dw_fde_end = xstrdup (label);
2729 dwarf2out_frame_init (void)
2731 /* Allocate the initial hunk of the fde_table. */
2732 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
2733 fde_table_allocated = FDE_TABLE_INCREMENT;
2734 fde_table_in_use = 0;
2736 /* Generate the CFA instructions common to all FDE's. Do it now for the
2737 sake of lookup_cfa. */
2739 /* On entry, the Canonical Frame Address is at SP. */
2740 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2742 #ifdef DWARF2_UNWIND_INFO
2743 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2744 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2749 dwarf2out_frame_finish (void)
2751 /* Output call frame information. */
2752 if (DWARF2_FRAME_INFO)
2753 output_call_frame_info (0);
2755 #ifndef TARGET_UNWIND_INFO
2756 /* Output another copy for the unwinder. */
2757 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2758 output_call_frame_info (1);
2762 /* Note that the current function section is being used for code. */
2765 dwarf2out_note_section_used (void)
2767 section *sec = current_function_section ();
2768 if (sec == text_section)
2769 text_section_used = true;
2770 else if (sec == cold_text_section)
2771 cold_text_section_used = true;
2775 dwarf2out_switch_text_section (void)
2777 dw_fde_ref fde = current_fde ();
2779 gcc_assert (cfun && fde);
2781 fde->dw_fde_switched_sections = true;
2782 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
2783 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
2784 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
2785 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
2786 have_multiple_function_sections = true;
2788 /* Reset the current label on switching text sections, so that we
2789 don't attempt to advance_loc4 between labels in different sections. */
2790 fde->dw_fde_current_label = NULL;
2792 /* There is no need to mark used sections when not debugging. */
2793 if (cold_text_section != NULL)
2794 dwarf2out_note_section_used ();
2798 /* And now, the subset of the debugging information support code necessary
2799 for emitting location expressions. */
2801 /* Data about a single source file. */
2802 struct dwarf_file_data GTY(())
2804 const char * filename;
2808 /* We need some way to distinguish DW_OP_addr with a direct symbol
2809 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2810 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2813 typedef struct dw_val_struct *dw_val_ref;
2814 typedef struct die_struct *dw_die_ref;
2815 typedef const struct die_struct *const_dw_die_ref;
2816 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2817 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2819 /* Each DIE may have a series of attribute/value pairs. Values
2820 can take on several forms. The forms that are used in this
2821 implementation are listed below. */
2826 dw_val_class_offset,
2828 dw_val_class_loc_list,
2829 dw_val_class_range_list,
2831 dw_val_class_unsigned_const,
2832 dw_val_class_long_long,
2835 dw_val_class_die_ref,
2836 dw_val_class_fde_ref,
2837 dw_val_class_lbl_id,
2838 dw_val_class_lineptr,
2840 dw_val_class_macptr,
2844 /* Describe a double word constant value. */
2845 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2847 typedef struct dw_long_long_struct GTY(())
2854 /* Describe a floating point constant value, or a vector constant value. */
2856 typedef struct dw_vec_struct GTY(())
2858 unsigned char * GTY((length ("%h.length"))) array;
2864 /* The dw_val_node describes an attribute's value, as it is
2865 represented internally. */
2867 typedef struct dw_val_struct GTY(())
2869 enum dw_val_class val_class;
2870 union dw_val_struct_union
2872 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2873 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2874 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2875 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2876 HOST_WIDE_INT GTY ((default)) val_int;
2877 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2878 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2879 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2880 struct dw_val_die_union
2884 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2885 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2886 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2887 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2888 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2889 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2891 GTY ((desc ("%1.val_class"))) v;
2895 /* Locations in memory are described using a sequence of stack machine
2898 typedef struct dw_loc_descr_struct GTY(())
2900 dw_loc_descr_ref dw_loc_next;
2901 enum dwarf_location_atom dw_loc_opc;
2902 dw_val_node dw_loc_oprnd1;
2903 dw_val_node dw_loc_oprnd2;
2908 /* Location lists are ranges + location descriptions for that range,
2909 so you can track variables that are in different places over
2910 their entire life. */
2911 typedef struct dw_loc_list_struct GTY(())
2913 dw_loc_list_ref dw_loc_next;
2914 const char *begin; /* Label for begin address of range */
2915 const char *end; /* Label for end address of range */
2916 char *ll_symbol; /* Label for beginning of location list.
2917 Only on head of list */
2918 const char *section; /* Section this loclist is relative to */
2919 dw_loc_descr_ref expr;
2922 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2924 static const char *dwarf_stack_op_name (unsigned);
2925 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2926 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2927 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2928 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2929 static unsigned long size_of_locs (dw_loc_descr_ref);
2930 static void output_loc_operands (dw_loc_descr_ref);
2931 static void output_loc_sequence (dw_loc_descr_ref);
2933 /* Convert a DWARF stack opcode into its string name. */
2936 dwarf_stack_op_name (unsigned int op)
2941 case INTERNAL_DW_OP_tls_addr:
2942 return "DW_OP_addr";
2944 return "DW_OP_deref";
2946 return "DW_OP_const1u";
2948 return "DW_OP_const1s";
2950 return "DW_OP_const2u";
2952 return "DW_OP_const2s";
2954 return "DW_OP_const4u";
2956 return "DW_OP_const4s";
2958 return "DW_OP_const8u";
2960 return "DW_OP_const8s";
2962 return "DW_OP_constu";
2964 return "DW_OP_consts";
2968 return "DW_OP_drop";
2970 return "DW_OP_over";
2972 return "DW_OP_pick";
2974 return "DW_OP_swap";
2978 return "DW_OP_xderef";
2986 return "DW_OP_minus";
2998 return "DW_OP_plus";
2999 case DW_OP_plus_uconst:
3000 return "DW_OP_plus_uconst";
3006 return "DW_OP_shra";
3024 return "DW_OP_skip";
3026 return "DW_OP_lit0";
3028 return "DW_OP_lit1";
3030 return "DW_OP_lit2";
3032 return "DW_OP_lit3";
3034 return "DW_OP_lit4";
3036 return "DW_OP_lit5";
3038 return "DW_OP_lit6";
3040 return "DW_OP_lit7";
3042 return "DW_OP_lit8";
3044 return "DW_OP_lit9";
3046 return "DW_OP_lit10";
3048 return "DW_OP_lit11";
3050 return "DW_OP_lit12";
3052 return "DW_OP_lit13";
3054 return "DW_OP_lit14";
3056 return "DW_OP_lit15";
3058 return "DW_OP_lit16";
3060 return "DW_OP_lit17";
3062 return "DW_OP_lit18";
3064 return "DW_OP_lit19";
3066 return "DW_OP_lit20";
3068 return "DW_OP_lit21";
3070 return "DW_OP_lit22";
3072 return "DW_OP_lit23";
3074 return "DW_OP_lit24";
3076 return "DW_OP_lit25";
3078 return "DW_OP_lit26";
3080 return "DW_OP_lit27";
3082 return "DW_OP_lit28";
3084 return "DW_OP_lit29";
3086 return "DW_OP_lit30";
3088 return "DW_OP_lit31";
3090 return "DW_OP_reg0";
3092 return "DW_OP_reg1";
3094 return "DW_OP_reg2";
3096 return "DW_OP_reg3";
3098 return "DW_OP_reg4";
3100 return "DW_OP_reg5";
3102 return "DW_OP_reg6";
3104 return "DW_OP_reg7";
3106 return "DW_OP_reg8";
3108 return "DW_OP_reg9";
3110 return "DW_OP_reg10";
3112 return "DW_OP_reg11";
3114 return "DW_OP_reg12";
3116 return "DW_OP_reg13";
3118 return "DW_OP_reg14";
3120 return "DW_OP_reg15";
3122 return "DW_OP_reg16";
3124 return "DW_OP_reg17";
3126 return "DW_OP_reg18";
3128 return "DW_OP_reg19";
3130 return "DW_OP_reg20";
3132 return "DW_OP_reg21";
3134 return "DW_OP_reg22";
3136 return "DW_OP_reg23";
3138 return "DW_OP_reg24";
3140 return "DW_OP_reg25";
3142 return "DW_OP_reg26";
3144 return "DW_OP_reg27";
3146 return "DW_OP_reg28";
3148 return "DW_OP_reg29";
3150 return "DW_OP_reg30";
3152 return "DW_OP_reg31";
3154 return "DW_OP_breg0";
3156 return "DW_OP_breg1";
3158 return "DW_OP_breg2";
3160 return "DW_OP_breg3";
3162 return "DW_OP_breg4";
3164 return "DW_OP_breg5";
3166 return "DW_OP_breg6";
3168 return "DW_OP_breg7";
3170 return "DW_OP_breg8";
3172 return "DW_OP_breg9";
3174 return "DW_OP_breg10";
3176 return "DW_OP_breg11";
3178 return "DW_OP_breg12";
3180 return "DW_OP_breg13";
3182 return "DW_OP_breg14";
3184 return "DW_OP_breg15";
3186 return "DW_OP_breg16";
3188 return "DW_OP_breg17";
3190 return "DW_OP_breg18";
3192 return "DW_OP_breg19";
3194 return "DW_OP_breg20";
3196 return "DW_OP_breg21";
3198 return "DW_OP_breg22";
3200 return "DW_OP_breg23";
3202 return "DW_OP_breg24";
3204 return "DW_OP_breg25";
3206 return "DW_OP_breg26";
3208 return "DW_OP_breg27";
3210 return "DW_OP_breg28";
3212 return "DW_OP_breg29";
3214 return "DW_OP_breg30";
3216 return "DW_OP_breg31";
3218 return "DW_OP_regx";
3220 return "DW_OP_fbreg";
3222 return "DW_OP_bregx";
3224 return "DW_OP_piece";
3225 case DW_OP_deref_size:
3226 return "DW_OP_deref_size";
3227 case DW_OP_xderef_size:
3228 return "DW_OP_xderef_size";
3231 case DW_OP_push_object_address:
3232 return "DW_OP_push_object_address";
3234 return "DW_OP_call2";
3236 return "DW_OP_call4";
3237 case DW_OP_call_ref:
3238 return "DW_OP_call_ref";
3239 case DW_OP_GNU_push_tls_address:
3240 return "DW_OP_GNU_push_tls_address";
3241 case DW_OP_GNU_uninit:
3242 return "DW_OP_GNU_uninit";
3244 return "OP_<unknown>";
3248 /* Return a pointer to a newly allocated location description. Location
3249 descriptions are simple expression terms that can be strung
3250 together to form more complicated location (address) descriptions. */
3252 static inline dw_loc_descr_ref
3253 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3254 unsigned HOST_WIDE_INT oprnd2)
3256 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3258 descr->dw_loc_opc = op;
3259 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3260 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3261 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3262 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3267 /* Add a location description term to a location description expression. */
3270 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3272 dw_loc_descr_ref *d;
3274 /* Find the end of the chain. */
3275 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3281 /* Return the size of a location descriptor. */
3283 static unsigned long
3284 size_of_loc_descr (dw_loc_descr_ref loc)
3286 unsigned long size = 1;
3288 switch (loc->dw_loc_opc)
3291 case INTERNAL_DW_OP_tls_addr:
3292 size += DWARF2_ADDR_SIZE;
3311 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3314 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3319 case DW_OP_plus_uconst:
3320 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3358 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3361 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3364 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3367 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3368 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3371 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3373 case DW_OP_deref_size:
3374 case DW_OP_xderef_size:
3383 case DW_OP_call_ref:
3384 size += DWARF2_ADDR_SIZE;
3393 /* Return the size of a series of location descriptors. */
3395 static unsigned long
3396 size_of_locs (dw_loc_descr_ref loc)
3401 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3402 field, to avoid writing to a PCH file. */
3403 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3405 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3407 size += size_of_loc_descr (l);
3412 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3414 l->dw_loc_addr = size;
3415 size += size_of_loc_descr (l);
3421 /* Output location description stack opcode's operands (if any). */
3424 output_loc_operands (dw_loc_descr_ref loc)
3426 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3427 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3429 switch (loc->dw_loc_opc)
3431 #ifdef DWARF2_DEBUGGING_INFO
3433 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3437 dw2_asm_output_data (2, val1->v.val_int, NULL);
3441 dw2_asm_output_data (4, val1->v.val_int, NULL);
3445 gcc_assert (HOST_BITS_PER_LONG >= 64);
3446 dw2_asm_output_data (8, val1->v.val_int, NULL);
3453 gcc_assert (val1->val_class == dw_val_class_loc);
3454 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3456 dw2_asm_output_data (2, offset, NULL);
3469 /* We currently don't make any attempt to make sure these are
3470 aligned properly like we do for the main unwind info, so
3471 don't support emitting things larger than a byte if we're
3472 only doing unwinding. */
3477 dw2_asm_output_data (1, val1->v.val_int, NULL);
3480 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3483 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3486 dw2_asm_output_data (1, val1->v.val_int, NULL);
3488 case DW_OP_plus_uconst:
3489 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3523 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3526 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3529 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3532 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3533 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3536 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3538 case DW_OP_deref_size:
3539 case DW_OP_xderef_size:
3540 dw2_asm_output_data (1, val1->v.val_int, NULL);
3543 case INTERNAL_DW_OP_tls_addr:
3544 if (targetm.asm_out.output_dwarf_dtprel)
3546 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3549 fputc ('\n', asm_out_file);
3556 /* Other codes have no operands. */
3561 /* Output a sequence of location operations. */
3564 output_loc_sequence (dw_loc_descr_ref loc)
3566 for (; loc != NULL; loc = loc->dw_loc_next)
3568 /* Output the opcode. */
3569 dw2_asm_output_data (1, loc->dw_loc_opc,
3570 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3572 /* Output the operand(s) (if any). */
3573 output_loc_operands (loc);
3577 /* This routine will generate the correct assembly data for a location
3578 description based on a cfi entry with a complex address. */
3581 output_cfa_loc (dw_cfi_ref cfi)
3583 dw_loc_descr_ref loc;
3586 /* Output the size of the block. */
3587 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3588 size = size_of_locs (loc);
3589 dw2_asm_output_data_uleb128 (size, NULL);
3591 /* Now output the operations themselves. */
3592 output_loc_sequence (loc);
3595 /* This function builds a dwarf location descriptor sequence from a
3596 dw_cfa_location, adding the given OFFSET to the result of the
3599 static struct dw_loc_descr_struct *
3600 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3602 struct dw_loc_descr_struct *head, *tmp;
3604 offset += cfa->offset;
3608 if (cfa->base_offset)
3611 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3613 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3615 else if (cfa->reg <= 31)
3616 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3618 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3620 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3621 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3622 add_loc_descr (&head, tmp);
3625 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3626 add_loc_descr (&head, tmp);
3633 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3635 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3636 else if (cfa->reg <= 31)
3637 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3639 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3645 /* This function fills in aa dw_cfa_location structure from a dwarf location
3646 descriptor sequence. */
3649 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3651 struct dw_loc_descr_struct *ptr;
3653 cfa->base_offset = 0;
3657 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3659 enum dwarf_location_atom op = ptr->dw_loc_opc;
3695 cfa->reg = op - DW_OP_reg0;
3698 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3732 cfa->reg = op - DW_OP_breg0;
3733 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3736 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3737 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3742 case DW_OP_plus_uconst:
3743 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3746 internal_error ("DW_LOC_OP %s not implemented",
3747 dwarf_stack_op_name (ptr->dw_loc_opc));
3751 #endif /* .debug_frame support */
3753 /* And now, the support for symbolic debugging information. */
3754 #ifdef DWARF2_DEBUGGING_INFO
3756 /* .debug_str support. */
3757 static int output_indirect_string (void **, void *);
3759 static void dwarf2out_init (const char *);
3760 static void dwarf2out_finish (const char *);
3761 static void dwarf2out_define (unsigned int, const char *);
3762 static void dwarf2out_undef (unsigned int, const char *);
3763 static void dwarf2out_start_source_file (unsigned, const char *);
3764 static void dwarf2out_end_source_file (unsigned);
3765 static void dwarf2out_begin_block (unsigned, unsigned);
3766 static void dwarf2out_end_block (unsigned, unsigned);
3767 static bool dwarf2out_ignore_block (const_tree);
3768 static void dwarf2out_global_decl (tree);
3769 static void dwarf2out_type_decl (tree, int);
3770 static void dwarf2out_imported_module_or_decl (tree, tree);
3771 static void dwarf2out_abstract_function (tree);
3772 static void dwarf2out_var_location (rtx);
3773 static void dwarf2out_begin_function (tree);
3775 /* The debug hooks structure. */
3777 const struct gcc_debug_hooks dwarf2_debug_hooks =
3783 dwarf2out_start_source_file,
3784 dwarf2out_end_source_file,
3785 dwarf2out_begin_block,
3786 dwarf2out_end_block,
3787 dwarf2out_ignore_block,
3788 dwarf2out_source_line,
3789 dwarf2out_begin_prologue,
3790 debug_nothing_int_charstar, /* end_prologue */
3791 dwarf2out_end_epilogue,
3792 dwarf2out_begin_function,
3793 debug_nothing_int, /* end_function */
3794 dwarf2out_decl, /* function_decl */
3795 dwarf2out_global_decl,
3796 dwarf2out_type_decl, /* type_decl */
3797 dwarf2out_imported_module_or_decl,
3798 debug_nothing_tree, /* deferred_inline_function */
3799 /* The DWARF 2 backend tries to reduce debugging bloat by not
3800 emitting the abstract description of inline functions until
3801 something tries to reference them. */
3802 dwarf2out_abstract_function, /* outlining_inline_function */
3803 debug_nothing_rtx, /* label */
3804 debug_nothing_int, /* handle_pch */
3805 dwarf2out_var_location,
3806 dwarf2out_switch_text_section,
3807 1 /* start_end_main_source_file */
3811 /* NOTE: In the comments in this file, many references are made to
3812 "Debugging Information Entries". This term is abbreviated as `DIE'
3813 throughout the remainder of this file. */
3815 /* An internal representation of the DWARF output is built, and then
3816 walked to generate the DWARF debugging info. The walk of the internal
3817 representation is done after the entire program has been compiled.
3818 The types below are used to describe the internal representation. */
3820 /* Various DIE's use offsets relative to the beginning of the
3821 .debug_info section to refer to each other. */
3823 typedef long int dw_offset;
3825 /* Define typedefs here to avoid circular dependencies. */
3827 typedef struct dw_attr_struct *dw_attr_ref;
3828 typedef struct dw_line_info_struct *dw_line_info_ref;
3829 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3830 typedef struct pubname_struct *pubname_ref;
3831 typedef struct dw_ranges_struct *dw_ranges_ref;
3832 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3834 /* Each entry in the line_info_table maintains the file and
3835 line number associated with the label generated for that
3836 entry. The label gives the PC value associated with
3837 the line number entry. */
3839 typedef struct dw_line_info_struct GTY(())
3841 unsigned long dw_file_num;
3842 unsigned long dw_line_num;
3846 /* Line information for functions in separate sections; each one gets its
3848 typedef struct dw_separate_line_info_struct GTY(())
3850 unsigned long dw_file_num;
3851 unsigned long dw_line_num;
3852 unsigned long function;
3854 dw_separate_line_info_entry;
3856 /* Each DIE attribute has a field specifying the attribute kind,
3857 a link to the next attribute in the chain, and an attribute value.
3858 Attributes are typically linked below the DIE they modify. */
3860 typedef struct dw_attr_struct GTY(())
3862 enum dwarf_attribute dw_attr;
3863 dw_val_node dw_attr_val;
3867 DEF_VEC_O(dw_attr_node);
3868 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3870 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3871 The children of each node form a circular list linked by
3872 die_sib. die_child points to the node *before* the "first" child node. */
3874 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
3876 enum dwarf_tag die_tag;
3878 VEC(dw_attr_node,gc) * die_attr;
3879 dw_die_ref die_parent;
3880 dw_die_ref die_child;
3882 dw_die_ref die_definition; /* ref from a specification to its definition */
3883 dw_offset die_offset;
3884 unsigned long die_abbrev;
3886 /* Die is used and must not be pruned as unused. */
3887 int die_perennial_p;
3888 unsigned int decl_id;
3892 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3893 #define FOR_EACH_CHILD(die, c, expr) do { \
3894 c = die->die_child; \
3898 } while (c != die->die_child); \
3901 /* The pubname structure */
3903 typedef struct pubname_struct GTY(())
3910 DEF_VEC_O(pubname_entry);
3911 DEF_VEC_ALLOC_O(pubname_entry, gc);
3913 struct dw_ranges_struct GTY(())
3915 /* If this is positive, it's a block number, otherwise it's a
3916 bitwise-negated index into dw_ranges_by_label. */
3920 struct dw_ranges_by_label_struct GTY(())
3926 /* The limbo die list structure. */
3927 typedef struct limbo_die_struct GTY(())
3931 struct limbo_die_struct *next;
3935 /* How to start an assembler comment. */
3936 #ifndef ASM_COMMENT_START
3937 #define ASM_COMMENT_START ";#"
3940 /* Define a macro which returns nonzero for a TYPE_DECL which was
3941 implicitly generated for a tagged type.
3943 Note that unlike the gcc front end (which generates a NULL named
3944 TYPE_DECL node for each complete tagged type, each array type, and
3945 each function type node created) the g++ front end generates a
3946 _named_ TYPE_DECL node for each tagged type node created.
3947 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3948 generate a DW_TAG_typedef DIE for them. */
3950 #define TYPE_DECL_IS_STUB(decl) \
3951 (DECL_NAME (decl) == NULL_TREE \
3952 || (DECL_ARTIFICIAL (decl) \
3953 && is_tagged_type (TREE_TYPE (decl)) \
3954 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3955 /* This is necessary for stub decls that \
3956 appear in nested inline functions. */ \
3957 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3958 && (decl_ultimate_origin (decl) \
3959 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3961 /* Information concerning the compilation unit's programming
3962 language, and compiler version. */
3964 /* Fixed size portion of the DWARF compilation unit header. */
3965 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3966 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3968 /* Fixed size portion of public names info. */
3969 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3971 /* Fixed size portion of the address range info. */
3972 #define DWARF_ARANGES_HEADER_SIZE \
3973 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3974 DWARF2_ADDR_SIZE * 2) \
3975 - DWARF_INITIAL_LENGTH_SIZE)
3977 /* Size of padding portion in the address range info. It must be
3978 aligned to twice the pointer size. */
3979 #define DWARF_ARANGES_PAD_SIZE \
3980 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3981 DWARF2_ADDR_SIZE * 2) \
3982 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3984 /* Use assembler line directives if available. */
3985 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3986 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3987 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3989 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3993 /* Minimum line offset in a special line info. opcode.
3994 This value was chosen to give a reasonable range of values. */
3995 #define DWARF_LINE_BASE -10
3997 /* First special line opcode - leave room for the standard opcodes. */
3998 #define DWARF_LINE_OPCODE_BASE 10
4000 /* Range of line offsets in a special line info. opcode. */
4001 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4003 /* Flag that indicates the initial value of the is_stmt_start flag.
4004 In the present implementation, we do not mark any lines as
4005 the beginning of a source statement, because that information
4006 is not made available by the GCC front-end. */
4007 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4009 #ifdef DWARF2_DEBUGGING_INFO
4010 /* This location is used by calc_die_sizes() to keep track
4011 the offset of each DIE within the .debug_info section. */
4012 static unsigned long next_die_offset;
4015 /* Record the root of the DIE's built for the current compilation unit. */
4016 static GTY(()) dw_die_ref comp_unit_die;
4018 /* A list of DIEs with a NULL parent waiting to be relocated. */
4019 static GTY(()) limbo_die_node *limbo_die_list;
4021 /* Filenames referenced by this compilation unit. */
4022 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4024 /* A hash table of references to DIE's that describe declarations.
4025 The key is a DECL_UID() which is a unique number identifying each decl. */
4026 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4028 /* Node of the variable location list. */
4029 struct var_loc_node GTY ((chain_next ("%h.next")))
4031 rtx GTY (()) var_loc_note;
4032 const char * GTY (()) label;
4033 const char * GTY (()) section_label;
4034 struct var_loc_node * GTY (()) next;
4037 /* Variable location list. */
4038 struct var_loc_list_def GTY (())
4040 struct var_loc_node * GTY (()) first;
4042 /* Do not mark the last element of the chained list because
4043 it is marked through the chain. */
4044 struct var_loc_node * GTY ((skip ("%h"))) last;
4046 /* DECL_UID of the variable decl. */
4047 unsigned int decl_id;
4049 typedef struct var_loc_list_def var_loc_list;
4052 /* Table of decl location linked lists. */
4053 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4055 /* A pointer to the base of a list of references to DIE's that
4056 are uniquely identified by their tag, presence/absence of
4057 children DIE's, and list of attribute/value pairs. */
4058 static GTY((length ("abbrev_die_table_allocated")))
4059 dw_die_ref *abbrev_die_table;
4061 /* Number of elements currently allocated for abbrev_die_table. */
4062 static GTY(()) unsigned abbrev_die_table_allocated;
4064 /* Number of elements in type_die_table currently in use. */
4065 static GTY(()) unsigned abbrev_die_table_in_use;
4067 /* Size (in elements) of increments by which we may expand the
4068 abbrev_die_table. */
4069 #define ABBREV_DIE_TABLE_INCREMENT 256
4071 /* A pointer to the base of a table that contains line information
4072 for each source code line in .text in the compilation unit. */
4073 static GTY((length ("line_info_table_allocated")))
4074 dw_line_info_ref line_info_table;
4076 /* Number of elements currently allocated for line_info_table. */
4077 static GTY(()) unsigned line_info_table_allocated;
4079 /* Number of elements in line_info_table currently in use. */
4080 static GTY(()) unsigned line_info_table_in_use;
4082 /* A pointer to the base of a table that contains line information
4083 for each source code line outside of .text in the compilation unit. */
4084 static GTY ((length ("separate_line_info_table_allocated")))
4085 dw_separate_line_info_ref separate_line_info_table;
4087 /* Number of elements currently allocated for separate_line_info_table. */
4088 static GTY(()) unsigned separate_line_info_table_allocated;
4090 /* Number of elements in separate_line_info_table currently in use. */
4091 static GTY(()) unsigned separate_line_info_table_in_use;
4093 /* Size (in elements) of increments by which we may expand the
4095 #define LINE_INFO_TABLE_INCREMENT 1024
4097 /* A pointer to the base of a table that contains a list of publicly
4098 accessible names. */
4099 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4101 /* A pointer to the base of a table that contains a list of publicly
4102 accessible types. */
4103 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4105 /* Array of dies for which we should generate .debug_arange info. */
4106 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4108 /* Number of elements currently allocated for arange_table. */
4109 static GTY(()) unsigned arange_table_allocated;
4111 /* Number of elements in arange_table currently in use. */
4112 static GTY(()) unsigned arange_table_in_use;
4114 /* Size (in elements) of increments by which we may expand the
4116 #define ARANGE_TABLE_INCREMENT 64
4118 /* Array of dies for which we should generate .debug_ranges info. */
4119 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4121 /* Number of elements currently allocated for ranges_table. */
4122 static GTY(()) unsigned ranges_table_allocated;
4124 /* Number of elements in ranges_table currently in use. */
4125 static GTY(()) unsigned ranges_table_in_use;
4127 /* Array of pairs of labels referenced in ranges_table. */
4128 static GTY ((length ("ranges_by_label_allocated")))
4129 dw_ranges_by_label_ref ranges_by_label;
4131 /* Number of elements currently allocated for ranges_by_label. */
4132 static GTY(()) unsigned ranges_by_label_allocated;
4134 /* Number of elements in ranges_by_label currently in use. */
4135 static GTY(()) unsigned ranges_by_label_in_use;
4137 /* Size (in elements) of increments by which we may expand the
4139 #define RANGES_TABLE_INCREMENT 64
4141 /* Whether we have location lists that need outputting */
4142 static GTY(()) bool have_location_lists;
4144 /* Unique label counter. */
4145 static GTY(()) unsigned int loclabel_num;
4147 #ifdef DWARF2_DEBUGGING_INFO
4148 /* Record whether the function being analyzed contains inlined functions. */
4149 static int current_function_has_inlines;
4151 #if 0 && defined (MIPS_DEBUGGING_INFO)
4152 static int comp_unit_has_inlines;
4155 /* The last file entry emitted by maybe_emit_file(). */
4156 static GTY(()) struct dwarf_file_data * last_emitted_file;
4158 /* Number of internal labels generated by gen_internal_sym(). */
4159 static GTY(()) int label_num;
4161 /* Cached result of previous call to lookup_filename. */
4162 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4164 #ifdef DWARF2_DEBUGGING_INFO
4166 /* Offset from the "steady-state frame pointer" to the frame base,
4167 within the current function. */
4168 static HOST_WIDE_INT frame_pointer_fb_offset;
4170 /* Forward declarations for functions defined in this file. */
4172 static int is_pseudo_reg (const_rtx);
4173 static tree type_main_variant (tree);
4174 static int is_tagged_type (const_tree);
4175 static const char *dwarf_tag_name (unsigned);
4176 static const char *dwarf_attr_name (unsigned);
4177 static const char *dwarf_form_name (unsigned);
4178 static tree decl_ultimate_origin (const_tree);
4179 static tree block_ultimate_origin (const_tree);
4180 static tree decl_class_context (tree);
4181 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4182 static inline enum dw_val_class AT_class (dw_attr_ref);
4183 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4184 static inline unsigned AT_flag (dw_attr_ref);
4185 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4186 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4187 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4188 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4189 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4191 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4192 unsigned int, unsigned char *);
4193 static hashval_t debug_str_do_hash (const void *);
4194 static int debug_str_eq (const void *, const void *);
4195 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4196 static inline const char *AT_string (dw_attr_ref);
4197 static int AT_string_form (dw_attr_ref);
4198 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4199 static void add_AT_specification (dw_die_ref, dw_die_ref);
4200 static inline dw_die_ref AT_ref (dw_attr_ref);
4201 static inline int AT_ref_external (dw_attr_ref);
4202 static inline void set_AT_ref_external (dw_attr_ref, int);
4203 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4204 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4205 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4206 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4208 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4209 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4210 static inline rtx AT_addr (dw_attr_ref);
4211 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4212 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4213 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4214 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4215 unsigned HOST_WIDE_INT);
4216 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4218 static inline const char *AT_lbl (dw_attr_ref);
4219 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4220 static const char *get_AT_low_pc (dw_die_ref);
4221 static const char *get_AT_hi_pc (dw_die_ref);
4222 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4223 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4224 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4225 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4226 static bool is_c_family (void);
4227 static bool is_cxx (void);
4228 static bool is_java (void);
4229 static bool is_fortran (void);
4230 static bool is_ada (void);
4231 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4232 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4233 static void add_child_die (dw_die_ref, dw_die_ref);
4234 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4235 static dw_die_ref lookup_type_die (tree);
4236 static void equate_type_number_to_die (tree, dw_die_ref);
4237 static hashval_t decl_die_table_hash (const void *);
4238 static int decl_die_table_eq (const void *, const void *);
4239 static dw_die_ref lookup_decl_die (tree);
4240 static hashval_t decl_loc_table_hash (const void *);
4241 static int decl_loc_table_eq (const void *, const void *);
4242 static var_loc_list *lookup_decl_loc (const_tree);
4243 static void equate_decl_number_to_die (tree, dw_die_ref);
4244 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4245 static void print_spaces (FILE *);
4246 static void print_die (dw_die_ref, FILE *);
4247 static void print_dwarf_line_table (FILE *);
4248 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4249 static dw_die_ref pop_compile_unit (dw_die_ref);
4250 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4251 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4252 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4253 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4254 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4255 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4256 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4257 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4258 static void compute_section_prefix (dw_die_ref);
4259 static int is_type_die (dw_die_ref);
4260 static int is_comdat_die (dw_die_ref);
4261 static int is_symbol_die (dw_die_ref);
4262 static void assign_symbol_names (dw_die_ref);
4263 static void break_out_includes (dw_die_ref);
4264 static hashval_t htab_cu_hash (const void *);
4265 static int htab_cu_eq (const void *, const void *);
4266 static void htab_cu_del (void *);
4267 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4268 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4269 static void add_sibling_attributes (dw_die_ref);
4270 static void build_abbrev_table (dw_die_ref);
4271 static void output_location_lists (dw_die_ref);
4272 static int constant_size (long unsigned);
4273 static unsigned long size_of_die (dw_die_ref);
4274 static void calc_die_sizes (dw_die_ref);
4275 static void mark_dies (dw_die_ref);
4276 static void unmark_dies (dw_die_ref);
4277 static void unmark_all_dies (dw_die_ref);
4278 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4279 static unsigned long size_of_aranges (void);
4280 static enum dwarf_form value_format (dw_attr_ref);
4281 static void output_value_format (dw_attr_ref);
4282 static void output_abbrev_section (void);
4283 static void output_die_symbol (dw_die_ref);
4284 static void output_die (dw_die_ref);
4285 static void output_compilation_unit_header (void);
4286 static void output_comp_unit (dw_die_ref, int);
4287 static const char *dwarf2_name (tree, int);
4288 static void add_pubname (tree, dw_die_ref);
4289 static void add_pubname_string (const char *, dw_die_ref);
4290 static void add_pubtype (tree, dw_die_ref);
4291 static void output_pubnames (VEC (pubname_entry,gc) *);
4292 static void add_arange (tree, dw_die_ref);
4293 static void output_aranges (void);
4294 static unsigned int add_ranges_num (int);
4295 static unsigned int add_ranges (const_tree);
4296 static unsigned int add_ranges_by_labels (const char *, const char *);
4297 static void output_ranges (void);
4298 static void output_line_info (void);
4299 static void output_file_names (void);
4300 static dw_die_ref base_type_die (tree);
4301 static int is_base_type (tree);
4302 static bool is_subrange_type (const_tree);
4303 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4304 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4305 static int type_is_enum (const_tree);
4306 static unsigned int dbx_reg_number (const_rtx);
4307 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4308 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4309 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4310 enum var_init_status);
4311 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4312 enum var_init_status);
4313 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4314 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4315 enum var_init_status);
4316 static int is_based_loc (const_rtx);
4317 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4318 enum var_init_status);
4319 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4320 enum var_init_status);
4321 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4322 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4323 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4324 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4325 static tree field_type (const_tree);
4326 static unsigned int simple_type_align_in_bits (const_tree);
4327 static unsigned int simple_decl_align_in_bits (const_tree);
4328 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
4329 static HOST_WIDE_INT field_byte_offset (const_tree);
4330 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4332 static void add_data_member_location_attribute (dw_die_ref, tree);
4333 static void add_const_value_attribute (dw_die_ref, rtx);
4334 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4335 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4336 static void insert_float (const_rtx, unsigned char *);
4337 static rtx rtl_for_decl_location (tree);
4338 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4339 enum dwarf_attribute);
4340 static void tree_add_const_value_attribute (dw_die_ref, tree);
4341 static void add_name_attribute (dw_die_ref, const char *);
4342 static void add_comp_dir_attribute (dw_die_ref);
4343 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4344 static void add_subscript_info (dw_die_ref, tree, bool);
4345 static void add_byte_size_attribute (dw_die_ref, tree);
4346 static void add_bit_offset_attribute (dw_die_ref, tree);
4347 static void add_bit_size_attribute (dw_die_ref, tree);
4348 static void add_prototyped_attribute (dw_die_ref, tree);
4349 static void add_abstract_origin_attribute (dw_die_ref, tree);
4350 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4351 static void add_src_coords_attributes (dw_die_ref, tree);
4352 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4353 static void push_decl_scope (tree);
4354 static void pop_decl_scope (void);
4355 static dw_die_ref scope_die_for (tree, dw_die_ref);
4356 static inline int local_scope_p (dw_die_ref);
4357 static inline int class_or_namespace_scope_p (dw_die_ref);
4358 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4359 static void add_calling_convention_attribute (dw_die_ref, tree);
4360 static const char *type_tag (const_tree);
4361 static tree member_declared_type (const_tree);
4363 static const char *decl_start_label (tree);
4365 static void gen_array_type_die (tree, dw_die_ref);
4366 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4368 static void gen_entry_point_die (tree, dw_die_ref);
4370 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4371 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4372 static void gen_inlined_union_type_die (tree, dw_die_ref);
4373 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4374 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4375 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4376 static void gen_formal_types_die (tree, dw_die_ref);
4377 static void gen_subprogram_die (tree, dw_die_ref);
4378 static void gen_variable_die (tree, dw_die_ref);
4379 static void gen_label_die (tree, dw_die_ref);
4380 static void gen_lexical_block_die (tree, dw_die_ref, int);
4381 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4382 static void gen_field_die (tree, dw_die_ref);
4383 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4384 static dw_die_ref gen_compile_unit_die (const char *);
4385 static void gen_inheritance_die (tree, tree, dw_die_ref);
4386 static void gen_member_die (tree, dw_die_ref);
4387 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4388 enum debug_info_usage);
4389 static void gen_subroutine_type_die (tree, dw_die_ref);
4390 static void gen_typedef_die (tree, dw_die_ref);
4391 static void gen_type_die (tree, dw_die_ref);
4392 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4393 static void gen_block_die (tree, dw_die_ref, int);
4394 static void decls_for_scope (tree, dw_die_ref, int);
4395 static int is_redundant_typedef (const_tree);
4396 static void gen_namespace_die (tree);
4397 static void gen_decl_die (tree, dw_die_ref);
4398 static dw_die_ref force_decl_die (tree);
4399 static dw_die_ref force_type_die (tree);
4400 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4401 static void declare_in_namespace (tree, dw_die_ref);
4402 static struct dwarf_file_data * lookup_filename (const char *);
4403 static void retry_incomplete_types (void);
4404 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4405 static void splice_child_die (dw_die_ref, dw_die_ref);
4406 static int file_info_cmp (const void *, const void *);
4407 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4408 const char *, const char *, unsigned);
4409 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4410 const char *, const char *,
4412 static void output_loc_list (dw_loc_list_ref);
4413 static char *gen_internal_sym (const char *);
4415 static void prune_unmark_dies (dw_die_ref);
4416 static void prune_unused_types_mark (dw_die_ref, int);
4417 static void prune_unused_types_walk (dw_die_ref);
4418 static void prune_unused_types_walk_attribs (dw_die_ref);
4419 static void prune_unused_types_prune (dw_die_ref);
4420 static void prune_unused_types (void);
4421 static int maybe_emit_file (struct dwarf_file_data *fd);
4423 /* Section names used to hold DWARF debugging information. */
4424 #ifndef DEBUG_INFO_SECTION
4425 #define DEBUG_INFO_SECTION ".debug_info"
4427 #ifndef DEBUG_ABBREV_SECTION
4428 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4430 #ifndef DEBUG_ARANGES_SECTION
4431 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4433 #ifndef DEBUG_MACINFO_SECTION
4434 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4436 #ifndef DEBUG_LINE_SECTION
4437 #define DEBUG_LINE_SECTION ".debug_line"
4439 #ifndef DEBUG_LOC_SECTION
4440 #define DEBUG_LOC_SECTION ".debug_loc"
4442 #ifndef DEBUG_PUBNAMES_SECTION
4443 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4445 #ifndef DEBUG_STR_SECTION
4446 #define DEBUG_STR_SECTION ".debug_str"
4448 #ifndef DEBUG_RANGES_SECTION
4449 #define DEBUG_RANGES_SECTION ".debug_ranges"
4452 /* Standard ELF section names for compiled code and data. */
4453 #ifndef TEXT_SECTION_NAME
4454 #define TEXT_SECTION_NAME ".text"
4457 /* Section flags for .debug_str section. */
4458 #define DEBUG_STR_SECTION_FLAGS \
4459 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4460 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4463 /* Labels we insert at beginning sections we can reference instead of
4464 the section names themselves. */
4466 #ifndef TEXT_SECTION_LABEL
4467 #define TEXT_SECTION_LABEL "Ltext"
4469 #ifndef COLD_TEXT_SECTION_LABEL
4470 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4472 #ifndef DEBUG_LINE_SECTION_LABEL
4473 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4475 #ifndef DEBUG_INFO_SECTION_LABEL
4476 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4478 #ifndef DEBUG_ABBREV_SECTION_LABEL
4479 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4481 #ifndef DEBUG_LOC_SECTION_LABEL
4482 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4484 #ifndef DEBUG_RANGES_SECTION_LABEL
4485 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4487 #ifndef DEBUG_MACINFO_SECTION_LABEL
4488 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4491 /* Definitions of defaults for formats and names of various special
4492 (artificial) labels which may be generated within this file (when the -g
4493 options is used and DWARF2_DEBUGGING_INFO is in effect.
4494 If necessary, these may be overridden from within the tm.h file, but
4495 typically, overriding these defaults is unnecessary. */
4497 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4498 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4499 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4500 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4501 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4502 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4503 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4504 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4505 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4506 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4508 #ifndef TEXT_END_LABEL
4509 #define TEXT_END_LABEL "Letext"
4511 #ifndef COLD_END_LABEL
4512 #define COLD_END_LABEL "Letext_cold"
4514 #ifndef BLOCK_BEGIN_LABEL
4515 #define BLOCK_BEGIN_LABEL "LBB"
4517 #ifndef BLOCK_END_LABEL
4518 #define BLOCK_END_LABEL "LBE"
4520 #ifndef LINE_CODE_LABEL
4521 #define LINE_CODE_LABEL "LM"
4523 #ifndef SEPARATE_LINE_CODE_LABEL
4524 #define SEPARATE_LINE_CODE_LABEL "LSM"
4528 /* We allow a language front-end to designate a function that is to be
4529 called to "demangle" any name before it is put into a DIE. */
4531 static const char *(*demangle_name_func) (const char *);
4534 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4536 demangle_name_func = func;
4539 /* Test if rtl node points to a pseudo register. */
4542 is_pseudo_reg (const_rtx rtl)
4544 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4545 || (GET_CODE (rtl) == SUBREG
4546 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4549 /* Return a reference to a type, with its const and volatile qualifiers
4553 type_main_variant (tree type)
4555 type = TYPE_MAIN_VARIANT (type);
4557 /* ??? There really should be only one main variant among any group of
4558 variants of a given type (and all of the MAIN_VARIANT values for all
4559 members of the group should point to that one type) but sometimes the C
4560 front-end messes this up for array types, so we work around that bug
4562 if (TREE_CODE (type) == ARRAY_TYPE)
4563 while (type != TYPE_MAIN_VARIANT (type))
4564 type = TYPE_MAIN_VARIANT (type);
4569 /* Return nonzero if the given type node represents a tagged type. */
4572 is_tagged_type (const_tree type)
4574 enum tree_code code = TREE_CODE (type);
4576 return (code == RECORD_TYPE || code == UNION_TYPE
4577 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4580 /* Convert a DIE tag into its string name. */
4583 dwarf_tag_name (unsigned int tag)
4587 case DW_TAG_padding:
4588 return "DW_TAG_padding";
4589 case DW_TAG_array_type:
4590 return "DW_TAG_array_type";
4591 case DW_TAG_class_type:
4592 return "DW_TAG_class_type";
4593 case DW_TAG_entry_point:
4594 return "DW_TAG_entry_point";
4595 case DW_TAG_enumeration_type:
4596 return "DW_TAG_enumeration_type";
4597 case DW_TAG_formal_parameter:
4598 return "DW_TAG_formal_parameter";
4599 case DW_TAG_imported_declaration:
4600 return "DW_TAG_imported_declaration";
4602 return "DW_TAG_label";
4603 case DW_TAG_lexical_block:
4604 return "DW_TAG_lexical_block";
4606 return "DW_TAG_member";
4607 case DW_TAG_pointer_type:
4608 return "DW_TAG_pointer_type";
4609 case DW_TAG_reference_type:
4610 return "DW_TAG_reference_type";
4611 case DW_TAG_compile_unit:
4612 return "DW_TAG_compile_unit";
4613 case DW_TAG_string_type:
4614 return "DW_TAG_string_type";
4615 case DW_TAG_structure_type:
4616 return "DW_TAG_structure_type";
4617 case DW_TAG_subroutine_type:
4618 return "DW_TAG_subroutine_type";
4619 case DW_TAG_typedef:
4620 return "DW_TAG_typedef";
4621 case DW_TAG_union_type:
4622 return "DW_TAG_union_type";
4623 case DW_TAG_unspecified_parameters:
4624 return "DW_TAG_unspecified_parameters";
4625 case DW_TAG_variant:
4626 return "DW_TAG_variant";
4627 case DW_TAG_common_block:
4628 return "DW_TAG_common_block";
4629 case DW_TAG_common_inclusion:
4630 return "DW_TAG_common_inclusion";
4631 case DW_TAG_inheritance:
4632 return "DW_TAG_inheritance";
4633 case DW_TAG_inlined_subroutine:
4634 return "DW_TAG_inlined_subroutine";
4636 return "DW_TAG_module";
4637 case DW_TAG_ptr_to_member_type:
4638 return "DW_TAG_ptr_to_member_type";
4639 case DW_TAG_set_type:
4640 return "DW_TAG_set_type";
4641 case DW_TAG_subrange_type:
4642 return "DW_TAG_subrange_type";
4643 case DW_TAG_with_stmt:
4644 return "DW_TAG_with_stmt";
4645 case DW_TAG_access_declaration:
4646 return "DW_TAG_access_declaration";
4647 case DW_TAG_base_type:
4648 return "DW_TAG_base_type";
4649 case DW_TAG_catch_block:
4650 return "DW_TAG_catch_block";
4651 case DW_TAG_const_type:
4652 return "DW_TAG_const_type";
4653 case DW_TAG_constant:
4654 return "DW_TAG_constant";
4655 case DW_TAG_enumerator:
4656 return "DW_TAG_enumerator";
4657 case DW_TAG_file_type:
4658 return "DW_TAG_file_type";
4660 return "DW_TAG_friend";
4661 case DW_TAG_namelist:
4662 return "DW_TAG_namelist";
4663 case DW_TAG_namelist_item:
4664 return "DW_TAG_namelist_item";
4665 case DW_TAG_packed_type:
4666 return "DW_TAG_packed_type";
4667 case DW_TAG_subprogram:
4668 return "DW_TAG_subprogram";
4669 case DW_TAG_template_type_param:
4670 return "DW_TAG_template_type_param";
4671 case DW_TAG_template_value_param:
4672 return "DW_TAG_template_value_param";
4673 case DW_TAG_thrown_type:
4674 return "DW_TAG_thrown_type";
4675 case DW_TAG_try_block:
4676 return "DW_TAG_try_block";
4677 case DW_TAG_variant_part:
4678 return "DW_TAG_variant_part";
4679 case DW_TAG_variable:
4680 return "DW_TAG_variable";
4681 case DW_TAG_volatile_type:
4682 return "DW_TAG_volatile_type";
4683 case DW_TAG_dwarf_procedure:
4684 return "DW_TAG_dwarf_procedure";
4685 case DW_TAG_restrict_type:
4686 return "DW_TAG_restrict_type";
4687 case DW_TAG_interface_type:
4688 return "DW_TAG_interface_type";
4689 case DW_TAG_namespace:
4690 return "DW_TAG_namespace";
4691 case DW_TAG_imported_module:
4692 return "DW_TAG_imported_module";
4693 case DW_TAG_unspecified_type:
4694 return "DW_TAG_unspecified_type";
4695 case DW_TAG_partial_unit:
4696 return "DW_TAG_partial_unit";
4697 case DW_TAG_imported_unit:
4698 return "DW_TAG_imported_unit";
4699 case DW_TAG_condition:
4700 return "DW_TAG_condition";
4701 case DW_TAG_shared_type:
4702 return "DW_TAG_shared_type";
4703 case DW_TAG_MIPS_loop:
4704 return "DW_TAG_MIPS_loop";
4705 case DW_TAG_format_label:
4706 return "DW_TAG_format_label";
4707 case DW_TAG_function_template:
4708 return "DW_TAG_function_template";
4709 case DW_TAG_class_template:
4710 return "DW_TAG_class_template";
4711 case DW_TAG_GNU_BINCL:
4712 return "DW_TAG_GNU_BINCL";
4713 case DW_TAG_GNU_EINCL:
4714 return "DW_TAG_GNU_EINCL";
4716 return "DW_TAG_<unknown>";
4720 /* Convert a DWARF attribute code into its string name. */
4723 dwarf_attr_name (unsigned int attr)
4728 return "DW_AT_sibling";
4729 case DW_AT_location:
4730 return "DW_AT_location";
4732 return "DW_AT_name";
4733 case DW_AT_ordering:
4734 return "DW_AT_ordering";
4735 case DW_AT_subscr_data:
4736 return "DW_AT_subscr_data";
4737 case DW_AT_byte_size:
4738 return "DW_AT_byte_size";
4739 case DW_AT_bit_offset:
4740 return "DW_AT_bit_offset";
4741 case DW_AT_bit_size:
4742 return "DW_AT_bit_size";
4743 case DW_AT_element_list:
4744 return "DW_AT_element_list";
4745 case DW_AT_stmt_list:
4746 return "DW_AT_stmt_list";
4748 return "DW_AT_low_pc";
4750 return "DW_AT_high_pc";
4751 case DW_AT_language:
4752 return "DW_AT_language";
4754 return "DW_AT_member";
4756 return "DW_AT_discr";
4757 case DW_AT_discr_value:
4758 return "DW_AT_discr_value";
4759 case DW_AT_visibility:
4760 return "DW_AT_visibility";
4762 return "DW_AT_import";
4763 case DW_AT_string_length:
4764 return "DW_AT_string_length";
4765 case DW_AT_common_reference:
4766 return "DW_AT_common_reference";
4767 case DW_AT_comp_dir:
4768 return "DW_AT_comp_dir";
4769 case DW_AT_const_value:
4770 return "DW_AT_const_value";
4771 case DW_AT_containing_type:
4772 return "DW_AT_containing_type";
4773 case DW_AT_default_value:
4774 return "DW_AT_default_value";
4776 return "DW_AT_inline";
4777 case DW_AT_is_optional:
4778 return "DW_AT_is_optional";
4779 case DW_AT_lower_bound:
4780 return "DW_AT_lower_bound";
4781 case DW_AT_producer:
4782 return "DW_AT_producer";
4783 case DW_AT_prototyped:
4784 return "DW_AT_prototyped";
4785 case DW_AT_return_addr:
4786 return "DW_AT_return_addr";
4787 case DW_AT_start_scope:
4788 return "DW_AT_start_scope";
4789 case DW_AT_bit_stride:
4790 return "DW_AT_bit_stride";
4791 case DW_AT_upper_bound:
4792 return "DW_AT_upper_bound";
4793 case DW_AT_abstract_origin:
4794 return "DW_AT_abstract_origin";
4795 case DW_AT_accessibility:
4796 return "DW_AT_accessibility";
4797 case DW_AT_address_class:
4798 return "DW_AT_address_class";
4799 case DW_AT_artificial:
4800 return "DW_AT_artificial";
4801 case DW_AT_base_types:
4802 return "DW_AT_base_types";
4803 case DW_AT_calling_convention:
4804 return "DW_AT_calling_convention";
4806 return "DW_AT_count";
4807 case DW_AT_data_member_location:
4808 return "DW_AT_data_member_location";
4809 case DW_AT_decl_column:
4810 return "DW_AT_decl_column";
4811 case DW_AT_decl_file:
4812 return "DW_AT_decl_file";
4813 case DW_AT_decl_line:
4814 return "DW_AT_decl_line";
4815 case DW_AT_declaration:
4816 return "DW_AT_declaration";
4817 case DW_AT_discr_list:
4818 return "DW_AT_discr_list";
4819 case DW_AT_encoding:
4820 return "DW_AT_encoding";
4821 case DW_AT_external:
4822 return "DW_AT_external";
4823 case DW_AT_frame_base:
4824 return "DW_AT_frame_base";
4826 return "DW_AT_friend";
4827 case DW_AT_identifier_case:
4828 return "DW_AT_identifier_case";
4829 case DW_AT_macro_info:
4830 return "DW_AT_macro_info";
4831 case DW_AT_namelist_items:
4832 return "DW_AT_namelist_items";
4833 case DW_AT_priority:
4834 return "DW_AT_priority";
4836 return "DW_AT_segment";
4837 case DW_AT_specification:
4838 return "DW_AT_specification";
4839 case DW_AT_static_link:
4840 return "DW_AT_static_link";
4842 return "DW_AT_type";
4843 case DW_AT_use_location:
4844 return "DW_AT_use_location";
4845 case DW_AT_variable_parameter:
4846 return "DW_AT_variable_parameter";
4847 case DW_AT_virtuality:
4848 return "DW_AT_virtuality";
4849 case DW_AT_vtable_elem_location:
4850 return "DW_AT_vtable_elem_location";
4852 case DW_AT_allocated:
4853 return "DW_AT_allocated";
4854 case DW_AT_associated:
4855 return "DW_AT_associated";
4856 case DW_AT_data_location:
4857 return "DW_AT_data_location";
4858 case DW_AT_byte_stride:
4859 return "DW_AT_byte_stride";
4860 case DW_AT_entry_pc:
4861 return "DW_AT_entry_pc";
4862 case DW_AT_use_UTF8:
4863 return "DW_AT_use_UTF8";
4864 case DW_AT_extension:
4865 return "DW_AT_extension";
4867 return "DW_AT_ranges";
4868 case DW_AT_trampoline:
4869 return "DW_AT_trampoline";
4870 case DW_AT_call_column:
4871 return "DW_AT_call_column";
4872 case DW_AT_call_file:
4873 return "DW_AT_call_file";
4874 case DW_AT_call_line:
4875 return "DW_AT_call_line";
4877 case DW_AT_MIPS_fde:
4878 return "DW_AT_MIPS_fde";
4879 case DW_AT_MIPS_loop_begin:
4880 return "DW_AT_MIPS_loop_begin";
4881 case DW_AT_MIPS_tail_loop_begin:
4882 return "DW_AT_MIPS_tail_loop_begin";
4883 case DW_AT_MIPS_epilog_begin:
4884 return "DW_AT_MIPS_epilog_begin";
4885 case DW_AT_MIPS_loop_unroll_factor:
4886 return "DW_AT_MIPS_loop_unroll_factor";
4887 case DW_AT_MIPS_software_pipeline_depth:
4888 return "DW_AT_MIPS_software_pipeline_depth";
4889 case DW_AT_MIPS_linkage_name:
4890 return "DW_AT_MIPS_linkage_name";
4891 case DW_AT_MIPS_stride:
4892 return "DW_AT_MIPS_stride";
4893 case DW_AT_MIPS_abstract_name:
4894 return "DW_AT_MIPS_abstract_name";
4895 case DW_AT_MIPS_clone_origin:
4896 return "DW_AT_MIPS_clone_origin";
4897 case DW_AT_MIPS_has_inlines:
4898 return "DW_AT_MIPS_has_inlines";
4900 case DW_AT_sf_names:
4901 return "DW_AT_sf_names";
4902 case DW_AT_src_info:
4903 return "DW_AT_src_info";
4904 case DW_AT_mac_info:
4905 return "DW_AT_mac_info";
4906 case DW_AT_src_coords:
4907 return "DW_AT_src_coords";
4908 case DW_AT_body_begin:
4909 return "DW_AT_body_begin";
4910 case DW_AT_body_end:
4911 return "DW_AT_body_end";
4912 case DW_AT_GNU_vector:
4913 return "DW_AT_GNU_vector";
4915 case DW_AT_VMS_rtnbeg_pd_address:
4916 return "DW_AT_VMS_rtnbeg_pd_address";
4919 return "DW_AT_<unknown>";
4923 /* Convert a DWARF value form code into its string name. */
4926 dwarf_form_name (unsigned int form)
4931 return "DW_FORM_addr";
4932 case DW_FORM_block2:
4933 return "DW_FORM_block2";
4934 case DW_FORM_block4:
4935 return "DW_FORM_block4";
4937 return "DW_FORM_data2";
4939 return "DW_FORM_data4";
4941 return "DW_FORM_data8";
4942 case DW_FORM_string:
4943 return "DW_FORM_string";
4945 return "DW_FORM_block";
4946 case DW_FORM_block1:
4947 return "DW_FORM_block1";
4949 return "DW_FORM_data1";
4951 return "DW_FORM_flag";
4953 return "DW_FORM_sdata";
4955 return "DW_FORM_strp";
4957 return "DW_FORM_udata";
4958 case DW_FORM_ref_addr:
4959 return "DW_FORM_ref_addr";
4961 return "DW_FORM_ref1";
4963 return "DW_FORM_ref2";
4965 return "DW_FORM_ref4";
4967 return "DW_FORM_ref8";
4968 case DW_FORM_ref_udata:
4969 return "DW_FORM_ref_udata";
4970 case DW_FORM_indirect:
4971 return "DW_FORM_indirect";
4973 return "DW_FORM_<unknown>";
4977 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4978 instance of an inlined instance of a decl which is local to an inline
4979 function, so we have to trace all of the way back through the origin chain
4980 to find out what sort of node actually served as the original seed for the
4984 decl_ultimate_origin (const_tree decl)
4986 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4989 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4990 nodes in the function to point to themselves; ignore that if
4991 we're trying to output the abstract instance of this function. */
4992 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4995 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4996 most distant ancestor, this should never happen. */
4997 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4999 return DECL_ABSTRACT_ORIGIN (decl);
5002 /* Determine the "ultimate origin" of a block. The block may be an inlined
5003 instance of an inlined instance of a block which is local to an inline
5004 function, so we have to trace all of the way back through the origin chain
5005 to find out what sort of node actually served as the original seed for the
5009 block_ultimate_origin (const_tree block)
5011 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
5013 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5014 nodes in the function to point to themselves; ignore that if
5015 we're trying to output the abstract instance of this function. */
5016 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
5019 if (immediate_origin == NULL_TREE)
5024 tree lookahead = immediate_origin;
5028 ret_val = lookahead;
5029 lookahead = (TREE_CODE (ret_val) == BLOCK
5030 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
5032 while (lookahead != NULL && lookahead != ret_val);
5034 /* The block's abstract origin chain may not be the *ultimate* origin of
5035 the block. It could lead to a DECL that has an abstract origin set.
5036 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5037 will give us if it has one). Note that DECL's abstract origins are
5038 supposed to be the most distant ancestor (or so decl_ultimate_origin
5039 claims), so we don't need to loop following the DECL origins. */
5040 if (DECL_P (ret_val))
5041 return DECL_ORIGIN (ret_val);
5047 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5048 of a virtual function may refer to a base class, so we check the 'this'
5052 decl_class_context (tree decl)
5054 tree context = NULL_TREE;
5056 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5057 context = DECL_CONTEXT (decl);
5059 context = TYPE_MAIN_VARIANT
5060 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5062 if (context && !TYPE_P (context))
5063 context = NULL_TREE;
5068 /* Add an attribute/value pair to a DIE. */
5071 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5073 /* Maybe this should be an assert? */
5077 if (die->die_attr == NULL)
5078 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5079 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5082 static inline enum dw_val_class
5083 AT_class (dw_attr_ref a)
5085 return a->dw_attr_val.val_class;
5088 /* Add a flag value attribute to a DIE. */
5091 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5095 attr.dw_attr = attr_kind;
5096 attr.dw_attr_val.val_class = dw_val_class_flag;
5097 attr.dw_attr_val.v.val_flag = flag;
5098 add_dwarf_attr (die, &attr);
5101 static inline unsigned
5102 AT_flag (dw_attr_ref a)
5104 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5105 return a->dw_attr_val.v.val_flag;
5108 /* Add a signed integer attribute value to a DIE. */
5111 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5115 attr.dw_attr = attr_kind;
5116 attr.dw_attr_val.val_class = dw_val_class_const;
5117 attr.dw_attr_val.v.val_int = int_val;
5118 add_dwarf_attr (die, &attr);
5121 static inline HOST_WIDE_INT
5122 AT_int (dw_attr_ref a)
5124 gcc_assert (a && AT_class (a) == dw_val_class_const);
5125 return a->dw_attr_val.v.val_int;
5128 /* Add an unsigned integer attribute value to a DIE. */
5131 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5132 unsigned HOST_WIDE_INT unsigned_val)
5136 attr.dw_attr = attr_kind;
5137 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5138 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5139 add_dwarf_attr (die, &attr);
5142 static inline unsigned HOST_WIDE_INT
5143 AT_unsigned (dw_attr_ref a)
5145 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5146 return a->dw_attr_val.v.val_unsigned;
5149 /* Add an unsigned double integer attribute value to a DIE. */
5152 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5153 long unsigned int val_hi, long unsigned int val_low)
5157 attr.dw_attr = attr_kind;
5158 attr.dw_attr_val.val_class = dw_val_class_long_long;
5159 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5160 attr.dw_attr_val.v.val_long_long.low = val_low;
5161 add_dwarf_attr (die, &attr);
5164 /* Add a floating point attribute value to a DIE and return it. */
5167 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5168 unsigned int length, unsigned int elt_size, unsigned char *array)
5172 attr.dw_attr = attr_kind;
5173 attr.dw_attr_val.val_class = dw_val_class_vec;
5174 attr.dw_attr_val.v.val_vec.length = length;
5175 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5176 attr.dw_attr_val.v.val_vec.array = array;
5177 add_dwarf_attr (die, &attr);
5180 /* Hash and equality functions for debug_str_hash. */
5183 debug_str_do_hash (const void *x)
5185 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5189 debug_str_eq (const void *x1, const void *x2)
5191 return strcmp ((((const struct indirect_string_node *)x1)->str),
5192 (const char *)x2) == 0;
5195 /* Add a string attribute value to a DIE. */
5198 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5201 struct indirect_string_node *node;
5204 if (! debug_str_hash)
5205 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5206 debug_str_eq, NULL);
5208 slot = htab_find_slot_with_hash (debug_str_hash, str,
5209 htab_hash_string (str), INSERT);
5212 node = (struct indirect_string_node *)
5213 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5214 node->str = ggc_strdup (str);
5218 node = (struct indirect_string_node *) *slot;
5222 attr.dw_attr = attr_kind;
5223 attr.dw_attr_val.val_class = dw_val_class_str;
5224 attr.dw_attr_val.v.val_str = node;
5225 add_dwarf_attr (die, &attr);
5228 static inline const char *
5229 AT_string (dw_attr_ref a)
5231 gcc_assert (a && AT_class (a) == dw_val_class_str);
5232 return a->dw_attr_val.v.val_str->str;
5235 /* Find out whether a string should be output inline in DIE
5236 or out-of-line in .debug_str section. */
5239 AT_string_form (dw_attr_ref a)
5241 struct indirect_string_node *node;
5245 gcc_assert (a && AT_class (a) == dw_val_class_str);
5247 node = a->dw_attr_val.v.val_str;
5251 len = strlen (node->str) + 1;
5253 /* If the string is shorter or equal to the size of the reference, it is
5254 always better to put it inline. */
5255 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5256 return node->form = DW_FORM_string;
5258 /* If we cannot expect the linker to merge strings in .debug_str
5259 section, only put it into .debug_str if it is worth even in this
5261 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5262 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5263 return node->form = DW_FORM_string;
5265 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5266 ++dw2_string_counter;
5267 node->label = xstrdup (label);
5269 return node->form = DW_FORM_strp;
5272 /* Add a DIE reference attribute value to a DIE. */
5275 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5279 attr.dw_attr = attr_kind;
5280 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5281 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5282 attr.dw_attr_val.v.val_die_ref.external = 0;
5283 add_dwarf_attr (die, &attr);
5286 /* Add an AT_specification attribute to a DIE, and also make the back
5287 pointer from the specification to the definition. */
5290 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5292 add_AT_die_ref (die, DW_AT_specification, targ_die);
5293 gcc_assert (!targ_die->die_definition);
5294 targ_die->die_definition = die;
5297 static inline dw_die_ref
5298 AT_ref (dw_attr_ref a)
5300 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5301 return a->dw_attr_val.v.val_die_ref.die;
5305 AT_ref_external (dw_attr_ref a)
5307 if (a && AT_class (a) == dw_val_class_die_ref)
5308 return a->dw_attr_val.v.val_die_ref.external;
5314 set_AT_ref_external (dw_attr_ref a, int i)
5316 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5317 a->dw_attr_val.v.val_die_ref.external = i;
5320 /* Add an FDE reference attribute value to a DIE. */
5323 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5327 attr.dw_attr = attr_kind;
5328 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5329 attr.dw_attr_val.v.val_fde_index = targ_fde;
5330 add_dwarf_attr (die, &attr);
5333 /* Add a location description attribute value to a DIE. */
5336 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5340 attr.dw_attr = attr_kind;
5341 attr.dw_attr_val.val_class = dw_val_class_loc;
5342 attr.dw_attr_val.v.val_loc = loc;
5343 add_dwarf_attr (die, &attr);
5346 static inline dw_loc_descr_ref
5347 AT_loc (dw_attr_ref a)
5349 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5350 return a->dw_attr_val.v.val_loc;
5354 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5358 attr.dw_attr = attr_kind;
5359 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5360 attr.dw_attr_val.v.val_loc_list = loc_list;
5361 add_dwarf_attr (die, &attr);
5362 have_location_lists = true;
5365 static inline dw_loc_list_ref
5366 AT_loc_list (dw_attr_ref a)
5368 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5369 return a->dw_attr_val.v.val_loc_list;
5372 /* Add an address constant attribute value to a DIE. */
5375 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5379 attr.dw_attr = attr_kind;
5380 attr.dw_attr_val.val_class = dw_val_class_addr;
5381 attr.dw_attr_val.v.val_addr = addr;
5382 add_dwarf_attr (die, &attr);
5385 /* Get the RTX from to an address DIE attribute. */
5388 AT_addr (dw_attr_ref a)
5390 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5391 return a->dw_attr_val.v.val_addr;
5394 /* Add a file attribute value to a DIE. */
5397 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5398 struct dwarf_file_data *fd)
5402 attr.dw_attr = attr_kind;
5403 attr.dw_attr_val.val_class = dw_val_class_file;
5404 attr.dw_attr_val.v.val_file = fd;
5405 add_dwarf_attr (die, &attr);
5408 /* Get the dwarf_file_data from a file DIE attribute. */
5410 static inline struct dwarf_file_data *
5411 AT_file (dw_attr_ref a)
5413 gcc_assert (a && AT_class (a) == dw_val_class_file);
5414 return a->dw_attr_val.v.val_file;
5417 /* Add a label identifier attribute value to a DIE. */
5420 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5424 attr.dw_attr = attr_kind;
5425 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5426 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5427 add_dwarf_attr (die, &attr);
5430 /* Add a section offset attribute value to a DIE, an offset into the
5431 debug_line section. */
5434 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5439 attr.dw_attr = attr_kind;
5440 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5441 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5442 add_dwarf_attr (die, &attr);
5445 /* Add a section offset attribute value to a DIE, an offset into the
5446 debug_macinfo section. */
5449 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5454 attr.dw_attr = attr_kind;
5455 attr.dw_attr_val.val_class = dw_val_class_macptr;
5456 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5457 add_dwarf_attr (die, &attr);
5460 /* Add an offset attribute value to a DIE. */
5463 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5464 unsigned HOST_WIDE_INT offset)
5468 attr.dw_attr = attr_kind;
5469 attr.dw_attr_val.val_class = dw_val_class_offset;
5470 attr.dw_attr_val.v.val_offset = offset;
5471 add_dwarf_attr (die, &attr);
5474 /* Add an range_list attribute value to a DIE. */
5477 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5478 long unsigned int offset)
5482 attr.dw_attr = attr_kind;
5483 attr.dw_attr_val.val_class = dw_val_class_range_list;
5484 attr.dw_attr_val.v.val_offset = offset;
5485 add_dwarf_attr (die, &attr);
5488 static inline const char *
5489 AT_lbl (dw_attr_ref a)
5491 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5492 || AT_class (a) == dw_val_class_lineptr
5493 || AT_class (a) == dw_val_class_macptr));
5494 return a->dw_attr_val.v.val_lbl_id;
5497 /* Get the attribute of type attr_kind. */
5500 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5504 dw_die_ref spec = NULL;
5509 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5510 if (a->dw_attr == attr_kind)
5512 else if (a->dw_attr == DW_AT_specification
5513 || a->dw_attr == DW_AT_abstract_origin)
5517 return get_AT (spec, attr_kind);
5522 /* Return the "low pc" attribute value, typically associated with a subprogram
5523 DIE. Return null if the "low pc" attribute is either not present, or if it
5524 cannot be represented as an assembler label identifier. */
5526 static inline const char *
5527 get_AT_low_pc (dw_die_ref die)
5529 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5531 return a ? AT_lbl (a) : NULL;
5534 /* Return the "high pc" attribute value, typically associated with a subprogram
5535 DIE. Return null if the "high pc" attribute is either not present, or if it
5536 cannot be represented as an assembler label identifier. */
5538 static inline const char *
5539 get_AT_hi_pc (dw_die_ref die)
5541 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5543 return a ? AT_lbl (a) : NULL;
5546 /* Return the value of the string attribute designated by ATTR_KIND, or
5547 NULL if it is not present. */
5549 static inline const char *
5550 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5552 dw_attr_ref a = get_AT (die, attr_kind);
5554 return a ? AT_string (a) : NULL;
5557 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5558 if it is not present. */
5561 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5563 dw_attr_ref a = get_AT (die, attr_kind);
5565 return a ? AT_flag (a) : 0;
5568 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5569 if it is not present. */
5571 static inline unsigned
5572 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5574 dw_attr_ref a = get_AT (die, attr_kind);
5576 return a ? AT_unsigned (a) : 0;
5579 static inline dw_die_ref
5580 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5582 dw_attr_ref a = get_AT (die, attr_kind);
5584 return a ? AT_ref (a) : NULL;
5587 static inline struct dwarf_file_data *
5588 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5590 dw_attr_ref a = get_AT (die, attr_kind);
5592 return a ? AT_file (a) : NULL;
5595 /* Return TRUE if the language is C or C++. */
5600 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5602 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5603 || lang == DW_LANG_C99
5604 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5607 /* Return TRUE if the language is C++. */
5612 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5614 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5617 /* Return TRUE if the language is Fortran. */
5622 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5624 return (lang == DW_LANG_Fortran77
5625 || lang == DW_LANG_Fortran90
5626 || lang == DW_LANG_Fortran95);
5629 /* Return TRUE if the language is Java. */
5634 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5636 return lang == DW_LANG_Java;
5639 /* Return TRUE if the language is Ada. */
5644 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5646 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5649 /* Remove the specified attribute if present. */
5652 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5660 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5661 if (a->dw_attr == attr_kind)
5663 if (AT_class (a) == dw_val_class_str)
5664 if (a->dw_attr_val.v.val_str->refcount)
5665 a->dw_attr_val.v.val_str->refcount--;
5667 /* VEC_ordered_remove should help reduce the number of abbrevs
5669 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5674 /* Remove CHILD from its parent. PREV must have the property that
5675 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5678 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5680 gcc_assert (child->die_parent == prev->die_parent);
5681 gcc_assert (prev->die_sib == child);
5684 gcc_assert (child->die_parent->die_child == child);
5688 prev->die_sib = child->die_sib;
5689 if (child->die_parent->die_child == child)
5690 child->die_parent->die_child = prev;
5693 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5697 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5703 dw_die_ref prev = c;
5705 while (c->die_tag == tag)
5707 remove_child_with_prev (c, prev);
5708 /* Might have removed every child. */
5709 if (c == c->die_sib)
5713 } while (c != die->die_child);
5716 /* Add a CHILD_DIE as the last child of DIE. */
5719 add_child_die (dw_die_ref die, dw_die_ref child_die)
5721 /* FIXME this should probably be an assert. */
5722 if (! die || ! child_die)
5724 gcc_assert (die != child_die);
5726 child_die->die_parent = die;
5729 child_die->die_sib = die->die_child->die_sib;
5730 die->die_child->die_sib = child_die;
5733 child_die->die_sib = child_die;
5734 die->die_child = child_die;
5737 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5738 is the specification, to the end of PARENT's list of children.
5739 This is done by removing and re-adding it. */
5742 splice_child_die (dw_die_ref parent, dw_die_ref child)
5746 /* We want the declaration DIE from inside the class, not the
5747 specification DIE at toplevel. */
5748 if (child->die_parent != parent)
5750 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5756 gcc_assert (child->die_parent == parent
5757 || (child->die_parent
5758 == get_AT_ref (parent, DW_AT_specification)));
5760 for (p = child->die_parent->die_child; ; p = p->die_sib)
5761 if (p->die_sib == child)
5763 remove_child_with_prev (child, p);
5767 add_child_die (parent, child);
5770 /* Return a pointer to a newly created DIE node. */
5772 static inline dw_die_ref
5773 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5775 dw_die_ref die = GGC_CNEW (die_node);
5777 die->die_tag = tag_value;
5779 if (parent_die != NULL)
5780 add_child_die (parent_die, die);
5783 limbo_die_node *limbo_node;
5785 limbo_node = GGC_CNEW (limbo_die_node);
5786 limbo_node->die = die;
5787 limbo_node->created_for = t;
5788 limbo_node->next = limbo_die_list;
5789 limbo_die_list = limbo_node;
5795 /* Return the DIE associated with the given type specifier. */
5797 static inline dw_die_ref
5798 lookup_type_die (tree type)
5800 return TYPE_SYMTAB_DIE (type);
5803 /* Equate a DIE to a given type specifier. */
5806 equate_type_number_to_die (tree type, dw_die_ref type_die)
5808 TYPE_SYMTAB_DIE (type) = type_die;
5811 /* Returns a hash value for X (which really is a die_struct). */
5814 decl_die_table_hash (const void *x)
5816 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5819 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5822 decl_die_table_eq (const void *x, const void *y)
5824 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5827 /* Return the DIE associated with a given declaration. */
5829 static inline dw_die_ref
5830 lookup_decl_die (tree decl)
5832 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5835 /* Returns a hash value for X (which really is a var_loc_list). */
5838 decl_loc_table_hash (const void *x)
5840 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5843 /* Return nonzero if decl_id of var_loc_list X is the same as
5847 decl_loc_table_eq (const void *x, const void *y)
5849 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5852 /* Return the var_loc list associated with a given declaration. */
5854 static inline var_loc_list *
5855 lookup_decl_loc (const_tree decl)
5857 return (var_loc_list *)
5858 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5861 /* Equate a DIE to a particular declaration. */
5864 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5866 unsigned int decl_id = DECL_UID (decl);
5869 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5871 decl_die->decl_id = decl_id;
5874 /* Add a variable location node to the linked list for DECL. */
5877 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5879 unsigned int decl_id = DECL_UID (decl);
5883 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5886 temp = GGC_CNEW (var_loc_list);
5887 temp->decl_id = decl_id;
5891 temp = (var_loc_list *) *slot;
5895 /* If the current location is the same as the end of the list,
5896 and either both or neither of the locations is uninitialized,
5897 we have nothing to do. */
5898 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5899 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5900 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5901 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
5902 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5903 == VAR_INIT_STATUS_UNINITIALIZED)
5904 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
5905 == VAR_INIT_STATUS_UNINITIALIZED))))
5907 /* Add LOC to the end of list and update LAST. */
5908 temp->last->next = loc;
5912 /* Do not add empty location to the beginning of the list. */
5913 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5920 /* Keep track of the number of spaces used to indent the
5921 output of the debugging routines that print the structure of
5922 the DIE internal representation. */
5923 static int print_indent;
5925 /* Indent the line the number of spaces given by print_indent. */
5928 print_spaces (FILE *outfile)
5930 fprintf (outfile, "%*s", print_indent, "");
5933 /* Print the information associated with a given DIE, and its children.
5934 This routine is a debugging aid only. */
5937 print_die (dw_die_ref die, FILE *outfile)
5943 print_spaces (outfile);
5944 fprintf (outfile, "DIE %4ld: %s\n",
5945 die->die_offset, dwarf_tag_name (die->die_tag));
5946 print_spaces (outfile);
5947 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5948 fprintf (outfile, " offset: %ld\n", die->die_offset);
5950 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5952 print_spaces (outfile);
5953 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5955 switch (AT_class (a))
5957 case dw_val_class_addr:
5958 fprintf (outfile, "address");
5960 case dw_val_class_offset:
5961 fprintf (outfile, "offset");
5963 case dw_val_class_loc:
5964 fprintf (outfile, "location descriptor");
5966 case dw_val_class_loc_list:
5967 fprintf (outfile, "location list -> label:%s",
5968 AT_loc_list (a)->ll_symbol);
5970 case dw_val_class_range_list:
5971 fprintf (outfile, "range list");
5973 case dw_val_class_const:
5974 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5976 case dw_val_class_unsigned_const:
5977 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5979 case dw_val_class_long_long:
5980 fprintf (outfile, "constant (%lu,%lu)",
5981 a->dw_attr_val.v.val_long_long.hi,
5982 a->dw_attr_val.v.val_long_long.low);
5984 case dw_val_class_vec:
5985 fprintf (outfile, "floating-point or vector constant");
5987 case dw_val_class_flag:
5988 fprintf (outfile, "%u", AT_flag (a));
5990 case dw_val_class_die_ref:
5991 if (AT_ref (a) != NULL)
5993 if (AT_ref (a)->die_symbol)
5994 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5996 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5999 fprintf (outfile, "die -> <null>");
6001 case dw_val_class_lbl_id:
6002 case dw_val_class_lineptr:
6003 case dw_val_class_macptr:
6004 fprintf (outfile, "label: %s", AT_lbl (a));
6006 case dw_val_class_str:
6007 if (AT_string (a) != NULL)
6008 fprintf (outfile, "\"%s\"", AT_string (a));
6010 fprintf (outfile, "<null>");
6012 case dw_val_class_file:
6013 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6014 AT_file (a)->emitted_number);
6020 fprintf (outfile, "\n");
6023 if (die->die_child != NULL)
6026 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6029 if (print_indent == 0)
6030 fprintf (outfile, "\n");
6033 /* Print the contents of the source code line number correspondence table.
6034 This routine is a debugging aid only. */
6037 print_dwarf_line_table (FILE *outfile)
6040 dw_line_info_ref line_info;
6042 fprintf (outfile, "\n\nDWARF source line information\n");
6043 for (i = 1; i < line_info_table_in_use; i++)
6045 line_info = &line_info_table[i];
6046 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6047 line_info->dw_file_num,
6048 line_info->dw_line_num);
6051 fprintf (outfile, "\n\n");
6054 /* Print the information collected for a given DIE. */
6057 debug_dwarf_die (dw_die_ref die)
6059 print_die (die, stderr);
6062 /* Print all DWARF information collected for the compilation unit.
6063 This routine is a debugging aid only. */
6069 print_die (comp_unit_die, stderr);
6070 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6071 print_dwarf_line_table (stderr);
6074 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6075 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6076 DIE that marks the start of the DIEs for this include file. */
6079 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6081 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6082 dw_die_ref new_unit = gen_compile_unit_die (filename);
6084 new_unit->die_sib = old_unit;
6088 /* Close an include-file CU and reopen the enclosing one. */
6091 pop_compile_unit (dw_die_ref old_unit)
6093 dw_die_ref new_unit = old_unit->die_sib;
6095 old_unit->die_sib = NULL;
6099 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6100 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6102 /* Calculate the checksum of a location expression. */
6105 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6107 CHECKSUM (loc->dw_loc_opc);
6108 CHECKSUM (loc->dw_loc_oprnd1);
6109 CHECKSUM (loc->dw_loc_oprnd2);
6112 /* Calculate the checksum of an attribute. */
6115 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6117 dw_loc_descr_ref loc;
6120 CHECKSUM (at->dw_attr);
6122 /* We don't care that this was compiled with a different compiler
6123 snapshot; if the output is the same, that's what matters. */
6124 if (at->dw_attr == DW_AT_producer)
6127 switch (AT_class (at))
6129 case dw_val_class_const:
6130 CHECKSUM (at->dw_attr_val.v.val_int);
6132 case dw_val_class_unsigned_const:
6133 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6135 case dw_val_class_long_long:
6136 CHECKSUM (at->dw_attr_val.v.val_long_long);
6138 case dw_val_class_vec:
6139 CHECKSUM (at->dw_attr_val.v.val_vec);
6141 case dw_val_class_flag:
6142 CHECKSUM (at->dw_attr_val.v.val_flag);
6144 case dw_val_class_str:
6145 CHECKSUM_STRING (AT_string (at));
6148 case dw_val_class_addr:
6150 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6151 CHECKSUM_STRING (XSTR (r, 0));
6154 case dw_val_class_offset:
6155 CHECKSUM (at->dw_attr_val.v.val_offset);
6158 case dw_val_class_loc:
6159 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6160 loc_checksum (loc, ctx);
6163 case dw_val_class_die_ref:
6164 die_checksum (AT_ref (at), ctx, mark);
6167 case dw_val_class_fde_ref:
6168 case dw_val_class_lbl_id:
6169 case dw_val_class_lineptr:
6170 case dw_val_class_macptr:
6173 case dw_val_class_file:
6174 CHECKSUM_STRING (AT_file (at)->filename);
6182 /* Calculate the checksum of a DIE. */
6185 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6191 /* To avoid infinite recursion. */
6194 CHECKSUM (die->die_mark);
6197 die->die_mark = ++(*mark);
6199 CHECKSUM (die->die_tag);
6201 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6202 attr_checksum (a, ctx, mark);
6204 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6208 #undef CHECKSUM_STRING
6210 /* Do the location expressions look same? */
6212 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6214 return loc1->dw_loc_opc == loc2->dw_loc_opc
6215 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6216 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6219 /* Do the values look the same? */
6221 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6223 dw_loc_descr_ref loc1, loc2;
6226 if (v1->val_class != v2->val_class)
6229 switch (v1->val_class)
6231 case dw_val_class_const:
6232 return v1->v.val_int == v2->v.val_int;
6233 case dw_val_class_unsigned_const:
6234 return v1->v.val_unsigned == v2->v.val_unsigned;
6235 case dw_val_class_long_long:
6236 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6237 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6238 case dw_val_class_vec:
6239 if (v1->v.val_vec.length != v2->v.val_vec.length
6240 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6242 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6243 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6246 case dw_val_class_flag:
6247 return v1->v.val_flag == v2->v.val_flag;
6248 case dw_val_class_str:
6249 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6251 case dw_val_class_addr:
6252 r1 = v1->v.val_addr;
6253 r2 = v2->v.val_addr;
6254 if (GET_CODE (r1) != GET_CODE (r2))
6256 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6257 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6259 case dw_val_class_offset:
6260 return v1->v.val_offset == v2->v.val_offset;
6262 case dw_val_class_loc:
6263 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6265 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6266 if (!same_loc_p (loc1, loc2, mark))
6268 return !loc1 && !loc2;
6270 case dw_val_class_die_ref:
6271 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6273 case dw_val_class_fde_ref:
6274 case dw_val_class_lbl_id:
6275 case dw_val_class_lineptr:
6276 case dw_val_class_macptr:
6279 case dw_val_class_file:
6280 return v1->v.val_file == v2->v.val_file;
6287 /* Do the attributes look the same? */
6290 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6292 if (at1->dw_attr != at2->dw_attr)
6295 /* We don't care that this was compiled with a different compiler
6296 snapshot; if the output is the same, that's what matters. */
6297 if (at1->dw_attr == DW_AT_producer)
6300 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6303 /* Do the dies look the same? */
6306 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6312 /* To avoid infinite recursion. */
6314 return die1->die_mark == die2->die_mark;
6315 die1->die_mark = die2->die_mark = ++(*mark);
6317 if (die1->die_tag != die2->die_tag)
6320 if (VEC_length (dw_attr_node, die1->die_attr)
6321 != VEC_length (dw_attr_node, die2->die_attr))
6324 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6325 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6328 c1 = die1->die_child;
6329 c2 = die2->die_child;
6338 if (!same_die_p (c1, c2, mark))
6342 if (c1 == die1->die_child)
6344 if (c2 == die2->die_child)
6354 /* Do the dies look the same? Wrapper around same_die_p. */
6357 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6360 int ret = same_die_p (die1, die2, &mark);
6362 unmark_all_dies (die1);
6363 unmark_all_dies (die2);
6368 /* The prefix to attach to symbols on DIEs in the current comdat debug
6370 static char *comdat_symbol_id;
6372 /* The index of the current symbol within the current comdat CU. */
6373 static unsigned int comdat_symbol_number;
6375 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6376 children, and set comdat_symbol_id accordingly. */
6379 compute_section_prefix (dw_die_ref unit_die)
6381 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6382 const char *base = die_name ? lbasename (die_name) : "anonymous";
6383 char *name = XALLOCAVEC (char, strlen (base) + 64);
6386 unsigned char checksum[16];
6389 /* Compute the checksum of the DIE, then append part of it as hex digits to
6390 the name filename of the unit. */
6392 md5_init_ctx (&ctx);
6394 die_checksum (unit_die, &ctx, &mark);
6395 unmark_all_dies (unit_die);
6396 md5_finish_ctx (&ctx, checksum);
6398 sprintf (name, "%s.", base);
6399 clean_symbol_name (name);
6401 p = name + strlen (name);
6402 for (i = 0; i < 4; i++)
6404 sprintf (p, "%.2x", checksum[i]);
6408 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6409 comdat_symbol_number = 0;
6412 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6415 is_type_die (dw_die_ref die)
6417 switch (die->die_tag)
6419 case DW_TAG_array_type:
6420 case DW_TAG_class_type:
6421 case DW_TAG_interface_type:
6422 case DW_TAG_enumeration_type:
6423 case DW_TAG_pointer_type:
6424 case DW_TAG_reference_type:
6425 case DW_TAG_string_type:
6426 case DW_TAG_structure_type:
6427 case DW_TAG_subroutine_type:
6428 case DW_TAG_union_type:
6429 case DW_TAG_ptr_to_member_type:
6430 case DW_TAG_set_type:
6431 case DW_TAG_subrange_type:
6432 case DW_TAG_base_type:
6433 case DW_TAG_const_type:
6434 case DW_TAG_file_type:
6435 case DW_TAG_packed_type:
6436 case DW_TAG_volatile_type:
6437 case DW_TAG_typedef:
6444 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6445 Basically, we want to choose the bits that are likely to be shared between
6446 compilations (types) and leave out the bits that are specific to individual
6447 compilations (functions). */
6450 is_comdat_die (dw_die_ref c)
6452 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6453 we do for stabs. The advantage is a greater likelihood of sharing between
6454 objects that don't include headers in the same order (and therefore would
6455 put the base types in a different comdat). jason 8/28/00 */
6457 if (c->die_tag == DW_TAG_base_type)
6460 if (c->die_tag == DW_TAG_pointer_type
6461 || c->die_tag == DW_TAG_reference_type
6462 || c->die_tag == DW_TAG_const_type
6463 || c->die_tag == DW_TAG_volatile_type)
6465 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6467 return t ? is_comdat_die (t) : 0;
6470 return is_type_die (c);
6473 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6474 compilation unit. */
6477 is_symbol_die (dw_die_ref c)
6479 return (is_type_die (c)
6480 || (get_AT (c, DW_AT_declaration)
6481 && !get_AT (c, DW_AT_specification))
6482 || c->die_tag == DW_TAG_namespace);
6486 gen_internal_sym (const char *prefix)
6490 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6491 return xstrdup (buf);
6494 /* Assign symbols to all worthy DIEs under DIE. */
6497 assign_symbol_names (dw_die_ref die)
6501 if (is_symbol_die (die))
6503 if (comdat_symbol_id)
6505 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6507 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6508 comdat_symbol_id, comdat_symbol_number++);
6509 die->die_symbol = xstrdup (p);
6512 die->die_symbol = gen_internal_sym ("LDIE");
6515 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6518 struct cu_hash_table_entry
6521 unsigned min_comdat_num, max_comdat_num;
6522 struct cu_hash_table_entry *next;
6525 /* Routines to manipulate hash table of CUs. */
6527 htab_cu_hash (const void *of)
6529 const struct cu_hash_table_entry *const entry =
6530 (const struct cu_hash_table_entry *) of;
6532 return htab_hash_string (entry->cu->die_symbol);
6536 htab_cu_eq (const void *of1, const void *of2)
6538 const struct cu_hash_table_entry *const entry1 =
6539 (const struct cu_hash_table_entry *) of1;
6540 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6542 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6546 htab_cu_del (void *what)
6548 struct cu_hash_table_entry *next,
6549 *entry = (struct cu_hash_table_entry *) what;
6559 /* Check whether we have already seen this CU and set up SYM_NUM
6562 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6564 struct cu_hash_table_entry dummy;
6565 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6567 dummy.max_comdat_num = 0;
6569 slot = (struct cu_hash_table_entry **)
6570 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6574 for (; entry; last = entry, entry = entry->next)
6576 if (same_die_p_wrap (cu, entry->cu))
6582 *sym_num = entry->min_comdat_num;
6586 entry = XCNEW (struct cu_hash_table_entry);
6588 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6589 entry->next = *slot;
6595 /* Record SYM_NUM to record of CU in HTABLE. */
6597 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6599 struct cu_hash_table_entry **slot, *entry;
6601 slot = (struct cu_hash_table_entry **)
6602 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6606 entry->max_comdat_num = sym_num;
6609 /* Traverse the DIE (which is always comp_unit_die), and set up
6610 additional compilation units for each of the include files we see
6611 bracketed by BINCL/EINCL. */
6614 break_out_includes (dw_die_ref die)
6617 dw_die_ref unit = NULL;
6618 limbo_die_node *node, **pnode;
6619 htab_t cu_hash_table;
6623 dw_die_ref prev = c;
6625 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6626 || (unit && is_comdat_die (c)))
6628 dw_die_ref next = c->die_sib;
6630 /* This DIE is for a secondary CU; remove it from the main one. */
6631 remove_child_with_prev (c, prev);
6633 if (c->die_tag == DW_TAG_GNU_BINCL)
6634 unit = push_new_compile_unit (unit, c);
6635 else if (c->die_tag == DW_TAG_GNU_EINCL)
6636 unit = pop_compile_unit (unit);
6638 add_child_die (unit, c);
6640 if (c == die->die_child)
6643 } while (c != die->die_child);
6646 /* We can only use this in debugging, since the frontend doesn't check
6647 to make sure that we leave every include file we enter. */
6651 assign_symbol_names (die);
6652 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6653 for (node = limbo_die_list, pnode = &limbo_die_list;
6659 compute_section_prefix (node->die);
6660 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6661 &comdat_symbol_number);
6662 assign_symbol_names (node->die);
6664 *pnode = node->next;
6667 pnode = &node->next;
6668 record_comdat_symbol_number (node->die, cu_hash_table,
6669 comdat_symbol_number);
6672 htab_delete (cu_hash_table);
6675 /* Traverse the DIE and add a sibling attribute if it may have the
6676 effect of speeding up access to siblings. To save some space,
6677 avoid generating sibling attributes for DIE's without children. */
6680 add_sibling_attributes (dw_die_ref die)
6684 if (! die->die_child)
6687 if (die->die_parent && die != die->die_parent->die_child)
6688 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6690 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6693 /* Output all location lists for the DIE and its children. */
6696 output_location_lists (dw_die_ref die)
6702 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6703 if (AT_class (a) == dw_val_class_loc_list)
6704 output_loc_list (AT_loc_list (a));
6706 FOR_EACH_CHILD (die, c, output_location_lists (c));
6709 /* The format of each DIE (and its attribute value pairs) is encoded in an
6710 abbreviation table. This routine builds the abbreviation table and assigns
6711 a unique abbreviation id for each abbreviation entry. The children of each
6712 die are visited recursively. */
6715 build_abbrev_table (dw_die_ref die)
6717 unsigned long abbrev_id;
6718 unsigned int n_alloc;
6723 /* Scan the DIE references, and mark as external any that refer to
6724 DIEs from other CUs (i.e. those which are not marked). */
6725 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6726 if (AT_class (a) == dw_val_class_die_ref
6727 && AT_ref (a)->die_mark == 0)
6729 gcc_assert (AT_ref (a)->die_symbol);
6731 set_AT_ref_external (a, 1);
6734 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6736 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6737 dw_attr_ref die_a, abbrev_a;
6741 if (abbrev->die_tag != die->die_tag)
6743 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6746 if (VEC_length (dw_attr_node, abbrev->die_attr)
6747 != VEC_length (dw_attr_node, die->die_attr))
6750 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6752 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6753 if ((abbrev_a->dw_attr != die_a->dw_attr)
6754 || (value_format (abbrev_a) != value_format (die_a)))
6764 if (abbrev_id >= abbrev_die_table_in_use)
6766 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6768 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6769 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
6772 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6773 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6774 abbrev_die_table_allocated = n_alloc;
6777 ++abbrev_die_table_in_use;
6778 abbrev_die_table[abbrev_id] = die;
6781 die->die_abbrev = abbrev_id;
6782 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6785 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6788 constant_size (long unsigned int value)
6795 log = floor_log2 (value);
6798 log = 1 << (floor_log2 (log) + 1);
6803 /* Return the size of a DIE as it is represented in the
6804 .debug_info section. */
6806 static unsigned long
6807 size_of_die (dw_die_ref die)
6809 unsigned long size = 0;
6813 size += size_of_uleb128 (die->die_abbrev);
6814 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6816 switch (AT_class (a))
6818 case dw_val_class_addr:
6819 size += DWARF2_ADDR_SIZE;
6821 case dw_val_class_offset:
6822 size += DWARF_OFFSET_SIZE;
6824 case dw_val_class_loc:
6826 unsigned long lsize = size_of_locs (AT_loc (a));
6829 size += constant_size (lsize);
6833 case dw_val_class_loc_list:
6834 size += DWARF_OFFSET_SIZE;
6836 case dw_val_class_range_list:
6837 size += DWARF_OFFSET_SIZE;
6839 case dw_val_class_const:
6840 size += size_of_sleb128 (AT_int (a));
6842 case dw_val_class_unsigned_const:
6843 size += constant_size (AT_unsigned (a));
6845 case dw_val_class_long_long:
6846 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6848 case dw_val_class_vec:
6849 size += 1 + (a->dw_attr_val.v.val_vec.length
6850 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6852 case dw_val_class_flag:
6855 case dw_val_class_die_ref:
6856 if (AT_ref_external (a))
6857 size += DWARF2_ADDR_SIZE;
6859 size += DWARF_OFFSET_SIZE;
6861 case dw_val_class_fde_ref:
6862 size += DWARF_OFFSET_SIZE;
6864 case dw_val_class_lbl_id:
6865 size += DWARF2_ADDR_SIZE;
6867 case dw_val_class_lineptr:
6868 case dw_val_class_macptr:
6869 size += DWARF_OFFSET_SIZE;
6871 case dw_val_class_str:
6872 if (AT_string_form (a) == DW_FORM_strp)
6873 size += DWARF_OFFSET_SIZE;
6875 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6877 case dw_val_class_file:
6878 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6888 /* Size the debugging information associated with a given DIE. Visits the
6889 DIE's children recursively. Updates the global variable next_die_offset, on
6890 each time through. Uses the current value of next_die_offset to update the
6891 die_offset field in each DIE. */
6894 calc_die_sizes (dw_die_ref die)
6898 die->die_offset = next_die_offset;
6899 next_die_offset += size_of_die (die);
6901 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6903 if (die->die_child != NULL)
6904 /* Count the null byte used to terminate sibling lists. */
6905 next_die_offset += 1;
6908 /* Set the marks for a die and its children. We do this so
6909 that we know whether or not a reference needs to use FORM_ref_addr; only
6910 DIEs in the same CU will be marked. We used to clear out the offset
6911 and use that as the flag, but ran into ordering problems. */
6914 mark_dies (dw_die_ref die)
6918 gcc_assert (!die->die_mark);
6921 FOR_EACH_CHILD (die, c, mark_dies (c));
6924 /* Clear the marks for a die and its children. */
6927 unmark_dies (dw_die_ref die)
6931 gcc_assert (die->die_mark);
6934 FOR_EACH_CHILD (die, c, unmark_dies (c));
6937 /* Clear the marks for a die, its children and referred dies. */
6940 unmark_all_dies (dw_die_ref die)
6950 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6952 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6953 if (AT_class (a) == dw_val_class_die_ref)
6954 unmark_all_dies (AT_ref (a));
6957 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6958 generated for the compilation unit. */
6960 static unsigned long
6961 size_of_pubnames (VEC (pubname_entry, gc) * names)
6967 size = DWARF_PUBNAMES_HEADER_SIZE;
6968 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6969 if (names != pubtype_table
6970 || p->die->die_offset != 0
6971 || !flag_eliminate_unused_debug_types)
6972 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6974 size += DWARF_OFFSET_SIZE;
6978 /* Return the size of the information in the .debug_aranges section. */
6980 static unsigned long
6981 size_of_aranges (void)
6985 size = DWARF_ARANGES_HEADER_SIZE;
6987 /* Count the address/length pair for this compilation unit. */
6988 if (text_section_used)
6989 size += 2 * DWARF2_ADDR_SIZE;
6990 if (cold_text_section_used)
6991 size += 2 * DWARF2_ADDR_SIZE;
6992 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6994 /* Count the two zero words used to terminated the address range table. */
6995 size += 2 * DWARF2_ADDR_SIZE;
6999 /* Select the encoding of an attribute value. */
7001 static enum dwarf_form
7002 value_format (dw_attr_ref a)
7004 switch (a->dw_attr_val.val_class)
7006 case dw_val_class_addr:
7007 return DW_FORM_addr;
7008 case dw_val_class_range_list:
7009 case dw_val_class_offset:
7010 case dw_val_class_loc_list:
7011 switch (DWARF_OFFSET_SIZE)
7014 return DW_FORM_data4;
7016 return DW_FORM_data8;
7020 case dw_val_class_loc:
7021 switch (constant_size (size_of_locs (AT_loc (a))))
7024 return DW_FORM_block1;
7026 return DW_FORM_block2;
7030 case dw_val_class_const:
7031 return DW_FORM_sdata;
7032 case dw_val_class_unsigned_const:
7033 switch (constant_size (AT_unsigned (a)))
7036 return DW_FORM_data1;
7038 return DW_FORM_data2;
7040 return DW_FORM_data4;
7042 return DW_FORM_data8;
7046 case dw_val_class_long_long:
7047 return DW_FORM_block1;
7048 case dw_val_class_vec:
7049 return DW_FORM_block1;
7050 case dw_val_class_flag:
7051 return DW_FORM_flag;
7052 case dw_val_class_die_ref:
7053 if (AT_ref_external (a))
7054 return DW_FORM_ref_addr;
7057 case dw_val_class_fde_ref:
7058 return DW_FORM_data;
7059 case dw_val_class_lbl_id:
7060 return DW_FORM_addr;
7061 case dw_val_class_lineptr:
7062 case dw_val_class_macptr:
7063 return DW_FORM_data;
7064 case dw_val_class_str:
7065 return AT_string_form (a);
7066 case dw_val_class_file:
7067 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7070 return DW_FORM_data1;
7072 return DW_FORM_data2;
7074 return DW_FORM_data4;
7084 /* Output the encoding of an attribute value. */
7087 output_value_format (dw_attr_ref a)
7089 enum dwarf_form form = value_format (a);
7091 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7094 /* Output the .debug_abbrev section which defines the DIE abbreviation
7098 output_abbrev_section (void)
7100 unsigned long abbrev_id;
7102 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7104 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7108 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7109 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7110 dwarf_tag_name (abbrev->die_tag));
7112 if (abbrev->die_child != NULL)
7113 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7115 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7117 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7120 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7121 dwarf_attr_name (a_attr->dw_attr));
7122 output_value_format (a_attr);
7125 dw2_asm_output_data (1, 0, NULL);
7126 dw2_asm_output_data (1, 0, NULL);
7129 /* Terminate the table. */
7130 dw2_asm_output_data (1, 0, NULL);
7133 /* Output a symbol we can use to refer to this DIE from another CU. */
7136 output_die_symbol (dw_die_ref die)
7138 char *sym = die->die_symbol;
7143 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7144 /* We make these global, not weak; if the target doesn't support
7145 .linkonce, it doesn't support combining the sections, so debugging
7147 targetm.asm_out.globalize_label (asm_out_file, sym);
7149 ASM_OUTPUT_LABEL (asm_out_file, sym);
7152 /* Return a new location list, given the begin and end range, and the
7153 expression. gensym tells us whether to generate a new internal symbol for
7154 this location list node, which is done for the head of the list only. */
7156 static inline dw_loc_list_ref
7157 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7158 const char *section, unsigned int gensym)
7160 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7162 retlist->begin = begin;
7164 retlist->expr = expr;
7165 retlist->section = section;
7167 retlist->ll_symbol = gen_internal_sym ("LLST");
7172 /* Add a location description expression to a location list. */
7175 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7176 const char *begin, const char *end,
7177 const char *section)
7181 /* Find the end of the chain. */
7182 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7185 /* Add a new location list node to the list. */
7186 *d = new_loc_list (descr, begin, end, section, 0);
7189 /* Output the location list given to us. */
7192 output_loc_list (dw_loc_list_ref list_head)
7194 dw_loc_list_ref curr = list_head;
7196 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7198 /* Walk the location list, and output each range + expression. */
7199 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7202 /* Don't output an entry that starts and ends at the same address. */
7203 if (strcmp (curr->begin, curr->end) == 0)
7205 if (!have_multiple_function_sections)
7207 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7208 "Location list begin address (%s)",
7209 list_head->ll_symbol);
7210 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7211 "Location list end address (%s)",
7212 list_head->ll_symbol);
7216 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7217 "Location list begin address (%s)",
7218 list_head->ll_symbol);
7219 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7220 "Location list end address (%s)",
7221 list_head->ll_symbol);
7223 size = size_of_locs (curr->expr);
7225 /* Output the block length for this list of location operations. */
7226 gcc_assert (size <= 0xffff);
7227 dw2_asm_output_data (2, size, "%s", "Location expression size");
7229 output_loc_sequence (curr->expr);
7232 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7233 "Location list terminator begin (%s)",
7234 list_head->ll_symbol);
7235 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7236 "Location list terminator end (%s)",
7237 list_head->ll_symbol);
7240 /* Output the DIE and its attributes. Called recursively to generate
7241 the definitions of each child DIE. */
7244 output_die (dw_die_ref die)
7251 /* If someone in another CU might refer to us, set up a symbol for
7252 them to point to. */
7253 if (die->die_symbol)
7254 output_die_symbol (die);
7256 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7257 (unsigned long)die->die_offset,
7258 dwarf_tag_name (die->die_tag));
7260 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7262 const char *name = dwarf_attr_name (a->dw_attr);
7264 switch (AT_class (a))
7266 case dw_val_class_addr:
7267 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7270 case dw_val_class_offset:
7271 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7275 case dw_val_class_range_list:
7277 char *p = strchr (ranges_section_label, '\0');
7279 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7280 a->dw_attr_val.v.val_offset);
7281 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7282 debug_ranges_section, "%s", name);
7287 case dw_val_class_loc:
7288 size = size_of_locs (AT_loc (a));
7290 /* Output the block length for this list of location operations. */
7291 dw2_asm_output_data (constant_size (size), size, "%s", name);
7293 output_loc_sequence (AT_loc (a));
7296 case dw_val_class_const:
7297 /* ??? It would be slightly more efficient to use a scheme like is
7298 used for unsigned constants below, but gdb 4.x does not sign
7299 extend. Gdb 5.x does sign extend. */
7300 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7303 case dw_val_class_unsigned_const:
7304 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7305 AT_unsigned (a), "%s", name);
7308 case dw_val_class_long_long:
7310 unsigned HOST_WIDE_INT first, second;
7312 dw2_asm_output_data (1,
7313 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7316 if (WORDS_BIG_ENDIAN)
7318 first = a->dw_attr_val.v.val_long_long.hi;
7319 second = a->dw_attr_val.v.val_long_long.low;
7323 first = a->dw_attr_val.v.val_long_long.low;
7324 second = a->dw_attr_val.v.val_long_long.hi;
7327 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7328 first, "long long constant");
7329 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7334 case dw_val_class_vec:
7336 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7337 unsigned int len = a->dw_attr_val.v.val_vec.length;
7341 dw2_asm_output_data (1, len * elt_size, "%s", name);
7342 if (elt_size > sizeof (HOST_WIDE_INT))
7347 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7350 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7351 "fp or vector constant word %u", i);
7355 case dw_val_class_flag:
7356 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7359 case dw_val_class_loc_list:
7361 char *sym = AT_loc_list (a)->ll_symbol;
7364 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7369 case dw_val_class_die_ref:
7370 if (AT_ref_external (a))
7372 char *sym = AT_ref (a)->die_symbol;
7375 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7380 gcc_assert (AT_ref (a)->die_offset);
7381 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7386 case dw_val_class_fde_ref:
7390 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7391 a->dw_attr_val.v.val_fde_index * 2);
7392 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7397 case dw_val_class_lbl_id:
7398 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7401 case dw_val_class_lineptr:
7402 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7403 debug_line_section, "%s", name);
7406 case dw_val_class_macptr:
7407 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7408 debug_macinfo_section, "%s", name);
7411 case dw_val_class_str:
7412 if (AT_string_form (a) == DW_FORM_strp)
7413 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7414 a->dw_attr_val.v.val_str->label,
7416 "%s: \"%s\"", name, AT_string (a));
7418 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7421 case dw_val_class_file:
7423 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7425 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7426 a->dw_attr_val.v.val_file->filename);
7435 FOR_EACH_CHILD (die, c, output_die (c));
7437 /* Add null byte to terminate sibling list. */
7438 if (die->die_child != NULL)
7439 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7440 (unsigned long) die->die_offset);
7443 /* Output the compilation unit that appears at the beginning of the
7444 .debug_info section, and precedes the DIE descriptions. */
7447 output_compilation_unit_header (void)
7449 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7450 dw2_asm_output_data (4, 0xffffffff,
7451 "Initial length escape value indicating 64-bit DWARF extension");
7452 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7453 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7454 "Length of Compilation Unit Info");
7455 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7456 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7457 debug_abbrev_section,
7458 "Offset Into Abbrev. Section");
7459 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7462 /* Output the compilation unit DIE and its children. */
7465 output_comp_unit (dw_die_ref die, int output_if_empty)
7467 const char *secname;
7470 /* Unless we are outputting main CU, we may throw away empty ones. */
7471 if (!output_if_empty && die->die_child == NULL)
7474 /* Even if there are no children of this DIE, we must output the information
7475 about the compilation unit. Otherwise, on an empty translation unit, we
7476 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7477 will then complain when examining the file. First mark all the DIEs in
7478 this CU so we know which get local refs. */
7481 build_abbrev_table (die);
7483 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7484 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7485 calc_die_sizes (die);
7487 oldsym = die->die_symbol;
7490 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
7492 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7494 die->die_symbol = NULL;
7495 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7498 switch_to_section (debug_info_section);
7500 /* Output debugging information. */
7501 output_compilation_unit_header ();
7504 /* Leave the marks on the main CU, so we can check them in
7509 die->die_symbol = oldsym;
7513 /* Return the DWARF2/3 pubname associated with a decl. */
7516 dwarf2_name (tree decl, int scope)
7518 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7521 /* Add a new entry to .debug_pubnames if appropriate. */
7524 add_pubname_string (const char *str, dw_die_ref die)
7529 e.name = xstrdup (str);
7530 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7534 add_pubname (tree decl, dw_die_ref die)
7537 if (TREE_PUBLIC (decl))
7538 add_pubname_string (dwarf2_name (decl, 1), die);
7541 /* Add a new entry to .debug_pubtypes if appropriate. */
7544 add_pubtype (tree decl, dw_die_ref die)
7549 if ((TREE_PUBLIC (decl)
7550 || die->die_parent == comp_unit_die)
7551 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7556 if (TYPE_NAME (decl))
7558 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7559 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7560 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7561 && DECL_NAME (TYPE_NAME (decl)))
7562 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7564 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7568 e.name = xstrdup (dwarf2_name (decl, 1));
7570 /* If we don't have a name for the type, there's no point in adding
7572 if (e.name && e.name[0] != '\0')
7573 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7577 /* Output the public names table used to speed up access to externally
7578 visible names; or the public types table used to find type definitions. */
7581 output_pubnames (VEC (pubname_entry, gc) * names)
7584 unsigned long pubnames_length = size_of_pubnames (names);
7587 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7588 dw2_asm_output_data (4, 0xffffffff,
7589 "Initial length escape value indicating 64-bit DWARF extension");
7590 if (names == pubname_table)
7591 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7592 "Length of Public Names Info");
7594 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7595 "Length of Public Type Names Info");
7596 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7597 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7599 "Offset of Compilation Unit Info");
7600 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7601 "Compilation Unit Length");
7603 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7605 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7606 if (names == pubname_table)
7607 gcc_assert (pub->die->die_mark);
7609 if (names != pubtype_table
7610 || pub->die->die_offset != 0
7611 || !flag_eliminate_unused_debug_types)
7613 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7616 dw2_asm_output_nstring (pub->name, -1, "external name");
7620 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7623 /* Add a new entry to .debug_aranges if appropriate. */
7626 add_arange (tree decl, dw_die_ref die)
7628 if (! DECL_SECTION_NAME (decl))
7631 if (arange_table_in_use == arange_table_allocated)
7633 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7634 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
7635 arange_table_allocated);
7636 memset (arange_table + arange_table_in_use, 0,
7637 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7640 arange_table[arange_table_in_use++] = die;
7643 /* Output the information that goes into the .debug_aranges table.
7644 Namely, define the beginning and ending address range of the
7645 text section generated for this compilation unit. */
7648 output_aranges (void)
7651 unsigned long aranges_length = size_of_aranges ();
7653 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7654 dw2_asm_output_data (4, 0xffffffff,
7655 "Initial length escape value indicating 64-bit DWARF extension");
7656 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7657 "Length of Address Ranges Info");
7658 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7659 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7661 "Offset of Compilation Unit Info");
7662 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7663 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7665 /* We need to align to twice the pointer size here. */
7666 if (DWARF_ARANGES_PAD_SIZE)
7668 /* Pad using a 2 byte words so that padding is correct for any
7670 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7671 2 * DWARF2_ADDR_SIZE);
7672 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7673 dw2_asm_output_data (2, 0, NULL);
7676 /* It is necessary not to output these entries if the sections were
7677 not used; if the sections were not used, the length will be 0 and
7678 the address may end up as 0 if the section is discarded by ld
7679 --gc-sections, leaving an invalid (0, 0) entry that can be
7680 confused with the terminator. */
7681 if (text_section_used)
7683 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7684 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7685 text_section_label, "Length");
7687 if (cold_text_section_used)
7689 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7691 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7692 cold_text_section_label, "Length");
7695 for (i = 0; i < arange_table_in_use; i++)
7697 dw_die_ref die = arange_table[i];
7699 /* We shouldn't see aranges for DIEs outside of the main CU. */
7700 gcc_assert (die->die_mark);
7702 if (die->die_tag == DW_TAG_subprogram)
7704 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7706 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7707 get_AT_low_pc (die), "Length");
7711 /* A static variable; extract the symbol from DW_AT_location.
7712 Note that this code isn't currently hit, as we only emit
7713 aranges for functions (jason 9/23/99). */
7714 dw_attr_ref a = get_AT (die, DW_AT_location);
7715 dw_loc_descr_ref loc;
7717 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7720 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7722 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7723 loc->dw_loc_oprnd1.v.val_addr, "Address");
7724 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7725 get_AT_unsigned (die, DW_AT_byte_size),
7730 /* Output the terminator words. */
7731 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7732 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7735 /* Add a new entry to .debug_ranges. Return the offset at which it
7739 add_ranges_num (int num)
7741 unsigned int in_use = ranges_table_in_use;
7743 if (in_use == ranges_table_allocated)
7745 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7746 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
7747 ranges_table_allocated);
7748 memset (ranges_table + ranges_table_in_use, 0,
7749 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7752 ranges_table[in_use].num = num;
7753 ranges_table_in_use = in_use + 1;
7755 return in_use * 2 * DWARF2_ADDR_SIZE;
7758 /* Add a new entry to .debug_ranges corresponding to a block, or a
7759 range terminator if BLOCK is NULL. */
7762 add_ranges (const_tree block)
7764 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
7767 /* Add a new entry to .debug_ranges corresponding to a pair of
7771 add_ranges_by_labels (const char *begin, const char *end)
7773 unsigned int in_use = ranges_by_label_in_use;
7775 if (in_use == ranges_by_label_allocated)
7777 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
7778 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
7780 ranges_by_label_allocated);
7781 memset (ranges_by_label + ranges_by_label_in_use, 0,
7782 RANGES_TABLE_INCREMENT
7783 * sizeof (struct dw_ranges_by_label_struct));
7786 ranges_by_label[in_use].begin = begin;
7787 ranges_by_label[in_use].end = end;
7788 ranges_by_label_in_use = in_use + 1;
7790 return add_ranges_num (-(int)in_use - 1);
7794 output_ranges (void)
7797 static const char *const start_fmt = "Offset 0x%x";
7798 const char *fmt = start_fmt;
7800 for (i = 0; i < ranges_table_in_use; i++)
7802 int block_num = ranges_table[i].num;
7806 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7807 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7809 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7810 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7812 /* If all code is in the text section, then the compilation
7813 unit base address defaults to DW_AT_low_pc, which is the
7814 base of the text section. */
7815 if (!have_multiple_function_sections)
7817 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7819 fmt, i * 2 * DWARF2_ADDR_SIZE);
7820 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7821 text_section_label, NULL);
7824 /* Otherwise, the compilation unit base address is zero,
7825 which allows us to use absolute addresses, and not worry
7826 about whether the target supports cross-section
7830 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7831 fmt, i * 2 * DWARF2_ADDR_SIZE);
7832 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7838 /* Negative block_num stands for an index into ranges_by_label. */
7839 else if (block_num < 0)
7841 int lab_idx = - block_num - 1;
7843 if (!have_multiple_function_sections)
7847 /* If we ever use add_ranges_by_labels () for a single
7848 function section, all we have to do is to take out
7850 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7851 ranges_by_label[lab_idx].begin,
7853 fmt, i * 2 * DWARF2_ADDR_SIZE);
7854 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7855 ranges_by_label[lab_idx].end,
7856 text_section_label, NULL);
7861 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7862 ranges_by_label[lab_idx].begin,
7863 fmt, i * 2 * DWARF2_ADDR_SIZE);
7864 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7865 ranges_by_label[lab_idx].end,
7871 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7872 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7878 /* Data structure containing information about input files. */
7881 const char *path; /* Complete file name. */
7882 const char *fname; /* File name part. */
7883 int length; /* Length of entire string. */
7884 struct dwarf_file_data * file_idx; /* Index in input file table. */
7885 int dir_idx; /* Index in directory table. */
7888 /* Data structure containing information about directories with source
7892 const char *path; /* Path including directory name. */
7893 int length; /* Path length. */
7894 int prefix; /* Index of directory entry which is a prefix. */
7895 int count; /* Number of files in this directory. */
7896 int dir_idx; /* Index of directory used as base. */
7899 /* Callback function for file_info comparison. We sort by looking at
7900 the directories in the path. */
7903 file_info_cmp (const void *p1, const void *p2)
7905 const struct file_info *const s1 = (const struct file_info *) p1;
7906 const struct file_info *const s2 = (const struct file_info *) p2;
7907 const unsigned char *cp1;
7908 const unsigned char *cp2;
7910 /* Take care of file names without directories. We need to make sure that
7911 we return consistent values to qsort since some will get confused if
7912 we return the same value when identical operands are passed in opposite
7913 orders. So if neither has a directory, return 0 and otherwise return
7914 1 or -1 depending on which one has the directory. */
7915 if ((s1->path == s1->fname || s2->path == s2->fname))
7916 return (s2->path == s2->fname) - (s1->path == s1->fname);
7918 cp1 = (const unsigned char *) s1->path;
7919 cp2 = (const unsigned char *) s2->path;
7925 /* Reached the end of the first path? If so, handle like above. */
7926 if ((cp1 == (const unsigned char *) s1->fname)
7927 || (cp2 == (const unsigned char *) s2->fname))
7928 return ((cp2 == (const unsigned char *) s2->fname)
7929 - (cp1 == (const unsigned char *) s1->fname));
7931 /* Character of current path component the same? */
7932 else if (*cp1 != *cp2)
7937 struct file_name_acquire_data
7939 struct file_info *files;
7944 /* Traversal function for the hash table. */
7947 file_name_acquire (void ** slot, void *data)
7949 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
7950 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
7951 struct file_info *fi;
7954 gcc_assert (fnad->max_files >= d->emitted_number);
7956 if (! d->emitted_number)
7959 gcc_assert (fnad->max_files != fnad->used_files);
7961 fi = fnad->files + fnad->used_files++;
7963 /* Skip all leading "./". */
7965 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7968 /* Create a new array entry. */
7970 fi->length = strlen (f);
7973 /* Search for the file name part. */
7974 f = strrchr (f, DIR_SEPARATOR);
7975 #if defined (DIR_SEPARATOR_2)
7977 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7981 if (f == NULL || f < g)
7987 fi->fname = f == NULL ? fi->path : f + 1;
7991 /* Output the directory table and the file name table. We try to minimize
7992 the total amount of memory needed. A heuristic is used to avoid large
7993 slowdowns with many input files. */
7996 output_file_names (void)
7998 struct file_name_acquire_data fnad;
8000 struct file_info *files;
8001 struct dir_info *dirs;
8010 if (!last_emitted_file)
8012 dw2_asm_output_data (1, 0, "End directory table");
8013 dw2_asm_output_data (1, 0, "End file name table");
8017 numfiles = last_emitted_file->emitted_number;
8019 /* Allocate the various arrays we need. */
8020 files = XALLOCAVEC (struct file_info, numfiles);
8021 dirs = XALLOCAVEC (struct dir_info, numfiles);
8024 fnad.used_files = 0;
8025 fnad.max_files = numfiles;
8026 htab_traverse (file_table, file_name_acquire, &fnad);
8027 gcc_assert (fnad.used_files == fnad.max_files);
8029 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8031 /* Find all the different directories used. */
8032 dirs[0].path = files[0].path;
8033 dirs[0].length = files[0].fname - files[0].path;
8034 dirs[0].prefix = -1;
8036 dirs[0].dir_idx = 0;
8037 files[0].dir_idx = 0;
8040 for (i = 1; i < numfiles; i++)
8041 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8042 && memcmp (dirs[ndirs - 1].path, files[i].path,
8043 dirs[ndirs - 1].length) == 0)
8045 /* Same directory as last entry. */
8046 files[i].dir_idx = ndirs - 1;
8047 ++dirs[ndirs - 1].count;
8053 /* This is a new directory. */
8054 dirs[ndirs].path = files[i].path;
8055 dirs[ndirs].length = files[i].fname - files[i].path;
8056 dirs[ndirs].count = 1;
8057 dirs[ndirs].dir_idx = ndirs;
8058 files[i].dir_idx = ndirs;
8060 /* Search for a prefix. */
8061 dirs[ndirs].prefix = -1;
8062 for (j = 0; j < ndirs; j++)
8063 if (dirs[j].length < dirs[ndirs].length
8064 && dirs[j].length > 1
8065 && (dirs[ndirs].prefix == -1
8066 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8067 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8068 dirs[ndirs].prefix = j;
8073 /* Now to the actual work. We have to find a subset of the directories which
8074 allow expressing the file name using references to the directory table
8075 with the least amount of characters. We do not do an exhaustive search
8076 where we would have to check out every combination of every single
8077 possible prefix. Instead we use a heuristic which provides nearly optimal
8078 results in most cases and never is much off. */
8079 saved = XALLOCAVEC (int, ndirs);
8080 savehere = XALLOCAVEC (int, ndirs);
8082 memset (saved, '\0', ndirs * sizeof (saved[0]));
8083 for (i = 0; i < ndirs; i++)
8088 /* We can always save some space for the current directory. But this
8089 does not mean it will be enough to justify adding the directory. */
8090 savehere[i] = dirs[i].length;
8091 total = (savehere[i] - saved[i]) * dirs[i].count;
8093 for (j = i + 1; j < ndirs; j++)
8096 if (saved[j] < dirs[i].length)
8098 /* Determine whether the dirs[i] path is a prefix of the
8103 while (k != -1 && k != (int) i)
8108 /* Yes it is. We can possibly save some memory by
8109 writing the filenames in dirs[j] relative to
8111 savehere[j] = dirs[i].length;
8112 total += (savehere[j] - saved[j]) * dirs[j].count;
8117 /* Check whether we can save enough to justify adding the dirs[i]
8119 if (total > dirs[i].length + 1)
8121 /* It's worthwhile adding. */
8122 for (j = i; j < ndirs; j++)
8123 if (savehere[j] > 0)
8125 /* Remember how much we saved for this directory so far. */
8126 saved[j] = savehere[j];
8128 /* Remember the prefix directory. */
8129 dirs[j].dir_idx = i;
8134 /* Emit the directory name table. */
8136 idx_offset = dirs[0].length > 0 ? 1 : 0;
8137 for (i = 1 - idx_offset; i < ndirs; i++)
8138 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8139 "Directory Entry: 0x%x", i + idx_offset);
8141 dw2_asm_output_data (1, 0, "End directory table");
8143 /* We have to emit them in the order of emitted_number since that's
8144 used in the debug info generation. To do this efficiently we
8145 generate a back-mapping of the indices first. */
8146 backmap = XALLOCAVEC (int, numfiles);
8147 for (i = 0; i < numfiles; i++)
8148 backmap[files[i].file_idx->emitted_number - 1] = i;
8150 /* Now write all the file names. */
8151 for (i = 0; i < numfiles; i++)
8153 int file_idx = backmap[i];
8154 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8156 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8157 "File Entry: 0x%x", (unsigned) i + 1);
8159 /* Include directory index. */
8160 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8162 /* Modification time. */
8163 dw2_asm_output_data_uleb128 (0, NULL);
8165 /* File length in bytes. */
8166 dw2_asm_output_data_uleb128 (0, NULL);
8169 dw2_asm_output_data (1, 0, "End file name table");
8173 /* Output the source line number correspondence information. This
8174 information goes into the .debug_line section. */
8177 output_line_info (void)
8179 char l1[20], l2[20], p1[20], p2[20];
8180 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8181 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8184 unsigned long lt_index;
8185 unsigned long current_line;
8188 unsigned long current_file;
8189 unsigned long function;
8191 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8192 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8193 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8194 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8196 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8197 dw2_asm_output_data (4, 0xffffffff,
8198 "Initial length escape value indicating 64-bit DWARF extension");
8199 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8200 "Length of Source Line Info");
8201 ASM_OUTPUT_LABEL (asm_out_file, l1);
8203 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8204 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8205 ASM_OUTPUT_LABEL (asm_out_file, p1);
8207 /* Define the architecture-dependent minimum instruction length (in
8208 bytes). In this implementation of DWARF, this field is used for
8209 information purposes only. Since GCC generates assembly language,
8210 we have no a priori knowledge of how many instruction bytes are
8211 generated for each source line, and therefore can use only the
8212 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8213 commands. Accordingly, we fix this as `1', which is "correct
8214 enough" for all architectures, and don't let the target override. */
8215 dw2_asm_output_data (1, 1,
8216 "Minimum Instruction Length");
8218 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8219 "Default is_stmt_start flag");
8220 dw2_asm_output_data (1, DWARF_LINE_BASE,
8221 "Line Base Value (Special Opcodes)");
8222 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8223 "Line Range Value (Special Opcodes)");
8224 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8225 "Special Opcode Base");
8227 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8231 case DW_LNS_advance_pc:
8232 case DW_LNS_advance_line:
8233 case DW_LNS_set_file:
8234 case DW_LNS_set_column:
8235 case DW_LNS_fixed_advance_pc:
8243 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8247 /* Write out the information about the files we use. */
8248 output_file_names ();
8249 ASM_OUTPUT_LABEL (asm_out_file, p2);
8251 /* We used to set the address register to the first location in the text
8252 section here, but that didn't accomplish anything since we already
8253 have a line note for the opening brace of the first function. */
8255 /* Generate the line number to PC correspondence table, encoded as
8256 a series of state machine operations. */
8260 if (cfun && in_cold_section_p)
8261 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8263 strcpy (prev_line_label, text_section_label);
8264 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8266 dw_line_info_ref line_info = &line_info_table[lt_index];
8269 /* Disable this optimization for now; GDB wants to see two line notes
8270 at the beginning of a function so it can find the end of the
8273 /* Don't emit anything for redundant notes. Just updating the
8274 address doesn't accomplish anything, because we already assume
8275 that anything after the last address is this line. */
8276 if (line_info->dw_line_num == current_line
8277 && line_info->dw_file_num == current_file)
8281 /* Emit debug info for the address of the current line.
8283 Unfortunately, we have little choice here currently, and must always
8284 use the most general form. GCC does not know the address delta
8285 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8286 attributes which will give an upper bound on the address range. We
8287 could perhaps use length attributes to determine when it is safe to
8288 use DW_LNS_fixed_advance_pc. */
8290 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8293 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8294 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8295 "DW_LNS_fixed_advance_pc");
8296 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8300 /* This can handle any delta. This takes
8301 4+DWARF2_ADDR_SIZE bytes. */
8302 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8303 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8304 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8305 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8308 strcpy (prev_line_label, line_label);
8310 /* Emit debug info for the source file of the current line, if
8311 different from the previous line. */
8312 if (line_info->dw_file_num != current_file)
8314 current_file = line_info->dw_file_num;
8315 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8316 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8319 /* Emit debug info for the current line number, choosing the encoding
8320 that uses the least amount of space. */
8321 if (line_info->dw_line_num != current_line)
8323 line_offset = line_info->dw_line_num - current_line;
8324 line_delta = line_offset - DWARF_LINE_BASE;
8325 current_line = line_info->dw_line_num;
8326 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8327 /* This can handle deltas from -10 to 234, using the current
8328 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8330 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8331 "line %lu", current_line);
8334 /* This can handle any delta. This takes at least 4 bytes,
8335 depending on the value being encoded. */
8336 dw2_asm_output_data (1, DW_LNS_advance_line,
8337 "advance to line %lu", current_line);
8338 dw2_asm_output_data_sleb128 (line_offset, NULL);
8339 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8343 /* We still need to start a new row, so output a copy insn. */
8344 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8347 /* Emit debug info for the address of the end of the function. */
8350 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8351 "DW_LNS_fixed_advance_pc");
8352 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8356 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8357 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8358 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8359 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8362 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8363 dw2_asm_output_data_uleb128 (1, NULL);
8364 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8369 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8371 dw_separate_line_info_ref line_info
8372 = &separate_line_info_table[lt_index];
8375 /* Don't emit anything for redundant notes. */
8376 if (line_info->dw_line_num == current_line
8377 && line_info->dw_file_num == current_file
8378 && line_info->function == function)
8382 /* Emit debug info for the address of the current line. If this is
8383 a new function, or the first line of a function, then we need
8384 to handle it differently. */
8385 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8387 if (function != line_info->function)
8389 function = line_info->function;
8391 /* Set the address register to the first line in the function. */
8392 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8393 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8394 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8395 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8399 /* ??? See the DW_LNS_advance_pc comment above. */
8402 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8403 "DW_LNS_fixed_advance_pc");
8404 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8408 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8409 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8410 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8415 strcpy (prev_line_label, line_label);
8417 /* Emit debug info for the source file of the current line, if
8418 different from the previous line. */
8419 if (line_info->dw_file_num != current_file)
8421 current_file = line_info->dw_file_num;
8422 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8423 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8426 /* Emit debug info for the current line number, choosing the encoding
8427 that uses the least amount of space. */
8428 if (line_info->dw_line_num != current_line)
8430 line_offset = line_info->dw_line_num - current_line;
8431 line_delta = line_offset - DWARF_LINE_BASE;
8432 current_line = line_info->dw_line_num;
8433 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8434 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8435 "line %lu", current_line);
8438 dw2_asm_output_data (1, DW_LNS_advance_line,
8439 "advance to line %lu", current_line);
8440 dw2_asm_output_data_sleb128 (line_offset, NULL);
8441 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8445 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8453 /* If we're done with a function, end its sequence. */
8454 if (lt_index == separate_line_info_table_in_use
8455 || separate_line_info_table[lt_index].function != function)
8460 /* Emit debug info for the address of the end of the function. */
8461 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8464 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8465 "DW_LNS_fixed_advance_pc");
8466 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8470 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8471 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8472 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8473 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8476 /* Output the marker for the end of this sequence. */
8477 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8478 dw2_asm_output_data_uleb128 (1, NULL);
8479 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8483 /* Output the marker for the end of the line number info. */
8484 ASM_OUTPUT_LABEL (asm_out_file, l2);
8487 /* Given a pointer to a tree node for some base type, return a pointer to
8488 a DIE that describes the given type.
8490 This routine must only be called for GCC type nodes that correspond to
8491 Dwarf base (fundamental) types. */
8494 base_type_die (tree type)
8496 dw_die_ref base_type_result;
8497 enum dwarf_type encoding;
8499 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8502 switch (TREE_CODE (type))
8505 if (TYPE_STRING_FLAG (type))
8507 if (TYPE_UNSIGNED (type))
8508 encoding = DW_ATE_unsigned_char;
8510 encoding = DW_ATE_signed_char;
8512 else if (TYPE_UNSIGNED (type))
8513 encoding = DW_ATE_unsigned;
8515 encoding = DW_ATE_signed;
8519 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8520 encoding = DW_ATE_decimal_float;
8522 encoding = DW_ATE_float;
8525 case FIXED_POINT_TYPE:
8526 if (TYPE_UNSIGNED (type))
8527 encoding = DW_ATE_unsigned_fixed;
8529 encoding = DW_ATE_signed_fixed;
8532 /* Dwarf2 doesn't know anything about complex ints, so use
8533 a user defined type for it. */
8535 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8536 encoding = DW_ATE_complex_float;
8538 encoding = DW_ATE_lo_user;
8542 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8543 encoding = DW_ATE_boolean;
8547 /* No other TREE_CODEs are Dwarf fundamental types. */
8551 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8553 /* This probably indicates a bug. */
8554 if (! TYPE_NAME (type))
8555 add_name_attribute (base_type_result, "__unknown__");
8557 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8558 int_size_in_bytes (type));
8559 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8561 return base_type_result;
8564 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8565 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8568 is_base_type (tree type)
8570 switch (TREE_CODE (type))
8576 case FIXED_POINT_TYPE:
8584 case QUAL_UNION_TYPE:
8589 case REFERENCE_TYPE:
8602 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8603 node, return the size in bits for the type if it is a constant, or else
8604 return the alignment for the type if the type's size is not constant, or
8605 else return BITS_PER_WORD if the type actually turns out to be an
8608 static inline unsigned HOST_WIDE_INT
8609 simple_type_size_in_bits (const_tree type)
8611 if (TREE_CODE (type) == ERROR_MARK)
8612 return BITS_PER_WORD;
8613 else if (TYPE_SIZE (type) == NULL_TREE)
8615 else if (host_integerp (TYPE_SIZE (type), 1))
8616 return tree_low_cst (TYPE_SIZE (type), 1);
8618 return TYPE_ALIGN (type);
8621 /* Return true if the debug information for the given type should be
8622 emitted as a subrange type. */
8625 is_subrange_type (const_tree type)
8627 tree subtype = TREE_TYPE (type);
8629 /* Subrange types are identified by the fact that they are integer
8630 types, and that they have a subtype which is either an integer type
8631 or an enumeral type. */
8633 if (TREE_CODE (type) != INTEGER_TYPE
8634 || subtype == NULL_TREE)
8637 if (TREE_CODE (subtype) != INTEGER_TYPE
8638 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8641 if (TREE_CODE (type) == TREE_CODE (subtype)
8642 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8643 && TYPE_MIN_VALUE (type) != NULL
8644 && TYPE_MIN_VALUE (subtype) != NULL
8645 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8646 && TYPE_MAX_VALUE (type) != NULL
8647 && TYPE_MAX_VALUE (subtype) != NULL
8648 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8650 /* The type and its subtype have the same representation. If in
8651 addition the two types also have the same name, then the given
8652 type is not a subrange type, but rather a plain base type. */
8653 /* FIXME: brobecker/2004-03-22:
8654 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8655 therefore be sufficient to check the TYPE_SIZE node pointers
8656 rather than checking the actual size. Unfortunately, we have
8657 found some cases, such as in the Ada "integer" type, where
8658 this is not the case. Until this problem is solved, we need to
8659 keep checking the actual size. */
8660 tree type_name = TYPE_NAME (type);
8661 tree subtype_name = TYPE_NAME (subtype);
8663 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8664 type_name = DECL_NAME (type_name);
8666 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8667 subtype_name = DECL_NAME (subtype_name);
8669 if (type_name == subtype_name)
8676 /* Given a pointer to a tree node for a subrange type, return a pointer
8677 to a DIE that describes the given type. */
8680 subrange_type_die (tree type, dw_die_ref context_die)
8682 dw_die_ref subrange_die;
8683 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8685 if (context_die == NULL)
8686 context_die = comp_unit_die;
8688 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8690 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8692 /* The size of the subrange type and its base type do not match,
8693 so we need to generate a size attribute for the subrange type. */
8694 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8697 if (TYPE_MIN_VALUE (type) != NULL)
8698 add_bound_info (subrange_die, DW_AT_lower_bound,
8699 TYPE_MIN_VALUE (type));
8700 if (TYPE_MAX_VALUE (type) != NULL)
8701 add_bound_info (subrange_die, DW_AT_upper_bound,
8702 TYPE_MAX_VALUE (type));
8704 return subrange_die;
8707 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8708 entry that chains various modifiers in front of the given type. */
8711 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8712 dw_die_ref context_die)
8714 enum tree_code code = TREE_CODE (type);
8715 dw_die_ref mod_type_die;
8716 dw_die_ref sub_die = NULL;
8717 tree item_type = NULL;
8718 tree qualified_type;
8721 if (code == ERROR_MARK)
8724 /* See if we already have the appropriately qualified variant of
8727 = get_qualified_type (type,
8728 ((is_const_type ? TYPE_QUAL_CONST : 0)
8729 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8731 /* If we do, then we can just use its DIE, if it exists. */
8734 mod_type_die = lookup_type_die (qualified_type);
8736 return mod_type_die;
8739 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8741 /* Handle C typedef types. */
8742 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8744 tree dtype = TREE_TYPE (name);
8746 if (qualified_type == dtype)
8748 /* For a named type, use the typedef. */
8749 gen_type_die (qualified_type, context_die);
8750 return lookup_type_die (qualified_type);
8752 else if (is_const_type < TYPE_READONLY (dtype)
8753 || is_volatile_type < TYPE_VOLATILE (dtype)
8754 || (is_const_type <= TYPE_READONLY (dtype)
8755 && is_volatile_type <= TYPE_VOLATILE (dtype)
8756 && DECL_ORIGINAL_TYPE (name) != type))
8757 /* cv-unqualified version of named type. Just use the unnamed
8758 type to which it refers. */
8759 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8760 is_const_type, is_volatile_type,
8762 /* Else cv-qualified version of named type; fall through. */
8767 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8768 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8770 else if (is_volatile_type)
8772 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8773 sub_die = modified_type_die (type, 0, 0, context_die);
8775 else if (code == POINTER_TYPE)
8777 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8778 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8779 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8780 item_type = TREE_TYPE (type);
8782 else if (code == REFERENCE_TYPE)
8784 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8785 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8786 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8787 item_type = TREE_TYPE (type);
8789 else if (is_subrange_type (type))
8791 mod_type_die = subrange_type_die (type, context_die);
8792 item_type = TREE_TYPE (type);
8794 else if (is_base_type (type))
8795 mod_type_die = base_type_die (type);
8798 gen_type_die (type, context_die);
8800 /* We have to get the type_main_variant here (and pass that to the
8801 `lookup_type_die' routine) because the ..._TYPE node we have
8802 might simply be a *copy* of some original type node (where the
8803 copy was created to help us keep track of typedef names) and
8804 that copy might have a different TYPE_UID from the original
8806 if (TREE_CODE (type) != VECTOR_TYPE)
8807 return lookup_type_die (type_main_variant (type));
8809 /* Vectors have the debugging information in the type,
8810 not the main variant. */
8811 return lookup_type_die (type);
8814 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8815 don't output a DW_TAG_typedef, since there isn't one in the
8816 user's program; just attach a DW_AT_name to the type. */
8818 && (TREE_CODE (name) != TYPE_DECL
8819 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
8821 if (TREE_CODE (name) == TYPE_DECL)
8822 /* Could just call add_name_and_src_coords_attributes here,
8823 but since this is a builtin type it doesn't have any
8824 useful source coordinates anyway. */
8825 name = DECL_NAME (name);
8826 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8830 equate_type_number_to_die (qualified_type, mod_type_die);
8833 /* We must do this after the equate_type_number_to_die call, in case
8834 this is a recursive type. This ensures that the modified_type_die
8835 recursion will terminate even if the type is recursive. Recursive
8836 types are possible in Ada. */
8837 sub_die = modified_type_die (item_type,
8838 TYPE_READONLY (item_type),
8839 TYPE_VOLATILE (item_type),
8842 if (sub_die != NULL)
8843 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8845 return mod_type_die;
8848 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8849 an enumerated type. */
8852 type_is_enum (const_tree type)
8854 return TREE_CODE (type) == ENUMERAL_TYPE;
8857 /* Return the DBX register number described by a given RTL node. */
8860 dbx_reg_number (const_rtx rtl)
8862 unsigned regno = REGNO (rtl);
8864 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8866 #ifdef LEAF_REG_REMAP
8867 if (current_function_uses_only_leaf_regs)
8869 int leaf_reg = LEAF_REG_REMAP (regno);
8871 regno = (unsigned) leaf_reg;
8875 return DBX_REGISTER_NUMBER (regno);
8878 /* Optionally add a DW_OP_piece term to a location description expression.
8879 DW_OP_piece is only added if the location description expression already
8880 doesn't end with DW_OP_piece. */
8883 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8885 dw_loc_descr_ref loc;
8887 if (*list_head != NULL)
8889 /* Find the end of the chain. */
8890 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8893 if (loc->dw_loc_opc != DW_OP_piece)
8894 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8898 /* Return a location descriptor that designates a machine register or
8899 zero if there is none. */
8901 static dw_loc_descr_ref
8902 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
8906 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8909 regs = targetm.dwarf_register_span (rtl);
8911 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8912 return multiple_reg_loc_descriptor (rtl, regs, initialized);
8914 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
8917 /* Return a location descriptor that designates a machine register for
8918 a given hard register number. */
8920 static dw_loc_descr_ref
8921 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
8923 dw_loc_descr_ref reg_loc_descr;
8925 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8927 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
8929 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8930 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8932 return reg_loc_descr;
8935 /* Given an RTL of a register, return a location descriptor that
8936 designates a value that spans more than one register. */
8938 static dw_loc_descr_ref
8939 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
8940 enum var_init_status initialized)
8944 dw_loc_descr_ref loc_result = NULL;
8947 #ifdef LEAF_REG_REMAP
8948 if (current_function_uses_only_leaf_regs)
8950 int leaf_reg = LEAF_REG_REMAP (reg);
8952 reg = (unsigned) leaf_reg;
8955 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8956 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8958 /* Simple, contiguous registers. */
8959 if (regs == NULL_RTX)
8961 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8968 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
8969 VAR_INIT_STATUS_INITIALIZED);
8970 add_loc_descr (&loc_result, t);
8971 add_loc_descr_op_piece (&loc_result, size);
8977 /* Now onto stupid register sets in non contiguous locations. */
8979 gcc_assert (GET_CODE (regs) == PARALLEL);
8981 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8984 for (i = 0; i < XVECLEN (regs, 0); ++i)
8988 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
8989 VAR_INIT_STATUS_INITIALIZED);
8990 add_loc_descr (&loc_result, t);
8991 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8992 add_loc_descr_op_piece (&loc_result, size);
8995 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8996 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9000 /* Return a location descriptor that designates a constant. */
9002 static dw_loc_descr_ref
9003 int_loc_descriptor (HOST_WIDE_INT i)
9005 enum dwarf_location_atom op;
9007 /* Pick the smallest representation of a constant, rather than just
9008 defaulting to the LEB encoding. */
9012 op = DW_OP_lit0 + i;
9015 else if (i <= 0xffff)
9017 else if (HOST_BITS_PER_WIDE_INT == 32
9027 else if (i >= -0x8000)
9029 else if (HOST_BITS_PER_WIDE_INT == 32
9030 || i >= -0x80000000)
9036 return new_loc_descr (op, i, 0);
9039 /* Return a location descriptor that designates a base+offset location. */
9041 static dw_loc_descr_ref
9042 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9043 enum var_init_status initialized)
9046 dw_loc_descr_ref result;
9048 /* We only use "frame base" when we're sure we're talking about the
9049 post-prologue local stack frame. We do this by *not* running
9050 register elimination until this point, and recognizing the special
9051 argument pointer and soft frame pointer rtx's. */
9052 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9054 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9058 if (GET_CODE (elim) == PLUS)
9060 offset += INTVAL (XEXP (elim, 1));
9061 elim = XEXP (elim, 0);
9063 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
9064 : stack_pointer_rtx));
9065 offset += frame_pointer_fb_offset;
9067 return new_loc_descr (DW_OP_fbreg, offset, 0);
9071 regno = dbx_reg_number (reg);
9073 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9075 result = new_loc_descr (DW_OP_bregx, regno, offset);
9077 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9078 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9083 /* Return true if this RTL expression describes a base+offset calculation. */
9086 is_based_loc (const_rtx rtl)
9088 return (GET_CODE (rtl) == PLUS
9089 && ((REG_P (XEXP (rtl, 0))
9090 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9091 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9094 /* Return a descriptor that describes the concatenation of N locations
9095 used to form the address of a memory location. */
9097 static dw_loc_descr_ref
9098 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9099 enum var_init_status initialized)
9102 dw_loc_descr_ref cc_loc_result = NULL;
9103 unsigned int n = XVECLEN (concatn, 0);
9105 for (i = 0; i < n; ++i)
9107 dw_loc_descr_ref ref;
9108 rtx x = XVECEXP (concatn, 0, i);
9110 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9114 add_loc_descr (&cc_loc_result, ref);
9115 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9118 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9119 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9121 return cc_loc_result;
9124 /* The following routine converts the RTL for a variable or parameter
9125 (resident in memory) into an equivalent Dwarf representation of a
9126 mechanism for getting the address of that same variable onto the top of a
9127 hypothetical "address evaluation" stack.
9129 When creating memory location descriptors, we are effectively transforming
9130 the RTL for a memory-resident object into its Dwarf postfix expression
9131 equivalent. This routine recursively descends an RTL tree, turning
9132 it into Dwarf postfix code as it goes.
9134 MODE is the mode of the memory reference, needed to handle some
9135 autoincrement addressing modes.
9137 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9138 location list for RTL.
9140 Return 0 if we can't represent the location. */
9142 static dw_loc_descr_ref
9143 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9144 enum var_init_status initialized)
9146 dw_loc_descr_ref mem_loc_result = NULL;
9147 enum dwarf_location_atom op;
9149 /* Note that for a dynamically sized array, the location we will generate a
9150 description of here will be the lowest numbered location which is
9151 actually within the array. That's *not* necessarily the same as the
9152 zeroth element of the array. */
9154 rtl = targetm.delegitimize_address (rtl);
9156 switch (GET_CODE (rtl))
9161 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9162 just fall into the SUBREG code. */
9164 /* ... fall through ... */
9167 /* The case of a subreg may arise when we have a local (register)
9168 variable or a formal (register) parameter which doesn't quite fill
9169 up an entire register. For now, just assume that it is
9170 legitimate to make the Dwarf info refer to the whole register which
9171 contains the given subreg. */
9172 rtl = XEXP (rtl, 0);
9174 /* ... fall through ... */
9177 /* Whenever a register number forms a part of the description of the
9178 method for calculating the (dynamic) address of a memory resident
9179 object, DWARF rules require the register number be referred to as
9180 a "base register". This distinction is not based in any way upon
9181 what category of register the hardware believes the given register
9182 belongs to. This is strictly DWARF terminology we're dealing with
9183 here. Note that in cases where the location of a memory-resident
9184 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9185 OP_CONST (0)) the actual DWARF location descriptor that we generate
9186 may just be OP_BASEREG (basereg). This may look deceptively like
9187 the object in question was allocated to a register (rather than in
9188 memory) so DWARF consumers need to be aware of the subtle
9189 distinction between OP_REG and OP_BASEREG. */
9190 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9191 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9195 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9196 VAR_INIT_STATUS_INITIALIZED);
9197 if (mem_loc_result != 0)
9198 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9202 rtl = XEXP (rtl, 1);
9204 /* ... fall through ... */
9207 /* Some ports can transform a symbol ref into a label ref, because
9208 the symbol ref is too far away and has to be dumped into a constant
9212 /* Alternatively, the symbol in the constant pool might be referenced
9213 by a different symbol. */
9214 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9217 rtx tmp = get_pool_constant_mark (rtl, &marked);
9219 if (GET_CODE (tmp) == SYMBOL_REF)
9222 if (CONSTANT_POOL_ADDRESS_P (tmp))
9223 get_pool_constant_mark (tmp, &marked);
9228 /* If all references to this pool constant were optimized away,
9229 it was not output and thus we can't represent it.
9230 FIXME: might try to use DW_OP_const_value here, though
9231 DW_OP_piece complicates it. */
9236 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9237 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9238 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9239 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9243 /* Extract the PLUS expression nested inside and fall into
9245 rtl = XEXP (rtl, 1);
9250 /* Turn these into a PLUS expression and fall into the PLUS code
9252 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9253 GEN_INT (GET_CODE (rtl) == PRE_INC
9254 ? GET_MODE_UNIT_SIZE (mode)
9255 : -GET_MODE_UNIT_SIZE (mode)));
9257 /* ... fall through ... */
9261 if (is_based_loc (rtl))
9262 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9263 INTVAL (XEXP (rtl, 1)),
9264 VAR_INIT_STATUS_INITIALIZED);
9267 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9268 VAR_INIT_STATUS_INITIALIZED);
9269 if (mem_loc_result == 0)
9272 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9273 && INTVAL (XEXP (rtl, 1)) >= 0)
9274 add_loc_descr (&mem_loc_result,
9275 new_loc_descr (DW_OP_plus_uconst,
9276 INTVAL (XEXP (rtl, 1)), 0));
9279 add_loc_descr (&mem_loc_result,
9280 mem_loc_descriptor (XEXP (rtl, 1), mode,
9281 VAR_INIT_STATUS_INITIALIZED));
9282 add_loc_descr (&mem_loc_result,
9283 new_loc_descr (DW_OP_plus, 0, 0));
9288 /* If a pseudo-reg is optimized away, it is possible for it to
9289 be replaced with a MEM containing a multiply or shift. */
9308 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9309 VAR_INIT_STATUS_INITIALIZED);
9310 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9311 VAR_INIT_STATUS_INITIALIZED);
9313 if (op0 == 0 || op1 == 0)
9316 mem_loc_result = op0;
9317 add_loc_descr (&mem_loc_result, op1);
9318 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9323 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9327 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9328 VAR_INIT_STATUS_INITIALIZED);
9335 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9336 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9338 return mem_loc_result;
9341 /* Return a descriptor that describes the concatenation of two locations.
9342 This is typically a complex variable. */
9344 static dw_loc_descr_ref
9345 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9347 dw_loc_descr_ref cc_loc_result = NULL;
9348 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9349 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9351 if (x0_ref == 0 || x1_ref == 0)
9354 cc_loc_result = x0_ref;
9355 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9357 add_loc_descr (&cc_loc_result, x1_ref);
9358 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9360 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9361 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9363 return cc_loc_result;
9366 /* Return a descriptor that describes the concatenation of N
9369 static dw_loc_descr_ref
9370 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9373 dw_loc_descr_ref cc_loc_result = NULL;
9374 unsigned int n = XVECLEN (concatn, 0);
9376 for (i = 0; i < n; ++i)
9378 dw_loc_descr_ref ref;
9379 rtx x = XVECEXP (concatn, 0, i);
9381 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9385 add_loc_descr (&cc_loc_result, ref);
9386 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9389 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9390 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9392 return cc_loc_result;
9395 /* Output a proper Dwarf location descriptor for a variable or parameter
9396 which is either allocated in a register or in a memory location. For a
9397 register, we just generate an OP_REG and the register number. For a
9398 memory location we provide a Dwarf postfix expression describing how to
9399 generate the (dynamic) address of the object onto the address stack.
9401 If we don't know how to describe it, return 0. */
9403 static dw_loc_descr_ref
9404 loc_descriptor (rtx rtl, enum var_init_status initialized)
9406 dw_loc_descr_ref loc_result = NULL;
9408 switch (GET_CODE (rtl))
9411 /* The case of a subreg may arise when we have a local (register)
9412 variable or a formal (register) parameter which doesn't quite fill
9413 up an entire register. For now, just assume that it is
9414 legitimate to make the Dwarf info refer to the whole register which
9415 contains the given subreg. */
9416 rtl = SUBREG_REG (rtl);
9418 /* ... fall through ... */
9421 loc_result = reg_loc_descriptor (rtl, initialized);
9425 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9430 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9435 loc_result = concatn_loc_descriptor (rtl, initialized);
9440 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9442 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9446 rtl = XEXP (rtl, 1);
9451 rtvec par_elems = XVEC (rtl, 0);
9452 int num_elem = GET_NUM_ELEM (par_elems);
9453 enum machine_mode mode;
9456 /* Create the first one, so we have something to add to. */
9457 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9459 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9460 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9461 for (i = 1; i < num_elem; i++)
9463 dw_loc_descr_ref temp;
9465 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9467 add_loc_descr (&loc_result, temp);
9468 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9469 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9481 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9482 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9483 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9484 top-level invocation, and we require the address of LOC; is 0 if we require
9485 the value of LOC. */
9487 static dw_loc_descr_ref
9488 loc_descriptor_from_tree_1 (tree loc, int want_address)
9490 dw_loc_descr_ref ret, ret1;
9491 int have_address = 0;
9492 enum dwarf_location_atom op;
9494 /* ??? Most of the time we do not take proper care for sign/zero
9495 extending the values properly. Hopefully this won't be a real
9498 switch (TREE_CODE (loc))
9503 case PLACEHOLDER_EXPR:
9504 /* This case involves extracting fields from an object to determine the
9505 position of other fields. We don't try to encode this here. The
9506 only user of this is Ada, which encodes the needed information using
9507 the names of types. */
9513 case PREINCREMENT_EXPR:
9514 case PREDECREMENT_EXPR:
9515 case POSTINCREMENT_EXPR:
9516 case POSTDECREMENT_EXPR:
9517 /* There are no opcodes for these operations. */
9521 /* If we already want an address, there's nothing we can do. */
9525 /* Otherwise, process the argument and look for the address. */
9526 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9529 if (DECL_THREAD_LOCAL_P (loc))
9535 if (targetm.have_tls)
9537 /* If this is not defined, we have no way to emit the
9539 if (!targetm.asm_out.output_dwarf_dtprel)
9542 /* The way DW_OP_GNU_push_tls_address is specified, we
9543 can only look up addresses of objects in the current
9545 if (DECL_EXTERNAL (loc))
9547 first_op = INTERNAL_DW_OP_tls_addr;
9548 second_op = DW_OP_GNU_push_tls_address;
9552 if (!targetm.emutls.debug_form_tls_address)
9554 loc = emutls_decl (loc);
9555 first_op = DW_OP_addr;
9556 second_op = DW_OP_form_tls_address;
9559 rtl = rtl_for_decl_location (loc);
9560 if (rtl == NULL_RTX)
9565 rtl = XEXP (rtl, 0);
9566 if (! CONSTANT_P (rtl))
9569 ret = new_loc_descr (first_op, 0, 0);
9570 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9571 ret->dw_loc_oprnd1.v.val_addr = rtl;
9573 ret1 = new_loc_descr (second_op, 0, 0);
9574 add_loc_descr (&ret, ret1);
9582 if (DECL_HAS_VALUE_EXPR_P (loc))
9583 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9590 rtx rtl = rtl_for_decl_location (loc);
9592 if (rtl == NULL_RTX)
9594 else if (GET_CODE (rtl) == CONST_INT)
9596 HOST_WIDE_INT val = INTVAL (rtl);
9597 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9598 val &= GET_MODE_MASK (DECL_MODE (loc));
9599 ret = int_loc_descriptor (val);
9601 else if (GET_CODE (rtl) == CONST_STRING)
9603 else if (CONSTANT_P (rtl))
9605 ret = new_loc_descr (DW_OP_addr, 0, 0);
9606 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9607 ret->dw_loc_oprnd1.v.val_addr = rtl;
9611 enum machine_mode mode;
9613 /* Certain constructs can only be represented at top-level. */
9614 if (want_address == 2)
9615 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
9617 mode = GET_MODE (rtl);
9620 rtl = XEXP (rtl, 0);
9623 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9629 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9634 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9637 case VIEW_CONVERT_EXPR:
9640 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
9645 case ARRAY_RANGE_REF:
9648 HOST_WIDE_INT bitsize, bitpos, bytepos;
9649 enum machine_mode mode;
9651 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9653 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9654 &unsignedp, &volatilep, false);
9659 ret = loc_descriptor_from_tree_1 (obj, 1);
9661 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9664 if (offset != NULL_TREE)
9666 /* Variable offset. */
9667 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9668 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9671 bytepos = bitpos / BITS_PER_UNIT;
9673 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9674 else if (bytepos < 0)
9676 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9677 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9685 if (host_integerp (loc, 0))
9686 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9693 /* Get an RTL for this, if something has been emitted. */
9694 rtx rtl = lookup_constant_def (loc);
9695 enum machine_mode mode;
9697 if (!rtl || !MEM_P (rtl))
9699 mode = GET_MODE (rtl);
9700 rtl = XEXP (rtl, 0);
9701 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9706 case TRUTH_AND_EXPR:
9707 case TRUTH_ANDIF_EXPR:
9712 case TRUTH_XOR_EXPR:
9718 case TRUTH_ORIF_EXPR:
9723 case FLOOR_DIV_EXPR:
9725 case ROUND_DIV_EXPR:
9726 case TRUNC_DIV_EXPR:
9734 case FLOOR_MOD_EXPR:
9736 case ROUND_MOD_EXPR:
9737 case TRUNC_MOD_EXPR:
9750 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9753 case POINTER_PLUS_EXPR:
9755 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9756 && host_integerp (TREE_OPERAND (loc, 1), 0))
9758 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9762 add_loc_descr (&ret,
9763 new_loc_descr (DW_OP_plus_uconst,
9764 tree_low_cst (TREE_OPERAND (loc, 1),
9774 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9781 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9788 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9795 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9810 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9811 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9812 if (ret == 0 || ret1 == 0)
9815 add_loc_descr (&ret, ret1);
9816 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9819 case TRUTH_NOT_EXPR:
9833 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9837 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9843 const enum tree_code code =
9844 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9846 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9847 build2 (code, integer_type_node,
9848 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9849 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9852 /* ... fall through ... */
9856 dw_loc_descr_ref lhs
9857 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9858 dw_loc_descr_ref rhs
9859 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9860 dw_loc_descr_ref bra_node, jump_node, tmp;
9862 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9863 if (ret == 0 || lhs == 0 || rhs == 0)
9866 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9867 add_loc_descr (&ret, bra_node);
9869 add_loc_descr (&ret, rhs);
9870 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9871 add_loc_descr (&ret, jump_node);
9873 add_loc_descr (&ret, lhs);
9874 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9875 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9877 /* ??? Need a node to point the skip at. Use a nop. */
9878 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9879 add_loc_descr (&ret, tmp);
9880 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9881 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9885 case FIX_TRUNC_EXPR:
9889 /* Leave front-end specific codes as simply unknown. This comes
9890 up, for instance, with the C STMT_EXPR. */
9891 if ((unsigned int) TREE_CODE (loc)
9892 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9895 #ifdef ENABLE_CHECKING
9896 /* Otherwise this is a generic code; we should just lists all of
9897 these explicitly. We forgot one. */
9900 /* In a release build, we want to degrade gracefully: better to
9901 generate incomplete debugging information than to crash. */
9906 /* Show if we can't fill the request for an address. */
9907 if (want_address && !have_address)
9910 /* If we've got an address and don't want one, dereference. */
9911 if (!want_address && have_address && ret)
9913 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9915 if (size > DWARF2_ADDR_SIZE || size == -1)
9917 else if (size == DWARF2_ADDR_SIZE)
9920 op = DW_OP_deref_size;
9922 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9928 static inline dw_loc_descr_ref
9929 loc_descriptor_from_tree (tree loc)
9931 return loc_descriptor_from_tree_1 (loc, 2);
9934 /* Given a value, round it up to the lowest multiple of `boundary'
9935 which is not less than the value itself. */
9937 static inline HOST_WIDE_INT
9938 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9940 return (((value + boundary - 1) / boundary) * boundary);
9943 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9944 pointer to the declared type for the relevant field variable, or return
9945 `integer_type_node' if the given node turns out to be an
9949 field_type (const_tree decl)
9953 if (TREE_CODE (decl) == ERROR_MARK)
9954 return integer_type_node;
9956 type = DECL_BIT_FIELD_TYPE (decl);
9957 if (type == NULL_TREE)
9958 type = TREE_TYPE (decl);
9963 /* Given a pointer to a tree node, return the alignment in bits for
9964 it, or else return BITS_PER_WORD if the node actually turns out to
9965 be an ERROR_MARK node. */
9967 static inline unsigned
9968 simple_type_align_in_bits (const_tree type)
9970 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9973 static inline unsigned
9974 simple_decl_align_in_bits (const_tree decl)
9976 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9979 /* Return the result of rounding T up to ALIGN. */
9981 static inline HOST_WIDE_INT
9982 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9984 /* We must be careful if T is negative because HOST_WIDE_INT can be
9985 either "above" or "below" unsigned int as per the C promotion
9986 rules, depending on the host, thus making the signedness of the
9987 direct multiplication and division unpredictable. */
9988 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9994 return (HOST_WIDE_INT) u;
9997 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9998 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9999 or return 0 if we are unable to determine what that offset is, either
10000 because the argument turns out to be a pointer to an ERROR_MARK node, or
10001 because the offset is actually variable. (We can't handle the latter case
10004 static HOST_WIDE_INT
10005 field_byte_offset (const_tree decl)
10007 HOST_WIDE_INT object_offset_in_bits;
10008 HOST_WIDE_INT bitpos_int;
10010 if (TREE_CODE (decl) == ERROR_MARK)
10013 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10015 /* We cannot yet cope with fields whose positions are variable, so
10016 for now, when we see such things, we simply return 0. Someday, we may
10017 be able to handle such cases, but it will be damn difficult. */
10018 if (! host_integerp (bit_position (decl), 0))
10021 bitpos_int = int_bit_position (decl);
10023 #ifdef PCC_BITFIELD_TYPE_MATTERS
10024 if (PCC_BITFIELD_TYPE_MATTERS)
10027 tree field_size_tree;
10028 HOST_WIDE_INT deepest_bitpos;
10029 unsigned HOST_WIDE_INT field_size_in_bits;
10030 unsigned int type_align_in_bits;
10031 unsigned int decl_align_in_bits;
10032 unsigned HOST_WIDE_INT type_size_in_bits;
10034 type = field_type (decl);
10035 field_size_tree = DECL_SIZE (decl);
10037 /* The size could be unspecified if there was an error, or for
10038 a flexible array member. */
10039 if (! field_size_tree)
10040 field_size_tree = bitsize_zero_node;
10042 /* If we don't know the size of the field, pretend it's a full word. */
10043 if (host_integerp (field_size_tree, 1))
10044 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10046 field_size_in_bits = BITS_PER_WORD;
10048 type_size_in_bits = simple_type_size_in_bits (type);
10049 type_align_in_bits = simple_type_align_in_bits (type);
10050 decl_align_in_bits = simple_decl_align_in_bits (decl);
10052 /* The GCC front-end doesn't make any attempt to keep track of the
10053 starting bit offset (relative to the start of the containing
10054 structure type) of the hypothetical "containing object" for a
10055 bit-field. Thus, when computing the byte offset value for the
10056 start of the "containing object" of a bit-field, we must deduce
10057 this information on our own. This can be rather tricky to do in
10058 some cases. For example, handling the following structure type
10059 definition when compiling for an i386/i486 target (which only
10060 aligns long long's to 32-bit boundaries) can be very tricky:
10062 struct S { int field1; long long field2:31; };
10064 Fortunately, there is a simple rule-of-thumb which can be used
10065 in such cases. When compiling for an i386/i486, GCC will
10066 allocate 8 bytes for the structure shown above. It decides to
10067 do this based upon one simple rule for bit-field allocation.
10068 GCC allocates each "containing object" for each bit-field at
10069 the first (i.e. lowest addressed) legitimate alignment boundary
10070 (based upon the required minimum alignment for the declared
10071 type of the field) which it can possibly use, subject to the
10072 condition that there is still enough available space remaining
10073 in the containing object (when allocated at the selected point)
10074 to fully accommodate all of the bits of the bit-field itself.
10076 This simple rule makes it obvious why GCC allocates 8 bytes for
10077 each object of the structure type shown above. When looking
10078 for a place to allocate the "containing object" for `field2',
10079 the compiler simply tries to allocate a 64-bit "containing
10080 object" at each successive 32-bit boundary (starting at zero)
10081 until it finds a place to allocate that 64- bit field such that
10082 at least 31 contiguous (and previously unallocated) bits remain
10083 within that selected 64 bit field. (As it turns out, for the
10084 example above, the compiler finds it is OK to allocate the
10085 "containing object" 64-bit field at bit-offset zero within the
10088 Here we attempt to work backwards from the limited set of facts
10089 we're given, and we try to deduce from those facts, where GCC
10090 must have believed that the containing object started (within
10091 the structure type). The value we deduce is then used (by the
10092 callers of this routine) to generate DW_AT_location and
10093 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10094 the case of DW_AT_location, regular fields as well). */
10096 /* Figure out the bit-distance from the start of the structure to
10097 the "deepest" bit of the bit-field. */
10098 deepest_bitpos = bitpos_int + field_size_in_bits;
10100 /* This is the tricky part. Use some fancy footwork to deduce
10101 where the lowest addressed bit of the containing object must
10103 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10105 /* Round up to type_align by default. This works best for
10107 object_offset_in_bits
10108 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10110 if (object_offset_in_bits > bitpos_int)
10112 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10114 /* Round up to decl_align instead. */
10115 object_offset_in_bits
10116 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10121 object_offset_in_bits = bitpos_int;
10123 return object_offset_in_bits / BITS_PER_UNIT;
10126 /* The following routines define various Dwarf attributes and any data
10127 associated with them. */
10129 /* Add a location description attribute value to a DIE.
10131 This emits location attributes suitable for whole variables and
10132 whole parameters. Note that the location attributes for struct fields are
10133 generated by the routine `data_member_location_attribute' below. */
10136 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10137 dw_loc_descr_ref descr)
10140 add_AT_loc (die, attr_kind, descr);
10143 /* Attach the specialized form of location attribute used for data members of
10144 struct and union types. In the special case of a FIELD_DECL node which
10145 represents a bit-field, the "offset" part of this special location
10146 descriptor must indicate the distance in bytes from the lowest-addressed
10147 byte of the containing struct or union type to the lowest-addressed byte of
10148 the "containing object" for the bit-field. (See the `field_byte_offset'
10151 For any given bit-field, the "containing object" is a hypothetical object
10152 (of some integral or enum type) within which the given bit-field lives. The
10153 type of this hypothetical "containing object" is always the same as the
10154 declared type of the individual bit-field itself (for GCC anyway... the
10155 DWARF spec doesn't actually mandate this). Note that it is the size (in
10156 bytes) of the hypothetical "containing object" which will be given in the
10157 DW_AT_byte_size attribute for this bit-field. (See the
10158 `byte_size_attribute' function below.) It is also used when calculating the
10159 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10160 function below.) */
10163 add_data_member_location_attribute (dw_die_ref die, tree decl)
10165 HOST_WIDE_INT offset;
10166 dw_loc_descr_ref loc_descr = 0;
10168 if (TREE_CODE (decl) == TREE_BINFO)
10170 /* We're working on the TAG_inheritance for a base class. */
10171 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10173 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10174 aren't at a fixed offset from all (sub)objects of the same
10175 type. We need to extract the appropriate offset from our
10176 vtable. The following dwarf expression means
10178 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10180 This is specific to the V3 ABI, of course. */
10182 dw_loc_descr_ref tmp;
10184 /* Make a copy of the object address. */
10185 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10186 add_loc_descr (&loc_descr, tmp);
10188 /* Extract the vtable address. */
10189 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10190 add_loc_descr (&loc_descr, tmp);
10192 /* Calculate the address of the offset. */
10193 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10194 gcc_assert (offset < 0);
10196 tmp = int_loc_descriptor (-offset);
10197 add_loc_descr (&loc_descr, tmp);
10198 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10199 add_loc_descr (&loc_descr, tmp);
10201 /* Extract the offset. */
10202 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10203 add_loc_descr (&loc_descr, tmp);
10205 /* Add it to the object address. */
10206 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10207 add_loc_descr (&loc_descr, tmp);
10210 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10213 offset = field_byte_offset (decl);
10217 enum dwarf_location_atom op;
10219 /* The DWARF2 standard says that we should assume that the structure
10220 address is already on the stack, so we can specify a structure field
10221 address by using DW_OP_plus_uconst. */
10223 #ifdef MIPS_DEBUGGING_INFO
10224 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10225 operator correctly. It works only if we leave the offset on the
10229 op = DW_OP_plus_uconst;
10232 loc_descr = new_loc_descr (op, offset, 0);
10235 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10238 /* Writes integer values to dw_vec_const array. */
10241 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10245 *dest++ = val & 0xff;
10251 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10253 static HOST_WIDE_INT
10254 extract_int (const unsigned char *src, unsigned int size)
10256 HOST_WIDE_INT val = 0;
10262 val |= *--src & 0xff;
10268 /* Writes floating point values to dw_vec_const array. */
10271 insert_float (const_rtx rtl, unsigned char *array)
10273 REAL_VALUE_TYPE rv;
10277 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10278 real_to_target (val, &rv, GET_MODE (rtl));
10280 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10281 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10283 insert_int (val[i], 4, array);
10288 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10289 does not have a "location" either in memory or in a register. These
10290 things can arise in GNU C when a constant is passed as an actual parameter
10291 to an inlined function. They can also arise in C++ where declared
10292 constants do not necessarily get memory "homes". */
10295 add_const_value_attribute (dw_die_ref die, rtx rtl)
10297 switch (GET_CODE (rtl))
10301 HOST_WIDE_INT val = INTVAL (rtl);
10304 add_AT_int (die, DW_AT_const_value, val);
10306 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10311 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10312 floating-point constant. A CONST_DOUBLE is used whenever the
10313 constant requires more than one word in order to be adequately
10314 represented. We output CONST_DOUBLEs as blocks. */
10316 enum machine_mode mode = GET_MODE (rtl);
10318 if (SCALAR_FLOAT_MODE_P (mode))
10320 unsigned int length = GET_MODE_SIZE (mode);
10321 unsigned char *array = GGC_NEWVEC (unsigned char, length);
10323 insert_float (rtl, array);
10324 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10328 /* ??? We really should be using HOST_WIDE_INT throughout. */
10329 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10331 add_AT_long_long (die, DW_AT_const_value,
10332 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10339 enum machine_mode mode = GET_MODE (rtl);
10340 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10341 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10342 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
10346 switch (GET_MODE_CLASS (mode))
10348 case MODE_VECTOR_INT:
10349 for (i = 0, p = array; i < length; i++, p += elt_size)
10351 rtx elt = CONST_VECTOR_ELT (rtl, i);
10352 HOST_WIDE_INT lo, hi;
10354 switch (GET_CODE (elt))
10362 lo = CONST_DOUBLE_LOW (elt);
10363 hi = CONST_DOUBLE_HIGH (elt);
10367 gcc_unreachable ();
10370 if (elt_size <= sizeof (HOST_WIDE_INT))
10371 insert_int (lo, elt_size, p);
10374 unsigned char *p0 = p;
10375 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10377 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10378 if (WORDS_BIG_ENDIAN)
10383 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10384 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10389 case MODE_VECTOR_FLOAT:
10390 for (i = 0, p = array; i < length; i++, p += elt_size)
10392 rtx elt = CONST_VECTOR_ELT (rtl, i);
10393 insert_float (elt, p);
10398 gcc_unreachable ();
10401 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10406 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10412 add_AT_addr (die, DW_AT_const_value, rtl);
10413 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10417 /* In cases where an inlined instance of an inline function is passed
10418 the address of an `auto' variable (which is local to the caller) we
10419 can get a situation where the DECL_RTL of the artificial local
10420 variable (for the inlining) which acts as a stand-in for the
10421 corresponding formal parameter (of the inline function) will look
10422 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10423 exactly a compile-time constant expression, but it isn't the address
10424 of the (artificial) local variable either. Rather, it represents the
10425 *value* which the artificial local variable always has during its
10426 lifetime. We currently have no way to represent such quasi-constant
10427 values in Dwarf, so for now we just punt and generate nothing. */
10431 /* No other kinds of rtx should be possible here. */
10432 gcc_unreachable ();
10437 /* Determine whether the evaluation of EXPR references any variables
10438 or functions which aren't otherwise used (and therefore may not be
10441 reference_to_unused (tree * tp, int * walk_subtrees,
10442 void * data ATTRIBUTE_UNUSED)
10444 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10445 *walk_subtrees = 0;
10447 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10448 && ! TREE_ASM_WRITTEN (*tp))
10450 /* ??? The C++ FE emits debug information for using decls, so
10451 putting gcc_unreachable here falls over. See PR31899. For now
10452 be conservative. */
10453 else if (!cgraph_global_info_ready
10454 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10456 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10458 struct varpool_node *node = varpool_node (*tp);
10462 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10463 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10465 struct cgraph_node *node = cgraph_node (*tp);
10469 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
10475 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10476 for use in a later add_const_value_attribute call. */
10479 rtl_for_decl_init (tree init, tree type)
10481 rtx rtl = NULL_RTX;
10483 /* If a variable is initialized with a string constant without embedded
10484 zeros, build CONST_STRING. */
10485 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10487 tree enttype = TREE_TYPE (type);
10488 tree domain = TYPE_DOMAIN (type);
10489 enum machine_mode mode = TYPE_MODE (enttype);
10491 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10493 && integer_zerop (TYPE_MIN_VALUE (domain))
10494 && compare_tree_int (TYPE_MAX_VALUE (domain),
10495 TREE_STRING_LENGTH (init) - 1) == 0
10496 && ((size_t) TREE_STRING_LENGTH (init)
10497 == strlen (TREE_STRING_POINTER (init)) + 1))
10498 rtl = gen_rtx_CONST_STRING (VOIDmode,
10499 ggc_strdup (TREE_STRING_POINTER (init)));
10501 /* Other aggregates, and complex values, could be represented using
10503 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10505 /* Vectors only work if their mode is supported by the target.
10506 FIXME: generic vectors ought to work too. */
10507 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10509 /* If the initializer is something that we know will expand into an
10510 immediate RTL constant, expand it now. We must be careful not to
10511 reference variables which won't be output. */
10512 else if (initializer_constant_valid_p (init, type)
10513 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10515 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10517 if (TREE_CODE (type) == VECTOR_TYPE)
10518 switch (TREE_CODE (init))
10523 if (TREE_CONSTANT (init))
10525 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
10526 bool constant_p = true;
10528 unsigned HOST_WIDE_INT ix;
10530 /* Even when ctor is constant, it might contain non-*_CST
10531 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10532 belong into VECTOR_CST nodes. */
10533 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
10534 if (!CONSTANT_CLASS_P (value))
10536 constant_p = false;
10542 init = build_vector_from_ctor (type, elts);
10552 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10554 /* If expand_expr returns a MEM, it wasn't immediate. */
10555 gcc_assert (!rtl || !MEM_P (rtl));
10561 /* Generate RTL for the variable DECL to represent its location. */
10564 rtl_for_decl_location (tree decl)
10568 /* Here we have to decide where we are going to say the parameter "lives"
10569 (as far as the debugger is concerned). We only have a couple of
10570 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10572 DECL_RTL normally indicates where the parameter lives during most of the
10573 activation of the function. If optimization is enabled however, this
10574 could be either NULL or else a pseudo-reg. Both of those cases indicate
10575 that the parameter doesn't really live anywhere (as far as the code
10576 generation parts of GCC are concerned) during most of the function's
10577 activation. That will happen (for example) if the parameter is never
10578 referenced within the function.
10580 We could just generate a location descriptor here for all non-NULL
10581 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10582 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10583 where DECL_RTL is NULL or is a pseudo-reg.
10585 Note however that we can only get away with using DECL_INCOMING_RTL as
10586 a backup substitute for DECL_RTL in certain limited cases. In cases
10587 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10588 we can be sure that the parameter was passed using the same type as it is
10589 declared to have within the function, and that its DECL_INCOMING_RTL
10590 points us to a place where a value of that type is passed.
10592 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10593 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10594 because in these cases DECL_INCOMING_RTL points us to a value of some
10595 type which is *different* from the type of the parameter itself. Thus,
10596 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10597 such cases, the debugger would end up (for example) trying to fetch a
10598 `float' from a place which actually contains the first part of a
10599 `double'. That would lead to really incorrect and confusing
10600 output at debug-time.
10602 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10603 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10604 are a couple of exceptions however. On little-endian machines we can
10605 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10606 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10607 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10608 when (on a little-endian machine) a non-prototyped function has a
10609 parameter declared to be of type `short' or `char'. In such cases,
10610 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10611 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10612 passed `int' value. If the debugger then uses that address to fetch
10613 a `short' or a `char' (on a little-endian machine) the result will be
10614 the correct data, so we allow for such exceptional cases below.
10616 Note that our goal here is to describe the place where the given formal
10617 parameter lives during most of the function's activation (i.e. between the
10618 end of the prologue and the start of the epilogue). We'll do that as best
10619 as we can. Note however that if the given formal parameter is modified
10620 sometime during the execution of the function, then a stack backtrace (at
10621 debug-time) will show the function as having been called with the *new*
10622 value rather than the value which was originally passed in. This happens
10623 rarely enough that it is not a major problem, but it *is* a problem, and
10624 I'd like to fix it.
10626 A future version of dwarf2out.c may generate two additional attributes for
10627 any given DW_TAG_formal_parameter DIE which will describe the "passed
10628 type" and the "passed location" for the given formal parameter in addition
10629 to the attributes we now generate to indicate the "declared type" and the
10630 "active location" for each parameter. This additional set of attributes
10631 could be used by debuggers for stack backtraces. Separately, note that
10632 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10633 This happens (for example) for inlined-instances of inline function formal
10634 parameters which are never referenced. This really shouldn't be
10635 happening. All PARM_DECL nodes should get valid non-NULL
10636 DECL_INCOMING_RTL values. FIXME. */
10638 /* Use DECL_RTL as the "location" unless we find something better. */
10639 rtl = DECL_RTL_IF_SET (decl);
10641 /* When generating abstract instances, ignore everything except
10642 constants, symbols living in memory, and symbols living in
10643 fixed registers. */
10644 if (! reload_completed)
10647 && (CONSTANT_P (rtl)
10649 && CONSTANT_P (XEXP (rtl, 0)))
10651 && TREE_CODE (decl) == VAR_DECL
10652 && TREE_STATIC (decl))))
10654 rtl = targetm.delegitimize_address (rtl);
10659 else if (TREE_CODE (decl) == PARM_DECL)
10661 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10663 tree declared_type = TREE_TYPE (decl);
10664 tree passed_type = DECL_ARG_TYPE (decl);
10665 enum machine_mode dmode = TYPE_MODE (declared_type);
10666 enum machine_mode pmode = TYPE_MODE (passed_type);
10668 /* This decl represents a formal parameter which was optimized out.
10669 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10670 all cases where (rtl == NULL_RTX) just below. */
10671 if (dmode == pmode)
10672 rtl = DECL_INCOMING_RTL (decl);
10673 else if (SCALAR_INT_MODE_P (dmode)
10674 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10675 && DECL_INCOMING_RTL (decl))
10677 rtx inc = DECL_INCOMING_RTL (decl);
10680 else if (MEM_P (inc))
10682 if (BYTES_BIG_ENDIAN)
10683 rtl = adjust_address_nv (inc, dmode,
10684 GET_MODE_SIZE (pmode)
10685 - GET_MODE_SIZE (dmode));
10692 /* If the parm was passed in registers, but lives on the stack, then
10693 make a big endian correction if the mode of the type of the
10694 parameter is not the same as the mode of the rtl. */
10695 /* ??? This is the same series of checks that are made in dbxout.c before
10696 we reach the big endian correction code there. It isn't clear if all
10697 of these checks are necessary here, but keeping them all is the safe
10699 else if (MEM_P (rtl)
10700 && XEXP (rtl, 0) != const0_rtx
10701 && ! CONSTANT_P (XEXP (rtl, 0))
10702 /* Not passed in memory. */
10703 && !MEM_P (DECL_INCOMING_RTL (decl))
10704 /* Not passed by invisible reference. */
10705 && (!REG_P (XEXP (rtl, 0))
10706 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10707 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10708 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10709 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10712 /* Big endian correction check. */
10713 && BYTES_BIG_ENDIAN
10714 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10715 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10718 int offset = (UNITS_PER_WORD
10719 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10721 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10722 plus_constant (XEXP (rtl, 0), offset));
10725 else if (TREE_CODE (decl) == VAR_DECL
10728 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10729 && BYTES_BIG_ENDIAN)
10731 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10732 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10734 /* If a variable is declared "register" yet is smaller than
10735 a register, then if we store the variable to memory, it
10736 looks like we're storing a register-sized value, when in
10737 fact we are not. We need to adjust the offset of the
10738 storage location to reflect the actual value's bytes,
10739 else gdb will not be able to display it. */
10741 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10742 plus_constant (XEXP (rtl, 0), rsize-dsize));
10745 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10746 and will have been substituted directly into all expressions that use it.
10747 C does not have such a concept, but C++ and other languages do. */
10748 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10749 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10752 rtl = targetm.delegitimize_address (rtl);
10754 /* If we don't look past the constant pool, we risk emitting a
10755 reference to a constant pool entry that isn't referenced from
10756 code, and thus is not emitted. */
10758 rtl = avoid_constant_pool_reference (rtl);
10763 /* We need to figure out what section we should use as the base for the
10764 address ranges where a given location is valid.
10765 1. If this particular DECL has a section associated with it, use that.
10766 2. If this function has a section associated with it, use that.
10767 3. Otherwise, use the text section.
10768 XXX: If you split a variable across multiple sections, we won't notice. */
10770 static const char *
10771 secname_for_decl (const_tree decl)
10773 const char *secname;
10775 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10777 tree sectree = DECL_SECTION_NAME (decl);
10778 secname = TREE_STRING_POINTER (sectree);
10780 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10782 tree sectree = DECL_SECTION_NAME (current_function_decl);
10783 secname = TREE_STRING_POINTER (sectree);
10785 else if (cfun && in_cold_section_p)
10786 secname = crtl->subsections.cold_section_label;
10788 secname = text_section_label;
10793 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
10794 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
10795 value is the offset into the common block for the symbol. */
10798 fortran_common (tree decl, HOST_WIDE_INT *value)
10800 tree val_expr, cvar;
10801 enum machine_mode mode;
10802 HOST_WIDE_INT bitsize, bitpos;
10804 int volatilep = 0, unsignedp = 0;
10806 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
10807 it does not have a value (the offset into the common area), or if it
10808 is thread local (as opposed to global) then it isn't common, and shouldn't
10809 be handled as such. */
10810 if (TREE_CODE (decl) != VAR_DECL
10811 || !TREE_PUBLIC (decl)
10812 || !TREE_STATIC (decl)
10813 || !DECL_HAS_VALUE_EXPR_P (decl)
10817 val_expr = DECL_VALUE_EXPR (decl);
10818 if (TREE_CODE (val_expr) != COMPONENT_REF)
10821 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
10822 &mode, &unsignedp, &volatilep, true);
10824 if (cvar == NULL_TREE
10825 || TREE_CODE (cvar) != VAR_DECL
10826 || DECL_ARTIFICIAL (cvar)
10827 || !TREE_PUBLIC (cvar))
10831 if (offset != NULL)
10833 if (!host_integerp (offset, 0))
10835 *value = tree_low_cst (offset, 0);
10838 *value += bitpos / BITS_PER_UNIT;
10844 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10845 data attribute for a variable or a parameter. We generate the
10846 DW_AT_const_value attribute only in those cases where the given variable
10847 or parameter does not have a true "location" either in memory or in a
10848 register. This can happen (for example) when a constant is passed as an
10849 actual argument in a call to an inline function. (It's possible that
10850 these things can crop up in other ways also.) Note that one type of
10851 constant value which can be passed into an inlined function is a constant
10852 pointer. This can happen for example if an actual argument in an inlined
10853 function call evaluates to a compile-time constant address. */
10856 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10857 enum dwarf_attribute attr)
10860 dw_loc_descr_ref descr;
10861 var_loc_list *loc_list;
10862 struct var_loc_node *node;
10863 if (TREE_CODE (decl) == ERROR_MARK)
10866 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10867 || TREE_CODE (decl) == RESULT_DECL);
10869 /* See if we possibly have multiple locations for this variable. */
10870 loc_list = lookup_decl_loc (decl);
10872 /* If it truly has multiple locations, the first and last node will
10874 if (loc_list && loc_list->first != loc_list->last)
10876 const char *endname, *secname;
10877 dw_loc_list_ref list;
10879 enum var_init_status initialized;
10881 /* Now that we know what section we are using for a base,
10882 actually construct the list of locations.
10883 The first location information is what is passed to the
10884 function that creates the location list, and the remaining
10885 locations just get added on to that list.
10886 Note that we only know the start address for a location
10887 (IE location changes), so to build the range, we use
10888 the range [current location start, next location start].
10889 This means we have to special case the last node, and generate
10890 a range of [last location start, end of function label]. */
10892 node = loc_list->first;
10893 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10894 secname = secname_for_decl (decl);
10896 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
10897 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10899 initialized = VAR_INIT_STATUS_INITIALIZED;
10901 list = new_loc_list (loc_descriptor (varloc, initialized),
10902 node->label, node->next->label, secname, 1);
10905 for (; node->next; node = node->next)
10906 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10908 /* The variable has a location between NODE->LABEL and
10909 NODE->NEXT->LABEL. */
10910 enum var_init_status initialized =
10911 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10912 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10913 add_loc_descr_to_loc_list (&list,
10914 loc_descriptor (varloc, initialized),
10915 node->label, node->next->label, secname);
10918 /* If the variable has a location at the last label
10919 it keeps its location until the end of function. */
10920 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10922 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10923 enum var_init_status initialized =
10924 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10926 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10927 if (!current_function_decl)
10928 endname = text_end_label;
10931 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10932 current_function_funcdef_no);
10933 endname = ggc_strdup (label_id);
10935 add_loc_descr_to_loc_list (&list,
10936 loc_descriptor (varloc, initialized),
10937 node->label, endname, secname);
10940 /* Finally, add the location list to the DIE, and we are done. */
10941 add_AT_loc_list (die, attr, list);
10945 /* Try to get some constant RTL for this decl, and use that as the value of
10948 rtl = rtl_for_decl_location (decl);
10949 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10951 add_const_value_attribute (die, rtl);
10955 /* If we have tried to generate the location otherwise, and it
10956 didn't work out (we wouldn't be here if we did), and we have a one entry
10957 location list, try generating a location from that. */
10958 if (loc_list && loc_list->first)
10960 enum var_init_status status;
10961 node = loc_list->first;
10962 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10963 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
10966 add_AT_location_description (die, attr, descr);
10971 /* We couldn't get any rtl, so try directly generating the location
10972 description from the tree. */
10973 descr = loc_descriptor_from_tree (decl);
10976 add_AT_location_description (die, attr, descr);
10979 /* None of that worked, so it must not really have a location;
10980 try adding a constant value attribute from the DECL_INITIAL. */
10981 tree_add_const_value_attribute (die, decl);
10984 /* If we don't have a copy of this variable in memory for some reason (such
10985 as a C++ member constant that doesn't have an out-of-line definition),
10986 we should tell the debugger about the constant value. */
10989 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10991 tree init = DECL_INITIAL (decl);
10992 tree type = TREE_TYPE (decl);
10995 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
11000 rtl = rtl_for_decl_init (init, type);
11002 add_const_value_attribute (var_die, rtl);
11005 /* Convert the CFI instructions for the current function into a
11006 location list. This is used for DW_AT_frame_base when we targeting
11007 a dwarf2 consumer that does not support the dwarf3
11008 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11011 static dw_loc_list_ref
11012 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
11015 dw_loc_list_ref list, *list_tail;
11017 dw_cfa_location last_cfa, next_cfa;
11018 const char *start_label, *last_label, *section;
11020 fde = current_fde ();
11021 gcc_assert (fde != NULL);
11023 section = secname_for_decl (current_function_decl);
11027 next_cfa.reg = INVALID_REGNUM;
11028 next_cfa.offset = 0;
11029 next_cfa.indirect = 0;
11030 next_cfa.base_offset = 0;
11032 start_label = fde->dw_fde_begin;
11034 /* ??? Bald assumption that the CIE opcode list does not contain
11035 advance opcodes. */
11036 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11037 lookup_cfa_1 (cfi, &next_cfa);
11039 last_cfa = next_cfa;
11040 last_label = start_label;
11042 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11043 switch (cfi->dw_cfi_opc)
11045 case DW_CFA_set_loc:
11046 case DW_CFA_advance_loc1:
11047 case DW_CFA_advance_loc2:
11048 case DW_CFA_advance_loc4:
11049 if (!cfa_equal_p (&last_cfa, &next_cfa))
11051 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11052 start_label, last_label, section,
11055 list_tail = &(*list_tail)->dw_loc_next;
11056 last_cfa = next_cfa;
11057 start_label = last_label;
11059 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11062 case DW_CFA_advance_loc:
11063 /* The encoding is complex enough that we should never emit this. */
11064 case DW_CFA_remember_state:
11065 case DW_CFA_restore_state:
11066 /* We don't handle these two in this function. It would be possible
11067 if it were to be required. */
11068 gcc_unreachable ();
11071 lookup_cfa_1 (cfi, &next_cfa);
11075 if (!cfa_equal_p (&last_cfa, &next_cfa))
11077 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11078 start_label, last_label, section,
11080 list_tail = &(*list_tail)->dw_loc_next;
11081 start_label = last_label;
11083 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11084 start_label, fde->dw_fde_end, section,
11090 /* Compute a displacement from the "steady-state frame pointer" to the
11091 frame base (often the same as the CFA), and store it in
11092 frame_pointer_fb_offset. OFFSET is added to the displacement
11093 before the latter is negated. */
11096 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11100 #ifdef FRAME_POINTER_CFA_OFFSET
11101 reg = frame_pointer_rtx;
11102 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11104 reg = arg_pointer_rtx;
11105 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11108 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11109 if (GET_CODE (elim) == PLUS)
11111 offset += INTVAL (XEXP (elim, 1));
11112 elim = XEXP (elim, 0);
11114 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
11115 : stack_pointer_rtx));
11117 frame_pointer_fb_offset = -offset;
11120 /* Generate a DW_AT_name attribute given some string value to be included as
11121 the value of the attribute. */
11124 add_name_attribute (dw_die_ref die, const char *name_string)
11126 if (name_string != NULL && *name_string != 0)
11128 if (demangle_name_func)
11129 name_string = (*demangle_name_func) (name_string);
11131 add_AT_string (die, DW_AT_name, name_string);
11135 /* Generate a DW_AT_comp_dir attribute for DIE. */
11138 add_comp_dir_attribute (dw_die_ref die)
11140 const char *wd = get_src_pwd ();
11142 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11145 /* Given a tree node describing an array bound (either lower or upper) output
11146 a representation for that bound. */
11149 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11151 switch (TREE_CODE (bound))
11156 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11158 if (! host_integerp (bound, 0)
11159 || (bound_attr == DW_AT_lower_bound
11160 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11161 || (is_fortran () && integer_onep (bound)))))
11162 /* Use the default. */
11165 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11169 case VIEW_CONVERT_EXPR:
11170 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11180 dw_die_ref decl_die = lookup_decl_die (bound);
11182 /* ??? Can this happen, or should the variable have been bound
11183 first? Probably it can, since I imagine that we try to create
11184 the types of parameters in the order in which they exist in
11185 the list, and won't have created a forward reference to a
11186 later parameter. */
11187 if (decl_die != NULL)
11188 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11194 /* Otherwise try to create a stack operation procedure to
11195 evaluate the value of the array bound. */
11197 dw_die_ref ctx, decl_die;
11198 dw_loc_descr_ref loc;
11200 loc = loc_descriptor_from_tree (bound);
11204 if (current_function_decl == 0)
11205 ctx = comp_unit_die;
11207 ctx = lookup_decl_die (current_function_decl);
11209 decl_die = new_die (DW_TAG_variable, ctx, bound);
11210 add_AT_flag (decl_die, DW_AT_artificial, 1);
11211 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11212 add_AT_loc (decl_die, DW_AT_location, loc);
11214 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11220 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
11221 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
11222 Note that the block of subscript information for an array type also
11223 includes information about the element type of the given array type. */
11226 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
11228 unsigned dimension_number;
11230 dw_die_ref subrange_die;
11232 for (dimension_number = 0;
11233 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
11234 type = TREE_TYPE (type), dimension_number++)
11236 tree domain = TYPE_DOMAIN (type);
11238 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11239 and (in GNU C only) variable bounds. Handle all three forms
11241 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11244 /* We have an array type with specified bounds. */
11245 lower = TYPE_MIN_VALUE (domain);
11246 upper = TYPE_MAX_VALUE (domain);
11248 /* Define the index type. */
11249 if (TREE_TYPE (domain))
11251 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11252 TREE_TYPE field. We can't emit debug info for this
11253 because it is an unnamed integral type. */
11254 if (TREE_CODE (domain) == INTEGER_TYPE
11255 && TYPE_NAME (domain) == NULL_TREE
11256 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11257 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11260 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11264 /* ??? If upper is NULL, the array has unspecified length,
11265 but it does have a lower bound. This happens with Fortran
11267 Since the debugger is definitely going to need to know N
11268 to produce useful results, go ahead and output the lower
11269 bound solo, and hope the debugger can cope. */
11271 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11273 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11276 /* Otherwise we have an array type with an unspecified length. The
11277 DWARF-2 spec does not say how to handle this; let's just leave out the
11283 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11287 switch (TREE_CODE (tree_node))
11292 case ENUMERAL_TYPE:
11295 case QUAL_UNION_TYPE:
11296 size = int_size_in_bytes (tree_node);
11299 /* For a data member of a struct or union, the DW_AT_byte_size is
11300 generally given as the number of bytes normally allocated for an
11301 object of the *declared* type of the member itself. This is true
11302 even for bit-fields. */
11303 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11306 gcc_unreachable ();
11309 /* Note that `size' might be -1 when we get to this point. If it is, that
11310 indicates that the byte size of the entity in question is variable. We
11311 have no good way of expressing this fact in Dwarf at the present time,
11312 so just let the -1 pass on through. */
11313 add_AT_unsigned (die, DW_AT_byte_size, size);
11316 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11317 which specifies the distance in bits from the highest order bit of the
11318 "containing object" for the bit-field to the highest order bit of the
11321 For any given bit-field, the "containing object" is a hypothetical object
11322 (of some integral or enum type) within which the given bit-field lives. The
11323 type of this hypothetical "containing object" is always the same as the
11324 declared type of the individual bit-field itself. The determination of the
11325 exact location of the "containing object" for a bit-field is rather
11326 complicated. It's handled by the `field_byte_offset' function (above).
11328 Note that it is the size (in bytes) of the hypothetical "containing object"
11329 which will be given in the DW_AT_byte_size attribute for this bit-field.
11330 (See `byte_size_attribute' above). */
11333 add_bit_offset_attribute (dw_die_ref die, tree decl)
11335 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11336 tree type = DECL_BIT_FIELD_TYPE (decl);
11337 HOST_WIDE_INT bitpos_int;
11338 HOST_WIDE_INT highest_order_object_bit_offset;
11339 HOST_WIDE_INT highest_order_field_bit_offset;
11340 HOST_WIDE_INT unsigned bit_offset;
11342 /* Must be a field and a bit field. */
11343 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11345 /* We can't yet handle bit-fields whose offsets are variable, so if we
11346 encounter such things, just return without generating any attribute
11347 whatsoever. Likewise for variable or too large size. */
11348 if (! host_integerp (bit_position (decl), 0)
11349 || ! host_integerp (DECL_SIZE (decl), 1))
11352 bitpos_int = int_bit_position (decl);
11354 /* Note that the bit offset is always the distance (in bits) from the
11355 highest-order bit of the "containing object" to the highest-order bit of
11356 the bit-field itself. Since the "high-order end" of any object or field
11357 is different on big-endian and little-endian machines, the computation
11358 below must take account of these differences. */
11359 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11360 highest_order_field_bit_offset = bitpos_int;
11362 if (! BYTES_BIG_ENDIAN)
11364 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11365 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11369 = (! BYTES_BIG_ENDIAN
11370 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11371 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11373 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11376 /* For a FIELD_DECL node which represents a bit field, output an attribute
11377 which specifies the length in bits of the given field. */
11380 add_bit_size_attribute (dw_die_ref die, tree decl)
11382 /* Must be a field and a bit field. */
11383 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11384 && DECL_BIT_FIELD_TYPE (decl));
11386 if (host_integerp (DECL_SIZE (decl), 1))
11387 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11390 /* If the compiled language is ANSI C, then add a 'prototyped'
11391 attribute, if arg types are given for the parameters of a function. */
11394 add_prototyped_attribute (dw_die_ref die, tree func_type)
11396 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11397 && TYPE_ARG_TYPES (func_type) != NULL)
11398 add_AT_flag (die, DW_AT_prototyped, 1);
11401 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11402 by looking in either the type declaration or object declaration
11406 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11408 dw_die_ref origin_die = NULL;
11410 if (TREE_CODE (origin) != FUNCTION_DECL)
11412 /* We may have gotten separated from the block for the inlined
11413 function, if we're in an exception handler or some such; make
11414 sure that the abstract function has been written out.
11416 Doing this for nested functions is wrong, however; functions are
11417 distinct units, and our context might not even be inline. */
11421 fn = TYPE_STUB_DECL (fn);
11423 fn = decl_function_context (fn);
11425 dwarf2out_abstract_function (fn);
11428 if (DECL_P (origin))
11429 origin_die = lookup_decl_die (origin);
11430 else if (TYPE_P (origin))
11431 origin_die = lookup_type_die (origin);
11433 /* XXX: Functions that are never lowered don't always have correct block
11434 trees (in the case of java, they simply have no block tree, in some other
11435 languages). For these functions, there is nothing we can really do to
11436 output correct debug info for inlined functions in all cases. Rather
11437 than die, we'll just produce deficient debug info now, in that we will
11438 have variables without a proper abstract origin. In the future, when all
11439 functions are lowered, we should re-add a gcc_assert (origin_die)
11443 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11446 /* We do not currently support the pure_virtual attribute. */
11449 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11451 if (DECL_VINDEX (func_decl))
11453 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11455 if (host_integerp (DECL_VINDEX (func_decl), 0))
11456 add_AT_loc (die, DW_AT_vtable_elem_location,
11457 new_loc_descr (DW_OP_constu,
11458 tree_low_cst (DECL_VINDEX (func_decl), 0),
11461 /* GNU extension: Record what type this method came from originally. */
11462 if (debug_info_level > DINFO_LEVEL_TERSE)
11463 add_AT_die_ref (die, DW_AT_containing_type,
11464 lookup_type_die (DECL_CONTEXT (func_decl)));
11468 /* Add source coordinate attributes for the given decl. */
11471 add_src_coords_attributes (dw_die_ref die, tree decl)
11473 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11475 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11476 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11479 /* Add a DW_AT_name attribute and source coordinate attribute for the
11480 given decl, but only if it actually has a name. */
11483 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11487 decl_name = DECL_NAME (decl);
11488 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11490 add_name_attribute (die, dwarf2_name (decl, 0));
11491 if (! DECL_ARTIFICIAL (decl))
11492 add_src_coords_attributes (die, decl);
11494 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11495 && TREE_PUBLIC (decl)
11496 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11497 && !DECL_ABSTRACT (decl)
11498 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
11500 add_AT_string (die, DW_AT_MIPS_linkage_name,
11501 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11504 #ifdef VMS_DEBUGGING_INFO
11505 /* Get the function's name, as described by its RTL. This may be different
11506 from the DECL_NAME name used in the source file. */
11507 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11509 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11510 XEXP (DECL_RTL (decl), 0));
11511 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11516 /* Push a new declaration scope. */
11519 push_decl_scope (tree scope)
11521 VEC_safe_push (tree, gc, decl_scope_table, scope);
11524 /* Pop a declaration scope. */
11527 pop_decl_scope (void)
11529 VEC_pop (tree, decl_scope_table);
11532 /* Return the DIE for the scope that immediately contains this type.
11533 Non-named types get global scope. Named types nested in other
11534 types get their containing scope if it's open, or global scope
11535 otherwise. All other types (i.e. function-local named types) get
11536 the current active scope. */
11539 scope_die_for (tree t, dw_die_ref context_die)
11541 dw_die_ref scope_die = NULL;
11542 tree containing_scope;
11545 /* Non-types always go in the current scope. */
11546 gcc_assert (TYPE_P (t));
11548 containing_scope = TYPE_CONTEXT (t);
11550 /* Use the containing namespace if it was passed in (for a declaration). */
11551 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11553 if (context_die == lookup_decl_die (containing_scope))
11556 containing_scope = NULL_TREE;
11559 /* Ignore function type "scopes" from the C frontend. They mean that
11560 a tagged type is local to a parmlist of a function declarator, but
11561 that isn't useful to DWARF. */
11562 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11563 containing_scope = NULL_TREE;
11565 if (containing_scope == NULL_TREE)
11566 scope_die = comp_unit_die;
11567 else if (TYPE_P (containing_scope))
11569 /* For types, we can just look up the appropriate DIE. But
11570 first we check to see if we're in the middle of emitting it
11571 so we know where the new DIE should go. */
11572 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11573 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11578 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11579 || TREE_ASM_WRITTEN (containing_scope));
11581 /* If none of the current dies are suitable, we get file scope. */
11582 scope_die = comp_unit_die;
11585 scope_die = lookup_type_die (containing_scope);
11588 scope_die = context_die;
11593 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11596 local_scope_p (dw_die_ref context_die)
11598 for (; context_die; context_die = context_die->die_parent)
11599 if (context_die->die_tag == DW_TAG_inlined_subroutine
11600 || context_die->die_tag == DW_TAG_subprogram)
11606 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11607 whether or not to treat a DIE in this context as a declaration. */
11610 class_or_namespace_scope_p (dw_die_ref context_die)
11612 return (context_die
11613 && (context_die->die_tag == DW_TAG_structure_type
11614 || context_die->die_tag == DW_TAG_class_type
11615 || context_die->die_tag == DW_TAG_interface_type
11616 || context_die->die_tag == DW_TAG_union_type
11617 || context_die->die_tag == DW_TAG_namespace));
11620 /* Many forms of DIEs require a "type description" attribute. This
11621 routine locates the proper "type descriptor" die for the type given
11622 by 'type', and adds a DW_AT_type attribute below the given die. */
11625 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11626 int decl_volatile, dw_die_ref context_die)
11628 enum tree_code code = TREE_CODE (type);
11629 dw_die_ref type_die = NULL;
11631 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11632 or fixed-point type, use the inner type. This is because we have no
11633 support for unnamed types in base_type_die. This can happen if this is
11634 an Ada subrange type. Correct solution is emit a subrange type die. */
11635 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
11636 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11637 type = TREE_TYPE (type), code = TREE_CODE (type);
11639 if (code == ERROR_MARK
11640 /* Handle a special case. For functions whose return type is void, we
11641 generate *no* type attribute. (Note that no object may have type
11642 `void', so this only applies to function return types). */
11643 || code == VOID_TYPE)
11646 type_die = modified_type_die (type,
11647 decl_const || TYPE_READONLY (type),
11648 decl_volatile || TYPE_VOLATILE (type),
11651 if (type_die != NULL)
11652 add_AT_die_ref (object_die, DW_AT_type, type_die);
11655 /* Given an object die, add the calling convention attribute for the
11656 function call type. */
11658 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
11660 enum dwarf_calling_convention value = DW_CC_normal;
11662 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
11664 /* DWARF doesn't provide a way to identify a program's source-level
11665 entry point. DW_AT_calling_convention attributes are only meant
11666 to describe functions' calling conventions. However, lacking a
11667 better way to signal the Fortran main program, we use this for the
11668 time being, following existing custom. */
11670 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
11671 value = DW_CC_program;
11673 /* Only add the attribute if the backend requests it, and
11674 is not DW_CC_normal. */
11675 if (value && (value != DW_CC_normal))
11676 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11679 /* Given a tree pointer to a struct, class, union, or enum type node, return
11680 a pointer to the (string) tag name for the given type, or zero if the type
11681 was declared without a tag. */
11683 static const char *
11684 type_tag (const_tree type)
11686 const char *name = 0;
11688 if (TYPE_NAME (type) != 0)
11692 /* Find the IDENTIFIER_NODE for the type name. */
11693 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11694 t = TYPE_NAME (type);
11696 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11697 a TYPE_DECL node, regardless of whether or not a `typedef' was
11699 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11700 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11702 /* We want to be extra verbose. Don't call dwarf_name if
11703 DECL_NAME isn't set. The default hook for decl_printable_name
11704 doesn't like that, and in this context it's correct to return
11705 0, instead of "<anonymous>" or the like. */
11706 if (DECL_NAME (TYPE_NAME (type)))
11707 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11710 /* Now get the name as a string, or invent one. */
11711 if (!name && t != 0)
11712 name = IDENTIFIER_POINTER (t);
11715 return (name == 0 || *name == '\0') ? 0 : name;
11718 /* Return the type associated with a data member, make a special check
11719 for bit field types. */
11722 member_declared_type (const_tree member)
11724 return (DECL_BIT_FIELD_TYPE (member)
11725 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11728 /* Get the decl's label, as described by its RTL. This may be different
11729 from the DECL_NAME name used in the source file. */
11732 static const char *
11733 decl_start_label (tree decl)
11736 const char *fnname;
11738 x = DECL_RTL (decl);
11739 gcc_assert (MEM_P (x));
11742 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11744 fnname = XSTR (x, 0);
11749 /* These routines generate the internal representation of the DIE's for
11750 the compilation unit. Debugging information is collected by walking
11751 the declaration trees passed in from dwarf2out_decl(). */
11754 gen_array_type_die (tree type, dw_die_ref context_die)
11756 dw_die_ref scope_die = scope_die_for (type, context_die);
11757 dw_die_ref array_die;
11759 /* GNU compilers represent multidimensional array types as sequences of one
11760 dimensional array types whose element types are themselves array types.
11761 We sometimes squish that down to a single array_type DIE with multiple
11762 subscripts in the Dwarf debugging info. The draft Dwarf specification
11763 say that we are allowed to do this kind of compression in C, because
11764 there is no difference between an array of arrays and a multidimensional
11765 array. We don't do this for Ada to remain as close as possible to the
11766 actual representation, which is especially important against the language
11767 flexibilty wrt arrays of variable size. */
11769 bool collapse_nested_arrays = !is_ada ();
11772 /* ??? The SGI dwarf reader fails for array of array of enum types
11773 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
11774 array type comes before the outer array type. We thus call gen_type_die
11775 before we new_die and must prevent nested array types collapsing for this
11778 #ifdef MIPS_DEBUGGING_INFO
11779 gen_type_die (TREE_TYPE (type), context_die);
11780 collapse_nested_arrays = false;
11783 array_die = new_die (DW_TAG_array_type, scope_die, type);
11784 add_name_attribute (array_die, type_tag (type));
11785 equate_type_number_to_die (type, array_die);
11787 if (TREE_CODE (type) == VECTOR_TYPE)
11789 /* The frontend feeds us a representation for the vector as a struct
11790 containing an array. Pull out the array type. */
11791 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11792 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11795 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11797 && TREE_CODE (type) == ARRAY_TYPE
11798 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
11799 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11802 /* We default the array ordering. SDB will probably do
11803 the right things even if DW_AT_ordering is not present. It's not even
11804 an issue until we start to get into multidimensional arrays anyway. If
11805 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11806 then we'll have to put the DW_AT_ordering attribute back in. (But if
11807 and when we find out that we need to put these in, we will only do so
11808 for multidimensional arrays. */
11809 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11812 #ifdef MIPS_DEBUGGING_INFO
11813 /* The SGI compilers handle arrays of unknown bound by setting
11814 AT_declaration and not emitting any subrange DIEs. */
11815 if (! TYPE_DOMAIN (type))
11816 add_AT_flag (array_die, DW_AT_declaration, 1);
11819 add_subscript_info (array_die, type, collapse_nested_arrays);
11821 /* Add representation of the type of the elements of this array type and
11822 emit the corresponding DIE if we haven't done it already. */
11823 element_type = TREE_TYPE (type);
11824 if (collapse_nested_arrays)
11825 while (TREE_CODE (element_type) == ARRAY_TYPE)
11826 element_type = TREE_TYPE (element_type);
11828 #ifndef MIPS_DEBUGGING_INFO
11829 gen_type_die (element_type, context_die);
11832 add_type_attribute (array_die, element_type, 0, 0, context_die);
11834 if (get_AT (array_die, DW_AT_name))
11835 add_pubtype (type, array_die);
11838 static dw_loc_descr_ref
11839 descr_info_loc (tree val, tree base_decl)
11841 HOST_WIDE_INT size;
11842 dw_loc_descr_ref loc, loc2;
11843 enum dwarf_location_atom op;
11845 if (val == base_decl)
11846 return new_loc_descr (DW_OP_push_object_address, 0, 0);
11848 switch (TREE_CODE (val))
11851 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11853 if (host_integerp (val, 0))
11854 return int_loc_descriptor (tree_low_cst (val, 0));
11857 size = int_size_in_bytes (TREE_TYPE (val));
11860 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11863 if (size == DWARF2_ADDR_SIZE)
11864 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
11866 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
11868 case POINTER_PLUS_EXPR:
11870 if (host_integerp (TREE_OPERAND (val, 1), 1)
11871 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
11874 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11877 add_loc_descr (&loc,
11878 new_loc_descr (DW_OP_plus_uconst,
11879 tree_low_cst (TREE_OPERAND (val, 1),
11886 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11889 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
11892 add_loc_descr (&loc, loc2);
11893 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
11915 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
11916 tree val, tree base_decl)
11918 dw_loc_descr_ref loc;
11920 if (host_integerp (val, 0))
11922 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
11926 loc = descr_info_loc (val, base_decl);
11930 add_AT_loc (die, attr, loc);
11933 /* This routine generates DIE for array with hidden descriptor, details
11934 are filled into *info by a langhook. */
11937 gen_descr_array_type_die (tree type, struct array_descr_info *info,
11938 dw_die_ref context_die)
11940 dw_die_ref scope_die = scope_die_for (type, context_die);
11941 dw_die_ref array_die;
11944 array_die = new_die (DW_TAG_array_type, scope_die, type);
11945 add_name_attribute (array_die, type_tag (type));
11946 equate_type_number_to_die (type, array_die);
11948 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11950 && info->ndimensions >= 2)
11951 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11953 if (info->data_location)
11954 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
11956 if (info->associated)
11957 add_descr_info_field (array_die, DW_AT_associated, info->associated,
11959 if (info->allocated)
11960 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
11963 for (dim = 0; dim < info->ndimensions; dim++)
11965 dw_die_ref subrange_die
11966 = new_die (DW_TAG_subrange_type, array_die, NULL);
11968 if (info->dimen[dim].lower_bound)
11970 /* If it is the default value, omit it. */
11971 if ((is_c_family () || is_java ())
11972 && integer_zerop (info->dimen[dim].lower_bound))
11974 else if (is_fortran ()
11975 && integer_onep (info->dimen[dim].lower_bound))
11978 add_descr_info_field (subrange_die, DW_AT_lower_bound,
11979 info->dimen[dim].lower_bound,
11982 if (info->dimen[dim].upper_bound)
11983 add_descr_info_field (subrange_die, DW_AT_upper_bound,
11984 info->dimen[dim].upper_bound,
11986 if (info->dimen[dim].stride)
11987 add_descr_info_field (subrange_die, DW_AT_byte_stride,
11988 info->dimen[dim].stride,
11992 gen_type_die (info->element_type, context_die);
11993 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
11995 if (get_AT (array_die, DW_AT_name))
11996 add_pubtype (type, array_die);
12001 gen_entry_point_die (tree decl, dw_die_ref context_die)
12003 tree origin = decl_ultimate_origin (decl);
12004 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
12006 if (origin != NULL)
12007 add_abstract_origin_attribute (decl_die, origin);
12010 add_name_and_src_coords_attributes (decl_die, decl);
12011 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
12012 0, 0, context_die);
12015 if (DECL_ABSTRACT (decl))
12016 equate_decl_number_to_die (decl, decl_die);
12018 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12022 /* Walk through the list of incomplete types again, trying once more to
12023 emit full debugging info for them. */
12026 retry_incomplete_types (void)
12030 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12031 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12034 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12037 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12039 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12041 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12042 be incomplete and such types are not marked. */
12043 add_abstract_origin_attribute (type_die, type);
12046 /* Determine what tag to use for a record type. */
12048 static enum dwarf_tag
12049 record_type_tag (tree type)
12051 if (! lang_hooks.types.classify_record)
12052 return DW_TAG_structure_type;
12054 switch (lang_hooks.types.classify_record (type))
12056 case RECORD_IS_STRUCT:
12057 return DW_TAG_structure_type;
12059 case RECORD_IS_CLASS:
12060 return DW_TAG_class_type;
12062 case RECORD_IS_INTERFACE:
12063 return DW_TAG_interface_type;
12066 gcc_unreachable ();
12070 /* Generate a DIE to represent an inlined instance of a structure type. */
12073 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12075 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12077 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12078 be incomplete and such types are not marked. */
12079 add_abstract_origin_attribute (type_die, type);
12082 /* Generate a DIE to represent an inlined instance of a union type. */
12085 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12087 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12089 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12090 be incomplete and such types are not marked. */
12091 add_abstract_origin_attribute (type_die, type);
12094 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12095 include all of the information about the enumeration values also. Each
12096 enumerated type name/value is listed as a child of the enumerated type
12100 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12102 dw_die_ref type_die = lookup_type_die (type);
12104 if (type_die == NULL)
12106 type_die = new_die (DW_TAG_enumeration_type,
12107 scope_die_for (type, context_die), type);
12108 equate_type_number_to_die (type, type_die);
12109 add_name_attribute (type_die, type_tag (type));
12111 else if (! TYPE_SIZE (type))
12114 remove_AT (type_die, DW_AT_declaration);
12116 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12117 given enum type is incomplete, do not generate the DW_AT_byte_size
12118 attribute or the DW_AT_element_list attribute. */
12119 if (TYPE_SIZE (type))
12123 TREE_ASM_WRITTEN (type) = 1;
12124 add_byte_size_attribute (type_die, type);
12125 if (TYPE_STUB_DECL (type) != NULL_TREE)
12126 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12128 /* If the first reference to this type was as the return type of an
12129 inline function, then it may not have a parent. Fix this now. */
12130 if (type_die->die_parent == NULL)
12131 add_child_die (scope_die_for (type, context_die), type_die);
12133 for (link = TYPE_VALUES (type);
12134 link != NULL; link = TREE_CHAIN (link))
12136 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12137 tree value = TREE_VALUE (link);
12139 add_name_attribute (enum_die,
12140 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12142 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12143 /* DWARF2 does not provide a way of indicating whether or
12144 not enumeration constants are signed or unsigned. GDB
12145 always assumes the values are signed, so we output all
12146 values as if they were signed. That means that
12147 enumeration constants with very large unsigned values
12148 will appear to have negative values in the debugger. */
12149 add_AT_int (enum_die, DW_AT_const_value,
12150 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12154 add_AT_flag (type_die, DW_AT_declaration, 1);
12156 if (get_AT (type_die, DW_AT_name))
12157 add_pubtype (type, type_die);
12162 /* Generate a DIE to represent either a real live formal parameter decl or to
12163 represent just the type of some formal parameter position in some function
12166 Note that this routine is a bit unusual because its argument may be a
12167 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12168 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12169 node. If it's the former then this function is being called to output a
12170 DIE to represent a formal parameter object (or some inlining thereof). If
12171 it's the latter, then this function is only being called to output a
12172 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12173 argument type of some subprogram type. */
12176 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12178 dw_die_ref parm_die
12179 = new_die (DW_TAG_formal_parameter, context_die, node);
12182 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12184 case tcc_declaration:
12185 origin = decl_ultimate_origin (node);
12186 if (origin != NULL)
12187 add_abstract_origin_attribute (parm_die, origin);
12190 tree type = TREE_TYPE (node);
12191 add_name_and_src_coords_attributes (parm_die, node);
12192 if (DECL_BY_REFERENCE (node))
12193 type = TREE_TYPE (type);
12194 add_type_attribute (parm_die, type,
12195 TREE_READONLY (node),
12196 TREE_THIS_VOLATILE (node),
12198 if (DECL_ARTIFICIAL (node))
12199 add_AT_flag (parm_die, DW_AT_artificial, 1);
12202 equate_decl_number_to_die (node, parm_die);
12203 if (! DECL_ABSTRACT (node))
12204 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12209 /* We were called with some kind of a ..._TYPE node. */
12210 add_type_attribute (parm_die, node, 0, 0, context_die);
12214 gcc_unreachable ();
12220 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12221 at the end of an (ANSI prototyped) formal parameters list. */
12224 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12226 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12229 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12230 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12231 parameters as specified in some function type specification (except for
12232 those which appear as part of a function *definition*). */
12235 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12238 tree formal_type = NULL;
12239 tree first_parm_type;
12242 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12244 arg = DECL_ARGUMENTS (function_or_method_type);
12245 function_or_method_type = TREE_TYPE (function_or_method_type);
12250 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
12252 /* Make our first pass over the list of formal parameter types and output a
12253 DW_TAG_formal_parameter DIE for each one. */
12254 for (link = first_parm_type; link; )
12256 dw_die_ref parm_die;
12258 formal_type = TREE_VALUE (link);
12259 if (formal_type == void_type_node)
12262 /* Output a (nameless) DIE to represent the formal parameter itself. */
12263 parm_die = gen_formal_parameter_die (formal_type, context_die);
12264 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
12265 && link == first_parm_type)
12266 || (arg && DECL_ARTIFICIAL (arg)))
12267 add_AT_flag (parm_die, DW_AT_artificial, 1);
12269 link = TREE_CHAIN (link);
12271 arg = TREE_CHAIN (arg);
12274 /* If this function type has an ellipsis, add a
12275 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12276 if (formal_type != void_type_node)
12277 gen_unspecified_parameters_die (function_or_method_type, context_die);
12279 /* Make our second (and final) pass over the list of formal parameter types
12280 and output DIEs to represent those types (as necessary). */
12281 for (link = TYPE_ARG_TYPES (function_or_method_type);
12282 link && TREE_VALUE (link);
12283 link = TREE_CHAIN (link))
12284 gen_type_die (TREE_VALUE (link), context_die);
12287 /* We want to generate the DIE for TYPE so that we can generate the
12288 die for MEMBER, which has been defined; we will need to refer back
12289 to the member declaration nested within TYPE. If we're trying to
12290 generate minimal debug info for TYPE, processing TYPE won't do the
12291 trick; we need to attach the member declaration by hand. */
12294 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
12296 gen_type_die (type, context_die);
12298 /* If we're trying to avoid duplicate debug info, we may not have
12299 emitted the member decl for this function. Emit it now. */
12300 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
12301 && ! lookup_decl_die (member))
12303 dw_die_ref type_die;
12304 gcc_assert (!decl_ultimate_origin (member));
12306 push_decl_scope (type);
12307 type_die = lookup_type_die (type);
12308 if (TREE_CODE (member) == FUNCTION_DECL)
12309 gen_subprogram_die (member, type_die);
12310 else if (TREE_CODE (member) == FIELD_DECL)
12312 /* Ignore the nameless fields that are used to skip bits but handle
12313 C++ anonymous unions and structs. */
12314 if (DECL_NAME (member) != NULL_TREE
12315 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
12316 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
12318 gen_type_die (member_declared_type (member), type_die);
12319 gen_field_die (member, type_die);
12323 gen_variable_die (member, type_die);
12329 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12330 may later generate inlined and/or out-of-line instances of. */
12333 dwarf2out_abstract_function (tree decl)
12335 dw_die_ref old_die;
12338 int was_abstract = DECL_ABSTRACT (decl);
12340 /* Make sure we have the actual abstract inline, not a clone. */
12341 decl = DECL_ORIGIN (decl);
12343 old_die = lookup_decl_die (decl);
12344 if (old_die && get_AT (old_die, DW_AT_inline))
12345 /* We've already generated the abstract instance. */
12348 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12349 we don't get confused by DECL_ABSTRACT. */
12350 if (debug_info_level > DINFO_LEVEL_TERSE)
12352 context = decl_class_context (decl);
12354 gen_type_die_for_member
12355 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
12358 /* Pretend we've just finished compiling this function. */
12359 save_fn = current_function_decl;
12360 current_function_decl = decl;
12361 push_cfun (DECL_STRUCT_FUNCTION (decl));
12363 set_decl_abstract_flags (decl, 1);
12364 dwarf2out_decl (decl);
12365 if (! was_abstract)
12366 set_decl_abstract_flags (decl, 0);
12368 current_function_decl = save_fn;
12372 /* Helper function of premark_used_types() which gets called through
12373 htab_traverse_resize().
12375 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12376 marked as unused by prune_unused_types. */
12378 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
12383 type = (tree) *slot;
12384 die = lookup_type_die (type);
12386 die->die_perennial_p = 1;
12390 /* Mark all members of used_types_hash as perennial. */
12392 premark_used_types (void)
12394 if (cfun && cfun->used_types_hash)
12395 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
12398 /* Generate a DIE to represent a declared function (either file-scope or
12402 gen_subprogram_die (tree decl, dw_die_ref context_die)
12404 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12405 tree origin = decl_ultimate_origin (decl);
12406 dw_die_ref subr_die;
12409 dw_die_ref old_die = lookup_decl_die (decl);
12410 int declaration = (current_function_decl != decl
12411 || class_or_namespace_scope_p (context_die));
12413 premark_used_types ();
12415 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12416 started to generate the abstract instance of an inline, decided to output
12417 its containing class, and proceeded to emit the declaration of the inline
12418 from the member list for the class. If so, DECLARATION takes priority;
12419 we'll get back to the abstract instance when done with the class. */
12421 /* The class-scope declaration DIE must be the primary DIE. */
12422 if (origin && declaration && class_or_namespace_scope_p (context_die))
12425 gcc_assert (!old_die);
12428 /* Now that the C++ front end lazily declares artificial member fns, we
12429 might need to retrofit the declaration into its class. */
12430 if (!declaration && !origin && !old_die
12431 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
12432 && !class_or_namespace_scope_p (context_die)
12433 && debug_info_level > DINFO_LEVEL_TERSE)
12434 old_die = force_decl_die (decl);
12436 if (origin != NULL)
12438 gcc_assert (!declaration || local_scope_p (context_die));
12440 /* Fixup die_parent for the abstract instance of a nested
12441 inline function. */
12442 if (old_die && old_die->die_parent == NULL)
12443 add_child_die (context_die, old_die);
12445 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12446 add_abstract_origin_attribute (subr_die, origin);
12450 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12451 struct dwarf_file_data * file_index = lookup_filename (s.file);
12453 if (!get_AT_flag (old_die, DW_AT_declaration)
12454 /* We can have a normal definition following an inline one in the
12455 case of redefinition of GNU C extern inlines.
12456 It seems reasonable to use AT_specification in this case. */
12457 && !get_AT (old_die, DW_AT_inline))
12459 /* Detect and ignore this case, where we are trying to output
12460 something we have already output. */
12464 /* If the definition comes from the same place as the declaration,
12465 maybe use the old DIE. We always want the DIE for this function
12466 that has the *_pc attributes to be under comp_unit_die so the
12467 debugger can find it. We also need to do this for abstract
12468 instances of inlines, since the spec requires the out-of-line copy
12469 to have the same parent. For local class methods, this doesn't
12470 apply; we just use the old DIE. */
12471 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12472 && (DECL_ARTIFICIAL (decl)
12473 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12474 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12475 == (unsigned) s.line))))
12477 subr_die = old_die;
12479 /* Clear out the declaration attribute and the formal parameters.
12480 Do not remove all children, because it is possible that this
12481 declaration die was forced using force_decl_die(). In such
12482 cases die that forced declaration die (e.g. TAG_imported_module)
12483 is one of the children that we do not want to remove. */
12484 remove_AT (subr_die, DW_AT_declaration);
12485 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12489 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12490 add_AT_specification (subr_die, old_die);
12491 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12492 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12493 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12494 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12499 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12501 if (TREE_PUBLIC (decl))
12502 add_AT_flag (subr_die, DW_AT_external, 1);
12504 add_name_and_src_coords_attributes (subr_die, decl);
12505 if (debug_info_level > DINFO_LEVEL_TERSE)
12507 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12508 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12509 0, 0, context_die);
12512 add_pure_or_virtual_attribute (subr_die, decl);
12513 if (DECL_ARTIFICIAL (decl))
12514 add_AT_flag (subr_die, DW_AT_artificial, 1);
12516 if (TREE_PROTECTED (decl))
12517 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12518 else if (TREE_PRIVATE (decl))
12519 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12524 if (!old_die || !get_AT (old_die, DW_AT_inline))
12526 add_AT_flag (subr_die, DW_AT_declaration, 1);
12528 /* The first time we see a member function, it is in the context of
12529 the class to which it belongs. We make sure of this by emitting
12530 the class first. The next time is the definition, which is
12531 handled above. The two may come from the same source text.
12533 Note that force_decl_die() forces function declaration die. It is
12534 later reused to represent definition. */
12535 equate_decl_number_to_die (decl, subr_die);
12538 else if (DECL_ABSTRACT (decl))
12540 if (DECL_DECLARED_INLINE_P (decl))
12542 if (cgraph_function_possibly_inlined_p (decl))
12543 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12545 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12549 if (cgraph_function_possibly_inlined_p (decl))
12550 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12552 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12555 if (DECL_DECLARED_INLINE_P (decl)
12556 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
12557 add_AT_flag (subr_die, DW_AT_artificial, 1);
12559 equate_decl_number_to_die (decl, subr_die);
12561 else if (!DECL_EXTERNAL (decl))
12563 HOST_WIDE_INT cfa_fb_offset;
12565 if (!old_die || !get_AT (old_die, DW_AT_inline))
12566 equate_decl_number_to_die (decl, subr_die);
12568 if (!flag_reorder_blocks_and_partition)
12570 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
12571 current_function_funcdef_no);
12572 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
12573 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12574 current_function_funcdef_no);
12575 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
12577 add_pubname (decl, subr_die);
12578 add_arange (decl, subr_die);
12581 { /* Do nothing for now; maybe need to duplicate die, one for
12582 hot section and one for cold section, then use the hot/cold
12583 section begin/end labels to generate the aranges... */
12585 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12586 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12587 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12588 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12590 add_pubname (decl, subr_die);
12591 add_arange (decl, subr_die);
12592 add_arange (decl, subr_die);
12596 #ifdef MIPS_DEBUGGING_INFO
12597 /* Add a reference to the FDE for this routine. */
12598 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
12601 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
12603 /* We define the "frame base" as the function's CFA. This is more
12604 convenient for several reasons: (1) It's stable across the prologue
12605 and epilogue, which makes it better than just a frame pointer,
12606 (2) With dwarf3, there exists a one-byte encoding that allows us
12607 to reference the .debug_frame data by proxy, but failing that,
12608 (3) We can at least reuse the code inspection and interpretation
12609 code that determines the CFA position at various points in the
12611 /* ??? Use some command-line or configury switch to enable the use
12612 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12613 consumers that understand it; fall back to "pure" dwarf2 and
12614 convert the CFA data into a location list. */
12616 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
12617 if (list->dw_loc_next)
12618 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12620 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12623 /* Compute a displacement from the "steady-state frame pointer" to
12624 the CFA. The former is what all stack slots and argument slots
12625 will reference in the rtl; the later is what we've told the
12626 debugger about. We'll need to adjust all frame_base references
12627 by this displacement. */
12628 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12630 if (cfun->static_chain_decl)
12631 add_AT_location_description (subr_die, DW_AT_static_link,
12632 loc_descriptor_from_tree (cfun->static_chain_decl));
12635 /* Now output descriptions of the arguments for this function. This gets
12636 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12637 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12638 `...' at the end of the formal parameter list. In order to find out if
12639 there was a trailing ellipsis or not, we must instead look at the type
12640 associated with the FUNCTION_DECL. This will be a node of type
12641 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12642 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12643 an ellipsis at the end. */
12645 /* In the case where we are describing a mere function declaration, all we
12646 need to do here (and all we *can* do here) is to describe the *types* of
12647 its formal parameters. */
12648 if (debug_info_level <= DINFO_LEVEL_TERSE)
12650 else if (declaration)
12651 gen_formal_types_die (decl, subr_die);
12654 /* Generate DIEs to represent all known formal parameters. */
12655 tree arg_decls = DECL_ARGUMENTS (decl);
12658 /* When generating DIEs, generate the unspecified_parameters DIE
12659 instead if we come across the arg "__builtin_va_alist" */
12660 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12661 if (TREE_CODE (parm) == PARM_DECL)
12663 if (DECL_NAME (parm)
12664 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12665 "__builtin_va_alist"))
12666 gen_unspecified_parameters_die (parm, subr_die);
12668 gen_decl_die (parm, subr_die);
12671 /* Decide whether we need an unspecified_parameters DIE at the end.
12672 There are 2 more cases to do this for: 1) the ansi ... declaration -
12673 this is detectable when the end of the arg list is not a
12674 void_type_node 2) an unprototyped function declaration (not a
12675 definition). This just means that we have no info about the
12676 parameters at all. */
12677 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12678 if (fn_arg_types != NULL)
12680 /* This is the prototyped case, check for.... */
12681 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12682 gen_unspecified_parameters_die (decl, subr_die);
12684 else if (DECL_INITIAL (decl) == NULL_TREE)
12685 gen_unspecified_parameters_die (decl, subr_die);
12688 /* Output Dwarf info for all of the stuff within the body of the function
12689 (if it has one - it may be just a declaration). */
12690 outer_scope = DECL_INITIAL (decl);
12692 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12693 a function. This BLOCK actually represents the outermost binding contour
12694 for the function, i.e. the contour in which the function's formal
12695 parameters and labels get declared. Curiously, it appears that the front
12696 end doesn't actually put the PARM_DECL nodes for the current function onto
12697 the BLOCK_VARS list for this outer scope, but are strung off of the
12698 DECL_ARGUMENTS list for the function instead.
12700 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12701 the LABEL_DECL nodes for the function however, and we output DWARF info
12702 for those in decls_for_scope. Just within the `outer_scope' there will be
12703 a BLOCK node representing the function's outermost pair of curly braces,
12704 and any blocks used for the base and member initializers of a C++
12705 constructor function. */
12706 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12708 /* Emit a DW_TAG_variable DIE for a named return value. */
12709 if (DECL_NAME (DECL_RESULT (decl)))
12710 gen_decl_die (DECL_RESULT (decl), subr_die);
12712 current_function_has_inlines = 0;
12713 decls_for_scope (outer_scope, subr_die, 0);
12715 #if 0 && defined (MIPS_DEBUGGING_INFO)
12716 if (current_function_has_inlines)
12718 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12719 if (! comp_unit_has_inlines)
12721 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12722 comp_unit_has_inlines = 1;
12727 /* Add the calling convention attribute if requested. */
12728 add_calling_convention_attribute (subr_die, decl);
12732 /* Generate a DIE to represent a declared data object. */
12735 gen_variable_die (tree decl, dw_die_ref context_die)
12739 dw_die_ref var_die;
12740 tree origin = decl_ultimate_origin (decl);
12741 dw_die_ref old_die = lookup_decl_die (decl);
12742 int declaration = (DECL_EXTERNAL (decl)
12743 /* If DECL is COMDAT and has not actually been
12744 emitted, we cannot take its address; there
12745 might end up being no definition anywhere in
12746 the program. For example, consider the C++
12750 struct S { static const int i = 7; };
12755 int f() { return S<int>::i; }
12757 Here, S<int>::i is not DECL_EXTERNAL, but no
12758 definition is required, so the compiler will
12759 not emit a definition. */
12760 || (TREE_CODE (decl) == VAR_DECL
12761 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12762 || class_or_namespace_scope_p (context_die));
12764 com_decl = fortran_common (decl, &off);
12766 /* Symbol in common gets emitted as a child of the common block, in the form
12769 ??? This creates a new common block die for every common block symbol.
12770 Better to share same common block die for all symbols in that block. */
12774 dw_die_ref com_die;
12775 const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
12776 dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl);
12778 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
12779 var_die = new_die (DW_TAG_common_block, context_die, decl);
12780 add_name_and_src_coords_attributes (var_die, field);
12781 add_AT_flag (var_die, DW_AT_external, 1);
12782 add_AT_loc (var_die, DW_AT_location, loc);
12783 com_die = new_die (DW_TAG_member, var_die, decl);
12784 add_name_and_src_coords_attributes (com_die, decl);
12785 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
12786 TREE_THIS_VOLATILE (decl), context_die);
12787 add_AT_loc (com_die, DW_AT_data_member_location,
12788 int_loc_descriptor (off));
12789 add_pubname_string (cnam, var_die); /* ??? needed? */
12793 var_die = new_die (DW_TAG_variable, context_die, decl);
12795 if (origin != NULL)
12796 add_abstract_origin_attribute (var_die, origin);
12798 /* Loop unrolling can create multiple blocks that refer to the same
12799 static variable, so we must test for the DW_AT_declaration flag.
12801 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12802 copy decls and set the DECL_ABSTRACT flag on them instead of
12805 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12807 ??? The declare_in_namespace support causes us to get two DIEs for one
12808 variable, both of which are declarations. We want to avoid considering
12809 one to be a specification, so we must test that this DIE is not a
12811 else if (old_die && TREE_STATIC (decl) && ! declaration
12812 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12814 /* This is a definition of a C++ class level static. */
12815 add_AT_specification (var_die, old_die);
12816 if (DECL_NAME (decl))
12818 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12819 struct dwarf_file_data * file_index = lookup_filename (s.file);
12821 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12822 add_AT_file (var_die, DW_AT_decl_file, file_index);
12824 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12825 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12830 tree type = TREE_TYPE (decl);
12831 if ((TREE_CODE (decl) == PARM_DECL
12832 || TREE_CODE (decl) == RESULT_DECL)
12833 && DECL_BY_REFERENCE (decl))
12834 type = TREE_TYPE (type);
12836 add_name_and_src_coords_attributes (var_die, decl);
12837 add_type_attribute (var_die, type, TREE_READONLY (decl),
12838 TREE_THIS_VOLATILE (decl), context_die);
12840 if (TREE_PUBLIC (decl))
12841 add_AT_flag (var_die, DW_AT_external, 1);
12843 if (DECL_ARTIFICIAL (decl))
12844 add_AT_flag (var_die, DW_AT_artificial, 1);
12846 if (TREE_PROTECTED (decl))
12847 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12848 else if (TREE_PRIVATE (decl))
12849 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12853 add_AT_flag (var_die, DW_AT_declaration, 1);
12855 if (DECL_ABSTRACT (decl) || declaration)
12856 equate_decl_number_to_die (decl, var_die);
12858 if (! declaration && ! DECL_ABSTRACT (decl))
12860 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12861 add_pubname (decl, var_die);
12864 tree_add_const_value_attribute (var_die, decl);
12867 /* Generate a DIE to represent a label identifier. */
12870 gen_label_die (tree decl, dw_die_ref context_die)
12872 tree origin = decl_ultimate_origin (decl);
12873 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12875 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12877 if (origin != NULL)
12878 add_abstract_origin_attribute (lbl_die, origin);
12880 add_name_and_src_coords_attributes (lbl_die, decl);
12882 if (DECL_ABSTRACT (decl))
12883 equate_decl_number_to_die (decl, lbl_die);
12886 insn = DECL_RTL_IF_SET (decl);
12888 /* Deleted labels are programmer specified labels which have been
12889 eliminated because of various optimizations. We still emit them
12890 here so that it is possible to put breakpoints on them. */
12894 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12896 /* When optimization is enabled (via -O) some parts of the compiler
12897 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12898 represent source-level labels which were explicitly declared by
12899 the user. This really shouldn't be happening though, so catch
12900 it if it ever does happen. */
12901 gcc_assert (!INSN_DELETED_P (insn));
12903 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12904 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12909 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12910 attributes to the DIE for a block STMT, to describe where the inlined
12911 function was called from. This is similar to add_src_coords_attributes. */
12914 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12916 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12918 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12919 add_AT_unsigned (die, DW_AT_call_line, s.line);
12923 /* If STMT's abstract origin is a function declaration and STMT's
12924 first subblock's abstract origin is the function's outermost block,
12925 then we're looking at the main entry point. */
12927 is_inlined_entry_point (const_tree stmt)
12931 if (!stmt || TREE_CODE (stmt) != BLOCK)
12934 decl = block_ultimate_origin (stmt);
12936 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12939 block = BLOCK_SUBBLOCKS (stmt);
12943 if (TREE_CODE (block) != BLOCK)
12946 block = block_ultimate_origin (block);
12949 return block == DECL_INITIAL (decl);
12952 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12953 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12956 add_high_low_attributes (tree stmt, dw_die_ref die)
12958 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12960 if (BLOCK_FRAGMENT_CHAIN (stmt))
12964 if (is_inlined_entry_point (stmt))
12966 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12967 BLOCK_NUMBER (stmt));
12968 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12971 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12973 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12976 add_ranges (chain);
12977 chain = BLOCK_FRAGMENT_CHAIN (chain);
12984 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12985 BLOCK_NUMBER (stmt));
12986 add_AT_lbl_id (die, DW_AT_low_pc, label);
12987 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12988 BLOCK_NUMBER (stmt));
12989 add_AT_lbl_id (die, DW_AT_high_pc, label);
12993 /* Generate a DIE for a lexical block. */
12996 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12998 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
13000 if (! BLOCK_ABSTRACT (stmt))
13001 add_high_low_attributes (stmt, stmt_die);
13003 decls_for_scope (stmt, stmt_die, depth);
13006 /* Generate a DIE for an inlined subprogram. */
13009 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
13011 tree decl = block_ultimate_origin (stmt);
13013 /* Emit info for the abstract instance first, if we haven't yet. We
13014 must emit this even if the block is abstract, otherwise when we
13015 emit the block below (or elsewhere), we may end up trying to emit
13016 a die whose origin die hasn't been emitted, and crashing. */
13017 dwarf2out_abstract_function (decl);
13019 if (! BLOCK_ABSTRACT (stmt))
13021 dw_die_ref subr_die
13022 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13024 add_abstract_origin_attribute (subr_die, decl);
13025 add_high_low_attributes (stmt, subr_die);
13026 add_call_src_coords_attributes (stmt, subr_die);
13028 decls_for_scope (stmt, subr_die, depth);
13029 current_function_has_inlines = 1;
13032 /* We may get here if we're the outer block of function A that was
13033 inlined into function B that was inlined into function C. When
13034 generating debugging info for C, dwarf2out_abstract_function(B)
13035 would mark all inlined blocks as abstract, including this one.
13036 So, we wouldn't (and shouldn't) expect labels to be generated
13037 for this one. Instead, just emit debugging info for
13038 declarations within the block. This is particularly important
13039 in the case of initializers of arguments passed from B to us:
13040 if they're statement expressions containing declarations, we
13041 wouldn't generate dies for their abstract variables, and then,
13042 when generating dies for the real variables, we'd die (pun
13044 gen_lexical_block_die (stmt, context_die, depth);
13047 /* Generate a DIE for a field in a record, or structure. */
13050 gen_field_die (tree decl, dw_die_ref context_die)
13052 dw_die_ref decl_die;
13054 if (TREE_TYPE (decl) == error_mark_node)
13057 decl_die = new_die (DW_TAG_member, context_die, decl);
13058 add_name_and_src_coords_attributes (decl_die, decl);
13059 add_type_attribute (decl_die, member_declared_type (decl),
13060 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13063 if (DECL_BIT_FIELD_TYPE (decl))
13065 add_byte_size_attribute (decl_die, decl);
13066 add_bit_size_attribute (decl_die, decl);
13067 add_bit_offset_attribute (decl_die, decl);
13070 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13071 add_data_member_location_attribute (decl_die, decl);
13073 if (DECL_ARTIFICIAL (decl))
13074 add_AT_flag (decl_die, DW_AT_artificial, 1);
13076 if (TREE_PROTECTED (decl))
13077 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13078 else if (TREE_PRIVATE (decl))
13079 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13081 /* Equate decl number to die, so that we can look up this decl later on. */
13082 equate_decl_number_to_die (decl, decl_die);
13086 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13087 Use modified_type_die instead.
13088 We keep this code here just in case these types of DIEs may be needed to
13089 represent certain things in other languages (e.g. Pascal) someday. */
13092 gen_pointer_type_die (tree type, dw_die_ref context_die)
13095 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13097 equate_type_number_to_die (type, ptr_die);
13098 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13099 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13102 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13103 Use modified_type_die instead.
13104 We keep this code here just in case these types of DIEs may be needed to
13105 represent certain things in other languages (e.g. Pascal) someday. */
13108 gen_reference_type_die (tree type, dw_die_ref context_die)
13111 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13113 equate_type_number_to_die (type, ref_die);
13114 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13115 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13119 /* Generate a DIE for a pointer to a member type. */
13122 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
13125 = new_die (DW_TAG_ptr_to_member_type,
13126 scope_die_for (type, context_die), type);
13128 equate_type_number_to_die (type, ptr_die);
13129 add_AT_die_ref (ptr_die, DW_AT_containing_type,
13130 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
13131 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13134 /* Generate the DIE for the compilation unit. */
13137 gen_compile_unit_die (const char *filename)
13140 char producer[250];
13141 const char *language_string = lang_hooks.name;
13144 die = new_die (DW_TAG_compile_unit, NULL, NULL);
13148 add_name_attribute (die, filename);
13149 /* Don't add cwd for <built-in>. */
13150 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
13151 add_comp_dir_attribute (die);
13154 sprintf (producer, "%s %s", language_string, version_string);
13156 #ifdef MIPS_DEBUGGING_INFO
13157 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13158 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13159 not appear in the producer string, the debugger reaches the conclusion
13160 that the object file is stripped and has no debugging information.
13161 To get the MIPS/SGI debugger to believe that there is debugging
13162 information in the object file, we add a -g to the producer string. */
13163 if (debug_info_level > DINFO_LEVEL_TERSE)
13164 strcat (producer, " -g");
13167 add_AT_string (die, DW_AT_producer, producer);
13169 if (strcmp (language_string, "GNU C++") == 0)
13170 language = DW_LANG_C_plus_plus;
13171 else if (strcmp (language_string, "GNU Ada") == 0)
13172 language = DW_LANG_Ada95;
13173 else if (strcmp (language_string, "GNU F77") == 0)
13174 language = DW_LANG_Fortran77;
13175 else if (strcmp (language_string, "GNU Fortran") == 0)
13176 language = DW_LANG_Fortran95;
13177 else if (strcmp (language_string, "GNU Pascal") == 0)
13178 language = DW_LANG_Pascal83;
13179 else if (strcmp (language_string, "GNU Java") == 0)
13180 language = DW_LANG_Java;
13181 else if (strcmp (language_string, "GNU Objective-C") == 0)
13182 language = DW_LANG_ObjC;
13183 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13184 language = DW_LANG_ObjC_plus_plus;
13186 language = DW_LANG_C89;
13188 add_AT_unsigned (die, DW_AT_language, language);
13192 /* Generate the DIE for a base class. */
13195 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13197 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13199 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13200 add_data_member_location_attribute (die, binfo);
13202 if (BINFO_VIRTUAL_P (binfo))
13203 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13205 if (access == access_public_node)
13206 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13207 else if (access == access_protected_node)
13208 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13211 /* Generate a DIE for a class member. */
13214 gen_member_die (tree type, dw_die_ref context_die)
13217 tree binfo = TYPE_BINFO (type);
13220 /* If this is not an incomplete type, output descriptions of each of its
13221 members. Note that as we output the DIEs necessary to represent the
13222 members of this record or union type, we will also be trying to output
13223 DIEs to represent the *types* of those members. However the `type'
13224 function (above) will specifically avoid generating type DIEs for member
13225 types *within* the list of member DIEs for this (containing) type except
13226 for those types (of members) which are explicitly marked as also being
13227 members of this (containing) type themselves. The g++ front- end can
13228 force any given type to be treated as a member of some other (containing)
13229 type by setting the TYPE_CONTEXT of the given (member) type to point to
13230 the TREE node representing the appropriate (containing) type. */
13232 /* First output info about the base classes. */
13235 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13239 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13240 gen_inheritance_die (base,
13241 (accesses ? VEC_index (tree, accesses, i)
13242 : access_public_node), context_die);
13245 /* Now output info about the data members and type members. */
13246 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
13248 /* If we thought we were generating minimal debug info for TYPE
13249 and then changed our minds, some of the member declarations
13250 may have already been defined. Don't define them again, but
13251 do put them in the right order. */
13253 child = lookup_decl_die (member);
13255 splice_child_die (context_die, child);
13257 gen_decl_die (member, context_die);
13260 /* Now output info about the function members (if any). */
13261 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
13263 /* Don't include clones in the member list. */
13264 if (DECL_ABSTRACT_ORIGIN (member))
13267 child = lookup_decl_die (member);
13269 splice_child_die (context_die, child);
13271 gen_decl_die (member, context_die);
13275 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13276 is set, we pretend that the type was never defined, so we only get the
13277 member DIEs needed by later specification DIEs. */
13280 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
13281 enum debug_info_usage usage)
13283 dw_die_ref type_die = lookup_type_die (type);
13284 dw_die_ref scope_die = 0;
13286 int complete = (TYPE_SIZE (type)
13287 && (! TYPE_STUB_DECL (type)
13288 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
13289 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
13290 complete = complete && should_emit_struct_debug (type, usage);
13292 if (type_die && ! complete)
13295 if (TYPE_CONTEXT (type) != NULL_TREE
13296 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13297 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
13300 scope_die = scope_die_for (type, context_die);
13302 if (! type_die || (nested && scope_die == comp_unit_die))
13303 /* First occurrence of type or toplevel definition of nested class. */
13305 dw_die_ref old_die = type_die;
13307 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
13308 ? record_type_tag (type) : DW_TAG_union_type,
13310 equate_type_number_to_die (type, type_die);
13312 add_AT_specification (type_die, old_die);
13314 add_name_attribute (type_die, type_tag (type));
13317 remove_AT (type_die, DW_AT_declaration);
13319 /* If this type has been completed, then give it a byte_size attribute and
13320 then give a list of members. */
13321 if (complete && !ns_decl)
13323 /* Prevent infinite recursion in cases where the type of some member of
13324 this type is expressed in terms of this type itself. */
13325 TREE_ASM_WRITTEN (type) = 1;
13326 add_byte_size_attribute (type_die, type);
13327 if (TYPE_STUB_DECL (type) != NULL_TREE)
13328 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13330 /* If the first reference to this type was as the return type of an
13331 inline function, then it may not have a parent. Fix this now. */
13332 if (type_die->die_parent == NULL)
13333 add_child_die (scope_die, type_die);
13335 push_decl_scope (type);
13336 gen_member_die (type, type_die);
13339 /* GNU extension: Record what type our vtable lives in. */
13340 if (TYPE_VFIELD (type))
13342 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
13344 gen_type_die (vtype, context_die);
13345 add_AT_die_ref (type_die, DW_AT_containing_type,
13346 lookup_type_die (vtype));
13351 add_AT_flag (type_die, DW_AT_declaration, 1);
13353 /* We don't need to do this for function-local types. */
13354 if (TYPE_STUB_DECL (type)
13355 && ! decl_function_context (TYPE_STUB_DECL (type)))
13356 VEC_safe_push (tree, gc, incomplete_types, type);
13359 if (get_AT (type_die, DW_AT_name))
13360 add_pubtype (type, type_die);
13363 /* Generate a DIE for a subroutine _type_. */
13366 gen_subroutine_type_die (tree type, dw_die_ref context_die)
13368 tree return_type = TREE_TYPE (type);
13369 dw_die_ref subr_die
13370 = new_die (DW_TAG_subroutine_type,
13371 scope_die_for (type, context_die), type);
13373 equate_type_number_to_die (type, subr_die);
13374 add_prototyped_attribute (subr_die, type);
13375 add_type_attribute (subr_die, return_type, 0, 0, context_die);
13376 gen_formal_types_die (type, subr_die);
13378 if (get_AT (subr_die, DW_AT_name))
13379 add_pubtype (type, subr_die);
13382 /* Generate a DIE for a type definition. */
13385 gen_typedef_die (tree decl, dw_die_ref context_die)
13387 dw_die_ref type_die;
13390 if (TREE_ASM_WRITTEN (decl))
13393 TREE_ASM_WRITTEN (decl) = 1;
13394 type_die = new_die (DW_TAG_typedef, context_die, decl);
13395 origin = decl_ultimate_origin (decl);
13396 if (origin != NULL)
13397 add_abstract_origin_attribute (type_die, origin);
13402 add_name_and_src_coords_attributes (type_die, decl);
13403 if (DECL_ORIGINAL_TYPE (decl))
13405 type = DECL_ORIGINAL_TYPE (decl);
13407 gcc_assert (type != TREE_TYPE (decl));
13408 equate_type_number_to_die (TREE_TYPE (decl), type_die);
13411 type = TREE_TYPE (decl);
13413 add_type_attribute (type_die, type, TREE_READONLY (decl),
13414 TREE_THIS_VOLATILE (decl), context_die);
13417 if (DECL_ABSTRACT (decl))
13418 equate_decl_number_to_die (decl, type_die);
13420 if (get_AT (type_die, DW_AT_name))
13421 add_pubtype (decl, type_die);
13424 /* Generate a type description DIE. */
13427 gen_type_die_with_usage (tree type, dw_die_ref context_die,
13428 enum debug_info_usage usage)
13431 struct array_descr_info info;
13433 if (type == NULL_TREE || type == error_mark_node)
13436 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13437 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
13439 if (TREE_ASM_WRITTEN (type))
13442 /* Prevent broken recursion; we can't hand off to the same type. */
13443 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
13445 TREE_ASM_WRITTEN (type) = 1;
13446 gen_decl_die (TYPE_NAME (type), context_die);
13450 /* If this is an array type with hidden descriptor, handle it first. */
13451 if (!TREE_ASM_WRITTEN (type)
13452 && lang_hooks.types.get_array_descr_info
13453 && lang_hooks.types.get_array_descr_info (type, &info))
13455 gen_descr_array_type_die (type, &info, context_die);
13456 TREE_ASM_WRITTEN (type) = 1;
13460 /* We are going to output a DIE to represent the unqualified version
13461 of this type (i.e. without any const or volatile qualifiers) so
13462 get the main variant (i.e. the unqualified version) of this type
13463 now. (Vectors are special because the debugging info is in the
13464 cloned type itself). */
13465 if (TREE_CODE (type) != VECTOR_TYPE)
13466 type = type_main_variant (type);
13468 if (TREE_ASM_WRITTEN (type))
13471 switch (TREE_CODE (type))
13477 case REFERENCE_TYPE:
13478 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13479 ensures that the gen_type_die recursion will terminate even if the
13480 type is recursive. Recursive types are possible in Ada. */
13481 /* ??? We could perhaps do this for all types before the switch
13483 TREE_ASM_WRITTEN (type) = 1;
13485 /* For these types, all that is required is that we output a DIE (or a
13486 set of DIEs) to represent the "basis" type. */
13487 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13488 DINFO_USAGE_IND_USE);
13492 /* This code is used for C++ pointer-to-data-member types.
13493 Output a description of the relevant class type. */
13494 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13495 DINFO_USAGE_IND_USE);
13497 /* Output a description of the type of the object pointed to. */
13498 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13499 DINFO_USAGE_IND_USE);
13501 /* Now output a DIE to represent this pointer-to-data-member type
13503 gen_ptr_to_mbr_type_die (type, context_die);
13506 case FUNCTION_TYPE:
13507 /* Force out return type (in case it wasn't forced out already). */
13508 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13509 DINFO_USAGE_DIR_USE);
13510 gen_subroutine_type_die (type, context_die);
13514 /* Force out return type (in case it wasn't forced out already). */
13515 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13516 DINFO_USAGE_DIR_USE);
13517 gen_subroutine_type_die (type, context_die);
13521 gen_array_type_die (type, context_die);
13525 gen_array_type_die (type, context_die);
13528 case ENUMERAL_TYPE:
13531 case QUAL_UNION_TYPE:
13532 /* If this is a nested type whose containing class hasn't been written
13533 out yet, writing it out will cover this one, too. This does not apply
13534 to instantiations of member class templates; they need to be added to
13535 the containing class as they are generated. FIXME: This hurts the
13536 idea of combining type decls from multiple TUs, since we can't predict
13537 what set of template instantiations we'll get. */
13538 if (TYPE_CONTEXT (type)
13539 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13540 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13542 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13544 if (TREE_ASM_WRITTEN (type))
13547 /* If that failed, attach ourselves to the stub. */
13548 push_decl_scope (TYPE_CONTEXT (type));
13549 context_die = lookup_type_die (TYPE_CONTEXT (type));
13554 declare_in_namespace (type, context_die);
13558 if (TREE_CODE (type) == ENUMERAL_TYPE)
13560 /* This might have been written out by the call to
13561 declare_in_namespace. */
13562 if (!TREE_ASM_WRITTEN (type))
13563 gen_enumeration_type_die (type, context_die);
13566 gen_struct_or_union_type_die (type, context_die, usage);
13571 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13572 it up if it is ever completed. gen_*_type_die will set it for us
13573 when appropriate. */
13579 case FIXED_POINT_TYPE:
13582 /* No DIEs needed for fundamental types. */
13586 /* No Dwarf representation currently defined. */
13590 gcc_unreachable ();
13593 TREE_ASM_WRITTEN (type) = 1;
13597 gen_type_die (tree type, dw_die_ref context_die)
13599 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
13602 /* Generate a DIE for a tagged type instantiation. */
13605 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
13607 if (type == NULL_TREE || type == error_mark_node)
13610 /* We are going to output a DIE to represent the unqualified version of
13611 this type (i.e. without any const or volatile qualifiers) so make sure
13612 that we have the main variant (i.e. the unqualified version) of this
13614 gcc_assert (type == type_main_variant (type));
13616 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13617 an instance of an unresolved type. */
13619 switch (TREE_CODE (type))
13624 case ENUMERAL_TYPE:
13625 gen_inlined_enumeration_type_die (type, context_die);
13629 gen_inlined_structure_type_die (type, context_die);
13633 case QUAL_UNION_TYPE:
13634 gen_inlined_union_type_die (type, context_die);
13638 gcc_unreachable ();
13642 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13643 things which are local to the given block. */
13646 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
13648 int must_output_die = 0;
13651 enum tree_code origin_code;
13653 /* Ignore blocks that are NULL. */
13654 if (stmt == NULL_TREE)
13657 /* If the block is one fragment of a non-contiguous block, do not
13658 process the variables, since they will have been done by the
13659 origin block. Do process subblocks. */
13660 if (BLOCK_FRAGMENT_ORIGIN (stmt))
13664 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
13665 gen_block_die (sub, context_die, depth + 1);
13670 /* Determine the "ultimate origin" of this block. This block may be an
13671 inlined instance of an inlined instance of inline function, so we have
13672 to trace all of the way back through the origin chain to find out what
13673 sort of node actually served as the original seed for the creation of
13674 the current block. */
13675 origin = block_ultimate_origin (stmt);
13676 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13678 /* Determine if we need to output any Dwarf DIEs at all to represent this
13680 if (origin_code == FUNCTION_DECL)
13681 /* The outer scopes for inlinings *must* always be represented. We
13682 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13683 must_output_die = 1;
13686 /* In the case where the current block represents an inlining of the
13687 "body block" of an inline function, we must *NOT* output any DIE for
13688 this block because we have already output a DIE to represent the whole
13689 inlined function scope and the "body block" of any function doesn't
13690 really represent a different scope according to ANSI C rules. So we
13691 check here to make sure that this block does not represent a "body
13692 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13693 if (! is_body_block (origin ? origin : stmt))
13695 /* Determine if this block directly contains any "significant"
13696 local declarations which we will need to output DIEs for. */
13697 if (debug_info_level > DINFO_LEVEL_TERSE)
13698 /* We are not in terse mode so *any* local declaration counts
13699 as being a "significant" one. */
13700 must_output_die = (BLOCK_VARS (stmt) != NULL
13701 && (TREE_USED (stmt)
13702 || TREE_ASM_WRITTEN (stmt)
13703 || BLOCK_ABSTRACT (stmt)));
13705 /* We are in terse mode, so only local (nested) function
13706 definitions count as "significant" local declarations. */
13707 for (decl = BLOCK_VARS (stmt);
13708 decl != NULL; decl = TREE_CHAIN (decl))
13709 if (TREE_CODE (decl) == FUNCTION_DECL
13710 && DECL_INITIAL (decl))
13712 must_output_die = 1;
13718 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13719 DIE for any block which contains no significant local declarations at
13720 all. Rather, in such cases we just call `decls_for_scope' so that any
13721 needed Dwarf info for any sub-blocks will get properly generated. Note
13722 that in terse mode, our definition of what constitutes a "significant"
13723 local declaration gets restricted to include only inlined function
13724 instances and local (nested) function definitions. */
13725 if (must_output_die)
13727 if (origin_code == FUNCTION_DECL)
13728 gen_inlined_subroutine_die (stmt, context_die, depth);
13730 gen_lexical_block_die (stmt, context_die, depth);
13733 decls_for_scope (stmt, context_die, depth);
13736 /* Generate all of the decls declared within a given scope and (recursively)
13737 all of its sub-blocks. */
13740 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13745 /* Ignore NULL blocks. */
13746 if (stmt == NULL_TREE)
13749 if (TREE_USED (stmt))
13751 /* Output the DIEs to represent all of the data objects and typedefs
13752 declared directly within this block but not within any nested
13753 sub-blocks. Also, nested function and tag DIEs have been
13754 generated with a parent of NULL; fix that up now. */
13755 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13759 if (TREE_CODE (decl) == FUNCTION_DECL)
13760 die = lookup_decl_die (decl);
13761 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13762 die = lookup_type_die (TREE_TYPE (decl));
13766 if (die != NULL && die->die_parent == NULL)
13767 add_child_die (context_die, die);
13768 /* Do not produce debug information for static variables since
13769 these might be optimized out. We are called for these later
13770 in varpool_analyze_pending_decls.
13772 But *do* produce it for Fortran COMMON variables because,
13773 even though they are static, their names can differ depending
13774 on the scope, which we need to preserve. */
13775 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
13776 && !(is_fortran () && TREE_PUBLIC (decl)))
13779 gen_decl_die (decl, context_die);
13783 /* If we're at -g1, we're not interested in subblocks. */
13784 if (debug_info_level <= DINFO_LEVEL_TERSE)
13787 /* Output the DIEs to represent all sub-blocks (and the items declared
13788 therein) of this block. */
13789 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13791 subblocks = BLOCK_CHAIN (subblocks))
13792 gen_block_die (subblocks, context_die, depth + 1);
13795 /* Is this a typedef we can avoid emitting? */
13798 is_redundant_typedef (const_tree decl)
13800 if (TYPE_DECL_IS_STUB (decl))
13803 if (DECL_ARTIFICIAL (decl)
13804 && DECL_CONTEXT (decl)
13805 && is_tagged_type (DECL_CONTEXT (decl))
13806 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13807 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13808 /* Also ignore the artificial member typedef for the class name. */
13814 /* Returns the DIE for decl. A DIE will always be returned. */
13817 force_decl_die (tree decl)
13819 dw_die_ref decl_die;
13820 unsigned saved_external_flag;
13821 tree save_fn = NULL_TREE;
13822 decl_die = lookup_decl_die (decl);
13825 dw_die_ref context_die;
13826 tree decl_context = DECL_CONTEXT (decl);
13829 /* Find die that represents this context. */
13830 if (TYPE_P (decl_context))
13831 context_die = force_type_die (decl_context);
13833 context_die = force_decl_die (decl_context);
13836 context_die = comp_unit_die;
13838 decl_die = lookup_decl_die (decl);
13842 switch (TREE_CODE (decl))
13844 case FUNCTION_DECL:
13845 /* Clear current_function_decl, so that gen_subprogram_die thinks
13846 that this is a declaration. At this point, we just want to force
13847 declaration die. */
13848 save_fn = current_function_decl;
13849 current_function_decl = NULL_TREE;
13850 gen_subprogram_die (decl, context_die);
13851 current_function_decl = save_fn;
13855 /* Set external flag to force declaration die. Restore it after
13856 gen_decl_die() call. */
13857 saved_external_flag = DECL_EXTERNAL (decl);
13858 DECL_EXTERNAL (decl) = 1;
13859 gen_decl_die (decl, context_die);
13860 DECL_EXTERNAL (decl) = saved_external_flag;
13863 case NAMESPACE_DECL:
13864 dwarf2out_decl (decl);
13868 gcc_unreachable ();
13871 /* We should be able to find the DIE now. */
13873 decl_die = lookup_decl_die (decl);
13874 gcc_assert (decl_die);
13880 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13881 always returned. */
13884 force_type_die (tree type)
13886 dw_die_ref type_die;
13888 type_die = lookup_type_die (type);
13891 dw_die_ref context_die;
13892 if (TYPE_CONTEXT (type))
13894 if (TYPE_P (TYPE_CONTEXT (type)))
13895 context_die = force_type_die (TYPE_CONTEXT (type));
13897 context_die = force_decl_die (TYPE_CONTEXT (type));
13900 context_die = comp_unit_die;
13902 type_die = modified_type_die (type, TYPE_READONLY (type),
13903 TYPE_VOLATILE (type), context_die);
13904 gcc_assert (type_die);
13909 /* Force out any required namespaces to be able to output DECL,
13910 and return the new context_die for it, if it's changed. */
13913 setup_namespace_context (tree thing, dw_die_ref context_die)
13915 tree context = (DECL_P (thing)
13916 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13917 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13918 /* Force out the namespace. */
13919 context_die = force_decl_die (context);
13921 return context_die;
13924 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13925 type) within its namespace, if appropriate.
13927 For compatibility with older debuggers, namespace DIEs only contain
13928 declarations; all definitions are emitted at CU scope. */
13931 declare_in_namespace (tree thing, dw_die_ref context_die)
13933 dw_die_ref ns_context;
13935 if (debug_info_level <= DINFO_LEVEL_TERSE)
13938 /* If this decl is from an inlined function, then don't try to emit it in its
13939 namespace, as we will get confused. It would have already been emitted
13940 when the abstract instance of the inline function was emitted anyways. */
13941 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13944 ns_context = setup_namespace_context (thing, context_die);
13946 if (ns_context != context_die)
13948 if (DECL_P (thing))
13949 gen_decl_die (thing, ns_context);
13951 gen_type_die (thing, ns_context);
13955 /* Generate a DIE for a namespace or namespace alias. */
13958 gen_namespace_die (tree decl)
13960 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13962 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13963 they are an alias of. */
13964 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13966 /* Output a real namespace. */
13967 dw_die_ref namespace_die
13968 = new_die (DW_TAG_namespace, context_die, decl);
13969 add_name_and_src_coords_attributes (namespace_die, decl);
13970 equate_decl_number_to_die (decl, namespace_die);
13974 /* Output a namespace alias. */
13976 /* Force out the namespace we are an alias of, if necessary. */
13977 dw_die_ref origin_die
13978 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13980 /* Now create the namespace alias DIE. */
13981 dw_die_ref namespace_die
13982 = new_die (DW_TAG_imported_declaration, context_die, decl);
13983 add_name_and_src_coords_attributes (namespace_die, decl);
13984 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13985 equate_decl_number_to_die (decl, namespace_die);
13989 /* Generate Dwarf debug information for a decl described by DECL. */
13992 gen_decl_die (tree decl, dw_die_ref context_die)
13996 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13999 switch (TREE_CODE (decl))
14005 /* The individual enumerators of an enum type get output when we output
14006 the Dwarf representation of the relevant enum type itself. */
14009 case FUNCTION_DECL:
14010 /* Don't output any DIEs to represent mere function declarations,
14011 unless they are class members or explicit block externs. */
14012 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
14013 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
14018 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14019 on local redeclarations of global functions. That seems broken. */
14020 if (current_function_decl != decl)
14021 /* This is only a declaration. */;
14024 /* If we're emitting a clone, emit info for the abstract instance. */
14025 if (DECL_ORIGIN (decl) != decl)
14026 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14028 /* If we're emitting an out-of-line copy of an inline function,
14029 emit info for the abstract instance and set up to refer to it. */
14030 else if (cgraph_function_possibly_inlined_p (decl)
14031 && ! DECL_ABSTRACT (decl)
14032 && ! class_or_namespace_scope_p (context_die)
14033 /* dwarf2out_abstract_function won't emit a die if this is just
14034 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14035 that case, because that works only if we have a die. */
14036 && DECL_INITIAL (decl) != NULL_TREE)
14038 dwarf2out_abstract_function (decl);
14039 set_decl_origin_self (decl);
14042 /* Otherwise we're emitting the primary DIE for this decl. */
14043 else if (debug_info_level > DINFO_LEVEL_TERSE)
14045 /* Before we describe the FUNCTION_DECL itself, make sure that we
14046 have described its return type. */
14047 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14049 /* And its virtual context. */
14050 if (DECL_VINDEX (decl) != NULL_TREE)
14051 gen_type_die (DECL_CONTEXT (decl), context_die);
14053 /* And its containing type. */
14054 origin = decl_class_context (decl);
14055 if (origin != NULL_TREE)
14056 gen_type_die_for_member (origin, decl, context_die);
14058 /* And its containing namespace. */
14059 declare_in_namespace (decl, context_die);
14062 /* Now output a DIE to represent the function itself. */
14063 gen_subprogram_die (decl, context_die);
14067 /* If we are in terse mode, don't generate any DIEs to represent any
14068 actual typedefs. */
14069 if (debug_info_level <= DINFO_LEVEL_TERSE)
14072 /* In the special case of a TYPE_DECL node representing the declaration
14073 of some type tag, if the given TYPE_DECL is marked as having been
14074 instantiated from some other (original) TYPE_DECL node (e.g. one which
14075 was generated within the original definition of an inline function) we
14076 have to generate a special (abbreviated) DW_TAG_structure_type,
14077 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14078 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14079 && is_tagged_type (TREE_TYPE (decl)))
14081 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14085 if (is_redundant_typedef (decl))
14086 gen_type_die (TREE_TYPE (decl), context_die);
14088 /* Output a DIE to represent the typedef itself. */
14089 gen_typedef_die (decl, context_die);
14093 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14094 gen_label_die (decl, context_die);
14099 /* If we are in terse mode, don't generate any DIEs to represent any
14100 variable declarations or definitions. */
14101 if (debug_info_level <= DINFO_LEVEL_TERSE)
14104 /* If this is the global definition of the Fortran COMMON block, we don't
14105 need to do anything. Syntactically, the block itself has no identity,
14106 just its constituent identifiers. */
14107 if (TREE_CODE (decl) == VAR_DECL
14108 && TREE_PUBLIC (decl)
14109 && TREE_STATIC (decl)
14111 && !DECL_HAS_VALUE_EXPR_P (decl))
14114 /* Output any DIEs that are needed to specify the type of this data
14116 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14117 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14119 gen_type_die (TREE_TYPE (decl), context_die);
14121 /* And its containing type. */
14122 origin = decl_class_context (decl);
14123 if (origin != NULL_TREE)
14124 gen_type_die_for_member (origin, decl, context_die);
14126 /* And its containing namespace. */
14127 declare_in_namespace (decl, context_die);
14129 /* Now output the DIE to represent the data object itself. This gets
14130 complicated because of the possibility that the VAR_DECL really
14131 represents an inlined instance of a formal parameter for an inline
14133 origin = decl_ultimate_origin (decl);
14134 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
14135 gen_formal_parameter_die (decl, context_die);
14137 gen_variable_die (decl, context_die);
14141 /* Ignore the nameless fields that are used to skip bits but handle C++
14142 anonymous unions and structs. */
14143 if (DECL_NAME (decl) != NULL_TREE
14144 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
14145 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
14147 gen_type_die (member_declared_type (decl), context_die);
14148 gen_field_die (decl, context_die);
14153 if (DECL_BY_REFERENCE (decl))
14154 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14156 gen_type_die (TREE_TYPE (decl), context_die);
14157 gen_formal_parameter_die (decl, context_die);
14160 case NAMESPACE_DECL:
14161 gen_namespace_die (decl);
14165 /* Probably some frontend-internal decl. Assume we don't care. */
14166 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
14171 /* Output debug information for global decl DECL. Called from toplev.c after
14172 compilation proper has finished. */
14175 dwarf2out_global_decl (tree decl)
14177 /* Output DWARF2 information for file-scope tentative data object
14178 declarations, file-scope (extern) function declarations (which
14179 had no corresponding body) and file-scope tagged type declarations
14180 and definitions which have not yet been forced out.
14182 Ignore the global decl of any Fortran COMMON blocks which also
14183 wind up here though they have already been described in the local
14184 scope for the procedures using them. */
14185 if (TREE_CODE (decl) == VAR_DECL
14186 && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ())
14189 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14190 dwarf2out_decl (decl);
14193 /* Output debug information for type decl DECL. Called from toplev.c
14194 and from language front ends (to record built-in types). */
14196 dwarf2out_type_decl (tree decl, int local)
14199 dwarf2out_decl (decl);
14202 /* Output debug information for imported module or decl. */
14205 dwarf2out_imported_module_or_decl (tree decl, tree context)
14207 dw_die_ref imported_die, at_import_die;
14208 dw_die_ref scope_die;
14209 expanded_location xloc;
14211 if (debug_info_level <= DINFO_LEVEL_TERSE)
14216 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14217 We need decl DIE for reference and scope die. First, get DIE for the decl
14220 /* Get the scope die for decl context. Use comp_unit_die for global module
14221 or decl. If die is not found for non globals, force new die. */
14223 scope_die = comp_unit_die;
14224 else if (TYPE_P (context))
14226 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14228 scope_die = force_type_die (context);
14231 scope_die = force_decl_die (context);
14233 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14234 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14236 if (is_base_type (TREE_TYPE (decl)))
14237 at_import_die = base_type_die (TREE_TYPE (decl));
14239 at_import_die = force_type_die (TREE_TYPE (decl));
14243 at_import_die = lookup_decl_die (decl);
14244 if (!at_import_die)
14246 /* If we're trying to avoid duplicate debug info, we may not have
14247 emitted the member decl for this field. Emit it now. */
14248 if (TREE_CODE (decl) == FIELD_DECL)
14250 tree type = DECL_CONTEXT (decl);
14251 dw_die_ref type_context_die;
14253 if (TYPE_CONTEXT (type))
14254 if (TYPE_P (TYPE_CONTEXT (type)))
14256 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
14257 DINFO_USAGE_DIR_USE))
14259 type_context_die = force_type_die (TYPE_CONTEXT (type));
14262 type_context_die = force_decl_die (TYPE_CONTEXT (type));
14264 type_context_die = comp_unit_die;
14265 gen_type_die_for_member (type, decl, type_context_die);
14267 at_import_die = force_decl_die (decl);
14271 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14272 if (TREE_CODE (decl) == NAMESPACE_DECL)
14273 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
14275 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
14277 xloc = expand_location (input_location);
14278 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
14279 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
14280 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
14283 /* Write the debugging output for DECL. */
14286 dwarf2out_decl (tree decl)
14288 dw_die_ref context_die = comp_unit_die;
14290 switch (TREE_CODE (decl))
14295 case FUNCTION_DECL:
14296 /* What we would really like to do here is to filter out all mere
14297 file-scope declarations of file-scope functions which are never
14298 referenced later within this translation unit (and keep all of ones
14299 that *are* referenced later on) but we aren't clairvoyant, so we have
14300 no idea which functions will be referenced in the future (i.e. later
14301 on within the current translation unit). So here we just ignore all
14302 file-scope function declarations which are not also definitions. If
14303 and when the debugger needs to know something about these functions,
14304 it will have to hunt around and find the DWARF information associated
14305 with the definition of the function.
14307 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14308 nodes represent definitions and which ones represent mere
14309 declarations. We have to check DECL_INITIAL instead. That's because
14310 the C front-end supports some weird semantics for "extern inline"
14311 function definitions. These can get inlined within the current
14312 translation unit (and thus, we need to generate Dwarf info for their
14313 abstract instances so that the Dwarf info for the concrete inlined
14314 instances can have something to refer to) but the compiler never
14315 generates any out-of-lines instances of such things (despite the fact
14316 that they *are* definitions).
14318 The important point is that the C front-end marks these "extern
14319 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14320 them anyway. Note that the C++ front-end also plays some similar games
14321 for inline function definitions appearing within include files which
14322 also contain `#pragma interface' pragmas. */
14323 if (DECL_INITIAL (decl) == NULL_TREE)
14326 /* If we're a nested function, initially use a parent of NULL; if we're
14327 a plain function, this will be fixed up in decls_for_scope. If
14328 we're a method, it will be ignored, since we already have a DIE. */
14329 if (decl_function_context (decl)
14330 /* But if we're in terse mode, we don't care about scope. */
14331 && debug_info_level > DINFO_LEVEL_TERSE)
14332 context_die = NULL;
14336 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14337 declaration and if the declaration was never even referenced from
14338 within this entire compilation unit. We suppress these DIEs in
14339 order to save space in the .debug section (by eliminating entries
14340 which are probably useless). Note that we must not suppress
14341 block-local extern declarations (whether used or not) because that
14342 would screw-up the debugger's name lookup mechanism and cause it to
14343 miss things which really ought to be in scope at a given point. */
14344 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
14347 /* For local statics lookup proper context die. */
14348 if (TREE_STATIC (decl) && decl_function_context (decl))
14349 context_die = lookup_decl_die (DECL_CONTEXT (decl));
14351 /* If we are in terse mode, don't generate any DIEs to represent any
14352 variable declarations or definitions. */
14353 if (debug_info_level <= DINFO_LEVEL_TERSE)
14357 case NAMESPACE_DECL:
14358 if (debug_info_level <= DINFO_LEVEL_TERSE)
14360 if (lookup_decl_die (decl) != NULL)
14365 /* Don't emit stubs for types unless they are needed by other DIEs. */
14366 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
14369 /* Don't bother trying to generate any DIEs to represent any of the
14370 normal built-in types for the language we are compiling. */
14371 if (DECL_IS_BUILTIN (decl))
14373 /* OK, we need to generate one for `bool' so GDB knows what type
14374 comparisons have. */
14376 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
14377 && ! DECL_IGNORED_P (decl))
14378 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
14383 /* If we are in terse mode, don't generate any DIEs for types. */
14384 if (debug_info_level <= DINFO_LEVEL_TERSE)
14387 /* If we're a function-scope tag, initially use a parent of NULL;
14388 this will be fixed up in decls_for_scope. */
14389 if (decl_function_context (decl))
14390 context_die = NULL;
14398 gen_decl_die (decl, context_die);
14401 /* Output a marker (i.e. a label) for the beginning of the generated code for
14402 a lexical block. */
14405 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
14406 unsigned int blocknum)
14408 switch_to_section (current_function_section ());
14409 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
14412 /* Output a marker (i.e. a label) for the end of the generated code for a
14416 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
14418 switch_to_section (current_function_section ());
14419 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
14422 /* Returns nonzero if it is appropriate not to emit any debugging
14423 information for BLOCK, because it doesn't contain any instructions.
14425 Don't allow this for blocks with nested functions or local classes
14426 as we would end up with orphans, and in the presence of scheduling
14427 we may end up calling them anyway. */
14430 dwarf2out_ignore_block (const_tree block)
14434 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
14435 if (TREE_CODE (decl) == FUNCTION_DECL
14436 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
14442 /* Hash table routines for file_hash. */
14445 file_table_eq (const void *p1_p, const void *p2_p)
14447 const struct dwarf_file_data *const p1 =
14448 (const struct dwarf_file_data *) p1_p;
14449 const char *const p2 = (const char *) p2_p;
14450 return strcmp (p1->filename, p2) == 0;
14454 file_table_hash (const void *p_p)
14456 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
14457 return htab_hash_string (p->filename);
14460 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14461 dwarf2out.c) and return its "index". The index of each (known) filename is
14462 just a unique number which is associated with only that one filename. We
14463 need such numbers for the sake of generating labels (in the .debug_sfnames
14464 section) and references to those files numbers (in the .debug_srcinfo
14465 and.debug_macinfo sections). If the filename given as an argument is not
14466 found in our current list, add it to the list and assign it the next
14467 available unique index number. In order to speed up searches, we remember
14468 the index of the filename was looked up last. This handles the majority of
14471 static struct dwarf_file_data *
14472 lookup_filename (const char *file_name)
14475 struct dwarf_file_data * created;
14477 /* Check to see if the file name that was searched on the previous
14478 call matches this file name. If so, return the index. */
14479 if (file_table_last_lookup
14480 && (file_name == file_table_last_lookup->filename
14481 || strcmp (file_table_last_lookup->filename, file_name) == 0))
14482 return file_table_last_lookup;
14484 /* Didn't match the previous lookup, search the table. */
14485 slot = htab_find_slot_with_hash (file_table, file_name,
14486 htab_hash_string (file_name), INSERT);
14488 return (struct dwarf_file_data *) *slot;
14490 created = GGC_NEW (struct dwarf_file_data);
14491 created->filename = file_name;
14492 created->emitted_number = 0;
14497 /* If the assembler will construct the file table, then translate the compiler
14498 internal file table number into the assembler file table number, and emit
14499 a .file directive if we haven't already emitted one yet. The file table
14500 numbers are different because we prune debug info for unused variables and
14501 types, which may include filenames. */
14504 maybe_emit_file (struct dwarf_file_data * fd)
14506 if (! fd->emitted_number)
14508 if (last_emitted_file)
14509 fd->emitted_number = last_emitted_file->emitted_number + 1;
14511 fd->emitted_number = 1;
14512 last_emitted_file = fd;
14514 if (DWARF2_ASM_LINE_DEBUG_INFO)
14516 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14517 output_quoted_string (asm_out_file,
14518 remap_debug_filename (fd->filename));
14519 fputc ('\n', asm_out_file);
14523 return fd->emitted_number;
14526 /* Called by the final INSN scan whenever we see a var location. We
14527 use it to drop labels in the right places, and throw the location in
14528 our lookup table. */
14531 dwarf2out_var_location (rtx loc_note)
14533 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14534 struct var_loc_node *newloc;
14536 static rtx last_insn;
14537 static const char *last_label;
14540 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14542 prev_insn = PREV_INSN (loc_note);
14544 newloc = GGC_CNEW (struct var_loc_node);
14545 /* If the insn we processed last time is the previous insn
14546 and it is also a var location note, use the label we emitted
14548 if (last_insn != NULL_RTX
14549 && last_insn == prev_insn
14550 && NOTE_P (prev_insn)
14551 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14553 newloc->label = last_label;
14557 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14558 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14560 newloc->label = ggc_strdup (loclabel);
14562 newloc->var_loc_note = loc_note;
14563 newloc->next = NULL;
14565 if (cfun && in_cold_section_p)
14566 newloc->section_label = crtl->subsections.cold_section_label;
14568 newloc->section_label = text_section_label;
14570 last_insn = loc_note;
14571 last_label = newloc->label;
14572 decl = NOTE_VAR_LOCATION_DECL (loc_note);
14573 add_var_loc_to_decl (decl, newloc);
14576 /* We need to reset the locations at the beginning of each
14577 function. We can't do this in the end_function hook, because the
14578 declarations that use the locations won't have been output when
14579 that hook is called. Also compute have_multiple_function_sections here. */
14582 dwarf2out_begin_function (tree fun)
14584 htab_empty (decl_loc_table);
14586 if (function_section (fun) != text_section)
14587 have_multiple_function_sections = true;
14589 dwarf2out_note_section_used ();
14592 /* Output a label to mark the beginning of a source code line entry
14593 and record information relating to this source line, in
14594 'line_info_table' for later output of the .debug_line section. */
14597 dwarf2out_source_line (unsigned int line, const char *filename)
14599 if (debug_info_level >= DINFO_LEVEL_NORMAL
14602 int file_num = maybe_emit_file (lookup_filename (filename));
14604 switch_to_section (current_function_section ());
14606 /* If requested, emit something human-readable. */
14607 if (flag_debug_asm)
14608 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
14611 if (DWARF2_ASM_LINE_DEBUG_INFO)
14613 /* Emit the .loc directive understood by GNU as. */
14614 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
14616 /* Indicate that line number info exists. */
14617 line_info_table_in_use++;
14619 else if (function_section (current_function_decl) != text_section)
14621 dw_separate_line_info_ref line_info;
14622 targetm.asm_out.internal_label (asm_out_file,
14623 SEPARATE_LINE_CODE_LABEL,
14624 separate_line_info_table_in_use);
14626 /* Expand the line info table if necessary. */
14627 if (separate_line_info_table_in_use
14628 == separate_line_info_table_allocated)
14630 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14631 separate_line_info_table
14632 = GGC_RESIZEVEC (dw_separate_line_info_entry,
14633 separate_line_info_table,
14634 separate_line_info_table_allocated);
14635 memset (separate_line_info_table
14636 + separate_line_info_table_in_use,
14638 (LINE_INFO_TABLE_INCREMENT
14639 * sizeof (dw_separate_line_info_entry)));
14642 /* Add the new entry at the end of the line_info_table. */
14644 = &separate_line_info_table[separate_line_info_table_in_use++];
14645 line_info->dw_file_num = file_num;
14646 line_info->dw_line_num = line;
14647 line_info->function = current_function_funcdef_no;
14651 dw_line_info_ref line_info;
14653 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
14654 line_info_table_in_use);
14656 /* Expand the line info table if necessary. */
14657 if (line_info_table_in_use == line_info_table_allocated)
14659 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14661 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
14662 line_info_table_allocated);
14663 memset (line_info_table + line_info_table_in_use, 0,
14664 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
14667 /* Add the new entry at the end of the line_info_table. */
14668 line_info = &line_info_table[line_info_table_in_use++];
14669 line_info->dw_file_num = file_num;
14670 line_info->dw_line_num = line;
14675 /* Record the beginning of a new source file. */
14678 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
14680 if (flag_eliminate_dwarf2_dups)
14682 /* Record the beginning of the file for break_out_includes. */
14683 dw_die_ref bincl_die;
14685 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
14686 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
14689 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14691 int file_num = maybe_emit_file (lookup_filename (filename));
14693 switch_to_section (debug_macinfo_section);
14694 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
14695 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14698 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14702 /* Record the end of a source file. */
14705 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14707 if (flag_eliminate_dwarf2_dups)
14708 /* Record the end of the file for break_out_includes. */
14709 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14711 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14713 switch_to_section (debug_macinfo_section);
14714 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14718 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14719 the tail part of the directive line, i.e. the part which is past the
14720 initial whitespace, #, whitespace, directive-name, whitespace part. */
14723 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14724 const char *buffer ATTRIBUTE_UNUSED)
14726 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14728 switch_to_section (debug_macinfo_section);
14729 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14730 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14731 dw2_asm_output_nstring (buffer, -1, "The macro");
14735 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14736 the tail part of the directive line, i.e. the part which is past the
14737 initial whitespace, #, whitespace, directive-name, whitespace part. */
14740 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14741 const char *buffer ATTRIBUTE_UNUSED)
14743 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14745 switch_to_section (debug_macinfo_section);
14746 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14747 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14748 dw2_asm_output_nstring (buffer, -1, "The macro");
14752 /* Set up for Dwarf output at the start of compilation. */
14755 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14757 /* Allocate the file_table. */
14758 file_table = htab_create_ggc (50, file_table_hash,
14759 file_table_eq, NULL);
14761 /* Allocate the decl_die_table. */
14762 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14763 decl_die_table_eq, NULL);
14765 /* Allocate the decl_loc_table. */
14766 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14767 decl_loc_table_eq, NULL);
14769 /* Allocate the initial hunk of the decl_scope_table. */
14770 decl_scope_table = VEC_alloc (tree, gc, 256);
14772 /* Allocate the initial hunk of the abbrev_die_table. */
14773 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
14774 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14775 /* Zero-th entry is allocated, but unused. */
14776 abbrev_die_table_in_use = 1;
14778 /* Allocate the initial hunk of the line_info_table. */
14779 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
14780 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14782 /* Zero-th entry is allocated, but unused. */
14783 line_info_table_in_use = 1;
14785 /* Allocate the pubtypes and pubnames vectors. */
14786 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14787 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14789 /* Generate the initial DIE for the .debug section. Note that the (string)
14790 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14791 will (typically) be a relative pathname and that this pathname should be
14792 taken as being relative to the directory from which the compiler was
14793 invoked when the given (base) source file was compiled. We will fill
14794 in this value in dwarf2out_finish. */
14795 comp_unit_die = gen_compile_unit_die (NULL);
14797 incomplete_types = VEC_alloc (tree, gc, 64);
14799 used_rtx_array = VEC_alloc (rtx, gc, 32);
14801 debug_info_section = get_section (DEBUG_INFO_SECTION,
14802 SECTION_DEBUG, NULL);
14803 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14804 SECTION_DEBUG, NULL);
14805 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14806 SECTION_DEBUG, NULL);
14807 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14808 SECTION_DEBUG, NULL);
14809 debug_line_section = get_section (DEBUG_LINE_SECTION,
14810 SECTION_DEBUG, NULL);
14811 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14812 SECTION_DEBUG, NULL);
14813 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14814 SECTION_DEBUG, NULL);
14815 #ifdef DEBUG_PUBTYPES_SECTION
14816 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14817 SECTION_DEBUG, NULL);
14819 debug_str_section = get_section (DEBUG_STR_SECTION,
14820 DEBUG_STR_SECTION_FLAGS, NULL);
14821 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14822 SECTION_DEBUG, NULL);
14823 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14824 SECTION_DEBUG, NULL);
14826 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14827 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14828 DEBUG_ABBREV_SECTION_LABEL, 0);
14829 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14830 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14831 COLD_TEXT_SECTION_LABEL, 0);
14832 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14834 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14835 DEBUG_INFO_SECTION_LABEL, 0);
14836 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14837 DEBUG_LINE_SECTION_LABEL, 0);
14838 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14839 DEBUG_RANGES_SECTION_LABEL, 0);
14840 switch_to_section (debug_abbrev_section);
14841 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14842 switch_to_section (debug_info_section);
14843 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14844 switch_to_section (debug_line_section);
14845 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14847 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14849 switch_to_section (debug_macinfo_section);
14850 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14851 DEBUG_MACINFO_SECTION_LABEL, 0);
14852 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14855 switch_to_section (text_section);
14856 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14857 if (flag_reorder_blocks_and_partition)
14859 cold_text_section = unlikely_text_section ();
14860 switch_to_section (cold_text_section);
14861 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14865 /* A helper function for dwarf2out_finish called through
14866 ht_forall. Emit one queued .debug_str string. */
14869 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14871 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14873 if (node->form == DW_FORM_strp)
14875 switch_to_section (debug_str_section);
14876 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14877 assemble_string (node->str, strlen (node->str) + 1);
14883 #if ENABLE_ASSERT_CHECKING
14884 /* Verify that all marks are clear. */
14887 verify_marks_clear (dw_die_ref die)
14891 gcc_assert (! die->die_mark);
14892 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14894 #endif /* ENABLE_ASSERT_CHECKING */
14896 /* Clear the marks for a die and its children.
14897 Be cool if the mark isn't set. */
14900 prune_unmark_dies (dw_die_ref die)
14906 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14909 /* Given DIE that we're marking as used, find any other dies
14910 it references as attributes and mark them as used. */
14913 prune_unused_types_walk_attribs (dw_die_ref die)
14918 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14920 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14922 /* A reference to another DIE.
14923 Make sure that it will get emitted. */
14924 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14926 /* Set the string's refcount to 0 so that prune_unused_types_mark
14927 accounts properly for it. */
14928 if (AT_class (a) == dw_val_class_str)
14929 a->dw_attr_val.v.val_str->refcount = 0;
14934 /* Mark DIE as being used. If DOKIDS is true, then walk down
14935 to DIE's children. */
14938 prune_unused_types_mark (dw_die_ref die, int dokids)
14942 if (die->die_mark == 0)
14944 /* We haven't done this node yet. Mark it as used. */
14947 /* We also have to mark its parents as used.
14948 (But we don't want to mark our parents' kids due to this.) */
14949 if (die->die_parent)
14950 prune_unused_types_mark (die->die_parent, 0);
14952 /* Mark any referenced nodes. */
14953 prune_unused_types_walk_attribs (die);
14955 /* If this node is a specification,
14956 also mark the definition, if it exists. */
14957 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14958 prune_unused_types_mark (die->die_definition, 1);
14961 if (dokids && die->die_mark != 2)
14963 /* We need to walk the children, but haven't done so yet.
14964 Remember that we've walked the kids. */
14967 /* If this is an array type, we need to make sure our
14968 kids get marked, even if they're types. */
14969 if (die->die_tag == DW_TAG_array_type)
14970 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14972 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14977 /* Walk the tree DIE and mark types that we actually use. */
14980 prune_unused_types_walk (dw_die_ref die)
14984 /* Don't do anything if this node is already marked. */
14988 switch (die->die_tag)
14990 case DW_TAG_const_type:
14991 case DW_TAG_packed_type:
14992 case DW_TAG_pointer_type:
14993 case DW_TAG_reference_type:
14994 case DW_TAG_volatile_type:
14995 case DW_TAG_typedef:
14996 case DW_TAG_array_type:
14997 case DW_TAG_structure_type:
14998 case DW_TAG_union_type:
14999 case DW_TAG_class_type:
15000 case DW_TAG_interface_type:
15001 case DW_TAG_friend:
15002 case DW_TAG_variant_part:
15003 case DW_TAG_enumeration_type:
15004 case DW_TAG_subroutine_type:
15005 case DW_TAG_string_type:
15006 case DW_TAG_set_type:
15007 case DW_TAG_subrange_type:
15008 case DW_TAG_ptr_to_member_type:
15009 case DW_TAG_file_type:
15010 if (die->die_perennial_p)
15013 /* It's a type node --- don't mark it. */
15017 /* Mark everything else. */
15023 /* Now, mark any dies referenced from here. */
15024 prune_unused_types_walk_attribs (die);
15026 /* Mark children. */
15027 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15030 /* Increment the string counts on strings referred to from DIE's
15034 prune_unused_types_update_strings (dw_die_ref die)
15039 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15040 if (AT_class (a) == dw_val_class_str)
15042 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15044 /* Avoid unnecessarily putting strings that are used less than
15045 twice in the hash table. */
15047 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15050 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15051 htab_hash_string (s->str),
15053 gcc_assert (*slot == NULL);
15059 /* Remove from the tree DIE any dies that aren't marked. */
15062 prune_unused_types_prune (dw_die_ref die)
15066 gcc_assert (die->die_mark);
15067 prune_unused_types_update_strings (die);
15069 if (! die->die_child)
15072 c = die->die_child;
15074 dw_die_ref prev = c;
15075 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15076 if (c == die->die_child)
15078 /* No marked children between 'prev' and the end of the list. */
15080 /* No marked children at all. */
15081 die->die_child = NULL;
15084 prev->die_sib = c->die_sib;
15085 die->die_child = prev;
15090 if (c != prev->die_sib)
15092 prune_unused_types_prune (c);
15093 } while (c != die->die_child);
15097 /* Remove dies representing declarations that we never use. */
15100 prune_unused_types (void)
15103 limbo_die_node *node;
15106 #if ENABLE_ASSERT_CHECKING
15107 /* All the marks should already be clear. */
15108 verify_marks_clear (comp_unit_die);
15109 for (node = limbo_die_list; node; node = node->next)
15110 verify_marks_clear (node->die);
15111 #endif /* ENABLE_ASSERT_CHECKING */
15113 /* Set the mark on nodes that are actually used. */
15114 prune_unused_types_walk (comp_unit_die);
15115 for (node = limbo_die_list; node; node = node->next)
15116 prune_unused_types_walk (node->die);
15118 /* Also set the mark on nodes referenced from the
15119 pubname_table or arange_table. */
15120 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15121 prune_unused_types_mark (pub->die, 1);
15122 for (i = 0; i < arange_table_in_use; i++)
15123 prune_unused_types_mark (arange_table[i], 1);
15125 /* Get rid of nodes that aren't marked; and update the string counts. */
15126 if (debug_str_hash)
15127 htab_empty (debug_str_hash);
15128 prune_unused_types_prune (comp_unit_die);
15129 for (node = limbo_die_list; node; node = node->next)
15130 prune_unused_types_prune (node->die);
15132 /* Leave the marks clear. */
15133 prune_unmark_dies (comp_unit_die);
15134 for (node = limbo_die_list; node; node = node->next)
15135 prune_unmark_dies (node->die);
15138 /* Set the parameter to true if there are any relative pathnames in
15141 file_table_relative_p (void ** slot, void *param)
15143 bool *p = (bool *) param;
15144 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
15145 if (!IS_ABSOLUTE_PATH (d->filename))
15153 /* Output stuff that dwarf requires at the end of every file,
15154 and generate the DWARF-2 debugging info. */
15157 dwarf2out_finish (const char *filename)
15159 limbo_die_node *node, *next_node;
15160 dw_die_ref die = 0;
15162 /* Add the name for the main input file now. We delayed this from
15163 dwarf2out_init to avoid complications with PCH. */
15164 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
15165 if (!IS_ABSOLUTE_PATH (filename))
15166 add_comp_dir_attribute (comp_unit_die);
15167 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
15170 htab_traverse (file_table, file_table_relative_p, &p);
15172 add_comp_dir_attribute (comp_unit_die);
15175 /* Traverse the limbo die list, and add parent/child links. The only
15176 dies without parents that should be here are concrete instances of
15177 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15178 For concrete instances, we can get the parent die from the abstract
15180 for (node = limbo_die_list; node; node = next_node)
15182 next_node = node->next;
15185 if (die->die_parent == NULL)
15187 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15190 add_child_die (origin->die_parent, die);
15191 else if (die == comp_unit_die)
15193 else if (errorcount > 0 || sorrycount > 0)
15194 /* It's OK to be confused by errors in the input. */
15195 add_child_die (comp_unit_die, die);
15198 /* In certain situations, the lexical block containing a
15199 nested function can be optimized away, which results
15200 in the nested function die being orphaned. Likewise
15201 with the return type of that nested function. Force
15202 this to be a child of the containing function.
15204 It may happen that even the containing function got fully
15205 inlined and optimized out. In that case we are lost and
15206 assign the empty child. This should not be big issue as
15207 the function is likely unreachable too. */
15208 tree context = NULL_TREE;
15210 gcc_assert (node->created_for);
15212 if (DECL_P (node->created_for))
15213 context = DECL_CONTEXT (node->created_for);
15214 else if (TYPE_P (node->created_for))
15215 context = TYPE_CONTEXT (node->created_for);
15217 gcc_assert (context
15218 && (TREE_CODE (context) == FUNCTION_DECL
15219 || TREE_CODE (context) == NAMESPACE_DECL));
15221 origin = lookup_decl_die (context);
15223 add_child_die (origin, die);
15225 add_child_die (comp_unit_die, die);
15230 limbo_die_list = NULL;
15232 /* Walk through the list of incomplete types again, trying once more to
15233 emit full debugging info for them. */
15234 retry_incomplete_types ();
15236 if (flag_eliminate_unused_debug_types)
15237 prune_unused_types ();
15239 /* Generate separate CUs for each of the include files we've seen.
15240 They will go into limbo_die_list. */
15241 if (flag_eliminate_dwarf2_dups)
15242 break_out_includes (comp_unit_die);
15244 /* Traverse the DIE's and add add sibling attributes to those DIE's
15245 that have children. */
15246 add_sibling_attributes (comp_unit_die);
15247 for (node = limbo_die_list; node; node = node->next)
15248 add_sibling_attributes (node->die);
15250 /* Output a terminator label for the .text section. */
15251 switch_to_section (text_section);
15252 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
15253 if (flag_reorder_blocks_and_partition)
15255 switch_to_section (unlikely_text_section ());
15256 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
15259 /* We can only use the low/high_pc attributes if all of the code was
15261 if (!have_multiple_function_sections)
15263 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
15264 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
15269 unsigned fde_idx = 0;
15271 /* We need to give .debug_loc and .debug_ranges an appropriate
15272 "base address". Use zero so that these addresses become
15273 absolute. Historically, we've emitted the unexpected
15274 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15275 Emit both to give time for other tools to adapt. */
15276 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
15277 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
15279 add_AT_range_list (comp_unit_die, DW_AT_ranges,
15280 add_ranges_by_labels (text_section_label,
15282 if (flag_reorder_blocks_and_partition)
15283 add_ranges_by_labels (cold_text_section_label,
15286 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
15288 dw_fde_ref fde = &fde_table[fde_idx];
15290 if (fde->dw_fde_switched_sections)
15292 add_ranges_by_labels (fde->dw_fde_hot_section_label,
15293 fde->dw_fde_hot_section_end_label);
15294 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
15295 fde->dw_fde_unlikely_section_end_label);
15298 add_ranges_by_labels (fde->dw_fde_begin,
15305 /* Output location list section if necessary. */
15306 if (have_location_lists)
15308 /* Output the location lists info. */
15309 switch_to_section (debug_loc_section);
15310 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
15311 DEBUG_LOC_SECTION_LABEL, 0);
15312 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
15313 output_location_lists (die);
15316 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15317 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
15318 debug_line_section_label);
15320 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15321 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
15323 /* Output all of the compilation units. We put the main one last so that
15324 the offsets are available to output_pubnames. */
15325 for (node = limbo_die_list; node; node = node->next)
15326 output_comp_unit (node->die, 0);
15328 output_comp_unit (comp_unit_die, 0);
15330 /* Output the abbreviation table. */
15331 switch_to_section (debug_abbrev_section);
15332 output_abbrev_section ();
15334 /* Output public names table if necessary. */
15335 if (!VEC_empty (pubname_entry, pubname_table))
15337 switch_to_section (debug_pubnames_section);
15338 output_pubnames (pubname_table);
15341 #ifdef DEBUG_PUBTYPES_SECTION
15342 /* Output public types table if necessary. */
15343 if (!VEC_empty (pubname_entry, pubtype_table))
15345 switch_to_section (debug_pubtypes_section);
15346 output_pubnames (pubtype_table);
15350 /* Output the address range information. We only put functions in the arange
15351 table, so don't write it out if we don't have any. */
15352 if (fde_table_in_use)
15354 switch_to_section (debug_aranges_section);
15358 /* Output ranges section if necessary. */
15359 if (ranges_table_in_use)
15361 switch_to_section (debug_ranges_section);
15362 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
15366 /* Output the source line correspondence table. We must do this
15367 even if there is no line information. Otherwise, on an empty
15368 translation unit, we will generate a present, but empty,
15369 .debug_info section. IRIX 6.5 `nm' will then complain when
15370 examining the file. This is done late so that any filenames
15371 used by the debug_info section are marked as 'used'. */
15372 if (! DWARF2_ASM_LINE_DEBUG_INFO)
15374 switch_to_section (debug_line_section);
15375 output_line_info ();
15378 /* Have to end the macro section. */
15379 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15381 switch_to_section (debug_macinfo_section);
15382 dw2_asm_output_data (1, 0, "End compilation unit");
15385 /* If we emitted any DW_FORM_strp form attribute, output the string
15387 if (debug_str_hash)
15388 htab_traverse (debug_str_hash, output_indirect_string, NULL);
15392 /* This should never be used, but its address is needed for comparisons. */
15393 const struct gcc_debug_hooks dwarf2_debug_hooks;
15395 #endif /* DWARF2_DEBUGGING_INFO */
15397 #include "gt-dwarf2out.h"