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 /* A list of call frame insns for the CIE. */
319 static GTY(()) dw_cfi_ref cie_cfi_head;
321 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326 static unsigned current_funcdef_fde;
329 struct indirect_string_node GTY(())
332 unsigned int refcount;
337 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
339 static GTY(()) int dw2_string_counter;
340 static GTY(()) unsigned long dwarf2out_cfi_label_num;
342 /* True if the compilation unit places functions in more than one section. */
343 static GTY(()) bool have_multiple_function_sections = false;
345 /* Whether the default text and cold text sections have been used at all. */
347 static GTY(()) bool text_section_used = false;
348 static GTY(()) bool cold_text_section_used = false;
350 /* The default cold text section. */
351 static GTY(()) section *cold_text_section;
353 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
355 /* Forward declarations for functions defined in this file. */
357 static char *stripattributes (const char *);
358 static const char *dwarf_cfi_name (unsigned);
359 static dw_cfi_ref new_cfi (void);
360 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
361 static void add_fde_cfi (const char *, dw_cfi_ref);
362 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
363 static void lookup_cfa (dw_cfa_location *);
364 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
365 #ifdef DWARF2_UNWIND_INFO
366 static void initial_return_save (rtx);
368 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
369 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
370 static void output_call_frame_info (int);
371 static void dwarf2out_note_section_used (void);
372 static void dwarf2out_stack_adjust (rtx, bool);
373 static void flush_queued_reg_saves (void);
374 static bool clobbers_queued_reg_save (const_rtx);
375 static void dwarf2out_frame_debug_expr (rtx, const char *);
377 /* Support for complex CFA locations. */
378 static void output_cfa_loc (dw_cfi_ref);
379 static void get_cfa_from_loc_descr (dw_cfa_location *,
380 struct dw_loc_descr_struct *);
381 static struct dw_loc_descr_struct *build_cfa_loc
382 (dw_cfa_location *, HOST_WIDE_INT);
383 static void def_cfa_1 (const char *, dw_cfa_location *);
385 /* How to start an assembler comment. */
386 #ifndef ASM_COMMENT_START
387 #define ASM_COMMENT_START ";#"
390 /* Data and reference forms for relocatable data. */
391 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
392 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
394 #ifndef DEBUG_FRAME_SECTION
395 #define DEBUG_FRAME_SECTION ".debug_frame"
398 #ifndef FUNC_BEGIN_LABEL
399 #define FUNC_BEGIN_LABEL "LFB"
402 #ifndef FUNC_END_LABEL
403 #define FUNC_END_LABEL "LFE"
406 #ifndef FRAME_BEGIN_LABEL
407 #define FRAME_BEGIN_LABEL "Lframe"
409 #define CIE_AFTER_SIZE_LABEL "LSCIE"
410 #define CIE_END_LABEL "LECIE"
411 #define FDE_LABEL "LSFDE"
412 #define FDE_AFTER_SIZE_LABEL "LASFDE"
413 #define FDE_END_LABEL "LEFDE"
414 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
415 #define LINE_NUMBER_END_LABEL "LELT"
416 #define LN_PROLOG_AS_LABEL "LASLTP"
417 #define LN_PROLOG_END_LABEL "LELTP"
418 #define DIE_LABEL_PREFIX "DW"
420 /* The DWARF 2 CFA column which tracks the return address. Normally this
421 is the column for PC, or the first column after all of the hard
423 #ifndef DWARF_FRAME_RETURN_COLUMN
425 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
427 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
431 /* The mapping from gcc register number to DWARF 2 CFA column number. By
432 default, we just provide columns for all registers. */
433 #ifndef DWARF_FRAME_REGNUM
434 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
437 /* Hook used by __throw. */
440 expand_builtin_dwarf_sp_column (void)
442 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
443 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
446 /* Return a pointer to a copy of the section string name S with all
447 attributes stripped off, and an asterisk prepended (for assemble_name). */
450 stripattributes (const char *s)
452 char *stripped = XNEWVEC (char, strlen (s) + 2);
457 while (*s && *s != ',')
464 /* MEM is a memory reference for the register size table, each element of
465 which has mode MODE. Initialize column C as a return address column. */
468 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
470 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
471 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
472 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
475 /* Generate code to initialize the register size table. */
478 expand_builtin_init_dwarf_reg_sizes (tree address)
481 enum machine_mode mode = TYPE_MODE (char_type_node);
482 rtx addr = expand_normal (address);
483 rtx mem = gen_rtx_MEM (BLKmode, addr);
484 bool wrote_return_column = false;
486 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
488 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
490 if (rnum < DWARF_FRAME_REGISTERS)
492 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
493 enum machine_mode save_mode = reg_raw_mode[i];
496 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
497 save_mode = choose_hard_reg_mode (i, 1, true);
498 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
500 if (save_mode == VOIDmode)
502 wrote_return_column = true;
504 size = GET_MODE_SIZE (save_mode);
508 emit_move_insn (adjust_address (mem, mode, offset),
509 gen_int_mode (size, mode));
513 if (!wrote_return_column)
514 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
516 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
517 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
520 targetm.init_dwarf_reg_sizes_extra (address);
523 /* Convert a DWARF call frame info. operation to its string name */
526 dwarf_cfi_name (unsigned int cfi_opc)
530 case DW_CFA_advance_loc:
531 return "DW_CFA_advance_loc";
533 return "DW_CFA_offset";
535 return "DW_CFA_restore";
539 return "DW_CFA_set_loc";
540 case DW_CFA_advance_loc1:
541 return "DW_CFA_advance_loc1";
542 case DW_CFA_advance_loc2:
543 return "DW_CFA_advance_loc2";
544 case DW_CFA_advance_loc4:
545 return "DW_CFA_advance_loc4";
546 case DW_CFA_offset_extended:
547 return "DW_CFA_offset_extended";
548 case DW_CFA_restore_extended:
549 return "DW_CFA_restore_extended";
550 case DW_CFA_undefined:
551 return "DW_CFA_undefined";
552 case DW_CFA_same_value:
553 return "DW_CFA_same_value";
554 case DW_CFA_register:
555 return "DW_CFA_register";
556 case DW_CFA_remember_state:
557 return "DW_CFA_remember_state";
558 case DW_CFA_restore_state:
559 return "DW_CFA_restore_state";
561 return "DW_CFA_def_cfa";
562 case DW_CFA_def_cfa_register:
563 return "DW_CFA_def_cfa_register";
564 case DW_CFA_def_cfa_offset:
565 return "DW_CFA_def_cfa_offset";
568 case DW_CFA_def_cfa_expression:
569 return "DW_CFA_def_cfa_expression";
570 case DW_CFA_expression:
571 return "DW_CFA_expression";
572 case DW_CFA_offset_extended_sf:
573 return "DW_CFA_offset_extended_sf";
574 case DW_CFA_def_cfa_sf:
575 return "DW_CFA_def_cfa_sf";
576 case DW_CFA_def_cfa_offset_sf:
577 return "DW_CFA_def_cfa_offset_sf";
579 /* SGI/MIPS specific */
580 case DW_CFA_MIPS_advance_loc8:
581 return "DW_CFA_MIPS_advance_loc8";
584 case DW_CFA_GNU_window_save:
585 return "DW_CFA_GNU_window_save";
586 case DW_CFA_GNU_args_size:
587 return "DW_CFA_GNU_args_size";
588 case DW_CFA_GNU_negative_offset_extended:
589 return "DW_CFA_GNU_negative_offset_extended";
592 return "DW_CFA_<unknown>";
596 /* Return a pointer to a newly allocated Call Frame Instruction. */
598 static inline dw_cfi_ref
601 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
603 cfi->dw_cfi_next = NULL;
604 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
605 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
610 /* Add a Call Frame Instruction to list of instructions. */
613 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
617 /* Find the end of the chain. */
618 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
624 /* Generate a new label for the CFI info to refer to. */
627 dwarf2out_cfi_label (void)
629 static char label[20];
631 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
632 ASM_OUTPUT_LABEL (asm_out_file, label);
636 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
637 or to the CIE if LABEL is NULL. */
640 add_fde_cfi (const char *label, dw_cfi_ref cfi)
644 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
647 label = dwarf2out_cfi_label ();
649 if (fde->dw_fde_current_label == NULL
650 || strcmp (label, fde->dw_fde_current_label) != 0)
654 label = xstrdup (label);
656 /* Set the location counter to the new label. */
658 /* If we have a current label, advance from there, otherwise
659 set the location directly using set_loc. */
660 xcfi->dw_cfi_opc = fde->dw_fde_current_label
661 ? DW_CFA_advance_loc4
663 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
664 add_cfi (&fde->dw_fde_cfi, xcfi);
666 fde->dw_fde_current_label = label;
669 add_cfi (&fde->dw_fde_cfi, cfi);
673 add_cfi (&cie_cfi_head, cfi);
676 /* Subroutine of lookup_cfa. */
679 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
681 switch (cfi->dw_cfi_opc)
683 case DW_CFA_def_cfa_offset:
684 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
686 case DW_CFA_def_cfa_offset_sf:
688 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
690 case DW_CFA_def_cfa_register:
691 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
694 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
695 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
697 case DW_CFA_def_cfa_sf:
698 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
700 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
702 case DW_CFA_def_cfa_expression:
703 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
710 /* Find the previous value for the CFA. */
713 lookup_cfa (dw_cfa_location *loc)
717 loc->reg = INVALID_REGNUM;
720 loc->base_offset = 0;
722 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
723 lookup_cfa_1 (cfi, loc);
725 if (fde_table_in_use)
727 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
728 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
729 lookup_cfa_1 (cfi, loc);
733 /* The current rule for calculating the DWARF2 canonical frame address. */
734 static dw_cfa_location cfa;
736 /* The register used for saving registers to the stack, and its offset
738 static dw_cfa_location cfa_store;
740 /* The running total of the size of arguments pushed onto the stack. */
741 static HOST_WIDE_INT args_size;
743 /* The last args_size we actually output. */
744 static HOST_WIDE_INT old_args_size;
746 /* Entry point to update the canonical frame address (CFA).
747 LABEL is passed to add_fde_cfi. The value of CFA is now to be
748 calculated from REG+OFFSET. */
751 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
758 def_cfa_1 (label, &loc);
761 /* Determine if two dw_cfa_location structures define the same data. */
764 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
766 return (loc1->reg == loc2->reg
767 && loc1->offset == loc2->offset
768 && loc1->indirect == loc2->indirect
769 && (loc1->indirect == 0
770 || loc1->base_offset == loc2->base_offset));
773 /* This routine does the actual work. The CFA is now calculated from
774 the dw_cfa_location structure. */
777 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
780 dw_cfa_location old_cfa, loc;
785 if (cfa_store.reg == loc.reg && loc.indirect == 0)
786 cfa_store.offset = loc.offset;
788 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
789 lookup_cfa (&old_cfa);
791 /* If nothing changed, no need to issue any call frame instructions. */
792 if (cfa_equal_p (&loc, &old_cfa))
797 if (loc.reg == old_cfa.reg && !loc.indirect)
799 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
800 the CFA register did not change but the offset did. */
803 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
804 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
806 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
807 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
811 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
812 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
816 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
817 else if (loc.offset == old_cfa.offset
818 && old_cfa.reg != INVALID_REGNUM
821 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
822 indicating the CFA register has changed to <register> but the
823 offset has not changed. */
824 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
825 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 else if (loc.indirect == 0)
831 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
832 indicating the CFA register has changed to <register> with
833 the specified offset. */
836 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
837 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
840 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
841 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
845 cfi->dw_cfi_opc = DW_CFA_def_cfa;
846 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
847 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
852 /* Construct a DW_CFA_def_cfa_expression instruction to
853 calculate the CFA using a full location expression since no
854 register-offset pair is available. */
855 struct dw_loc_descr_struct *loc_list;
857 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
858 loc_list = build_cfa_loc (&loc, 0);
859 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
862 add_fde_cfi (label, cfi);
865 /* Add the CFI for saving a register. REG is the CFA column number.
866 LABEL is passed to add_fde_cfi.
867 If SREG is -1, the register is saved at OFFSET from the CFA;
868 otherwise it is saved in SREG. */
871 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
873 dw_cfi_ref cfi = new_cfi ();
875 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
877 if (sreg == INVALID_REGNUM)
880 /* The register number won't fit in 6 bits, so we have to use
882 cfi->dw_cfi_opc = DW_CFA_offset_extended;
884 cfi->dw_cfi_opc = DW_CFA_offset;
886 #ifdef ENABLE_CHECKING
888 /* If we get an offset that is not a multiple of
889 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
890 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
892 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
894 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
897 offset /= DWARF_CIE_DATA_ALIGNMENT;
899 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
901 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
903 else if (sreg == reg)
904 cfi->dw_cfi_opc = DW_CFA_same_value;
907 cfi->dw_cfi_opc = DW_CFA_register;
908 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
911 add_fde_cfi (label, cfi);
914 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
915 This CFI tells the unwinder that it needs to restore the window registers
916 from the previous frame's window save area.
918 ??? Perhaps we should note in the CIE where windows are saved (instead of
919 assuming 0(cfa)) and what registers are in the window. */
922 dwarf2out_window_save (const char *label)
924 dw_cfi_ref cfi = new_cfi ();
926 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
927 add_fde_cfi (label, cfi);
930 /* Add a CFI to update the running total of the size of arguments
931 pushed onto the stack. */
934 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
938 if (size == old_args_size)
941 old_args_size = size;
944 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
945 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
946 add_fde_cfi (label, cfi);
949 /* Entry point for saving a register to the stack. REG is the GCC register
950 number. LABEL and OFFSET are passed to reg_save. */
953 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
955 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
964 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
967 /* Entry point for saving the return address in a register.
968 LABEL and SREG are passed to reg_save. */
971 dwarf2out_return_reg (const char *label, unsigned int sreg)
973 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
976 #ifdef DWARF2_UNWIND_INFO
977 /* Record the initial position of the return address. RTL is
978 INCOMING_RETURN_ADDR_RTX. */
981 initial_return_save (rtx rtl)
983 unsigned int reg = INVALID_REGNUM;
984 HOST_WIDE_INT offset = 0;
986 switch (GET_CODE (rtl))
989 /* RA is in a register. */
990 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
994 /* RA is on the stack. */
996 switch (GET_CODE (rtl))
999 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1004 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1005 offset = INTVAL (XEXP (rtl, 1));
1009 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1010 offset = -INTVAL (XEXP (rtl, 1));
1020 /* The return address is at some offset from any value we can
1021 actually load. For instance, on the SPARC it is in %i7+8. Just
1022 ignore the offset for now; it doesn't matter for unwinding frames. */
1023 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1024 initial_return_save (XEXP (rtl, 0));
1031 if (reg != DWARF_FRAME_RETURN_COLUMN)
1032 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1036 /* Given a SET, calculate the amount of stack adjustment it
1039 static HOST_WIDE_INT
1040 stack_adjust_offset (const_rtx pattern)
1042 const_rtx src = SET_SRC (pattern);
1043 const_rtx dest = SET_DEST (pattern);
1044 HOST_WIDE_INT offset = 0;
1047 if (dest == stack_pointer_rtx)
1049 /* (set (reg sp) (plus (reg sp) (const_int))) */
1050 code = GET_CODE (src);
1051 if (! (code == PLUS || code == MINUS)
1052 || XEXP (src, 0) != stack_pointer_rtx
1053 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1056 offset = INTVAL (XEXP (src, 1));
1060 else if (MEM_P (dest))
1062 /* (set (mem (pre_dec (reg sp))) (foo)) */
1063 src = XEXP (dest, 0);
1064 code = GET_CODE (src);
1070 if (XEXP (src, 0) == stack_pointer_rtx)
1072 rtx val = XEXP (XEXP (src, 1), 1);
1073 /* We handle only adjustments by constant amount. */
1074 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1075 && GET_CODE (val) == CONST_INT);
1076 offset = -INTVAL (val);
1083 if (XEXP (src, 0) == stack_pointer_rtx)
1085 offset = GET_MODE_SIZE (GET_MODE (dest));
1092 if (XEXP (src, 0) == stack_pointer_rtx)
1094 offset = -GET_MODE_SIZE (GET_MODE (dest));
1109 /* Check INSN to see if it looks like a push or a stack adjustment, and
1110 make a note of it if it does. EH uses this information to find out how
1111 much extra space it needs to pop off the stack. */
1114 dwarf2out_stack_adjust (rtx insn, bool after_p)
1116 HOST_WIDE_INT offset;
1120 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1121 with this function. Proper support would require all frame-related
1122 insns to be marked, and to be able to handle saving state around
1123 epilogues textually in the middle of the function. */
1124 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1127 /* If only calls can throw, and we have a frame pointer,
1128 save up adjustments until we see the CALL_INSN. */
1129 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1131 if (CALL_P (insn) && !after_p)
1133 /* Extract the size of the args from the CALL rtx itself. */
1134 insn = PATTERN (insn);
1135 if (GET_CODE (insn) == PARALLEL)
1136 insn = XVECEXP (insn, 0, 0);
1137 if (GET_CODE (insn) == SET)
1138 insn = SET_SRC (insn);
1139 gcc_assert (GET_CODE (insn) == CALL);
1140 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1145 if (CALL_P (insn) && !after_p)
1147 if (!flag_asynchronous_unwind_tables)
1148 dwarf2out_args_size ("", args_size);
1151 else if (BARRIER_P (insn))
1153 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1154 the compiler will have already emitted a stack adjustment, but
1155 doesn't bother for calls to noreturn functions. */
1156 #ifdef STACK_GROWS_DOWNWARD
1157 offset = -args_size;
1162 else if (GET_CODE (PATTERN (insn)) == SET)
1163 offset = stack_adjust_offset (PATTERN (insn));
1164 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1165 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1167 /* There may be stack adjustments inside compound insns. Search
1169 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1170 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1171 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1179 if (cfa.reg == STACK_POINTER_REGNUM)
1180 cfa.offset += offset;
1182 #ifndef STACK_GROWS_DOWNWARD
1186 args_size += offset;
1190 label = dwarf2out_cfi_label ();
1191 def_cfa_1 (label, &cfa);
1192 if (flag_asynchronous_unwind_tables)
1193 dwarf2out_args_size (label, args_size);
1198 /* We delay emitting a register save until either (a) we reach the end
1199 of the prologue or (b) the register is clobbered. This clusters
1200 register saves so that there are fewer pc advances. */
1202 struct queued_reg_save GTY(())
1204 struct queued_reg_save *next;
1206 HOST_WIDE_INT cfa_offset;
1210 static GTY(()) struct queued_reg_save *queued_reg_saves;
1212 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1213 struct reg_saved_in_data GTY(()) {
1218 /* A list of registers saved in other registers.
1219 The list intentionally has a small maximum capacity of 4; if your
1220 port needs more than that, you might consider implementing a
1221 more efficient data structure. */
1222 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1223 static GTY(()) size_t num_regs_saved_in_regs;
1225 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1226 static const char *last_reg_save_label;
1228 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1229 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1232 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1234 struct queued_reg_save *q;
1236 /* Duplicates waste space, but it's also necessary to remove them
1237 for correctness, since the queue gets output in reverse
1239 for (q = queued_reg_saves; q != NULL; q = q->next)
1240 if (REGNO (q->reg) == REGNO (reg))
1245 q = ggc_alloc (sizeof (*q));
1246 q->next = queued_reg_saves;
1247 queued_reg_saves = q;
1251 q->cfa_offset = offset;
1252 q->saved_reg = sreg;
1254 last_reg_save_label = label;
1257 /* Output all the entries in QUEUED_REG_SAVES. */
1260 flush_queued_reg_saves (void)
1262 struct queued_reg_save *q;
1264 for (q = queued_reg_saves; q; q = q->next)
1267 unsigned int reg, sreg;
1269 for (i = 0; i < num_regs_saved_in_regs; i++)
1270 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1272 if (q->saved_reg && i == num_regs_saved_in_regs)
1274 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1275 num_regs_saved_in_regs++;
1277 if (i != num_regs_saved_in_regs)
1279 regs_saved_in_regs[i].orig_reg = q->reg;
1280 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1283 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1285 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1287 sreg = INVALID_REGNUM;
1288 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1291 queued_reg_saves = NULL;
1292 last_reg_save_label = NULL;
1295 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1296 location for? Or, does it clobber a register which we've previously
1297 said that some other register is saved in, and for which we now
1298 have a new location for? */
1301 clobbers_queued_reg_save (const_rtx insn)
1303 struct queued_reg_save *q;
1305 for (q = queued_reg_saves; q; q = q->next)
1308 if (modified_in_p (q->reg, insn))
1310 for (i = 0; i < num_regs_saved_in_regs; i++)
1311 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1312 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1319 /* Entry point for saving the first register into the second. */
1322 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1325 unsigned int regno, sregno;
1327 for (i = 0; i < num_regs_saved_in_regs; i++)
1328 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1330 if (i == num_regs_saved_in_regs)
1332 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1333 num_regs_saved_in_regs++;
1335 regs_saved_in_regs[i].orig_reg = reg;
1336 regs_saved_in_regs[i].saved_in_reg = sreg;
1338 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1339 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1340 reg_save (label, regno, sregno, 0);
1343 /* What register, if any, is currently saved in REG? */
1346 reg_saved_in (rtx reg)
1348 unsigned int regn = REGNO (reg);
1350 struct queued_reg_save *q;
1352 for (q = queued_reg_saves; q; q = q->next)
1353 if (q->saved_reg && regn == REGNO (q->saved_reg))
1356 for (i = 0; i < num_regs_saved_in_regs; i++)
1357 if (regs_saved_in_regs[i].saved_in_reg
1358 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1359 return regs_saved_in_regs[i].orig_reg;
1365 /* A temporary register holding an integral value used in adjusting SP
1366 or setting up the store_reg. The "offset" field holds the integer
1367 value, not an offset. */
1368 static dw_cfa_location cfa_temp;
1370 /* Record call frame debugging information for an expression EXPR,
1371 which either sets SP or FP (adjusting how we calculate the frame
1372 address) or saves a register to the stack or another register.
1373 LABEL indicates the address of EXPR.
1375 This function encodes a state machine mapping rtxes to actions on
1376 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1377 users need not read the source code.
1379 The High-Level Picture
1381 Changes in the register we use to calculate the CFA: Currently we
1382 assume that if you copy the CFA register into another register, we
1383 should take the other one as the new CFA register; this seems to
1384 work pretty well. If it's wrong for some target, it's simple
1385 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1387 Changes in the register we use for saving registers to the stack:
1388 This is usually SP, but not always. Again, we deduce that if you
1389 copy SP into another register (and SP is not the CFA register),
1390 then the new register is the one we will be using for register
1391 saves. This also seems to work.
1393 Register saves: There's not much guesswork about this one; if
1394 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1395 register save, and the register used to calculate the destination
1396 had better be the one we think we're using for this purpose.
1397 It's also assumed that a copy from a call-saved register to another
1398 register is saving that register if RTX_FRAME_RELATED_P is set on
1399 that instruction. If the copy is from a call-saved register to
1400 the *same* register, that means that the register is now the same
1401 value as in the caller.
1403 Except: If the register being saved is the CFA register, and the
1404 offset is nonzero, we are saving the CFA, so we assume we have to
1405 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1406 the intent is to save the value of SP from the previous frame.
1408 In addition, if a register has previously been saved to a different
1411 Invariants / Summaries of Rules
1413 cfa current rule for calculating the CFA. It usually
1414 consists of a register and an offset.
1415 cfa_store register used by prologue code to save things to the stack
1416 cfa_store.offset is the offset from the value of
1417 cfa_store.reg to the actual CFA
1418 cfa_temp register holding an integral value. cfa_temp.offset
1419 stores the value, which will be used to adjust the
1420 stack pointer. cfa_temp is also used like cfa_store,
1421 to track stores to the stack via fp or a temp reg.
1423 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1424 with cfa.reg as the first operand changes the cfa.reg and its
1425 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1428 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1429 expression yielding a constant. This sets cfa_temp.reg
1430 and cfa_temp.offset.
1432 Rule 5: Create a new register cfa_store used to save items to the
1435 Rules 10-14: Save a register to the stack. Define offset as the
1436 difference of the original location and cfa_store's
1437 location (or cfa_temp's location if cfa_temp is used).
1441 "{a,b}" indicates a choice of a xor b.
1442 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1445 (set <reg1> <reg2>:cfa.reg)
1446 effects: cfa.reg = <reg1>
1447 cfa.offset unchanged
1448 cfa_temp.reg = <reg1>
1449 cfa_temp.offset = cfa.offset
1452 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1453 {<const_int>,<reg>:cfa_temp.reg}))
1454 effects: cfa.reg = sp if fp used
1455 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1456 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1457 if cfa_store.reg==sp
1460 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1461 effects: cfa.reg = fp
1462 cfa_offset += +/- <const_int>
1465 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1466 constraints: <reg1> != fp
1468 effects: cfa.reg = <reg1>
1469 cfa_temp.reg = <reg1>
1470 cfa_temp.offset = cfa.offset
1473 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1474 constraints: <reg1> != fp
1476 effects: cfa_store.reg = <reg1>
1477 cfa_store.offset = cfa.offset - cfa_temp.offset
1480 (set <reg> <const_int>)
1481 effects: cfa_temp.reg = <reg>
1482 cfa_temp.offset = <const_int>
1485 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1486 effects: cfa_temp.reg = <reg1>
1487 cfa_temp.offset |= <const_int>
1490 (set <reg> (high <exp>))
1494 (set <reg> (lo_sum <exp> <const_int>))
1495 effects: cfa_temp.reg = <reg>
1496 cfa_temp.offset = <const_int>
1499 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1500 effects: cfa_store.offset -= <const_int>
1501 cfa.offset = cfa_store.offset if cfa.reg == sp
1503 cfa.base_offset = -cfa_store.offset
1506 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1507 effects: cfa_store.offset += -/+ mode_size(mem)
1508 cfa.offset = cfa_store.offset if cfa.reg == sp
1510 cfa.base_offset = -cfa_store.offset
1513 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1516 effects: cfa.reg = <reg1>
1517 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1520 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1521 effects: cfa.reg = <reg1>
1522 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1525 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1526 effects: cfa.reg = <reg1>
1527 cfa.base_offset = -cfa_temp.offset
1528 cfa_temp.offset -= mode_size(mem)
1531 (set <reg> {unspec, unspec_volatile})
1532 effects: target-dependent */
1535 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1538 HOST_WIDE_INT offset;
1540 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1541 the PARALLEL independently. The first element is always processed if
1542 it is a SET. This is for backward compatibility. Other elements
1543 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1544 flag is set in them. */
1545 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1548 int limit = XVECLEN (expr, 0);
1551 /* PARALLELs have strict read-modify-write semantics, so we
1552 ought to evaluate every rvalue before changing any lvalue.
1553 It's cumbersome to do that in general, but there's an
1554 easy approximation that is enough for all current users:
1555 handle register saves before register assignments. */
1556 if (GET_CODE (expr) == PARALLEL)
1557 for (par_index = 0; par_index < limit; par_index++)
1559 elem = XVECEXP (expr, 0, par_index);
1560 if (GET_CODE (elem) == SET
1561 && MEM_P (SET_DEST (elem))
1562 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1563 dwarf2out_frame_debug_expr (elem, label);
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)) || GET_CODE (expr) == SEQUENCE)
1571 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1572 dwarf2out_frame_debug_expr (elem, label);
1577 gcc_assert (GET_CODE (expr) == SET);
1579 src = SET_SRC (expr);
1580 dest = SET_DEST (expr);
1584 rtx rsi = reg_saved_in (src);
1589 switch (GET_CODE (dest))
1592 switch (GET_CODE (src))
1594 /* Setting FP from SP. */
1596 if (cfa.reg == (unsigned) REGNO (src))
1599 /* Update the CFA rule wrt SP or FP. Make sure src is
1600 relative to the current CFA register.
1602 We used to require that dest be either SP or FP, but the
1603 ARM copies SP to a temporary register, and from there to
1604 FP. So we just rely on the backends to only set
1605 RTX_FRAME_RELATED_P on appropriate insns. */
1606 cfa.reg = REGNO (dest);
1607 cfa_temp.reg = cfa.reg;
1608 cfa_temp.offset = cfa.offset;
1612 /* Saving a register in a register. */
1613 gcc_assert (!fixed_regs [REGNO (dest)]
1614 /* For the SPARC and its register window. */
1615 || (DWARF_FRAME_REGNUM (REGNO (src))
1616 == DWARF_FRAME_RETURN_COLUMN));
1617 queue_reg_save (label, src, dest, 0);
1624 if (dest == stack_pointer_rtx)
1628 switch (GET_CODE (XEXP (src, 1)))
1631 offset = INTVAL (XEXP (src, 1));
1634 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1636 offset = cfa_temp.offset;
1642 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1644 /* Restoring SP from FP in the epilogue. */
1645 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1646 cfa.reg = STACK_POINTER_REGNUM;
1648 else if (GET_CODE (src) == LO_SUM)
1649 /* Assume we've set the source reg of the LO_SUM from sp. */
1652 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1654 if (GET_CODE (src) != MINUS)
1656 if (cfa.reg == STACK_POINTER_REGNUM)
1657 cfa.offset += offset;
1658 if (cfa_store.reg == STACK_POINTER_REGNUM)
1659 cfa_store.offset += offset;
1661 else if (dest == hard_frame_pointer_rtx)
1664 /* Either setting the FP from an offset of the SP,
1665 or adjusting the FP */
1666 gcc_assert (frame_pointer_needed);
1668 gcc_assert (REG_P (XEXP (src, 0))
1669 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1670 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1671 offset = INTVAL (XEXP (src, 1));
1672 if (GET_CODE (src) != MINUS)
1674 cfa.offset += offset;
1675 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1679 gcc_assert (GET_CODE (src) != MINUS);
1682 if (REG_P (XEXP (src, 0))
1683 && REGNO (XEXP (src, 0)) == cfa.reg
1684 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1686 /* Setting a temporary CFA register that will be copied
1687 into the FP later on. */
1688 offset = - INTVAL (XEXP (src, 1));
1689 cfa.offset += offset;
1690 cfa.reg = REGNO (dest);
1691 /* Or used to save regs to the stack. */
1692 cfa_temp.reg = cfa.reg;
1693 cfa_temp.offset = cfa.offset;
1697 else if (REG_P (XEXP (src, 0))
1698 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1699 && XEXP (src, 1) == stack_pointer_rtx)
1701 /* Setting a scratch register that we will use instead
1702 of SP for saving registers to the stack. */
1703 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1704 cfa_store.reg = REGNO (dest);
1705 cfa_store.offset = cfa.offset - cfa_temp.offset;
1709 else if (GET_CODE (src) == LO_SUM
1710 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1712 cfa_temp.reg = REGNO (dest);
1713 cfa_temp.offset = INTVAL (XEXP (src, 1));
1722 cfa_temp.reg = REGNO (dest);
1723 cfa_temp.offset = INTVAL (src);
1728 gcc_assert (REG_P (XEXP (src, 0))
1729 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1730 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1732 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1733 cfa_temp.reg = REGNO (dest);
1734 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1737 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1738 which will fill in all of the bits. */
1745 case UNSPEC_VOLATILE:
1746 gcc_assert (targetm.dwarf_handle_frame_unspec);
1747 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1754 def_cfa_1 (label, &cfa);
1758 gcc_assert (REG_P (src));
1760 /* Saving a register to the stack. Make sure dest is relative to the
1762 switch (GET_CODE (XEXP (dest, 0)))
1767 /* We can't handle variable size modifications. */
1768 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1770 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1772 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1773 && cfa_store.reg == STACK_POINTER_REGNUM);
1775 cfa_store.offset += offset;
1776 if (cfa.reg == STACK_POINTER_REGNUM)
1777 cfa.offset = cfa_store.offset;
1779 offset = -cfa_store.offset;
1785 offset = GET_MODE_SIZE (GET_MODE (dest));
1786 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1789 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1790 && cfa_store.reg == STACK_POINTER_REGNUM);
1792 cfa_store.offset += offset;
1793 if (cfa.reg == STACK_POINTER_REGNUM)
1794 cfa.offset = cfa_store.offset;
1796 offset = -cfa_store.offset;
1800 /* With an offset. */
1807 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1808 && REG_P (XEXP (XEXP (dest, 0), 0)));
1809 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1810 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1813 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1815 if (cfa_store.reg == (unsigned) regno)
1816 offset -= cfa_store.offset;
1819 gcc_assert (cfa_temp.reg == (unsigned) regno);
1820 offset -= cfa_temp.offset;
1826 /* Without an offset. */
1829 int regno = REGNO (XEXP (dest, 0));
1831 if (cfa_store.reg == (unsigned) regno)
1832 offset = -cfa_store.offset;
1835 gcc_assert (cfa_temp.reg == (unsigned) regno);
1836 offset = -cfa_temp.offset;
1843 gcc_assert (cfa_temp.reg
1844 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1845 offset = -cfa_temp.offset;
1846 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1853 if (REGNO (src) != STACK_POINTER_REGNUM
1854 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1855 && (unsigned) REGNO (src) == cfa.reg)
1857 /* We're storing the current CFA reg into the stack. */
1859 if (cfa.offset == 0)
1861 /* If the source register is exactly the CFA, assume
1862 we're saving SP like any other register; this happens
1864 def_cfa_1 (label, &cfa);
1865 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1870 /* Otherwise, we'll need to look in the stack to
1871 calculate the CFA. */
1872 rtx x = XEXP (dest, 0);
1876 gcc_assert (REG_P (x));
1878 cfa.reg = REGNO (x);
1879 cfa.base_offset = offset;
1881 def_cfa_1 (label, &cfa);
1886 def_cfa_1 (label, &cfa);
1887 queue_reg_save (label, src, NULL_RTX, offset);
1895 /* Record call frame debugging information for INSN, which either
1896 sets SP or FP (adjusting how we calculate the frame address) or saves a
1897 register to the stack. If INSN is NULL_RTX, initialize our state.
1899 If AFTER_P is false, we're being called before the insn is emitted,
1900 otherwise after. Call instructions get invoked twice. */
1903 dwarf2out_frame_debug (rtx insn, bool after_p)
1908 if (insn == NULL_RTX)
1912 /* Flush any queued register saves. */
1913 flush_queued_reg_saves ();
1915 /* Set up state for generating call frame debug info. */
1918 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1920 cfa.reg = STACK_POINTER_REGNUM;
1923 cfa_temp.offset = 0;
1925 for (i = 0; i < num_regs_saved_in_regs; i++)
1927 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1928 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1930 num_regs_saved_in_regs = 0;
1934 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1935 flush_queued_reg_saves ();
1937 if (! RTX_FRAME_RELATED_P (insn))
1939 if (!ACCUMULATE_OUTGOING_ARGS)
1940 dwarf2out_stack_adjust (insn, after_p);
1944 label = dwarf2out_cfi_label ();
1945 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1947 insn = XEXP (src, 0);
1949 insn = PATTERN (insn);
1951 dwarf2out_frame_debug_expr (insn, label);
1956 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1957 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1958 (enum dwarf_call_frame_info cfi);
1960 static enum dw_cfi_oprnd_type
1961 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1966 case DW_CFA_GNU_window_save:
1967 return dw_cfi_oprnd_unused;
1969 case DW_CFA_set_loc:
1970 case DW_CFA_advance_loc1:
1971 case DW_CFA_advance_loc2:
1972 case DW_CFA_advance_loc4:
1973 case DW_CFA_MIPS_advance_loc8:
1974 return dw_cfi_oprnd_addr;
1977 case DW_CFA_offset_extended:
1978 case DW_CFA_def_cfa:
1979 case DW_CFA_offset_extended_sf:
1980 case DW_CFA_def_cfa_sf:
1981 case DW_CFA_restore_extended:
1982 case DW_CFA_undefined:
1983 case DW_CFA_same_value:
1984 case DW_CFA_def_cfa_register:
1985 case DW_CFA_register:
1986 return dw_cfi_oprnd_reg_num;
1988 case DW_CFA_def_cfa_offset:
1989 case DW_CFA_GNU_args_size:
1990 case DW_CFA_def_cfa_offset_sf:
1991 return dw_cfi_oprnd_offset;
1993 case DW_CFA_def_cfa_expression:
1994 case DW_CFA_expression:
1995 return dw_cfi_oprnd_loc;
2002 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2003 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2004 (enum dwarf_call_frame_info cfi);
2006 static enum dw_cfi_oprnd_type
2007 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2011 case DW_CFA_def_cfa:
2012 case DW_CFA_def_cfa_sf:
2014 case DW_CFA_offset_extended_sf:
2015 case DW_CFA_offset_extended:
2016 return dw_cfi_oprnd_offset;
2018 case DW_CFA_register:
2019 return dw_cfi_oprnd_reg_num;
2022 return dw_cfi_oprnd_unused;
2026 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2028 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2029 switch to the data section instead, and write out a synthetic label
2033 switch_to_eh_frame_section (void)
2037 #ifdef EH_FRAME_SECTION_NAME
2038 if (eh_frame_section == 0)
2042 if (EH_TABLES_CAN_BE_READ_ONLY)
2048 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2050 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2052 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2054 flags = ((! flag_pic
2055 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2056 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2057 && (per_encoding & 0x70) != DW_EH_PE_absptr
2058 && (per_encoding & 0x70) != DW_EH_PE_aligned
2059 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2060 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2061 ? 0 : SECTION_WRITE);
2064 flags = SECTION_WRITE;
2065 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2069 if (eh_frame_section)
2070 switch_to_section (eh_frame_section);
2073 /* We have no special eh_frame section. Put the information in
2074 the data section and emit special labels to guide collect2. */
2075 switch_to_section (data_section);
2076 label = get_file_function_name ("F");
2077 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2078 targetm.asm_out.globalize_label (asm_out_file,
2079 IDENTIFIER_POINTER (label));
2080 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2084 /* Output a Call Frame Information opcode and its operand(s). */
2087 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2090 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2091 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2092 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2093 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2094 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2095 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2097 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2098 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2099 "DW_CFA_offset, column 0x%lx", r);
2100 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2102 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2104 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2105 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2106 "DW_CFA_restore, column 0x%lx", r);
2110 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2111 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2113 switch (cfi->dw_cfi_opc)
2115 case DW_CFA_set_loc:
2117 dw2_asm_output_encoded_addr_rtx (
2118 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2119 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2122 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2123 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2124 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2127 case DW_CFA_advance_loc1:
2128 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2129 fde->dw_fde_current_label, NULL);
2130 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2133 case DW_CFA_advance_loc2:
2134 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2135 fde->dw_fde_current_label, NULL);
2136 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2139 case DW_CFA_advance_loc4:
2140 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2141 fde->dw_fde_current_label, NULL);
2142 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2145 case DW_CFA_MIPS_advance_loc8:
2146 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2147 fde->dw_fde_current_label, NULL);
2148 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2151 case DW_CFA_offset_extended:
2152 case DW_CFA_def_cfa:
2153 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2154 dw2_asm_output_data_uleb128 (r, NULL);
2155 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2158 case DW_CFA_offset_extended_sf:
2159 case DW_CFA_def_cfa_sf:
2160 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2161 dw2_asm_output_data_uleb128 (r, NULL);
2162 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2165 case DW_CFA_restore_extended:
2166 case DW_CFA_undefined:
2167 case DW_CFA_same_value:
2168 case DW_CFA_def_cfa_register:
2169 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2170 dw2_asm_output_data_uleb128 (r, NULL);
2173 case DW_CFA_register:
2174 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2175 dw2_asm_output_data_uleb128 (r, NULL);
2176 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2177 dw2_asm_output_data_uleb128 (r, NULL);
2180 case DW_CFA_def_cfa_offset:
2181 case DW_CFA_GNU_args_size:
2182 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2185 case DW_CFA_def_cfa_offset_sf:
2186 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2189 case DW_CFA_GNU_window_save:
2192 case DW_CFA_def_cfa_expression:
2193 case DW_CFA_expression:
2194 output_cfa_loc (cfi);
2197 case DW_CFA_GNU_negative_offset_extended:
2198 /* Obsoleted by DW_CFA_offset_extended_sf. */
2207 /* Output the call frame information used to record information
2208 that relates to calculating the frame pointer, and records the
2209 location of saved registers. */
2212 output_call_frame_info (int for_eh)
2217 char l1[20], l2[20], section_start_label[20];
2218 bool any_lsda_needed = false;
2219 char augmentation[6];
2220 int augmentation_size;
2221 int fde_encoding = DW_EH_PE_absptr;
2222 int per_encoding = DW_EH_PE_absptr;
2223 int lsda_encoding = DW_EH_PE_absptr;
2226 /* Don't emit a CIE if there won't be any FDEs. */
2227 if (fde_table_in_use == 0)
2230 /* If we make FDEs linkonce, we may have to emit an empty label for
2231 an FDE that wouldn't otherwise be emitted. We want to avoid
2232 having an FDE kept around when the function it refers to is
2233 discarded. Example where this matters: a primary function
2234 template in C++ requires EH information, but an explicit
2235 specialization doesn't. */
2236 if (TARGET_USES_WEAK_UNWIND_INFO
2237 && ! flag_asynchronous_unwind_tables
2240 for (i = 0; i < fde_table_in_use; i++)
2241 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2242 && !fde_table[i].uses_eh_lsda
2243 && ! DECL_WEAK (fde_table[i].decl))
2244 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2245 for_eh, /* empty */ 1);
2247 /* If we don't have any functions we'll want to unwind out of, don't
2248 emit any EH unwind information. Note that if exceptions aren't
2249 enabled, we won't have collected nothrow information, and if we
2250 asked for asynchronous tables, we always want this info. */
2253 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2255 for (i = 0; i < fde_table_in_use; i++)
2256 if (fde_table[i].uses_eh_lsda)
2257 any_eh_needed = any_lsda_needed = true;
2258 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2259 any_eh_needed = true;
2260 else if (! fde_table[i].nothrow
2261 && ! fde_table[i].all_throwers_are_sibcalls)
2262 any_eh_needed = true;
2264 if (! any_eh_needed)
2268 /* We're going to be generating comments, so turn on app. */
2273 switch_to_eh_frame_section ();
2276 if (!debug_frame_section)
2277 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2278 SECTION_DEBUG, NULL);
2279 switch_to_section (debug_frame_section);
2282 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2283 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2285 /* Output the CIE. */
2286 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2287 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2288 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2289 dw2_asm_output_data (4, 0xffffffff,
2290 "Initial length escape value indicating 64-bit DWARF extension");
2291 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2292 "Length of Common Information Entry");
2293 ASM_OUTPUT_LABEL (asm_out_file, l1);
2295 /* Now that the CIE pointer is PC-relative for EH,
2296 use 0 to identify the CIE. */
2297 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2298 (for_eh ? 0 : DWARF_CIE_ID),
2299 "CIE Identifier Tag");
2301 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2303 augmentation[0] = 0;
2304 augmentation_size = 0;
2310 z Indicates that a uleb128 is present to size the
2311 augmentation section.
2312 L Indicates the encoding (and thus presence) of
2313 an LSDA pointer in the FDE augmentation.
2314 R Indicates a non-default pointer encoding for
2316 P Indicates the presence of an encoding + language
2317 personality routine in the CIE augmentation. */
2319 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2320 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2321 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2323 p = augmentation + 1;
2324 if (eh_personality_libfunc)
2327 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2328 assemble_external_libcall (eh_personality_libfunc);
2330 if (any_lsda_needed)
2333 augmentation_size += 1;
2335 if (fde_encoding != DW_EH_PE_absptr)
2338 augmentation_size += 1;
2340 if (p > augmentation + 1)
2342 augmentation[0] = 'z';
2346 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2347 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2349 int offset = ( 4 /* Length */
2351 + 1 /* CIE version */
2352 + strlen (augmentation) + 1 /* Augmentation */
2353 + size_of_uleb128 (1) /* Code alignment */
2354 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2356 + 1 /* Augmentation size */
2357 + 1 /* Personality encoding */ );
2358 int pad = -offset & (PTR_SIZE - 1);
2360 augmentation_size += pad;
2362 /* Augmentations should be small, so there's scarce need to
2363 iterate for a solution. Die if we exceed one uleb128 byte. */
2364 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2368 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2369 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2370 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2371 "CIE Data Alignment Factor");
2373 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2374 if (DW_CIE_VERSION == 1)
2375 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2377 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2379 if (augmentation[0])
2381 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2382 if (eh_personality_libfunc)
2384 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2385 eh_data_format_name (per_encoding));
2386 dw2_asm_output_encoded_addr_rtx (per_encoding,
2387 eh_personality_libfunc,
2391 if (any_lsda_needed)
2392 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2393 eh_data_format_name (lsda_encoding));
2395 if (fde_encoding != DW_EH_PE_absptr)
2396 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2397 eh_data_format_name (fde_encoding));
2400 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2401 output_cfi (cfi, NULL, for_eh);
2403 /* Pad the CIE out to an address sized boundary. */
2404 ASM_OUTPUT_ALIGN (asm_out_file,
2405 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2406 ASM_OUTPUT_LABEL (asm_out_file, l2);
2408 /* Loop through all of the FDE's. */
2409 for (i = 0; i < fde_table_in_use; i++)
2411 fde = &fde_table[i];
2413 /* Don't emit EH unwind info for leaf functions that don't need it. */
2414 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2415 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2416 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2417 && !fde->uses_eh_lsda)
2420 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2421 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2422 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2423 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2424 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2425 dw2_asm_output_data (4, 0xffffffff,
2426 "Initial length escape value indicating 64-bit DWARF extension");
2427 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2429 ASM_OUTPUT_LABEL (asm_out_file, l1);
2432 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2434 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2435 debug_frame_section, "FDE CIE offset");
2439 if (fde->dw_fde_switched_sections)
2441 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2442 fde->dw_fde_unlikely_section_label);
2443 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2444 fde->dw_fde_hot_section_label);
2445 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2446 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2447 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2448 "FDE initial location");
2449 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2450 fde->dw_fde_hot_section_end_label,
2451 fde->dw_fde_hot_section_label,
2452 "FDE address range");
2453 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2454 "FDE initial location");
2455 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2456 fde->dw_fde_unlikely_section_end_label,
2457 fde->dw_fde_unlikely_section_label,
2458 "FDE address range");
2462 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2463 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2464 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2467 "FDE initial location");
2468 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2469 fde->dw_fde_end, fde->dw_fde_begin,
2470 "FDE address range");
2475 if (fde->dw_fde_switched_sections)
2477 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2478 fde->dw_fde_hot_section_label,
2479 "FDE initial location");
2480 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2481 fde->dw_fde_hot_section_end_label,
2482 fde->dw_fde_hot_section_label,
2483 "FDE address range");
2484 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2485 fde->dw_fde_unlikely_section_label,
2486 "FDE initial location");
2487 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2488 fde->dw_fde_unlikely_section_end_label,
2489 fde->dw_fde_unlikely_section_label,
2490 "FDE address range");
2494 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2495 "FDE initial location");
2496 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2497 fde->dw_fde_end, fde->dw_fde_begin,
2498 "FDE address range");
2502 if (augmentation[0])
2504 if (any_lsda_needed)
2506 int size = size_of_encoded_value (lsda_encoding);
2508 if (lsda_encoding == DW_EH_PE_aligned)
2510 int offset = ( 4 /* Length */
2511 + 4 /* CIE offset */
2512 + 2 * size_of_encoded_value (fde_encoding)
2513 + 1 /* Augmentation size */ );
2514 int pad = -offset & (PTR_SIZE - 1);
2517 gcc_assert (size_of_uleb128 (size) == 1);
2520 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2522 if (fde->uses_eh_lsda)
2524 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2525 fde->funcdef_number);
2526 dw2_asm_output_encoded_addr_rtx (
2527 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2528 false, "Language Specific Data Area");
2532 if (lsda_encoding == DW_EH_PE_aligned)
2533 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2535 (size_of_encoded_value (lsda_encoding), 0,
2536 "Language Specific Data Area (none)");
2540 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2543 /* Loop through the Call Frame Instructions associated with
2545 fde->dw_fde_current_label = fde->dw_fde_begin;
2546 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2547 output_cfi (cfi, fde, for_eh);
2549 /* Pad the FDE out to an address sized boundary. */
2550 ASM_OUTPUT_ALIGN (asm_out_file,
2551 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2552 ASM_OUTPUT_LABEL (asm_out_file, l2);
2555 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2556 dw2_asm_output_data (4, 0, "End of Table");
2557 #ifdef MIPS_DEBUGGING_INFO
2558 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2559 get a value of 0. Putting .align 0 after the label fixes it. */
2560 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2563 /* Turn off app to make assembly quicker. */
2568 /* Output a marker (i.e. a label) for the beginning of a function, before
2572 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2573 const char *file ATTRIBUTE_UNUSED)
2575 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2579 current_function_func_begin_label = NULL;
2581 #ifdef TARGET_UNWIND_INFO
2582 /* ??? current_function_func_begin_label is also used by except.c
2583 for call-site information. We must emit this label if it might
2585 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2586 && ! dwarf2out_do_frame ())
2589 if (! dwarf2out_do_frame ())
2593 switch_to_section (function_section (current_function_decl));
2594 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2595 current_function_funcdef_no);
2596 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2597 current_function_funcdef_no);
2598 dup_label = xstrdup (label);
2599 current_function_func_begin_label = dup_label;
2601 #ifdef TARGET_UNWIND_INFO
2602 /* We can elide the fde allocation if we're not emitting debug info. */
2603 if (! dwarf2out_do_frame ())
2607 /* Expand the fde table if necessary. */
2608 if (fde_table_in_use == fde_table_allocated)
2610 fde_table_allocated += FDE_TABLE_INCREMENT;
2611 fde_table = ggc_realloc (fde_table,
2612 fde_table_allocated * sizeof (dw_fde_node));
2613 memset (fde_table + fde_table_in_use, 0,
2614 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2617 /* Record the FDE associated with this function. */
2618 current_funcdef_fde = fde_table_in_use;
2620 /* Add the new FDE at the end of the fde_table. */
2621 fde = &fde_table[fde_table_in_use++];
2622 fde->decl = current_function_decl;
2623 fde->dw_fde_begin = dup_label;
2624 fde->dw_fde_current_label = dup_label;
2625 fde->dw_fde_hot_section_label = NULL;
2626 fde->dw_fde_hot_section_end_label = NULL;
2627 fde->dw_fde_unlikely_section_label = NULL;
2628 fde->dw_fde_unlikely_section_end_label = NULL;
2629 fde->dw_fde_switched_sections = false;
2630 fde->dw_fde_end = NULL;
2631 fde->dw_fde_cfi = NULL;
2632 fde->funcdef_number = current_function_funcdef_no;
2633 fde->nothrow = TREE_NOTHROW (current_function_decl);
2634 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2635 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2637 args_size = old_args_size = 0;
2639 /* We only want to output line number information for the genuine dwarf2
2640 prologue case, not the eh frame case. */
2641 #ifdef DWARF2_DEBUGGING_INFO
2643 dwarf2out_source_line (line, file);
2647 /* Output a marker (i.e. a label) for the absolute end of the generated code
2648 for a function definition. This gets called *after* the epilogue code has
2652 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2653 const char *file ATTRIBUTE_UNUSED)
2656 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2658 /* Output a label to mark the endpoint of the code generated for this
2660 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2661 current_function_funcdef_no);
2662 ASM_OUTPUT_LABEL (asm_out_file, label);
2663 fde = &fde_table[fde_table_in_use - 1];
2664 fde->dw_fde_end = xstrdup (label);
2668 dwarf2out_frame_init (void)
2670 /* Allocate the initial hunk of the fde_table. */
2671 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2672 fde_table_allocated = FDE_TABLE_INCREMENT;
2673 fde_table_in_use = 0;
2675 /* Generate the CFA instructions common to all FDE's. Do it now for the
2676 sake of lookup_cfa. */
2678 /* On entry, the Canonical Frame Address is at SP. */
2679 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2681 #ifdef DWARF2_UNWIND_INFO
2682 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2683 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2688 dwarf2out_frame_finish (void)
2690 /* Output call frame information. */
2691 if (DWARF2_FRAME_INFO)
2692 output_call_frame_info (0);
2694 #ifndef TARGET_UNWIND_INFO
2695 /* Output another copy for the unwinder. */
2696 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2697 output_call_frame_info (1);
2701 /* Note that the current function section is being used for code. */
2704 dwarf2out_note_section_used (void)
2706 section *sec = current_function_section ();
2707 if (sec == text_section)
2708 text_section_used = true;
2709 else if (sec == cold_text_section)
2710 cold_text_section_used = true;
2714 dwarf2out_switch_text_section (void)
2720 fde = &fde_table[fde_table_in_use - 1];
2721 fde->dw_fde_switched_sections = true;
2722 fde->dw_fde_hot_section_label = cfun->hot_section_label;
2723 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
2724 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
2725 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
2726 have_multiple_function_sections = true;
2728 /* Reset the current label on switching text sections, so that we
2729 don't attempt to advance_loc4 between labels in different sections. */
2730 fde->dw_fde_current_label = NULL;
2732 dwarf2out_note_section_used ();
2736 /* And now, the subset of the debugging information support code necessary
2737 for emitting location expressions. */
2739 /* Data about a single source file. */
2740 struct dwarf_file_data GTY(())
2742 const char * filename;
2746 /* We need some way to distinguish DW_OP_addr with a direct symbol
2747 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2748 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2751 typedef struct dw_val_struct *dw_val_ref;
2752 typedef struct die_struct *dw_die_ref;
2753 typedef const struct die_struct *const_dw_die_ref;
2754 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2755 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2757 /* Each DIE may have a series of attribute/value pairs. Values
2758 can take on several forms. The forms that are used in this
2759 implementation are listed below. */
2764 dw_val_class_offset,
2766 dw_val_class_loc_list,
2767 dw_val_class_range_list,
2769 dw_val_class_unsigned_const,
2770 dw_val_class_long_long,
2773 dw_val_class_die_ref,
2774 dw_val_class_fde_ref,
2775 dw_val_class_lbl_id,
2776 dw_val_class_lineptr,
2778 dw_val_class_macptr,
2782 /* Describe a double word constant value. */
2783 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2785 typedef struct dw_long_long_struct GTY(())
2792 /* Describe a floating point constant value, or a vector constant value. */
2794 typedef struct dw_vec_struct GTY(())
2796 unsigned char * GTY((length ("%h.length"))) array;
2802 /* The dw_val_node describes an attribute's value, as it is
2803 represented internally. */
2805 typedef struct dw_val_struct GTY(())
2807 enum dw_val_class val_class;
2808 union dw_val_struct_union
2810 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2811 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2812 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2813 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2814 HOST_WIDE_INT GTY ((default)) val_int;
2815 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2816 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2817 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2818 struct dw_val_die_union
2822 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2823 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2824 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2825 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2826 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2827 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2829 GTY ((desc ("%1.val_class"))) v;
2833 /* Locations in memory are described using a sequence of stack machine
2836 typedef struct dw_loc_descr_struct GTY(())
2838 dw_loc_descr_ref dw_loc_next;
2839 enum dwarf_location_atom dw_loc_opc;
2840 dw_val_node dw_loc_oprnd1;
2841 dw_val_node dw_loc_oprnd2;
2846 /* Location lists are ranges + location descriptions for that range,
2847 so you can track variables that are in different places over
2848 their entire life. */
2849 typedef struct dw_loc_list_struct GTY(())
2851 dw_loc_list_ref dw_loc_next;
2852 const char *begin; /* Label for begin address of range */
2853 const char *end; /* Label for end address of range */
2854 char *ll_symbol; /* Label for beginning of location list.
2855 Only on head of list */
2856 const char *section; /* Section this loclist is relative to */
2857 dw_loc_descr_ref expr;
2860 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2862 static const char *dwarf_stack_op_name (unsigned);
2863 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2864 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2865 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2866 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2867 static unsigned long size_of_locs (dw_loc_descr_ref);
2868 static void output_loc_operands (dw_loc_descr_ref);
2869 static void output_loc_sequence (dw_loc_descr_ref);
2871 /* Convert a DWARF stack opcode into its string name. */
2874 dwarf_stack_op_name (unsigned int op)
2879 case INTERNAL_DW_OP_tls_addr:
2880 return "DW_OP_addr";
2882 return "DW_OP_deref";
2884 return "DW_OP_const1u";
2886 return "DW_OP_const1s";
2888 return "DW_OP_const2u";
2890 return "DW_OP_const2s";
2892 return "DW_OP_const4u";
2894 return "DW_OP_const4s";
2896 return "DW_OP_const8u";
2898 return "DW_OP_const8s";
2900 return "DW_OP_constu";
2902 return "DW_OP_consts";
2906 return "DW_OP_drop";
2908 return "DW_OP_over";
2910 return "DW_OP_pick";
2912 return "DW_OP_swap";
2916 return "DW_OP_xderef";
2924 return "DW_OP_minus";
2936 return "DW_OP_plus";
2937 case DW_OP_plus_uconst:
2938 return "DW_OP_plus_uconst";
2944 return "DW_OP_shra";
2962 return "DW_OP_skip";
2964 return "DW_OP_lit0";
2966 return "DW_OP_lit1";
2968 return "DW_OP_lit2";
2970 return "DW_OP_lit3";
2972 return "DW_OP_lit4";
2974 return "DW_OP_lit5";
2976 return "DW_OP_lit6";
2978 return "DW_OP_lit7";
2980 return "DW_OP_lit8";
2982 return "DW_OP_lit9";
2984 return "DW_OP_lit10";
2986 return "DW_OP_lit11";
2988 return "DW_OP_lit12";
2990 return "DW_OP_lit13";
2992 return "DW_OP_lit14";
2994 return "DW_OP_lit15";
2996 return "DW_OP_lit16";
2998 return "DW_OP_lit17";
3000 return "DW_OP_lit18";
3002 return "DW_OP_lit19";
3004 return "DW_OP_lit20";
3006 return "DW_OP_lit21";
3008 return "DW_OP_lit22";
3010 return "DW_OP_lit23";
3012 return "DW_OP_lit24";
3014 return "DW_OP_lit25";
3016 return "DW_OP_lit26";
3018 return "DW_OP_lit27";
3020 return "DW_OP_lit28";
3022 return "DW_OP_lit29";
3024 return "DW_OP_lit30";
3026 return "DW_OP_lit31";
3028 return "DW_OP_reg0";
3030 return "DW_OP_reg1";
3032 return "DW_OP_reg2";
3034 return "DW_OP_reg3";
3036 return "DW_OP_reg4";
3038 return "DW_OP_reg5";
3040 return "DW_OP_reg6";
3042 return "DW_OP_reg7";
3044 return "DW_OP_reg8";
3046 return "DW_OP_reg9";
3048 return "DW_OP_reg10";
3050 return "DW_OP_reg11";
3052 return "DW_OP_reg12";
3054 return "DW_OP_reg13";
3056 return "DW_OP_reg14";
3058 return "DW_OP_reg15";
3060 return "DW_OP_reg16";
3062 return "DW_OP_reg17";
3064 return "DW_OP_reg18";
3066 return "DW_OP_reg19";
3068 return "DW_OP_reg20";
3070 return "DW_OP_reg21";
3072 return "DW_OP_reg22";
3074 return "DW_OP_reg23";
3076 return "DW_OP_reg24";
3078 return "DW_OP_reg25";
3080 return "DW_OP_reg26";
3082 return "DW_OP_reg27";
3084 return "DW_OP_reg28";
3086 return "DW_OP_reg29";
3088 return "DW_OP_reg30";
3090 return "DW_OP_reg31";
3092 return "DW_OP_breg0";
3094 return "DW_OP_breg1";
3096 return "DW_OP_breg2";
3098 return "DW_OP_breg3";
3100 return "DW_OP_breg4";
3102 return "DW_OP_breg5";
3104 return "DW_OP_breg6";
3106 return "DW_OP_breg7";
3108 return "DW_OP_breg8";
3110 return "DW_OP_breg9";
3112 return "DW_OP_breg10";
3114 return "DW_OP_breg11";
3116 return "DW_OP_breg12";
3118 return "DW_OP_breg13";
3120 return "DW_OP_breg14";
3122 return "DW_OP_breg15";
3124 return "DW_OP_breg16";
3126 return "DW_OP_breg17";
3128 return "DW_OP_breg18";
3130 return "DW_OP_breg19";
3132 return "DW_OP_breg20";
3134 return "DW_OP_breg21";
3136 return "DW_OP_breg22";
3138 return "DW_OP_breg23";
3140 return "DW_OP_breg24";
3142 return "DW_OP_breg25";
3144 return "DW_OP_breg26";
3146 return "DW_OP_breg27";
3148 return "DW_OP_breg28";
3150 return "DW_OP_breg29";
3152 return "DW_OP_breg30";
3154 return "DW_OP_breg31";
3156 return "DW_OP_regx";
3158 return "DW_OP_fbreg";
3160 return "DW_OP_bregx";
3162 return "DW_OP_piece";
3163 case DW_OP_deref_size:
3164 return "DW_OP_deref_size";
3165 case DW_OP_xderef_size:
3166 return "DW_OP_xderef_size";
3169 case DW_OP_push_object_address:
3170 return "DW_OP_push_object_address";
3172 return "DW_OP_call2";
3174 return "DW_OP_call4";
3175 case DW_OP_call_ref:
3176 return "DW_OP_call_ref";
3177 case DW_OP_GNU_push_tls_address:
3178 return "DW_OP_GNU_push_tls_address";
3179 case DW_OP_GNU_uninit:
3180 return "DW_OP_GNU_uninit";
3182 return "OP_<unknown>";
3186 /* Return a pointer to a newly allocated location description. Location
3187 descriptions are simple expression terms that can be strung
3188 together to form more complicated location (address) descriptions. */
3190 static inline dw_loc_descr_ref
3191 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3192 unsigned HOST_WIDE_INT oprnd2)
3194 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3196 descr->dw_loc_opc = op;
3197 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3198 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3199 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3200 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3205 /* Add a location description term to a location description expression. */
3208 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3210 dw_loc_descr_ref *d;
3212 /* Find the end of the chain. */
3213 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3219 /* Return the size of a location descriptor. */
3221 static unsigned long
3222 size_of_loc_descr (dw_loc_descr_ref loc)
3224 unsigned long size = 1;
3226 switch (loc->dw_loc_opc)
3229 case INTERNAL_DW_OP_tls_addr:
3230 size += DWARF2_ADDR_SIZE;
3249 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3252 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3257 case DW_OP_plus_uconst:
3258 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3296 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3299 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3302 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3305 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3306 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3309 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3311 case DW_OP_deref_size:
3312 case DW_OP_xderef_size:
3321 case DW_OP_call_ref:
3322 size += DWARF2_ADDR_SIZE;
3331 /* Return the size of a series of location descriptors. */
3333 static unsigned long
3334 size_of_locs (dw_loc_descr_ref loc)
3339 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3340 field, to avoid writing to a PCH file. */
3341 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3343 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3345 size += size_of_loc_descr (l);
3350 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3352 l->dw_loc_addr = size;
3353 size += size_of_loc_descr (l);
3359 /* Output location description stack opcode's operands (if any). */
3362 output_loc_operands (dw_loc_descr_ref loc)
3364 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3365 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3367 switch (loc->dw_loc_opc)
3369 #ifdef DWARF2_DEBUGGING_INFO
3371 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3375 dw2_asm_output_data (2, val1->v.val_int, NULL);
3379 dw2_asm_output_data (4, val1->v.val_int, NULL);
3383 gcc_assert (HOST_BITS_PER_LONG >= 64);
3384 dw2_asm_output_data (8, val1->v.val_int, NULL);
3391 gcc_assert (val1->val_class == dw_val_class_loc);
3392 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3394 dw2_asm_output_data (2, offset, NULL);
3407 /* We currently don't make any attempt to make sure these are
3408 aligned properly like we do for the main unwind info, so
3409 don't support emitting things larger than a byte if we're
3410 only doing unwinding. */
3415 dw2_asm_output_data (1, val1->v.val_int, NULL);
3418 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3421 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3424 dw2_asm_output_data (1, val1->v.val_int, NULL);
3426 case DW_OP_plus_uconst:
3427 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3461 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3464 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3467 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3470 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3471 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3474 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3476 case DW_OP_deref_size:
3477 case DW_OP_xderef_size:
3478 dw2_asm_output_data (1, val1->v.val_int, NULL);
3481 case INTERNAL_DW_OP_tls_addr:
3482 if (targetm.asm_out.output_dwarf_dtprel)
3484 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3487 fputc ('\n', asm_out_file);
3494 /* Other codes have no operands. */
3499 /* Output a sequence of location operations. */
3502 output_loc_sequence (dw_loc_descr_ref loc)
3504 for (; loc != NULL; loc = loc->dw_loc_next)
3506 /* Output the opcode. */
3507 dw2_asm_output_data (1, loc->dw_loc_opc,
3508 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3510 /* Output the operand(s) (if any). */
3511 output_loc_operands (loc);
3515 /* This routine will generate the correct assembly data for a location
3516 description based on a cfi entry with a complex address. */
3519 output_cfa_loc (dw_cfi_ref cfi)
3521 dw_loc_descr_ref loc;
3524 /* Output the size of the block. */
3525 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3526 size = size_of_locs (loc);
3527 dw2_asm_output_data_uleb128 (size, NULL);
3529 /* Now output the operations themselves. */
3530 output_loc_sequence (loc);
3533 /* This function builds a dwarf location descriptor sequence from a
3534 dw_cfa_location, adding the given OFFSET to the result of the
3537 static struct dw_loc_descr_struct *
3538 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3540 struct dw_loc_descr_struct *head, *tmp;
3542 offset += cfa->offset;
3546 if (cfa->base_offset)
3549 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3551 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3553 else if (cfa->reg <= 31)
3554 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3556 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3558 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3559 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3560 add_loc_descr (&head, tmp);
3563 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3564 add_loc_descr (&head, tmp);
3571 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3573 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3574 else if (cfa->reg <= 31)
3575 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3577 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3583 /* This function fills in aa dw_cfa_location structure from a dwarf location
3584 descriptor sequence. */
3587 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3589 struct dw_loc_descr_struct *ptr;
3591 cfa->base_offset = 0;
3595 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3597 enum dwarf_location_atom op = ptr->dw_loc_opc;
3633 cfa->reg = op - DW_OP_reg0;
3636 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3670 cfa->reg = op - DW_OP_breg0;
3671 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3674 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3675 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3680 case DW_OP_plus_uconst:
3681 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3684 internal_error ("DW_LOC_OP %s not implemented",
3685 dwarf_stack_op_name (ptr->dw_loc_opc));
3689 #endif /* .debug_frame support */
3691 /* And now, the support for symbolic debugging information. */
3692 #ifdef DWARF2_DEBUGGING_INFO
3694 /* .debug_str support. */
3695 static int output_indirect_string (void **, void *);
3697 static void dwarf2out_init (const char *);
3698 static void dwarf2out_finish (const char *);
3699 static void dwarf2out_define (unsigned int, const char *);
3700 static void dwarf2out_undef (unsigned int, const char *);
3701 static void dwarf2out_start_source_file (unsigned, const char *);
3702 static void dwarf2out_end_source_file (unsigned);
3703 static void dwarf2out_begin_block (unsigned, unsigned);
3704 static void dwarf2out_end_block (unsigned, unsigned);
3705 static bool dwarf2out_ignore_block (const_tree);
3706 static void dwarf2out_global_decl (tree);
3707 static void dwarf2out_type_decl (tree, int);
3708 static void dwarf2out_imported_module_or_decl (tree, tree);
3709 static void dwarf2out_abstract_function (tree);
3710 static void dwarf2out_var_location (rtx);
3711 static void dwarf2out_begin_function (tree);
3713 /* The debug hooks structure. */
3715 const struct gcc_debug_hooks dwarf2_debug_hooks =
3721 dwarf2out_start_source_file,
3722 dwarf2out_end_source_file,
3723 dwarf2out_begin_block,
3724 dwarf2out_end_block,
3725 dwarf2out_ignore_block,
3726 dwarf2out_source_line,
3727 dwarf2out_begin_prologue,
3728 debug_nothing_int_charstar, /* end_prologue */
3729 dwarf2out_end_epilogue,
3730 dwarf2out_begin_function,
3731 debug_nothing_int, /* end_function */
3732 dwarf2out_decl, /* function_decl */
3733 dwarf2out_global_decl,
3734 dwarf2out_type_decl, /* type_decl */
3735 dwarf2out_imported_module_or_decl,
3736 debug_nothing_tree, /* deferred_inline_function */
3737 /* The DWARF 2 backend tries to reduce debugging bloat by not
3738 emitting the abstract description of inline functions until
3739 something tries to reference them. */
3740 dwarf2out_abstract_function, /* outlining_inline_function */
3741 debug_nothing_rtx, /* label */
3742 debug_nothing_int, /* handle_pch */
3743 dwarf2out_var_location,
3744 dwarf2out_switch_text_section,
3745 1 /* start_end_main_source_file */
3749 /* NOTE: In the comments in this file, many references are made to
3750 "Debugging Information Entries". This term is abbreviated as `DIE'
3751 throughout the remainder of this file. */
3753 /* An internal representation of the DWARF output is built, and then
3754 walked to generate the DWARF debugging info. The walk of the internal
3755 representation is done after the entire program has been compiled.
3756 The types below are used to describe the internal representation. */
3758 /* Various DIE's use offsets relative to the beginning of the
3759 .debug_info section to refer to each other. */
3761 typedef long int dw_offset;
3763 /* Define typedefs here to avoid circular dependencies. */
3765 typedef struct dw_attr_struct *dw_attr_ref;
3766 typedef struct dw_line_info_struct *dw_line_info_ref;
3767 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3768 typedef struct pubname_struct *pubname_ref;
3769 typedef struct dw_ranges_struct *dw_ranges_ref;
3770 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3772 /* Each entry in the line_info_table maintains the file and
3773 line number associated with the label generated for that
3774 entry. The label gives the PC value associated with
3775 the line number entry. */
3777 typedef struct dw_line_info_struct GTY(())
3779 unsigned long dw_file_num;
3780 unsigned long dw_line_num;
3784 /* Line information for functions in separate sections; each one gets its
3786 typedef struct dw_separate_line_info_struct GTY(())
3788 unsigned long dw_file_num;
3789 unsigned long dw_line_num;
3790 unsigned long function;
3792 dw_separate_line_info_entry;
3794 /* Each DIE attribute has a field specifying the attribute kind,
3795 a link to the next attribute in the chain, and an attribute value.
3796 Attributes are typically linked below the DIE they modify. */
3798 typedef struct dw_attr_struct GTY(())
3800 enum dwarf_attribute dw_attr;
3801 dw_val_node dw_attr_val;
3805 DEF_VEC_O(dw_attr_node);
3806 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3808 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3809 The children of each node form a circular list linked by
3810 die_sib. die_child points to the node *before* the "first" child node. */
3812 typedef struct die_struct GTY(())
3814 enum dwarf_tag die_tag;
3816 VEC(dw_attr_node,gc) * die_attr;
3817 dw_die_ref die_parent;
3818 dw_die_ref die_child;
3820 dw_die_ref die_definition; /* ref from a specification to its definition */
3821 dw_offset die_offset;
3822 unsigned long die_abbrev;
3824 /* Die is used and must not be pruned as unused. */
3825 int die_perennial_p;
3826 unsigned int decl_id;
3830 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3831 #define FOR_EACH_CHILD(die, c, expr) do { \
3832 c = die->die_child; \
3836 } while (c != die->die_child); \
3839 /* The pubname structure */
3841 typedef struct pubname_struct GTY(())
3848 DEF_VEC_O(pubname_entry);
3849 DEF_VEC_ALLOC_O(pubname_entry, gc);
3851 struct dw_ranges_struct GTY(())
3853 /* If this is positive, it's a block number, otherwise it's a
3854 bitwise-negated index into dw_ranges_by_label. */
3858 struct dw_ranges_by_label_struct GTY(())
3864 /* The limbo die list structure. */
3865 typedef struct limbo_die_struct GTY(())
3869 struct limbo_die_struct *next;
3873 /* How to start an assembler comment. */
3874 #ifndef ASM_COMMENT_START
3875 #define ASM_COMMENT_START ";#"
3878 /* Define a macro which returns nonzero for a TYPE_DECL which was
3879 implicitly generated for a tagged type.
3881 Note that unlike the gcc front end (which generates a NULL named
3882 TYPE_DECL node for each complete tagged type, each array type, and
3883 each function type node created) the g++ front end generates a
3884 _named_ TYPE_DECL node for each tagged type node created.
3885 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3886 generate a DW_TAG_typedef DIE for them. */
3888 #define TYPE_DECL_IS_STUB(decl) \
3889 (DECL_NAME (decl) == NULL_TREE \
3890 || (DECL_ARTIFICIAL (decl) \
3891 && is_tagged_type (TREE_TYPE (decl)) \
3892 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3893 /* This is necessary for stub decls that \
3894 appear in nested inline functions. */ \
3895 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3896 && (decl_ultimate_origin (decl) \
3897 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3899 /* Information concerning the compilation unit's programming
3900 language, and compiler version. */
3902 /* Fixed size portion of the DWARF compilation unit header. */
3903 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3904 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3906 /* Fixed size portion of public names info. */
3907 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3909 /* Fixed size portion of the address range info. */
3910 #define DWARF_ARANGES_HEADER_SIZE \
3911 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3912 DWARF2_ADDR_SIZE * 2) \
3913 - DWARF_INITIAL_LENGTH_SIZE)
3915 /* Size of padding portion in the address range info. It must be
3916 aligned to twice the pointer size. */
3917 #define DWARF_ARANGES_PAD_SIZE \
3918 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3919 DWARF2_ADDR_SIZE * 2) \
3920 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3922 /* Use assembler line directives if available. */
3923 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3924 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3925 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3927 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3931 /* Minimum line offset in a special line info. opcode.
3932 This value was chosen to give a reasonable range of values. */
3933 #define DWARF_LINE_BASE -10
3935 /* First special line opcode - leave room for the standard opcodes. */
3936 #define DWARF_LINE_OPCODE_BASE 10
3938 /* Range of line offsets in a special line info. opcode. */
3939 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3941 /* Flag that indicates the initial value of the is_stmt_start flag.
3942 In the present implementation, we do not mark any lines as
3943 the beginning of a source statement, because that information
3944 is not made available by the GCC front-end. */
3945 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3947 #ifdef DWARF2_DEBUGGING_INFO
3948 /* This location is used by calc_die_sizes() to keep track
3949 the offset of each DIE within the .debug_info section. */
3950 static unsigned long next_die_offset;
3953 /* Record the root of the DIE's built for the current compilation unit. */
3954 static GTY(()) dw_die_ref comp_unit_die;
3956 /* A list of DIEs with a NULL parent waiting to be relocated. */
3957 static GTY(()) limbo_die_node *limbo_die_list;
3959 /* Filenames referenced by this compilation unit. */
3960 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3962 /* A hash table of references to DIE's that describe declarations.
3963 The key is a DECL_UID() which is a unique number identifying each decl. */
3964 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3966 /* Node of the variable location list. */
3967 struct var_loc_node GTY ((chain_next ("%h.next")))
3969 rtx GTY (()) var_loc_note;
3970 const char * GTY (()) label;
3971 const char * GTY (()) section_label;
3972 struct var_loc_node * GTY (()) next;
3975 /* Variable location list. */
3976 struct var_loc_list_def GTY (())
3978 struct var_loc_node * GTY (()) first;
3980 /* Do not mark the last element of the chained list because
3981 it is marked through the chain. */
3982 struct var_loc_node * GTY ((skip ("%h"))) last;
3984 /* DECL_UID of the variable decl. */
3985 unsigned int decl_id;
3987 typedef struct var_loc_list_def var_loc_list;
3990 /* Table of decl location linked lists. */
3991 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3993 /* A pointer to the base of a list of references to DIE's that
3994 are uniquely identified by their tag, presence/absence of
3995 children DIE's, and list of attribute/value pairs. */
3996 static GTY((length ("abbrev_die_table_allocated")))
3997 dw_die_ref *abbrev_die_table;
3999 /* Number of elements currently allocated for abbrev_die_table. */
4000 static GTY(()) unsigned abbrev_die_table_allocated;
4002 /* Number of elements in type_die_table currently in use. */
4003 static GTY(()) unsigned abbrev_die_table_in_use;
4005 /* Size (in elements) of increments by which we may expand the
4006 abbrev_die_table. */
4007 #define ABBREV_DIE_TABLE_INCREMENT 256
4009 /* A pointer to the base of a table that contains line information
4010 for each source code line in .text in the compilation unit. */
4011 static GTY((length ("line_info_table_allocated")))
4012 dw_line_info_ref line_info_table;
4014 /* Number of elements currently allocated for line_info_table. */
4015 static GTY(()) unsigned line_info_table_allocated;
4017 /* Number of elements in line_info_table currently in use. */
4018 static GTY(()) unsigned line_info_table_in_use;
4020 /* A pointer to the base of a table that contains line information
4021 for each source code line outside of .text in the compilation unit. */
4022 static GTY ((length ("separate_line_info_table_allocated")))
4023 dw_separate_line_info_ref separate_line_info_table;
4025 /* Number of elements currently allocated for separate_line_info_table. */
4026 static GTY(()) unsigned separate_line_info_table_allocated;
4028 /* Number of elements in separate_line_info_table currently in use. */
4029 static GTY(()) unsigned separate_line_info_table_in_use;
4031 /* Size (in elements) of increments by which we may expand the
4033 #define LINE_INFO_TABLE_INCREMENT 1024
4035 /* A pointer to the base of a table that contains a list of publicly
4036 accessible names. */
4037 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4039 /* A pointer to the base of a table that contains a list of publicly
4040 accessible types. */
4041 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4043 /* Array of dies for which we should generate .debug_arange info. */
4044 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4046 /* Number of elements currently allocated for arange_table. */
4047 static GTY(()) unsigned arange_table_allocated;
4049 /* Number of elements in arange_table currently in use. */
4050 static GTY(()) unsigned arange_table_in_use;
4052 /* Size (in elements) of increments by which we may expand the
4054 #define ARANGE_TABLE_INCREMENT 64
4056 /* Array of dies for which we should generate .debug_ranges info. */
4057 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4059 /* Number of elements currently allocated for ranges_table. */
4060 static GTY(()) unsigned ranges_table_allocated;
4062 /* Number of elements in ranges_table currently in use. */
4063 static GTY(()) unsigned ranges_table_in_use;
4065 /* Array of pairs of labels referenced in ranges_table. */
4066 static GTY ((length ("ranges_by_label_allocated")))
4067 dw_ranges_by_label_ref ranges_by_label;
4069 /* Number of elements currently allocated for ranges_by_label. */
4070 static GTY(()) unsigned ranges_by_label_allocated;
4072 /* Number of elements in ranges_by_label currently in use. */
4073 static GTY(()) unsigned ranges_by_label_in_use;
4075 /* Size (in elements) of increments by which we may expand the
4077 #define RANGES_TABLE_INCREMENT 64
4079 /* Whether we have location lists that need outputting */
4080 static GTY(()) bool have_location_lists;
4082 /* Unique label counter. */
4083 static GTY(()) unsigned int loclabel_num;
4085 #ifdef DWARF2_DEBUGGING_INFO
4086 /* Record whether the function being analyzed contains inlined functions. */
4087 static int current_function_has_inlines;
4089 #if 0 && defined (MIPS_DEBUGGING_INFO)
4090 static int comp_unit_has_inlines;
4093 /* The last file entry emitted by maybe_emit_file(). */
4094 static GTY(()) struct dwarf_file_data * last_emitted_file;
4096 /* Number of internal labels generated by gen_internal_sym(). */
4097 static GTY(()) int label_num;
4099 /* Cached result of previous call to lookup_filename. */
4100 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4102 #ifdef DWARF2_DEBUGGING_INFO
4104 /* Offset from the "steady-state frame pointer" to the frame base,
4105 within the current function. */
4106 static HOST_WIDE_INT frame_pointer_fb_offset;
4108 /* Forward declarations for functions defined in this file. */
4110 static int is_pseudo_reg (const_rtx);
4111 static tree type_main_variant (tree);
4112 static int is_tagged_type (const_tree);
4113 static const char *dwarf_tag_name (unsigned);
4114 static const char *dwarf_attr_name (unsigned);
4115 static const char *dwarf_form_name (unsigned);
4116 static tree decl_ultimate_origin (const_tree);
4117 static tree block_ultimate_origin (const_tree);
4118 static tree decl_class_context (tree);
4119 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4120 static inline enum dw_val_class AT_class (dw_attr_ref);
4121 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4122 static inline unsigned AT_flag (dw_attr_ref);
4123 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4124 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4125 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4126 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4127 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4129 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4130 unsigned int, unsigned char *);
4131 static hashval_t debug_str_do_hash (const void *);
4132 static int debug_str_eq (const void *, const void *);
4133 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4134 static inline const char *AT_string (dw_attr_ref);
4135 static int AT_string_form (dw_attr_ref);
4136 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4137 static void add_AT_specification (dw_die_ref, dw_die_ref);
4138 static inline dw_die_ref AT_ref (dw_attr_ref);
4139 static inline int AT_ref_external (dw_attr_ref);
4140 static inline void set_AT_ref_external (dw_attr_ref, int);
4141 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4142 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4143 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4144 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4146 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4147 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4148 static inline rtx AT_addr (dw_attr_ref);
4149 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4150 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4151 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4152 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4153 unsigned HOST_WIDE_INT);
4154 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4156 static inline const char *AT_lbl (dw_attr_ref);
4157 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4158 static const char *get_AT_low_pc (dw_die_ref);
4159 static const char *get_AT_hi_pc (dw_die_ref);
4160 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4161 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4162 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4163 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4164 static bool is_c_family (void);
4165 static bool is_cxx (void);
4166 static bool is_java (void);
4167 static bool is_fortran (void);
4168 static bool is_ada (void);
4169 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4170 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4171 static void add_child_die (dw_die_ref, dw_die_ref);
4172 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4173 static dw_die_ref lookup_type_die (tree);
4174 static void equate_type_number_to_die (tree, dw_die_ref);
4175 static hashval_t decl_die_table_hash (const void *);
4176 static int decl_die_table_eq (const void *, const void *);
4177 static dw_die_ref lookup_decl_die (tree);
4178 static hashval_t decl_loc_table_hash (const void *);
4179 static int decl_loc_table_eq (const void *, const void *);
4180 static var_loc_list *lookup_decl_loc (const_tree);
4181 static void equate_decl_number_to_die (tree, dw_die_ref);
4182 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4183 static void print_spaces (FILE *);
4184 static void print_die (dw_die_ref, FILE *);
4185 static void print_dwarf_line_table (FILE *);
4186 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4187 static dw_die_ref pop_compile_unit (dw_die_ref);
4188 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4189 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4190 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4191 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4192 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4193 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4194 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4195 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4196 static void compute_section_prefix (dw_die_ref);
4197 static int is_type_die (dw_die_ref);
4198 static int is_comdat_die (dw_die_ref);
4199 static int is_symbol_die (dw_die_ref);
4200 static void assign_symbol_names (dw_die_ref);
4201 static void break_out_includes (dw_die_ref);
4202 static hashval_t htab_cu_hash (const void *);
4203 static int htab_cu_eq (const void *, const void *);
4204 static void htab_cu_del (void *);
4205 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4206 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4207 static void add_sibling_attributes (dw_die_ref);
4208 static void build_abbrev_table (dw_die_ref);
4209 static void output_location_lists (dw_die_ref);
4210 static int constant_size (long unsigned);
4211 static unsigned long size_of_die (dw_die_ref);
4212 static void calc_die_sizes (dw_die_ref);
4213 static void mark_dies (dw_die_ref);
4214 static void unmark_dies (dw_die_ref);
4215 static void unmark_all_dies (dw_die_ref);
4216 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4217 static unsigned long size_of_aranges (void);
4218 static enum dwarf_form value_format (dw_attr_ref);
4219 static void output_value_format (dw_attr_ref);
4220 static void output_abbrev_section (void);
4221 static void output_die_symbol (dw_die_ref);
4222 static void output_die (dw_die_ref);
4223 static void output_compilation_unit_header (void);
4224 static void output_comp_unit (dw_die_ref, int);
4225 static const char *dwarf2_name (tree, int);
4226 static void add_pubname (tree, dw_die_ref);
4227 static void add_pubtype (tree, dw_die_ref);
4228 static void output_pubnames (VEC (pubname_entry,gc) *);
4229 static void add_arange (tree, dw_die_ref);
4230 static void output_aranges (void);
4231 static unsigned int add_ranges_num (int);
4232 static unsigned int add_ranges (const_tree);
4233 static unsigned int add_ranges_by_labels (const char *, const char *);
4234 static void output_ranges (void);
4235 static void output_line_info (void);
4236 static void output_file_names (void);
4237 static dw_die_ref base_type_die (tree);
4238 static int is_base_type (tree);
4239 static bool is_subrange_type (const_tree);
4240 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4241 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4242 static int type_is_enum (const_tree);
4243 static unsigned int dbx_reg_number (const_rtx);
4244 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4245 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4246 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4247 enum var_init_status);
4248 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4249 enum var_init_status);
4250 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4251 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4252 enum var_init_status);
4253 static int is_based_loc (const_rtx);
4254 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4255 enum var_init_status);
4256 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4257 enum var_init_status);
4258 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4259 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4260 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4261 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4262 static tree field_type (const_tree);
4263 static unsigned int simple_type_align_in_bits (const_tree);
4264 static unsigned int simple_decl_align_in_bits (const_tree);
4265 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
4266 static HOST_WIDE_INT field_byte_offset (const_tree);
4267 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4269 static void add_data_member_location_attribute (dw_die_ref, tree);
4270 static void add_const_value_attribute (dw_die_ref, rtx);
4271 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4272 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4273 static void insert_float (const_rtx, unsigned char *);
4274 static rtx rtl_for_decl_location (tree);
4275 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4276 enum dwarf_attribute);
4277 static void tree_add_const_value_attribute (dw_die_ref, tree);
4278 static void add_name_attribute (dw_die_ref, const char *);
4279 static void add_comp_dir_attribute (dw_die_ref);
4280 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4281 static void add_subscript_info (dw_die_ref, tree);
4282 static void add_byte_size_attribute (dw_die_ref, tree);
4283 static void add_bit_offset_attribute (dw_die_ref, tree);
4284 static void add_bit_size_attribute (dw_die_ref, tree);
4285 static void add_prototyped_attribute (dw_die_ref, tree);
4286 static void add_abstract_origin_attribute (dw_die_ref, tree);
4287 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4288 static void add_src_coords_attributes (dw_die_ref, tree);
4289 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4290 static void push_decl_scope (tree);
4291 static void pop_decl_scope (void);
4292 static dw_die_ref scope_die_for (tree, dw_die_ref);
4293 static inline int local_scope_p (dw_die_ref);
4294 static inline int class_or_namespace_scope_p (dw_die_ref);
4295 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4296 static void add_calling_convention_attribute (dw_die_ref, tree);
4297 static const char *type_tag (const_tree);
4298 static tree member_declared_type (const_tree);
4300 static const char *decl_start_label (tree);
4302 static void gen_array_type_die (tree, dw_die_ref);
4303 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4305 static void gen_entry_point_die (tree, dw_die_ref);
4307 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4308 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4309 static void gen_inlined_union_type_die (tree, dw_die_ref);
4310 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4311 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4312 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4313 static void gen_formal_types_die (tree, dw_die_ref);
4314 static void gen_subprogram_die (tree, dw_die_ref);
4315 static void gen_variable_die (tree, dw_die_ref);
4316 static void gen_label_die (tree, dw_die_ref);
4317 static void gen_lexical_block_die (tree, dw_die_ref, int);
4318 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4319 static void gen_field_die (tree, dw_die_ref);
4320 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4321 static dw_die_ref gen_compile_unit_die (const char *);
4322 static void gen_inheritance_die (tree, tree, dw_die_ref);
4323 static void gen_member_die (tree, dw_die_ref);
4324 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4325 enum debug_info_usage);
4326 static void gen_subroutine_type_die (tree, dw_die_ref);
4327 static void gen_typedef_die (tree, dw_die_ref);
4328 static void gen_type_die (tree, dw_die_ref);
4329 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4330 static void gen_block_die (tree, dw_die_ref, int);
4331 static void decls_for_scope (tree, dw_die_ref, int);
4332 static int is_redundant_typedef (const_tree);
4333 static void gen_namespace_die (tree);
4334 static void gen_decl_die (tree, dw_die_ref);
4335 static dw_die_ref force_decl_die (tree);
4336 static dw_die_ref force_type_die (tree);
4337 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4338 static void declare_in_namespace (tree, dw_die_ref);
4339 static struct dwarf_file_data * lookup_filename (const char *);
4340 static void retry_incomplete_types (void);
4341 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4342 static void splice_child_die (dw_die_ref, dw_die_ref);
4343 static int file_info_cmp (const void *, const void *);
4344 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4345 const char *, const char *, unsigned);
4346 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4347 const char *, const char *,
4349 static void output_loc_list (dw_loc_list_ref);
4350 static char *gen_internal_sym (const char *);
4352 static void prune_unmark_dies (dw_die_ref);
4353 static void prune_unused_types_mark (dw_die_ref, int);
4354 static void prune_unused_types_walk (dw_die_ref);
4355 static void prune_unused_types_walk_attribs (dw_die_ref);
4356 static void prune_unused_types_prune (dw_die_ref);
4357 static void prune_unused_types (void);
4358 static int maybe_emit_file (struct dwarf_file_data *fd);
4360 /* Section names used to hold DWARF debugging information. */
4361 #ifndef DEBUG_INFO_SECTION
4362 #define DEBUG_INFO_SECTION ".debug_info"
4364 #ifndef DEBUG_ABBREV_SECTION
4365 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4367 #ifndef DEBUG_ARANGES_SECTION
4368 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4370 #ifndef DEBUG_MACINFO_SECTION
4371 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4373 #ifndef DEBUG_LINE_SECTION
4374 #define DEBUG_LINE_SECTION ".debug_line"
4376 #ifndef DEBUG_LOC_SECTION
4377 #define DEBUG_LOC_SECTION ".debug_loc"
4379 #ifndef DEBUG_PUBNAMES_SECTION
4380 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4382 #ifndef DEBUG_STR_SECTION
4383 #define DEBUG_STR_SECTION ".debug_str"
4385 #ifndef DEBUG_RANGES_SECTION
4386 #define DEBUG_RANGES_SECTION ".debug_ranges"
4389 /* Standard ELF section names for compiled code and data. */
4390 #ifndef TEXT_SECTION_NAME
4391 #define TEXT_SECTION_NAME ".text"
4394 /* Section flags for .debug_str section. */
4395 #define DEBUG_STR_SECTION_FLAGS \
4396 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4397 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4400 /* Labels we insert at beginning sections we can reference instead of
4401 the section names themselves. */
4403 #ifndef TEXT_SECTION_LABEL
4404 #define TEXT_SECTION_LABEL "Ltext"
4406 #ifndef COLD_TEXT_SECTION_LABEL
4407 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4409 #ifndef DEBUG_LINE_SECTION_LABEL
4410 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4412 #ifndef DEBUG_INFO_SECTION_LABEL
4413 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4415 #ifndef DEBUG_ABBREV_SECTION_LABEL
4416 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4418 #ifndef DEBUG_LOC_SECTION_LABEL
4419 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4421 #ifndef DEBUG_RANGES_SECTION_LABEL
4422 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4424 #ifndef DEBUG_MACINFO_SECTION_LABEL
4425 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4428 /* Definitions of defaults for formats and names of various special
4429 (artificial) labels which may be generated within this file (when the -g
4430 options is used and DWARF2_DEBUGGING_INFO is in effect.
4431 If necessary, these may be overridden from within the tm.h file, but
4432 typically, overriding these defaults is unnecessary. */
4434 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4435 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4436 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4437 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4438 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4439 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4440 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4441 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4442 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4443 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4445 #ifndef TEXT_END_LABEL
4446 #define TEXT_END_LABEL "Letext"
4448 #ifndef COLD_END_LABEL
4449 #define COLD_END_LABEL "Letext_cold"
4451 #ifndef BLOCK_BEGIN_LABEL
4452 #define BLOCK_BEGIN_LABEL "LBB"
4454 #ifndef BLOCK_END_LABEL
4455 #define BLOCK_END_LABEL "LBE"
4457 #ifndef LINE_CODE_LABEL
4458 #define LINE_CODE_LABEL "LM"
4460 #ifndef SEPARATE_LINE_CODE_LABEL
4461 #define SEPARATE_LINE_CODE_LABEL "LSM"
4465 /* We allow a language front-end to designate a function that is to be
4466 called to "demangle" any name before it is put into a DIE. */
4468 static const char *(*demangle_name_func) (const char *);
4471 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4473 demangle_name_func = func;
4476 /* Test if rtl node points to a pseudo register. */
4479 is_pseudo_reg (const_rtx rtl)
4481 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4482 || (GET_CODE (rtl) == SUBREG
4483 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4486 /* Return a reference to a type, with its const and volatile qualifiers
4490 type_main_variant (tree type)
4492 type = TYPE_MAIN_VARIANT (type);
4494 /* ??? There really should be only one main variant among any group of
4495 variants of a given type (and all of the MAIN_VARIANT values for all
4496 members of the group should point to that one type) but sometimes the C
4497 front-end messes this up for array types, so we work around that bug
4499 if (TREE_CODE (type) == ARRAY_TYPE)
4500 while (type != TYPE_MAIN_VARIANT (type))
4501 type = TYPE_MAIN_VARIANT (type);
4506 /* Return nonzero if the given type node represents a tagged type. */
4509 is_tagged_type (const_tree type)
4511 enum tree_code code = TREE_CODE (type);
4513 return (code == RECORD_TYPE || code == UNION_TYPE
4514 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4517 /* Convert a DIE tag into its string name. */
4520 dwarf_tag_name (unsigned int tag)
4524 case DW_TAG_padding:
4525 return "DW_TAG_padding";
4526 case DW_TAG_array_type:
4527 return "DW_TAG_array_type";
4528 case DW_TAG_class_type:
4529 return "DW_TAG_class_type";
4530 case DW_TAG_entry_point:
4531 return "DW_TAG_entry_point";
4532 case DW_TAG_enumeration_type:
4533 return "DW_TAG_enumeration_type";
4534 case DW_TAG_formal_parameter:
4535 return "DW_TAG_formal_parameter";
4536 case DW_TAG_imported_declaration:
4537 return "DW_TAG_imported_declaration";
4539 return "DW_TAG_label";
4540 case DW_TAG_lexical_block:
4541 return "DW_TAG_lexical_block";
4543 return "DW_TAG_member";
4544 case DW_TAG_pointer_type:
4545 return "DW_TAG_pointer_type";
4546 case DW_TAG_reference_type:
4547 return "DW_TAG_reference_type";
4548 case DW_TAG_compile_unit:
4549 return "DW_TAG_compile_unit";
4550 case DW_TAG_string_type:
4551 return "DW_TAG_string_type";
4552 case DW_TAG_structure_type:
4553 return "DW_TAG_structure_type";
4554 case DW_TAG_subroutine_type:
4555 return "DW_TAG_subroutine_type";
4556 case DW_TAG_typedef:
4557 return "DW_TAG_typedef";
4558 case DW_TAG_union_type:
4559 return "DW_TAG_union_type";
4560 case DW_TAG_unspecified_parameters:
4561 return "DW_TAG_unspecified_parameters";
4562 case DW_TAG_variant:
4563 return "DW_TAG_variant";
4564 case DW_TAG_common_block:
4565 return "DW_TAG_common_block";
4566 case DW_TAG_common_inclusion:
4567 return "DW_TAG_common_inclusion";
4568 case DW_TAG_inheritance:
4569 return "DW_TAG_inheritance";
4570 case DW_TAG_inlined_subroutine:
4571 return "DW_TAG_inlined_subroutine";
4573 return "DW_TAG_module";
4574 case DW_TAG_ptr_to_member_type:
4575 return "DW_TAG_ptr_to_member_type";
4576 case DW_TAG_set_type:
4577 return "DW_TAG_set_type";
4578 case DW_TAG_subrange_type:
4579 return "DW_TAG_subrange_type";
4580 case DW_TAG_with_stmt:
4581 return "DW_TAG_with_stmt";
4582 case DW_TAG_access_declaration:
4583 return "DW_TAG_access_declaration";
4584 case DW_TAG_base_type:
4585 return "DW_TAG_base_type";
4586 case DW_TAG_catch_block:
4587 return "DW_TAG_catch_block";
4588 case DW_TAG_const_type:
4589 return "DW_TAG_const_type";
4590 case DW_TAG_constant:
4591 return "DW_TAG_constant";
4592 case DW_TAG_enumerator:
4593 return "DW_TAG_enumerator";
4594 case DW_TAG_file_type:
4595 return "DW_TAG_file_type";
4597 return "DW_TAG_friend";
4598 case DW_TAG_namelist:
4599 return "DW_TAG_namelist";
4600 case DW_TAG_namelist_item:
4601 return "DW_TAG_namelist_item";
4602 case DW_TAG_packed_type:
4603 return "DW_TAG_packed_type";
4604 case DW_TAG_subprogram:
4605 return "DW_TAG_subprogram";
4606 case DW_TAG_template_type_param:
4607 return "DW_TAG_template_type_param";
4608 case DW_TAG_template_value_param:
4609 return "DW_TAG_template_value_param";
4610 case DW_TAG_thrown_type:
4611 return "DW_TAG_thrown_type";
4612 case DW_TAG_try_block:
4613 return "DW_TAG_try_block";
4614 case DW_TAG_variant_part:
4615 return "DW_TAG_variant_part";
4616 case DW_TAG_variable:
4617 return "DW_TAG_variable";
4618 case DW_TAG_volatile_type:
4619 return "DW_TAG_volatile_type";
4620 case DW_TAG_dwarf_procedure:
4621 return "DW_TAG_dwarf_procedure";
4622 case DW_TAG_restrict_type:
4623 return "DW_TAG_restrict_type";
4624 case DW_TAG_interface_type:
4625 return "DW_TAG_interface_type";
4626 case DW_TAG_namespace:
4627 return "DW_TAG_namespace";
4628 case DW_TAG_imported_module:
4629 return "DW_TAG_imported_module";
4630 case DW_TAG_unspecified_type:
4631 return "DW_TAG_unspecified_type";
4632 case DW_TAG_partial_unit:
4633 return "DW_TAG_partial_unit";
4634 case DW_TAG_imported_unit:
4635 return "DW_TAG_imported_unit";
4636 case DW_TAG_condition:
4637 return "DW_TAG_condition";
4638 case DW_TAG_shared_type:
4639 return "DW_TAG_shared_type";
4640 case DW_TAG_MIPS_loop:
4641 return "DW_TAG_MIPS_loop";
4642 case DW_TAG_format_label:
4643 return "DW_TAG_format_label";
4644 case DW_TAG_function_template:
4645 return "DW_TAG_function_template";
4646 case DW_TAG_class_template:
4647 return "DW_TAG_class_template";
4648 case DW_TAG_GNU_BINCL:
4649 return "DW_TAG_GNU_BINCL";
4650 case DW_TAG_GNU_EINCL:
4651 return "DW_TAG_GNU_EINCL";
4653 return "DW_TAG_<unknown>";
4657 /* Convert a DWARF attribute code into its string name. */
4660 dwarf_attr_name (unsigned int attr)
4665 return "DW_AT_sibling";
4666 case DW_AT_location:
4667 return "DW_AT_location";
4669 return "DW_AT_name";
4670 case DW_AT_ordering:
4671 return "DW_AT_ordering";
4672 case DW_AT_subscr_data:
4673 return "DW_AT_subscr_data";
4674 case DW_AT_byte_size:
4675 return "DW_AT_byte_size";
4676 case DW_AT_bit_offset:
4677 return "DW_AT_bit_offset";
4678 case DW_AT_bit_size:
4679 return "DW_AT_bit_size";
4680 case DW_AT_element_list:
4681 return "DW_AT_element_list";
4682 case DW_AT_stmt_list:
4683 return "DW_AT_stmt_list";
4685 return "DW_AT_low_pc";
4687 return "DW_AT_high_pc";
4688 case DW_AT_language:
4689 return "DW_AT_language";
4691 return "DW_AT_member";
4693 return "DW_AT_discr";
4694 case DW_AT_discr_value:
4695 return "DW_AT_discr_value";
4696 case DW_AT_visibility:
4697 return "DW_AT_visibility";
4699 return "DW_AT_import";
4700 case DW_AT_string_length:
4701 return "DW_AT_string_length";
4702 case DW_AT_common_reference:
4703 return "DW_AT_common_reference";
4704 case DW_AT_comp_dir:
4705 return "DW_AT_comp_dir";
4706 case DW_AT_const_value:
4707 return "DW_AT_const_value";
4708 case DW_AT_containing_type:
4709 return "DW_AT_containing_type";
4710 case DW_AT_default_value:
4711 return "DW_AT_default_value";
4713 return "DW_AT_inline";
4714 case DW_AT_is_optional:
4715 return "DW_AT_is_optional";
4716 case DW_AT_lower_bound:
4717 return "DW_AT_lower_bound";
4718 case DW_AT_producer:
4719 return "DW_AT_producer";
4720 case DW_AT_prototyped:
4721 return "DW_AT_prototyped";
4722 case DW_AT_return_addr:
4723 return "DW_AT_return_addr";
4724 case DW_AT_start_scope:
4725 return "DW_AT_start_scope";
4726 case DW_AT_bit_stride:
4727 return "DW_AT_bit_stride";
4728 case DW_AT_upper_bound:
4729 return "DW_AT_upper_bound";
4730 case DW_AT_abstract_origin:
4731 return "DW_AT_abstract_origin";
4732 case DW_AT_accessibility:
4733 return "DW_AT_accessibility";
4734 case DW_AT_address_class:
4735 return "DW_AT_address_class";
4736 case DW_AT_artificial:
4737 return "DW_AT_artificial";
4738 case DW_AT_base_types:
4739 return "DW_AT_base_types";
4740 case DW_AT_calling_convention:
4741 return "DW_AT_calling_convention";
4743 return "DW_AT_count";
4744 case DW_AT_data_member_location:
4745 return "DW_AT_data_member_location";
4746 case DW_AT_decl_column:
4747 return "DW_AT_decl_column";
4748 case DW_AT_decl_file:
4749 return "DW_AT_decl_file";
4750 case DW_AT_decl_line:
4751 return "DW_AT_decl_line";
4752 case DW_AT_declaration:
4753 return "DW_AT_declaration";
4754 case DW_AT_discr_list:
4755 return "DW_AT_discr_list";
4756 case DW_AT_encoding:
4757 return "DW_AT_encoding";
4758 case DW_AT_external:
4759 return "DW_AT_external";
4760 case DW_AT_frame_base:
4761 return "DW_AT_frame_base";
4763 return "DW_AT_friend";
4764 case DW_AT_identifier_case:
4765 return "DW_AT_identifier_case";
4766 case DW_AT_macro_info:
4767 return "DW_AT_macro_info";
4768 case DW_AT_namelist_items:
4769 return "DW_AT_namelist_items";
4770 case DW_AT_priority:
4771 return "DW_AT_priority";
4773 return "DW_AT_segment";
4774 case DW_AT_specification:
4775 return "DW_AT_specification";
4776 case DW_AT_static_link:
4777 return "DW_AT_static_link";
4779 return "DW_AT_type";
4780 case DW_AT_use_location:
4781 return "DW_AT_use_location";
4782 case DW_AT_variable_parameter:
4783 return "DW_AT_variable_parameter";
4784 case DW_AT_virtuality:
4785 return "DW_AT_virtuality";
4786 case DW_AT_vtable_elem_location:
4787 return "DW_AT_vtable_elem_location";
4789 case DW_AT_allocated:
4790 return "DW_AT_allocated";
4791 case DW_AT_associated:
4792 return "DW_AT_associated";
4793 case DW_AT_data_location:
4794 return "DW_AT_data_location";
4795 case DW_AT_byte_stride:
4796 return "DW_AT_byte_stride";
4797 case DW_AT_entry_pc:
4798 return "DW_AT_entry_pc";
4799 case DW_AT_use_UTF8:
4800 return "DW_AT_use_UTF8";
4801 case DW_AT_extension:
4802 return "DW_AT_extension";
4804 return "DW_AT_ranges";
4805 case DW_AT_trampoline:
4806 return "DW_AT_trampoline";
4807 case DW_AT_call_column:
4808 return "DW_AT_call_column";
4809 case DW_AT_call_file:
4810 return "DW_AT_call_file";
4811 case DW_AT_call_line:
4812 return "DW_AT_call_line";
4814 case DW_AT_MIPS_fde:
4815 return "DW_AT_MIPS_fde";
4816 case DW_AT_MIPS_loop_begin:
4817 return "DW_AT_MIPS_loop_begin";
4818 case DW_AT_MIPS_tail_loop_begin:
4819 return "DW_AT_MIPS_tail_loop_begin";
4820 case DW_AT_MIPS_epilog_begin:
4821 return "DW_AT_MIPS_epilog_begin";
4822 case DW_AT_MIPS_loop_unroll_factor:
4823 return "DW_AT_MIPS_loop_unroll_factor";
4824 case DW_AT_MIPS_software_pipeline_depth:
4825 return "DW_AT_MIPS_software_pipeline_depth";
4826 case DW_AT_MIPS_linkage_name:
4827 return "DW_AT_MIPS_linkage_name";
4828 case DW_AT_MIPS_stride:
4829 return "DW_AT_MIPS_stride";
4830 case DW_AT_MIPS_abstract_name:
4831 return "DW_AT_MIPS_abstract_name";
4832 case DW_AT_MIPS_clone_origin:
4833 return "DW_AT_MIPS_clone_origin";
4834 case DW_AT_MIPS_has_inlines:
4835 return "DW_AT_MIPS_has_inlines";
4837 case DW_AT_sf_names:
4838 return "DW_AT_sf_names";
4839 case DW_AT_src_info:
4840 return "DW_AT_src_info";
4841 case DW_AT_mac_info:
4842 return "DW_AT_mac_info";
4843 case DW_AT_src_coords:
4844 return "DW_AT_src_coords";
4845 case DW_AT_body_begin:
4846 return "DW_AT_body_begin";
4847 case DW_AT_body_end:
4848 return "DW_AT_body_end";
4849 case DW_AT_GNU_vector:
4850 return "DW_AT_GNU_vector";
4852 case DW_AT_VMS_rtnbeg_pd_address:
4853 return "DW_AT_VMS_rtnbeg_pd_address";
4856 return "DW_AT_<unknown>";
4860 /* Convert a DWARF value form code into its string name. */
4863 dwarf_form_name (unsigned int form)
4868 return "DW_FORM_addr";
4869 case DW_FORM_block2:
4870 return "DW_FORM_block2";
4871 case DW_FORM_block4:
4872 return "DW_FORM_block4";
4874 return "DW_FORM_data2";
4876 return "DW_FORM_data4";
4878 return "DW_FORM_data8";
4879 case DW_FORM_string:
4880 return "DW_FORM_string";
4882 return "DW_FORM_block";
4883 case DW_FORM_block1:
4884 return "DW_FORM_block1";
4886 return "DW_FORM_data1";
4888 return "DW_FORM_flag";
4890 return "DW_FORM_sdata";
4892 return "DW_FORM_strp";
4894 return "DW_FORM_udata";
4895 case DW_FORM_ref_addr:
4896 return "DW_FORM_ref_addr";
4898 return "DW_FORM_ref1";
4900 return "DW_FORM_ref2";
4902 return "DW_FORM_ref4";
4904 return "DW_FORM_ref8";
4905 case DW_FORM_ref_udata:
4906 return "DW_FORM_ref_udata";
4907 case DW_FORM_indirect:
4908 return "DW_FORM_indirect";
4910 return "DW_FORM_<unknown>";
4914 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4915 instance of an inlined instance of a decl which is local to an inline
4916 function, so we have to trace all of the way back through the origin chain
4917 to find out what sort of node actually served as the original seed for the
4921 decl_ultimate_origin (const_tree decl)
4923 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4926 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4927 nodes in the function to point to themselves; ignore that if
4928 we're trying to output the abstract instance of this function. */
4929 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4932 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4933 most distant ancestor, this should never happen. */
4934 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4936 return DECL_ABSTRACT_ORIGIN (decl);
4939 /* Determine the "ultimate origin" of a block. The block may be an inlined
4940 instance of an inlined instance of a block which is local to an inline
4941 function, so we have to trace all of the way back through the origin chain
4942 to find out what sort of node actually served as the original seed for the
4946 block_ultimate_origin (const_tree block)
4948 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4950 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4951 nodes in the function to point to themselves; ignore that if
4952 we're trying to output the abstract instance of this function. */
4953 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4956 if (immediate_origin == NULL_TREE)
4961 tree lookahead = immediate_origin;
4965 ret_val = lookahead;
4966 lookahead = (TREE_CODE (ret_val) == BLOCK
4967 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4969 while (lookahead != NULL && lookahead != ret_val);
4971 /* The block's abstract origin chain may not be the *ultimate* origin of
4972 the block. It could lead to a DECL that has an abstract origin set.
4973 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4974 will give us if it has one). Note that DECL's abstract origins are
4975 supposed to be the most distant ancestor (or so decl_ultimate_origin
4976 claims), so we don't need to loop following the DECL origins. */
4977 if (DECL_P (ret_val))
4978 return DECL_ORIGIN (ret_val);
4984 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4985 of a virtual function may refer to a base class, so we check the 'this'
4989 decl_class_context (tree decl)
4991 tree context = NULL_TREE;
4993 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4994 context = DECL_CONTEXT (decl);
4996 context = TYPE_MAIN_VARIANT
4997 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4999 if (context && !TYPE_P (context))
5000 context = NULL_TREE;
5005 /* Add an attribute/value pair to a DIE. */
5008 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5010 /* Maybe this should be an assert? */
5014 if (die->die_attr == NULL)
5015 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5016 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5019 static inline enum dw_val_class
5020 AT_class (dw_attr_ref a)
5022 return a->dw_attr_val.val_class;
5025 /* Add a flag value attribute to a DIE. */
5028 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5032 attr.dw_attr = attr_kind;
5033 attr.dw_attr_val.val_class = dw_val_class_flag;
5034 attr.dw_attr_val.v.val_flag = flag;
5035 add_dwarf_attr (die, &attr);
5038 static inline unsigned
5039 AT_flag (dw_attr_ref a)
5041 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5042 return a->dw_attr_val.v.val_flag;
5045 /* Add a signed integer attribute value to a DIE. */
5048 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5052 attr.dw_attr = attr_kind;
5053 attr.dw_attr_val.val_class = dw_val_class_const;
5054 attr.dw_attr_val.v.val_int = int_val;
5055 add_dwarf_attr (die, &attr);
5058 static inline HOST_WIDE_INT
5059 AT_int (dw_attr_ref a)
5061 gcc_assert (a && AT_class (a) == dw_val_class_const);
5062 return a->dw_attr_val.v.val_int;
5065 /* Add an unsigned integer attribute value to a DIE. */
5068 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5069 unsigned HOST_WIDE_INT unsigned_val)
5073 attr.dw_attr = attr_kind;
5074 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5075 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5076 add_dwarf_attr (die, &attr);
5079 static inline unsigned HOST_WIDE_INT
5080 AT_unsigned (dw_attr_ref a)
5082 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5083 return a->dw_attr_val.v.val_unsigned;
5086 /* Add an unsigned double integer attribute value to a DIE. */
5089 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5090 long unsigned int val_hi, long unsigned int val_low)
5094 attr.dw_attr = attr_kind;
5095 attr.dw_attr_val.val_class = dw_val_class_long_long;
5096 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5097 attr.dw_attr_val.v.val_long_long.low = val_low;
5098 add_dwarf_attr (die, &attr);
5101 /* Add a floating point attribute value to a DIE and return it. */
5104 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5105 unsigned int length, unsigned int elt_size, unsigned char *array)
5109 attr.dw_attr = attr_kind;
5110 attr.dw_attr_val.val_class = dw_val_class_vec;
5111 attr.dw_attr_val.v.val_vec.length = length;
5112 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5113 attr.dw_attr_val.v.val_vec.array = array;
5114 add_dwarf_attr (die, &attr);
5117 /* Hash and equality functions for debug_str_hash. */
5120 debug_str_do_hash (const void *x)
5122 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5126 debug_str_eq (const void *x1, const void *x2)
5128 return strcmp ((((const struct indirect_string_node *)x1)->str),
5129 (const char *)x2) == 0;
5132 /* Add a string attribute value to a DIE. */
5135 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5138 struct indirect_string_node *node;
5141 if (! debug_str_hash)
5142 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5143 debug_str_eq, NULL);
5145 slot = htab_find_slot_with_hash (debug_str_hash, str,
5146 htab_hash_string (str), INSERT);
5149 node = (struct indirect_string_node *)
5150 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5151 node->str = ggc_strdup (str);
5155 node = (struct indirect_string_node *) *slot;
5159 attr.dw_attr = attr_kind;
5160 attr.dw_attr_val.val_class = dw_val_class_str;
5161 attr.dw_attr_val.v.val_str = node;
5162 add_dwarf_attr (die, &attr);
5165 static inline const char *
5166 AT_string (dw_attr_ref a)
5168 gcc_assert (a && AT_class (a) == dw_val_class_str);
5169 return a->dw_attr_val.v.val_str->str;
5172 /* Find out whether a string should be output inline in DIE
5173 or out-of-line in .debug_str section. */
5176 AT_string_form (dw_attr_ref a)
5178 struct indirect_string_node *node;
5182 gcc_assert (a && AT_class (a) == dw_val_class_str);
5184 node = a->dw_attr_val.v.val_str;
5188 len = strlen (node->str) + 1;
5190 /* If the string is shorter or equal to the size of the reference, it is
5191 always better to put it inline. */
5192 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5193 return node->form = DW_FORM_string;
5195 /* If we cannot expect the linker to merge strings in .debug_str
5196 section, only put it into .debug_str if it is worth even in this
5198 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5199 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5200 return node->form = DW_FORM_string;
5202 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5203 ++dw2_string_counter;
5204 node->label = xstrdup (label);
5206 return node->form = DW_FORM_strp;
5209 /* Add a DIE reference attribute value to a DIE. */
5212 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5216 attr.dw_attr = attr_kind;
5217 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5218 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5219 attr.dw_attr_val.v.val_die_ref.external = 0;
5220 add_dwarf_attr (die, &attr);
5223 /* Add an AT_specification attribute to a DIE, and also make the back
5224 pointer from the specification to the definition. */
5227 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5229 add_AT_die_ref (die, DW_AT_specification, targ_die);
5230 gcc_assert (!targ_die->die_definition);
5231 targ_die->die_definition = die;
5234 static inline dw_die_ref
5235 AT_ref (dw_attr_ref a)
5237 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5238 return a->dw_attr_val.v.val_die_ref.die;
5242 AT_ref_external (dw_attr_ref a)
5244 if (a && AT_class (a) == dw_val_class_die_ref)
5245 return a->dw_attr_val.v.val_die_ref.external;
5251 set_AT_ref_external (dw_attr_ref a, int i)
5253 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5254 a->dw_attr_val.v.val_die_ref.external = i;
5257 /* Add an FDE reference attribute value to a DIE. */
5260 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5264 attr.dw_attr = attr_kind;
5265 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5266 attr.dw_attr_val.v.val_fde_index = targ_fde;
5267 add_dwarf_attr (die, &attr);
5270 /* Add a location description attribute value to a DIE. */
5273 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5277 attr.dw_attr = attr_kind;
5278 attr.dw_attr_val.val_class = dw_val_class_loc;
5279 attr.dw_attr_val.v.val_loc = loc;
5280 add_dwarf_attr (die, &attr);
5283 static inline dw_loc_descr_ref
5284 AT_loc (dw_attr_ref a)
5286 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5287 return a->dw_attr_val.v.val_loc;
5291 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5295 attr.dw_attr = attr_kind;
5296 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5297 attr.dw_attr_val.v.val_loc_list = loc_list;
5298 add_dwarf_attr (die, &attr);
5299 have_location_lists = true;
5302 static inline dw_loc_list_ref
5303 AT_loc_list (dw_attr_ref a)
5305 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5306 return a->dw_attr_val.v.val_loc_list;
5309 /* Add an address constant attribute value to a DIE. */
5312 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5316 attr.dw_attr = attr_kind;
5317 attr.dw_attr_val.val_class = dw_val_class_addr;
5318 attr.dw_attr_val.v.val_addr = addr;
5319 add_dwarf_attr (die, &attr);
5322 /* Get the RTX from to an address DIE attribute. */
5325 AT_addr (dw_attr_ref a)
5327 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5328 return a->dw_attr_val.v.val_addr;
5331 /* Add a file attribute value to a DIE. */
5334 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5335 struct dwarf_file_data *fd)
5339 attr.dw_attr = attr_kind;
5340 attr.dw_attr_val.val_class = dw_val_class_file;
5341 attr.dw_attr_val.v.val_file = fd;
5342 add_dwarf_attr (die, &attr);
5345 /* Get the dwarf_file_data from a file DIE attribute. */
5347 static inline struct dwarf_file_data *
5348 AT_file (dw_attr_ref a)
5350 gcc_assert (a && AT_class (a) == dw_val_class_file);
5351 return a->dw_attr_val.v.val_file;
5354 /* Add a label identifier attribute value to a DIE. */
5357 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5361 attr.dw_attr = attr_kind;
5362 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5363 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5364 add_dwarf_attr (die, &attr);
5367 /* Add a section offset attribute value to a DIE, an offset into the
5368 debug_line section. */
5371 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5376 attr.dw_attr = attr_kind;
5377 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5378 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5379 add_dwarf_attr (die, &attr);
5382 /* Add a section offset attribute value to a DIE, an offset into the
5383 debug_macinfo section. */
5386 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5391 attr.dw_attr = attr_kind;
5392 attr.dw_attr_val.val_class = dw_val_class_macptr;
5393 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5394 add_dwarf_attr (die, &attr);
5397 /* Add an offset attribute value to a DIE. */
5400 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5401 unsigned HOST_WIDE_INT offset)
5405 attr.dw_attr = attr_kind;
5406 attr.dw_attr_val.val_class = dw_val_class_offset;
5407 attr.dw_attr_val.v.val_offset = offset;
5408 add_dwarf_attr (die, &attr);
5411 /* Add an range_list attribute value to a DIE. */
5414 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5415 long unsigned int offset)
5419 attr.dw_attr = attr_kind;
5420 attr.dw_attr_val.val_class = dw_val_class_range_list;
5421 attr.dw_attr_val.v.val_offset = offset;
5422 add_dwarf_attr (die, &attr);
5425 static inline const char *
5426 AT_lbl (dw_attr_ref a)
5428 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5429 || AT_class (a) == dw_val_class_lineptr
5430 || AT_class (a) == dw_val_class_macptr));
5431 return a->dw_attr_val.v.val_lbl_id;
5434 /* Get the attribute of type attr_kind. */
5437 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5441 dw_die_ref spec = NULL;
5446 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5447 if (a->dw_attr == attr_kind)
5449 else if (a->dw_attr == DW_AT_specification
5450 || a->dw_attr == DW_AT_abstract_origin)
5454 return get_AT (spec, attr_kind);
5459 /* Return the "low pc" attribute value, typically associated with a subprogram
5460 DIE. Return null if the "low pc" attribute is either not present, or if it
5461 cannot be represented as an assembler label identifier. */
5463 static inline const char *
5464 get_AT_low_pc (dw_die_ref die)
5466 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5468 return a ? AT_lbl (a) : NULL;
5471 /* Return the "high pc" attribute value, typically associated with a subprogram
5472 DIE. Return null if the "high pc" attribute is either not present, or if it
5473 cannot be represented as an assembler label identifier. */
5475 static inline const char *
5476 get_AT_hi_pc (dw_die_ref die)
5478 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5480 return a ? AT_lbl (a) : NULL;
5483 /* Return the value of the string attribute designated by ATTR_KIND, or
5484 NULL if it is not present. */
5486 static inline const char *
5487 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5489 dw_attr_ref a = get_AT (die, attr_kind);
5491 return a ? AT_string (a) : NULL;
5494 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5495 if it is not present. */
5498 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5500 dw_attr_ref a = get_AT (die, attr_kind);
5502 return a ? AT_flag (a) : 0;
5505 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5506 if it is not present. */
5508 static inline unsigned
5509 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5511 dw_attr_ref a = get_AT (die, attr_kind);
5513 return a ? AT_unsigned (a) : 0;
5516 static inline dw_die_ref
5517 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5519 dw_attr_ref a = get_AT (die, attr_kind);
5521 return a ? AT_ref (a) : NULL;
5524 static inline struct dwarf_file_data *
5525 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5527 dw_attr_ref a = get_AT (die, attr_kind);
5529 return a ? AT_file (a) : NULL;
5532 /* Return TRUE if the language is C or C++. */
5537 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5539 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5540 || lang == DW_LANG_C99
5541 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5544 /* Return TRUE if the language is C++. */
5549 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5551 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5554 /* Return TRUE if the language is Fortran. */
5559 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5561 return (lang == DW_LANG_Fortran77
5562 || lang == DW_LANG_Fortran90
5563 || lang == DW_LANG_Fortran95);
5566 /* Return TRUE if the language is Java. */
5571 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5573 return lang == DW_LANG_Java;
5576 /* Return TRUE if the language is Ada. */
5581 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5583 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5586 /* Remove the specified attribute if present. */
5589 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5597 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5598 if (a->dw_attr == attr_kind)
5600 if (AT_class (a) == dw_val_class_str)
5601 if (a->dw_attr_val.v.val_str->refcount)
5602 a->dw_attr_val.v.val_str->refcount--;
5604 /* VEC_ordered_remove should help reduce the number of abbrevs
5606 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5611 /* Remove CHILD from its parent. PREV must have the property that
5612 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5615 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5617 gcc_assert (child->die_parent == prev->die_parent);
5618 gcc_assert (prev->die_sib == child);
5621 gcc_assert (child->die_parent->die_child == child);
5625 prev->die_sib = child->die_sib;
5626 if (child->die_parent->die_child == child)
5627 child->die_parent->die_child = prev;
5630 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5634 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5640 dw_die_ref prev = c;
5642 while (c->die_tag == tag)
5644 remove_child_with_prev (c, prev);
5645 /* Might have removed every child. */
5646 if (c == c->die_sib)
5650 } while (c != die->die_child);
5653 /* Add a CHILD_DIE as the last child of DIE. */
5656 add_child_die (dw_die_ref die, dw_die_ref child_die)
5658 /* FIXME this should probably be an assert. */
5659 if (! die || ! child_die)
5661 gcc_assert (die != child_die);
5663 child_die->die_parent = die;
5666 child_die->die_sib = die->die_child->die_sib;
5667 die->die_child->die_sib = child_die;
5670 child_die->die_sib = child_die;
5671 die->die_child = child_die;
5674 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5675 is the specification, to the end of PARENT's list of children.
5676 This is done by removing and re-adding it. */
5679 splice_child_die (dw_die_ref parent, dw_die_ref child)
5683 /* We want the declaration DIE from inside the class, not the
5684 specification DIE at toplevel. */
5685 if (child->die_parent != parent)
5687 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5693 gcc_assert (child->die_parent == parent
5694 || (child->die_parent
5695 == get_AT_ref (parent, DW_AT_specification)));
5697 for (p = child->die_parent->die_child; ; p = p->die_sib)
5698 if (p->die_sib == child)
5700 remove_child_with_prev (child, p);
5704 add_child_die (parent, child);
5707 /* Return a pointer to a newly created DIE node. */
5709 static inline dw_die_ref
5710 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5712 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5714 die->die_tag = tag_value;
5716 if (parent_die != NULL)
5717 add_child_die (parent_die, die);
5720 limbo_die_node *limbo_node;
5722 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5723 limbo_node->die = die;
5724 limbo_node->created_for = t;
5725 limbo_node->next = limbo_die_list;
5726 limbo_die_list = limbo_node;
5732 /* Return the DIE associated with the given type specifier. */
5734 static inline dw_die_ref
5735 lookup_type_die (tree type)
5737 return TYPE_SYMTAB_DIE (type);
5740 /* Equate a DIE to a given type specifier. */
5743 equate_type_number_to_die (tree type, dw_die_ref type_die)
5745 TYPE_SYMTAB_DIE (type) = type_die;
5748 /* Returns a hash value for X (which really is a die_struct). */
5751 decl_die_table_hash (const void *x)
5753 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5756 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5759 decl_die_table_eq (const void *x, const void *y)
5761 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5764 /* Return the DIE associated with a given declaration. */
5766 static inline dw_die_ref
5767 lookup_decl_die (tree decl)
5769 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5772 /* Returns a hash value for X (which really is a var_loc_list). */
5775 decl_loc_table_hash (const void *x)
5777 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5780 /* Return nonzero if decl_id of var_loc_list X is the same as
5784 decl_loc_table_eq (const void *x, const void *y)
5786 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5789 /* Return the var_loc list associated with a given declaration. */
5791 static inline var_loc_list *
5792 lookup_decl_loc (const_tree decl)
5794 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5797 /* Equate a DIE to a particular declaration. */
5800 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5802 unsigned int decl_id = DECL_UID (decl);
5805 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5807 decl_die->decl_id = decl_id;
5810 /* Add a variable location node to the linked list for DECL. */
5813 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5815 unsigned int decl_id = DECL_UID (decl);
5819 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5822 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5823 temp->decl_id = decl_id;
5831 /* If the current location is the same as the end of the list,
5832 and either both or neither of the locations is uninitialized,
5833 we have nothing to do. */
5834 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5835 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5836 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5837 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
5838 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5839 == VAR_INIT_STATUS_UNINITIALIZED)
5840 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
5841 == VAR_INIT_STATUS_UNINITIALIZED))))
5843 /* Add LOC to the end of list and update LAST. */
5844 temp->last->next = loc;
5848 /* Do not add empty location to the beginning of the list. */
5849 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5856 /* Keep track of the number of spaces used to indent the
5857 output of the debugging routines that print the structure of
5858 the DIE internal representation. */
5859 static int print_indent;
5861 /* Indent the line the number of spaces given by print_indent. */
5864 print_spaces (FILE *outfile)
5866 fprintf (outfile, "%*s", print_indent, "");
5869 /* Print the information associated with a given DIE, and its children.
5870 This routine is a debugging aid only. */
5873 print_die (dw_die_ref die, FILE *outfile)
5879 print_spaces (outfile);
5880 fprintf (outfile, "DIE %4ld: %s\n",
5881 die->die_offset, dwarf_tag_name (die->die_tag));
5882 print_spaces (outfile);
5883 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5884 fprintf (outfile, " offset: %ld\n", die->die_offset);
5886 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5888 print_spaces (outfile);
5889 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5891 switch (AT_class (a))
5893 case dw_val_class_addr:
5894 fprintf (outfile, "address");
5896 case dw_val_class_offset:
5897 fprintf (outfile, "offset");
5899 case dw_val_class_loc:
5900 fprintf (outfile, "location descriptor");
5902 case dw_val_class_loc_list:
5903 fprintf (outfile, "location list -> label:%s",
5904 AT_loc_list (a)->ll_symbol);
5906 case dw_val_class_range_list:
5907 fprintf (outfile, "range list");
5909 case dw_val_class_const:
5910 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5912 case dw_val_class_unsigned_const:
5913 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5915 case dw_val_class_long_long:
5916 fprintf (outfile, "constant (%lu,%lu)",
5917 a->dw_attr_val.v.val_long_long.hi,
5918 a->dw_attr_val.v.val_long_long.low);
5920 case dw_val_class_vec:
5921 fprintf (outfile, "floating-point or vector constant");
5923 case dw_val_class_flag:
5924 fprintf (outfile, "%u", AT_flag (a));
5926 case dw_val_class_die_ref:
5927 if (AT_ref (a) != NULL)
5929 if (AT_ref (a)->die_symbol)
5930 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5932 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5935 fprintf (outfile, "die -> <null>");
5937 case dw_val_class_lbl_id:
5938 case dw_val_class_lineptr:
5939 case dw_val_class_macptr:
5940 fprintf (outfile, "label: %s", AT_lbl (a));
5942 case dw_val_class_str:
5943 if (AT_string (a) != NULL)
5944 fprintf (outfile, "\"%s\"", AT_string (a));
5946 fprintf (outfile, "<null>");
5948 case dw_val_class_file:
5949 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5950 AT_file (a)->emitted_number);
5956 fprintf (outfile, "\n");
5959 if (die->die_child != NULL)
5962 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5965 if (print_indent == 0)
5966 fprintf (outfile, "\n");
5969 /* Print the contents of the source code line number correspondence table.
5970 This routine is a debugging aid only. */
5973 print_dwarf_line_table (FILE *outfile)
5976 dw_line_info_ref line_info;
5978 fprintf (outfile, "\n\nDWARF source line information\n");
5979 for (i = 1; i < line_info_table_in_use; i++)
5981 line_info = &line_info_table[i];
5982 fprintf (outfile, "%5d: %4ld %6ld\n", i,
5983 line_info->dw_file_num,
5984 line_info->dw_line_num);
5987 fprintf (outfile, "\n\n");
5990 /* Print the information collected for a given DIE. */
5993 debug_dwarf_die (dw_die_ref die)
5995 print_die (die, stderr);
5998 /* Print all DWARF information collected for the compilation unit.
5999 This routine is a debugging aid only. */
6005 print_die (comp_unit_die, stderr);
6006 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6007 print_dwarf_line_table (stderr);
6010 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6011 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6012 DIE that marks the start of the DIEs for this include file. */
6015 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6017 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6018 dw_die_ref new_unit = gen_compile_unit_die (filename);
6020 new_unit->die_sib = old_unit;
6024 /* Close an include-file CU and reopen the enclosing one. */
6027 pop_compile_unit (dw_die_ref old_unit)
6029 dw_die_ref new_unit = old_unit->die_sib;
6031 old_unit->die_sib = NULL;
6035 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6036 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6038 /* Calculate the checksum of a location expression. */
6041 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6043 CHECKSUM (loc->dw_loc_opc);
6044 CHECKSUM (loc->dw_loc_oprnd1);
6045 CHECKSUM (loc->dw_loc_oprnd2);
6048 /* Calculate the checksum of an attribute. */
6051 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6053 dw_loc_descr_ref loc;
6056 CHECKSUM (at->dw_attr);
6058 /* We don't care that this was compiled with a different compiler
6059 snapshot; if the output is the same, that's what matters. */
6060 if (at->dw_attr == DW_AT_producer)
6063 switch (AT_class (at))
6065 case dw_val_class_const:
6066 CHECKSUM (at->dw_attr_val.v.val_int);
6068 case dw_val_class_unsigned_const:
6069 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6071 case dw_val_class_long_long:
6072 CHECKSUM (at->dw_attr_val.v.val_long_long);
6074 case dw_val_class_vec:
6075 CHECKSUM (at->dw_attr_val.v.val_vec);
6077 case dw_val_class_flag:
6078 CHECKSUM (at->dw_attr_val.v.val_flag);
6080 case dw_val_class_str:
6081 CHECKSUM_STRING (AT_string (at));
6084 case dw_val_class_addr:
6086 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6087 CHECKSUM_STRING (XSTR (r, 0));
6090 case dw_val_class_offset:
6091 CHECKSUM (at->dw_attr_val.v.val_offset);
6094 case dw_val_class_loc:
6095 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6096 loc_checksum (loc, ctx);
6099 case dw_val_class_die_ref:
6100 die_checksum (AT_ref (at), ctx, mark);
6103 case dw_val_class_fde_ref:
6104 case dw_val_class_lbl_id:
6105 case dw_val_class_lineptr:
6106 case dw_val_class_macptr:
6109 case dw_val_class_file:
6110 CHECKSUM_STRING (AT_file (at)->filename);
6118 /* Calculate the checksum of a DIE. */
6121 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6127 /* To avoid infinite recursion. */
6130 CHECKSUM (die->die_mark);
6133 die->die_mark = ++(*mark);
6135 CHECKSUM (die->die_tag);
6137 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6138 attr_checksum (a, ctx, mark);
6140 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6144 #undef CHECKSUM_STRING
6146 /* Do the location expressions look same? */
6148 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6150 return loc1->dw_loc_opc == loc2->dw_loc_opc
6151 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6152 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6155 /* Do the values look the same? */
6157 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6159 dw_loc_descr_ref loc1, loc2;
6162 if (v1->val_class != v2->val_class)
6165 switch (v1->val_class)
6167 case dw_val_class_const:
6168 return v1->v.val_int == v2->v.val_int;
6169 case dw_val_class_unsigned_const:
6170 return v1->v.val_unsigned == v2->v.val_unsigned;
6171 case dw_val_class_long_long:
6172 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6173 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6174 case dw_val_class_vec:
6175 if (v1->v.val_vec.length != v2->v.val_vec.length
6176 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6178 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6179 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6182 case dw_val_class_flag:
6183 return v1->v.val_flag == v2->v.val_flag;
6184 case dw_val_class_str:
6185 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6187 case dw_val_class_addr:
6188 r1 = v1->v.val_addr;
6189 r2 = v2->v.val_addr;
6190 if (GET_CODE (r1) != GET_CODE (r2))
6192 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6193 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6195 case dw_val_class_offset:
6196 return v1->v.val_offset == v2->v.val_offset;
6198 case dw_val_class_loc:
6199 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6201 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6202 if (!same_loc_p (loc1, loc2, mark))
6204 return !loc1 && !loc2;
6206 case dw_val_class_die_ref:
6207 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6209 case dw_val_class_fde_ref:
6210 case dw_val_class_lbl_id:
6211 case dw_val_class_lineptr:
6212 case dw_val_class_macptr:
6215 case dw_val_class_file:
6216 return v1->v.val_file == v2->v.val_file;
6223 /* Do the attributes look the same? */
6226 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6228 if (at1->dw_attr != at2->dw_attr)
6231 /* We don't care that this was compiled with a different compiler
6232 snapshot; if the output is the same, that's what matters. */
6233 if (at1->dw_attr == DW_AT_producer)
6236 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6239 /* Do the dies look the same? */
6242 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6248 /* To avoid infinite recursion. */
6250 return die1->die_mark == die2->die_mark;
6251 die1->die_mark = die2->die_mark = ++(*mark);
6253 if (die1->die_tag != die2->die_tag)
6256 if (VEC_length (dw_attr_node, die1->die_attr)
6257 != VEC_length (dw_attr_node, die2->die_attr))
6260 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6261 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6264 c1 = die1->die_child;
6265 c2 = die2->die_child;
6274 if (!same_die_p (c1, c2, mark))
6278 if (c1 == die1->die_child)
6280 if (c2 == die2->die_child)
6290 /* Do the dies look the same? Wrapper around same_die_p. */
6293 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6296 int ret = same_die_p (die1, die2, &mark);
6298 unmark_all_dies (die1);
6299 unmark_all_dies (die2);
6304 /* The prefix to attach to symbols on DIEs in the current comdat debug
6306 static char *comdat_symbol_id;
6308 /* The index of the current symbol within the current comdat CU. */
6309 static unsigned int comdat_symbol_number;
6311 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6312 children, and set comdat_symbol_id accordingly. */
6315 compute_section_prefix (dw_die_ref unit_die)
6317 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6318 const char *base = die_name ? lbasename (die_name) : "anonymous";
6319 char *name = alloca (strlen (base) + 64);
6322 unsigned char checksum[16];
6325 /* Compute the checksum of the DIE, then append part of it as hex digits to
6326 the name filename of the unit. */
6328 md5_init_ctx (&ctx);
6330 die_checksum (unit_die, &ctx, &mark);
6331 unmark_all_dies (unit_die);
6332 md5_finish_ctx (&ctx, checksum);
6334 sprintf (name, "%s.", base);
6335 clean_symbol_name (name);
6337 p = name + strlen (name);
6338 for (i = 0; i < 4; i++)
6340 sprintf (p, "%.2x", checksum[i]);
6344 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6345 comdat_symbol_number = 0;
6348 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6351 is_type_die (dw_die_ref die)
6353 switch (die->die_tag)
6355 case DW_TAG_array_type:
6356 case DW_TAG_class_type:
6357 case DW_TAG_interface_type:
6358 case DW_TAG_enumeration_type:
6359 case DW_TAG_pointer_type:
6360 case DW_TAG_reference_type:
6361 case DW_TAG_string_type:
6362 case DW_TAG_structure_type:
6363 case DW_TAG_subroutine_type:
6364 case DW_TAG_union_type:
6365 case DW_TAG_ptr_to_member_type:
6366 case DW_TAG_set_type:
6367 case DW_TAG_subrange_type:
6368 case DW_TAG_base_type:
6369 case DW_TAG_const_type:
6370 case DW_TAG_file_type:
6371 case DW_TAG_packed_type:
6372 case DW_TAG_volatile_type:
6373 case DW_TAG_typedef:
6380 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6381 Basically, we want to choose the bits that are likely to be shared between
6382 compilations (types) and leave out the bits that are specific to individual
6383 compilations (functions). */
6386 is_comdat_die (dw_die_ref c)
6388 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6389 we do for stabs. The advantage is a greater likelihood of sharing between
6390 objects that don't include headers in the same order (and therefore would
6391 put the base types in a different comdat). jason 8/28/00 */
6393 if (c->die_tag == DW_TAG_base_type)
6396 if (c->die_tag == DW_TAG_pointer_type
6397 || c->die_tag == DW_TAG_reference_type
6398 || c->die_tag == DW_TAG_const_type
6399 || c->die_tag == DW_TAG_volatile_type)
6401 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6403 return t ? is_comdat_die (t) : 0;
6406 return is_type_die (c);
6409 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6410 compilation unit. */
6413 is_symbol_die (dw_die_ref c)
6415 return (is_type_die (c)
6416 || (get_AT (c, DW_AT_declaration)
6417 && !get_AT (c, DW_AT_specification))
6418 || c->die_tag == DW_TAG_namespace);
6422 gen_internal_sym (const char *prefix)
6426 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6427 return xstrdup (buf);
6430 /* Assign symbols to all worthy DIEs under DIE. */
6433 assign_symbol_names (dw_die_ref die)
6437 if (is_symbol_die (die))
6439 if (comdat_symbol_id)
6441 char *p = alloca (strlen (comdat_symbol_id) + 64);
6443 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6444 comdat_symbol_id, comdat_symbol_number++);
6445 die->die_symbol = xstrdup (p);
6448 die->die_symbol = gen_internal_sym ("LDIE");
6451 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6454 struct cu_hash_table_entry
6457 unsigned min_comdat_num, max_comdat_num;
6458 struct cu_hash_table_entry *next;
6461 /* Routines to manipulate hash table of CUs. */
6463 htab_cu_hash (const void *of)
6465 const struct cu_hash_table_entry *entry = of;
6467 return htab_hash_string (entry->cu->die_symbol);
6471 htab_cu_eq (const void *of1, const void *of2)
6473 const struct cu_hash_table_entry *entry1 = of1;
6474 const struct die_struct *entry2 = of2;
6476 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6480 htab_cu_del (void *what)
6482 struct cu_hash_table_entry *next, *entry = what;
6492 /* Check whether we have already seen this CU and set up SYM_NUM
6495 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6497 struct cu_hash_table_entry dummy;
6498 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6500 dummy.max_comdat_num = 0;
6502 slot = (struct cu_hash_table_entry **)
6503 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6507 for (; entry; last = entry, entry = entry->next)
6509 if (same_die_p_wrap (cu, entry->cu))
6515 *sym_num = entry->min_comdat_num;
6519 entry = XCNEW (struct cu_hash_table_entry);
6521 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6522 entry->next = *slot;
6528 /* Record SYM_NUM to record of CU in HTABLE. */
6530 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6532 struct cu_hash_table_entry **slot, *entry;
6534 slot = (struct cu_hash_table_entry **)
6535 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6539 entry->max_comdat_num = sym_num;
6542 /* Traverse the DIE (which is always comp_unit_die), and set up
6543 additional compilation units for each of the include files we see
6544 bracketed by BINCL/EINCL. */
6547 break_out_includes (dw_die_ref die)
6550 dw_die_ref unit = NULL;
6551 limbo_die_node *node, **pnode;
6552 htab_t cu_hash_table;
6556 dw_die_ref prev = c;
6558 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6559 || (unit && is_comdat_die (c)))
6561 dw_die_ref next = c->die_sib;
6563 /* This DIE is for a secondary CU; remove it from the main one. */
6564 remove_child_with_prev (c, prev);
6566 if (c->die_tag == DW_TAG_GNU_BINCL)
6567 unit = push_new_compile_unit (unit, c);
6568 else if (c->die_tag == DW_TAG_GNU_EINCL)
6569 unit = pop_compile_unit (unit);
6571 add_child_die (unit, c);
6573 if (c == die->die_child)
6576 } while (c != die->die_child);
6579 /* We can only use this in debugging, since the frontend doesn't check
6580 to make sure that we leave every include file we enter. */
6584 assign_symbol_names (die);
6585 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6586 for (node = limbo_die_list, pnode = &limbo_die_list;
6592 compute_section_prefix (node->die);
6593 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6594 &comdat_symbol_number);
6595 assign_symbol_names (node->die);
6597 *pnode = node->next;
6600 pnode = &node->next;
6601 record_comdat_symbol_number (node->die, cu_hash_table,
6602 comdat_symbol_number);
6605 htab_delete (cu_hash_table);
6608 /* Traverse the DIE and add a sibling attribute if it may have the
6609 effect of speeding up access to siblings. To save some space,
6610 avoid generating sibling attributes for DIE's without children. */
6613 add_sibling_attributes (dw_die_ref die)
6617 if (! die->die_child)
6620 if (die->die_parent && die != die->die_parent->die_child)
6621 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6623 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6626 /* Output all location lists for the DIE and its children. */
6629 output_location_lists (dw_die_ref die)
6635 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6636 if (AT_class (a) == dw_val_class_loc_list)
6637 output_loc_list (AT_loc_list (a));
6639 FOR_EACH_CHILD (die, c, output_location_lists (c));
6642 /* The format of each DIE (and its attribute value pairs) is encoded in an
6643 abbreviation table. This routine builds the abbreviation table and assigns
6644 a unique abbreviation id for each abbreviation entry. The children of each
6645 die are visited recursively. */
6648 build_abbrev_table (dw_die_ref die)
6650 unsigned long abbrev_id;
6651 unsigned int n_alloc;
6656 /* Scan the DIE references, and mark as external any that refer to
6657 DIEs from other CUs (i.e. those which are not marked). */
6658 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6659 if (AT_class (a) == dw_val_class_die_ref
6660 && AT_ref (a)->die_mark == 0)
6662 gcc_assert (AT_ref (a)->die_symbol);
6664 set_AT_ref_external (a, 1);
6667 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6669 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6670 dw_attr_ref die_a, abbrev_a;
6674 if (abbrev->die_tag != die->die_tag)
6676 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6679 if (VEC_length (dw_attr_node, abbrev->die_attr)
6680 != VEC_length (dw_attr_node, die->die_attr))
6683 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6685 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6686 if ((abbrev_a->dw_attr != die_a->dw_attr)
6687 || (value_format (abbrev_a) != value_format (die_a)))
6697 if (abbrev_id >= abbrev_die_table_in_use)
6699 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6701 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6702 abbrev_die_table = ggc_realloc (abbrev_die_table,
6703 sizeof (dw_die_ref) * n_alloc);
6705 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6706 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6707 abbrev_die_table_allocated = n_alloc;
6710 ++abbrev_die_table_in_use;
6711 abbrev_die_table[abbrev_id] = die;
6714 die->die_abbrev = abbrev_id;
6715 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6718 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6721 constant_size (long unsigned int value)
6728 log = floor_log2 (value);
6731 log = 1 << (floor_log2 (log) + 1);
6736 /* Return the size of a DIE as it is represented in the
6737 .debug_info section. */
6739 static unsigned long
6740 size_of_die (dw_die_ref die)
6742 unsigned long size = 0;
6746 size += size_of_uleb128 (die->die_abbrev);
6747 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6749 switch (AT_class (a))
6751 case dw_val_class_addr:
6752 size += DWARF2_ADDR_SIZE;
6754 case dw_val_class_offset:
6755 size += DWARF_OFFSET_SIZE;
6757 case dw_val_class_loc:
6759 unsigned long lsize = size_of_locs (AT_loc (a));
6762 size += constant_size (lsize);
6766 case dw_val_class_loc_list:
6767 size += DWARF_OFFSET_SIZE;
6769 case dw_val_class_range_list:
6770 size += DWARF_OFFSET_SIZE;
6772 case dw_val_class_const:
6773 size += size_of_sleb128 (AT_int (a));
6775 case dw_val_class_unsigned_const:
6776 size += constant_size (AT_unsigned (a));
6778 case dw_val_class_long_long:
6779 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6781 case dw_val_class_vec:
6782 size += 1 + (a->dw_attr_val.v.val_vec.length
6783 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6785 case dw_val_class_flag:
6788 case dw_val_class_die_ref:
6789 if (AT_ref_external (a))
6790 size += DWARF2_ADDR_SIZE;
6792 size += DWARF_OFFSET_SIZE;
6794 case dw_val_class_fde_ref:
6795 size += DWARF_OFFSET_SIZE;
6797 case dw_val_class_lbl_id:
6798 size += DWARF2_ADDR_SIZE;
6800 case dw_val_class_lineptr:
6801 case dw_val_class_macptr:
6802 size += DWARF_OFFSET_SIZE;
6804 case dw_val_class_str:
6805 if (AT_string_form (a) == DW_FORM_strp)
6806 size += DWARF_OFFSET_SIZE;
6808 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6810 case dw_val_class_file:
6811 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6821 /* Size the debugging information associated with a given DIE. Visits the
6822 DIE's children recursively. Updates the global variable next_die_offset, on
6823 each time through. Uses the current value of next_die_offset to update the
6824 die_offset field in each DIE. */
6827 calc_die_sizes (dw_die_ref die)
6831 die->die_offset = next_die_offset;
6832 next_die_offset += size_of_die (die);
6834 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6836 if (die->die_child != NULL)
6837 /* Count the null byte used to terminate sibling lists. */
6838 next_die_offset += 1;
6841 /* Set the marks for a die and its children. We do this so
6842 that we know whether or not a reference needs to use FORM_ref_addr; only
6843 DIEs in the same CU will be marked. We used to clear out the offset
6844 and use that as the flag, but ran into ordering problems. */
6847 mark_dies (dw_die_ref die)
6851 gcc_assert (!die->die_mark);
6854 FOR_EACH_CHILD (die, c, mark_dies (c));
6857 /* Clear the marks for a die and its children. */
6860 unmark_dies (dw_die_ref die)
6864 gcc_assert (die->die_mark);
6867 FOR_EACH_CHILD (die, c, unmark_dies (c));
6870 /* Clear the marks for a die, its children and referred dies. */
6873 unmark_all_dies (dw_die_ref die)
6883 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6885 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6886 if (AT_class (a) == dw_val_class_die_ref)
6887 unmark_all_dies (AT_ref (a));
6890 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6891 generated for the compilation unit. */
6893 static unsigned long
6894 size_of_pubnames (VEC (pubname_entry, gc) * names)
6900 size = DWARF_PUBNAMES_HEADER_SIZE;
6901 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6902 if (names != pubtype_table
6903 || p->die->die_offset != 0
6904 || !flag_eliminate_unused_debug_types)
6905 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6907 size += DWARF_OFFSET_SIZE;
6911 /* Return the size of the information in the .debug_aranges section. */
6913 static unsigned long
6914 size_of_aranges (void)
6918 size = DWARF_ARANGES_HEADER_SIZE;
6920 /* Count the address/length pair for this compilation unit. */
6921 if (text_section_used)
6922 size += 2 * DWARF2_ADDR_SIZE;
6923 if (cold_text_section_used)
6924 size += 2 * DWARF2_ADDR_SIZE;
6925 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6927 /* Count the two zero words used to terminated the address range table. */
6928 size += 2 * DWARF2_ADDR_SIZE;
6932 /* Select the encoding of an attribute value. */
6934 static enum dwarf_form
6935 value_format (dw_attr_ref a)
6937 switch (a->dw_attr_val.val_class)
6939 case dw_val_class_addr:
6940 return DW_FORM_addr;
6941 case dw_val_class_range_list:
6942 case dw_val_class_offset:
6943 case dw_val_class_loc_list:
6944 switch (DWARF_OFFSET_SIZE)
6947 return DW_FORM_data4;
6949 return DW_FORM_data8;
6953 case dw_val_class_loc:
6954 switch (constant_size (size_of_locs (AT_loc (a))))
6957 return DW_FORM_block1;
6959 return DW_FORM_block2;
6963 case dw_val_class_const:
6964 return DW_FORM_sdata;
6965 case dw_val_class_unsigned_const:
6966 switch (constant_size (AT_unsigned (a)))
6969 return DW_FORM_data1;
6971 return DW_FORM_data2;
6973 return DW_FORM_data4;
6975 return DW_FORM_data8;
6979 case dw_val_class_long_long:
6980 return DW_FORM_block1;
6981 case dw_val_class_vec:
6982 return DW_FORM_block1;
6983 case dw_val_class_flag:
6984 return DW_FORM_flag;
6985 case dw_val_class_die_ref:
6986 if (AT_ref_external (a))
6987 return DW_FORM_ref_addr;
6990 case dw_val_class_fde_ref:
6991 return DW_FORM_data;
6992 case dw_val_class_lbl_id:
6993 return DW_FORM_addr;
6994 case dw_val_class_lineptr:
6995 case dw_val_class_macptr:
6996 return DW_FORM_data;
6997 case dw_val_class_str:
6998 return AT_string_form (a);
6999 case dw_val_class_file:
7000 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7003 return DW_FORM_data1;
7005 return DW_FORM_data2;
7007 return DW_FORM_data4;
7017 /* Output the encoding of an attribute value. */
7020 output_value_format (dw_attr_ref a)
7022 enum dwarf_form form = value_format (a);
7024 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7027 /* Output the .debug_abbrev section which defines the DIE abbreviation
7031 output_abbrev_section (void)
7033 unsigned long abbrev_id;
7035 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7037 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7041 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7042 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7043 dwarf_tag_name (abbrev->die_tag));
7045 if (abbrev->die_child != NULL)
7046 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7048 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7050 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7053 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7054 dwarf_attr_name (a_attr->dw_attr));
7055 output_value_format (a_attr);
7058 dw2_asm_output_data (1, 0, NULL);
7059 dw2_asm_output_data (1, 0, NULL);
7062 /* Terminate the table. */
7063 dw2_asm_output_data (1, 0, NULL);
7066 /* Output a symbol we can use to refer to this DIE from another CU. */
7069 output_die_symbol (dw_die_ref die)
7071 char *sym = die->die_symbol;
7076 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7077 /* We make these global, not weak; if the target doesn't support
7078 .linkonce, it doesn't support combining the sections, so debugging
7080 targetm.asm_out.globalize_label (asm_out_file, sym);
7082 ASM_OUTPUT_LABEL (asm_out_file, sym);
7085 /* Return a new location list, given the begin and end range, and the
7086 expression. gensym tells us whether to generate a new internal symbol for
7087 this location list node, which is done for the head of the list only. */
7089 static inline dw_loc_list_ref
7090 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7091 const char *section, unsigned int gensym)
7093 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
7095 retlist->begin = begin;
7097 retlist->expr = expr;
7098 retlist->section = section;
7100 retlist->ll_symbol = gen_internal_sym ("LLST");
7105 /* Add a location description expression to a location list. */
7108 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7109 const char *begin, const char *end,
7110 const char *section)
7114 /* Find the end of the chain. */
7115 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7118 /* Add a new location list node to the list. */
7119 *d = new_loc_list (descr, begin, end, section, 0);
7122 /* Output the location list given to us. */
7125 output_loc_list (dw_loc_list_ref list_head)
7127 dw_loc_list_ref curr = list_head;
7129 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7131 /* Walk the location list, and output each range + expression. */
7132 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7135 /* Don't output an entry that starts and ends at the same address. */
7136 if (strcmp (curr->begin, curr->end) == 0)
7138 if (!have_multiple_function_sections)
7140 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7141 "Location list begin address (%s)",
7142 list_head->ll_symbol);
7143 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7144 "Location list end address (%s)",
7145 list_head->ll_symbol);
7149 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7150 "Location list begin address (%s)",
7151 list_head->ll_symbol);
7152 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7153 "Location list end address (%s)",
7154 list_head->ll_symbol);
7156 size = size_of_locs (curr->expr);
7158 /* Output the block length for this list of location operations. */
7159 gcc_assert (size <= 0xffff);
7160 dw2_asm_output_data (2, size, "%s", "Location expression size");
7162 output_loc_sequence (curr->expr);
7165 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7166 "Location list terminator begin (%s)",
7167 list_head->ll_symbol);
7168 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7169 "Location list terminator end (%s)",
7170 list_head->ll_symbol);
7173 /* Output the DIE and its attributes. Called recursively to generate
7174 the definitions of each child DIE. */
7177 output_die (dw_die_ref die)
7184 /* If someone in another CU might refer to us, set up a symbol for
7185 them to point to. */
7186 if (die->die_symbol)
7187 output_die_symbol (die);
7189 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7190 (unsigned long)die->die_offset,
7191 dwarf_tag_name (die->die_tag));
7193 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7195 const char *name = dwarf_attr_name (a->dw_attr);
7197 switch (AT_class (a))
7199 case dw_val_class_addr:
7200 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7203 case dw_val_class_offset:
7204 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7208 case dw_val_class_range_list:
7210 char *p = strchr (ranges_section_label, '\0');
7212 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7213 a->dw_attr_val.v.val_offset);
7214 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7215 debug_ranges_section, "%s", name);
7220 case dw_val_class_loc:
7221 size = size_of_locs (AT_loc (a));
7223 /* Output the block length for this list of location operations. */
7224 dw2_asm_output_data (constant_size (size), size, "%s", name);
7226 output_loc_sequence (AT_loc (a));
7229 case dw_val_class_const:
7230 /* ??? It would be slightly more efficient to use a scheme like is
7231 used for unsigned constants below, but gdb 4.x does not sign
7232 extend. Gdb 5.x does sign extend. */
7233 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7236 case dw_val_class_unsigned_const:
7237 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7238 AT_unsigned (a), "%s", name);
7241 case dw_val_class_long_long:
7243 unsigned HOST_WIDE_INT first, second;
7245 dw2_asm_output_data (1,
7246 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7249 if (WORDS_BIG_ENDIAN)
7251 first = a->dw_attr_val.v.val_long_long.hi;
7252 second = a->dw_attr_val.v.val_long_long.low;
7256 first = a->dw_attr_val.v.val_long_long.low;
7257 second = a->dw_attr_val.v.val_long_long.hi;
7260 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7261 first, "long long constant");
7262 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7267 case dw_val_class_vec:
7269 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7270 unsigned int len = a->dw_attr_val.v.val_vec.length;
7274 dw2_asm_output_data (1, len * elt_size, "%s", name);
7275 if (elt_size > sizeof (HOST_WIDE_INT))
7280 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7283 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7284 "fp or vector constant word %u", i);
7288 case dw_val_class_flag:
7289 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7292 case dw_val_class_loc_list:
7294 char *sym = AT_loc_list (a)->ll_symbol;
7297 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7302 case dw_val_class_die_ref:
7303 if (AT_ref_external (a))
7305 char *sym = AT_ref (a)->die_symbol;
7308 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7313 gcc_assert (AT_ref (a)->die_offset);
7314 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7319 case dw_val_class_fde_ref:
7323 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7324 a->dw_attr_val.v.val_fde_index * 2);
7325 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7330 case dw_val_class_lbl_id:
7331 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7334 case dw_val_class_lineptr:
7335 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7336 debug_line_section, "%s", name);
7339 case dw_val_class_macptr:
7340 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7341 debug_macinfo_section, "%s", name);
7344 case dw_val_class_str:
7345 if (AT_string_form (a) == DW_FORM_strp)
7346 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7347 a->dw_attr_val.v.val_str->label,
7349 "%s: \"%s\"", name, AT_string (a));
7351 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7354 case dw_val_class_file:
7356 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7358 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7359 a->dw_attr_val.v.val_file->filename);
7368 FOR_EACH_CHILD (die, c, output_die (c));
7370 /* Add null byte to terminate sibling list. */
7371 if (die->die_child != NULL)
7372 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7373 (unsigned long) die->die_offset);
7376 /* Output the compilation unit that appears at the beginning of the
7377 .debug_info section, and precedes the DIE descriptions. */
7380 output_compilation_unit_header (void)
7382 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7383 dw2_asm_output_data (4, 0xffffffff,
7384 "Initial length escape value indicating 64-bit DWARF extension");
7385 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7386 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7387 "Length of Compilation Unit Info");
7388 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7389 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7390 debug_abbrev_section,
7391 "Offset Into Abbrev. Section");
7392 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7395 /* Output the compilation unit DIE and its children. */
7398 output_comp_unit (dw_die_ref die, int output_if_empty)
7400 const char *secname;
7403 /* Unless we are outputting main CU, we may throw away empty ones. */
7404 if (!output_if_empty && die->die_child == NULL)
7407 /* Even if there are no children of this DIE, we must output the information
7408 about the compilation unit. Otherwise, on an empty translation unit, we
7409 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7410 will then complain when examining the file. First mark all the DIEs in
7411 this CU so we know which get local refs. */
7414 build_abbrev_table (die);
7416 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7417 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7418 calc_die_sizes (die);
7420 oldsym = die->die_symbol;
7423 tmp = alloca (strlen (oldsym) + 24);
7425 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7427 die->die_symbol = NULL;
7428 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7431 switch_to_section (debug_info_section);
7433 /* Output debugging information. */
7434 output_compilation_unit_header ();
7437 /* Leave the marks on the main CU, so we can check them in
7442 die->die_symbol = oldsym;
7446 /* Return the DWARF2/3 pubname associated with a decl. */
7449 dwarf2_name (tree decl, int scope)
7451 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7454 /* Add a new entry to .debug_pubnames if appropriate. */
7457 add_pubname (tree decl, dw_die_ref die)
7461 if (! TREE_PUBLIC (decl))
7465 e.name = xstrdup (dwarf2_name (decl, 1));
7466 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7469 /* Add a new entry to .debug_pubtypes if appropriate. */
7472 add_pubtype (tree decl, dw_die_ref die)
7477 if ((TREE_PUBLIC (decl)
7478 || die->die_parent == comp_unit_die)
7479 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7484 if (TYPE_NAME (decl))
7486 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7487 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7488 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7489 && DECL_NAME (TYPE_NAME (decl)))
7490 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7492 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7496 e.name = xstrdup (dwarf2_name (decl, 1));
7498 /* If we don't have a name for the type, there's no point in adding
7500 if (e.name && e.name[0] != '\0')
7501 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7505 /* Output the public names table used to speed up access to externally
7506 visible names; or the public types table used to find type definitions. */
7509 output_pubnames (VEC (pubname_entry, gc) * names)
7512 unsigned long pubnames_length = size_of_pubnames (names);
7515 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7516 dw2_asm_output_data (4, 0xffffffff,
7517 "Initial length escape value indicating 64-bit DWARF extension");
7518 if (names == pubname_table)
7519 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7520 "Length of Public Names Info");
7522 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7523 "Length of Public Type Names Info");
7524 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7525 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7527 "Offset of Compilation Unit Info");
7528 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7529 "Compilation Unit Length");
7531 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7533 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7534 if (names == pubname_table)
7535 gcc_assert (pub->die->die_mark);
7537 if (names != pubtype_table
7538 || pub->die->die_offset != 0
7539 || !flag_eliminate_unused_debug_types)
7541 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7544 dw2_asm_output_nstring (pub->name, -1, "external name");
7548 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7551 /* Add a new entry to .debug_aranges if appropriate. */
7554 add_arange (tree decl, dw_die_ref die)
7556 if (! DECL_SECTION_NAME (decl))
7559 if (arange_table_in_use == arange_table_allocated)
7561 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7562 arange_table = ggc_realloc (arange_table,
7563 (arange_table_allocated
7564 * sizeof (dw_die_ref)));
7565 memset (arange_table + arange_table_in_use, 0,
7566 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7569 arange_table[arange_table_in_use++] = die;
7572 /* Output the information that goes into the .debug_aranges table.
7573 Namely, define the beginning and ending address range of the
7574 text section generated for this compilation unit. */
7577 output_aranges (void)
7580 unsigned long aranges_length = size_of_aranges ();
7582 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7583 dw2_asm_output_data (4, 0xffffffff,
7584 "Initial length escape value indicating 64-bit DWARF extension");
7585 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7586 "Length of Address Ranges Info");
7587 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7588 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7590 "Offset of Compilation Unit Info");
7591 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7592 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7594 /* We need to align to twice the pointer size here. */
7595 if (DWARF_ARANGES_PAD_SIZE)
7597 /* Pad using a 2 byte words so that padding is correct for any
7599 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7600 2 * DWARF2_ADDR_SIZE);
7601 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7602 dw2_asm_output_data (2, 0, NULL);
7605 /* It is necessary not to output these entries if the sections were
7606 not used; if the sections were not used, the length will be 0 and
7607 the address may end up as 0 if the section is discarded by ld
7608 --gc-sections, leaving an invalid (0, 0) entry that can be
7609 confused with the terminator. */
7610 if (text_section_used)
7612 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7613 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7614 text_section_label, "Length");
7616 if (cold_text_section_used)
7618 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7620 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7621 cold_text_section_label, "Length");
7624 for (i = 0; i < arange_table_in_use; i++)
7626 dw_die_ref die = arange_table[i];
7628 /* We shouldn't see aranges for DIEs outside of the main CU. */
7629 gcc_assert (die->die_mark);
7631 if (die->die_tag == DW_TAG_subprogram)
7633 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7635 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7636 get_AT_low_pc (die), "Length");
7640 /* A static variable; extract the symbol from DW_AT_location.
7641 Note that this code isn't currently hit, as we only emit
7642 aranges for functions (jason 9/23/99). */
7643 dw_attr_ref a = get_AT (die, DW_AT_location);
7644 dw_loc_descr_ref loc;
7646 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7649 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7651 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7652 loc->dw_loc_oprnd1.v.val_addr, "Address");
7653 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7654 get_AT_unsigned (die, DW_AT_byte_size),
7659 /* Output the terminator words. */
7660 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7661 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7664 /* Add a new entry to .debug_ranges. Return the offset at which it
7668 add_ranges_num (int num)
7670 unsigned int in_use = ranges_table_in_use;
7672 if (in_use == ranges_table_allocated)
7674 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7676 = ggc_realloc (ranges_table, (ranges_table_allocated
7677 * sizeof (struct dw_ranges_struct)));
7678 memset (ranges_table + ranges_table_in_use, 0,
7679 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7682 ranges_table[in_use].num = num;
7683 ranges_table_in_use = in_use + 1;
7685 return in_use * 2 * DWARF2_ADDR_SIZE;
7688 /* Add a new entry to .debug_ranges corresponding to a block, or a
7689 range terminator if BLOCK is NULL. */
7692 add_ranges (const_tree block)
7694 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
7697 /* Add a new entry to .debug_ranges corresponding to a pair of
7701 add_ranges_by_labels (const char *begin, const char *end)
7703 unsigned int in_use = ranges_by_label_in_use;
7705 if (in_use == ranges_by_label_allocated)
7707 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
7709 = ggc_realloc (ranges_by_label,
7710 (ranges_by_label_allocated
7711 * sizeof (struct dw_ranges_by_label_struct)));
7712 memset (ranges_by_label + ranges_by_label_in_use, 0,
7713 RANGES_TABLE_INCREMENT
7714 * sizeof (struct dw_ranges_by_label_struct));
7717 ranges_by_label[in_use].begin = begin;
7718 ranges_by_label[in_use].end = end;
7719 ranges_by_label_in_use = in_use + 1;
7721 return add_ranges_num (-(int)in_use - 1);
7725 output_ranges (void)
7728 static const char *const start_fmt = "Offset 0x%x";
7729 const char *fmt = start_fmt;
7731 for (i = 0; i < ranges_table_in_use; i++)
7733 int block_num = ranges_table[i].num;
7737 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7738 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7740 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7741 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7743 /* If all code is in the text section, then the compilation
7744 unit base address defaults to DW_AT_low_pc, which is the
7745 base of the text section. */
7746 if (!have_multiple_function_sections)
7748 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7750 fmt, i * 2 * DWARF2_ADDR_SIZE);
7751 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7752 text_section_label, NULL);
7755 /* Otherwise, the compilation unit base address is zero,
7756 which allows us to use absolute addresses, and not worry
7757 about whether the target supports cross-section
7761 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7762 fmt, i * 2 * DWARF2_ADDR_SIZE);
7763 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7769 /* Negative block_num stands for an index into ranges_by_label. */
7770 else if (block_num < 0)
7772 int lab_idx = - block_num - 1;
7774 if (!have_multiple_function_sections)
7778 /* If we ever use add_ranges_by_labels () for a single
7779 function section, all we have to do is to take out
7781 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7782 ranges_by_label[lab_idx].begin,
7784 fmt, i * 2 * DWARF2_ADDR_SIZE);
7785 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7786 ranges_by_label[lab_idx].end,
7787 text_section_label, NULL);
7792 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7793 ranges_by_label[lab_idx].begin,
7794 fmt, i * 2 * DWARF2_ADDR_SIZE);
7795 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7796 ranges_by_label[lab_idx].end,
7802 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7803 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7809 /* Data structure containing information about input files. */
7812 const char *path; /* Complete file name. */
7813 const char *fname; /* File name part. */
7814 int length; /* Length of entire string. */
7815 struct dwarf_file_data * file_idx; /* Index in input file table. */
7816 int dir_idx; /* Index in directory table. */
7819 /* Data structure containing information about directories with source
7823 const char *path; /* Path including directory name. */
7824 int length; /* Path length. */
7825 int prefix; /* Index of directory entry which is a prefix. */
7826 int count; /* Number of files in this directory. */
7827 int dir_idx; /* Index of directory used as base. */
7830 /* Callback function for file_info comparison. We sort by looking at
7831 the directories in the path. */
7834 file_info_cmp (const void *p1, const void *p2)
7836 const struct file_info *s1 = p1;
7837 const struct file_info *s2 = p2;
7838 const unsigned char *cp1;
7839 const unsigned char *cp2;
7841 /* Take care of file names without directories. We need to make sure that
7842 we return consistent values to qsort since some will get confused if
7843 we return the same value when identical operands are passed in opposite
7844 orders. So if neither has a directory, return 0 and otherwise return
7845 1 or -1 depending on which one has the directory. */
7846 if ((s1->path == s1->fname || s2->path == s2->fname))
7847 return (s2->path == s2->fname) - (s1->path == s1->fname);
7849 cp1 = (const unsigned char *) s1->path;
7850 cp2 = (const unsigned char *) s2->path;
7856 /* Reached the end of the first path? If so, handle like above. */
7857 if ((cp1 == (const unsigned char *) s1->fname)
7858 || (cp2 == (const unsigned char *) s2->fname))
7859 return ((cp2 == (const unsigned char *) s2->fname)
7860 - (cp1 == (const unsigned char *) s1->fname));
7862 /* Character of current path component the same? */
7863 else if (*cp1 != *cp2)
7868 struct file_name_acquire_data
7870 struct file_info *files;
7875 /* Traversal function for the hash table. */
7878 file_name_acquire (void ** slot, void *data)
7880 struct file_name_acquire_data *fnad = data;
7881 struct dwarf_file_data *d = *slot;
7882 struct file_info *fi;
7885 gcc_assert (fnad->max_files >= d->emitted_number);
7887 if (! d->emitted_number)
7890 gcc_assert (fnad->max_files != fnad->used_files);
7892 fi = fnad->files + fnad->used_files++;
7894 /* Skip all leading "./". */
7896 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7899 /* Create a new array entry. */
7901 fi->length = strlen (f);
7904 /* Search for the file name part. */
7905 f = strrchr (f, DIR_SEPARATOR);
7906 #if defined (DIR_SEPARATOR_2)
7908 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7912 if (f == NULL || f < g)
7918 fi->fname = f == NULL ? fi->path : f + 1;
7922 /* Output the directory table and the file name table. We try to minimize
7923 the total amount of memory needed. A heuristic is used to avoid large
7924 slowdowns with many input files. */
7927 output_file_names (void)
7929 struct file_name_acquire_data fnad;
7931 struct file_info *files;
7932 struct dir_info *dirs;
7941 if (!last_emitted_file)
7943 dw2_asm_output_data (1, 0, "End directory table");
7944 dw2_asm_output_data (1, 0, "End file name table");
7948 numfiles = last_emitted_file->emitted_number;
7950 /* Allocate the various arrays we need. */
7951 files = alloca (numfiles * sizeof (struct file_info));
7952 dirs = alloca (numfiles * sizeof (struct dir_info));
7955 fnad.used_files = 0;
7956 fnad.max_files = numfiles;
7957 htab_traverse (file_table, file_name_acquire, &fnad);
7958 gcc_assert (fnad.used_files == fnad.max_files);
7960 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
7962 /* Find all the different directories used. */
7963 dirs[0].path = files[0].path;
7964 dirs[0].length = files[0].fname - files[0].path;
7965 dirs[0].prefix = -1;
7967 dirs[0].dir_idx = 0;
7968 files[0].dir_idx = 0;
7971 for (i = 1; i < numfiles; i++)
7972 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7973 && memcmp (dirs[ndirs - 1].path, files[i].path,
7974 dirs[ndirs - 1].length) == 0)
7976 /* Same directory as last entry. */
7977 files[i].dir_idx = ndirs - 1;
7978 ++dirs[ndirs - 1].count;
7984 /* This is a new directory. */
7985 dirs[ndirs].path = files[i].path;
7986 dirs[ndirs].length = files[i].fname - files[i].path;
7987 dirs[ndirs].count = 1;
7988 dirs[ndirs].dir_idx = ndirs;
7989 files[i].dir_idx = ndirs;
7991 /* Search for a prefix. */
7992 dirs[ndirs].prefix = -1;
7993 for (j = 0; j < ndirs; j++)
7994 if (dirs[j].length < dirs[ndirs].length
7995 && dirs[j].length > 1
7996 && (dirs[ndirs].prefix == -1
7997 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7998 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7999 dirs[ndirs].prefix = j;
8004 /* Now to the actual work. We have to find a subset of the directories which
8005 allow expressing the file name using references to the directory table
8006 with the least amount of characters. We do not do an exhaustive search
8007 where we would have to check out every combination of every single
8008 possible prefix. Instead we use a heuristic which provides nearly optimal
8009 results in most cases and never is much off. */
8010 saved = alloca (ndirs * sizeof (int));
8011 savehere = alloca (ndirs * sizeof (int));
8013 memset (saved, '\0', ndirs * sizeof (saved[0]));
8014 for (i = 0; i < ndirs; i++)
8019 /* We can always save some space for the current directory. But this
8020 does not mean it will be enough to justify adding the directory. */
8021 savehere[i] = dirs[i].length;
8022 total = (savehere[i] - saved[i]) * dirs[i].count;
8024 for (j = i + 1; j < ndirs; j++)
8027 if (saved[j] < dirs[i].length)
8029 /* Determine whether the dirs[i] path is a prefix of the
8034 while (k != -1 && k != (int) i)
8039 /* Yes it is. We can possibly save some memory by
8040 writing the filenames in dirs[j] relative to
8042 savehere[j] = dirs[i].length;
8043 total += (savehere[j] - saved[j]) * dirs[j].count;
8048 /* Check whether we can save enough to justify adding the dirs[i]
8050 if (total > dirs[i].length + 1)
8052 /* It's worthwhile adding. */
8053 for (j = i; j < ndirs; j++)
8054 if (savehere[j] > 0)
8056 /* Remember how much we saved for this directory so far. */
8057 saved[j] = savehere[j];
8059 /* Remember the prefix directory. */
8060 dirs[j].dir_idx = i;
8065 /* Emit the directory name table. */
8067 idx_offset = dirs[0].length > 0 ? 1 : 0;
8068 for (i = 1 - idx_offset; i < ndirs; i++)
8069 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8070 "Directory Entry: 0x%x", i + idx_offset);
8072 dw2_asm_output_data (1, 0, "End directory table");
8074 /* We have to emit them in the order of emitted_number since that's
8075 used in the debug info generation. To do this efficiently we
8076 generate a back-mapping of the indices first. */
8077 backmap = alloca (numfiles * sizeof (int));
8078 for (i = 0; i < numfiles; i++)
8079 backmap[files[i].file_idx->emitted_number - 1] = i;
8081 /* Now write all the file names. */
8082 for (i = 0; i < numfiles; i++)
8084 int file_idx = backmap[i];
8085 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8087 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8088 "File Entry: 0x%x", (unsigned) i + 1);
8090 /* Include directory index. */
8091 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8093 /* Modification time. */
8094 dw2_asm_output_data_uleb128 (0, NULL);
8096 /* File length in bytes. */
8097 dw2_asm_output_data_uleb128 (0, NULL);
8100 dw2_asm_output_data (1, 0, "End file name table");
8104 /* Output the source line number correspondence information. This
8105 information goes into the .debug_line section. */
8108 output_line_info (void)
8110 char l1[20], l2[20], p1[20], p2[20];
8111 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8112 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8115 unsigned long lt_index;
8116 unsigned long current_line;
8119 unsigned long current_file;
8120 unsigned long function;
8122 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8123 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8124 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8125 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8127 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8128 dw2_asm_output_data (4, 0xffffffff,
8129 "Initial length escape value indicating 64-bit DWARF extension");
8130 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8131 "Length of Source Line Info");
8132 ASM_OUTPUT_LABEL (asm_out_file, l1);
8134 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8135 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8136 ASM_OUTPUT_LABEL (asm_out_file, p1);
8138 /* Define the architecture-dependent minimum instruction length (in
8139 bytes). In this implementation of DWARF, this field is used for
8140 information purposes only. Since GCC generates assembly language,
8141 we have no a priori knowledge of how many instruction bytes are
8142 generated for each source line, and therefore can use only the
8143 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8144 commands. Accordingly, we fix this as `1', which is "correct
8145 enough" for all architectures, and don't let the target override. */
8146 dw2_asm_output_data (1, 1,
8147 "Minimum Instruction Length");
8149 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8150 "Default is_stmt_start flag");
8151 dw2_asm_output_data (1, DWARF_LINE_BASE,
8152 "Line Base Value (Special Opcodes)");
8153 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8154 "Line Range Value (Special Opcodes)");
8155 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8156 "Special Opcode Base");
8158 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8162 case DW_LNS_advance_pc:
8163 case DW_LNS_advance_line:
8164 case DW_LNS_set_file:
8165 case DW_LNS_set_column:
8166 case DW_LNS_fixed_advance_pc:
8174 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8178 /* Write out the information about the files we use. */
8179 output_file_names ();
8180 ASM_OUTPUT_LABEL (asm_out_file, p2);
8182 /* We used to set the address register to the first location in the text
8183 section here, but that didn't accomplish anything since we already
8184 have a line note for the opening brace of the first function. */
8186 /* Generate the line number to PC correspondence table, encoded as
8187 a series of state machine operations. */
8191 if (cfun && in_cold_section_p)
8192 strcpy (prev_line_label, cfun->cold_section_label);
8194 strcpy (prev_line_label, text_section_label);
8195 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8197 dw_line_info_ref line_info = &line_info_table[lt_index];
8200 /* Disable this optimization for now; GDB wants to see two line notes
8201 at the beginning of a function so it can find the end of the
8204 /* Don't emit anything for redundant notes. Just updating the
8205 address doesn't accomplish anything, because we already assume
8206 that anything after the last address is this line. */
8207 if (line_info->dw_line_num == current_line
8208 && line_info->dw_file_num == current_file)
8212 /* Emit debug info for the address of the current line.
8214 Unfortunately, we have little choice here currently, and must always
8215 use the most general form. GCC does not know the address delta
8216 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8217 attributes which will give an upper bound on the address range. We
8218 could perhaps use length attributes to determine when it is safe to
8219 use DW_LNS_fixed_advance_pc. */
8221 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8224 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8225 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8226 "DW_LNS_fixed_advance_pc");
8227 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8231 /* This can handle any delta. This takes
8232 4+DWARF2_ADDR_SIZE bytes. */
8233 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8234 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8235 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8236 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8239 strcpy (prev_line_label, line_label);
8241 /* Emit debug info for the source file of the current line, if
8242 different from the previous line. */
8243 if (line_info->dw_file_num != current_file)
8245 current_file = line_info->dw_file_num;
8246 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8247 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8250 /* Emit debug info for the current line number, choosing the encoding
8251 that uses the least amount of space. */
8252 if (line_info->dw_line_num != current_line)
8254 line_offset = line_info->dw_line_num - current_line;
8255 line_delta = line_offset - DWARF_LINE_BASE;
8256 current_line = line_info->dw_line_num;
8257 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8258 /* This can handle deltas from -10 to 234, using the current
8259 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8261 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8262 "line %lu", current_line);
8265 /* This can handle any delta. This takes at least 4 bytes,
8266 depending on the value being encoded. */
8267 dw2_asm_output_data (1, DW_LNS_advance_line,
8268 "advance to line %lu", current_line);
8269 dw2_asm_output_data_sleb128 (line_offset, NULL);
8270 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8274 /* We still need to start a new row, so output a copy insn. */
8275 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8278 /* Emit debug info for the address of the end of the function. */
8281 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8282 "DW_LNS_fixed_advance_pc");
8283 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8287 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8288 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8289 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8290 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8293 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8294 dw2_asm_output_data_uleb128 (1, NULL);
8295 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8300 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8302 dw_separate_line_info_ref line_info
8303 = &separate_line_info_table[lt_index];
8306 /* Don't emit anything for redundant notes. */
8307 if (line_info->dw_line_num == current_line
8308 && line_info->dw_file_num == current_file
8309 && line_info->function == function)
8313 /* Emit debug info for the address of the current line. If this is
8314 a new function, or the first line of a function, then we need
8315 to handle it differently. */
8316 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8318 if (function != line_info->function)
8320 function = line_info->function;
8322 /* Set the address register to the first line in the function. */
8323 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8324 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8325 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8326 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8330 /* ??? See the DW_LNS_advance_pc comment above. */
8333 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8334 "DW_LNS_fixed_advance_pc");
8335 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8339 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8340 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8341 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8342 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8346 strcpy (prev_line_label, line_label);
8348 /* Emit debug info for the source file of the current line, if
8349 different from the previous line. */
8350 if (line_info->dw_file_num != current_file)
8352 current_file = line_info->dw_file_num;
8353 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8354 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8357 /* Emit debug info for the current line number, choosing the encoding
8358 that uses the least amount of space. */
8359 if (line_info->dw_line_num != current_line)
8361 line_offset = line_info->dw_line_num - current_line;
8362 line_delta = line_offset - DWARF_LINE_BASE;
8363 current_line = line_info->dw_line_num;
8364 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8365 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8366 "line %lu", current_line);
8369 dw2_asm_output_data (1, DW_LNS_advance_line,
8370 "advance to line %lu", current_line);
8371 dw2_asm_output_data_sleb128 (line_offset, NULL);
8372 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8376 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8384 /* If we're done with a function, end its sequence. */
8385 if (lt_index == separate_line_info_table_in_use
8386 || separate_line_info_table[lt_index].function != function)
8391 /* Emit debug info for the address of the end of the function. */
8392 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8395 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8396 "DW_LNS_fixed_advance_pc");
8397 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8401 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8402 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8403 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8404 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8407 /* Output the marker for the end of this sequence. */
8408 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8409 dw2_asm_output_data_uleb128 (1, NULL);
8410 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8414 /* Output the marker for the end of the line number info. */
8415 ASM_OUTPUT_LABEL (asm_out_file, l2);
8418 /* Given a pointer to a tree node for some base type, return a pointer to
8419 a DIE that describes the given type.
8421 This routine must only be called for GCC type nodes that correspond to
8422 Dwarf base (fundamental) types. */
8425 base_type_die (tree type)
8427 dw_die_ref base_type_result;
8428 enum dwarf_type encoding;
8430 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8433 switch (TREE_CODE (type))
8436 if (TYPE_STRING_FLAG (type))
8438 if (TYPE_UNSIGNED (type))
8439 encoding = DW_ATE_unsigned_char;
8441 encoding = DW_ATE_signed_char;
8443 else if (TYPE_UNSIGNED (type))
8444 encoding = DW_ATE_unsigned;
8446 encoding = DW_ATE_signed;
8450 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8451 encoding = DW_ATE_decimal_float;
8453 encoding = DW_ATE_float;
8456 case FIXED_POINT_TYPE:
8457 if (TYPE_UNSIGNED (type))
8458 encoding = DW_ATE_unsigned_fixed;
8460 encoding = DW_ATE_signed_fixed;
8463 /* Dwarf2 doesn't know anything about complex ints, so use
8464 a user defined type for it. */
8466 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8467 encoding = DW_ATE_complex_float;
8469 encoding = DW_ATE_lo_user;
8473 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8474 encoding = DW_ATE_boolean;
8478 /* No other TREE_CODEs are Dwarf fundamental types. */
8482 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8484 /* This probably indicates a bug. */
8485 if (! TYPE_NAME (type))
8486 add_name_attribute (base_type_result, "__unknown__");
8488 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8489 int_size_in_bytes (type));
8490 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8492 return base_type_result;
8495 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8496 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8499 is_base_type (tree type)
8501 switch (TREE_CODE (type))
8507 case FIXED_POINT_TYPE:
8515 case QUAL_UNION_TYPE:
8520 case REFERENCE_TYPE:
8533 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8534 node, return the size in bits for the type if it is a constant, or else
8535 return the alignment for the type if the type's size is not constant, or
8536 else return BITS_PER_WORD if the type actually turns out to be an
8539 static inline unsigned HOST_WIDE_INT
8540 simple_type_size_in_bits (const_tree type)
8542 if (TREE_CODE (type) == ERROR_MARK)
8543 return BITS_PER_WORD;
8544 else if (TYPE_SIZE (type) == NULL_TREE)
8546 else if (host_integerp (TYPE_SIZE (type), 1))
8547 return tree_low_cst (TYPE_SIZE (type), 1);
8549 return TYPE_ALIGN (type);
8552 /* Return true if the debug information for the given type should be
8553 emitted as a subrange type. */
8556 is_subrange_type (const_tree type)
8558 tree subtype = TREE_TYPE (type);
8560 /* Subrange types are identified by the fact that they are integer
8561 types, and that they have a subtype which is either an integer type
8562 or an enumeral type. */
8564 if (TREE_CODE (type) != INTEGER_TYPE
8565 || subtype == NULL_TREE)
8568 if (TREE_CODE (subtype) != INTEGER_TYPE
8569 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8572 if (TREE_CODE (type) == TREE_CODE (subtype)
8573 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8574 && TYPE_MIN_VALUE (type) != NULL
8575 && TYPE_MIN_VALUE (subtype) != NULL
8576 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8577 && TYPE_MAX_VALUE (type) != NULL
8578 && TYPE_MAX_VALUE (subtype) != NULL
8579 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8581 /* The type and its subtype have the same representation. If in
8582 addition the two types also have the same name, then the given
8583 type is not a subrange type, but rather a plain base type. */
8584 /* FIXME: brobecker/2004-03-22:
8585 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8586 therefore be sufficient to check the TYPE_SIZE node pointers
8587 rather than checking the actual size. Unfortunately, we have
8588 found some cases, such as in the Ada "integer" type, where
8589 this is not the case. Until this problem is solved, we need to
8590 keep checking the actual size. */
8591 tree type_name = TYPE_NAME (type);
8592 tree subtype_name = TYPE_NAME (subtype);
8594 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8595 type_name = DECL_NAME (type_name);
8597 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8598 subtype_name = DECL_NAME (subtype_name);
8600 if (type_name == subtype_name)
8607 /* Given a pointer to a tree node for a subrange type, return a pointer
8608 to a DIE that describes the given type. */
8611 subrange_type_die (tree type, dw_die_ref context_die)
8613 dw_die_ref subrange_die;
8614 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8616 if (context_die == NULL)
8617 context_die = comp_unit_die;
8619 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8621 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8623 /* The size of the subrange type and its base type do not match,
8624 so we need to generate a size attribute for the subrange type. */
8625 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8628 if (TYPE_MIN_VALUE (type) != NULL)
8629 add_bound_info (subrange_die, DW_AT_lower_bound,
8630 TYPE_MIN_VALUE (type));
8631 if (TYPE_MAX_VALUE (type) != NULL)
8632 add_bound_info (subrange_die, DW_AT_upper_bound,
8633 TYPE_MAX_VALUE (type));
8635 return subrange_die;
8638 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8639 entry that chains various modifiers in front of the given type. */
8642 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8643 dw_die_ref context_die)
8645 enum tree_code code = TREE_CODE (type);
8646 dw_die_ref mod_type_die;
8647 dw_die_ref sub_die = NULL;
8648 tree item_type = NULL;
8649 tree qualified_type;
8652 if (code == ERROR_MARK)
8655 /* See if we already have the appropriately qualified variant of
8658 = get_qualified_type (type,
8659 ((is_const_type ? TYPE_QUAL_CONST : 0)
8660 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8662 /* If we do, then we can just use its DIE, if it exists. */
8665 mod_type_die = lookup_type_die (qualified_type);
8667 return mod_type_die;
8670 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8672 /* Handle C typedef types. */
8673 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8675 tree dtype = TREE_TYPE (name);
8677 if (qualified_type == dtype)
8679 /* For a named type, use the typedef. */
8680 gen_type_die (qualified_type, context_die);
8681 return lookup_type_die (qualified_type);
8683 else if (is_const_type < TYPE_READONLY (dtype)
8684 || is_volatile_type < TYPE_VOLATILE (dtype)
8685 || (is_const_type <= TYPE_READONLY (dtype)
8686 && is_volatile_type <= TYPE_VOLATILE (dtype)
8687 && DECL_ORIGINAL_TYPE (name) != type))
8688 /* cv-unqualified version of named type. Just use the unnamed
8689 type to which it refers. */
8690 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8691 is_const_type, is_volatile_type,
8693 /* Else cv-qualified version of named type; fall through. */
8698 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8699 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8701 else if (is_volatile_type)
8703 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8704 sub_die = modified_type_die (type, 0, 0, context_die);
8706 else if (code == POINTER_TYPE)
8708 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8709 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8710 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8711 item_type = TREE_TYPE (type);
8713 else if (code == REFERENCE_TYPE)
8715 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8716 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8717 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8718 item_type = TREE_TYPE (type);
8720 else if (is_subrange_type (type))
8722 mod_type_die = subrange_type_die (type, context_die);
8723 item_type = TREE_TYPE (type);
8725 else if (is_base_type (type))
8726 mod_type_die = base_type_die (type);
8729 gen_type_die (type, context_die);
8731 /* We have to get the type_main_variant here (and pass that to the
8732 `lookup_type_die' routine) because the ..._TYPE node we have
8733 might simply be a *copy* of some original type node (where the
8734 copy was created to help us keep track of typedef names) and
8735 that copy might have a different TYPE_UID from the original
8737 if (TREE_CODE (type) != VECTOR_TYPE)
8738 return lookup_type_die (type_main_variant (type));
8740 /* Vectors have the debugging information in the type,
8741 not the main variant. */
8742 return lookup_type_die (type);
8745 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8746 don't output a DW_TAG_typedef, since there isn't one in the
8747 user's program; just attach a DW_AT_name to the type. */
8749 && (TREE_CODE (name) != TYPE_DECL
8750 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
8752 if (TREE_CODE (name) == TYPE_DECL)
8753 /* Could just call add_name_and_src_coords_attributes here,
8754 but since this is a builtin type it doesn't have any
8755 useful source coordinates anyway. */
8756 name = DECL_NAME (name);
8757 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8761 equate_type_number_to_die (qualified_type, mod_type_die);
8764 /* We must do this after the equate_type_number_to_die call, in case
8765 this is a recursive type. This ensures that the modified_type_die
8766 recursion will terminate even if the type is recursive. Recursive
8767 types are possible in Ada. */
8768 sub_die = modified_type_die (item_type,
8769 TYPE_READONLY (item_type),
8770 TYPE_VOLATILE (item_type),
8773 if (sub_die != NULL)
8774 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8776 return mod_type_die;
8779 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8780 an enumerated type. */
8783 type_is_enum (const_tree type)
8785 return TREE_CODE (type) == ENUMERAL_TYPE;
8788 /* Return the DBX register number described by a given RTL node. */
8791 dbx_reg_number (const_rtx rtl)
8793 unsigned regno = REGNO (rtl);
8795 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8797 #ifdef LEAF_REG_REMAP
8798 if (current_function_uses_only_leaf_regs)
8800 int leaf_reg = LEAF_REG_REMAP (regno);
8802 regno = (unsigned) leaf_reg;
8806 return DBX_REGISTER_NUMBER (regno);
8809 /* Optionally add a DW_OP_piece term to a location description expression.
8810 DW_OP_piece is only added if the location description expression already
8811 doesn't end with DW_OP_piece. */
8814 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8816 dw_loc_descr_ref loc;
8818 if (*list_head != NULL)
8820 /* Find the end of the chain. */
8821 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8824 if (loc->dw_loc_opc != DW_OP_piece)
8825 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8829 /* Return a location descriptor that designates a machine register or
8830 zero if there is none. */
8832 static dw_loc_descr_ref
8833 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
8837 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8840 regs = targetm.dwarf_register_span (rtl);
8842 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8843 return multiple_reg_loc_descriptor (rtl, regs, initialized);
8845 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
8848 /* Return a location descriptor that designates a machine register for
8849 a given hard register number. */
8851 static dw_loc_descr_ref
8852 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
8854 dw_loc_descr_ref reg_loc_descr;
8856 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8858 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
8860 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8861 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8863 return reg_loc_descr;
8866 /* Given an RTL of a register, return a location descriptor that
8867 designates a value that spans more than one register. */
8869 static dw_loc_descr_ref
8870 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
8871 enum var_init_status initialized)
8875 dw_loc_descr_ref loc_result = NULL;
8878 #ifdef LEAF_REG_REMAP
8879 if (current_function_uses_only_leaf_regs)
8881 int leaf_reg = LEAF_REG_REMAP (reg);
8883 reg = (unsigned) leaf_reg;
8886 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8887 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8889 /* Simple, contiguous registers. */
8890 if (regs == NULL_RTX)
8892 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8899 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
8900 VAR_INIT_STATUS_INITIALIZED);
8901 add_loc_descr (&loc_result, t);
8902 add_loc_descr_op_piece (&loc_result, size);
8908 /* Now onto stupid register sets in non contiguous locations. */
8910 gcc_assert (GET_CODE (regs) == PARALLEL);
8912 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8915 for (i = 0; i < XVECLEN (regs, 0); ++i)
8919 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
8920 VAR_INIT_STATUS_INITIALIZED);
8921 add_loc_descr (&loc_result, t);
8922 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8923 add_loc_descr_op_piece (&loc_result, size);
8926 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8927 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8931 /* Return a location descriptor that designates a constant. */
8933 static dw_loc_descr_ref
8934 int_loc_descriptor (HOST_WIDE_INT i)
8936 enum dwarf_location_atom op;
8938 /* Pick the smallest representation of a constant, rather than just
8939 defaulting to the LEB encoding. */
8943 op = DW_OP_lit0 + i;
8946 else if (i <= 0xffff)
8948 else if (HOST_BITS_PER_WIDE_INT == 32
8958 else if (i >= -0x8000)
8960 else if (HOST_BITS_PER_WIDE_INT == 32
8961 || i >= -0x80000000)
8967 return new_loc_descr (op, i, 0);
8970 /* Return a location descriptor that designates a base+offset location. */
8972 static dw_loc_descr_ref
8973 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
8974 enum var_init_status initialized)
8977 dw_loc_descr_ref result;
8979 /* We only use "frame base" when we're sure we're talking about the
8980 post-prologue local stack frame. We do this by *not* running
8981 register elimination until this point, and recognizing the special
8982 argument pointer and soft frame pointer rtx's. */
8983 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8985 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8989 if (GET_CODE (elim) == PLUS)
8991 offset += INTVAL (XEXP (elim, 1));
8992 elim = XEXP (elim, 0);
8994 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8995 : stack_pointer_rtx));
8996 offset += frame_pointer_fb_offset;
8998 return new_loc_descr (DW_OP_fbreg, offset, 0);
9002 regno = dbx_reg_number (reg);
9004 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9006 result = new_loc_descr (DW_OP_bregx, regno, offset);
9008 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9009 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9014 /* Return true if this RTL expression describes a base+offset calculation. */
9017 is_based_loc (const_rtx rtl)
9019 return (GET_CODE (rtl) == PLUS
9020 && ((REG_P (XEXP (rtl, 0))
9021 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9022 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9025 /* Return a descriptor that describes the concatenation of N locations
9026 used to form the address of a memory location. */
9028 static dw_loc_descr_ref
9029 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9030 enum var_init_status initialized)
9033 dw_loc_descr_ref cc_loc_result = NULL;
9034 unsigned int n = XVECLEN (concatn, 0);
9036 for (i = 0; i < n; ++i)
9038 dw_loc_descr_ref ref;
9039 rtx x = XVECEXP (concatn, 0, i);
9041 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9045 add_loc_descr (&cc_loc_result, ref);
9046 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9049 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9050 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9052 return cc_loc_result;
9055 /* The following routine converts the RTL for a variable or parameter
9056 (resident in memory) into an equivalent Dwarf representation of a
9057 mechanism for getting the address of that same variable onto the top of a
9058 hypothetical "address evaluation" stack.
9060 When creating memory location descriptors, we are effectively transforming
9061 the RTL for a memory-resident object into its Dwarf postfix expression
9062 equivalent. This routine recursively descends an RTL tree, turning
9063 it into Dwarf postfix code as it goes.
9065 MODE is the mode of the memory reference, needed to handle some
9066 autoincrement addressing modes.
9068 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9069 location list for RTL.
9071 Return 0 if we can't represent the location. */
9073 static dw_loc_descr_ref
9074 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9075 enum var_init_status initialized)
9077 dw_loc_descr_ref mem_loc_result = NULL;
9078 enum dwarf_location_atom op;
9080 /* Note that for a dynamically sized array, the location we will generate a
9081 description of here will be the lowest numbered location which is
9082 actually within the array. That's *not* necessarily the same as the
9083 zeroth element of the array. */
9085 rtl = targetm.delegitimize_address (rtl);
9087 switch (GET_CODE (rtl))
9092 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9093 just fall into the SUBREG code. */
9095 /* ... fall through ... */
9098 /* The case of a subreg may arise when we have a local (register)
9099 variable or a formal (register) parameter which doesn't quite fill
9100 up an entire register. For now, just assume that it is
9101 legitimate to make the Dwarf info refer to the whole register which
9102 contains the given subreg. */
9103 rtl = XEXP (rtl, 0);
9105 /* ... fall through ... */
9108 /* Whenever a register number forms a part of the description of the
9109 method for calculating the (dynamic) address of a memory resident
9110 object, DWARF rules require the register number be referred to as
9111 a "base register". This distinction is not based in any way upon
9112 what category of register the hardware believes the given register
9113 belongs to. This is strictly DWARF terminology we're dealing with
9114 here. Note that in cases where the location of a memory-resident
9115 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9116 OP_CONST (0)) the actual DWARF location descriptor that we generate
9117 may just be OP_BASEREG (basereg). This may look deceptively like
9118 the object in question was allocated to a register (rather than in
9119 memory) so DWARF consumers need to be aware of the subtle
9120 distinction between OP_REG and OP_BASEREG. */
9121 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9122 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9126 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9127 VAR_INIT_STATUS_INITIALIZED);
9128 if (mem_loc_result != 0)
9129 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9133 rtl = XEXP (rtl, 1);
9135 /* ... fall through ... */
9138 /* Some ports can transform a symbol ref into a label ref, because
9139 the symbol ref is too far away and has to be dumped into a constant
9143 /* Alternatively, the symbol in the constant pool might be referenced
9144 by a different symbol. */
9145 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9148 rtx tmp = get_pool_constant_mark (rtl, &marked);
9150 if (GET_CODE (tmp) == SYMBOL_REF)
9153 if (CONSTANT_POOL_ADDRESS_P (tmp))
9154 get_pool_constant_mark (tmp, &marked);
9159 /* If all references to this pool constant were optimized away,
9160 it was not output and thus we can't represent it.
9161 FIXME: might try to use DW_OP_const_value here, though
9162 DW_OP_piece complicates it. */
9167 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9168 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9169 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9170 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9174 /* Extract the PLUS expression nested inside and fall into
9176 rtl = XEXP (rtl, 1);
9181 /* Turn these into a PLUS expression and fall into the PLUS code
9183 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9184 GEN_INT (GET_CODE (rtl) == PRE_INC
9185 ? GET_MODE_UNIT_SIZE (mode)
9186 : -GET_MODE_UNIT_SIZE (mode)));
9188 /* ... fall through ... */
9192 if (is_based_loc (rtl))
9193 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9194 INTVAL (XEXP (rtl, 1)),
9195 VAR_INIT_STATUS_INITIALIZED);
9198 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9199 VAR_INIT_STATUS_INITIALIZED);
9200 if (mem_loc_result == 0)
9203 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9204 && INTVAL (XEXP (rtl, 1)) >= 0)
9205 add_loc_descr (&mem_loc_result,
9206 new_loc_descr (DW_OP_plus_uconst,
9207 INTVAL (XEXP (rtl, 1)), 0));
9210 add_loc_descr (&mem_loc_result,
9211 mem_loc_descriptor (XEXP (rtl, 1), mode,
9212 VAR_INIT_STATUS_INITIALIZED));
9213 add_loc_descr (&mem_loc_result,
9214 new_loc_descr (DW_OP_plus, 0, 0));
9219 /* If a pseudo-reg is optimized away, it is possible for it to
9220 be replaced with a MEM containing a multiply or shift. */
9239 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9240 VAR_INIT_STATUS_INITIALIZED);
9241 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9242 VAR_INIT_STATUS_INITIALIZED);
9244 if (op0 == 0 || op1 == 0)
9247 mem_loc_result = op0;
9248 add_loc_descr (&mem_loc_result, op1);
9249 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9254 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9258 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9259 VAR_INIT_STATUS_INITIALIZED);
9266 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9267 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9269 return mem_loc_result;
9272 /* Return a descriptor that describes the concatenation of two locations.
9273 This is typically a complex variable. */
9275 static dw_loc_descr_ref
9276 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9278 dw_loc_descr_ref cc_loc_result = NULL;
9279 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9280 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9282 if (x0_ref == 0 || x1_ref == 0)
9285 cc_loc_result = x0_ref;
9286 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9288 add_loc_descr (&cc_loc_result, x1_ref);
9289 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9291 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9292 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9294 return cc_loc_result;
9297 /* Return a descriptor that describes the concatenation of N
9300 static dw_loc_descr_ref
9301 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9304 dw_loc_descr_ref cc_loc_result = NULL;
9305 unsigned int n = XVECLEN (concatn, 0);
9307 for (i = 0; i < n; ++i)
9309 dw_loc_descr_ref ref;
9310 rtx x = XVECEXP (concatn, 0, i);
9312 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9316 add_loc_descr (&cc_loc_result, ref);
9317 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9320 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9321 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9323 return cc_loc_result;
9326 /* Output a proper Dwarf location descriptor for a variable or parameter
9327 which is either allocated in a register or in a memory location. For a
9328 register, we just generate an OP_REG and the register number. For a
9329 memory location we provide a Dwarf postfix expression describing how to
9330 generate the (dynamic) address of the object onto the address stack.
9332 If we don't know how to describe it, return 0. */
9334 static dw_loc_descr_ref
9335 loc_descriptor (rtx rtl, enum var_init_status initialized)
9337 dw_loc_descr_ref loc_result = NULL;
9339 switch (GET_CODE (rtl))
9342 /* The case of a subreg may arise when we have a local (register)
9343 variable or a formal (register) parameter which doesn't quite fill
9344 up an entire register. For now, just assume that it is
9345 legitimate to make the Dwarf info refer to the whole register which
9346 contains the given subreg. */
9347 rtl = SUBREG_REG (rtl);
9349 /* ... fall through ... */
9352 loc_result = reg_loc_descriptor (rtl, initialized);
9356 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9361 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9366 loc_result = concatn_loc_descriptor (rtl, initialized);
9371 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9373 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9377 rtl = XEXP (rtl, 1);
9382 rtvec par_elems = XVEC (rtl, 0);
9383 int num_elem = GET_NUM_ELEM (par_elems);
9384 enum machine_mode mode;
9387 /* Create the first one, so we have something to add to. */
9388 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9390 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9391 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9392 for (i = 1; i < num_elem; i++)
9394 dw_loc_descr_ref temp;
9396 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9398 add_loc_descr (&loc_result, temp);
9399 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9400 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9412 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9413 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9414 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9415 top-level invocation, and we require the address of LOC; is 0 if we require
9416 the value of LOC. */
9418 static dw_loc_descr_ref
9419 loc_descriptor_from_tree_1 (tree loc, int want_address)
9421 dw_loc_descr_ref ret, ret1;
9422 int have_address = 0;
9423 enum dwarf_location_atom op;
9425 /* ??? Most of the time we do not take proper care for sign/zero
9426 extending the values properly. Hopefully this won't be a real
9429 switch (TREE_CODE (loc))
9434 case PLACEHOLDER_EXPR:
9435 /* This case involves extracting fields from an object to determine the
9436 position of other fields. We don't try to encode this here. The
9437 only user of this is Ada, which encodes the needed information using
9438 the names of types. */
9444 case PREINCREMENT_EXPR:
9445 case PREDECREMENT_EXPR:
9446 case POSTINCREMENT_EXPR:
9447 case POSTDECREMENT_EXPR:
9448 /* There are no opcodes for these operations. */
9452 /* If we already want an address, there's nothing we can do. */
9456 /* Otherwise, process the argument and look for the address. */
9457 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9460 if (DECL_THREAD_LOCAL_P (loc))
9464 /* If this is not defined, we have no way to emit the data. */
9465 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
9468 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9469 look up addresses of objects in the current module. */
9470 if (DECL_EXTERNAL (loc))
9473 rtl = rtl_for_decl_location (loc);
9474 if (rtl == NULL_RTX)
9479 rtl = XEXP (rtl, 0);
9480 if (! CONSTANT_P (rtl))
9483 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9484 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9485 ret->dw_loc_oprnd1.v.val_addr = rtl;
9487 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9488 add_loc_descr (&ret, ret1);
9496 if (DECL_HAS_VALUE_EXPR_P (loc))
9497 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9504 rtx rtl = rtl_for_decl_location (loc);
9506 if (rtl == NULL_RTX)
9508 else if (GET_CODE (rtl) == CONST_INT)
9510 HOST_WIDE_INT val = INTVAL (rtl);
9511 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9512 val &= GET_MODE_MASK (DECL_MODE (loc));
9513 ret = int_loc_descriptor (val);
9515 else if (GET_CODE (rtl) == CONST_STRING)
9517 else if (CONSTANT_P (rtl))
9519 ret = new_loc_descr (DW_OP_addr, 0, 0);
9520 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9521 ret->dw_loc_oprnd1.v.val_addr = rtl;
9525 enum machine_mode mode;
9527 /* Certain constructs can only be represented at top-level. */
9528 if (want_address == 2)
9529 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
9531 mode = GET_MODE (rtl);
9534 rtl = XEXP (rtl, 0);
9537 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9543 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9548 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9552 case NON_LVALUE_EXPR:
9553 case VIEW_CONVERT_EXPR:
9555 case GIMPLE_MODIFY_STMT:
9556 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0),
9562 case ARRAY_RANGE_REF:
9565 HOST_WIDE_INT bitsize, bitpos, bytepos;
9566 enum machine_mode mode;
9568 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9570 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9571 &unsignedp, &volatilep, false);
9576 ret = loc_descriptor_from_tree_1 (obj, 1);
9578 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9581 if (offset != NULL_TREE)
9583 /* Variable offset. */
9584 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9585 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9588 bytepos = bitpos / BITS_PER_UNIT;
9590 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9591 else if (bytepos < 0)
9593 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9594 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9602 if (host_integerp (loc, 0))
9603 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9610 /* Get an RTL for this, if something has been emitted. */
9611 rtx rtl = lookup_constant_def (loc);
9612 enum machine_mode mode;
9614 if (!rtl || !MEM_P (rtl))
9616 mode = GET_MODE (rtl);
9617 rtl = XEXP (rtl, 0);
9618 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9623 case TRUTH_AND_EXPR:
9624 case TRUTH_ANDIF_EXPR:
9629 case TRUTH_XOR_EXPR:
9635 case TRUTH_ORIF_EXPR:
9640 case FLOOR_DIV_EXPR:
9642 case ROUND_DIV_EXPR:
9643 case TRUNC_DIV_EXPR:
9651 case FLOOR_MOD_EXPR:
9653 case ROUND_MOD_EXPR:
9654 case TRUNC_MOD_EXPR:
9667 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9670 case POINTER_PLUS_EXPR:
9672 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9673 && host_integerp (TREE_OPERAND (loc, 1), 0))
9675 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9679 add_loc_descr (&ret,
9680 new_loc_descr (DW_OP_plus_uconst,
9681 tree_low_cst (TREE_OPERAND (loc, 1),
9691 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9698 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9705 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9712 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9727 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9728 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9729 if (ret == 0 || ret1 == 0)
9732 add_loc_descr (&ret, ret1);
9733 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9736 case TRUTH_NOT_EXPR:
9750 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9754 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9760 const enum tree_code code =
9761 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9763 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9764 build2 (code, integer_type_node,
9765 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9766 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9769 /* ... fall through ... */
9773 dw_loc_descr_ref lhs
9774 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9775 dw_loc_descr_ref rhs
9776 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9777 dw_loc_descr_ref bra_node, jump_node, tmp;
9779 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9780 if (ret == 0 || lhs == 0 || rhs == 0)
9783 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9784 add_loc_descr (&ret, bra_node);
9786 add_loc_descr (&ret, rhs);
9787 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9788 add_loc_descr (&ret, jump_node);
9790 add_loc_descr (&ret, lhs);
9791 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9792 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9794 /* ??? Need a node to point the skip at. Use a nop. */
9795 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9796 add_loc_descr (&ret, tmp);
9797 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9798 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9802 case FIX_TRUNC_EXPR:
9806 /* Leave front-end specific codes as simply unknown. This comes
9807 up, for instance, with the C STMT_EXPR. */
9808 if ((unsigned int) TREE_CODE (loc)
9809 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9812 #ifdef ENABLE_CHECKING
9813 /* Otherwise this is a generic code; we should just lists all of
9814 these explicitly. We forgot one. */
9817 /* In a release build, we want to degrade gracefully: better to
9818 generate incomplete debugging information than to crash. */
9823 /* Show if we can't fill the request for an address. */
9824 if (want_address && !have_address)
9827 /* If we've got an address and don't want one, dereference. */
9828 if (!want_address && have_address && ret)
9830 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9832 if (size > DWARF2_ADDR_SIZE || size == -1)
9834 else if (size == DWARF2_ADDR_SIZE)
9837 op = DW_OP_deref_size;
9839 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9845 static inline dw_loc_descr_ref
9846 loc_descriptor_from_tree (tree loc)
9848 return loc_descriptor_from_tree_1 (loc, 2);
9851 /* Given a value, round it up to the lowest multiple of `boundary'
9852 which is not less than the value itself. */
9854 static inline HOST_WIDE_INT
9855 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9857 return (((value + boundary - 1) / boundary) * boundary);
9860 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9861 pointer to the declared type for the relevant field variable, or return
9862 `integer_type_node' if the given node turns out to be an
9866 field_type (const_tree decl)
9870 if (TREE_CODE (decl) == ERROR_MARK)
9871 return integer_type_node;
9873 type = DECL_BIT_FIELD_TYPE (decl);
9874 if (type == NULL_TREE)
9875 type = TREE_TYPE (decl);
9880 /* Given a pointer to a tree node, return the alignment in bits for
9881 it, or else return BITS_PER_WORD if the node actually turns out to
9882 be an ERROR_MARK node. */
9884 static inline unsigned
9885 simple_type_align_in_bits (const_tree type)
9887 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9890 static inline unsigned
9891 simple_decl_align_in_bits (const_tree decl)
9893 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9896 /* Return the result of rounding T up to ALIGN. */
9898 static inline HOST_WIDE_INT
9899 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9901 /* We must be careful if T is negative because HOST_WIDE_INT can be
9902 either "above" or "below" unsigned int as per the C promotion
9903 rules, depending on the host, thus making the signedness of the
9904 direct multiplication and division unpredictable. */
9905 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9911 return (HOST_WIDE_INT) u;
9914 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9915 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9916 or return 0 if we are unable to determine what that offset is, either
9917 because the argument turns out to be a pointer to an ERROR_MARK node, or
9918 because the offset is actually variable. (We can't handle the latter case
9921 static HOST_WIDE_INT
9922 field_byte_offset (const_tree decl)
9924 HOST_WIDE_INT object_offset_in_bits;
9925 HOST_WIDE_INT bitpos_int;
9927 if (TREE_CODE (decl) == ERROR_MARK)
9930 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9932 /* We cannot yet cope with fields whose positions are variable, so
9933 for now, when we see such things, we simply return 0. Someday, we may
9934 be able to handle such cases, but it will be damn difficult. */
9935 if (! host_integerp (bit_position (decl), 0))
9938 bitpos_int = int_bit_position (decl);
9940 #ifdef PCC_BITFIELD_TYPE_MATTERS
9941 if (PCC_BITFIELD_TYPE_MATTERS)
9944 tree field_size_tree;
9945 HOST_WIDE_INT deepest_bitpos;
9946 unsigned HOST_WIDE_INT field_size_in_bits;
9947 unsigned int type_align_in_bits;
9948 unsigned int decl_align_in_bits;
9949 unsigned HOST_WIDE_INT type_size_in_bits;
9951 type = field_type (decl);
9952 field_size_tree = DECL_SIZE (decl);
9954 /* The size could be unspecified if there was an error, or for
9955 a flexible array member. */
9956 if (! field_size_tree)
9957 field_size_tree = bitsize_zero_node;
9959 /* If we don't know the size of the field, pretend it's a full word. */
9960 if (host_integerp (field_size_tree, 1))
9961 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9963 field_size_in_bits = BITS_PER_WORD;
9965 type_size_in_bits = simple_type_size_in_bits (type);
9966 type_align_in_bits = simple_type_align_in_bits (type);
9967 decl_align_in_bits = simple_decl_align_in_bits (decl);
9969 /* The GCC front-end doesn't make any attempt to keep track of the
9970 starting bit offset (relative to the start of the containing
9971 structure type) of the hypothetical "containing object" for a
9972 bit-field. Thus, when computing the byte offset value for the
9973 start of the "containing object" of a bit-field, we must deduce
9974 this information on our own. This can be rather tricky to do in
9975 some cases. For example, handling the following structure type
9976 definition when compiling for an i386/i486 target (which only
9977 aligns long long's to 32-bit boundaries) can be very tricky:
9979 struct S { int field1; long long field2:31; };
9981 Fortunately, there is a simple rule-of-thumb which can be used
9982 in such cases. When compiling for an i386/i486, GCC will
9983 allocate 8 bytes for the structure shown above. It decides to
9984 do this based upon one simple rule for bit-field allocation.
9985 GCC allocates each "containing object" for each bit-field at
9986 the first (i.e. lowest addressed) legitimate alignment boundary
9987 (based upon the required minimum alignment for the declared
9988 type of the field) which it can possibly use, subject to the
9989 condition that there is still enough available space remaining
9990 in the containing object (when allocated at the selected point)
9991 to fully accommodate all of the bits of the bit-field itself.
9993 This simple rule makes it obvious why GCC allocates 8 bytes for
9994 each object of the structure type shown above. When looking
9995 for a place to allocate the "containing object" for `field2',
9996 the compiler simply tries to allocate a 64-bit "containing
9997 object" at each successive 32-bit boundary (starting at zero)
9998 until it finds a place to allocate that 64- bit field such that
9999 at least 31 contiguous (and previously unallocated) bits remain
10000 within that selected 64 bit field. (As it turns out, for the
10001 example above, the compiler finds it is OK to allocate the
10002 "containing object" 64-bit field at bit-offset zero within the
10005 Here we attempt to work backwards from the limited set of facts
10006 we're given, and we try to deduce from those facts, where GCC
10007 must have believed that the containing object started (within
10008 the structure type). The value we deduce is then used (by the
10009 callers of this routine) to generate DW_AT_location and
10010 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10011 the case of DW_AT_location, regular fields as well). */
10013 /* Figure out the bit-distance from the start of the structure to
10014 the "deepest" bit of the bit-field. */
10015 deepest_bitpos = bitpos_int + field_size_in_bits;
10017 /* This is the tricky part. Use some fancy footwork to deduce
10018 where the lowest addressed bit of the containing object must
10020 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10022 /* Round up to type_align by default. This works best for
10024 object_offset_in_bits
10025 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10027 if (object_offset_in_bits > bitpos_int)
10029 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10031 /* Round up to decl_align instead. */
10032 object_offset_in_bits
10033 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10038 object_offset_in_bits = bitpos_int;
10040 return object_offset_in_bits / BITS_PER_UNIT;
10043 /* The following routines define various Dwarf attributes and any data
10044 associated with them. */
10046 /* Add a location description attribute value to a DIE.
10048 This emits location attributes suitable for whole variables and
10049 whole parameters. Note that the location attributes for struct fields are
10050 generated by the routine `data_member_location_attribute' below. */
10053 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10054 dw_loc_descr_ref descr)
10057 add_AT_loc (die, attr_kind, descr);
10060 /* Attach the specialized form of location attribute used for data members of
10061 struct and union types. In the special case of a FIELD_DECL node which
10062 represents a bit-field, the "offset" part of this special location
10063 descriptor must indicate the distance in bytes from the lowest-addressed
10064 byte of the containing struct or union type to the lowest-addressed byte of
10065 the "containing object" for the bit-field. (See the `field_byte_offset'
10068 For any given bit-field, the "containing object" is a hypothetical object
10069 (of some integral or enum type) within which the given bit-field lives. The
10070 type of this hypothetical "containing object" is always the same as the
10071 declared type of the individual bit-field itself (for GCC anyway... the
10072 DWARF spec doesn't actually mandate this). Note that it is the size (in
10073 bytes) of the hypothetical "containing object" which will be given in the
10074 DW_AT_byte_size attribute for this bit-field. (See the
10075 `byte_size_attribute' function below.) It is also used when calculating the
10076 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10077 function below.) */
10080 add_data_member_location_attribute (dw_die_ref die, tree decl)
10082 HOST_WIDE_INT offset;
10083 dw_loc_descr_ref loc_descr = 0;
10085 if (TREE_CODE (decl) == TREE_BINFO)
10087 /* We're working on the TAG_inheritance for a base class. */
10088 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10090 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10091 aren't at a fixed offset from all (sub)objects of the same
10092 type. We need to extract the appropriate offset from our
10093 vtable. The following dwarf expression means
10095 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10097 This is specific to the V3 ABI, of course. */
10099 dw_loc_descr_ref tmp;
10101 /* Make a copy of the object address. */
10102 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10103 add_loc_descr (&loc_descr, tmp);
10105 /* Extract the vtable address. */
10106 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10107 add_loc_descr (&loc_descr, tmp);
10109 /* Calculate the address of the offset. */
10110 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10111 gcc_assert (offset < 0);
10113 tmp = int_loc_descriptor (-offset);
10114 add_loc_descr (&loc_descr, tmp);
10115 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10116 add_loc_descr (&loc_descr, tmp);
10118 /* Extract the offset. */
10119 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10120 add_loc_descr (&loc_descr, tmp);
10122 /* Add it to the object address. */
10123 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10124 add_loc_descr (&loc_descr, tmp);
10127 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10130 offset = field_byte_offset (decl);
10134 enum dwarf_location_atom op;
10136 /* The DWARF2 standard says that we should assume that the structure
10137 address is already on the stack, so we can specify a structure field
10138 address by using DW_OP_plus_uconst. */
10140 #ifdef MIPS_DEBUGGING_INFO
10141 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10142 operator correctly. It works only if we leave the offset on the
10146 op = DW_OP_plus_uconst;
10149 loc_descr = new_loc_descr (op, offset, 0);
10152 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10155 /* Writes integer values to dw_vec_const array. */
10158 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10162 *dest++ = val & 0xff;
10168 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10170 static HOST_WIDE_INT
10171 extract_int (const unsigned char *src, unsigned int size)
10173 HOST_WIDE_INT val = 0;
10179 val |= *--src & 0xff;
10185 /* Writes floating point values to dw_vec_const array. */
10188 insert_float (const_rtx rtl, unsigned char *array)
10190 REAL_VALUE_TYPE rv;
10194 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10195 real_to_target (val, &rv, GET_MODE (rtl));
10197 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10198 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10200 insert_int (val[i], 4, array);
10205 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10206 does not have a "location" either in memory or in a register. These
10207 things can arise in GNU C when a constant is passed as an actual parameter
10208 to an inlined function. They can also arise in C++ where declared
10209 constants do not necessarily get memory "homes". */
10212 add_const_value_attribute (dw_die_ref die, rtx rtl)
10214 switch (GET_CODE (rtl))
10218 HOST_WIDE_INT val = INTVAL (rtl);
10221 add_AT_int (die, DW_AT_const_value, val);
10223 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10228 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10229 floating-point constant. A CONST_DOUBLE is used whenever the
10230 constant requires more than one word in order to be adequately
10231 represented. We output CONST_DOUBLEs as blocks. */
10233 enum machine_mode mode = GET_MODE (rtl);
10235 if (SCALAR_FLOAT_MODE_P (mode))
10237 unsigned int length = GET_MODE_SIZE (mode);
10238 unsigned char *array = ggc_alloc (length);
10240 insert_float (rtl, array);
10241 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10245 /* ??? We really should be using HOST_WIDE_INT throughout. */
10246 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10248 add_AT_long_long (die, DW_AT_const_value,
10249 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10256 enum machine_mode mode = GET_MODE (rtl);
10257 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10258 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10259 unsigned char *array = ggc_alloc (length * elt_size);
10263 switch (GET_MODE_CLASS (mode))
10265 case MODE_VECTOR_INT:
10266 for (i = 0, p = array; i < length; i++, p += elt_size)
10268 rtx elt = CONST_VECTOR_ELT (rtl, i);
10269 HOST_WIDE_INT lo, hi;
10271 switch (GET_CODE (elt))
10279 lo = CONST_DOUBLE_LOW (elt);
10280 hi = CONST_DOUBLE_HIGH (elt);
10284 gcc_unreachable ();
10287 if (elt_size <= sizeof (HOST_WIDE_INT))
10288 insert_int (lo, elt_size, p);
10291 unsigned char *p0 = p;
10292 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10294 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10295 if (WORDS_BIG_ENDIAN)
10300 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10301 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10306 case MODE_VECTOR_FLOAT:
10307 for (i = 0, p = array; i < length; i++, p += elt_size)
10309 rtx elt = CONST_VECTOR_ELT (rtl, i);
10310 insert_float (elt, p);
10315 gcc_unreachable ();
10318 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10323 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10329 add_AT_addr (die, DW_AT_const_value, rtl);
10330 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10334 /* In cases where an inlined instance of an inline function is passed
10335 the address of an `auto' variable (which is local to the caller) we
10336 can get a situation where the DECL_RTL of the artificial local
10337 variable (for the inlining) which acts as a stand-in for the
10338 corresponding formal parameter (of the inline function) will look
10339 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10340 exactly a compile-time constant expression, but it isn't the address
10341 of the (artificial) local variable either. Rather, it represents the
10342 *value* which the artificial local variable always has during its
10343 lifetime. We currently have no way to represent such quasi-constant
10344 values in Dwarf, so for now we just punt and generate nothing. */
10348 /* No other kinds of rtx should be possible here. */
10349 gcc_unreachable ();
10354 /* Determine whether the evaluation of EXPR references any variables
10355 or functions which aren't otherwise used (and therefore may not be
10358 reference_to_unused (tree * tp, int * walk_subtrees,
10359 void * data ATTRIBUTE_UNUSED)
10361 if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10362 *walk_subtrees = 0;
10364 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10365 && ! TREE_ASM_WRITTEN (*tp))
10367 else if (!flag_unit_at_a_time)
10369 /* ??? The C++ FE emits debug information for using decls, so
10370 putting gcc_unreachable here falls over. See PR31899. For now
10371 be conservative. */
10372 else if (!cgraph_global_info_ready
10373 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10375 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10377 struct varpool_node *node = varpool_node (*tp);
10381 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10382 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10384 struct cgraph_node *node = cgraph_node (*tp);
10388 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
10394 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10395 for use in a later add_const_value_attribute call. */
10398 rtl_for_decl_init (tree init, tree type)
10400 rtx rtl = NULL_RTX;
10402 /* If a variable is initialized with a string constant without embedded
10403 zeros, build CONST_STRING. */
10404 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10406 tree enttype = TREE_TYPE (type);
10407 tree domain = TYPE_DOMAIN (type);
10408 enum machine_mode mode = TYPE_MODE (enttype);
10410 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10412 && integer_zerop (TYPE_MIN_VALUE (domain))
10413 && compare_tree_int (TYPE_MAX_VALUE (domain),
10414 TREE_STRING_LENGTH (init) - 1) == 0
10415 && ((size_t) TREE_STRING_LENGTH (init)
10416 == strlen (TREE_STRING_POINTER (init)) + 1))
10417 rtl = gen_rtx_CONST_STRING (VOIDmode,
10418 ggc_strdup (TREE_STRING_POINTER (init)));
10420 /* Other aggregates, and complex values, could be represented using
10422 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10424 /* Vectors only work if their mode is supported by the target.
10425 FIXME: generic vectors ought to work too. */
10426 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10428 /* If the initializer is something that we know will expand into an
10429 immediate RTL constant, expand it now. We must be careful not to
10430 reference variables which won't be output. */
10431 else if (initializer_constant_valid_p (init, type)
10432 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10434 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10436 if (TREE_CODE (type) == VECTOR_TYPE)
10437 switch (TREE_CODE (init))
10442 if (TREE_CONSTANT (init))
10444 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
10445 bool constant_p = true;
10447 unsigned HOST_WIDE_INT ix;
10449 /* Even when ctor is constant, it might contain non-*_CST
10450 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10451 belong into VECTOR_CST nodes. */
10452 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
10453 if (!CONSTANT_CLASS_P (value))
10455 constant_p = false;
10461 init = build_vector_from_ctor (type, elts);
10471 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10473 /* If expand_expr returns a MEM, it wasn't immediate. */
10474 gcc_assert (!rtl || !MEM_P (rtl));
10480 /* Generate RTL for the variable DECL to represent its location. */
10483 rtl_for_decl_location (tree decl)
10487 /* Here we have to decide where we are going to say the parameter "lives"
10488 (as far as the debugger is concerned). We only have a couple of
10489 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10491 DECL_RTL normally indicates where the parameter lives during most of the
10492 activation of the function. If optimization is enabled however, this
10493 could be either NULL or else a pseudo-reg. Both of those cases indicate
10494 that the parameter doesn't really live anywhere (as far as the code
10495 generation parts of GCC are concerned) during most of the function's
10496 activation. That will happen (for example) if the parameter is never
10497 referenced within the function.
10499 We could just generate a location descriptor here for all non-NULL
10500 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10501 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10502 where DECL_RTL is NULL or is a pseudo-reg.
10504 Note however that we can only get away with using DECL_INCOMING_RTL as
10505 a backup substitute for DECL_RTL in certain limited cases. In cases
10506 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10507 we can be sure that the parameter was passed using the same type as it is
10508 declared to have within the function, and that its DECL_INCOMING_RTL
10509 points us to a place where a value of that type is passed.
10511 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10512 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10513 because in these cases DECL_INCOMING_RTL points us to a value of some
10514 type which is *different* from the type of the parameter itself. Thus,
10515 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10516 such cases, the debugger would end up (for example) trying to fetch a
10517 `float' from a place which actually contains the first part of a
10518 `double'. That would lead to really incorrect and confusing
10519 output at debug-time.
10521 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10522 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10523 are a couple of exceptions however. On little-endian machines we can
10524 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10525 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10526 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10527 when (on a little-endian machine) a non-prototyped function has a
10528 parameter declared to be of type `short' or `char'. In such cases,
10529 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10530 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10531 passed `int' value. If the debugger then uses that address to fetch
10532 a `short' or a `char' (on a little-endian machine) the result will be
10533 the correct data, so we allow for such exceptional cases below.
10535 Note that our goal here is to describe the place where the given formal
10536 parameter lives during most of the function's activation (i.e. between the
10537 end of the prologue and the start of the epilogue). We'll do that as best
10538 as we can. Note however that if the given formal parameter is modified
10539 sometime during the execution of the function, then a stack backtrace (at
10540 debug-time) will show the function as having been called with the *new*
10541 value rather than the value which was originally passed in. This happens
10542 rarely enough that it is not a major problem, but it *is* a problem, and
10543 I'd like to fix it.
10545 A future version of dwarf2out.c may generate two additional attributes for
10546 any given DW_TAG_formal_parameter DIE which will describe the "passed
10547 type" and the "passed location" for the given formal parameter in addition
10548 to the attributes we now generate to indicate the "declared type" and the
10549 "active location" for each parameter. This additional set of attributes
10550 could be used by debuggers for stack backtraces. Separately, note that
10551 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10552 This happens (for example) for inlined-instances of inline function formal
10553 parameters which are never referenced. This really shouldn't be
10554 happening. All PARM_DECL nodes should get valid non-NULL
10555 DECL_INCOMING_RTL values. FIXME. */
10557 /* Use DECL_RTL as the "location" unless we find something better. */
10558 rtl = DECL_RTL_IF_SET (decl);
10560 /* When generating abstract instances, ignore everything except
10561 constants, symbols living in memory, and symbols living in
10562 fixed registers. */
10563 if (! reload_completed)
10566 && (CONSTANT_P (rtl)
10568 && CONSTANT_P (XEXP (rtl, 0)))
10570 && TREE_CODE (decl) == VAR_DECL
10571 && TREE_STATIC (decl))))
10573 rtl = targetm.delegitimize_address (rtl);
10578 else if (TREE_CODE (decl) == PARM_DECL)
10580 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10582 tree declared_type = TREE_TYPE (decl);
10583 tree passed_type = DECL_ARG_TYPE (decl);
10584 enum machine_mode dmode = TYPE_MODE (declared_type);
10585 enum machine_mode pmode = TYPE_MODE (passed_type);
10587 /* This decl represents a formal parameter which was optimized out.
10588 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10589 all cases where (rtl == NULL_RTX) just below. */
10590 if (dmode == pmode)
10591 rtl = DECL_INCOMING_RTL (decl);
10592 else if (SCALAR_INT_MODE_P (dmode)
10593 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10594 && DECL_INCOMING_RTL (decl))
10596 rtx inc = DECL_INCOMING_RTL (decl);
10599 else if (MEM_P (inc))
10601 if (BYTES_BIG_ENDIAN)
10602 rtl = adjust_address_nv (inc, dmode,
10603 GET_MODE_SIZE (pmode)
10604 - GET_MODE_SIZE (dmode));
10611 /* If the parm was passed in registers, but lives on the stack, then
10612 make a big endian correction if the mode of the type of the
10613 parameter is not the same as the mode of the rtl. */
10614 /* ??? This is the same series of checks that are made in dbxout.c before
10615 we reach the big endian correction code there. It isn't clear if all
10616 of these checks are necessary here, but keeping them all is the safe
10618 else if (MEM_P (rtl)
10619 && XEXP (rtl, 0) != const0_rtx
10620 && ! CONSTANT_P (XEXP (rtl, 0))
10621 /* Not passed in memory. */
10622 && !MEM_P (DECL_INCOMING_RTL (decl))
10623 /* Not passed by invisible reference. */
10624 && (!REG_P (XEXP (rtl, 0))
10625 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10626 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10627 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10628 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10631 /* Big endian correction check. */
10632 && BYTES_BIG_ENDIAN
10633 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10634 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10637 int offset = (UNITS_PER_WORD
10638 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10640 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10641 plus_constant (XEXP (rtl, 0), offset));
10644 else if (TREE_CODE (decl) == VAR_DECL
10647 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10648 && BYTES_BIG_ENDIAN)
10650 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10651 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10653 /* If a variable is declared "register" yet is smaller than
10654 a register, then if we store the variable to memory, it
10655 looks like we're storing a register-sized value, when in
10656 fact we are not. We need to adjust the offset of the
10657 storage location to reflect the actual value's bytes,
10658 else gdb will not be able to display it. */
10660 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10661 plus_constant (XEXP (rtl, 0), rsize-dsize));
10664 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10665 and will have been substituted directly into all expressions that use it.
10666 C does not have such a concept, but C++ and other languages do. */
10667 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10668 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10671 rtl = targetm.delegitimize_address (rtl);
10673 /* If we don't look past the constant pool, we risk emitting a
10674 reference to a constant pool entry that isn't referenced from
10675 code, and thus is not emitted. */
10677 rtl = avoid_constant_pool_reference (rtl);
10682 /* We need to figure out what section we should use as the base for the
10683 address ranges where a given location is valid.
10684 1. If this particular DECL has a section associated with it, use that.
10685 2. If this function has a section associated with it, use that.
10686 3. Otherwise, use the text section.
10687 XXX: If you split a variable across multiple sections, we won't notice. */
10689 static const char *
10690 secname_for_decl (const_tree decl)
10692 const char *secname;
10694 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10696 tree sectree = DECL_SECTION_NAME (decl);
10697 secname = TREE_STRING_POINTER (sectree);
10699 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10701 tree sectree = DECL_SECTION_NAME (current_function_decl);
10702 secname = TREE_STRING_POINTER (sectree);
10704 else if (cfun && in_cold_section_p)
10705 secname = cfun->cold_section_label;
10707 secname = text_section_label;
10712 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10713 data attribute for a variable or a parameter. We generate the
10714 DW_AT_const_value attribute only in those cases where the given variable
10715 or parameter does not have a true "location" either in memory or in a
10716 register. This can happen (for example) when a constant is passed as an
10717 actual argument in a call to an inline function. (It's possible that
10718 these things can crop up in other ways also.) Note that one type of
10719 constant value which can be passed into an inlined function is a constant
10720 pointer. This can happen for example if an actual argument in an inlined
10721 function call evaluates to a compile-time constant address. */
10724 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10725 enum dwarf_attribute attr)
10728 dw_loc_descr_ref descr;
10729 var_loc_list *loc_list;
10730 struct var_loc_node *node;
10731 if (TREE_CODE (decl) == ERROR_MARK)
10734 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10735 || TREE_CODE (decl) == RESULT_DECL);
10737 /* See if we possibly have multiple locations for this variable. */
10738 loc_list = lookup_decl_loc (decl);
10740 /* If it truly has multiple locations, the first and last node will
10742 if (loc_list && loc_list->first != loc_list->last)
10744 const char *endname, *secname;
10745 dw_loc_list_ref list;
10747 enum var_init_status initialized;
10749 /* Now that we know what section we are using for a base,
10750 actually construct the list of locations.
10751 The first location information is what is passed to the
10752 function that creates the location list, and the remaining
10753 locations just get added on to that list.
10754 Note that we only know the start address for a location
10755 (IE location changes), so to build the range, we use
10756 the range [current location start, next location start].
10757 This means we have to special case the last node, and generate
10758 a range of [last location start, end of function label]. */
10760 node = loc_list->first;
10761 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10762 secname = secname_for_decl (decl);
10764 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
10765 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10767 initialized = VAR_INIT_STATUS_INITIALIZED;
10769 list = new_loc_list (loc_descriptor (varloc, initialized),
10770 node->label, node->next->label, secname, 1);
10773 for (; node->next; node = node->next)
10774 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10776 /* The variable has a location between NODE->LABEL and
10777 NODE->NEXT->LABEL. */
10778 enum var_init_status initialized =
10779 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10780 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10781 add_loc_descr_to_loc_list (&list,
10782 loc_descriptor (varloc, initialized),
10783 node->label, node->next->label, secname);
10786 /* If the variable has a location at the last label
10787 it keeps its location until the end of function. */
10788 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10790 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10791 enum var_init_status initialized =
10792 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10794 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10795 if (!current_function_decl)
10796 endname = text_end_label;
10799 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10800 current_function_funcdef_no);
10801 endname = ggc_strdup (label_id);
10803 add_loc_descr_to_loc_list (&list,
10804 loc_descriptor (varloc, initialized),
10805 node->label, endname, secname);
10808 /* Finally, add the location list to the DIE, and we are done. */
10809 add_AT_loc_list (die, attr, list);
10813 /* Try to get some constant RTL for this decl, and use that as the value of
10816 rtl = rtl_for_decl_location (decl);
10817 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10819 add_const_value_attribute (die, rtl);
10823 /* If we have tried to generate the location otherwise, and it
10824 didn't work out (we wouldn't be here if we did), and we have a one entry
10825 location list, try generating a location from that. */
10826 if (loc_list && loc_list->first)
10828 enum var_init_status status;
10829 node = loc_list->first;
10830 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10831 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
10834 add_AT_location_description (die, attr, descr);
10839 /* We couldn't get any rtl, so try directly generating the location
10840 description from the tree. */
10841 descr = loc_descriptor_from_tree (decl);
10844 add_AT_location_description (die, attr, descr);
10847 /* None of that worked, so it must not really have a location;
10848 try adding a constant value attribute from the DECL_INITIAL. */
10849 tree_add_const_value_attribute (die, decl);
10852 /* If we don't have a copy of this variable in memory for some reason (such
10853 as a C++ member constant that doesn't have an out-of-line definition),
10854 we should tell the debugger about the constant value. */
10857 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10859 tree init = DECL_INITIAL (decl);
10860 tree type = TREE_TYPE (decl);
10863 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10868 rtl = rtl_for_decl_init (init, type);
10870 add_const_value_attribute (var_die, rtl);
10873 /* Convert the CFI instructions for the current function into a
10874 location list. This is used for DW_AT_frame_base when we targeting
10875 a dwarf2 consumer that does not support the dwarf3
10876 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10879 static dw_loc_list_ref
10880 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10883 dw_loc_list_ref list, *list_tail;
10885 dw_cfa_location last_cfa, next_cfa;
10886 const char *start_label, *last_label, *section;
10888 fde = &fde_table[fde_table_in_use - 1];
10890 section = secname_for_decl (current_function_decl);
10894 next_cfa.reg = INVALID_REGNUM;
10895 next_cfa.offset = 0;
10896 next_cfa.indirect = 0;
10897 next_cfa.base_offset = 0;
10899 start_label = fde->dw_fde_begin;
10901 /* ??? Bald assumption that the CIE opcode list does not contain
10902 advance opcodes. */
10903 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10904 lookup_cfa_1 (cfi, &next_cfa);
10906 last_cfa = next_cfa;
10907 last_label = start_label;
10909 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10910 switch (cfi->dw_cfi_opc)
10912 case DW_CFA_set_loc:
10913 case DW_CFA_advance_loc1:
10914 case DW_CFA_advance_loc2:
10915 case DW_CFA_advance_loc4:
10916 if (!cfa_equal_p (&last_cfa, &next_cfa))
10918 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10919 start_label, last_label, section,
10922 list_tail = &(*list_tail)->dw_loc_next;
10923 last_cfa = next_cfa;
10924 start_label = last_label;
10926 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10929 case DW_CFA_advance_loc:
10930 /* The encoding is complex enough that we should never emit this. */
10931 case DW_CFA_remember_state:
10932 case DW_CFA_restore_state:
10933 /* We don't handle these two in this function. It would be possible
10934 if it were to be required. */
10935 gcc_unreachable ();
10938 lookup_cfa_1 (cfi, &next_cfa);
10942 if (!cfa_equal_p (&last_cfa, &next_cfa))
10944 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10945 start_label, last_label, section,
10947 list_tail = &(*list_tail)->dw_loc_next;
10948 start_label = last_label;
10950 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
10951 start_label, fde->dw_fde_end, section,
10957 /* Compute a displacement from the "steady-state frame pointer" to the
10958 frame base (often the same as the CFA), and store it in
10959 frame_pointer_fb_offset. OFFSET is added to the displacement
10960 before the latter is negated. */
10963 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
10967 #ifdef FRAME_POINTER_CFA_OFFSET
10968 reg = frame_pointer_rtx;
10969 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
10971 reg = arg_pointer_rtx;
10972 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
10975 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10976 if (GET_CODE (elim) == PLUS)
10978 offset += INTVAL (XEXP (elim, 1));
10979 elim = XEXP (elim, 0);
10981 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10982 : stack_pointer_rtx));
10984 frame_pointer_fb_offset = -offset;
10987 /* Generate a DW_AT_name attribute given some string value to be included as
10988 the value of the attribute. */
10991 add_name_attribute (dw_die_ref die, const char *name_string)
10993 if (name_string != NULL && *name_string != 0)
10995 if (demangle_name_func)
10996 name_string = (*demangle_name_func) (name_string);
10998 add_AT_string (die, DW_AT_name, name_string);
11002 /* Generate a DW_AT_comp_dir attribute for DIE. */
11005 add_comp_dir_attribute (dw_die_ref die)
11007 const char *wd = get_src_pwd ();
11009 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11012 /* Given a tree node describing an array bound (either lower or upper) output
11013 a representation for that bound. */
11016 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11018 switch (TREE_CODE (bound))
11023 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11025 if (! host_integerp (bound, 0)
11026 || (bound_attr == DW_AT_lower_bound
11027 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11028 || (is_fortran () && integer_onep (bound)))))
11029 /* Use the default. */
11032 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11037 case NON_LVALUE_EXPR:
11038 case VIEW_CONVERT_EXPR:
11039 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11049 dw_die_ref decl_die = lookup_decl_die (bound);
11051 /* ??? Can this happen, or should the variable have been bound
11052 first? Probably it can, since I imagine that we try to create
11053 the types of parameters in the order in which they exist in
11054 the list, and won't have created a forward reference to a
11055 later parameter. */
11056 if (decl_die != NULL)
11057 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11063 /* Otherwise try to create a stack operation procedure to
11064 evaluate the value of the array bound. */
11066 dw_die_ref ctx, decl_die;
11067 dw_loc_descr_ref loc;
11069 loc = loc_descriptor_from_tree (bound);
11073 if (current_function_decl == 0)
11074 ctx = comp_unit_die;
11076 ctx = lookup_decl_die (current_function_decl);
11078 decl_die = new_die (DW_TAG_variable, ctx, bound);
11079 add_AT_flag (decl_die, DW_AT_artificial, 1);
11080 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11081 add_AT_loc (decl_die, DW_AT_location, loc);
11083 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11089 /* Note that the block of subscript information for an array type also
11090 includes information about the element type of type given array type. */
11093 add_subscript_info (dw_die_ref type_die, tree type)
11095 #ifndef MIPS_DEBUGGING_INFO
11096 unsigned dimension_number;
11099 dw_die_ref subrange_die;
11101 /* The GNU compilers represent multidimensional array types as sequences of
11102 one dimensional array types whose element types are themselves array
11103 types. Here we squish that down, so that each multidimensional array
11104 type gets only one array_type DIE in the Dwarf debugging info. The draft
11105 Dwarf specification say that we are allowed to do this kind of
11106 compression in C (because there is no difference between an array or
11107 arrays and a multidimensional array in C) but for other source languages
11108 (e.g. Ada) we probably shouldn't do this. */
11110 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11111 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11112 We work around this by disabling this feature. See also
11113 gen_array_type_die. */
11114 #ifndef MIPS_DEBUGGING_INFO
11115 for (dimension_number = 0;
11116 TREE_CODE (type) == ARRAY_TYPE;
11117 type = TREE_TYPE (type), dimension_number++)
11120 tree domain = TYPE_DOMAIN (type);
11122 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11123 and (in GNU C only) variable bounds. Handle all three forms
11125 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11128 /* We have an array type with specified bounds. */
11129 lower = TYPE_MIN_VALUE (domain);
11130 upper = TYPE_MAX_VALUE (domain);
11132 /* Define the index type. */
11133 if (TREE_TYPE (domain))
11135 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11136 TREE_TYPE field. We can't emit debug info for this
11137 because it is an unnamed integral type. */
11138 if (TREE_CODE (domain) == INTEGER_TYPE
11139 && TYPE_NAME (domain) == NULL_TREE
11140 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11141 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11144 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11148 /* ??? If upper is NULL, the array has unspecified length,
11149 but it does have a lower bound. This happens with Fortran
11151 Since the debugger is definitely going to need to know N
11152 to produce useful results, go ahead and output the lower
11153 bound solo, and hope the debugger can cope. */
11155 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11157 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11160 /* Otherwise we have an array type with an unspecified length. The
11161 DWARF-2 spec does not say how to handle this; let's just leave out the
11167 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11171 switch (TREE_CODE (tree_node))
11176 case ENUMERAL_TYPE:
11179 case QUAL_UNION_TYPE:
11180 size = int_size_in_bytes (tree_node);
11183 /* For a data member of a struct or union, the DW_AT_byte_size is
11184 generally given as the number of bytes normally allocated for an
11185 object of the *declared* type of the member itself. This is true
11186 even for bit-fields. */
11187 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11190 gcc_unreachable ();
11193 /* Note that `size' might be -1 when we get to this point. If it is, that
11194 indicates that the byte size of the entity in question is variable. We
11195 have no good way of expressing this fact in Dwarf at the present time,
11196 so just let the -1 pass on through. */
11197 add_AT_unsigned (die, DW_AT_byte_size, size);
11200 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11201 which specifies the distance in bits from the highest order bit of the
11202 "containing object" for the bit-field to the highest order bit of the
11205 For any given bit-field, the "containing object" is a hypothetical object
11206 (of some integral or enum type) within which the given bit-field lives. The
11207 type of this hypothetical "containing object" is always the same as the
11208 declared type of the individual bit-field itself. The determination of the
11209 exact location of the "containing object" for a bit-field is rather
11210 complicated. It's handled by the `field_byte_offset' function (above).
11212 Note that it is the size (in bytes) of the hypothetical "containing object"
11213 which will be given in the DW_AT_byte_size attribute for this bit-field.
11214 (See `byte_size_attribute' above). */
11217 add_bit_offset_attribute (dw_die_ref die, tree decl)
11219 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11220 tree type = DECL_BIT_FIELD_TYPE (decl);
11221 HOST_WIDE_INT bitpos_int;
11222 HOST_WIDE_INT highest_order_object_bit_offset;
11223 HOST_WIDE_INT highest_order_field_bit_offset;
11224 HOST_WIDE_INT unsigned bit_offset;
11226 /* Must be a field and a bit field. */
11227 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11229 /* We can't yet handle bit-fields whose offsets are variable, so if we
11230 encounter such things, just return without generating any attribute
11231 whatsoever. Likewise for variable or too large size. */
11232 if (! host_integerp (bit_position (decl), 0)
11233 || ! host_integerp (DECL_SIZE (decl), 1))
11236 bitpos_int = int_bit_position (decl);
11238 /* Note that the bit offset is always the distance (in bits) from the
11239 highest-order bit of the "containing object" to the highest-order bit of
11240 the bit-field itself. Since the "high-order end" of any object or field
11241 is different on big-endian and little-endian machines, the computation
11242 below must take account of these differences. */
11243 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11244 highest_order_field_bit_offset = bitpos_int;
11246 if (! BYTES_BIG_ENDIAN)
11248 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11249 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11253 = (! BYTES_BIG_ENDIAN
11254 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11255 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11257 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11260 /* For a FIELD_DECL node which represents a bit field, output an attribute
11261 which specifies the length in bits of the given field. */
11264 add_bit_size_attribute (dw_die_ref die, tree decl)
11266 /* Must be a field and a bit field. */
11267 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11268 && DECL_BIT_FIELD_TYPE (decl));
11270 if (host_integerp (DECL_SIZE (decl), 1))
11271 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11274 /* If the compiled language is ANSI C, then add a 'prototyped'
11275 attribute, if arg types are given for the parameters of a function. */
11278 add_prototyped_attribute (dw_die_ref die, tree func_type)
11280 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11281 && TYPE_ARG_TYPES (func_type) != NULL)
11282 add_AT_flag (die, DW_AT_prototyped, 1);
11285 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11286 by looking in either the type declaration or object declaration
11290 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11292 dw_die_ref origin_die = NULL;
11294 if (TREE_CODE (origin) != FUNCTION_DECL)
11296 /* We may have gotten separated from the block for the inlined
11297 function, if we're in an exception handler or some such; make
11298 sure that the abstract function has been written out.
11300 Doing this for nested functions is wrong, however; functions are
11301 distinct units, and our context might not even be inline. */
11305 fn = TYPE_STUB_DECL (fn);
11307 fn = decl_function_context (fn);
11309 dwarf2out_abstract_function (fn);
11312 if (DECL_P (origin))
11313 origin_die = lookup_decl_die (origin);
11314 else if (TYPE_P (origin))
11315 origin_die = lookup_type_die (origin);
11317 /* XXX: Functions that are never lowered don't always have correct block
11318 trees (in the case of java, they simply have no block tree, in some other
11319 languages). For these functions, there is nothing we can really do to
11320 output correct debug info for inlined functions in all cases. Rather
11321 than die, we'll just produce deficient debug info now, in that we will
11322 have variables without a proper abstract origin. In the future, when all
11323 functions are lowered, we should re-add a gcc_assert (origin_die)
11327 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11330 /* We do not currently support the pure_virtual attribute. */
11333 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11335 if (DECL_VINDEX (func_decl))
11337 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11339 if (host_integerp (DECL_VINDEX (func_decl), 0))
11340 add_AT_loc (die, DW_AT_vtable_elem_location,
11341 new_loc_descr (DW_OP_constu,
11342 tree_low_cst (DECL_VINDEX (func_decl), 0),
11345 /* GNU extension: Record what type this method came from originally. */
11346 if (debug_info_level > DINFO_LEVEL_TERSE)
11347 add_AT_die_ref (die, DW_AT_containing_type,
11348 lookup_type_die (DECL_CONTEXT (func_decl)));
11352 /* Add source coordinate attributes for the given decl. */
11355 add_src_coords_attributes (dw_die_ref die, tree decl)
11357 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11359 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11360 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11363 /* Add a DW_AT_name attribute and source coordinate attribute for the
11364 given decl, but only if it actually has a name. */
11367 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11371 decl_name = DECL_NAME (decl);
11372 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11374 add_name_attribute (die, dwarf2_name (decl, 0));
11375 if (! DECL_ARTIFICIAL (decl))
11376 add_src_coords_attributes (die, decl);
11378 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11379 && TREE_PUBLIC (decl)
11380 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11381 && !DECL_ABSTRACT (decl)
11382 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
11384 add_AT_string (die, DW_AT_MIPS_linkage_name,
11385 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11388 #ifdef VMS_DEBUGGING_INFO
11389 /* Get the function's name, as described by its RTL. This may be different
11390 from the DECL_NAME name used in the source file. */
11391 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11393 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11394 XEXP (DECL_RTL (decl), 0));
11395 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11400 /* Push a new declaration scope. */
11403 push_decl_scope (tree scope)
11405 VEC_safe_push (tree, gc, decl_scope_table, scope);
11408 /* Pop a declaration scope. */
11411 pop_decl_scope (void)
11413 VEC_pop (tree, decl_scope_table);
11416 /* Return the DIE for the scope that immediately contains this type.
11417 Non-named types get global scope. Named types nested in other
11418 types get their containing scope if it's open, or global scope
11419 otherwise. All other types (i.e. function-local named types) get
11420 the current active scope. */
11423 scope_die_for (tree t, dw_die_ref context_die)
11425 dw_die_ref scope_die = NULL;
11426 tree containing_scope;
11429 /* Non-types always go in the current scope. */
11430 gcc_assert (TYPE_P (t));
11432 containing_scope = TYPE_CONTEXT (t);
11434 /* Use the containing namespace if it was passed in (for a declaration). */
11435 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11437 if (context_die == lookup_decl_die (containing_scope))
11440 containing_scope = NULL_TREE;
11443 /* Ignore function type "scopes" from the C frontend. They mean that
11444 a tagged type is local to a parmlist of a function declarator, but
11445 that isn't useful to DWARF. */
11446 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11447 containing_scope = NULL_TREE;
11449 if (containing_scope == NULL_TREE)
11450 scope_die = comp_unit_die;
11451 else if (TYPE_P (containing_scope))
11453 /* For types, we can just look up the appropriate DIE. But
11454 first we check to see if we're in the middle of emitting it
11455 so we know where the new DIE should go. */
11456 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11457 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11462 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11463 || TREE_ASM_WRITTEN (containing_scope));
11465 /* If none of the current dies are suitable, we get file scope. */
11466 scope_die = comp_unit_die;
11469 scope_die = lookup_type_die (containing_scope);
11472 scope_die = context_die;
11477 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11480 local_scope_p (dw_die_ref context_die)
11482 for (; context_die; context_die = context_die->die_parent)
11483 if (context_die->die_tag == DW_TAG_inlined_subroutine
11484 || context_die->die_tag == DW_TAG_subprogram)
11490 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11491 whether or not to treat a DIE in this context as a declaration. */
11494 class_or_namespace_scope_p (dw_die_ref context_die)
11496 return (context_die
11497 && (context_die->die_tag == DW_TAG_structure_type
11498 || context_die->die_tag == DW_TAG_class_type
11499 || context_die->die_tag == DW_TAG_interface_type
11500 || context_die->die_tag == DW_TAG_union_type
11501 || context_die->die_tag == DW_TAG_namespace));
11504 /* Many forms of DIEs require a "type description" attribute. This
11505 routine locates the proper "type descriptor" die for the type given
11506 by 'type', and adds a DW_AT_type attribute below the given die. */
11509 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11510 int decl_volatile, dw_die_ref context_die)
11512 enum tree_code code = TREE_CODE (type);
11513 dw_die_ref type_die = NULL;
11515 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11516 or fixed-point type, use the inner type. This is because we have no
11517 support for unnamed types in base_type_die. This can happen if this is
11518 an Ada subrange type. Correct solution is emit a subrange type die. */
11519 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
11520 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11521 type = TREE_TYPE (type), code = TREE_CODE (type);
11523 if (code == ERROR_MARK
11524 /* Handle a special case. For functions whose return type is void, we
11525 generate *no* type attribute. (Note that no object may have type
11526 `void', so this only applies to function return types). */
11527 || code == VOID_TYPE)
11530 type_die = modified_type_die (type,
11531 decl_const || TYPE_READONLY (type),
11532 decl_volatile || TYPE_VOLATILE (type),
11535 if (type_die != NULL)
11536 add_AT_die_ref (object_die, DW_AT_type, type_die);
11539 /* Given an object die, add the calling convention attribute for the
11540 function call type. */
11542 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
11544 enum dwarf_calling_convention value = DW_CC_normal;
11546 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
11548 /* DWARF doesn't provide a way to identify a program's source-level
11549 entry point. DW_AT_calling_convention attributes are only meant
11550 to describe functions' calling conventions. However, lacking a
11551 better way to signal the Fortran main program, we use this for the
11552 time being, following existing custom. */
11554 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
11555 value = DW_CC_program;
11557 /* Only add the attribute if the backend requests it, and
11558 is not DW_CC_normal. */
11559 if (value && (value != DW_CC_normal))
11560 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11563 /* Given a tree pointer to a struct, class, union, or enum type node, return
11564 a pointer to the (string) tag name for the given type, or zero if the type
11565 was declared without a tag. */
11567 static const char *
11568 type_tag (const_tree type)
11570 const char *name = 0;
11572 if (TYPE_NAME (type) != 0)
11576 /* Find the IDENTIFIER_NODE for the type name. */
11577 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11578 t = TYPE_NAME (type);
11580 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11581 a TYPE_DECL node, regardless of whether or not a `typedef' was
11583 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11584 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11586 /* We want to be extra verbose. Don't call dwarf_name if
11587 DECL_NAME isn't set. The default hook for decl_printable_name
11588 doesn't like that, and in this context it's correct to return
11589 0, instead of "<anonymous>" or the like. */
11590 if (DECL_NAME (TYPE_NAME (type)))
11591 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11594 /* Now get the name as a string, or invent one. */
11595 if (!name && t != 0)
11596 name = IDENTIFIER_POINTER (t);
11599 return (name == 0 || *name == '\0') ? 0 : name;
11602 /* Return the type associated with a data member, make a special check
11603 for bit field types. */
11606 member_declared_type (const_tree member)
11608 return (DECL_BIT_FIELD_TYPE (member)
11609 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11612 /* Get the decl's label, as described by its RTL. This may be different
11613 from the DECL_NAME name used in the source file. */
11616 static const char *
11617 decl_start_label (tree decl)
11620 const char *fnname;
11622 x = DECL_RTL (decl);
11623 gcc_assert (MEM_P (x));
11626 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11628 fnname = XSTR (x, 0);
11633 /* These routines generate the internal representation of the DIE's for
11634 the compilation unit. Debugging information is collected by walking
11635 the declaration trees passed in from dwarf2out_decl(). */
11638 gen_array_type_die (tree type, dw_die_ref context_die)
11640 dw_die_ref scope_die = scope_die_for (type, context_die);
11641 dw_die_ref array_die;
11644 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11645 the inner array type comes before the outer array type. Thus we must
11646 call gen_type_die before we call new_die. See below also. */
11647 #ifdef MIPS_DEBUGGING_INFO
11648 gen_type_die (TREE_TYPE (type), context_die);
11651 array_die = new_die (DW_TAG_array_type, scope_die, type);
11652 add_name_attribute (array_die, type_tag (type));
11653 equate_type_number_to_die (type, array_die);
11655 if (TREE_CODE (type) == VECTOR_TYPE)
11657 /* The frontend feeds us a representation for the vector as a struct
11658 containing an array. Pull out the array type. */
11659 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11660 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11663 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11665 && TREE_CODE (type) == ARRAY_TYPE
11666 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
11667 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11670 /* We default the array ordering. SDB will probably do
11671 the right things even if DW_AT_ordering is not present. It's not even
11672 an issue until we start to get into multidimensional arrays anyway. If
11673 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11674 then we'll have to put the DW_AT_ordering attribute back in. (But if
11675 and when we find out that we need to put these in, we will only do so
11676 for multidimensional arrays. */
11677 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11680 #ifdef MIPS_DEBUGGING_INFO
11681 /* The SGI compilers handle arrays of unknown bound by setting
11682 AT_declaration and not emitting any subrange DIEs. */
11683 if (! TYPE_DOMAIN (type))
11684 add_AT_flag (array_die, DW_AT_declaration, 1);
11687 add_subscript_info (array_die, type);
11689 /* Add representation of the type of the elements of this array type. */
11690 element_type = TREE_TYPE (type);
11692 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11693 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11694 We work around this by disabling this feature. See also
11695 add_subscript_info. */
11696 #ifndef MIPS_DEBUGGING_INFO
11697 while (TREE_CODE (element_type) == ARRAY_TYPE)
11698 element_type = TREE_TYPE (element_type);
11700 gen_type_die (element_type, context_die);
11703 add_type_attribute (array_die, element_type, 0, 0, context_die);
11705 if (get_AT (array_die, DW_AT_name))
11706 add_pubtype (type, array_die);
11709 static dw_loc_descr_ref
11710 descr_info_loc (tree val, tree base_decl)
11712 HOST_WIDE_INT size;
11713 dw_loc_descr_ref loc, loc2;
11714 enum dwarf_location_atom op;
11716 if (val == base_decl)
11717 return new_loc_descr (DW_OP_push_object_address, 0, 0);
11719 switch (TREE_CODE (val))
11723 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11725 if (host_integerp (val, 0))
11726 return int_loc_descriptor (tree_low_cst (val, 0));
11729 size = int_size_in_bytes (TREE_TYPE (val));
11732 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11735 if (size == DWARF2_ADDR_SIZE)
11736 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
11738 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
11740 case POINTER_PLUS_EXPR:
11742 if (host_integerp (TREE_OPERAND (val, 1), 1)
11743 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
11746 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11749 add_loc_descr (&loc,
11750 new_loc_descr (DW_OP_plus_uconst,
11751 tree_low_cst (TREE_OPERAND (val, 1),
11758 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11761 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
11764 add_loc_descr (&loc, loc2);
11765 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
11787 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
11788 tree val, tree base_decl)
11790 dw_loc_descr_ref loc;
11792 if (host_integerp (val, 0))
11794 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
11798 loc = descr_info_loc (val, base_decl);
11802 add_AT_loc (die, attr, loc);
11805 /* This routine generates DIE for array with hidden descriptor, details
11806 are filled into *info by a langhook. */
11809 gen_descr_array_type_die (tree type, struct array_descr_info *info,
11810 dw_die_ref context_die)
11812 dw_die_ref scope_die = scope_die_for (type, context_die);
11813 dw_die_ref array_die;
11816 array_die = new_die (DW_TAG_array_type, scope_die, type);
11817 add_name_attribute (array_die, type_tag (type));
11818 equate_type_number_to_die (type, array_die);
11820 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11822 && info->ndimensions >= 2)
11823 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11825 if (info->data_location)
11826 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
11828 if (info->associated)
11829 add_descr_info_field (array_die, DW_AT_associated, info->associated,
11831 if (info->allocated)
11832 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
11835 for (dim = 0; dim < info->ndimensions; dim++)
11837 dw_die_ref subrange_die
11838 = new_die (DW_TAG_subrange_type, array_die, NULL);
11840 if (info->dimen[dim].lower_bound)
11842 /* If it is the default value, omit it. */
11843 if ((is_c_family () || is_java ())
11844 && integer_zerop (info->dimen[dim].lower_bound))
11846 else if (is_fortran ()
11847 && integer_onep (info->dimen[dim].lower_bound))
11850 add_descr_info_field (subrange_die, DW_AT_lower_bound,
11851 info->dimen[dim].lower_bound,
11854 if (info->dimen[dim].upper_bound)
11855 add_descr_info_field (subrange_die, DW_AT_upper_bound,
11856 info->dimen[dim].upper_bound,
11858 if (info->dimen[dim].stride)
11859 add_descr_info_field (subrange_die, DW_AT_byte_stride,
11860 info->dimen[dim].stride,
11864 gen_type_die (info->element_type, context_die);
11865 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
11867 if (get_AT (array_die, DW_AT_name))
11868 add_pubtype (type, array_die);
11873 gen_entry_point_die (tree decl, dw_die_ref context_die)
11875 tree origin = decl_ultimate_origin (decl);
11876 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11878 if (origin != NULL)
11879 add_abstract_origin_attribute (decl_die, origin);
11882 add_name_and_src_coords_attributes (decl_die, decl);
11883 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11884 0, 0, context_die);
11887 if (DECL_ABSTRACT (decl))
11888 equate_decl_number_to_die (decl, decl_die);
11890 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11894 /* Walk through the list of incomplete types again, trying once more to
11895 emit full debugging info for them. */
11898 retry_incomplete_types (void)
11902 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11903 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11906 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11909 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11911 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11913 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11914 be incomplete and such types are not marked. */
11915 add_abstract_origin_attribute (type_die, type);
11918 /* Determine what tag to use for a record type. */
11920 static enum dwarf_tag
11921 record_type_tag (tree type)
11923 if (! lang_hooks.types.classify_record)
11924 return DW_TAG_structure_type;
11926 switch (lang_hooks.types.classify_record (type))
11928 case RECORD_IS_STRUCT:
11929 return DW_TAG_structure_type;
11931 case RECORD_IS_CLASS:
11932 return DW_TAG_class_type;
11934 case RECORD_IS_INTERFACE:
11935 return DW_TAG_interface_type;
11938 gcc_unreachable ();
11942 /* Generate a DIE to represent an inlined instance of a structure type. */
11945 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11947 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
11949 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11950 be incomplete and such types are not marked. */
11951 add_abstract_origin_attribute (type_die, type);
11954 /* Generate a DIE to represent an inlined instance of a union type. */
11957 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11959 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11961 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11962 be incomplete and such types are not marked. */
11963 add_abstract_origin_attribute (type_die, type);
11966 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11967 include all of the information about the enumeration values also. Each
11968 enumerated type name/value is listed as a child of the enumerated type
11972 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11974 dw_die_ref type_die = lookup_type_die (type);
11976 if (type_die == NULL)
11978 type_die = new_die (DW_TAG_enumeration_type,
11979 scope_die_for (type, context_die), type);
11980 equate_type_number_to_die (type, type_die);
11981 add_name_attribute (type_die, type_tag (type));
11983 else if (! TYPE_SIZE (type))
11986 remove_AT (type_die, DW_AT_declaration);
11988 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11989 given enum type is incomplete, do not generate the DW_AT_byte_size
11990 attribute or the DW_AT_element_list attribute. */
11991 if (TYPE_SIZE (type))
11995 TREE_ASM_WRITTEN (type) = 1;
11996 add_byte_size_attribute (type_die, type);
11997 if (TYPE_STUB_DECL (type) != NULL_TREE)
11998 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12000 /* If the first reference to this type was as the return type of an
12001 inline function, then it may not have a parent. Fix this now. */
12002 if (type_die->die_parent == NULL)
12003 add_child_die (scope_die_for (type, context_die), type_die);
12005 for (link = TYPE_VALUES (type);
12006 link != NULL; link = TREE_CHAIN (link))
12008 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12009 tree value = TREE_VALUE (link);
12011 add_name_attribute (enum_die,
12012 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12014 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12015 /* DWARF2 does not provide a way of indicating whether or
12016 not enumeration constants are signed or unsigned. GDB
12017 always assumes the values are signed, so we output all
12018 values as if they were signed. That means that
12019 enumeration constants with very large unsigned values
12020 will appear to have negative values in the debugger. */
12021 add_AT_int (enum_die, DW_AT_const_value,
12022 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12026 add_AT_flag (type_die, DW_AT_declaration, 1);
12028 if (get_AT (type_die, DW_AT_name))
12029 add_pubtype (type, type_die);
12034 /* Generate a DIE to represent either a real live formal parameter decl or to
12035 represent just the type of some formal parameter position in some function
12038 Note that this routine is a bit unusual because its argument may be a
12039 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12040 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12041 node. If it's the former then this function is being called to output a
12042 DIE to represent a formal parameter object (or some inlining thereof). If
12043 it's the latter, then this function is only being called to output a
12044 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12045 argument type of some subprogram type. */
12048 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12050 dw_die_ref parm_die
12051 = new_die (DW_TAG_formal_parameter, context_die, node);
12054 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12056 case tcc_declaration:
12057 origin = decl_ultimate_origin (node);
12058 if (origin != NULL)
12059 add_abstract_origin_attribute (parm_die, origin);
12062 tree type = TREE_TYPE (node);
12063 add_name_and_src_coords_attributes (parm_die, node);
12064 if (DECL_BY_REFERENCE (node))
12065 type = TREE_TYPE (type);
12066 add_type_attribute (parm_die, type,
12067 TREE_READONLY (node),
12068 TREE_THIS_VOLATILE (node),
12070 if (DECL_ARTIFICIAL (node))
12071 add_AT_flag (parm_die, DW_AT_artificial, 1);
12074 equate_decl_number_to_die (node, parm_die);
12075 if (! DECL_ABSTRACT (node))
12076 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12081 /* We were called with some kind of a ..._TYPE node. */
12082 add_type_attribute (parm_die, node, 0, 0, context_die);
12086 gcc_unreachable ();
12092 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12093 at the end of an (ANSI prototyped) formal parameters list. */
12096 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12098 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12101 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12102 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12103 parameters as specified in some function type specification (except for
12104 those which appear as part of a function *definition*). */
12107 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12110 tree formal_type = NULL;
12111 tree first_parm_type;
12114 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12116 arg = DECL_ARGUMENTS (function_or_method_type);
12117 function_or_method_type = TREE_TYPE (function_or_method_type);
12122 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
12124 /* Make our first pass over the list of formal parameter types and output a
12125 DW_TAG_formal_parameter DIE for each one. */
12126 for (link = first_parm_type; link; )
12128 dw_die_ref parm_die;
12130 formal_type = TREE_VALUE (link);
12131 if (formal_type == void_type_node)
12134 /* Output a (nameless) DIE to represent the formal parameter itself. */
12135 parm_die = gen_formal_parameter_die (formal_type, context_die);
12136 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
12137 && link == first_parm_type)
12138 || (arg && DECL_ARTIFICIAL (arg)))
12139 add_AT_flag (parm_die, DW_AT_artificial, 1);
12141 link = TREE_CHAIN (link);
12143 arg = TREE_CHAIN (arg);
12146 /* If this function type has an ellipsis, add a
12147 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12148 if (formal_type != void_type_node)
12149 gen_unspecified_parameters_die (function_or_method_type, context_die);
12151 /* Make our second (and final) pass over the list of formal parameter types
12152 and output DIEs to represent those types (as necessary). */
12153 for (link = TYPE_ARG_TYPES (function_or_method_type);
12154 link && TREE_VALUE (link);
12155 link = TREE_CHAIN (link))
12156 gen_type_die (TREE_VALUE (link), context_die);
12159 /* We want to generate the DIE for TYPE so that we can generate the
12160 die for MEMBER, which has been defined; we will need to refer back
12161 to the member declaration nested within TYPE. If we're trying to
12162 generate minimal debug info for TYPE, processing TYPE won't do the
12163 trick; we need to attach the member declaration by hand. */
12166 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
12168 gen_type_die (type, context_die);
12170 /* If we're trying to avoid duplicate debug info, we may not have
12171 emitted the member decl for this function. Emit it now. */
12172 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
12173 && ! lookup_decl_die (member))
12175 dw_die_ref type_die;
12176 gcc_assert (!decl_ultimate_origin (member));
12178 push_decl_scope (type);
12179 type_die = lookup_type_die (type);
12180 if (TREE_CODE (member) == FUNCTION_DECL)
12181 gen_subprogram_die (member, type_die);
12182 else if (TREE_CODE (member) == FIELD_DECL)
12184 /* Ignore the nameless fields that are used to skip bits but handle
12185 C++ anonymous unions and structs. */
12186 if (DECL_NAME (member) != NULL_TREE
12187 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
12188 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
12190 gen_type_die (member_declared_type (member), type_die);
12191 gen_field_die (member, type_die);
12195 gen_variable_die (member, type_die);
12201 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12202 may later generate inlined and/or out-of-line instances of. */
12205 dwarf2out_abstract_function (tree decl)
12207 dw_die_ref old_die;
12210 int was_abstract = DECL_ABSTRACT (decl);
12212 /* Make sure we have the actual abstract inline, not a clone. */
12213 decl = DECL_ORIGIN (decl);
12215 old_die = lookup_decl_die (decl);
12216 if (old_die && get_AT (old_die, DW_AT_inline))
12217 /* We've already generated the abstract instance. */
12220 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12221 we don't get confused by DECL_ABSTRACT. */
12222 if (debug_info_level > DINFO_LEVEL_TERSE)
12224 context = decl_class_context (decl);
12226 gen_type_die_for_member
12227 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
12230 /* Pretend we've just finished compiling this function. */
12231 save_fn = current_function_decl;
12232 current_function_decl = decl;
12233 push_cfun (DECL_STRUCT_FUNCTION (decl));
12235 set_decl_abstract_flags (decl, 1);
12236 dwarf2out_decl (decl);
12237 if (! was_abstract)
12238 set_decl_abstract_flags (decl, 0);
12240 current_function_decl = save_fn;
12244 /* Helper function of premark_used_types() which gets called through
12245 htab_traverse_resize().
12247 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12248 marked as unused by prune_unused_types. */
12250 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
12256 die = lookup_type_die (type);
12258 die->die_perennial_p = 1;
12262 /* Mark all members of used_types_hash as perennial. */
12264 premark_used_types (void)
12266 if (cfun && cfun->used_types_hash)
12267 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
12270 /* Generate a DIE to represent a declared function (either file-scope or
12274 gen_subprogram_die (tree decl, dw_die_ref context_die)
12276 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12277 tree origin = decl_ultimate_origin (decl);
12278 dw_die_ref subr_die;
12281 dw_die_ref old_die = lookup_decl_die (decl);
12282 int declaration = (current_function_decl != decl
12283 || class_or_namespace_scope_p (context_die));
12285 premark_used_types ();
12287 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12288 started to generate the abstract instance of an inline, decided to output
12289 its containing class, and proceeded to emit the declaration of the inline
12290 from the member list for the class. If so, DECLARATION takes priority;
12291 we'll get back to the abstract instance when done with the class. */
12293 /* The class-scope declaration DIE must be the primary DIE. */
12294 if (origin && declaration && class_or_namespace_scope_p (context_die))
12297 gcc_assert (!old_die);
12300 /* Now that the C++ front end lazily declares artificial member fns, we
12301 might need to retrofit the declaration into its class. */
12302 if (!declaration && !origin && !old_die
12303 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
12304 && !class_or_namespace_scope_p (context_die)
12305 && debug_info_level > DINFO_LEVEL_TERSE)
12306 old_die = force_decl_die (decl);
12308 if (origin != NULL)
12310 gcc_assert (!declaration || local_scope_p (context_die));
12312 /* Fixup die_parent for the abstract instance of a nested
12313 inline function. */
12314 if (old_die && old_die->die_parent == NULL)
12315 add_child_die (context_die, old_die);
12317 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12318 add_abstract_origin_attribute (subr_die, origin);
12322 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12323 struct dwarf_file_data * file_index = lookup_filename (s.file);
12325 if (!get_AT_flag (old_die, DW_AT_declaration)
12326 /* We can have a normal definition following an inline one in the
12327 case of redefinition of GNU C extern inlines.
12328 It seems reasonable to use AT_specification in this case. */
12329 && !get_AT (old_die, DW_AT_inline))
12331 /* Detect and ignore this case, where we are trying to output
12332 something we have already output. */
12336 /* If the definition comes from the same place as the declaration,
12337 maybe use the old DIE. We always want the DIE for this function
12338 that has the *_pc attributes to be under comp_unit_die so the
12339 debugger can find it. We also need to do this for abstract
12340 instances of inlines, since the spec requires the out-of-line copy
12341 to have the same parent. For local class methods, this doesn't
12342 apply; we just use the old DIE. */
12343 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12344 && (DECL_ARTIFICIAL (decl)
12345 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12346 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12347 == (unsigned) s.line))))
12349 subr_die = old_die;
12351 /* Clear out the declaration attribute and the formal parameters.
12352 Do not remove all children, because it is possible that this
12353 declaration die was forced using force_decl_die(). In such
12354 cases die that forced declaration die (e.g. TAG_imported_module)
12355 is one of the children that we do not want to remove. */
12356 remove_AT (subr_die, DW_AT_declaration);
12357 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12361 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12362 add_AT_specification (subr_die, old_die);
12363 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12364 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12365 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12366 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12371 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12373 if (TREE_PUBLIC (decl))
12374 add_AT_flag (subr_die, DW_AT_external, 1);
12376 add_name_and_src_coords_attributes (subr_die, decl);
12377 if (debug_info_level > DINFO_LEVEL_TERSE)
12379 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12380 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12381 0, 0, context_die);
12384 add_pure_or_virtual_attribute (subr_die, decl);
12385 if (DECL_ARTIFICIAL (decl))
12386 add_AT_flag (subr_die, DW_AT_artificial, 1);
12388 if (TREE_PROTECTED (decl))
12389 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12390 else if (TREE_PRIVATE (decl))
12391 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12396 if (!old_die || !get_AT (old_die, DW_AT_inline))
12398 add_AT_flag (subr_die, DW_AT_declaration, 1);
12400 /* The first time we see a member function, it is in the context of
12401 the class to which it belongs. We make sure of this by emitting
12402 the class first. The next time is the definition, which is
12403 handled above. The two may come from the same source text.
12405 Note that force_decl_die() forces function declaration die. It is
12406 later reused to represent definition. */
12407 equate_decl_number_to_die (decl, subr_die);
12410 else if (DECL_ABSTRACT (decl))
12412 if (DECL_DECLARED_INLINE_P (decl))
12414 if (cgraph_function_possibly_inlined_p (decl))
12415 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12417 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12421 if (cgraph_function_possibly_inlined_p (decl))
12422 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12424 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12427 if (DECL_DECLARED_INLINE_P (decl)
12428 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
12429 add_AT_flag (subr_die, DW_AT_artificial, 1);
12431 equate_decl_number_to_die (decl, subr_die);
12433 else if (!DECL_EXTERNAL (decl))
12435 HOST_WIDE_INT cfa_fb_offset;
12437 if (!old_die || !get_AT (old_die, DW_AT_inline))
12438 equate_decl_number_to_die (decl, subr_die);
12440 if (!flag_reorder_blocks_and_partition)
12442 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
12443 current_function_funcdef_no);
12444 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
12445 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12446 current_function_funcdef_no);
12447 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
12449 add_pubname (decl, subr_die);
12450 add_arange (decl, subr_die);
12453 { /* Do nothing for now; maybe need to duplicate die, one for
12454 hot section and ond for cold section, then use the hot/cold
12455 section begin/end labels to generate the aranges... */
12457 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12458 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12459 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12460 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12462 add_pubname (decl, subr_die);
12463 add_arange (decl, subr_die);
12464 add_arange (decl, subr_die);
12468 #ifdef MIPS_DEBUGGING_INFO
12469 /* Add a reference to the FDE for this routine. */
12470 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
12473 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
12475 /* We define the "frame base" as the function's CFA. This is more
12476 convenient for several reasons: (1) It's stable across the prologue
12477 and epilogue, which makes it better than just a frame pointer,
12478 (2) With dwarf3, there exists a one-byte encoding that allows us
12479 to reference the .debug_frame data by proxy, but failing that,
12480 (3) We can at least reuse the code inspection and interpretation
12481 code that determines the CFA position at various points in the
12483 /* ??? Use some command-line or configury switch to enable the use
12484 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12485 consumers that understand it; fall back to "pure" dwarf2 and
12486 convert the CFA data into a location list. */
12488 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
12489 if (list->dw_loc_next)
12490 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12492 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12495 /* Compute a displacement from the "steady-state frame pointer" to
12496 the CFA. The former is what all stack slots and argument slots
12497 will reference in the rtl; the later is what we've told the
12498 debugger about. We'll need to adjust all frame_base references
12499 by this displacement. */
12500 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12502 if (cfun->static_chain_decl)
12503 add_AT_location_description (subr_die, DW_AT_static_link,
12504 loc_descriptor_from_tree (cfun->static_chain_decl));
12507 /* Now output descriptions of the arguments for this function. This gets
12508 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12509 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12510 `...' at the end of the formal parameter list. In order to find out if
12511 there was a trailing ellipsis or not, we must instead look at the type
12512 associated with the FUNCTION_DECL. This will be a node of type
12513 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12514 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12515 an ellipsis at the end. */
12517 /* In the case where we are describing a mere function declaration, all we
12518 need to do here (and all we *can* do here) is to describe the *types* of
12519 its formal parameters. */
12520 if (debug_info_level <= DINFO_LEVEL_TERSE)
12522 else if (declaration)
12523 gen_formal_types_die (decl, subr_die);
12526 /* Generate DIEs to represent all known formal parameters. */
12527 tree arg_decls = DECL_ARGUMENTS (decl);
12530 /* When generating DIEs, generate the unspecified_parameters DIE
12531 instead if we come across the arg "__builtin_va_alist" */
12532 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12533 if (TREE_CODE (parm) == PARM_DECL)
12535 if (DECL_NAME (parm)
12536 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12537 "__builtin_va_alist"))
12538 gen_unspecified_parameters_die (parm, subr_die);
12540 gen_decl_die (parm, subr_die);
12543 /* Decide whether we need an unspecified_parameters DIE at the end.
12544 There are 2 more cases to do this for: 1) the ansi ... declaration -
12545 this is detectable when the end of the arg list is not a
12546 void_type_node 2) an unprototyped function declaration (not a
12547 definition). This just means that we have no info about the
12548 parameters at all. */
12549 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12550 if (fn_arg_types != NULL)
12552 /* This is the prototyped case, check for.... */
12553 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12554 gen_unspecified_parameters_die (decl, subr_die);
12556 else if (DECL_INITIAL (decl) == NULL_TREE)
12557 gen_unspecified_parameters_die (decl, subr_die);
12560 /* Output Dwarf info for all of the stuff within the body of the function
12561 (if it has one - it may be just a declaration). */
12562 outer_scope = DECL_INITIAL (decl);
12564 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12565 a function. This BLOCK actually represents the outermost binding contour
12566 for the function, i.e. the contour in which the function's formal
12567 parameters and labels get declared. Curiously, it appears that the front
12568 end doesn't actually put the PARM_DECL nodes for the current function onto
12569 the BLOCK_VARS list for this outer scope, but are strung off of the
12570 DECL_ARGUMENTS list for the function instead.
12572 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12573 the LABEL_DECL nodes for the function however, and we output DWARF info
12574 for those in decls_for_scope. Just within the `outer_scope' there will be
12575 a BLOCK node representing the function's outermost pair of curly braces,
12576 and any blocks used for the base and member initializers of a C++
12577 constructor function. */
12578 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12580 /* Emit a DW_TAG_variable DIE for a named return value. */
12581 if (DECL_NAME (DECL_RESULT (decl)))
12582 gen_decl_die (DECL_RESULT (decl), subr_die);
12584 current_function_has_inlines = 0;
12585 decls_for_scope (outer_scope, subr_die, 0);
12587 #if 0 && defined (MIPS_DEBUGGING_INFO)
12588 if (current_function_has_inlines)
12590 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12591 if (! comp_unit_has_inlines)
12593 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12594 comp_unit_has_inlines = 1;
12599 /* Add the calling convention attribute if requested. */
12600 add_calling_convention_attribute (subr_die, decl);
12604 /* Generate a DIE to represent a declared data object. */
12607 gen_variable_die (tree decl, dw_die_ref context_die)
12609 tree origin = decl_ultimate_origin (decl);
12610 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
12612 dw_die_ref old_die = lookup_decl_die (decl);
12613 int declaration = (DECL_EXTERNAL (decl)
12614 /* If DECL is COMDAT and has not actually been
12615 emitted, we cannot take its address; there
12616 might end up being no definition anywhere in
12617 the program. For example, consider the C++
12621 struct S { static const int i = 7; };
12626 int f() { return S<int>::i; }
12628 Here, S<int>::i is not DECL_EXTERNAL, but no
12629 definition is required, so the compiler will
12630 not emit a definition. */
12631 || (TREE_CODE (decl) == VAR_DECL
12632 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12633 || class_or_namespace_scope_p (context_die));
12635 if (origin != NULL)
12636 add_abstract_origin_attribute (var_die, origin);
12638 /* Loop unrolling can create multiple blocks that refer to the same
12639 static variable, so we must test for the DW_AT_declaration flag.
12641 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12642 copy decls and set the DECL_ABSTRACT flag on them instead of
12645 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12647 ??? The declare_in_namespace support causes us to get two DIEs for one
12648 variable, both of which are declarations. We want to avoid considering
12649 one to be a specification, so we must test that this DIE is not a
12651 else if (old_die && TREE_STATIC (decl) && ! declaration
12652 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12654 /* This is a definition of a C++ class level static. */
12655 add_AT_specification (var_die, old_die);
12656 if (DECL_NAME (decl))
12658 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12659 struct dwarf_file_data * file_index = lookup_filename (s.file);
12661 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12662 add_AT_file (var_die, DW_AT_decl_file, file_index);
12664 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12665 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12670 tree type = TREE_TYPE (decl);
12671 if ((TREE_CODE (decl) == PARM_DECL
12672 || TREE_CODE (decl) == RESULT_DECL)
12673 && DECL_BY_REFERENCE (decl))
12674 type = TREE_TYPE (type);
12676 add_name_and_src_coords_attributes (var_die, decl);
12677 add_type_attribute (var_die, type, TREE_READONLY (decl),
12678 TREE_THIS_VOLATILE (decl), context_die);
12680 if (TREE_PUBLIC (decl))
12681 add_AT_flag (var_die, DW_AT_external, 1);
12683 if (DECL_ARTIFICIAL (decl))
12684 add_AT_flag (var_die, DW_AT_artificial, 1);
12686 if (TREE_PROTECTED (decl))
12687 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12688 else if (TREE_PRIVATE (decl))
12689 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12693 add_AT_flag (var_die, DW_AT_declaration, 1);
12695 if (DECL_ABSTRACT (decl) || declaration)
12696 equate_decl_number_to_die (decl, var_die);
12698 if (! declaration && ! DECL_ABSTRACT (decl))
12700 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12701 add_pubname (decl, var_die);
12704 tree_add_const_value_attribute (var_die, decl);
12707 /* Generate a DIE to represent a label identifier. */
12710 gen_label_die (tree decl, dw_die_ref context_die)
12712 tree origin = decl_ultimate_origin (decl);
12713 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12715 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12717 if (origin != NULL)
12718 add_abstract_origin_attribute (lbl_die, origin);
12720 add_name_and_src_coords_attributes (lbl_die, decl);
12722 if (DECL_ABSTRACT (decl))
12723 equate_decl_number_to_die (decl, lbl_die);
12726 insn = DECL_RTL_IF_SET (decl);
12728 /* Deleted labels are programmer specified labels which have been
12729 eliminated because of various optimizations. We still emit them
12730 here so that it is possible to put breakpoints on them. */
12734 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12736 /* When optimization is enabled (via -O) some parts of the compiler
12737 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12738 represent source-level labels which were explicitly declared by
12739 the user. This really shouldn't be happening though, so catch
12740 it if it ever does happen. */
12741 gcc_assert (!INSN_DELETED_P (insn));
12743 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12744 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12749 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12750 attributes to the DIE for a block STMT, to describe where the inlined
12751 function was called from. This is similar to add_src_coords_attributes. */
12754 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12756 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12758 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12759 add_AT_unsigned (die, DW_AT_call_line, s.line);
12763 /* If STMT's abstract origin is a function declaration and STMT's
12764 first subblock's abstract origin is the function's outermost block,
12765 then we're looking at the main entry point. */
12767 is_inlined_entry_point (const_tree stmt)
12771 if (!stmt || TREE_CODE (stmt) != BLOCK)
12774 decl = block_ultimate_origin (stmt);
12776 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12779 block = BLOCK_SUBBLOCKS (stmt);
12783 if (TREE_CODE (block) != BLOCK)
12786 block = block_ultimate_origin (block);
12789 return block == DECL_INITIAL (decl);
12792 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12793 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12796 add_high_low_attributes (tree stmt, dw_die_ref die)
12798 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12800 if (BLOCK_FRAGMENT_CHAIN (stmt))
12804 if (is_inlined_entry_point (stmt))
12806 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12807 BLOCK_NUMBER (stmt));
12808 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12811 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12813 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12816 add_ranges (chain);
12817 chain = BLOCK_FRAGMENT_CHAIN (chain);
12824 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12825 BLOCK_NUMBER (stmt));
12826 add_AT_lbl_id (die, DW_AT_low_pc, label);
12827 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12828 BLOCK_NUMBER (stmt));
12829 add_AT_lbl_id (die, DW_AT_high_pc, label);
12833 /* Generate a DIE for a lexical block. */
12836 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12838 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12840 if (! BLOCK_ABSTRACT (stmt))
12841 add_high_low_attributes (stmt, stmt_die);
12843 decls_for_scope (stmt, stmt_die, depth);
12846 /* Generate a DIE for an inlined subprogram. */
12849 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12851 tree decl = block_ultimate_origin (stmt);
12853 /* Emit info for the abstract instance first, if we haven't yet. We
12854 must emit this even if the block is abstract, otherwise when we
12855 emit the block below (or elsewhere), we may end up trying to emit
12856 a die whose origin die hasn't been emitted, and crashing. */
12857 dwarf2out_abstract_function (decl);
12859 if (! BLOCK_ABSTRACT (stmt))
12861 dw_die_ref subr_die
12862 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12864 add_abstract_origin_attribute (subr_die, decl);
12865 add_high_low_attributes (stmt, subr_die);
12866 add_call_src_coords_attributes (stmt, subr_die);
12868 decls_for_scope (stmt, subr_die, depth);
12869 current_function_has_inlines = 1;
12872 /* We may get here if we're the outer block of function A that was
12873 inlined into function B that was inlined into function C. When
12874 generating debugging info for C, dwarf2out_abstract_function(B)
12875 would mark all inlined blocks as abstract, including this one.
12876 So, we wouldn't (and shouldn't) expect labels to be generated
12877 for this one. Instead, just emit debugging info for
12878 declarations within the block. This is particularly important
12879 in the case of initializers of arguments passed from B to us:
12880 if they're statement expressions containing declarations, we
12881 wouldn't generate dies for their abstract variables, and then,
12882 when generating dies for the real variables, we'd die (pun
12884 gen_lexical_block_die (stmt, context_die, depth);
12887 /* Generate a DIE for a field in a record, or structure. */
12890 gen_field_die (tree decl, dw_die_ref context_die)
12892 dw_die_ref decl_die;
12894 if (TREE_TYPE (decl) == error_mark_node)
12897 decl_die = new_die (DW_TAG_member, context_die, decl);
12898 add_name_and_src_coords_attributes (decl_die, decl);
12899 add_type_attribute (decl_die, member_declared_type (decl),
12900 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12903 if (DECL_BIT_FIELD_TYPE (decl))
12905 add_byte_size_attribute (decl_die, decl);
12906 add_bit_size_attribute (decl_die, decl);
12907 add_bit_offset_attribute (decl_die, decl);
12910 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12911 add_data_member_location_attribute (decl_die, decl);
12913 if (DECL_ARTIFICIAL (decl))
12914 add_AT_flag (decl_die, DW_AT_artificial, 1);
12916 if (TREE_PROTECTED (decl))
12917 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12918 else if (TREE_PRIVATE (decl))
12919 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12921 /* Equate decl number to die, so that we can look up this decl later on. */
12922 equate_decl_number_to_die (decl, decl_die);
12926 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12927 Use modified_type_die instead.
12928 We keep this code here just in case these types of DIEs may be needed to
12929 represent certain things in other languages (e.g. Pascal) someday. */
12932 gen_pointer_type_die (tree type, dw_die_ref context_die)
12935 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12937 equate_type_number_to_die (type, ptr_die);
12938 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12939 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12942 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12943 Use modified_type_die instead.
12944 We keep this code here just in case these types of DIEs may be needed to
12945 represent certain things in other languages (e.g. Pascal) someday. */
12948 gen_reference_type_die (tree type, dw_die_ref context_die)
12951 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12953 equate_type_number_to_die (type, ref_die);
12954 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12955 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12959 /* Generate a DIE for a pointer to a member type. */
12962 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12965 = new_die (DW_TAG_ptr_to_member_type,
12966 scope_die_for (type, context_die), type);
12968 equate_type_number_to_die (type, ptr_die);
12969 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12970 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12971 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12974 /* Generate the DIE for the compilation unit. */
12977 gen_compile_unit_die (const char *filename)
12980 char producer[250];
12981 const char *language_string = lang_hooks.name;
12984 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12988 add_name_attribute (die, filename);
12989 /* Don't add cwd for <built-in>. */
12990 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
12991 add_comp_dir_attribute (die);
12994 sprintf (producer, "%s %s", language_string, version_string);
12996 #ifdef MIPS_DEBUGGING_INFO
12997 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12998 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12999 not appear in the producer string, the debugger reaches the conclusion
13000 that the object file is stripped and has no debugging information.
13001 To get the MIPS/SGI debugger to believe that there is debugging
13002 information in the object file, we add a -g to the producer string. */
13003 if (debug_info_level > DINFO_LEVEL_TERSE)
13004 strcat (producer, " -g");
13007 add_AT_string (die, DW_AT_producer, producer);
13009 if (strcmp (language_string, "GNU C++") == 0)
13010 language = DW_LANG_C_plus_plus;
13011 else if (strcmp (language_string, "GNU Ada") == 0)
13012 language = DW_LANG_Ada95;
13013 else if (strcmp (language_string, "GNU F77") == 0)
13014 language = DW_LANG_Fortran77;
13015 else if (strcmp (language_string, "GNU F95") == 0)
13016 language = DW_LANG_Fortran95;
13017 else if (strcmp (language_string, "GNU Pascal") == 0)
13018 language = DW_LANG_Pascal83;
13019 else if (strcmp (language_string, "GNU Java") == 0)
13020 language = DW_LANG_Java;
13021 else if (strcmp (language_string, "GNU Objective-C") == 0)
13022 language = DW_LANG_ObjC;
13023 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13024 language = DW_LANG_ObjC_plus_plus;
13026 language = DW_LANG_C89;
13028 add_AT_unsigned (die, DW_AT_language, language);
13032 /* Generate the DIE for a base class. */
13035 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13037 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13039 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13040 add_data_member_location_attribute (die, binfo);
13042 if (BINFO_VIRTUAL_P (binfo))
13043 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13045 if (access == access_public_node)
13046 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13047 else if (access == access_protected_node)
13048 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13051 /* Generate a DIE for a class member. */
13054 gen_member_die (tree type, dw_die_ref context_die)
13057 tree binfo = TYPE_BINFO (type);
13060 /* If this is not an incomplete type, output descriptions of each of its
13061 members. Note that as we output the DIEs necessary to represent the
13062 members of this record or union type, we will also be trying to output
13063 DIEs to represent the *types* of those members. However the `type'
13064 function (above) will specifically avoid generating type DIEs for member
13065 types *within* the list of member DIEs for this (containing) type except
13066 for those types (of members) which are explicitly marked as also being
13067 members of this (containing) type themselves. The g++ front- end can
13068 force any given type to be treated as a member of some other (containing)
13069 type by setting the TYPE_CONTEXT of the given (member) type to point to
13070 the TREE node representing the appropriate (containing) type. */
13072 /* First output info about the base classes. */
13075 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13079 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13080 gen_inheritance_die (base,
13081 (accesses ? VEC_index (tree, accesses, i)
13082 : access_public_node), context_die);
13085 /* Now output info about the data members and type members. */
13086 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
13088 /* If we thought we were generating minimal debug info for TYPE
13089 and then changed our minds, some of the member declarations
13090 may have already been defined. Don't define them again, but
13091 do put them in the right order. */
13093 child = lookup_decl_die (member);
13095 splice_child_die (context_die, child);
13097 gen_decl_die (member, context_die);
13100 /* Now output info about the function members (if any). */
13101 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
13103 /* Don't include clones in the member list. */
13104 if (DECL_ABSTRACT_ORIGIN (member))
13107 child = lookup_decl_die (member);
13109 splice_child_die (context_die, child);
13111 gen_decl_die (member, context_die);
13115 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13116 is set, we pretend that the type was never defined, so we only get the
13117 member DIEs needed by later specification DIEs. */
13120 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
13121 enum debug_info_usage usage)
13123 dw_die_ref type_die = lookup_type_die (type);
13124 dw_die_ref scope_die = 0;
13126 int complete = (TYPE_SIZE (type)
13127 && (! TYPE_STUB_DECL (type)
13128 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
13129 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
13130 complete = complete && should_emit_struct_debug (type, usage);
13132 if (type_die && ! complete)
13135 if (TYPE_CONTEXT (type) != NULL_TREE
13136 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13137 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
13140 scope_die = scope_die_for (type, context_die);
13142 if (! type_die || (nested && scope_die == comp_unit_die))
13143 /* First occurrence of type or toplevel definition of nested class. */
13145 dw_die_ref old_die = type_die;
13147 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
13148 ? record_type_tag (type) : DW_TAG_union_type,
13150 equate_type_number_to_die (type, type_die);
13152 add_AT_specification (type_die, old_die);
13154 add_name_attribute (type_die, type_tag (type));
13157 remove_AT (type_die, DW_AT_declaration);
13159 /* If this type has been completed, then give it a byte_size attribute and
13160 then give a list of members. */
13161 if (complete && !ns_decl)
13163 /* Prevent infinite recursion in cases where the type of some member of
13164 this type is expressed in terms of this type itself. */
13165 TREE_ASM_WRITTEN (type) = 1;
13166 add_byte_size_attribute (type_die, type);
13167 if (TYPE_STUB_DECL (type) != NULL_TREE)
13168 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13170 /* If the first reference to this type was as the return type of an
13171 inline function, then it may not have a parent. Fix this now. */
13172 if (type_die->die_parent == NULL)
13173 add_child_die (scope_die, type_die);
13175 push_decl_scope (type);
13176 gen_member_die (type, type_die);
13179 /* GNU extension: Record what type our vtable lives in. */
13180 if (TYPE_VFIELD (type))
13182 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
13184 gen_type_die (vtype, context_die);
13185 add_AT_die_ref (type_die, DW_AT_containing_type,
13186 lookup_type_die (vtype));
13191 add_AT_flag (type_die, DW_AT_declaration, 1);
13193 /* We don't need to do this for function-local types. */
13194 if (TYPE_STUB_DECL (type)
13195 && ! decl_function_context (TYPE_STUB_DECL (type)))
13196 VEC_safe_push (tree, gc, incomplete_types, type);
13199 if (get_AT (type_die, DW_AT_name))
13200 add_pubtype (type, type_die);
13203 /* Generate a DIE for a subroutine _type_. */
13206 gen_subroutine_type_die (tree type, dw_die_ref context_die)
13208 tree return_type = TREE_TYPE (type);
13209 dw_die_ref subr_die
13210 = new_die (DW_TAG_subroutine_type,
13211 scope_die_for (type, context_die), type);
13213 equate_type_number_to_die (type, subr_die);
13214 add_prototyped_attribute (subr_die, type);
13215 add_type_attribute (subr_die, return_type, 0, 0, context_die);
13216 gen_formal_types_die (type, subr_die);
13218 if (get_AT (subr_die, DW_AT_name))
13219 add_pubtype (type, subr_die);
13222 /* Generate a DIE for a type definition. */
13225 gen_typedef_die (tree decl, dw_die_ref context_die)
13227 dw_die_ref type_die;
13230 if (TREE_ASM_WRITTEN (decl))
13233 TREE_ASM_WRITTEN (decl) = 1;
13234 type_die = new_die (DW_TAG_typedef, context_die, decl);
13235 origin = decl_ultimate_origin (decl);
13236 if (origin != NULL)
13237 add_abstract_origin_attribute (type_die, origin);
13242 add_name_and_src_coords_attributes (type_die, decl);
13243 if (DECL_ORIGINAL_TYPE (decl))
13245 type = DECL_ORIGINAL_TYPE (decl);
13247 gcc_assert (type != TREE_TYPE (decl));
13248 equate_type_number_to_die (TREE_TYPE (decl), type_die);
13251 type = TREE_TYPE (decl);
13253 add_type_attribute (type_die, type, TREE_READONLY (decl),
13254 TREE_THIS_VOLATILE (decl), context_die);
13257 if (DECL_ABSTRACT (decl))
13258 equate_decl_number_to_die (decl, type_die);
13260 if (get_AT (type_die, DW_AT_name))
13261 add_pubtype (decl, type_die);
13264 /* Generate a type description DIE. */
13267 gen_type_die_with_usage (tree type, dw_die_ref context_die,
13268 enum debug_info_usage usage)
13271 struct array_descr_info info;
13273 if (type == NULL_TREE || type == error_mark_node)
13276 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13277 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
13279 if (TREE_ASM_WRITTEN (type))
13282 /* Prevent broken recursion; we can't hand off to the same type. */
13283 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
13285 TREE_ASM_WRITTEN (type) = 1;
13286 gen_decl_die (TYPE_NAME (type), context_die);
13290 /* If this is an array type with hidden descriptor, handle it first. */
13291 if (!TREE_ASM_WRITTEN (type)
13292 && lang_hooks.types.get_array_descr_info
13293 && lang_hooks.types.get_array_descr_info (type, &info))
13295 gen_descr_array_type_die (type, &info, context_die);
13296 TREE_ASM_WRITTEN (type) = 1;
13300 /* We are going to output a DIE to represent the unqualified version
13301 of this type (i.e. without any const or volatile qualifiers) so
13302 get the main variant (i.e. the unqualified version) of this type
13303 now. (Vectors are special because the debugging info is in the
13304 cloned type itself). */
13305 if (TREE_CODE (type) != VECTOR_TYPE)
13306 type = type_main_variant (type);
13308 if (TREE_ASM_WRITTEN (type))
13311 switch (TREE_CODE (type))
13317 case REFERENCE_TYPE:
13318 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13319 ensures that the gen_type_die recursion will terminate even if the
13320 type is recursive. Recursive types are possible in Ada. */
13321 /* ??? We could perhaps do this for all types before the switch
13323 TREE_ASM_WRITTEN (type) = 1;
13325 /* For these types, all that is required is that we output a DIE (or a
13326 set of DIEs) to represent the "basis" type. */
13327 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13328 DINFO_USAGE_IND_USE);
13332 /* This code is used for C++ pointer-to-data-member types.
13333 Output a description of the relevant class type. */
13334 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13335 DINFO_USAGE_IND_USE);
13337 /* Output a description of the type of the object pointed to. */
13338 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13339 DINFO_USAGE_IND_USE);
13341 /* Now output a DIE to represent this pointer-to-data-member type
13343 gen_ptr_to_mbr_type_die (type, context_die);
13346 case FUNCTION_TYPE:
13347 /* Force out return type (in case it wasn't forced out already). */
13348 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13349 DINFO_USAGE_DIR_USE);
13350 gen_subroutine_type_die (type, context_die);
13354 /* Force out return type (in case it wasn't forced out already). */
13355 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13356 DINFO_USAGE_DIR_USE);
13357 gen_subroutine_type_die (type, context_die);
13361 gen_array_type_die (type, context_die);
13365 gen_array_type_die (type, context_die);
13368 case ENUMERAL_TYPE:
13371 case QUAL_UNION_TYPE:
13372 /* If this is a nested type whose containing class hasn't been written
13373 out yet, writing it out will cover this one, too. This does not apply
13374 to instantiations of member class templates; they need to be added to
13375 the containing class as they are generated. FIXME: This hurts the
13376 idea of combining type decls from multiple TUs, since we can't predict
13377 what set of template instantiations we'll get. */
13378 if (TYPE_CONTEXT (type)
13379 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13380 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13382 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13384 if (TREE_ASM_WRITTEN (type))
13387 /* If that failed, attach ourselves to the stub. */
13388 push_decl_scope (TYPE_CONTEXT (type));
13389 context_die = lookup_type_die (TYPE_CONTEXT (type));
13394 declare_in_namespace (type, context_die);
13398 if (TREE_CODE (type) == ENUMERAL_TYPE)
13400 /* This might have been written out by the call to
13401 declare_in_namespace. */
13402 if (!TREE_ASM_WRITTEN (type))
13403 gen_enumeration_type_die (type, context_die);
13406 gen_struct_or_union_type_die (type, context_die, usage);
13411 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13412 it up if it is ever completed. gen_*_type_die will set it for us
13413 when appropriate. */
13419 case FIXED_POINT_TYPE:
13422 /* No DIEs needed for fundamental types. */
13426 /* No Dwarf representation currently defined. */
13430 gcc_unreachable ();
13433 TREE_ASM_WRITTEN (type) = 1;
13437 gen_type_die (tree type, dw_die_ref context_die)
13439 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
13442 /* Generate a DIE for a tagged type instantiation. */
13445 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
13447 if (type == NULL_TREE || type == error_mark_node)
13450 /* We are going to output a DIE to represent the unqualified version of
13451 this type (i.e. without any const or volatile qualifiers) so make sure
13452 that we have the main variant (i.e. the unqualified version) of this
13454 gcc_assert (type == type_main_variant (type));
13456 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13457 an instance of an unresolved type. */
13459 switch (TREE_CODE (type))
13464 case ENUMERAL_TYPE:
13465 gen_inlined_enumeration_type_die (type, context_die);
13469 gen_inlined_structure_type_die (type, context_die);
13473 case QUAL_UNION_TYPE:
13474 gen_inlined_union_type_die (type, context_die);
13478 gcc_unreachable ();
13482 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13483 things which are local to the given block. */
13486 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
13488 int must_output_die = 0;
13491 enum tree_code origin_code;
13493 /* Ignore blocks that are NULL. */
13494 if (stmt == NULL_TREE)
13497 /* If the block is one fragment of a non-contiguous block, do not
13498 process the variables, since they will have been done by the
13499 origin block. Do process subblocks. */
13500 if (BLOCK_FRAGMENT_ORIGIN (stmt))
13504 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
13505 gen_block_die (sub, context_die, depth + 1);
13510 /* Determine the "ultimate origin" of this block. This block may be an
13511 inlined instance of an inlined instance of inline function, so we have
13512 to trace all of the way back through the origin chain to find out what
13513 sort of node actually served as the original seed for the creation of
13514 the current block. */
13515 origin = block_ultimate_origin (stmt);
13516 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13518 /* Determine if we need to output any Dwarf DIEs at all to represent this
13520 if (origin_code == FUNCTION_DECL)
13521 /* The outer scopes for inlinings *must* always be represented. We
13522 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13523 must_output_die = 1;
13526 /* In the case where the current block represents an inlining of the
13527 "body block" of an inline function, we must *NOT* output any DIE for
13528 this block because we have already output a DIE to represent the whole
13529 inlined function scope and the "body block" of any function doesn't
13530 really represent a different scope according to ANSI C rules. So we
13531 check here to make sure that this block does not represent a "body
13532 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13533 if (! is_body_block (origin ? origin : stmt))
13535 /* Determine if this block directly contains any "significant"
13536 local declarations which we will need to output DIEs for. */
13537 if (debug_info_level > DINFO_LEVEL_TERSE)
13538 /* We are not in terse mode so *any* local declaration counts
13539 as being a "significant" one. */
13540 must_output_die = (BLOCK_VARS (stmt) != NULL
13541 && (TREE_USED (stmt)
13542 || TREE_ASM_WRITTEN (stmt)
13543 || BLOCK_ABSTRACT (stmt)));
13545 /* We are in terse mode, so only local (nested) function
13546 definitions count as "significant" local declarations. */
13547 for (decl = BLOCK_VARS (stmt);
13548 decl != NULL; decl = TREE_CHAIN (decl))
13549 if (TREE_CODE (decl) == FUNCTION_DECL
13550 && DECL_INITIAL (decl))
13552 must_output_die = 1;
13558 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13559 DIE for any block which contains no significant local declarations at
13560 all. Rather, in such cases we just call `decls_for_scope' so that any
13561 needed Dwarf info for any sub-blocks will get properly generated. Note
13562 that in terse mode, our definition of what constitutes a "significant"
13563 local declaration gets restricted to include only inlined function
13564 instances and local (nested) function definitions. */
13565 if (must_output_die)
13567 if (origin_code == FUNCTION_DECL)
13568 gen_inlined_subroutine_die (stmt, context_die, depth);
13570 gen_lexical_block_die (stmt, context_die, depth);
13573 decls_for_scope (stmt, context_die, depth);
13576 /* Generate all of the decls declared within a given scope and (recursively)
13577 all of its sub-blocks. */
13580 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13585 /* Ignore NULL blocks. */
13586 if (stmt == NULL_TREE)
13589 if (TREE_USED (stmt))
13591 /* Output the DIEs to represent all of the data objects and typedefs
13592 declared directly within this block but not within any nested
13593 sub-blocks. Also, nested function and tag DIEs have been
13594 generated with a parent of NULL; fix that up now. */
13595 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13599 if (TREE_CODE (decl) == FUNCTION_DECL)
13600 die = lookup_decl_die (decl);
13601 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13602 die = lookup_type_die (TREE_TYPE (decl));
13606 if (die != NULL && die->die_parent == NULL)
13607 add_child_die (context_die, die);
13608 /* Do not produce debug information for static variables since
13609 these might be optimized out. We are called for these later
13610 in varpool_analyze_pending_decls. */
13611 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
13614 gen_decl_die (decl, context_die);
13618 /* If we're at -g1, we're not interested in subblocks. */
13619 if (debug_info_level <= DINFO_LEVEL_TERSE)
13622 /* Output the DIEs to represent all sub-blocks (and the items declared
13623 therein) of this block. */
13624 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13626 subblocks = BLOCK_CHAIN (subblocks))
13627 gen_block_die (subblocks, context_die, depth + 1);
13630 /* Is this a typedef we can avoid emitting? */
13633 is_redundant_typedef (const_tree decl)
13635 if (TYPE_DECL_IS_STUB (decl))
13638 if (DECL_ARTIFICIAL (decl)
13639 && DECL_CONTEXT (decl)
13640 && is_tagged_type (DECL_CONTEXT (decl))
13641 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13642 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13643 /* Also ignore the artificial member typedef for the class name. */
13649 /* Returns the DIE for decl. A DIE will always be returned. */
13652 force_decl_die (tree decl)
13654 dw_die_ref decl_die;
13655 unsigned saved_external_flag;
13656 tree save_fn = NULL_TREE;
13657 decl_die = lookup_decl_die (decl);
13660 dw_die_ref context_die;
13661 tree decl_context = DECL_CONTEXT (decl);
13664 /* Find die that represents this context. */
13665 if (TYPE_P (decl_context))
13666 context_die = force_type_die (decl_context);
13668 context_die = force_decl_die (decl_context);
13671 context_die = comp_unit_die;
13673 decl_die = lookup_decl_die (decl);
13677 switch (TREE_CODE (decl))
13679 case FUNCTION_DECL:
13680 /* Clear current_function_decl, so that gen_subprogram_die thinks
13681 that this is a declaration. At this point, we just want to force
13682 declaration die. */
13683 save_fn = current_function_decl;
13684 current_function_decl = NULL_TREE;
13685 gen_subprogram_die (decl, context_die);
13686 current_function_decl = save_fn;
13690 /* Set external flag to force declaration die. Restore it after
13691 gen_decl_die() call. */
13692 saved_external_flag = DECL_EXTERNAL (decl);
13693 DECL_EXTERNAL (decl) = 1;
13694 gen_decl_die (decl, context_die);
13695 DECL_EXTERNAL (decl) = saved_external_flag;
13698 case NAMESPACE_DECL:
13699 dwarf2out_decl (decl);
13703 gcc_unreachable ();
13706 /* We should be able to find the DIE now. */
13708 decl_die = lookup_decl_die (decl);
13709 gcc_assert (decl_die);
13715 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13716 always returned. */
13719 force_type_die (tree type)
13721 dw_die_ref type_die;
13723 type_die = lookup_type_die (type);
13726 dw_die_ref context_die;
13727 if (TYPE_CONTEXT (type))
13729 if (TYPE_P (TYPE_CONTEXT (type)))
13730 context_die = force_type_die (TYPE_CONTEXT (type));
13732 context_die = force_decl_die (TYPE_CONTEXT (type));
13735 context_die = comp_unit_die;
13737 type_die = lookup_type_die (type);
13740 gen_type_die (type, context_die);
13741 type_die = lookup_type_die (type);
13742 gcc_assert (type_die);
13747 /* Force out any required namespaces to be able to output DECL,
13748 and return the new context_die for it, if it's changed. */
13751 setup_namespace_context (tree thing, dw_die_ref context_die)
13753 tree context = (DECL_P (thing)
13754 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13755 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13756 /* Force out the namespace. */
13757 context_die = force_decl_die (context);
13759 return context_die;
13762 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13763 type) within its namespace, if appropriate.
13765 For compatibility with older debuggers, namespace DIEs only contain
13766 declarations; all definitions are emitted at CU scope. */
13769 declare_in_namespace (tree thing, dw_die_ref context_die)
13771 dw_die_ref ns_context;
13773 if (debug_info_level <= DINFO_LEVEL_TERSE)
13776 /* If this decl is from an inlined function, then don't try to emit it in its
13777 namespace, as we will get confused. It would have already been emitted
13778 when the abstract instance of the inline function was emitted anyways. */
13779 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13782 ns_context = setup_namespace_context (thing, context_die);
13784 if (ns_context != context_die)
13786 if (DECL_P (thing))
13787 gen_decl_die (thing, ns_context);
13789 gen_type_die (thing, ns_context);
13793 /* Generate a DIE for a namespace or namespace alias. */
13796 gen_namespace_die (tree decl)
13798 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13800 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13801 they are an alias of. */
13802 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13804 /* Output a real namespace. */
13805 dw_die_ref namespace_die
13806 = new_die (DW_TAG_namespace, context_die, decl);
13807 add_name_and_src_coords_attributes (namespace_die, decl);
13808 equate_decl_number_to_die (decl, namespace_die);
13812 /* Output a namespace alias. */
13814 /* Force out the namespace we are an alias of, if necessary. */
13815 dw_die_ref origin_die
13816 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13818 /* Now create the namespace alias DIE. */
13819 dw_die_ref namespace_die
13820 = new_die (DW_TAG_imported_declaration, context_die, decl);
13821 add_name_and_src_coords_attributes (namespace_die, decl);
13822 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13823 equate_decl_number_to_die (decl, namespace_die);
13827 /* Generate Dwarf debug information for a decl described by DECL. */
13830 gen_decl_die (tree decl, dw_die_ref context_die)
13834 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13837 switch (TREE_CODE (decl))
13843 /* The individual enumerators of an enum type get output when we output
13844 the Dwarf representation of the relevant enum type itself. */
13847 case FUNCTION_DECL:
13848 /* Don't output any DIEs to represent mere function declarations,
13849 unless they are class members or explicit block externs. */
13850 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13851 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13856 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13857 on local redeclarations of global functions. That seems broken. */
13858 if (current_function_decl != decl)
13859 /* This is only a declaration. */;
13862 /* If we're emitting a clone, emit info for the abstract instance. */
13863 if (DECL_ORIGIN (decl) != decl)
13864 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13866 /* If we're emitting an out-of-line copy of an inline function,
13867 emit info for the abstract instance and set up to refer to it. */
13868 else if (cgraph_function_possibly_inlined_p (decl)
13869 && ! DECL_ABSTRACT (decl)
13870 && ! class_or_namespace_scope_p (context_die)
13871 /* dwarf2out_abstract_function won't emit a die if this is just
13872 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13873 that case, because that works only if we have a die. */
13874 && DECL_INITIAL (decl) != NULL_TREE)
13876 dwarf2out_abstract_function (decl);
13877 set_decl_origin_self (decl);
13880 /* Otherwise we're emitting the primary DIE for this decl. */
13881 else if (debug_info_level > DINFO_LEVEL_TERSE)
13883 /* Before we describe the FUNCTION_DECL itself, make sure that we
13884 have described its return type. */
13885 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13887 /* And its virtual context. */
13888 if (DECL_VINDEX (decl) != NULL_TREE)
13889 gen_type_die (DECL_CONTEXT (decl), context_die);
13891 /* And its containing type. */
13892 origin = decl_class_context (decl);
13893 if (origin != NULL_TREE)
13894 gen_type_die_for_member (origin, decl, context_die);
13896 /* And its containing namespace. */
13897 declare_in_namespace (decl, context_die);
13900 /* Now output a DIE to represent the function itself. */
13901 gen_subprogram_die (decl, context_die);
13905 /* If we are in terse mode, don't generate any DIEs to represent any
13906 actual typedefs. */
13907 if (debug_info_level <= DINFO_LEVEL_TERSE)
13910 /* In the special case of a TYPE_DECL node representing the declaration
13911 of some type tag, if the given TYPE_DECL is marked as having been
13912 instantiated from some other (original) TYPE_DECL node (e.g. one which
13913 was generated within the original definition of an inline function) we
13914 have to generate a special (abbreviated) DW_TAG_structure_type,
13915 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13916 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
13917 && is_tagged_type (TREE_TYPE (decl)))
13919 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13923 if (is_redundant_typedef (decl))
13924 gen_type_die (TREE_TYPE (decl), context_die);
13926 /* Output a DIE to represent the typedef itself. */
13927 gen_typedef_die (decl, context_die);
13931 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13932 gen_label_die (decl, context_die);
13937 /* If we are in terse mode, don't generate any DIEs to represent any
13938 variable declarations or definitions. */
13939 if (debug_info_level <= DINFO_LEVEL_TERSE)
13942 /* Output any DIEs that are needed to specify the type of this data
13944 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
13945 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13947 gen_type_die (TREE_TYPE (decl), context_die);
13949 /* And its containing type. */
13950 origin = decl_class_context (decl);
13951 if (origin != NULL_TREE)
13952 gen_type_die_for_member (origin, decl, context_die);
13954 /* And its containing namespace. */
13955 declare_in_namespace (decl, context_die);
13957 /* Now output the DIE to represent the data object itself. This gets
13958 complicated because of the possibility that the VAR_DECL really
13959 represents an inlined instance of a formal parameter for an inline
13961 origin = decl_ultimate_origin (decl);
13962 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13963 gen_formal_parameter_die (decl, context_die);
13965 gen_variable_die (decl, context_die);
13969 /* Ignore the nameless fields that are used to skip bits but handle C++
13970 anonymous unions and structs. */
13971 if (DECL_NAME (decl) != NULL_TREE
13972 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13973 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13975 gen_type_die (member_declared_type (decl), context_die);
13976 gen_field_die (decl, context_die);
13981 if (DECL_BY_REFERENCE (decl))
13982 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13984 gen_type_die (TREE_TYPE (decl), context_die);
13985 gen_formal_parameter_die (decl, context_die);
13988 case NAMESPACE_DECL:
13989 gen_namespace_die (decl);
13993 /* Probably some frontend-internal decl. Assume we don't care. */
13994 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13999 /* Output debug information for global decl DECL. Called from toplev.c after
14000 compilation proper has finished. */
14003 dwarf2out_global_decl (tree decl)
14005 /* Output DWARF2 information for file-scope tentative data object
14006 declarations, file-scope (extern) function declarations (which had no
14007 corresponding body) and file-scope tagged type declarations and
14008 definitions which have not yet been forced out. */
14009 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14010 dwarf2out_decl (decl);
14013 /* Output debug information for type decl DECL. Called from toplev.c
14014 and from language front ends (to record built-in types). */
14016 dwarf2out_type_decl (tree decl, int local)
14019 dwarf2out_decl (decl);
14022 /* Output debug information for imported module or decl. */
14025 dwarf2out_imported_module_or_decl (tree decl, tree context)
14027 dw_die_ref imported_die, at_import_die;
14028 dw_die_ref scope_die;
14029 expanded_location xloc;
14031 if (debug_info_level <= DINFO_LEVEL_TERSE)
14036 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14037 We need decl DIE for reference and scope die. First, get DIE for the decl
14040 /* Get the scope die for decl context. Use comp_unit_die for global module
14041 or decl. If die is not found for non globals, force new die. */
14043 scope_die = comp_unit_die;
14044 else if (TYPE_P (context))
14046 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14048 scope_die = force_type_die (context);
14051 scope_die = force_decl_die (context);
14053 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14054 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14056 if (is_base_type (TREE_TYPE (decl)))
14057 at_import_die = base_type_die (TREE_TYPE (decl));
14059 at_import_die = force_type_die (TREE_TYPE (decl));
14063 at_import_die = lookup_decl_die (decl);
14064 if (!at_import_die)
14066 /* If we're trying to avoid duplicate debug info, we may not have
14067 emitted the member decl for this field. Emit it now. */
14068 if (TREE_CODE (decl) == FIELD_DECL)
14070 tree type = DECL_CONTEXT (decl);
14071 dw_die_ref type_context_die;
14073 if (TYPE_CONTEXT (type))
14074 if (TYPE_P (TYPE_CONTEXT (type)))
14076 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
14077 DINFO_USAGE_DIR_USE))
14079 type_context_die = force_type_die (TYPE_CONTEXT (type));
14082 type_context_die = force_decl_die (TYPE_CONTEXT (type));
14084 type_context_die = comp_unit_die;
14085 gen_type_die_for_member (type, decl, type_context_die);
14087 at_import_die = force_decl_die (decl);
14091 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14092 if (TREE_CODE (decl) == NAMESPACE_DECL)
14093 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
14095 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
14097 xloc = expand_location (input_location);
14098 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
14099 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
14100 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
14103 /* Write the debugging output for DECL. */
14106 dwarf2out_decl (tree decl)
14108 dw_die_ref context_die = comp_unit_die;
14110 switch (TREE_CODE (decl))
14115 case FUNCTION_DECL:
14116 /* What we would really like to do here is to filter out all mere
14117 file-scope declarations of file-scope functions which are never
14118 referenced later within this translation unit (and keep all of ones
14119 that *are* referenced later on) but we aren't clairvoyant, so we have
14120 no idea which functions will be referenced in the future (i.e. later
14121 on within the current translation unit). So here we just ignore all
14122 file-scope function declarations which are not also definitions. If
14123 and when the debugger needs to know something about these functions,
14124 it will have to hunt around and find the DWARF information associated
14125 with the definition of the function.
14127 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14128 nodes represent definitions and which ones represent mere
14129 declarations. We have to check DECL_INITIAL instead. That's because
14130 the C front-end supports some weird semantics for "extern inline"
14131 function definitions. These can get inlined within the current
14132 translation unit (and thus, we need to generate Dwarf info for their
14133 abstract instances so that the Dwarf info for the concrete inlined
14134 instances can have something to refer to) but the compiler never
14135 generates any out-of-lines instances of such things (despite the fact
14136 that they *are* definitions).
14138 The important point is that the C front-end marks these "extern
14139 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14140 them anyway. Note that the C++ front-end also plays some similar games
14141 for inline function definitions appearing within include files which
14142 also contain `#pragma interface' pragmas. */
14143 if (DECL_INITIAL (decl) == NULL_TREE)
14146 /* If we're a nested function, initially use a parent of NULL; if we're
14147 a plain function, this will be fixed up in decls_for_scope. If
14148 we're a method, it will be ignored, since we already have a DIE. */
14149 if (decl_function_context (decl)
14150 /* But if we're in terse mode, we don't care about scope. */
14151 && debug_info_level > DINFO_LEVEL_TERSE)
14152 context_die = NULL;
14156 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14157 declaration and if the declaration was never even referenced from
14158 within this entire compilation unit. We suppress these DIEs in
14159 order to save space in the .debug section (by eliminating entries
14160 which are probably useless). Note that we must not suppress
14161 block-local extern declarations (whether used or not) because that
14162 would screw-up the debugger's name lookup mechanism and cause it to
14163 miss things which really ought to be in scope at a given point. */
14164 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
14167 /* For local statics lookup proper context die. */
14168 if (TREE_STATIC (decl) && decl_function_context (decl))
14169 context_die = lookup_decl_die (DECL_CONTEXT (decl));
14171 /* If we are in terse mode, don't generate any DIEs to represent any
14172 variable declarations or definitions. */
14173 if (debug_info_level <= DINFO_LEVEL_TERSE)
14177 case NAMESPACE_DECL:
14178 if (debug_info_level <= DINFO_LEVEL_TERSE)
14180 if (lookup_decl_die (decl) != NULL)
14185 /* Don't emit stubs for types unless they are needed by other DIEs. */
14186 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
14189 /* Don't bother trying to generate any DIEs to represent any of the
14190 normal built-in types for the language we are compiling. */
14191 if (DECL_IS_BUILTIN (decl))
14193 /* OK, we need to generate one for `bool' so GDB knows what type
14194 comparisons have. */
14196 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
14197 && ! DECL_IGNORED_P (decl))
14198 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
14203 /* If we are in terse mode, don't generate any DIEs for types. */
14204 if (debug_info_level <= DINFO_LEVEL_TERSE)
14207 /* If we're a function-scope tag, initially use a parent of NULL;
14208 this will be fixed up in decls_for_scope. */
14209 if (decl_function_context (decl))
14210 context_die = NULL;
14218 gen_decl_die (decl, context_die);
14221 /* Output a marker (i.e. a label) for the beginning of the generated code for
14222 a lexical block. */
14225 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
14226 unsigned int blocknum)
14228 switch_to_section (current_function_section ());
14229 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
14232 /* Output a marker (i.e. a label) for the end of the generated code for a
14236 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
14238 switch_to_section (current_function_section ());
14239 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
14242 /* Returns nonzero if it is appropriate not to emit any debugging
14243 information for BLOCK, because it doesn't contain any instructions.
14245 Don't allow this for blocks with nested functions or local classes
14246 as we would end up with orphans, and in the presence of scheduling
14247 we may end up calling them anyway. */
14250 dwarf2out_ignore_block (const_tree block)
14254 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
14255 if (TREE_CODE (decl) == FUNCTION_DECL
14256 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
14262 /* Hash table routines for file_hash. */
14265 file_table_eq (const void *p1_p, const void *p2_p)
14267 const struct dwarf_file_data * p1 = p1_p;
14268 const char * p2 = p2_p;
14269 return strcmp (p1->filename, p2) == 0;
14273 file_table_hash (const void *p_p)
14275 const struct dwarf_file_data * p = p_p;
14276 return htab_hash_string (p->filename);
14279 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14280 dwarf2out.c) and return its "index". The index of each (known) filename is
14281 just a unique number which is associated with only that one filename. We
14282 need such numbers for the sake of generating labels (in the .debug_sfnames
14283 section) and references to those files numbers (in the .debug_srcinfo
14284 and.debug_macinfo sections). If the filename given as an argument is not
14285 found in our current list, add it to the list and assign it the next
14286 available unique index number. In order to speed up searches, we remember
14287 the index of the filename was looked up last. This handles the majority of
14290 static struct dwarf_file_data *
14291 lookup_filename (const char *file_name)
14294 struct dwarf_file_data * created;
14296 /* Check to see if the file name that was searched on the previous
14297 call matches this file name. If so, return the index. */
14298 if (file_table_last_lookup
14299 && (file_name == file_table_last_lookup->filename
14300 || strcmp (file_table_last_lookup->filename, file_name) == 0))
14301 return file_table_last_lookup;
14303 /* Didn't match the previous lookup, search the table. */
14304 slot = htab_find_slot_with_hash (file_table, file_name,
14305 htab_hash_string (file_name), INSERT);
14309 created = ggc_alloc (sizeof (struct dwarf_file_data));
14310 created->filename = file_name;
14311 created->emitted_number = 0;
14316 /* If the assembler will construct the file table, then translate the compiler
14317 internal file table number into the assembler file table number, and emit
14318 a .file directive if we haven't already emitted one yet. The file table
14319 numbers are different because we prune debug info for unused variables and
14320 types, which may include filenames. */
14323 maybe_emit_file (struct dwarf_file_data * fd)
14325 if (! fd->emitted_number)
14327 if (last_emitted_file)
14328 fd->emitted_number = last_emitted_file->emitted_number + 1;
14330 fd->emitted_number = 1;
14331 last_emitted_file = fd;
14333 if (DWARF2_ASM_LINE_DEBUG_INFO)
14335 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14336 output_quoted_string (asm_out_file,
14337 remap_debug_filename (fd->filename));
14338 fputc ('\n', asm_out_file);
14342 return fd->emitted_number;
14345 /* Called by the final INSN scan whenever we see a var location. We
14346 use it to drop labels in the right places, and throw the location in
14347 our lookup table. */
14350 dwarf2out_var_location (rtx loc_note)
14352 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14353 struct var_loc_node *newloc;
14355 static rtx last_insn;
14356 static const char *last_label;
14359 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14361 prev_insn = PREV_INSN (loc_note);
14363 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
14364 /* If the insn we processed last time is the previous insn
14365 and it is also a var location note, use the label we emitted
14367 if (last_insn != NULL_RTX
14368 && last_insn == prev_insn
14369 && NOTE_P (prev_insn)
14370 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14372 newloc->label = last_label;
14376 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14377 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14379 newloc->label = ggc_strdup (loclabel);
14381 newloc->var_loc_note = loc_note;
14382 newloc->next = NULL;
14384 if (cfun && in_cold_section_p)
14385 newloc->section_label = cfun->cold_section_label;
14387 newloc->section_label = text_section_label;
14389 last_insn = loc_note;
14390 last_label = newloc->label;
14391 decl = NOTE_VAR_LOCATION_DECL (loc_note);
14392 add_var_loc_to_decl (decl, newloc);
14395 /* We need to reset the locations at the beginning of each
14396 function. We can't do this in the end_function hook, because the
14397 declarations that use the locations won't have been output when
14398 that hook is called. Also compute have_multiple_function_sections here. */
14401 dwarf2out_begin_function (tree fun)
14403 htab_empty (decl_loc_table);
14405 if (function_section (fun) != text_section)
14406 have_multiple_function_sections = true;
14408 dwarf2out_note_section_used ();
14411 /* Output a label to mark the beginning of a source code line entry
14412 and record information relating to this source line, in
14413 'line_info_table' for later output of the .debug_line section. */
14416 dwarf2out_source_line (unsigned int line, const char *filename)
14418 if (debug_info_level >= DINFO_LEVEL_NORMAL
14421 int file_num = maybe_emit_file (lookup_filename (filename));
14423 switch_to_section (current_function_section ());
14425 /* If requested, emit something human-readable. */
14426 if (flag_debug_asm)
14427 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
14430 if (DWARF2_ASM_LINE_DEBUG_INFO)
14432 /* Emit the .loc directive understood by GNU as. */
14433 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
14435 /* Indicate that line number info exists. */
14436 line_info_table_in_use++;
14438 else if (function_section (current_function_decl) != text_section)
14440 dw_separate_line_info_ref line_info;
14441 targetm.asm_out.internal_label (asm_out_file,
14442 SEPARATE_LINE_CODE_LABEL,
14443 separate_line_info_table_in_use);
14445 /* Expand the line info table if necessary. */
14446 if (separate_line_info_table_in_use
14447 == separate_line_info_table_allocated)
14449 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14450 separate_line_info_table
14451 = ggc_realloc (separate_line_info_table,
14452 separate_line_info_table_allocated
14453 * sizeof (dw_separate_line_info_entry));
14454 memset (separate_line_info_table
14455 + separate_line_info_table_in_use,
14457 (LINE_INFO_TABLE_INCREMENT
14458 * sizeof (dw_separate_line_info_entry)));
14461 /* Add the new entry at the end of the line_info_table. */
14463 = &separate_line_info_table[separate_line_info_table_in_use++];
14464 line_info->dw_file_num = file_num;
14465 line_info->dw_line_num = line;
14466 line_info->function = current_function_funcdef_no;
14470 dw_line_info_ref line_info;
14472 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
14473 line_info_table_in_use);
14475 /* Expand the line info table if necessary. */
14476 if (line_info_table_in_use == line_info_table_allocated)
14478 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14480 = ggc_realloc (line_info_table,
14481 (line_info_table_allocated
14482 * sizeof (dw_line_info_entry)));
14483 memset (line_info_table + line_info_table_in_use, 0,
14484 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
14487 /* Add the new entry at the end of the line_info_table. */
14488 line_info = &line_info_table[line_info_table_in_use++];
14489 line_info->dw_file_num = file_num;
14490 line_info->dw_line_num = line;
14495 /* Record the beginning of a new source file. */
14498 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
14500 if (flag_eliminate_dwarf2_dups)
14502 /* Record the beginning of the file for break_out_includes. */
14503 dw_die_ref bincl_die;
14505 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
14506 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
14509 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14511 int file_num = maybe_emit_file (lookup_filename (filename));
14513 switch_to_section (debug_macinfo_section);
14514 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
14515 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14518 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14522 /* Record the end of a source file. */
14525 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14527 if (flag_eliminate_dwarf2_dups)
14528 /* Record the end of the file for break_out_includes. */
14529 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14531 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14533 switch_to_section (debug_macinfo_section);
14534 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14538 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14539 the tail part of the directive line, i.e. the part which is past the
14540 initial whitespace, #, whitespace, directive-name, whitespace part. */
14543 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14544 const char *buffer ATTRIBUTE_UNUSED)
14546 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14548 switch_to_section (debug_macinfo_section);
14549 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14550 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14551 dw2_asm_output_nstring (buffer, -1, "The macro");
14555 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14556 the tail part of the directive line, i.e. the part which is past the
14557 initial whitespace, #, whitespace, directive-name, whitespace part. */
14560 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14561 const char *buffer ATTRIBUTE_UNUSED)
14563 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14565 switch_to_section (debug_macinfo_section);
14566 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14567 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14568 dw2_asm_output_nstring (buffer, -1, "The macro");
14572 /* Set up for Dwarf output at the start of compilation. */
14575 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14577 /* Allocate the file_table. */
14578 file_table = htab_create_ggc (50, file_table_hash,
14579 file_table_eq, NULL);
14581 /* Allocate the decl_die_table. */
14582 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14583 decl_die_table_eq, NULL);
14585 /* Allocate the decl_loc_table. */
14586 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14587 decl_loc_table_eq, NULL);
14589 /* Allocate the initial hunk of the decl_scope_table. */
14590 decl_scope_table = VEC_alloc (tree, gc, 256);
14592 /* Allocate the initial hunk of the abbrev_die_table. */
14593 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
14594 * sizeof (dw_die_ref));
14595 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14596 /* Zero-th entry is allocated, but unused. */
14597 abbrev_die_table_in_use = 1;
14599 /* Allocate the initial hunk of the line_info_table. */
14600 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
14601 * sizeof (dw_line_info_entry));
14602 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14604 /* Zero-th entry is allocated, but unused. */
14605 line_info_table_in_use = 1;
14607 /* Allocate the pubtypes and pubnames vectors. */
14608 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14609 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14611 /* Generate the initial DIE for the .debug section. Note that the (string)
14612 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14613 will (typically) be a relative pathname and that this pathname should be
14614 taken as being relative to the directory from which the compiler was
14615 invoked when the given (base) source file was compiled. We will fill
14616 in this value in dwarf2out_finish. */
14617 comp_unit_die = gen_compile_unit_die (NULL);
14619 incomplete_types = VEC_alloc (tree, gc, 64);
14621 used_rtx_array = VEC_alloc (rtx, gc, 32);
14623 debug_info_section = get_section (DEBUG_INFO_SECTION,
14624 SECTION_DEBUG, NULL);
14625 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14626 SECTION_DEBUG, NULL);
14627 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14628 SECTION_DEBUG, NULL);
14629 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14630 SECTION_DEBUG, NULL);
14631 debug_line_section = get_section (DEBUG_LINE_SECTION,
14632 SECTION_DEBUG, NULL);
14633 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14634 SECTION_DEBUG, NULL);
14635 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14636 SECTION_DEBUG, NULL);
14637 #ifdef DEBUG_PUBTYPES_SECTION
14638 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14639 SECTION_DEBUG, NULL);
14641 debug_str_section = get_section (DEBUG_STR_SECTION,
14642 DEBUG_STR_SECTION_FLAGS, NULL);
14643 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14644 SECTION_DEBUG, NULL);
14645 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14646 SECTION_DEBUG, NULL);
14648 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14649 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14650 DEBUG_ABBREV_SECTION_LABEL, 0);
14651 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14652 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14653 COLD_TEXT_SECTION_LABEL, 0);
14654 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14656 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14657 DEBUG_INFO_SECTION_LABEL, 0);
14658 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14659 DEBUG_LINE_SECTION_LABEL, 0);
14660 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14661 DEBUG_RANGES_SECTION_LABEL, 0);
14662 switch_to_section (debug_abbrev_section);
14663 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14664 switch_to_section (debug_info_section);
14665 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14666 switch_to_section (debug_line_section);
14667 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14669 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14671 switch_to_section (debug_macinfo_section);
14672 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14673 DEBUG_MACINFO_SECTION_LABEL, 0);
14674 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14677 switch_to_section (text_section);
14678 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14679 if (flag_reorder_blocks_and_partition)
14681 cold_text_section = unlikely_text_section ();
14682 switch_to_section (cold_text_section);
14683 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14687 /* A helper function for dwarf2out_finish called through
14688 ht_forall. Emit one queued .debug_str string. */
14691 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14693 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14695 if (node->form == DW_FORM_strp)
14697 switch_to_section (debug_str_section);
14698 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14699 assemble_string (node->str, strlen (node->str) + 1);
14705 #if ENABLE_ASSERT_CHECKING
14706 /* Verify that all marks are clear. */
14709 verify_marks_clear (dw_die_ref die)
14713 gcc_assert (! die->die_mark);
14714 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14716 #endif /* ENABLE_ASSERT_CHECKING */
14718 /* Clear the marks for a die and its children.
14719 Be cool if the mark isn't set. */
14722 prune_unmark_dies (dw_die_ref die)
14728 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14731 /* Given DIE that we're marking as used, find any other dies
14732 it references as attributes and mark them as used. */
14735 prune_unused_types_walk_attribs (dw_die_ref die)
14740 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14742 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14744 /* A reference to another DIE.
14745 Make sure that it will get emitted. */
14746 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14748 /* Set the string's refcount to 0 so that prune_unused_types_mark
14749 accounts properly for it. */
14750 if (AT_class (a) == dw_val_class_str)
14751 a->dw_attr_val.v.val_str->refcount = 0;
14756 /* Mark DIE as being used. If DOKIDS is true, then walk down
14757 to DIE's children. */
14760 prune_unused_types_mark (dw_die_ref die, int dokids)
14764 if (die->die_mark == 0)
14766 /* We haven't done this node yet. Mark it as used. */
14769 /* We also have to mark its parents as used.
14770 (But we don't want to mark our parents' kids due to this.) */
14771 if (die->die_parent)
14772 prune_unused_types_mark (die->die_parent, 0);
14774 /* Mark any referenced nodes. */
14775 prune_unused_types_walk_attribs (die);
14777 /* If this node is a specification,
14778 also mark the definition, if it exists. */
14779 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14780 prune_unused_types_mark (die->die_definition, 1);
14783 if (dokids && die->die_mark != 2)
14785 /* We need to walk the children, but haven't done so yet.
14786 Remember that we've walked the kids. */
14789 /* If this is an array type, we need to make sure our
14790 kids get marked, even if they're types. */
14791 if (die->die_tag == DW_TAG_array_type)
14792 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14794 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14799 /* Walk the tree DIE and mark types that we actually use. */
14802 prune_unused_types_walk (dw_die_ref die)
14806 /* Don't do anything if this node is already marked. */
14810 switch (die->die_tag)
14812 case DW_TAG_const_type:
14813 case DW_TAG_packed_type:
14814 case DW_TAG_pointer_type:
14815 case DW_TAG_reference_type:
14816 case DW_TAG_volatile_type:
14817 case DW_TAG_typedef:
14818 case DW_TAG_array_type:
14819 case DW_TAG_structure_type:
14820 case DW_TAG_union_type:
14821 case DW_TAG_class_type:
14822 case DW_TAG_interface_type:
14823 case DW_TAG_friend:
14824 case DW_TAG_variant_part:
14825 case DW_TAG_enumeration_type:
14826 case DW_TAG_subroutine_type:
14827 case DW_TAG_string_type:
14828 case DW_TAG_set_type:
14829 case DW_TAG_subrange_type:
14830 case DW_TAG_ptr_to_member_type:
14831 case DW_TAG_file_type:
14832 if (die->die_perennial_p)
14835 /* It's a type node --- don't mark it. */
14839 /* Mark everything else. */
14845 /* Now, mark any dies referenced from here. */
14846 prune_unused_types_walk_attribs (die);
14848 /* Mark children. */
14849 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14852 /* Increment the string counts on strings referred to from DIE's
14856 prune_unused_types_update_strings (dw_die_ref die)
14861 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14862 if (AT_class (a) == dw_val_class_str)
14864 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
14866 /* Avoid unnecessarily putting strings that are used less than
14867 twice in the hash table. */
14869 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
14872 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
14873 htab_hash_string (s->str),
14875 gcc_assert (*slot == NULL);
14881 /* Remove from the tree DIE any dies that aren't marked. */
14884 prune_unused_types_prune (dw_die_ref die)
14888 gcc_assert (die->die_mark);
14889 prune_unused_types_update_strings (die);
14891 if (! die->die_child)
14894 c = die->die_child;
14896 dw_die_ref prev = c;
14897 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
14898 if (c == die->die_child)
14900 /* No marked children between 'prev' and the end of the list. */
14902 /* No marked children at all. */
14903 die->die_child = NULL;
14906 prev->die_sib = c->die_sib;
14907 die->die_child = prev;
14912 if (c != prev->die_sib)
14914 prune_unused_types_prune (c);
14915 } while (c != die->die_child);
14919 /* Remove dies representing declarations that we never use. */
14922 prune_unused_types (void)
14925 limbo_die_node *node;
14928 #if ENABLE_ASSERT_CHECKING
14929 /* All the marks should already be clear. */
14930 verify_marks_clear (comp_unit_die);
14931 for (node = limbo_die_list; node; node = node->next)
14932 verify_marks_clear (node->die);
14933 #endif /* ENABLE_ASSERT_CHECKING */
14935 /* Set the mark on nodes that are actually used. */
14936 prune_unused_types_walk (comp_unit_die);
14937 for (node = limbo_die_list; node; node = node->next)
14938 prune_unused_types_walk (node->die);
14940 /* Also set the mark on nodes referenced from the
14941 pubname_table or arange_table. */
14942 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
14943 prune_unused_types_mark (pub->die, 1);
14944 for (i = 0; i < arange_table_in_use; i++)
14945 prune_unused_types_mark (arange_table[i], 1);
14947 /* Get rid of nodes that aren't marked; and update the string counts. */
14948 if (debug_str_hash)
14949 htab_empty (debug_str_hash);
14950 prune_unused_types_prune (comp_unit_die);
14951 for (node = limbo_die_list; node; node = node->next)
14952 prune_unused_types_prune (node->die);
14954 /* Leave the marks clear. */
14955 prune_unmark_dies (comp_unit_die);
14956 for (node = limbo_die_list; node; node = node->next)
14957 prune_unmark_dies (node->die);
14960 /* Set the parameter to true if there are any relative pathnames in
14963 file_table_relative_p (void ** slot, void *param)
14966 struct dwarf_file_data *d = *slot;
14967 if (!IS_ABSOLUTE_PATH (d->filename))
14975 /* Output stuff that dwarf requires at the end of every file,
14976 and generate the DWARF-2 debugging info. */
14979 dwarf2out_finish (const char *filename)
14981 limbo_die_node *node, *next_node;
14982 dw_die_ref die = 0;
14984 /* Add the name for the main input file now. We delayed this from
14985 dwarf2out_init to avoid complications with PCH. */
14986 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
14987 if (!IS_ABSOLUTE_PATH (filename))
14988 add_comp_dir_attribute (comp_unit_die);
14989 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14992 htab_traverse (file_table, file_table_relative_p, &p);
14994 add_comp_dir_attribute (comp_unit_die);
14997 /* Traverse the limbo die list, and add parent/child links. The only
14998 dies without parents that should be here are concrete instances of
14999 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15000 For concrete instances, we can get the parent die from the abstract
15002 for (node = limbo_die_list; node; node = next_node)
15004 next_node = node->next;
15007 if (die->die_parent == NULL)
15009 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15012 add_child_die (origin->die_parent, die);
15013 else if (die == comp_unit_die)
15015 else if (errorcount > 0 || sorrycount > 0)
15016 /* It's OK to be confused by errors in the input. */
15017 add_child_die (comp_unit_die, die);
15020 /* In certain situations, the lexical block containing a
15021 nested function can be optimized away, which results
15022 in the nested function die being orphaned. Likewise
15023 with the return type of that nested function. Force
15024 this to be a child of the containing function.
15026 It may happen that even the containing function got fully
15027 inlined and optimized out. In that case we are lost and
15028 assign the empty child. This should not be big issue as
15029 the function is likely unreachable too. */
15030 tree context = NULL_TREE;
15032 gcc_assert (node->created_for);
15034 if (DECL_P (node->created_for))
15035 context = DECL_CONTEXT (node->created_for);
15036 else if (TYPE_P (node->created_for))
15037 context = TYPE_CONTEXT (node->created_for);
15039 gcc_assert (context
15040 && (TREE_CODE (context) == FUNCTION_DECL
15041 || TREE_CODE (context) == NAMESPACE_DECL));
15043 origin = lookup_decl_die (context);
15045 add_child_die (origin, die);
15047 add_child_die (comp_unit_die, die);
15052 limbo_die_list = NULL;
15054 /* Walk through the list of incomplete types again, trying once more to
15055 emit full debugging info for them. */
15056 retry_incomplete_types ();
15058 if (flag_eliminate_unused_debug_types)
15059 prune_unused_types ();
15061 /* Generate separate CUs for each of the include files we've seen.
15062 They will go into limbo_die_list. */
15063 if (flag_eliminate_dwarf2_dups)
15064 break_out_includes (comp_unit_die);
15066 /* Traverse the DIE's and add add sibling attributes to those DIE's
15067 that have children. */
15068 add_sibling_attributes (comp_unit_die);
15069 for (node = limbo_die_list; node; node = node->next)
15070 add_sibling_attributes (node->die);
15072 /* Output a terminator label for the .text section. */
15073 switch_to_section (text_section);
15074 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
15075 if (flag_reorder_blocks_and_partition)
15077 switch_to_section (unlikely_text_section ());
15078 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
15081 /* We can only use the low/high_pc attributes if all of the code was
15083 if (!have_multiple_function_sections)
15085 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
15086 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
15091 unsigned fde_idx = 0;
15093 /* We need to give .debug_loc and .debug_ranges an appropriate
15094 "base address". Use zero so that these addresses become
15095 absolute. Historically, we've emitted the unexpected
15096 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15097 Emit both to give time for other tools to adapt. */
15098 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
15099 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
15101 add_AT_range_list (comp_unit_die, DW_AT_ranges,
15102 add_ranges_by_labels (text_section_label,
15104 if (flag_reorder_blocks_and_partition)
15105 add_ranges_by_labels (cold_text_section_label,
15108 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
15110 dw_fde_ref fde = &fde_table[fde_idx];
15112 if (fde->dw_fde_switched_sections)
15114 add_ranges_by_labels (fde->dw_fde_hot_section_label,
15115 fde->dw_fde_hot_section_end_label);
15116 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
15117 fde->dw_fde_unlikely_section_end_label);
15120 add_ranges_by_labels (fde->dw_fde_begin,
15127 /* Output location list section if necessary. */
15128 if (have_location_lists)
15130 /* Output the location lists info. */
15131 switch_to_section (debug_loc_section);
15132 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
15133 DEBUG_LOC_SECTION_LABEL, 0);
15134 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
15135 output_location_lists (die);
15138 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15139 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
15140 debug_line_section_label);
15142 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15143 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
15145 /* Output all of the compilation units. We put the main one last so that
15146 the offsets are available to output_pubnames. */
15147 for (node = limbo_die_list; node; node = node->next)
15148 output_comp_unit (node->die, 0);
15150 output_comp_unit (comp_unit_die, 0);
15152 /* Output the abbreviation table. */
15153 switch_to_section (debug_abbrev_section);
15154 output_abbrev_section ();
15156 /* Output public names table if necessary. */
15157 if (!VEC_empty (pubname_entry, pubname_table))
15159 switch_to_section (debug_pubnames_section);
15160 output_pubnames (pubname_table);
15163 #ifdef DEBUG_PUBTYPES_SECTION
15164 /* Output public types table if necessary. */
15165 if (!VEC_empty (pubname_entry, pubtype_table))
15167 switch_to_section (debug_pubtypes_section);
15168 output_pubnames (pubtype_table);
15172 /* Output the address range information. We only put functions in the arange
15173 table, so don't write it out if we don't have any. */
15174 if (fde_table_in_use)
15176 switch_to_section (debug_aranges_section);
15180 /* Output ranges section if necessary. */
15181 if (ranges_table_in_use)
15183 switch_to_section (debug_ranges_section);
15184 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
15188 /* Output the source line correspondence table. We must do this
15189 even if there is no line information. Otherwise, on an empty
15190 translation unit, we will generate a present, but empty,
15191 .debug_info section. IRIX 6.5 `nm' will then complain when
15192 examining the file. This is done late so that any filenames
15193 used by the debug_info section are marked as 'used'. */
15194 if (! DWARF2_ASM_LINE_DEBUG_INFO)
15196 switch_to_section (debug_line_section);
15197 output_line_info ();
15200 /* Have to end the macro section. */
15201 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15203 switch_to_section (debug_macinfo_section);
15204 dw2_asm_output_data (1, 0, "End compilation unit");
15207 /* If we emitted any DW_FORM_strp form attribute, output the string
15209 if (debug_str_hash)
15210 htab_traverse (debug_str_hash, output_indirect_string, NULL);
15214 /* This should never be used, but its address is needed for comparisons. */
15215 const struct gcc_debug_hooks dwarf2_debug_hooks;
15217 #endif /* DWARF2_DEBUGGING_INFO */
15219 #include "gt-dwarf2out.h"