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, 2009 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 /* Save the result of dwarf2out_do_frame across PCH. */
114 static GTY(()) bool saved_do_cfi_asm = 0;
116 /* Decide whether we want to emit frame unwind information for the current
120 dwarf2out_do_frame (void)
122 /* We want to emit correct CFA location expressions or lists, so we
123 have to return true if we're going to output debug info, even if
124 we're not going to output frame or unwind info. */
125 return (write_symbols == DWARF2_DEBUG
126 || write_symbols == VMS_AND_DWARF2_DEBUG
127 || DWARF2_FRAME_INFO || saved_do_cfi_asm
128 #ifdef DWARF2_UNWIND_INFO
129 || (DWARF2_UNWIND_INFO
130 && (flag_unwind_tables
131 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
136 /* Decide whether to emit frame unwind via assembler directives. */
139 dwarf2out_do_cfi_asm (void)
143 #ifdef MIPS_DEBUGGING_INFO
146 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
148 if (saved_do_cfi_asm || !eh_personality_libfunc)
150 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
153 /* Make sure the personality encoding is one the assembler can support.
154 In particular, aligned addresses can't be handled. */
155 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
156 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
158 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
159 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
162 saved_do_cfi_asm = true;
166 /* The size of the target's pointer type. */
168 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
171 /* Array of RTXes referenced by the debugging information, which therefore
172 must be kept around forever. */
173 static GTY(()) VEC(rtx,gc) *used_rtx_array;
175 /* A pointer to the base of a list of incomplete types which might be
176 completed at some later time. incomplete_types_list needs to be a
177 VEC(tree,gc) because we want to tell the garbage collector about
179 static GTY(()) VEC(tree,gc) *incomplete_types;
181 /* A pointer to the base of a table of references to declaration
182 scopes. This table is a display which tracks the nesting
183 of declaration scopes at the current scope and containing
184 scopes. This table is used to find the proper place to
185 define type declaration DIE's. */
186 static GTY(()) VEC(tree,gc) *decl_scope_table;
188 /* Pointers to various DWARF2 sections. */
189 static GTY(()) section *debug_info_section;
190 static GTY(()) section *debug_abbrev_section;
191 static GTY(()) section *debug_aranges_section;
192 static GTY(()) section *debug_macinfo_section;
193 static GTY(()) section *debug_line_section;
194 static GTY(()) section *debug_loc_section;
195 static GTY(()) section *debug_pubnames_section;
196 static GTY(()) section *debug_pubtypes_section;
197 static GTY(()) section *debug_str_section;
198 static GTY(()) section *debug_ranges_section;
199 static GTY(()) section *debug_frame_section;
201 /* How to start an assembler comment. */
202 #ifndef ASM_COMMENT_START
203 #define ASM_COMMENT_START ";#"
206 typedef struct dw_cfi_struct *dw_cfi_ref;
207 typedef struct dw_fde_struct *dw_fde_ref;
208 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
210 /* Call frames are described using a sequence of Call Frame
211 Information instructions. The register number, offset
212 and address fields are provided as possible operands;
213 their use is selected by the opcode field. */
215 enum dw_cfi_oprnd_type {
217 dw_cfi_oprnd_reg_num,
223 typedef union dw_cfi_oprnd_struct GTY(())
225 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
226 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
227 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
228 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
232 typedef struct dw_cfi_struct GTY(())
234 dw_cfi_ref dw_cfi_next;
235 enum dwarf_call_frame_info dw_cfi_opc;
236 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
238 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
243 /* This is how we define the location of the CFA. We use to handle it
244 as REG + OFFSET all the time, but now it can be more complex.
245 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
246 Instead of passing around REG and OFFSET, we pass a copy
247 of this structure. */
248 typedef struct cfa_loc GTY(())
250 HOST_WIDE_INT offset;
251 HOST_WIDE_INT base_offset;
253 int indirect; /* 1 if CFA is accessed via a dereference. */
256 /* All call frame descriptions (FDE's) in the GCC generated DWARF
257 refer to a single Common Information Entry (CIE), defined at
258 the beginning of the .debug_frame section. This use of a single
259 CIE obviates the need to keep track of multiple CIE's
260 in the DWARF generation routines below. */
262 typedef struct dw_fde_struct GTY(())
265 const char *dw_fde_begin;
266 const char *dw_fde_current_label;
267 const char *dw_fde_end;
268 const char *dw_fde_hot_section_label;
269 const char *dw_fde_hot_section_end_label;
270 const char *dw_fde_unlikely_section_label;
271 const char *dw_fde_unlikely_section_end_label;
272 bool dw_fde_switched_sections;
273 dw_cfi_ref dw_fde_cfi;
274 unsigned funcdef_number;
275 HOST_WIDE_INT stack_realignment;
276 /* Dynamic realign argument pointer register. */
277 unsigned int drap_reg;
278 /* Virtual dynamic realign argument pointer register. */
279 unsigned int vdrap_reg;
280 unsigned all_throwers_are_sibcalls : 1;
281 unsigned nothrow : 1;
282 unsigned uses_eh_lsda : 1;
283 /* Whether we did stack realign in this call frame. */
284 unsigned stack_realign : 1;
285 /* Whether dynamic realign argument pointer register has been saved. */
286 unsigned drap_reg_saved: 1;
290 /* Maximum size (in bytes) of an artificially generated label. */
291 #define MAX_ARTIFICIAL_LABEL_BYTES 30
293 /* The size of addresses as they appear in the Dwarf 2 data.
294 Some architectures use word addresses to refer to code locations,
295 but Dwarf 2 info always uses byte addresses. On such machines,
296 Dwarf 2 addresses need to be larger than the architecture's
298 #ifndef DWARF2_ADDR_SIZE
299 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
302 /* The size in bytes of a DWARF field indicating an offset or length
303 relative to a debug info section, specified to be 4 bytes in the
304 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
307 #ifndef DWARF_OFFSET_SIZE
308 #define DWARF_OFFSET_SIZE 4
311 /* According to the (draft) DWARF 3 specification, the initial length
312 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
313 bytes are 0xffffffff, followed by the length stored in the next 8
316 However, the SGI/MIPS ABI uses an initial length which is equal to
317 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
319 #ifndef DWARF_INITIAL_LENGTH_SIZE
320 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
323 #define DWARF_VERSION 2
325 /* Round SIZE up to the nearest BOUNDARY. */
326 #define DWARF_ROUND(SIZE,BOUNDARY) \
327 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
329 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
330 #ifndef DWARF_CIE_DATA_ALIGNMENT
331 #ifdef STACK_GROWS_DOWNWARD
332 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
334 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
338 /* CIE identifier. */
339 #if HOST_BITS_PER_WIDE_INT >= 64
340 #define DWARF_CIE_ID \
341 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
343 #define DWARF_CIE_ID DW_CIE_ID
346 /* A pointer to the base of a table that contains frame description
347 information for each routine. */
348 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
350 /* Number of elements currently allocated for fde_table. */
351 static GTY(()) unsigned fde_table_allocated;
353 /* Number of elements in fde_table currently in use. */
354 static GTY(()) unsigned fde_table_in_use;
356 /* Size (in elements) of increments by which we may expand the
358 #define FDE_TABLE_INCREMENT 256
360 /* Get the current fde_table entry we should use. */
362 static inline dw_fde_ref
365 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
368 /* A list of call frame insns for the CIE. */
369 static GTY(()) dw_cfi_ref cie_cfi_head;
371 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
372 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
373 attribute that accelerates the lookup of the FDE associated
374 with the subprogram. This variable holds the table index of the FDE
375 associated with the current function (body) definition. */
376 static unsigned current_funcdef_fde;
379 struct indirect_string_node GTY(())
382 unsigned int refcount;
387 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
389 static GTY(()) int dw2_string_counter;
390 static GTY(()) unsigned long dwarf2out_cfi_label_num;
392 /* True if the compilation unit places functions in more than one section. */
393 static GTY(()) bool have_multiple_function_sections = false;
395 /* Whether the default text and cold text sections have been used at all. */
397 static GTY(()) bool text_section_used = false;
398 static GTY(()) bool cold_text_section_used = false;
400 /* The default cold text section. */
401 static GTY(()) section *cold_text_section;
403 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
405 /* Forward declarations for functions defined in this file. */
407 static char *stripattributes (const char *);
408 static const char *dwarf_cfi_name (unsigned);
409 static dw_cfi_ref new_cfi (void);
410 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
411 static void add_fde_cfi (const char *, dw_cfi_ref);
412 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
413 static void lookup_cfa (dw_cfa_location *);
414 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
415 #ifdef DWARF2_UNWIND_INFO
416 static void initial_return_save (rtx);
418 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
420 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
421 static void output_cfi_directive (dw_cfi_ref);
422 static void output_call_frame_info (int);
423 static void dwarf2out_note_section_used (void);
424 static void dwarf2out_stack_adjust (rtx, bool);
425 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
426 static void flush_queued_reg_saves (void);
427 static bool clobbers_queued_reg_save (const_rtx);
428 static void dwarf2out_frame_debug_expr (rtx, const char *);
430 /* Support for complex CFA locations. */
431 static void output_cfa_loc (dw_cfi_ref);
432 static void output_cfa_loc_raw (dw_cfi_ref);
433 static void get_cfa_from_loc_descr (dw_cfa_location *,
434 struct dw_loc_descr_struct *);
435 static struct dw_loc_descr_struct *build_cfa_loc
436 (dw_cfa_location *, HOST_WIDE_INT);
437 static struct dw_loc_descr_struct *build_cfa_aligned_loc
438 (HOST_WIDE_INT, HOST_WIDE_INT);
439 static void def_cfa_1 (const char *, dw_cfa_location *);
441 /* How to start an assembler comment. */
442 #ifndef ASM_COMMENT_START
443 #define ASM_COMMENT_START ";#"
446 /* Data and reference forms for relocatable data. */
447 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
448 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
450 #ifndef DEBUG_FRAME_SECTION
451 #define DEBUG_FRAME_SECTION ".debug_frame"
454 #ifndef FUNC_BEGIN_LABEL
455 #define FUNC_BEGIN_LABEL "LFB"
458 #ifndef FUNC_END_LABEL
459 #define FUNC_END_LABEL "LFE"
462 #ifndef FRAME_BEGIN_LABEL
463 #define FRAME_BEGIN_LABEL "Lframe"
465 #define CIE_AFTER_SIZE_LABEL "LSCIE"
466 #define CIE_END_LABEL "LECIE"
467 #define FDE_LABEL "LSFDE"
468 #define FDE_AFTER_SIZE_LABEL "LASFDE"
469 #define FDE_END_LABEL "LEFDE"
470 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
471 #define LINE_NUMBER_END_LABEL "LELT"
472 #define LN_PROLOG_AS_LABEL "LASLTP"
473 #define LN_PROLOG_END_LABEL "LELTP"
474 #define DIE_LABEL_PREFIX "DW"
476 /* The DWARF 2 CFA column which tracks the return address. Normally this
477 is the column for PC, or the first column after all of the hard
479 #ifndef DWARF_FRAME_RETURN_COLUMN
481 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
483 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
487 /* The mapping from gcc register number to DWARF 2 CFA column number. By
488 default, we just provide columns for all registers. */
489 #ifndef DWARF_FRAME_REGNUM
490 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
493 /* Hook used by __throw. */
496 expand_builtin_dwarf_sp_column (void)
498 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
499 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
502 /* Return a pointer to a copy of the section string name S with all
503 attributes stripped off, and an asterisk prepended (for assemble_name). */
506 stripattributes (const char *s)
508 char *stripped = XNEWVEC (char, strlen (s) + 2);
513 while (*s && *s != ',')
520 /* MEM is a memory reference for the register size table, each element of
521 which has mode MODE. Initialize column C as a return address column. */
524 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
526 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
527 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
528 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
531 /* Generate code to initialize the register size table. */
534 expand_builtin_init_dwarf_reg_sizes (tree address)
537 enum machine_mode mode = TYPE_MODE (char_type_node);
538 rtx addr = expand_normal (address);
539 rtx mem = gen_rtx_MEM (BLKmode, addr);
540 bool wrote_return_column = false;
542 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
544 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
546 if (rnum < DWARF_FRAME_REGISTERS)
548 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
549 enum machine_mode save_mode = reg_raw_mode[i];
552 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
553 save_mode = choose_hard_reg_mode (i, 1, true);
554 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
556 if (save_mode == VOIDmode)
558 wrote_return_column = true;
560 size = GET_MODE_SIZE (save_mode);
564 emit_move_insn (adjust_address (mem, mode, offset),
565 gen_int_mode (size, mode));
569 if (!wrote_return_column)
570 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
572 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
573 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
576 targetm.init_dwarf_reg_sizes_extra (address);
579 /* Convert a DWARF call frame info. operation to its string name */
582 dwarf_cfi_name (unsigned int cfi_opc)
586 case DW_CFA_advance_loc:
587 return "DW_CFA_advance_loc";
589 return "DW_CFA_offset";
591 return "DW_CFA_restore";
595 return "DW_CFA_set_loc";
596 case DW_CFA_advance_loc1:
597 return "DW_CFA_advance_loc1";
598 case DW_CFA_advance_loc2:
599 return "DW_CFA_advance_loc2";
600 case DW_CFA_advance_loc4:
601 return "DW_CFA_advance_loc4";
602 case DW_CFA_offset_extended:
603 return "DW_CFA_offset_extended";
604 case DW_CFA_restore_extended:
605 return "DW_CFA_restore_extended";
606 case DW_CFA_undefined:
607 return "DW_CFA_undefined";
608 case DW_CFA_same_value:
609 return "DW_CFA_same_value";
610 case DW_CFA_register:
611 return "DW_CFA_register";
612 case DW_CFA_remember_state:
613 return "DW_CFA_remember_state";
614 case DW_CFA_restore_state:
615 return "DW_CFA_restore_state";
617 return "DW_CFA_def_cfa";
618 case DW_CFA_def_cfa_register:
619 return "DW_CFA_def_cfa_register";
620 case DW_CFA_def_cfa_offset:
621 return "DW_CFA_def_cfa_offset";
624 case DW_CFA_def_cfa_expression:
625 return "DW_CFA_def_cfa_expression";
626 case DW_CFA_expression:
627 return "DW_CFA_expression";
628 case DW_CFA_offset_extended_sf:
629 return "DW_CFA_offset_extended_sf";
630 case DW_CFA_def_cfa_sf:
631 return "DW_CFA_def_cfa_sf";
632 case DW_CFA_def_cfa_offset_sf:
633 return "DW_CFA_def_cfa_offset_sf";
635 /* SGI/MIPS specific */
636 case DW_CFA_MIPS_advance_loc8:
637 return "DW_CFA_MIPS_advance_loc8";
640 case DW_CFA_GNU_window_save:
641 return "DW_CFA_GNU_window_save";
642 case DW_CFA_GNU_args_size:
643 return "DW_CFA_GNU_args_size";
644 case DW_CFA_GNU_negative_offset_extended:
645 return "DW_CFA_GNU_negative_offset_extended";
648 return "DW_CFA_<unknown>";
652 /* Return a pointer to a newly allocated Call Frame Instruction. */
654 static inline dw_cfi_ref
657 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
659 cfi->dw_cfi_next = NULL;
660 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
661 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
666 /* Add a Call Frame Instruction to list of instructions. */
669 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
672 dw_fde_ref fde = current_fde ();
674 /* When DRAP is used, CFA is defined with an expression. Redefine
675 CFA may lead to a different CFA value. */
676 if (fde && fde->drap_reg != INVALID_REGNUM)
677 switch (cfi->dw_cfi_opc)
679 case DW_CFA_def_cfa_register:
680 case DW_CFA_def_cfa_offset:
681 case DW_CFA_def_cfa_offset_sf:
683 case DW_CFA_def_cfa_sf:
690 /* Find the end of the chain. */
691 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
697 /* Generate a new label for the CFI info to refer to. */
700 dwarf2out_cfi_label (void)
702 static char label[20];
704 if (dwarf2out_do_cfi_asm ())
706 /* In this case, we will be emitting the asm directive instead of
707 the label, so just return a placeholder to keep the rest of the
709 strcpy (label, "<do not output>");
713 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
714 ASM_OUTPUT_LABEL (asm_out_file, label);
720 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
721 or to the CIE if LABEL is NULL. */
724 add_fde_cfi (const char *label, dw_cfi_ref cfi)
726 dw_cfi_ref *list_head = &cie_cfi_head;
728 if (dwarf2out_do_cfi_asm ())
732 output_cfi_directive (cfi);
734 /* We still have to add the cfi to the list so that
735 lookup_cfa works later on. */
736 list_head = ¤t_fde ()->dw_fde_cfi;
738 /* ??? If this is a CFI for the CIE, we don't emit. This
739 assumes that the standard CIE contents that the assembler
740 uses matches the standard CIE contents that the compiler
741 uses. This is probably a bad assumption. I'm not quite
742 sure how to address this for now. */
746 dw_fde_ref fde = current_fde ();
748 gcc_assert (fde != NULL);
751 label = dwarf2out_cfi_label ();
753 if (fde->dw_fde_current_label == NULL
754 || strcmp (label, fde->dw_fde_current_label) != 0)
758 label = xstrdup (label);
760 /* Set the location counter to the new label. */
762 /* If we have a current label, advance from there, otherwise
763 set the location directly using set_loc. */
764 xcfi->dw_cfi_opc = fde->dw_fde_current_label
765 ? DW_CFA_advance_loc4
767 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
768 add_cfi (&fde->dw_fde_cfi, xcfi);
770 fde->dw_fde_current_label = label;
773 list_head = &fde->dw_fde_cfi;
776 add_cfi (list_head, cfi);
779 /* Subroutine of lookup_cfa. */
782 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
784 switch (cfi->dw_cfi_opc)
786 case DW_CFA_def_cfa_offset:
787 case DW_CFA_def_cfa_offset_sf:
788 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
790 case DW_CFA_def_cfa_register:
791 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
794 case DW_CFA_def_cfa_sf:
795 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
796 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
798 case DW_CFA_def_cfa_expression:
799 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
806 /* Find the previous value for the CFA. */
809 lookup_cfa (dw_cfa_location *loc)
814 loc->reg = INVALID_REGNUM;
817 loc->base_offset = 0;
819 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
820 lookup_cfa_1 (cfi, loc);
822 fde = current_fde ();
824 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
825 lookup_cfa_1 (cfi, loc);
828 /* The current rule for calculating the DWARF2 canonical frame address. */
829 static dw_cfa_location cfa;
831 /* The register used for saving registers to the stack, and its offset
833 static dw_cfa_location cfa_store;
835 /* The running total of the size of arguments pushed onto the stack. */
836 static HOST_WIDE_INT args_size;
838 /* The last args_size we actually output. */
839 static HOST_WIDE_INT old_args_size;
841 /* Entry point to update the canonical frame address (CFA).
842 LABEL is passed to add_fde_cfi. The value of CFA is now to be
843 calculated from REG+OFFSET. */
846 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
853 def_cfa_1 (label, &loc);
856 /* Determine if two dw_cfa_location structures define the same data. */
859 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
861 return (loc1->reg == loc2->reg
862 && loc1->offset == loc2->offset
863 && loc1->indirect == loc2->indirect
864 && (loc1->indirect == 0
865 || loc1->base_offset == loc2->base_offset));
868 /* This routine does the actual work. The CFA is now calculated from
869 the dw_cfa_location structure. */
872 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
875 dw_cfa_location old_cfa, loc;
880 if (cfa_store.reg == loc.reg && loc.indirect == 0)
881 cfa_store.offset = loc.offset;
883 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
884 lookup_cfa (&old_cfa);
886 /* If nothing changed, no need to issue any call frame instructions. */
887 if (cfa_equal_p (&loc, &old_cfa))
892 if (loc.reg == old_cfa.reg && !loc.indirect)
894 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
895 the CFA register did not change but the offset did. The data
896 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
897 in the assembler via the .cfi_def_cfa_offset directive. */
899 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
901 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
902 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
905 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
906 else if (loc.offset == old_cfa.offset
907 && old_cfa.reg != INVALID_REGNUM
910 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
911 indicating the CFA register has changed to <register> but the
912 offset has not changed. */
913 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
914 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
918 else if (loc.indirect == 0)
920 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
921 indicating the CFA register has changed to <register> with
922 the specified offset. The data factoring for DW_CFA_def_cfa_sf
923 happens in output_cfi, or in the assembler via the .cfi_def_cfa
926 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
928 cfi->dw_cfi_opc = DW_CFA_def_cfa;
929 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
930 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
934 /* Construct a DW_CFA_def_cfa_expression instruction to
935 calculate the CFA using a full location expression since no
936 register-offset pair is available. */
937 struct dw_loc_descr_struct *loc_list;
939 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
940 loc_list = build_cfa_loc (&loc, 0);
941 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
944 add_fde_cfi (label, cfi);
947 /* Add the CFI for saving a register. REG is the CFA column number.
948 LABEL is passed to add_fde_cfi.
949 If SREG is -1, the register is saved at OFFSET from the CFA;
950 otherwise it is saved in SREG. */
953 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
955 dw_cfi_ref cfi = new_cfi ();
956 dw_fde_ref fde = current_fde ();
958 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
960 /* When stack is aligned, store REG using DW_CFA_expression with
963 && fde->stack_realign
964 && sreg == INVALID_REGNUM)
966 cfi->dw_cfi_opc = DW_CFA_expression;
967 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
968 cfi->dw_cfi_oprnd1.dw_cfi_loc
969 = build_cfa_aligned_loc (offset, fde->stack_realignment);
971 else if (sreg == INVALID_REGNUM)
974 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
975 else if (reg & ~0x3f)
976 cfi->dw_cfi_opc = DW_CFA_offset_extended;
978 cfi->dw_cfi_opc = DW_CFA_offset;
979 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
981 else if (sreg == reg)
982 cfi->dw_cfi_opc = DW_CFA_same_value;
985 cfi->dw_cfi_opc = DW_CFA_register;
986 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
989 add_fde_cfi (label, cfi);
992 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
993 This CFI tells the unwinder that it needs to restore the window registers
994 from the previous frame's window save area.
996 ??? Perhaps we should note in the CIE where windows are saved (instead of
997 assuming 0(cfa)) and what registers are in the window. */
1000 dwarf2out_window_save (const char *label)
1002 dw_cfi_ref cfi = new_cfi ();
1004 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1005 add_fde_cfi (label, cfi);
1008 /* Add a CFI to update the running total of the size of arguments
1009 pushed onto the stack. */
1012 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1016 if (size == old_args_size)
1019 old_args_size = size;
1022 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1023 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1024 add_fde_cfi (label, cfi);
1027 /* Entry point for saving a register to the stack. REG is the GCC register
1028 number. LABEL and OFFSET are passed to reg_save. */
1031 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1033 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1036 /* Entry point for saving the return address in the stack.
1037 LABEL and OFFSET are passed to reg_save. */
1040 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1042 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1045 /* Entry point for saving the return address in a register.
1046 LABEL and SREG are passed to reg_save. */
1049 dwarf2out_return_reg (const char *label, unsigned int sreg)
1051 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1054 #ifdef DWARF2_UNWIND_INFO
1055 /* Record the initial position of the return address. RTL is
1056 INCOMING_RETURN_ADDR_RTX. */
1059 initial_return_save (rtx rtl)
1061 unsigned int reg = INVALID_REGNUM;
1062 HOST_WIDE_INT offset = 0;
1064 switch (GET_CODE (rtl))
1067 /* RA is in a register. */
1068 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1072 /* RA is on the stack. */
1073 rtl = XEXP (rtl, 0);
1074 switch (GET_CODE (rtl))
1077 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1082 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1083 offset = INTVAL (XEXP (rtl, 1));
1087 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1088 offset = -INTVAL (XEXP (rtl, 1));
1098 /* The return address is at some offset from any value we can
1099 actually load. For instance, on the SPARC it is in %i7+8. Just
1100 ignore the offset for now; it doesn't matter for unwinding frames. */
1101 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1102 initial_return_save (XEXP (rtl, 0));
1109 if (reg != DWARF_FRAME_RETURN_COLUMN)
1110 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1114 /* Given a SET, calculate the amount of stack adjustment it
1117 static HOST_WIDE_INT
1118 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1119 HOST_WIDE_INT cur_offset)
1121 const_rtx src = SET_SRC (pattern);
1122 const_rtx dest = SET_DEST (pattern);
1123 HOST_WIDE_INT offset = 0;
1126 if (dest == stack_pointer_rtx)
1128 code = GET_CODE (src);
1130 /* Assume (set (reg sp) (reg whatever)) sets args_size
1132 if (code == REG && src != stack_pointer_rtx)
1134 offset = -cur_args_size;
1135 #ifndef STACK_GROWS_DOWNWARD
1138 return offset - cur_offset;
1141 if (! (code == PLUS || code == MINUS)
1142 || XEXP (src, 0) != stack_pointer_rtx
1143 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1146 /* (set (reg sp) (plus (reg sp) (const_int))) */
1147 offset = INTVAL (XEXP (src, 1));
1153 if (MEM_P (src) && !MEM_P (dest))
1157 /* (set (mem (pre_dec (reg sp))) (foo)) */
1158 src = XEXP (dest, 0);
1159 code = GET_CODE (src);
1165 if (XEXP (src, 0) == stack_pointer_rtx)
1167 rtx val = XEXP (XEXP (src, 1), 1);
1168 /* We handle only adjustments by constant amount. */
1169 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1170 && GET_CODE (val) == CONST_INT);
1171 offset = -INTVAL (val);
1178 if (XEXP (src, 0) == stack_pointer_rtx)
1180 offset = GET_MODE_SIZE (GET_MODE (dest));
1187 if (XEXP (src, 0) == stack_pointer_rtx)
1189 offset = -GET_MODE_SIZE (GET_MODE (dest));
1204 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1205 indexed by INSN_UID. */
1207 static HOST_WIDE_INT *barrier_args_size;
1209 /* Helper function for compute_barrier_args_size. Handle one insn. */
1211 static HOST_WIDE_INT
1212 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1213 VEC (rtx, heap) **next)
1215 HOST_WIDE_INT offset = 0;
1218 if (! RTX_FRAME_RELATED_P (insn))
1220 if (prologue_epilogue_contains (insn)
1221 || sibcall_epilogue_contains (insn))
1223 else if (GET_CODE (PATTERN (insn)) == SET)
1224 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1225 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1226 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1228 /* There may be stack adjustments inside compound insns. Search
1230 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1231 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1232 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1233 cur_args_size, offset);
1238 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1242 expr = XEXP (expr, 0);
1243 if (GET_CODE (expr) == PARALLEL
1244 || GET_CODE (expr) == SEQUENCE)
1245 for (i = 1; i < XVECLEN (expr, 0); i++)
1247 rtx elem = XVECEXP (expr, 0, i);
1249 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1250 offset += stack_adjust_offset (elem, cur_args_size, offset);
1255 #ifndef STACK_GROWS_DOWNWARD
1259 cur_args_size += offset;
1260 if (cur_args_size < 0)
1265 rtx dest = JUMP_LABEL (insn);
1269 if (barrier_args_size [INSN_UID (dest)] < 0)
1271 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1272 VEC_safe_push (rtx, heap, *next, dest);
1277 return cur_args_size;
1280 /* Walk the whole function and compute args_size on BARRIERs. */
1283 compute_barrier_args_size (void)
1285 int max_uid = get_max_uid (), i;
1287 VEC (rtx, heap) *worklist, *next, *tmp;
1289 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1290 for (i = 0; i < max_uid; i++)
1291 barrier_args_size[i] = -1;
1293 worklist = VEC_alloc (rtx, heap, 20);
1294 next = VEC_alloc (rtx, heap, 20);
1295 insn = get_insns ();
1296 barrier_args_size[INSN_UID (insn)] = 0;
1297 VEC_quick_push (rtx, worklist, insn);
1300 while (!VEC_empty (rtx, worklist))
1302 rtx prev, body, first_insn;
1303 HOST_WIDE_INT cur_args_size;
1305 first_insn = insn = VEC_pop (rtx, worklist);
1306 cur_args_size = barrier_args_size[INSN_UID (insn)];
1307 prev = prev_nonnote_insn (insn);
1308 if (prev && BARRIER_P (prev))
1309 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1311 for (; insn; insn = NEXT_INSN (insn))
1313 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1315 if (BARRIER_P (insn))
1320 if (insn == first_insn)
1322 else if (barrier_args_size[INSN_UID (insn)] < 0)
1324 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1329 /* The insns starting with this label have been
1330 already scanned or are in the worklist. */
1335 body = PATTERN (insn);
1336 if (GET_CODE (body) == SEQUENCE)
1338 HOST_WIDE_INT dest_args_size = cur_args_size;
1339 for (i = 1; i < XVECLEN (body, 0); i++)
1340 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1341 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1343 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1344 dest_args_size, &next);
1347 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1348 cur_args_size, &next);
1350 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1351 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1352 dest_args_size, &next);
1355 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1356 cur_args_size, &next);
1360 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1364 if (VEC_empty (rtx, next))
1367 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1371 VEC_truncate (rtx, next, 0);
1374 VEC_free (rtx, heap, worklist);
1375 VEC_free (rtx, heap, next);
1379 /* Check INSN to see if it looks like a push or a stack adjustment, and
1380 make a note of it if it does. EH uses this information to find out how
1381 much extra space it needs to pop off the stack. */
1384 dwarf2out_stack_adjust (rtx insn, bool after_p)
1386 HOST_WIDE_INT offset;
1390 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1391 with this function. Proper support would require all frame-related
1392 insns to be marked, and to be able to handle saving state around
1393 epilogues textually in the middle of the function. */
1394 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1397 /* If INSN is an instruction from target of an annulled branch, the
1398 effects are for the target only and so current argument size
1399 shouldn't change at all. */
1401 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1402 && INSN_FROM_TARGET_P (insn))
1405 /* If only calls can throw, and we have a frame pointer,
1406 save up adjustments until we see the CALL_INSN. */
1407 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1409 if (CALL_P (insn) && !after_p)
1411 /* Extract the size of the args from the CALL rtx itself. */
1412 insn = PATTERN (insn);
1413 if (GET_CODE (insn) == PARALLEL)
1414 insn = XVECEXP (insn, 0, 0);
1415 if (GET_CODE (insn) == SET)
1416 insn = SET_SRC (insn);
1417 gcc_assert (GET_CODE (insn) == CALL);
1418 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1423 if (CALL_P (insn) && !after_p)
1425 if (!flag_asynchronous_unwind_tables)
1426 dwarf2out_args_size ("", args_size);
1429 else if (BARRIER_P (insn))
1431 /* Don't call compute_barrier_args_size () if the only
1432 BARRIER is at the end of function. */
1433 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1434 compute_barrier_args_size ();
1435 if (barrier_args_size == NULL)
1439 offset = barrier_args_size[INSN_UID (insn)];
1444 offset -= args_size;
1445 #ifndef STACK_GROWS_DOWNWARD
1449 else if (GET_CODE (PATTERN (insn)) == SET)
1450 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1451 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1452 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1454 /* There may be stack adjustments inside compound insns. Search
1456 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1457 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1458 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1467 label = dwarf2out_cfi_label ();
1468 dwarf2out_args_size_adjust (offset, label);
1471 /* Adjust args_size based on stack adjustment OFFSET. */
1474 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1476 if (cfa.reg == STACK_POINTER_REGNUM)
1477 cfa.offset += offset;
1479 if (cfa_store.reg == STACK_POINTER_REGNUM)
1480 cfa_store.offset += offset;
1482 #ifndef STACK_GROWS_DOWNWARD
1486 args_size += offset;
1490 def_cfa_1 (label, &cfa);
1491 if (flag_asynchronous_unwind_tables)
1492 dwarf2out_args_size (label, args_size);
1497 /* We delay emitting a register save until either (a) we reach the end
1498 of the prologue or (b) the register is clobbered. This clusters
1499 register saves so that there are fewer pc advances. */
1501 struct queued_reg_save GTY(())
1503 struct queued_reg_save *next;
1505 HOST_WIDE_INT cfa_offset;
1509 static GTY(()) struct queued_reg_save *queued_reg_saves;
1511 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1512 struct reg_saved_in_data GTY(()) {
1517 /* A list of registers saved in other registers.
1518 The list intentionally has a small maximum capacity of 4; if your
1519 port needs more than that, you might consider implementing a
1520 more efficient data structure. */
1521 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1522 static GTY(()) size_t num_regs_saved_in_regs;
1524 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1525 static const char *last_reg_save_label;
1527 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1528 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1531 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1533 struct queued_reg_save *q;
1535 /* Duplicates waste space, but it's also necessary to remove them
1536 for correctness, since the queue gets output in reverse
1538 for (q = queued_reg_saves; q != NULL; q = q->next)
1539 if (REGNO (q->reg) == REGNO (reg))
1544 q = GGC_NEW (struct queued_reg_save);
1545 q->next = queued_reg_saves;
1546 queued_reg_saves = q;
1550 q->cfa_offset = offset;
1551 q->saved_reg = sreg;
1553 last_reg_save_label = label;
1556 /* Output all the entries in QUEUED_REG_SAVES. */
1559 flush_queued_reg_saves (void)
1561 struct queued_reg_save *q;
1563 for (q = queued_reg_saves; q; q = q->next)
1566 unsigned int reg, sreg;
1568 for (i = 0; i < num_regs_saved_in_regs; i++)
1569 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1571 if (q->saved_reg && i == num_regs_saved_in_regs)
1573 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1574 num_regs_saved_in_regs++;
1576 if (i != num_regs_saved_in_regs)
1578 regs_saved_in_regs[i].orig_reg = q->reg;
1579 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1582 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1584 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1586 sreg = INVALID_REGNUM;
1587 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1590 queued_reg_saves = NULL;
1591 last_reg_save_label = NULL;
1594 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1595 location for? Or, does it clobber a register which we've previously
1596 said that some other register is saved in, and for which we now
1597 have a new location for? */
1600 clobbers_queued_reg_save (const_rtx insn)
1602 struct queued_reg_save *q;
1604 for (q = queued_reg_saves; q; q = q->next)
1607 if (modified_in_p (q->reg, insn))
1609 for (i = 0; i < num_regs_saved_in_regs; i++)
1610 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1611 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1618 /* Entry point for saving the first register into the second. */
1621 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1624 unsigned int regno, sregno;
1626 for (i = 0; i < num_regs_saved_in_regs; i++)
1627 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1629 if (i == num_regs_saved_in_regs)
1631 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1632 num_regs_saved_in_regs++;
1634 regs_saved_in_regs[i].orig_reg = reg;
1635 regs_saved_in_regs[i].saved_in_reg = sreg;
1637 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1638 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1639 reg_save (label, regno, sregno, 0);
1642 /* What register, if any, is currently saved in REG? */
1645 reg_saved_in (rtx reg)
1647 unsigned int regn = REGNO (reg);
1649 struct queued_reg_save *q;
1651 for (q = queued_reg_saves; q; q = q->next)
1652 if (q->saved_reg && regn == REGNO (q->saved_reg))
1655 for (i = 0; i < num_regs_saved_in_regs; i++)
1656 if (regs_saved_in_regs[i].saved_in_reg
1657 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1658 return regs_saved_in_regs[i].orig_reg;
1664 /* A temporary register holding an integral value used in adjusting SP
1665 or setting up the store_reg. The "offset" field holds the integer
1666 value, not an offset. */
1667 static dw_cfa_location cfa_temp;
1669 /* Record call frame debugging information for an expression EXPR,
1670 which either sets SP or FP (adjusting how we calculate the frame
1671 address) or saves a register to the stack or another register.
1672 LABEL indicates the address of EXPR.
1674 This function encodes a state machine mapping rtxes to actions on
1675 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1676 users need not read the source code.
1678 The High-Level Picture
1680 Changes in the register we use to calculate the CFA: Currently we
1681 assume that if you copy the CFA register into another register, we
1682 should take the other one as the new CFA register; this seems to
1683 work pretty well. If it's wrong for some target, it's simple
1684 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1686 Changes in the register we use for saving registers to the stack:
1687 This is usually SP, but not always. Again, we deduce that if you
1688 copy SP into another register (and SP is not the CFA register),
1689 then the new register is the one we will be using for register
1690 saves. This also seems to work.
1692 Register saves: There's not much guesswork about this one; if
1693 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1694 register save, and the register used to calculate the destination
1695 had better be the one we think we're using for this purpose.
1696 It's also assumed that a copy from a call-saved register to another
1697 register is saving that register if RTX_FRAME_RELATED_P is set on
1698 that instruction. If the copy is from a call-saved register to
1699 the *same* register, that means that the register is now the same
1700 value as in the caller.
1702 Except: If the register being saved is the CFA register, and the
1703 offset is nonzero, we are saving the CFA, so we assume we have to
1704 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1705 the intent is to save the value of SP from the previous frame.
1707 In addition, if a register has previously been saved to a different
1710 Invariants / Summaries of Rules
1712 cfa current rule for calculating the CFA. It usually
1713 consists of a register and an offset.
1714 cfa_store register used by prologue code to save things to the stack
1715 cfa_store.offset is the offset from the value of
1716 cfa_store.reg to the actual CFA
1717 cfa_temp register holding an integral value. cfa_temp.offset
1718 stores the value, which will be used to adjust the
1719 stack pointer. cfa_temp is also used like cfa_store,
1720 to track stores to the stack via fp or a temp reg.
1722 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1723 with cfa.reg as the first operand changes the cfa.reg and its
1724 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1727 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1728 expression yielding a constant. This sets cfa_temp.reg
1729 and cfa_temp.offset.
1731 Rule 5: Create a new register cfa_store used to save items to the
1734 Rules 10-14: Save a register to the stack. Define offset as the
1735 difference of the original location and cfa_store's
1736 location (or cfa_temp's location if cfa_temp is used).
1738 Rules 16-20: If AND operation happens on sp in prologue, we assume
1739 stack is realigned. We will use a group of DW_OP_XXX
1740 expressions to represent the location of the stored
1741 register instead of CFA+offset.
1745 "{a,b}" indicates a choice of a xor b.
1746 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1749 (set <reg1> <reg2>:cfa.reg)
1750 effects: cfa.reg = <reg1>
1751 cfa.offset unchanged
1752 cfa_temp.reg = <reg1>
1753 cfa_temp.offset = cfa.offset
1756 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1757 {<const_int>,<reg>:cfa_temp.reg}))
1758 effects: cfa.reg = sp if fp used
1759 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1760 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1761 if cfa_store.reg==sp
1764 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1765 effects: cfa.reg = fp
1766 cfa_offset += +/- <const_int>
1769 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1770 constraints: <reg1> != fp
1772 effects: cfa.reg = <reg1>
1773 cfa_temp.reg = <reg1>
1774 cfa_temp.offset = cfa.offset
1777 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1778 constraints: <reg1> != fp
1780 effects: cfa_store.reg = <reg1>
1781 cfa_store.offset = cfa.offset - cfa_temp.offset
1784 (set <reg> <const_int>)
1785 effects: cfa_temp.reg = <reg>
1786 cfa_temp.offset = <const_int>
1789 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1790 effects: cfa_temp.reg = <reg1>
1791 cfa_temp.offset |= <const_int>
1794 (set <reg> (high <exp>))
1798 (set <reg> (lo_sum <exp> <const_int>))
1799 effects: cfa_temp.reg = <reg>
1800 cfa_temp.offset = <const_int>
1803 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1804 effects: cfa_store.offset -= <const_int>
1805 cfa.offset = cfa_store.offset if cfa.reg == sp
1807 cfa.base_offset = -cfa_store.offset
1810 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1811 effects: cfa_store.offset += -/+ mode_size(mem)
1812 cfa.offset = cfa_store.offset if cfa.reg == sp
1814 cfa.base_offset = -cfa_store.offset
1817 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1820 effects: cfa.reg = <reg1>
1821 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1824 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1825 effects: cfa.reg = <reg1>
1826 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1829 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1830 effects: cfa.reg = <reg1>
1831 cfa.base_offset = -cfa_temp.offset
1832 cfa_temp.offset -= mode_size(mem)
1835 (set <reg> {unspec, unspec_volatile})
1836 effects: target-dependent
1839 (set sp (and: sp <const_int>))
1840 constraints: cfa_store.reg == sp
1841 effects: current_fde.stack_realign = 1
1842 cfa_store.offset = 0
1843 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1846 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1847 effects: cfa_store.offset += -/+ mode_size(mem)
1850 (set (mem ({pre_inc, pre_dec} sp)) fp)
1851 constraints: fde->stack_realign == 1
1852 effects: cfa_store.offset = 0
1853 cfa.reg != HARD_FRAME_POINTER_REGNUM
1856 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1857 constraints: fde->stack_realign == 1
1859 && cfa.indirect == 0
1860 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1861 effects: Use DW_CFA_def_cfa_expression to define cfa
1862 cfa.reg == fde->drap_reg
1865 (set reg fde->drap_reg)
1866 constraints: fde->vdrap_reg == INVALID_REGNUM
1867 effects: fde->vdrap_reg = reg.
1868 (set mem fde->drap_reg)
1869 constraints: fde->drap_reg_saved == 1
1873 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1875 rtx src, dest, span;
1876 HOST_WIDE_INT offset;
1879 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1880 the PARALLEL independently. The first element is always processed if
1881 it is a SET. This is for backward compatibility. Other elements
1882 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1883 flag is set in them. */
1884 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1887 int limit = XVECLEN (expr, 0);
1890 /* PARALLELs have strict read-modify-write semantics, so we
1891 ought to evaluate every rvalue before changing any lvalue.
1892 It's cumbersome to do that in general, but there's an
1893 easy approximation that is enough for all current users:
1894 handle register saves before register assignments. */
1895 if (GET_CODE (expr) == PARALLEL)
1896 for (par_index = 0; par_index < limit; par_index++)
1898 elem = XVECEXP (expr, 0, par_index);
1899 if (GET_CODE (elem) == SET
1900 && MEM_P (SET_DEST (elem))
1901 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1902 dwarf2out_frame_debug_expr (elem, label);
1905 for (par_index = 0; par_index < limit; par_index++)
1907 elem = XVECEXP (expr, 0, par_index);
1908 if (GET_CODE (elem) == SET
1909 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1910 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1911 dwarf2out_frame_debug_expr (elem, label);
1912 else if (GET_CODE (elem) == SET
1914 && !RTX_FRAME_RELATED_P (elem))
1916 /* Stack adjustment combining might combine some post-prologue
1917 stack adjustment into a prologue stack adjustment. */
1918 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
1921 dwarf2out_args_size_adjust (offset, label);
1927 gcc_assert (GET_CODE (expr) == SET);
1929 src = SET_SRC (expr);
1930 dest = SET_DEST (expr);
1934 rtx rsi = reg_saved_in (src);
1939 fde = current_fde ();
1941 if (GET_CODE (src) == REG
1943 && fde->drap_reg == REGNO (src)
1944 && (fde->drap_reg_saved
1945 || GET_CODE (dest) == REG))
1948 /* If we are saving dynamic realign argument pointer to a
1949 register, the destination is virtual dynamic realign
1950 argument pointer. It may be used to access argument. */
1951 if (GET_CODE (dest) == REG)
1953 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
1954 fde->vdrap_reg = REGNO (dest);
1959 switch (GET_CODE (dest))
1962 switch (GET_CODE (src))
1964 /* Setting FP from SP. */
1966 if (cfa.reg == (unsigned) REGNO (src))
1969 /* Update the CFA rule wrt SP or FP. Make sure src is
1970 relative to the current CFA register.
1972 We used to require that dest be either SP or FP, but the
1973 ARM copies SP to a temporary register, and from there to
1974 FP. So we just rely on the backends to only set
1975 RTX_FRAME_RELATED_P on appropriate insns. */
1976 cfa.reg = REGNO (dest);
1977 cfa_temp.reg = cfa.reg;
1978 cfa_temp.offset = cfa.offset;
1982 /* Saving a register in a register. */
1983 gcc_assert (!fixed_regs [REGNO (dest)]
1984 /* For the SPARC and its register window. */
1985 || (DWARF_FRAME_REGNUM (REGNO (src))
1986 == DWARF_FRAME_RETURN_COLUMN));
1988 /* After stack is aligned, we can only save SP in FP
1989 if drap register is used. In this case, we have
1990 to restore stack pointer with the CFA value and we
1991 don't generate this DWARF information. */
1993 && fde->stack_realign
1994 && REGNO (src) == STACK_POINTER_REGNUM)
1995 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
1996 && fde->drap_reg != INVALID_REGNUM
1997 && cfa.reg != REGNO (src));
1999 queue_reg_save (label, src, dest, 0);
2006 if (dest == stack_pointer_rtx)
2010 switch (GET_CODE (XEXP (src, 1)))
2013 offset = INTVAL (XEXP (src, 1));
2016 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2018 offset = cfa_temp.offset;
2024 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2026 /* Restoring SP from FP in the epilogue. */
2027 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2028 cfa.reg = STACK_POINTER_REGNUM;
2030 else if (GET_CODE (src) == LO_SUM)
2031 /* Assume we've set the source reg of the LO_SUM from sp. */
2034 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2036 if (GET_CODE (src) != MINUS)
2038 if (cfa.reg == STACK_POINTER_REGNUM)
2039 cfa.offset += offset;
2040 if (cfa_store.reg == STACK_POINTER_REGNUM)
2041 cfa_store.offset += offset;
2043 else if (dest == hard_frame_pointer_rtx)
2046 /* Either setting the FP from an offset of the SP,
2047 or adjusting the FP */
2048 gcc_assert (frame_pointer_needed);
2050 gcc_assert (REG_P (XEXP (src, 0))
2051 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2052 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2053 offset = INTVAL (XEXP (src, 1));
2054 if (GET_CODE (src) != MINUS)
2056 cfa.offset += offset;
2057 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2061 gcc_assert (GET_CODE (src) != MINUS);
2064 if (REG_P (XEXP (src, 0))
2065 && REGNO (XEXP (src, 0)) == cfa.reg
2066 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2068 /* Setting a temporary CFA register that will be copied
2069 into the FP later on. */
2070 offset = - INTVAL (XEXP (src, 1));
2071 cfa.offset += offset;
2072 cfa.reg = REGNO (dest);
2073 /* Or used to save regs to the stack. */
2074 cfa_temp.reg = cfa.reg;
2075 cfa_temp.offset = cfa.offset;
2079 else if (REG_P (XEXP (src, 0))
2080 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2081 && XEXP (src, 1) == stack_pointer_rtx)
2083 /* Setting a scratch register that we will use instead
2084 of SP for saving registers to the stack. */
2085 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2086 cfa_store.reg = REGNO (dest);
2087 cfa_store.offset = cfa.offset - cfa_temp.offset;
2091 else if (GET_CODE (src) == LO_SUM
2092 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2094 cfa_temp.reg = REGNO (dest);
2095 cfa_temp.offset = INTVAL (XEXP (src, 1));
2104 cfa_temp.reg = REGNO (dest);
2105 cfa_temp.offset = INTVAL (src);
2110 gcc_assert (REG_P (XEXP (src, 0))
2111 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2112 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2114 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2115 cfa_temp.reg = REGNO (dest);
2116 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2119 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2120 which will fill in all of the bits. */
2127 case UNSPEC_VOLATILE:
2128 gcc_assert (targetm.dwarf_handle_frame_unspec);
2129 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2134 /* If this AND operation happens on stack pointer in prologue,
2135 we assume the stack is realigned and we extract the
2137 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2139 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2140 fde->stack_realign = 1;
2141 fde->stack_realignment = INTVAL (XEXP (src, 1));
2142 cfa_store.offset = 0;
2144 if (cfa.reg != STACK_POINTER_REGNUM
2145 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2146 fde->drap_reg = cfa.reg;
2154 def_cfa_1 (label, &cfa);
2159 /* Saving a register to the stack. Make sure dest is relative to the
2161 switch (GET_CODE (XEXP (dest, 0)))
2166 /* We can't handle variable size modifications. */
2167 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2169 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2171 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2172 && cfa_store.reg == STACK_POINTER_REGNUM);
2174 cfa_store.offset += offset;
2175 if (cfa.reg == STACK_POINTER_REGNUM)
2176 cfa.offset = cfa_store.offset;
2178 offset = -cfa_store.offset;
2184 offset = GET_MODE_SIZE (GET_MODE (dest));
2185 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2188 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2189 == STACK_POINTER_REGNUM)
2190 && cfa_store.reg == STACK_POINTER_REGNUM);
2192 cfa_store.offset += offset;
2194 /* Rule 18: If stack is aligned, we will use FP as a
2195 reference to represent the address of the stored
2198 && fde->stack_realign
2199 && src == hard_frame_pointer_rtx)
2201 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2202 cfa_store.offset = 0;
2205 if (cfa.reg == STACK_POINTER_REGNUM)
2206 cfa.offset = cfa_store.offset;
2208 offset = -cfa_store.offset;
2212 /* With an offset. */
2219 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2220 && REG_P (XEXP (XEXP (dest, 0), 0)));
2221 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2222 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2225 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2227 if (cfa_store.reg == (unsigned) regno)
2228 offset -= cfa_store.offset;
2231 gcc_assert (cfa_temp.reg == (unsigned) regno);
2232 offset -= cfa_temp.offset;
2238 /* Without an offset. */
2241 int regno = REGNO (XEXP (dest, 0));
2243 if (cfa_store.reg == (unsigned) regno)
2244 offset = -cfa_store.offset;
2247 gcc_assert (cfa_temp.reg == (unsigned) regno);
2248 offset = -cfa_temp.offset;
2255 gcc_assert (cfa_temp.reg
2256 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2257 offset = -cfa_temp.offset;
2258 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2266 /* If the source operand of this MEM operation is not a
2267 register, basically the source is return address. Here
2268 we only care how much stack grew and we don't save it. */
2272 if (REGNO (src) != STACK_POINTER_REGNUM
2273 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2274 && (unsigned) REGNO (src) == cfa.reg)
2276 /* We're storing the current CFA reg into the stack. */
2278 if (cfa.offset == 0)
2281 /* If stack is aligned, putting CFA reg into stack means
2282 we can no longer use reg + offset to represent CFA.
2283 Here we use DW_CFA_def_cfa_expression instead. The
2284 result of this expression equals to the original CFA
2287 && fde->stack_realign
2288 && cfa.indirect == 0
2289 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2291 dw_cfa_location cfa_exp;
2293 gcc_assert (fde->drap_reg == cfa.reg);
2295 cfa_exp.indirect = 1;
2296 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2297 cfa_exp.base_offset = offset;
2300 fde->drap_reg_saved = 1;
2302 def_cfa_1 (label, &cfa_exp);
2306 /* If the source register is exactly the CFA, assume
2307 we're saving SP like any other register; this happens
2309 def_cfa_1 (label, &cfa);
2310 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2315 /* Otherwise, we'll need to look in the stack to
2316 calculate the CFA. */
2317 rtx x = XEXP (dest, 0);
2321 gcc_assert (REG_P (x));
2323 cfa.reg = REGNO (x);
2324 cfa.base_offset = offset;
2326 def_cfa_1 (label, &cfa);
2331 def_cfa_1 (label, &cfa);
2333 span = targetm.dwarf_register_span (src);
2336 queue_reg_save (label, src, NULL_RTX, offset);
2339 /* We have a PARALLEL describing where the contents of SRC
2340 live. Queue register saves for each piece of the
2344 HOST_WIDE_INT span_offset = offset;
2346 gcc_assert (GET_CODE (span) == PARALLEL);
2348 limit = XVECLEN (span, 0);
2349 for (par_index = 0; par_index < limit; par_index++)
2351 rtx elem = XVECEXP (span, 0, par_index);
2353 queue_reg_save (label, elem, NULL_RTX, span_offset);
2354 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2365 /* Record call frame debugging information for INSN, which either
2366 sets SP or FP (adjusting how we calculate the frame address) or saves a
2367 register to the stack. If INSN is NULL_RTX, initialize our state.
2369 If AFTER_P is false, we're being called before the insn is emitted,
2370 otherwise after. Call instructions get invoked twice. */
2373 dwarf2out_frame_debug (rtx insn, bool after_p)
2378 if (insn == NULL_RTX)
2382 /* Flush any queued register saves. */
2383 flush_queued_reg_saves ();
2385 /* Set up state for generating call frame debug info. */
2388 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2390 cfa.reg = STACK_POINTER_REGNUM;
2393 cfa_temp.offset = 0;
2395 for (i = 0; i < num_regs_saved_in_regs; i++)
2397 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2398 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2400 num_regs_saved_in_regs = 0;
2402 if (barrier_args_size)
2404 XDELETEVEC (barrier_args_size);
2405 barrier_args_size = NULL;
2410 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2411 flush_queued_reg_saves ();
2413 if (! RTX_FRAME_RELATED_P (insn))
2415 if (!ACCUMULATE_OUTGOING_ARGS)
2416 dwarf2out_stack_adjust (insn, after_p);
2420 label = dwarf2out_cfi_label ();
2421 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2423 insn = XEXP (src, 0);
2425 insn = PATTERN (insn);
2427 dwarf2out_frame_debug_expr (insn, label);
2432 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2433 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2434 (enum dwarf_call_frame_info cfi);
2436 static enum dw_cfi_oprnd_type
2437 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2442 case DW_CFA_GNU_window_save:
2443 return dw_cfi_oprnd_unused;
2445 case DW_CFA_set_loc:
2446 case DW_CFA_advance_loc1:
2447 case DW_CFA_advance_loc2:
2448 case DW_CFA_advance_loc4:
2449 case DW_CFA_MIPS_advance_loc8:
2450 return dw_cfi_oprnd_addr;
2453 case DW_CFA_offset_extended:
2454 case DW_CFA_def_cfa:
2455 case DW_CFA_offset_extended_sf:
2456 case DW_CFA_def_cfa_sf:
2457 case DW_CFA_restore_extended:
2458 case DW_CFA_undefined:
2459 case DW_CFA_same_value:
2460 case DW_CFA_def_cfa_register:
2461 case DW_CFA_register:
2462 return dw_cfi_oprnd_reg_num;
2464 case DW_CFA_def_cfa_offset:
2465 case DW_CFA_GNU_args_size:
2466 case DW_CFA_def_cfa_offset_sf:
2467 return dw_cfi_oprnd_offset;
2469 case DW_CFA_def_cfa_expression:
2470 case DW_CFA_expression:
2471 return dw_cfi_oprnd_loc;
2478 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2479 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2480 (enum dwarf_call_frame_info cfi);
2482 static enum dw_cfi_oprnd_type
2483 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2487 case DW_CFA_def_cfa:
2488 case DW_CFA_def_cfa_sf:
2490 case DW_CFA_offset_extended_sf:
2491 case DW_CFA_offset_extended:
2492 return dw_cfi_oprnd_offset;
2494 case DW_CFA_register:
2495 return dw_cfi_oprnd_reg_num;
2498 return dw_cfi_oprnd_unused;
2502 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2504 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2505 switch to the data section instead, and write out a synthetic label
2509 switch_to_eh_frame_section (void)
2513 #ifdef EH_FRAME_SECTION_NAME
2514 if (eh_frame_section == 0)
2518 if (EH_TABLES_CAN_BE_READ_ONLY)
2524 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2526 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2528 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2530 flags = ((! flag_pic
2531 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2532 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2533 && (per_encoding & 0x70) != DW_EH_PE_absptr
2534 && (per_encoding & 0x70) != DW_EH_PE_aligned
2535 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2536 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2537 ? 0 : SECTION_WRITE);
2540 flags = SECTION_WRITE;
2541 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2545 if (eh_frame_section)
2546 switch_to_section (eh_frame_section);
2549 /* We have no special eh_frame section. Put the information in
2550 the data section and emit special labels to guide collect2. */
2551 switch_to_section (data_section);
2552 label = get_file_function_name ("F");
2553 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2554 targetm.asm_out.globalize_label (asm_out_file,
2555 IDENTIFIER_POINTER (label));
2556 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2560 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2562 static HOST_WIDE_INT
2563 div_data_align (HOST_WIDE_INT off)
2565 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
2566 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
2570 /* Output a Call Frame Information opcode and its operand(s). */
2573 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2578 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2579 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2580 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2581 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2582 ((unsigned HOST_WIDE_INT)
2583 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2584 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2586 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2587 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2588 "DW_CFA_offset, column 0x%lx", r);
2589 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2590 dw2_asm_output_data_uleb128 (off, NULL);
2592 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2594 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2595 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2596 "DW_CFA_restore, column 0x%lx", r);
2600 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2601 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2603 switch (cfi->dw_cfi_opc)
2605 case DW_CFA_set_loc:
2607 dw2_asm_output_encoded_addr_rtx (
2608 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2609 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2612 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2613 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2614 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2617 case DW_CFA_advance_loc1:
2618 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2619 fde->dw_fde_current_label, NULL);
2620 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2623 case DW_CFA_advance_loc2:
2624 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2625 fde->dw_fde_current_label, NULL);
2626 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2629 case DW_CFA_advance_loc4:
2630 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2631 fde->dw_fde_current_label, NULL);
2632 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2635 case DW_CFA_MIPS_advance_loc8:
2636 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2637 fde->dw_fde_current_label, NULL);
2638 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2641 case DW_CFA_offset_extended:
2642 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2643 dw2_asm_output_data_uleb128 (r, NULL);
2644 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2645 dw2_asm_output_data_uleb128 (off, NULL);
2648 case DW_CFA_def_cfa:
2649 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2650 dw2_asm_output_data_uleb128 (r, NULL);
2651 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2654 case DW_CFA_offset_extended_sf:
2655 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2656 dw2_asm_output_data_uleb128 (r, NULL);
2657 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2658 dw2_asm_output_data_sleb128 (off, NULL);
2661 case DW_CFA_def_cfa_sf:
2662 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2663 dw2_asm_output_data_uleb128 (r, NULL);
2664 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2665 dw2_asm_output_data_sleb128 (off, NULL);
2668 case DW_CFA_restore_extended:
2669 case DW_CFA_undefined:
2670 case DW_CFA_same_value:
2671 case DW_CFA_def_cfa_register:
2672 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2673 dw2_asm_output_data_uleb128 (r, NULL);
2676 case DW_CFA_register:
2677 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2678 dw2_asm_output_data_uleb128 (r, NULL);
2679 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2680 dw2_asm_output_data_uleb128 (r, NULL);
2683 case DW_CFA_def_cfa_offset:
2684 case DW_CFA_GNU_args_size:
2685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2688 case DW_CFA_def_cfa_offset_sf:
2689 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2690 dw2_asm_output_data_sleb128 (off, NULL);
2693 case DW_CFA_GNU_window_save:
2696 case DW_CFA_def_cfa_expression:
2697 case DW_CFA_expression:
2698 output_cfa_loc (cfi);
2701 case DW_CFA_GNU_negative_offset_extended:
2702 /* Obsoleted by DW_CFA_offset_extended_sf. */
2711 /* Similar, but do it via assembler directives instead. */
2714 output_cfi_directive (dw_cfi_ref cfi)
2716 unsigned long r, r2;
2718 switch (cfi->dw_cfi_opc)
2720 case DW_CFA_advance_loc:
2721 case DW_CFA_advance_loc1:
2722 case DW_CFA_advance_loc2:
2723 case DW_CFA_advance_loc4:
2724 case DW_CFA_MIPS_advance_loc8:
2725 case DW_CFA_set_loc:
2726 /* Should only be created by add_fde_cfi in a code path not
2727 followed when emitting via directives. The assembler is
2728 going to take care of this for us. */
2732 case DW_CFA_offset_extended:
2733 case DW_CFA_offset_extended_sf:
2734 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2735 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2736 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2739 case DW_CFA_restore:
2740 case DW_CFA_restore_extended:
2741 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2742 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
2745 case DW_CFA_undefined:
2746 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2747 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
2750 case DW_CFA_same_value:
2751 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2752 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
2755 case DW_CFA_def_cfa:
2756 case DW_CFA_def_cfa_sf:
2757 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2758 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2759 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2762 case DW_CFA_def_cfa_register:
2763 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2764 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
2767 case DW_CFA_register:
2768 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2769 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 0);
2770 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
2773 case DW_CFA_def_cfa_offset:
2774 case DW_CFA_def_cfa_offset_sf:
2775 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
2776 HOST_WIDE_INT_PRINT_DEC"\n",
2777 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2780 case DW_CFA_GNU_args_size:
2781 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
2782 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2784 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
2785 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
2786 fputc ('\n', asm_out_file);
2789 case DW_CFA_GNU_window_save:
2790 fprintf (asm_out_file, "\t.cfi_window_save\n");
2793 case DW_CFA_def_cfa_expression:
2794 case DW_CFA_expression:
2795 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
2796 output_cfa_loc_raw (cfi);
2797 fputc ('\n', asm_out_file);
2805 /* Output the call frame information used to record information
2806 that relates to calculating the frame pointer, and records the
2807 location of saved registers. */
2810 output_call_frame_info (int for_eh)
2815 char l1[20], l2[20], section_start_label[20];
2816 bool any_lsda_needed = false;
2817 char augmentation[6];
2818 int augmentation_size;
2819 int fde_encoding = DW_EH_PE_absptr;
2820 int per_encoding = DW_EH_PE_absptr;
2821 int lsda_encoding = DW_EH_PE_absptr;
2824 /* Don't emit a CIE if there won't be any FDEs. */
2825 if (fde_table_in_use == 0)
2828 /* Nothing to do if the assembler's doing it all. */
2829 if (dwarf2out_do_cfi_asm ())
2832 /* If we make FDEs linkonce, we may have to emit an empty label for
2833 an FDE that wouldn't otherwise be emitted. We want to avoid
2834 having an FDE kept around when the function it refers to is
2835 discarded. Example where this matters: a primary function
2836 template in C++ requires EH information, but an explicit
2837 specialization doesn't. */
2838 if (TARGET_USES_WEAK_UNWIND_INFO
2839 && ! flag_asynchronous_unwind_tables
2842 for (i = 0; i < fde_table_in_use; i++)
2843 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2844 && !fde_table[i].uses_eh_lsda
2845 && ! DECL_WEAK (fde_table[i].decl))
2846 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2847 for_eh, /* empty */ 1);
2849 /* If we don't have any functions we'll want to unwind out of, don't
2850 emit any EH unwind information. Note that if exceptions aren't
2851 enabled, we won't have collected nothrow information, and if we
2852 asked for asynchronous tables, we always want this info. */
2855 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2857 for (i = 0; i < fde_table_in_use; i++)
2858 if (fde_table[i].uses_eh_lsda)
2859 any_eh_needed = any_lsda_needed = true;
2860 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2861 any_eh_needed = true;
2862 else if (! fde_table[i].nothrow
2863 && ! fde_table[i].all_throwers_are_sibcalls)
2864 any_eh_needed = true;
2866 if (! any_eh_needed)
2870 /* We're going to be generating comments, so turn on app. */
2875 switch_to_eh_frame_section ();
2878 if (!debug_frame_section)
2879 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2880 SECTION_DEBUG, NULL);
2881 switch_to_section (debug_frame_section);
2884 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2885 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2887 /* Output the CIE. */
2888 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2889 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2890 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2891 dw2_asm_output_data (4, 0xffffffff,
2892 "Initial length escape value indicating 64-bit DWARF extension");
2893 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2894 "Length of Common Information Entry");
2895 ASM_OUTPUT_LABEL (asm_out_file, l1);
2897 /* Now that the CIE pointer is PC-relative for EH,
2898 use 0 to identify the CIE. */
2899 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2900 (for_eh ? 0 : DWARF_CIE_ID),
2901 "CIE Identifier Tag");
2903 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2905 augmentation[0] = 0;
2906 augmentation_size = 0;
2912 z Indicates that a uleb128 is present to size the
2913 augmentation section.
2914 L Indicates the encoding (and thus presence) of
2915 an LSDA pointer in the FDE augmentation.
2916 R Indicates a non-default pointer encoding for
2918 P Indicates the presence of an encoding + language
2919 personality routine in the CIE augmentation. */
2921 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2922 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2923 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2925 p = augmentation + 1;
2926 if (eh_personality_libfunc)
2929 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2930 assemble_external_libcall (eh_personality_libfunc);
2932 if (any_lsda_needed)
2935 augmentation_size += 1;
2937 if (fde_encoding != DW_EH_PE_absptr)
2940 augmentation_size += 1;
2942 if (p > augmentation + 1)
2944 augmentation[0] = 'z';
2948 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2949 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2951 int offset = ( 4 /* Length */
2953 + 1 /* CIE version */
2954 + strlen (augmentation) + 1 /* Augmentation */
2955 + size_of_uleb128 (1) /* Code alignment */
2956 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2958 + 1 /* Augmentation size */
2959 + 1 /* Personality encoding */ );
2960 int pad = -offset & (PTR_SIZE - 1);
2962 augmentation_size += pad;
2964 /* Augmentations should be small, so there's scarce need to
2965 iterate for a solution. Die if we exceed one uleb128 byte. */
2966 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2970 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2971 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2972 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2973 "CIE Data Alignment Factor");
2975 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2976 if (DW_CIE_VERSION == 1)
2977 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2979 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2981 if (augmentation[0])
2983 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2984 if (eh_personality_libfunc)
2986 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2987 eh_data_format_name (per_encoding));
2988 dw2_asm_output_encoded_addr_rtx (per_encoding,
2989 eh_personality_libfunc,
2993 if (any_lsda_needed)
2994 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2995 eh_data_format_name (lsda_encoding));
2997 if (fde_encoding != DW_EH_PE_absptr)
2998 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2999 eh_data_format_name (fde_encoding));
3002 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3003 output_cfi (cfi, NULL, for_eh);
3005 /* Pad the CIE out to an address sized boundary. */
3006 ASM_OUTPUT_ALIGN (asm_out_file,
3007 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3008 ASM_OUTPUT_LABEL (asm_out_file, l2);
3010 /* Loop through all of the FDE's. */
3011 for (i = 0; i < fde_table_in_use; i++)
3013 fde = &fde_table[i];
3015 /* Don't emit EH unwind info for leaf functions that don't need it. */
3016 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3017 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3018 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3019 && !fde->uses_eh_lsda)
3022 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
3023 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
3024 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
3025 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
3026 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3027 dw2_asm_output_data (4, 0xffffffff,
3028 "Initial length escape value indicating 64-bit DWARF extension");
3029 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3031 ASM_OUTPUT_LABEL (asm_out_file, l1);
3034 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3036 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3037 debug_frame_section, "FDE CIE offset");
3041 if (fde->dw_fde_switched_sections)
3043 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
3044 fde->dw_fde_unlikely_section_label);
3045 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
3046 fde->dw_fde_hot_section_label);
3047 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3048 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3049 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3050 "FDE initial location");
3051 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3052 fde->dw_fde_hot_section_end_label,
3053 fde->dw_fde_hot_section_label,
3054 "FDE address range");
3055 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3056 "FDE initial location");
3057 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3058 fde->dw_fde_unlikely_section_end_label,
3059 fde->dw_fde_unlikely_section_label,
3060 "FDE address range");
3064 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3065 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3066 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3069 "FDE initial location");
3070 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3071 fde->dw_fde_end, fde->dw_fde_begin,
3072 "FDE address range");
3077 if (fde->dw_fde_switched_sections)
3079 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3080 fde->dw_fde_hot_section_label,
3081 "FDE initial location");
3082 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3083 fde->dw_fde_hot_section_end_label,
3084 fde->dw_fde_hot_section_label,
3085 "FDE address range");
3086 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3087 fde->dw_fde_unlikely_section_label,
3088 "FDE initial location");
3089 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3090 fde->dw_fde_unlikely_section_end_label,
3091 fde->dw_fde_unlikely_section_label,
3092 "FDE address range");
3096 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3097 "FDE initial location");
3098 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3099 fde->dw_fde_end, fde->dw_fde_begin,
3100 "FDE address range");
3104 if (augmentation[0])
3106 if (any_lsda_needed)
3108 int size = size_of_encoded_value (lsda_encoding);
3110 if (lsda_encoding == DW_EH_PE_aligned)
3112 int offset = ( 4 /* Length */
3113 + 4 /* CIE offset */
3114 + 2 * size_of_encoded_value (fde_encoding)
3115 + 1 /* Augmentation size */ );
3116 int pad = -offset & (PTR_SIZE - 1);
3119 gcc_assert (size_of_uleb128 (size) == 1);
3122 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3124 if (fde->uses_eh_lsda)
3126 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3127 fde->funcdef_number);
3128 dw2_asm_output_encoded_addr_rtx (
3129 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3130 false, "Language Specific Data Area");
3134 if (lsda_encoding == DW_EH_PE_aligned)
3135 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3137 (size_of_encoded_value (lsda_encoding), 0,
3138 "Language Specific Data Area (none)");
3142 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3145 /* Loop through the Call Frame Instructions associated with
3147 fde->dw_fde_current_label = fde->dw_fde_begin;
3148 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3149 output_cfi (cfi, fde, for_eh);
3151 /* Pad the FDE out to an address sized boundary. */
3152 ASM_OUTPUT_ALIGN (asm_out_file,
3153 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3154 ASM_OUTPUT_LABEL (asm_out_file, l2);
3157 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3158 dw2_asm_output_data (4, 0, "End of Table");
3159 #ifdef MIPS_DEBUGGING_INFO
3160 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3161 get a value of 0. Putting .align 0 after the label fixes it. */
3162 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3165 /* Turn off app to make assembly quicker. */
3170 /* Output a marker (i.e. a label) for the beginning of a function, before
3174 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3175 const char *file ATTRIBUTE_UNUSED)
3177 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3181 current_function_func_begin_label = NULL;
3183 #ifdef TARGET_UNWIND_INFO
3184 /* ??? current_function_func_begin_label is also used by except.c
3185 for call-site information. We must emit this label if it might
3187 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3188 && ! dwarf2out_do_frame ())
3191 if (! dwarf2out_do_frame ())
3195 switch_to_section (function_section (current_function_decl));
3196 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3197 current_function_funcdef_no);
3198 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3199 current_function_funcdef_no);
3200 dup_label = xstrdup (label);
3201 current_function_func_begin_label = dup_label;
3203 #ifdef TARGET_UNWIND_INFO
3204 /* We can elide the fde allocation if we're not emitting debug info. */
3205 if (! dwarf2out_do_frame ())
3209 /* Expand the fde table if necessary. */
3210 if (fde_table_in_use == fde_table_allocated)
3212 fde_table_allocated += FDE_TABLE_INCREMENT;
3213 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3214 memset (fde_table + fde_table_in_use, 0,
3215 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3218 /* Record the FDE associated with this function. */
3219 current_funcdef_fde = fde_table_in_use;
3221 /* Add the new FDE at the end of the fde_table. */
3222 fde = &fde_table[fde_table_in_use++];
3223 fde->decl = current_function_decl;
3224 fde->dw_fde_begin = dup_label;
3225 fde->dw_fde_current_label = dup_label;
3226 fde->dw_fde_hot_section_label = NULL;
3227 fde->dw_fde_hot_section_end_label = NULL;
3228 fde->dw_fde_unlikely_section_label = NULL;
3229 fde->dw_fde_unlikely_section_end_label = NULL;
3230 fde->dw_fde_switched_sections = false;
3231 fde->dw_fde_end = NULL;
3232 fde->dw_fde_cfi = NULL;
3233 fde->funcdef_number = current_function_funcdef_no;
3234 fde->nothrow = crtl->nothrow;
3235 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3236 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3237 fde->drap_reg = INVALID_REGNUM;
3238 fde->vdrap_reg = INVALID_REGNUM;
3240 args_size = old_args_size = 0;
3242 /* We only want to output line number information for the genuine dwarf2
3243 prologue case, not the eh frame case. */
3244 #ifdef DWARF2_DEBUGGING_INFO
3246 dwarf2out_source_line (line, file);
3249 if (dwarf2out_do_cfi_asm ())
3254 fprintf (asm_out_file, "\t.cfi_startproc\n");
3256 if (eh_personality_libfunc)
3258 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3259 ref = eh_personality_libfunc;
3261 /* ??? The GAS support isn't entirely consistent. We have to
3262 handle indirect support ourselves, but PC-relative is done
3263 in the assembler. Further, the assembler can't handle any
3264 of the weirder relocation types. */
3265 if (enc & DW_EH_PE_indirect)
3266 ref = dw2_force_const_mem (ref, true);
3268 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3269 output_addr_const (asm_out_file, ref);
3270 fputc ('\n', asm_out_file);
3273 if (crtl->uses_eh_lsda)
3277 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3278 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3279 current_function_funcdef_no);
3280 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3281 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3283 if (enc & DW_EH_PE_indirect)
3284 ref = dw2_force_const_mem (ref, true);
3286 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3287 output_addr_const (asm_out_file, ref);
3288 fputc ('\n', asm_out_file);
3293 /* Output a marker (i.e. a label) for the absolute end of the generated code
3294 for a function definition. This gets called *after* the epilogue code has
3298 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3299 const char *file ATTRIBUTE_UNUSED)
3302 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3304 if (dwarf2out_do_cfi_asm ())
3305 fprintf (asm_out_file, "\t.cfi_endproc\n");
3307 /* Output a label to mark the endpoint of the code generated for this
3309 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3310 current_function_funcdef_no);
3311 ASM_OUTPUT_LABEL (asm_out_file, label);
3312 fde = current_fde ();
3313 gcc_assert (fde != NULL);
3314 fde->dw_fde_end = xstrdup (label);
3318 dwarf2out_frame_init (void)
3320 /* Allocate the initial hunk of the fde_table. */
3321 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3322 fde_table_allocated = FDE_TABLE_INCREMENT;
3323 fde_table_in_use = 0;
3325 /* Generate the CFA instructions common to all FDE's. Do it now for the
3326 sake of lookup_cfa. */
3328 /* On entry, the Canonical Frame Address is at SP. */
3329 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3331 #ifdef DWARF2_UNWIND_INFO
3332 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3333 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3338 dwarf2out_frame_finish (void)
3340 /* Output call frame information. */
3341 if (DWARF2_FRAME_INFO)
3342 output_call_frame_info (0);
3344 #ifndef TARGET_UNWIND_INFO
3345 /* Output another copy for the unwinder. */
3346 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3347 output_call_frame_info (1);
3351 /* Note that the current function section is being used for code. */
3354 dwarf2out_note_section_used (void)
3356 section *sec = current_function_section ();
3357 if (sec == text_section)
3358 text_section_used = true;
3359 else if (sec == cold_text_section)
3360 cold_text_section_used = true;
3364 dwarf2out_switch_text_section (void)
3366 dw_fde_ref fde = current_fde ();
3368 gcc_assert (cfun && fde);
3370 fde->dw_fde_switched_sections = true;
3371 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3372 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3373 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3374 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3375 have_multiple_function_sections = true;
3377 /* Reset the current label on switching text sections, so that we
3378 don't attempt to advance_loc4 between labels in different sections. */
3379 fde->dw_fde_current_label = NULL;
3381 /* There is no need to mark used sections when not debugging. */
3382 if (cold_text_section != NULL)
3383 dwarf2out_note_section_used ();
3387 /* And now, the subset of the debugging information support code necessary
3388 for emitting location expressions. */
3390 /* Data about a single source file. */
3391 struct dwarf_file_data GTY(())
3393 const char * filename;
3397 /* We need some way to distinguish DW_OP_addr with a direct symbol
3398 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3399 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3402 typedef struct dw_val_struct *dw_val_ref;
3403 typedef struct die_struct *dw_die_ref;
3404 typedef const struct die_struct *const_dw_die_ref;
3405 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3406 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3408 typedef struct deferred_locations_struct GTY(())
3412 } deferred_locations;
3414 DEF_VEC_O(deferred_locations);
3415 DEF_VEC_ALLOC_O(deferred_locations,gc);
3417 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
3419 /* Each DIE may have a series of attribute/value pairs. Values
3420 can take on several forms. The forms that are used in this
3421 implementation are listed below. */
3426 dw_val_class_offset,
3428 dw_val_class_loc_list,
3429 dw_val_class_range_list,
3431 dw_val_class_unsigned_const,
3432 dw_val_class_long_long,
3435 dw_val_class_die_ref,
3436 dw_val_class_fde_ref,
3437 dw_val_class_lbl_id,
3438 dw_val_class_lineptr,
3440 dw_val_class_macptr,
3444 /* Describe a double word constant value. */
3445 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3447 typedef struct dw_long_long_struct GTY(())
3454 /* Describe a floating point constant value, or a vector constant value. */
3456 typedef struct dw_vec_struct GTY(())
3458 unsigned char * GTY((length ("%h.length"))) array;
3464 /* The dw_val_node describes an attribute's value, as it is
3465 represented internally. */
3467 typedef struct dw_val_struct GTY(())
3469 enum dw_val_class val_class;
3470 union dw_val_struct_union
3472 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3473 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3474 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3475 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3476 HOST_WIDE_INT GTY ((default)) val_int;
3477 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3478 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3479 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3480 struct dw_val_die_union
3484 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3485 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3486 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3487 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3488 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3489 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3491 GTY ((desc ("%1.val_class"))) v;
3495 /* Locations in memory are described using a sequence of stack machine
3498 typedef struct dw_loc_descr_struct GTY(())
3500 dw_loc_descr_ref dw_loc_next;
3501 enum dwarf_location_atom dw_loc_opc;
3503 dw_val_node dw_loc_oprnd1;
3504 dw_val_node dw_loc_oprnd2;
3508 /* Location lists are ranges + location descriptions for that range,
3509 so you can track variables that are in different places over
3510 their entire life. */
3511 typedef struct dw_loc_list_struct GTY(())
3513 dw_loc_list_ref dw_loc_next;
3514 const char *begin; /* Label for begin address of range */
3515 const char *end; /* Label for end address of range */
3516 char *ll_symbol; /* Label for beginning of location list.
3517 Only on head of list */
3518 const char *section; /* Section this loclist is relative to */
3519 dw_loc_descr_ref expr;
3522 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3524 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3526 /* Convert a DWARF stack opcode into its string name. */
3529 dwarf_stack_op_name (unsigned int op)
3534 case INTERNAL_DW_OP_tls_addr:
3535 return "DW_OP_addr";
3537 return "DW_OP_deref";
3539 return "DW_OP_const1u";
3541 return "DW_OP_const1s";
3543 return "DW_OP_const2u";
3545 return "DW_OP_const2s";
3547 return "DW_OP_const4u";
3549 return "DW_OP_const4s";
3551 return "DW_OP_const8u";
3553 return "DW_OP_const8s";
3555 return "DW_OP_constu";
3557 return "DW_OP_consts";
3561 return "DW_OP_drop";
3563 return "DW_OP_over";
3565 return "DW_OP_pick";
3567 return "DW_OP_swap";
3571 return "DW_OP_xderef";
3579 return "DW_OP_minus";
3591 return "DW_OP_plus";
3592 case DW_OP_plus_uconst:
3593 return "DW_OP_plus_uconst";
3599 return "DW_OP_shra";
3617 return "DW_OP_skip";
3619 return "DW_OP_lit0";
3621 return "DW_OP_lit1";
3623 return "DW_OP_lit2";
3625 return "DW_OP_lit3";
3627 return "DW_OP_lit4";
3629 return "DW_OP_lit5";
3631 return "DW_OP_lit6";
3633 return "DW_OP_lit7";
3635 return "DW_OP_lit8";
3637 return "DW_OP_lit9";
3639 return "DW_OP_lit10";
3641 return "DW_OP_lit11";
3643 return "DW_OP_lit12";
3645 return "DW_OP_lit13";
3647 return "DW_OP_lit14";
3649 return "DW_OP_lit15";
3651 return "DW_OP_lit16";
3653 return "DW_OP_lit17";
3655 return "DW_OP_lit18";
3657 return "DW_OP_lit19";
3659 return "DW_OP_lit20";
3661 return "DW_OP_lit21";
3663 return "DW_OP_lit22";
3665 return "DW_OP_lit23";
3667 return "DW_OP_lit24";
3669 return "DW_OP_lit25";
3671 return "DW_OP_lit26";
3673 return "DW_OP_lit27";
3675 return "DW_OP_lit28";
3677 return "DW_OP_lit29";
3679 return "DW_OP_lit30";
3681 return "DW_OP_lit31";
3683 return "DW_OP_reg0";
3685 return "DW_OP_reg1";
3687 return "DW_OP_reg2";
3689 return "DW_OP_reg3";
3691 return "DW_OP_reg4";
3693 return "DW_OP_reg5";
3695 return "DW_OP_reg6";
3697 return "DW_OP_reg7";
3699 return "DW_OP_reg8";
3701 return "DW_OP_reg9";
3703 return "DW_OP_reg10";
3705 return "DW_OP_reg11";
3707 return "DW_OP_reg12";
3709 return "DW_OP_reg13";
3711 return "DW_OP_reg14";
3713 return "DW_OP_reg15";
3715 return "DW_OP_reg16";
3717 return "DW_OP_reg17";
3719 return "DW_OP_reg18";
3721 return "DW_OP_reg19";
3723 return "DW_OP_reg20";
3725 return "DW_OP_reg21";
3727 return "DW_OP_reg22";
3729 return "DW_OP_reg23";
3731 return "DW_OP_reg24";
3733 return "DW_OP_reg25";
3735 return "DW_OP_reg26";
3737 return "DW_OP_reg27";
3739 return "DW_OP_reg28";
3741 return "DW_OP_reg29";
3743 return "DW_OP_reg30";
3745 return "DW_OP_reg31";
3747 return "DW_OP_breg0";
3749 return "DW_OP_breg1";
3751 return "DW_OP_breg2";
3753 return "DW_OP_breg3";
3755 return "DW_OP_breg4";
3757 return "DW_OP_breg5";
3759 return "DW_OP_breg6";
3761 return "DW_OP_breg7";
3763 return "DW_OP_breg8";
3765 return "DW_OP_breg9";
3767 return "DW_OP_breg10";
3769 return "DW_OP_breg11";
3771 return "DW_OP_breg12";
3773 return "DW_OP_breg13";
3775 return "DW_OP_breg14";
3777 return "DW_OP_breg15";
3779 return "DW_OP_breg16";
3781 return "DW_OP_breg17";
3783 return "DW_OP_breg18";
3785 return "DW_OP_breg19";
3787 return "DW_OP_breg20";
3789 return "DW_OP_breg21";
3791 return "DW_OP_breg22";
3793 return "DW_OP_breg23";
3795 return "DW_OP_breg24";
3797 return "DW_OP_breg25";
3799 return "DW_OP_breg26";
3801 return "DW_OP_breg27";
3803 return "DW_OP_breg28";
3805 return "DW_OP_breg29";
3807 return "DW_OP_breg30";
3809 return "DW_OP_breg31";
3811 return "DW_OP_regx";
3813 return "DW_OP_fbreg";
3815 return "DW_OP_bregx";
3817 return "DW_OP_piece";
3818 case DW_OP_deref_size:
3819 return "DW_OP_deref_size";
3820 case DW_OP_xderef_size:
3821 return "DW_OP_xderef_size";
3824 case DW_OP_push_object_address:
3825 return "DW_OP_push_object_address";
3827 return "DW_OP_call2";
3829 return "DW_OP_call4";
3830 case DW_OP_call_ref:
3831 return "DW_OP_call_ref";
3832 case DW_OP_GNU_push_tls_address:
3833 return "DW_OP_GNU_push_tls_address";
3834 case DW_OP_GNU_uninit:
3835 return "DW_OP_GNU_uninit";
3837 return "OP_<unknown>";
3841 /* Return a pointer to a newly allocated location description. Location
3842 descriptions are simple expression terms that can be strung
3843 together to form more complicated location (address) descriptions. */
3845 static inline dw_loc_descr_ref
3846 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3847 unsigned HOST_WIDE_INT oprnd2)
3849 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3851 descr->dw_loc_opc = op;
3852 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3853 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3854 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3855 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3860 /* Return a pointer to a newly allocated location description for
3863 static inline dw_loc_descr_ref
3864 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
3869 return new_loc_descr (DW_OP_breg0 + reg, offset, 0);
3871 return new_loc_descr (DW_OP_bregx, reg, offset);
3874 return new_loc_descr (DW_OP_reg0 + reg, 0, 0);
3876 return new_loc_descr (DW_OP_regx, reg, 0);
3879 /* Add a location description term to a location description expression. */
3882 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3884 dw_loc_descr_ref *d;
3886 /* Find the end of the chain. */
3887 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3893 /* Return the size of a location descriptor. */
3895 static unsigned long
3896 size_of_loc_descr (dw_loc_descr_ref loc)
3898 unsigned long size = 1;
3900 switch (loc->dw_loc_opc)
3903 case INTERNAL_DW_OP_tls_addr:
3904 size += DWARF2_ADDR_SIZE;
3923 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3926 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3931 case DW_OP_plus_uconst:
3932 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3970 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3973 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3976 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3979 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3980 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3983 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3985 case DW_OP_deref_size:
3986 case DW_OP_xderef_size:
3995 case DW_OP_call_ref:
3996 size += DWARF2_ADDR_SIZE;
4005 /* Return the size of a series of location descriptors. */
4007 static unsigned long
4008 size_of_locs (dw_loc_descr_ref loc)
4013 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4014 field, to avoid writing to a PCH file. */
4015 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4017 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4019 size += size_of_loc_descr (l);
4024 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4026 l->dw_loc_addr = size;
4027 size += size_of_loc_descr (l);
4033 /* Output location description stack opcode's operands (if any). */
4036 output_loc_operands (dw_loc_descr_ref loc)
4038 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4039 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4041 switch (loc->dw_loc_opc)
4043 #ifdef DWARF2_DEBUGGING_INFO
4045 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4049 dw2_asm_output_data (2, val1->v.val_int, NULL);
4053 dw2_asm_output_data (4, val1->v.val_int, NULL);
4057 gcc_assert (HOST_BITS_PER_LONG >= 64);
4058 dw2_asm_output_data (8, val1->v.val_int, NULL);
4065 gcc_assert (val1->val_class == dw_val_class_loc);
4066 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4068 dw2_asm_output_data (2, offset, NULL);
4081 /* We currently don't make any attempt to make sure these are
4082 aligned properly like we do for the main unwind info, so
4083 don't support emitting things larger than a byte if we're
4084 only doing unwinding. */
4089 dw2_asm_output_data (1, val1->v.val_int, NULL);
4092 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4095 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4098 dw2_asm_output_data (1, val1->v.val_int, NULL);
4100 case DW_OP_plus_uconst:
4101 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4135 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4138 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4141 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4144 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4145 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4148 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4150 case DW_OP_deref_size:
4151 case DW_OP_xderef_size:
4152 dw2_asm_output_data (1, val1->v.val_int, NULL);
4155 case INTERNAL_DW_OP_tls_addr:
4156 if (targetm.asm_out.output_dwarf_dtprel)
4158 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4161 fputc ('\n', asm_out_file);
4168 /* Other codes have no operands. */
4173 /* Output a sequence of location operations. */
4176 output_loc_sequence (dw_loc_descr_ref loc)
4178 for (; loc != NULL; loc = loc->dw_loc_next)
4180 /* Output the opcode. */
4181 dw2_asm_output_data (1, loc->dw_loc_opc,
4182 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4184 /* Output the operand(s) (if any). */
4185 output_loc_operands (loc);
4189 /* Output location description stack opcode's operands (if any).
4190 The output is single bytes on a line, suitable for .cfi_escape. */
4193 output_loc_operands_raw (dw_loc_descr_ref loc)
4195 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4196 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4198 switch (loc->dw_loc_opc)
4201 /* We cannot output addresses in .cfi_escape, only bytes. */
4207 case DW_OP_deref_size:
4208 case DW_OP_xderef_size:
4209 fputc (',', asm_out_file);
4210 dw2_asm_output_data_raw (1, val1->v.val_int);
4215 fputc (',', asm_out_file);
4216 dw2_asm_output_data_raw (2, val1->v.val_int);
4221 fputc (',', asm_out_file);
4222 dw2_asm_output_data_raw (4, val1->v.val_int);
4227 gcc_assert (HOST_BITS_PER_LONG >= 64);
4228 fputc (',', asm_out_file);
4229 dw2_asm_output_data_raw (8, val1->v.val_int);
4237 gcc_assert (val1->val_class == dw_val_class_loc);
4238 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4240 fputc (',', asm_out_file);
4241 dw2_asm_output_data_raw (2, offset);
4246 case DW_OP_plus_uconst:
4249 fputc (',', asm_out_file);
4250 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4287 fputc (',', asm_out_file);
4288 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4292 fputc (',', asm_out_file);
4293 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4294 fputc (',', asm_out_file);
4295 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4298 case INTERNAL_DW_OP_tls_addr:
4302 /* Other codes have no operands. */
4308 output_loc_sequence_raw (dw_loc_descr_ref loc)
4312 /* Output the opcode. */
4313 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4314 output_loc_operands_raw (loc);
4316 if (!loc->dw_loc_next)
4318 loc = loc->dw_loc_next;
4320 fputc (',', asm_out_file);
4324 /* This routine will generate the correct assembly data for a location
4325 description based on a cfi entry with a complex address. */
4328 output_cfa_loc (dw_cfi_ref cfi)
4330 dw_loc_descr_ref loc;
4333 if (cfi->dw_cfi_opc == DW_CFA_expression)
4334 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4336 /* Output the size of the block. */
4337 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4338 size = size_of_locs (loc);
4339 dw2_asm_output_data_uleb128 (size, NULL);
4341 /* Now output the operations themselves. */
4342 output_loc_sequence (loc);
4345 /* Similar, but used for .cfi_escape. */
4348 output_cfa_loc_raw (dw_cfi_ref cfi)
4350 dw_loc_descr_ref loc;
4353 if (cfi->dw_cfi_opc == DW_CFA_expression)
4354 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4356 /* Output the size of the block. */
4357 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4358 size = size_of_locs (loc);
4359 dw2_asm_output_data_uleb128_raw (size);
4360 fputc (',', asm_out_file);
4362 /* Now output the operations themselves. */
4363 output_loc_sequence_raw (loc);
4366 /* This function builds a dwarf location descriptor sequence from a
4367 dw_cfa_location, adding the given OFFSET to the result of the
4370 static struct dw_loc_descr_struct *
4371 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4373 struct dw_loc_descr_struct *head, *tmp;
4375 offset += cfa->offset;
4379 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4380 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4381 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4382 add_loc_descr (&head, tmp);
4385 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4386 add_loc_descr (&head, tmp);
4390 head = new_reg_loc_descr (cfa->reg, offset);
4395 /* This function builds a dwarf location descriptor sequence for
4396 the address at OFFSET from the CFA when stack is aligned to
4399 static struct dw_loc_descr_struct *
4400 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4402 struct dw_loc_descr_struct *head;
4403 unsigned int dwarf_fp
4404 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4406 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4407 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4409 head = new_reg_loc_descr (dwarf_fp, 0);
4410 add_loc_descr (&head, int_loc_descriptor (alignment));
4411 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4413 add_loc_descr (&head, int_loc_descriptor (offset));
4414 add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
4417 head = new_reg_loc_descr (dwarf_fp, offset);
4421 /* This function fills in aa dw_cfa_location structure from a dwarf location
4422 descriptor sequence. */
4425 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4427 struct dw_loc_descr_struct *ptr;
4429 cfa->base_offset = 0;
4433 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4435 enum dwarf_location_atom op = ptr->dw_loc_opc;
4471 cfa->reg = op - DW_OP_reg0;
4474 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4508 cfa->reg = op - DW_OP_breg0;
4509 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4512 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4513 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4518 case DW_OP_plus_uconst:
4519 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4522 internal_error ("DW_LOC_OP %s not implemented",
4523 dwarf_stack_op_name (ptr->dw_loc_opc));
4527 #endif /* .debug_frame support */
4529 /* And now, the support for symbolic debugging information. */
4530 #ifdef DWARF2_DEBUGGING_INFO
4532 /* .debug_str support. */
4533 static int output_indirect_string (void **, void *);
4535 static void dwarf2out_init (const char *);
4536 static void dwarf2out_finish (const char *);
4537 static void dwarf2out_define (unsigned int, const char *);
4538 static void dwarf2out_undef (unsigned int, const char *);
4539 static void dwarf2out_start_source_file (unsigned, const char *);
4540 static void dwarf2out_end_source_file (unsigned);
4541 static void dwarf2out_begin_block (unsigned, unsigned);
4542 static void dwarf2out_end_block (unsigned, unsigned);
4543 static bool dwarf2out_ignore_block (const_tree);
4544 static void dwarf2out_global_decl (tree);
4545 static void dwarf2out_type_decl (tree, int);
4546 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
4547 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
4549 static void dwarf2out_abstract_function (tree);
4550 static void dwarf2out_var_location (rtx);
4551 static void dwarf2out_begin_function (tree);
4553 /* The debug hooks structure. */
4555 const struct gcc_debug_hooks dwarf2_debug_hooks =
4561 dwarf2out_start_source_file,
4562 dwarf2out_end_source_file,
4563 dwarf2out_begin_block,
4564 dwarf2out_end_block,
4565 dwarf2out_ignore_block,
4566 dwarf2out_source_line,
4567 dwarf2out_begin_prologue,
4568 debug_nothing_int_charstar, /* end_prologue */
4569 dwarf2out_end_epilogue,
4570 dwarf2out_begin_function,
4571 debug_nothing_int, /* end_function */
4572 dwarf2out_decl, /* function_decl */
4573 dwarf2out_global_decl,
4574 dwarf2out_type_decl, /* type_decl */
4575 dwarf2out_imported_module_or_decl,
4576 debug_nothing_tree, /* deferred_inline_function */
4577 /* The DWARF 2 backend tries to reduce debugging bloat by not
4578 emitting the abstract description of inline functions until
4579 something tries to reference them. */
4580 dwarf2out_abstract_function, /* outlining_inline_function */
4581 debug_nothing_rtx, /* label */
4582 debug_nothing_int, /* handle_pch */
4583 dwarf2out_var_location,
4584 dwarf2out_switch_text_section,
4585 1 /* start_end_main_source_file */
4589 /* NOTE: In the comments in this file, many references are made to
4590 "Debugging Information Entries". This term is abbreviated as `DIE'
4591 throughout the remainder of this file. */
4593 /* An internal representation of the DWARF output is built, and then
4594 walked to generate the DWARF debugging info. The walk of the internal
4595 representation is done after the entire program has been compiled.
4596 The types below are used to describe the internal representation. */
4598 /* Various DIE's use offsets relative to the beginning of the
4599 .debug_info section to refer to each other. */
4601 typedef long int dw_offset;
4603 /* Define typedefs here to avoid circular dependencies. */
4605 typedef struct dw_attr_struct *dw_attr_ref;
4606 typedef struct dw_line_info_struct *dw_line_info_ref;
4607 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4608 typedef struct pubname_struct *pubname_ref;
4609 typedef struct dw_ranges_struct *dw_ranges_ref;
4610 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4612 /* Each entry in the line_info_table maintains the file and
4613 line number associated with the label generated for that
4614 entry. The label gives the PC value associated with
4615 the line number entry. */
4617 typedef struct dw_line_info_struct GTY(())
4619 unsigned long dw_file_num;
4620 unsigned long dw_line_num;
4624 /* Line information for functions in separate sections; each one gets its
4626 typedef struct dw_separate_line_info_struct GTY(())
4628 unsigned long dw_file_num;
4629 unsigned long dw_line_num;
4630 unsigned long function;
4632 dw_separate_line_info_entry;
4634 /* Each DIE attribute has a field specifying the attribute kind,
4635 a link to the next attribute in the chain, and an attribute value.
4636 Attributes are typically linked below the DIE they modify. */
4638 typedef struct dw_attr_struct GTY(())
4640 enum dwarf_attribute dw_attr;
4641 dw_val_node dw_attr_val;
4645 DEF_VEC_O(dw_attr_node);
4646 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4648 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4649 The children of each node form a circular list linked by
4650 die_sib. die_child points to the node *before* the "first" child node. */
4652 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
4654 enum dwarf_tag die_tag;
4656 VEC(dw_attr_node,gc) * die_attr;
4657 dw_die_ref die_parent;
4658 dw_die_ref die_child;
4660 dw_die_ref die_definition; /* ref from a specification to its definition */
4661 dw_offset die_offset;
4662 unsigned long die_abbrev;
4664 /* Die is used and must not be pruned as unused. */
4665 int die_perennial_p;
4666 unsigned int decl_id;
4670 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4671 #define FOR_EACH_CHILD(die, c, expr) do { \
4672 c = die->die_child; \
4676 } while (c != die->die_child); \
4679 /* The pubname structure */
4681 typedef struct pubname_struct GTY(())
4688 DEF_VEC_O(pubname_entry);
4689 DEF_VEC_ALLOC_O(pubname_entry, gc);
4691 struct dw_ranges_struct GTY(())
4693 /* If this is positive, it's a block number, otherwise it's a
4694 bitwise-negated index into dw_ranges_by_label. */
4698 struct dw_ranges_by_label_struct GTY(())
4704 /* The limbo die list structure. */
4705 typedef struct limbo_die_struct GTY(())
4709 struct limbo_die_struct *next;
4713 /* How to start an assembler comment. */
4714 #ifndef ASM_COMMENT_START
4715 #define ASM_COMMENT_START ";#"
4718 /* Define a macro which returns nonzero for a TYPE_DECL which was
4719 implicitly generated for a tagged type.
4721 Note that unlike the gcc front end (which generates a NULL named
4722 TYPE_DECL node for each complete tagged type, each array type, and
4723 each function type node created) the g++ front end generates a
4724 _named_ TYPE_DECL node for each tagged type node created.
4725 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4726 generate a DW_TAG_typedef DIE for them. */
4728 #define TYPE_DECL_IS_STUB(decl) \
4729 (DECL_NAME (decl) == NULL_TREE \
4730 || (DECL_ARTIFICIAL (decl) \
4731 && is_tagged_type (TREE_TYPE (decl)) \
4732 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4733 /* This is necessary for stub decls that \
4734 appear in nested inline functions. */ \
4735 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4736 && (decl_ultimate_origin (decl) \
4737 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4739 /* Information concerning the compilation unit's programming
4740 language, and compiler version. */
4742 /* Fixed size portion of the DWARF compilation unit header. */
4743 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4744 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4746 /* Fixed size portion of public names info. */
4747 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4749 /* Fixed size portion of the address range info. */
4750 #define DWARF_ARANGES_HEADER_SIZE \
4751 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4752 DWARF2_ADDR_SIZE * 2) \
4753 - DWARF_INITIAL_LENGTH_SIZE)
4755 /* Size of padding portion in the address range info. It must be
4756 aligned to twice the pointer size. */
4757 #define DWARF_ARANGES_PAD_SIZE \
4758 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4759 DWARF2_ADDR_SIZE * 2) \
4760 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4762 /* Use assembler line directives if available. */
4763 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4764 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4765 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4767 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4771 /* Minimum line offset in a special line info. opcode.
4772 This value was chosen to give a reasonable range of values. */
4773 #define DWARF_LINE_BASE -10
4775 /* First special line opcode - leave room for the standard opcodes. */
4776 #define DWARF_LINE_OPCODE_BASE 10
4778 /* Range of line offsets in a special line info. opcode. */
4779 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4781 /* Flag that indicates the initial value of the is_stmt_start flag.
4782 In the present implementation, we do not mark any lines as
4783 the beginning of a source statement, because that information
4784 is not made available by the GCC front-end. */
4785 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4787 #ifdef DWARF2_DEBUGGING_INFO
4788 /* This location is used by calc_die_sizes() to keep track
4789 the offset of each DIE within the .debug_info section. */
4790 static unsigned long next_die_offset;
4793 /* Record the root of the DIE's built for the current compilation unit. */
4794 static GTY(()) dw_die_ref comp_unit_die;
4796 /* A list of DIEs with a NULL parent waiting to be relocated. */
4797 static GTY(()) limbo_die_node *limbo_die_list;
4799 /* Filenames referenced by this compilation unit. */
4800 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4802 /* A hash table of references to DIE's that describe declarations.
4803 The key is a DECL_UID() which is a unique number identifying each decl. */
4804 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4806 /* A hash table of references to DIE's that describe COMMON blocks.
4807 The key is DECL_UID() ^ die_parent. */
4808 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
4810 /* Node of the variable location list. */
4811 struct var_loc_node GTY ((chain_next ("%h.next")))
4813 rtx GTY (()) var_loc_note;
4814 const char * GTY (()) label;
4815 const char * GTY (()) section_label;
4816 struct var_loc_node * GTY (()) next;
4819 /* Variable location list. */
4820 struct var_loc_list_def GTY (())
4822 struct var_loc_node * GTY (()) first;
4824 /* Do not mark the last element of the chained list because
4825 it is marked through the chain. */
4826 struct var_loc_node * GTY ((skip ("%h"))) last;
4828 /* DECL_UID of the variable decl. */
4829 unsigned int decl_id;
4831 typedef struct var_loc_list_def var_loc_list;
4834 /* Table of decl location linked lists. */
4835 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4837 /* A pointer to the base of a list of references to DIE's that
4838 are uniquely identified by their tag, presence/absence of
4839 children DIE's, and list of attribute/value pairs. */
4840 static GTY((length ("abbrev_die_table_allocated")))
4841 dw_die_ref *abbrev_die_table;
4843 /* Number of elements currently allocated for abbrev_die_table. */
4844 static GTY(()) unsigned abbrev_die_table_allocated;
4846 /* Number of elements in type_die_table currently in use. */
4847 static GTY(()) unsigned abbrev_die_table_in_use;
4849 /* Size (in elements) of increments by which we may expand the
4850 abbrev_die_table. */
4851 #define ABBREV_DIE_TABLE_INCREMENT 256
4853 /* A pointer to the base of a table that contains line information
4854 for each source code line in .text in the compilation unit. */
4855 static GTY((length ("line_info_table_allocated")))
4856 dw_line_info_ref line_info_table;
4858 /* Number of elements currently allocated for line_info_table. */
4859 static GTY(()) unsigned line_info_table_allocated;
4861 /* Number of elements in line_info_table currently in use. */
4862 static GTY(()) unsigned line_info_table_in_use;
4864 /* A pointer to the base of a table that contains line information
4865 for each source code line outside of .text in the compilation unit. */
4866 static GTY ((length ("separate_line_info_table_allocated")))
4867 dw_separate_line_info_ref separate_line_info_table;
4869 /* Number of elements currently allocated for separate_line_info_table. */
4870 static GTY(()) unsigned separate_line_info_table_allocated;
4872 /* Number of elements in separate_line_info_table currently in use. */
4873 static GTY(()) unsigned separate_line_info_table_in_use;
4875 /* Size (in elements) of increments by which we may expand the
4877 #define LINE_INFO_TABLE_INCREMENT 1024
4879 /* A pointer to the base of a table that contains a list of publicly
4880 accessible names. */
4881 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4883 /* A pointer to the base of a table that contains a list of publicly
4884 accessible types. */
4885 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4887 /* Array of dies for which we should generate .debug_arange info. */
4888 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4890 /* Number of elements currently allocated for arange_table. */
4891 static GTY(()) unsigned arange_table_allocated;
4893 /* Number of elements in arange_table currently in use. */
4894 static GTY(()) unsigned arange_table_in_use;
4896 /* Size (in elements) of increments by which we may expand the
4898 #define ARANGE_TABLE_INCREMENT 64
4900 /* Array of dies for which we should generate .debug_ranges info. */
4901 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4903 /* Number of elements currently allocated for ranges_table. */
4904 static GTY(()) unsigned ranges_table_allocated;
4906 /* Number of elements in ranges_table currently in use. */
4907 static GTY(()) unsigned ranges_table_in_use;
4909 /* Array of pairs of labels referenced in ranges_table. */
4910 static GTY ((length ("ranges_by_label_allocated")))
4911 dw_ranges_by_label_ref ranges_by_label;
4913 /* Number of elements currently allocated for ranges_by_label. */
4914 static GTY(()) unsigned ranges_by_label_allocated;
4916 /* Number of elements in ranges_by_label currently in use. */
4917 static GTY(()) unsigned ranges_by_label_in_use;
4919 /* Size (in elements) of increments by which we may expand the
4921 #define RANGES_TABLE_INCREMENT 64
4923 /* Whether we have location lists that need outputting */
4924 static GTY(()) bool have_location_lists;
4926 /* Unique label counter. */
4927 static GTY(()) unsigned int loclabel_num;
4929 #ifdef DWARF2_DEBUGGING_INFO
4930 /* Record whether the function being analyzed contains inlined functions. */
4931 static int current_function_has_inlines;
4933 #if 0 && defined (MIPS_DEBUGGING_INFO)
4934 static int comp_unit_has_inlines;
4937 /* The last file entry emitted by maybe_emit_file(). */
4938 static GTY(()) struct dwarf_file_data * last_emitted_file;
4940 /* Number of internal labels generated by gen_internal_sym(). */
4941 static GTY(()) int label_num;
4943 /* Cached result of previous call to lookup_filename. */
4944 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4946 #ifdef DWARF2_DEBUGGING_INFO
4948 /* Offset from the "steady-state frame pointer" to the frame base,
4949 within the current function. */
4950 static HOST_WIDE_INT frame_pointer_fb_offset;
4952 /* Forward declarations for functions defined in this file. */
4954 static int is_pseudo_reg (const_rtx);
4955 static tree type_main_variant (tree);
4956 static int is_tagged_type (const_tree);
4957 static const char *dwarf_tag_name (unsigned);
4958 static const char *dwarf_attr_name (unsigned);
4959 static const char *dwarf_form_name (unsigned);
4960 static tree decl_ultimate_origin (const_tree);
4961 static tree decl_class_context (tree);
4962 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4963 static inline enum dw_val_class AT_class (dw_attr_ref);
4964 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4965 static inline unsigned AT_flag (dw_attr_ref);
4966 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4967 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4968 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4969 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4970 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4972 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4973 unsigned int, unsigned char *);
4974 static hashval_t debug_str_do_hash (const void *);
4975 static int debug_str_eq (const void *, const void *);
4976 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4977 static inline const char *AT_string (dw_attr_ref);
4978 static int AT_string_form (dw_attr_ref);
4979 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4980 static void add_AT_specification (dw_die_ref, dw_die_ref);
4981 static inline dw_die_ref AT_ref (dw_attr_ref);
4982 static inline int AT_ref_external (dw_attr_ref);
4983 static inline void set_AT_ref_external (dw_attr_ref, int);
4984 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4985 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4986 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4987 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4989 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4990 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4991 static inline rtx AT_addr (dw_attr_ref);
4992 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4993 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4994 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4995 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4996 unsigned HOST_WIDE_INT);
4997 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4999 static inline const char *AT_lbl (dw_attr_ref);
5000 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5001 static const char *get_AT_low_pc (dw_die_ref);
5002 static const char *get_AT_hi_pc (dw_die_ref);
5003 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5004 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5005 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5006 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5007 static bool is_c_family (void);
5008 static bool is_cxx (void);
5009 static bool is_java (void);
5010 static bool is_fortran (void);
5011 static bool is_ada (void);
5012 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5013 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5014 static void add_child_die (dw_die_ref, dw_die_ref);
5015 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5016 static dw_die_ref lookup_type_die (tree);
5017 static void equate_type_number_to_die (tree, dw_die_ref);
5018 static hashval_t decl_die_table_hash (const void *);
5019 static int decl_die_table_eq (const void *, const void *);
5020 static dw_die_ref lookup_decl_die (tree);
5021 static hashval_t common_block_die_table_hash (const void *);
5022 static int common_block_die_table_eq (const void *, const void *);
5023 static hashval_t decl_loc_table_hash (const void *);
5024 static int decl_loc_table_eq (const void *, const void *);
5025 static var_loc_list *lookup_decl_loc (const_tree);
5026 static void equate_decl_number_to_die (tree, dw_die_ref);
5027 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5028 static void print_spaces (FILE *);
5029 static void print_die (dw_die_ref, FILE *);
5030 static void print_dwarf_line_table (FILE *);
5031 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5032 static dw_die_ref pop_compile_unit (dw_die_ref);
5033 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5034 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5035 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5036 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5037 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5038 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5039 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5040 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5041 static void compute_section_prefix (dw_die_ref);
5042 static int is_type_die (dw_die_ref);
5043 static int is_comdat_die (dw_die_ref);
5044 static int is_symbol_die (dw_die_ref);
5045 static void assign_symbol_names (dw_die_ref);
5046 static void break_out_includes (dw_die_ref);
5047 static hashval_t htab_cu_hash (const void *);
5048 static int htab_cu_eq (const void *, const void *);
5049 static void htab_cu_del (void *);
5050 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5051 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5052 static void add_sibling_attributes (dw_die_ref);
5053 static void build_abbrev_table (dw_die_ref);
5054 static void output_location_lists (dw_die_ref);
5055 static int constant_size (unsigned HOST_WIDE_INT);
5056 static unsigned long size_of_die (dw_die_ref);
5057 static void calc_die_sizes (dw_die_ref);
5058 static void mark_dies (dw_die_ref);
5059 static void unmark_dies (dw_die_ref);
5060 static void unmark_all_dies (dw_die_ref);
5061 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5062 static unsigned long size_of_aranges (void);
5063 static enum dwarf_form value_format (dw_attr_ref);
5064 static void output_value_format (dw_attr_ref);
5065 static void output_abbrev_section (void);
5066 static void output_die_symbol (dw_die_ref);
5067 static void output_die (dw_die_ref);
5068 static void output_compilation_unit_header (void);
5069 static void output_comp_unit (dw_die_ref, int);
5070 static const char *dwarf2_name (tree, int);
5071 static void add_pubname (tree, dw_die_ref);
5072 static void add_pubname_string (const char *, dw_die_ref);
5073 static void add_pubtype (tree, dw_die_ref);
5074 static void output_pubnames (VEC (pubname_entry,gc) *);
5075 static void add_arange (tree, dw_die_ref);
5076 static void output_aranges (void);
5077 static unsigned int add_ranges_num (int);
5078 static unsigned int add_ranges (const_tree);
5079 static unsigned int add_ranges_by_labels (const char *, const char *);
5080 static void output_ranges (void);
5081 static void output_line_info (void);
5082 static void output_file_names (void);
5083 static dw_die_ref base_type_die (tree);
5084 static int is_base_type (tree);
5085 static bool is_subrange_type (const_tree);
5086 static dw_die_ref subrange_type_die (tree, dw_die_ref);
5087 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5088 static int type_is_enum (const_tree);
5089 static unsigned int dbx_reg_number (const_rtx);
5090 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5091 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5092 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5093 enum var_init_status);
5094 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5095 enum var_init_status);
5096 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5097 enum var_init_status);
5098 static int is_based_loc (const_rtx);
5099 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5100 enum var_init_status);
5101 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5102 enum var_init_status);
5103 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5104 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5105 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5106 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5107 static tree field_type (const_tree);
5108 static unsigned int simple_type_align_in_bits (const_tree);
5109 static unsigned int simple_decl_align_in_bits (const_tree);
5110 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5111 static HOST_WIDE_INT field_byte_offset (const_tree);
5112 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5114 static void add_data_member_location_attribute (dw_die_ref, tree);
5115 static void add_const_value_attribute (dw_die_ref, rtx);
5116 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5117 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5118 static void insert_float (const_rtx, unsigned char *);
5119 static rtx rtl_for_decl_location (tree);
5120 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5121 enum dwarf_attribute);
5122 static void tree_add_const_value_attribute (dw_die_ref, tree);
5123 static void add_name_attribute (dw_die_ref, const char *);
5124 static void add_comp_dir_attribute (dw_die_ref);
5125 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5126 static void add_subscript_info (dw_die_ref, tree, bool);
5127 static void add_byte_size_attribute (dw_die_ref, tree);
5128 static void add_bit_offset_attribute (dw_die_ref, tree);
5129 static void add_bit_size_attribute (dw_die_ref, tree);
5130 static void add_prototyped_attribute (dw_die_ref, tree);
5131 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5132 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5133 static void add_src_coords_attributes (dw_die_ref, tree);
5134 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5135 static void push_decl_scope (tree);
5136 static void pop_decl_scope (void);
5137 static dw_die_ref scope_die_for (tree, dw_die_ref);
5138 static inline int local_scope_p (dw_die_ref);
5139 static inline int class_scope_p (dw_die_ref);
5140 static inline int class_or_namespace_scope_p (dw_die_ref);
5141 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5142 static void add_calling_convention_attribute (dw_die_ref, tree);
5143 static const char *type_tag (const_tree);
5144 static tree member_declared_type (const_tree);
5146 static const char *decl_start_label (tree);
5148 static void gen_array_type_die (tree, dw_die_ref);
5149 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5151 static void gen_entry_point_die (tree, dw_die_ref);
5153 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5154 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5155 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5156 static void gen_formal_types_die (tree, dw_die_ref);
5157 static void gen_subprogram_die (tree, dw_die_ref);
5158 static void gen_variable_die (tree, tree, dw_die_ref);
5159 static void gen_const_die (tree, dw_die_ref);
5160 static void gen_label_die (tree, dw_die_ref);
5161 static void gen_lexical_block_die (tree, dw_die_ref, int);
5162 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5163 static void gen_field_die (tree, dw_die_ref);
5164 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5165 static dw_die_ref gen_compile_unit_die (const char *);
5166 static void gen_inheritance_die (tree, tree, dw_die_ref);
5167 static void gen_member_die (tree, dw_die_ref);
5168 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5169 enum debug_info_usage);
5170 static void gen_subroutine_type_die (tree, dw_die_ref);
5171 static void gen_typedef_die (tree, dw_die_ref);
5172 static void gen_type_die (tree, dw_die_ref);
5173 static void gen_block_die (tree, dw_die_ref, int);
5174 static void decls_for_scope (tree, dw_die_ref, int);
5175 static int is_redundant_typedef (const_tree);
5176 static void gen_namespace_die (tree, dw_die_ref);
5177 static void gen_decl_die (tree, tree, dw_die_ref);
5178 static dw_die_ref force_decl_die (tree);
5179 static dw_die_ref force_type_die (tree);
5180 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5181 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5182 static struct dwarf_file_data * lookup_filename (const char *);
5183 static void retry_incomplete_types (void);
5184 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5185 static void splice_child_die (dw_die_ref, dw_die_ref);
5186 static int file_info_cmp (const void *, const void *);
5187 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5188 const char *, const char *, unsigned);
5189 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5190 const char *, const char *,
5192 static void output_loc_list (dw_loc_list_ref);
5193 static char *gen_internal_sym (const char *);
5195 static void prune_unmark_dies (dw_die_ref);
5196 static void prune_unused_types_mark (dw_die_ref, int);
5197 static void prune_unused_types_walk (dw_die_ref);
5198 static void prune_unused_types_walk_attribs (dw_die_ref);
5199 static void prune_unused_types_prune (dw_die_ref);
5200 static void prune_unused_types (void);
5201 static int maybe_emit_file (struct dwarf_file_data *fd);
5203 /* Section names used to hold DWARF debugging information. */
5204 #ifndef DEBUG_INFO_SECTION
5205 #define DEBUG_INFO_SECTION ".debug_info"
5207 #ifndef DEBUG_ABBREV_SECTION
5208 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5210 #ifndef DEBUG_ARANGES_SECTION
5211 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5213 #ifndef DEBUG_MACINFO_SECTION
5214 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5216 #ifndef DEBUG_LINE_SECTION
5217 #define DEBUG_LINE_SECTION ".debug_line"
5219 #ifndef DEBUG_LOC_SECTION
5220 #define DEBUG_LOC_SECTION ".debug_loc"
5222 #ifndef DEBUG_PUBNAMES_SECTION
5223 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5225 #ifndef DEBUG_STR_SECTION
5226 #define DEBUG_STR_SECTION ".debug_str"
5228 #ifndef DEBUG_RANGES_SECTION
5229 #define DEBUG_RANGES_SECTION ".debug_ranges"
5232 /* Standard ELF section names for compiled code and data. */
5233 #ifndef TEXT_SECTION_NAME
5234 #define TEXT_SECTION_NAME ".text"
5237 /* Section flags for .debug_str section. */
5238 #define DEBUG_STR_SECTION_FLAGS \
5239 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5240 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5243 /* Labels we insert at beginning sections we can reference instead of
5244 the section names themselves. */
5246 #ifndef TEXT_SECTION_LABEL
5247 #define TEXT_SECTION_LABEL "Ltext"
5249 #ifndef COLD_TEXT_SECTION_LABEL
5250 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5252 #ifndef DEBUG_LINE_SECTION_LABEL
5253 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5255 #ifndef DEBUG_INFO_SECTION_LABEL
5256 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5258 #ifndef DEBUG_ABBREV_SECTION_LABEL
5259 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5261 #ifndef DEBUG_LOC_SECTION_LABEL
5262 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5264 #ifndef DEBUG_RANGES_SECTION_LABEL
5265 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5267 #ifndef DEBUG_MACINFO_SECTION_LABEL
5268 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5271 /* Definitions of defaults for formats and names of various special
5272 (artificial) labels which may be generated within this file (when the -g
5273 options is used and DWARF2_DEBUGGING_INFO is in effect.
5274 If necessary, these may be overridden from within the tm.h file, but
5275 typically, overriding these defaults is unnecessary. */
5277 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5278 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5279 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5280 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5281 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5282 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5283 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5284 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5285 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5286 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5288 #ifndef TEXT_END_LABEL
5289 #define TEXT_END_LABEL "Letext"
5291 #ifndef COLD_END_LABEL
5292 #define COLD_END_LABEL "Letext_cold"
5294 #ifndef BLOCK_BEGIN_LABEL
5295 #define BLOCK_BEGIN_LABEL "LBB"
5297 #ifndef BLOCK_END_LABEL
5298 #define BLOCK_END_LABEL "LBE"
5300 #ifndef LINE_CODE_LABEL
5301 #define LINE_CODE_LABEL "LM"
5303 #ifndef SEPARATE_LINE_CODE_LABEL
5304 #define SEPARATE_LINE_CODE_LABEL "LSM"
5308 /* We allow a language front-end to designate a function that is to be
5309 called to "demangle" any name before it is put into a DIE. */
5311 static const char *(*demangle_name_func) (const char *);
5314 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5316 demangle_name_func = func;
5319 /* Test if rtl node points to a pseudo register. */
5322 is_pseudo_reg (const_rtx rtl)
5324 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5325 || (GET_CODE (rtl) == SUBREG
5326 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5329 /* Return a reference to a type, with its const and volatile qualifiers
5333 type_main_variant (tree type)
5335 type = TYPE_MAIN_VARIANT (type);
5337 /* ??? There really should be only one main variant among any group of
5338 variants of a given type (and all of the MAIN_VARIANT values for all
5339 members of the group should point to that one type) but sometimes the C
5340 front-end messes this up for array types, so we work around that bug
5342 if (TREE_CODE (type) == ARRAY_TYPE)
5343 while (type != TYPE_MAIN_VARIANT (type))
5344 type = TYPE_MAIN_VARIANT (type);
5349 /* Return nonzero if the given type node represents a tagged type. */
5352 is_tagged_type (const_tree type)
5354 enum tree_code code = TREE_CODE (type);
5356 return (code == RECORD_TYPE || code == UNION_TYPE
5357 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5360 /* Convert a DIE tag into its string name. */
5363 dwarf_tag_name (unsigned int tag)
5367 case DW_TAG_padding:
5368 return "DW_TAG_padding";
5369 case DW_TAG_array_type:
5370 return "DW_TAG_array_type";
5371 case DW_TAG_class_type:
5372 return "DW_TAG_class_type";
5373 case DW_TAG_entry_point:
5374 return "DW_TAG_entry_point";
5375 case DW_TAG_enumeration_type:
5376 return "DW_TAG_enumeration_type";
5377 case DW_TAG_formal_parameter:
5378 return "DW_TAG_formal_parameter";
5379 case DW_TAG_imported_declaration:
5380 return "DW_TAG_imported_declaration";
5382 return "DW_TAG_label";
5383 case DW_TAG_lexical_block:
5384 return "DW_TAG_lexical_block";
5386 return "DW_TAG_member";
5387 case DW_TAG_pointer_type:
5388 return "DW_TAG_pointer_type";
5389 case DW_TAG_reference_type:
5390 return "DW_TAG_reference_type";
5391 case DW_TAG_compile_unit:
5392 return "DW_TAG_compile_unit";
5393 case DW_TAG_string_type:
5394 return "DW_TAG_string_type";
5395 case DW_TAG_structure_type:
5396 return "DW_TAG_structure_type";
5397 case DW_TAG_subroutine_type:
5398 return "DW_TAG_subroutine_type";
5399 case DW_TAG_typedef:
5400 return "DW_TAG_typedef";
5401 case DW_TAG_union_type:
5402 return "DW_TAG_union_type";
5403 case DW_TAG_unspecified_parameters:
5404 return "DW_TAG_unspecified_parameters";
5405 case DW_TAG_variant:
5406 return "DW_TAG_variant";
5407 case DW_TAG_common_block:
5408 return "DW_TAG_common_block";
5409 case DW_TAG_common_inclusion:
5410 return "DW_TAG_common_inclusion";
5411 case DW_TAG_inheritance:
5412 return "DW_TAG_inheritance";
5413 case DW_TAG_inlined_subroutine:
5414 return "DW_TAG_inlined_subroutine";
5416 return "DW_TAG_module";
5417 case DW_TAG_ptr_to_member_type:
5418 return "DW_TAG_ptr_to_member_type";
5419 case DW_TAG_set_type:
5420 return "DW_TAG_set_type";
5421 case DW_TAG_subrange_type:
5422 return "DW_TAG_subrange_type";
5423 case DW_TAG_with_stmt:
5424 return "DW_TAG_with_stmt";
5425 case DW_TAG_access_declaration:
5426 return "DW_TAG_access_declaration";
5427 case DW_TAG_base_type:
5428 return "DW_TAG_base_type";
5429 case DW_TAG_catch_block:
5430 return "DW_TAG_catch_block";
5431 case DW_TAG_const_type:
5432 return "DW_TAG_const_type";
5433 case DW_TAG_constant:
5434 return "DW_TAG_constant";
5435 case DW_TAG_enumerator:
5436 return "DW_TAG_enumerator";
5437 case DW_TAG_file_type:
5438 return "DW_TAG_file_type";
5440 return "DW_TAG_friend";
5441 case DW_TAG_namelist:
5442 return "DW_TAG_namelist";
5443 case DW_TAG_namelist_item:
5444 return "DW_TAG_namelist_item";
5445 case DW_TAG_packed_type:
5446 return "DW_TAG_packed_type";
5447 case DW_TAG_subprogram:
5448 return "DW_TAG_subprogram";
5449 case DW_TAG_template_type_param:
5450 return "DW_TAG_template_type_param";
5451 case DW_TAG_template_value_param:
5452 return "DW_TAG_template_value_param";
5453 case DW_TAG_thrown_type:
5454 return "DW_TAG_thrown_type";
5455 case DW_TAG_try_block:
5456 return "DW_TAG_try_block";
5457 case DW_TAG_variant_part:
5458 return "DW_TAG_variant_part";
5459 case DW_TAG_variable:
5460 return "DW_TAG_variable";
5461 case DW_TAG_volatile_type:
5462 return "DW_TAG_volatile_type";
5463 case DW_TAG_dwarf_procedure:
5464 return "DW_TAG_dwarf_procedure";
5465 case DW_TAG_restrict_type:
5466 return "DW_TAG_restrict_type";
5467 case DW_TAG_interface_type:
5468 return "DW_TAG_interface_type";
5469 case DW_TAG_namespace:
5470 return "DW_TAG_namespace";
5471 case DW_TAG_imported_module:
5472 return "DW_TAG_imported_module";
5473 case DW_TAG_unspecified_type:
5474 return "DW_TAG_unspecified_type";
5475 case DW_TAG_partial_unit:
5476 return "DW_TAG_partial_unit";
5477 case DW_TAG_imported_unit:
5478 return "DW_TAG_imported_unit";
5479 case DW_TAG_condition:
5480 return "DW_TAG_condition";
5481 case DW_TAG_shared_type:
5482 return "DW_TAG_shared_type";
5483 case DW_TAG_MIPS_loop:
5484 return "DW_TAG_MIPS_loop";
5485 case DW_TAG_format_label:
5486 return "DW_TAG_format_label";
5487 case DW_TAG_function_template:
5488 return "DW_TAG_function_template";
5489 case DW_TAG_class_template:
5490 return "DW_TAG_class_template";
5491 case DW_TAG_GNU_BINCL:
5492 return "DW_TAG_GNU_BINCL";
5493 case DW_TAG_GNU_EINCL:
5494 return "DW_TAG_GNU_EINCL";
5496 return "DW_TAG_<unknown>";
5500 /* Convert a DWARF attribute code into its string name. */
5503 dwarf_attr_name (unsigned int attr)
5508 return "DW_AT_sibling";
5509 case DW_AT_location:
5510 return "DW_AT_location";
5512 return "DW_AT_name";
5513 case DW_AT_ordering:
5514 return "DW_AT_ordering";
5515 case DW_AT_subscr_data:
5516 return "DW_AT_subscr_data";
5517 case DW_AT_byte_size:
5518 return "DW_AT_byte_size";
5519 case DW_AT_bit_offset:
5520 return "DW_AT_bit_offset";
5521 case DW_AT_bit_size:
5522 return "DW_AT_bit_size";
5523 case DW_AT_element_list:
5524 return "DW_AT_element_list";
5525 case DW_AT_stmt_list:
5526 return "DW_AT_stmt_list";
5528 return "DW_AT_low_pc";
5530 return "DW_AT_high_pc";
5531 case DW_AT_language:
5532 return "DW_AT_language";
5534 return "DW_AT_member";
5536 return "DW_AT_discr";
5537 case DW_AT_discr_value:
5538 return "DW_AT_discr_value";
5539 case DW_AT_visibility:
5540 return "DW_AT_visibility";
5542 return "DW_AT_import";
5543 case DW_AT_string_length:
5544 return "DW_AT_string_length";
5545 case DW_AT_common_reference:
5546 return "DW_AT_common_reference";
5547 case DW_AT_comp_dir:
5548 return "DW_AT_comp_dir";
5549 case DW_AT_const_value:
5550 return "DW_AT_const_value";
5551 case DW_AT_containing_type:
5552 return "DW_AT_containing_type";
5553 case DW_AT_default_value:
5554 return "DW_AT_default_value";
5556 return "DW_AT_inline";
5557 case DW_AT_is_optional:
5558 return "DW_AT_is_optional";
5559 case DW_AT_lower_bound:
5560 return "DW_AT_lower_bound";
5561 case DW_AT_producer:
5562 return "DW_AT_producer";
5563 case DW_AT_prototyped:
5564 return "DW_AT_prototyped";
5565 case DW_AT_return_addr:
5566 return "DW_AT_return_addr";
5567 case DW_AT_start_scope:
5568 return "DW_AT_start_scope";
5569 case DW_AT_bit_stride:
5570 return "DW_AT_bit_stride";
5571 case DW_AT_upper_bound:
5572 return "DW_AT_upper_bound";
5573 case DW_AT_abstract_origin:
5574 return "DW_AT_abstract_origin";
5575 case DW_AT_accessibility:
5576 return "DW_AT_accessibility";
5577 case DW_AT_address_class:
5578 return "DW_AT_address_class";
5579 case DW_AT_artificial:
5580 return "DW_AT_artificial";
5581 case DW_AT_base_types:
5582 return "DW_AT_base_types";
5583 case DW_AT_calling_convention:
5584 return "DW_AT_calling_convention";
5586 return "DW_AT_count";
5587 case DW_AT_data_member_location:
5588 return "DW_AT_data_member_location";
5589 case DW_AT_decl_column:
5590 return "DW_AT_decl_column";
5591 case DW_AT_decl_file:
5592 return "DW_AT_decl_file";
5593 case DW_AT_decl_line:
5594 return "DW_AT_decl_line";
5595 case DW_AT_declaration:
5596 return "DW_AT_declaration";
5597 case DW_AT_discr_list:
5598 return "DW_AT_discr_list";
5599 case DW_AT_encoding:
5600 return "DW_AT_encoding";
5601 case DW_AT_external:
5602 return "DW_AT_external";
5603 case DW_AT_explicit:
5604 return "DW_AT_explicit";
5605 case DW_AT_frame_base:
5606 return "DW_AT_frame_base";
5608 return "DW_AT_friend";
5609 case DW_AT_identifier_case:
5610 return "DW_AT_identifier_case";
5611 case DW_AT_macro_info:
5612 return "DW_AT_macro_info";
5613 case DW_AT_namelist_items:
5614 return "DW_AT_namelist_items";
5615 case DW_AT_priority:
5616 return "DW_AT_priority";
5618 return "DW_AT_segment";
5619 case DW_AT_specification:
5620 return "DW_AT_specification";
5621 case DW_AT_static_link:
5622 return "DW_AT_static_link";
5624 return "DW_AT_type";
5625 case DW_AT_use_location:
5626 return "DW_AT_use_location";
5627 case DW_AT_variable_parameter:
5628 return "DW_AT_variable_parameter";
5629 case DW_AT_virtuality:
5630 return "DW_AT_virtuality";
5631 case DW_AT_vtable_elem_location:
5632 return "DW_AT_vtable_elem_location";
5634 case DW_AT_allocated:
5635 return "DW_AT_allocated";
5636 case DW_AT_associated:
5637 return "DW_AT_associated";
5638 case DW_AT_data_location:
5639 return "DW_AT_data_location";
5640 case DW_AT_byte_stride:
5641 return "DW_AT_byte_stride";
5642 case DW_AT_entry_pc:
5643 return "DW_AT_entry_pc";
5644 case DW_AT_use_UTF8:
5645 return "DW_AT_use_UTF8";
5646 case DW_AT_extension:
5647 return "DW_AT_extension";
5649 return "DW_AT_ranges";
5650 case DW_AT_trampoline:
5651 return "DW_AT_trampoline";
5652 case DW_AT_call_column:
5653 return "DW_AT_call_column";
5654 case DW_AT_call_file:
5655 return "DW_AT_call_file";
5656 case DW_AT_call_line:
5657 return "DW_AT_call_line";
5659 case DW_AT_MIPS_fde:
5660 return "DW_AT_MIPS_fde";
5661 case DW_AT_MIPS_loop_begin:
5662 return "DW_AT_MIPS_loop_begin";
5663 case DW_AT_MIPS_tail_loop_begin:
5664 return "DW_AT_MIPS_tail_loop_begin";
5665 case DW_AT_MIPS_epilog_begin:
5666 return "DW_AT_MIPS_epilog_begin";
5667 case DW_AT_MIPS_loop_unroll_factor:
5668 return "DW_AT_MIPS_loop_unroll_factor";
5669 case DW_AT_MIPS_software_pipeline_depth:
5670 return "DW_AT_MIPS_software_pipeline_depth";
5671 case DW_AT_MIPS_linkage_name:
5672 return "DW_AT_MIPS_linkage_name";
5673 case DW_AT_MIPS_stride:
5674 return "DW_AT_MIPS_stride";
5675 case DW_AT_MIPS_abstract_name:
5676 return "DW_AT_MIPS_abstract_name";
5677 case DW_AT_MIPS_clone_origin:
5678 return "DW_AT_MIPS_clone_origin";
5679 case DW_AT_MIPS_has_inlines:
5680 return "DW_AT_MIPS_has_inlines";
5682 case DW_AT_sf_names:
5683 return "DW_AT_sf_names";
5684 case DW_AT_src_info:
5685 return "DW_AT_src_info";
5686 case DW_AT_mac_info:
5687 return "DW_AT_mac_info";
5688 case DW_AT_src_coords:
5689 return "DW_AT_src_coords";
5690 case DW_AT_body_begin:
5691 return "DW_AT_body_begin";
5692 case DW_AT_body_end:
5693 return "DW_AT_body_end";
5694 case DW_AT_GNU_vector:
5695 return "DW_AT_GNU_vector";
5697 case DW_AT_VMS_rtnbeg_pd_address:
5698 return "DW_AT_VMS_rtnbeg_pd_address";
5701 return "DW_AT_<unknown>";
5705 /* Convert a DWARF value form code into its string name. */
5708 dwarf_form_name (unsigned int form)
5713 return "DW_FORM_addr";
5714 case DW_FORM_block2:
5715 return "DW_FORM_block2";
5716 case DW_FORM_block4:
5717 return "DW_FORM_block4";
5719 return "DW_FORM_data2";
5721 return "DW_FORM_data4";
5723 return "DW_FORM_data8";
5724 case DW_FORM_string:
5725 return "DW_FORM_string";
5727 return "DW_FORM_block";
5728 case DW_FORM_block1:
5729 return "DW_FORM_block1";
5731 return "DW_FORM_data1";
5733 return "DW_FORM_flag";
5735 return "DW_FORM_sdata";
5737 return "DW_FORM_strp";
5739 return "DW_FORM_udata";
5740 case DW_FORM_ref_addr:
5741 return "DW_FORM_ref_addr";
5743 return "DW_FORM_ref1";
5745 return "DW_FORM_ref2";
5747 return "DW_FORM_ref4";
5749 return "DW_FORM_ref8";
5750 case DW_FORM_ref_udata:
5751 return "DW_FORM_ref_udata";
5752 case DW_FORM_indirect:
5753 return "DW_FORM_indirect";
5755 return "DW_FORM_<unknown>";
5759 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5760 instance of an inlined instance of a decl which is local to an inline
5761 function, so we have to trace all of the way back through the origin chain
5762 to find out what sort of node actually served as the original seed for the
5766 decl_ultimate_origin (const_tree decl)
5768 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
5771 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5772 nodes in the function to point to themselves; ignore that if
5773 we're trying to output the abstract instance of this function. */
5774 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
5777 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5778 most distant ancestor, this should never happen. */
5779 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
5781 return DECL_ABSTRACT_ORIGIN (decl);
5784 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5785 of a virtual function may refer to a base class, so we check the 'this'
5789 decl_class_context (tree decl)
5791 tree context = NULL_TREE;
5793 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5794 context = DECL_CONTEXT (decl);
5796 context = TYPE_MAIN_VARIANT
5797 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5799 if (context && !TYPE_P (context))
5800 context = NULL_TREE;
5805 /* Add an attribute/value pair to a DIE. */
5808 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5810 /* Maybe this should be an assert? */
5814 if (die->die_attr == NULL)
5815 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5816 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5819 static inline enum dw_val_class
5820 AT_class (dw_attr_ref a)
5822 return a->dw_attr_val.val_class;
5825 /* Add a flag value attribute to a DIE. */
5828 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5832 attr.dw_attr = attr_kind;
5833 attr.dw_attr_val.val_class = dw_val_class_flag;
5834 attr.dw_attr_val.v.val_flag = flag;
5835 add_dwarf_attr (die, &attr);
5838 static inline unsigned
5839 AT_flag (dw_attr_ref a)
5841 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5842 return a->dw_attr_val.v.val_flag;
5845 /* Add a signed integer attribute value to a DIE. */
5848 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5852 attr.dw_attr = attr_kind;
5853 attr.dw_attr_val.val_class = dw_val_class_const;
5854 attr.dw_attr_val.v.val_int = int_val;
5855 add_dwarf_attr (die, &attr);
5858 static inline HOST_WIDE_INT
5859 AT_int (dw_attr_ref a)
5861 gcc_assert (a && AT_class (a) == dw_val_class_const);
5862 return a->dw_attr_val.v.val_int;
5865 /* Add an unsigned integer attribute value to a DIE. */
5868 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5869 unsigned HOST_WIDE_INT unsigned_val)
5873 attr.dw_attr = attr_kind;
5874 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5875 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5876 add_dwarf_attr (die, &attr);
5879 static inline unsigned HOST_WIDE_INT
5880 AT_unsigned (dw_attr_ref a)
5882 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5883 return a->dw_attr_val.v.val_unsigned;
5886 /* Add an unsigned double integer attribute value to a DIE. */
5889 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5890 long unsigned int val_hi, long unsigned int val_low)
5894 attr.dw_attr = attr_kind;
5895 attr.dw_attr_val.val_class = dw_val_class_long_long;
5896 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5897 attr.dw_attr_val.v.val_long_long.low = val_low;
5898 add_dwarf_attr (die, &attr);
5901 /* Add a floating point attribute value to a DIE and return it. */
5904 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5905 unsigned int length, unsigned int elt_size, unsigned char *array)
5909 attr.dw_attr = attr_kind;
5910 attr.dw_attr_val.val_class = dw_val_class_vec;
5911 attr.dw_attr_val.v.val_vec.length = length;
5912 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5913 attr.dw_attr_val.v.val_vec.array = array;
5914 add_dwarf_attr (die, &attr);
5917 /* Hash and equality functions for debug_str_hash. */
5920 debug_str_do_hash (const void *x)
5922 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5926 debug_str_eq (const void *x1, const void *x2)
5928 return strcmp ((((const struct indirect_string_node *)x1)->str),
5929 (const char *)x2) == 0;
5932 /* Add a string attribute value to a DIE. */
5935 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5938 struct indirect_string_node *node;
5941 if (! debug_str_hash)
5942 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5943 debug_str_eq, NULL);
5945 slot = htab_find_slot_with_hash (debug_str_hash, str,
5946 htab_hash_string (str), INSERT);
5949 node = (struct indirect_string_node *)
5950 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5951 node->str = ggc_strdup (str);
5955 node = (struct indirect_string_node *) *slot;
5959 attr.dw_attr = attr_kind;
5960 attr.dw_attr_val.val_class = dw_val_class_str;
5961 attr.dw_attr_val.v.val_str = node;
5962 add_dwarf_attr (die, &attr);
5965 static inline const char *
5966 AT_string (dw_attr_ref a)
5968 gcc_assert (a && AT_class (a) == dw_val_class_str);
5969 return a->dw_attr_val.v.val_str->str;
5972 /* Find out whether a string should be output inline in DIE
5973 or out-of-line in .debug_str section. */
5976 AT_string_form (dw_attr_ref a)
5978 struct indirect_string_node *node;
5982 gcc_assert (a && AT_class (a) == dw_val_class_str);
5984 node = a->dw_attr_val.v.val_str;
5988 len = strlen (node->str) + 1;
5990 /* If the string is shorter or equal to the size of the reference, it is
5991 always better to put it inline. */
5992 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5993 return node->form = DW_FORM_string;
5995 /* If we cannot expect the linker to merge strings in .debug_str
5996 section, only put it into .debug_str if it is worth even in this
5998 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5999 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
6000 return node->form = DW_FORM_string;
6002 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6003 ++dw2_string_counter;
6004 node->label = xstrdup (label);
6006 return node->form = DW_FORM_strp;
6009 /* Add a DIE reference attribute value to a DIE. */
6012 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6016 attr.dw_attr = attr_kind;
6017 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6018 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6019 attr.dw_attr_val.v.val_die_ref.external = 0;
6020 add_dwarf_attr (die, &attr);
6023 /* Add an AT_specification attribute to a DIE, and also make the back
6024 pointer from the specification to the definition. */
6027 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6029 add_AT_die_ref (die, DW_AT_specification, targ_die);
6030 gcc_assert (!targ_die->die_definition);
6031 targ_die->die_definition = die;
6034 static inline dw_die_ref
6035 AT_ref (dw_attr_ref a)
6037 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6038 return a->dw_attr_val.v.val_die_ref.die;
6042 AT_ref_external (dw_attr_ref a)
6044 if (a && AT_class (a) == dw_val_class_die_ref)
6045 return a->dw_attr_val.v.val_die_ref.external;
6051 set_AT_ref_external (dw_attr_ref a, int i)
6053 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6054 a->dw_attr_val.v.val_die_ref.external = i;
6057 /* Add an FDE reference attribute value to a DIE. */
6060 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6064 attr.dw_attr = attr_kind;
6065 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6066 attr.dw_attr_val.v.val_fde_index = targ_fde;
6067 add_dwarf_attr (die, &attr);
6070 /* Add a location description attribute value to a DIE. */
6073 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6077 attr.dw_attr = attr_kind;
6078 attr.dw_attr_val.val_class = dw_val_class_loc;
6079 attr.dw_attr_val.v.val_loc = loc;
6080 add_dwarf_attr (die, &attr);
6083 static inline dw_loc_descr_ref
6084 AT_loc (dw_attr_ref a)
6086 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6087 return a->dw_attr_val.v.val_loc;
6091 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6095 attr.dw_attr = attr_kind;
6096 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6097 attr.dw_attr_val.v.val_loc_list = loc_list;
6098 add_dwarf_attr (die, &attr);
6099 have_location_lists = true;
6102 static inline dw_loc_list_ref
6103 AT_loc_list (dw_attr_ref a)
6105 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6106 return a->dw_attr_val.v.val_loc_list;
6109 /* Add an address constant attribute value to a DIE. */
6112 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6116 attr.dw_attr = attr_kind;
6117 attr.dw_attr_val.val_class = dw_val_class_addr;
6118 attr.dw_attr_val.v.val_addr = addr;
6119 add_dwarf_attr (die, &attr);
6122 /* Get the RTX from to an address DIE attribute. */
6125 AT_addr (dw_attr_ref a)
6127 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6128 return a->dw_attr_val.v.val_addr;
6131 /* Add a file attribute value to a DIE. */
6134 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6135 struct dwarf_file_data *fd)
6139 attr.dw_attr = attr_kind;
6140 attr.dw_attr_val.val_class = dw_val_class_file;
6141 attr.dw_attr_val.v.val_file = fd;
6142 add_dwarf_attr (die, &attr);
6145 /* Get the dwarf_file_data from a file DIE attribute. */
6147 static inline struct dwarf_file_data *
6148 AT_file (dw_attr_ref a)
6150 gcc_assert (a && AT_class (a) == dw_val_class_file);
6151 return a->dw_attr_val.v.val_file;
6154 /* Add a label identifier attribute value to a DIE. */
6157 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6161 attr.dw_attr = attr_kind;
6162 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6163 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6164 add_dwarf_attr (die, &attr);
6167 /* Add a section offset attribute value to a DIE, an offset into the
6168 debug_line section. */
6171 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6176 attr.dw_attr = attr_kind;
6177 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6178 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6179 add_dwarf_attr (die, &attr);
6182 /* Add a section offset attribute value to a DIE, an offset into the
6183 debug_macinfo section. */
6186 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6191 attr.dw_attr = attr_kind;
6192 attr.dw_attr_val.val_class = dw_val_class_macptr;
6193 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6194 add_dwarf_attr (die, &attr);
6197 /* Add an offset attribute value to a DIE. */
6200 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6201 unsigned HOST_WIDE_INT offset)
6205 attr.dw_attr = attr_kind;
6206 attr.dw_attr_val.val_class = dw_val_class_offset;
6207 attr.dw_attr_val.v.val_offset = offset;
6208 add_dwarf_attr (die, &attr);
6211 /* Add an range_list attribute value to a DIE. */
6214 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6215 long unsigned int offset)
6219 attr.dw_attr = attr_kind;
6220 attr.dw_attr_val.val_class = dw_val_class_range_list;
6221 attr.dw_attr_val.v.val_offset = offset;
6222 add_dwarf_attr (die, &attr);
6225 static inline const char *
6226 AT_lbl (dw_attr_ref a)
6228 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6229 || AT_class (a) == dw_val_class_lineptr
6230 || AT_class (a) == dw_val_class_macptr));
6231 return a->dw_attr_val.v.val_lbl_id;
6234 /* Get the attribute of type attr_kind. */
6237 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6241 dw_die_ref spec = NULL;
6246 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6247 if (a->dw_attr == attr_kind)
6249 else if (a->dw_attr == DW_AT_specification
6250 || a->dw_attr == DW_AT_abstract_origin)
6254 return get_AT (spec, attr_kind);
6259 /* Return the "low pc" attribute value, typically associated with a subprogram
6260 DIE. Return null if the "low pc" attribute is either not present, or if it
6261 cannot be represented as an assembler label identifier. */
6263 static inline const char *
6264 get_AT_low_pc (dw_die_ref die)
6266 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6268 return a ? AT_lbl (a) : NULL;
6271 /* Return the "high pc" attribute value, typically associated with a subprogram
6272 DIE. Return null if the "high pc" attribute is either not present, or if it
6273 cannot be represented as an assembler label identifier. */
6275 static inline const char *
6276 get_AT_hi_pc (dw_die_ref die)
6278 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6280 return a ? AT_lbl (a) : NULL;
6283 /* Return the value of the string attribute designated by ATTR_KIND, or
6284 NULL if it is not present. */
6286 static inline const char *
6287 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6289 dw_attr_ref a = get_AT (die, attr_kind);
6291 return a ? AT_string (a) : NULL;
6294 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6295 if it is not present. */
6298 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6300 dw_attr_ref a = get_AT (die, attr_kind);
6302 return a ? AT_flag (a) : 0;
6305 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6306 if it is not present. */
6308 static inline unsigned
6309 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6311 dw_attr_ref a = get_AT (die, attr_kind);
6313 return a ? AT_unsigned (a) : 0;
6316 static inline dw_die_ref
6317 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6319 dw_attr_ref a = get_AT (die, attr_kind);
6321 return a ? AT_ref (a) : NULL;
6324 static inline struct dwarf_file_data *
6325 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6327 dw_attr_ref a = get_AT (die, attr_kind);
6329 return a ? AT_file (a) : NULL;
6332 /* Return TRUE if the language is C or C++. */
6337 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6339 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6340 || lang == DW_LANG_C99
6341 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6344 /* Return TRUE if the language is C++. */
6349 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6351 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6354 /* Return TRUE if the language is Fortran. */
6359 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6361 return (lang == DW_LANG_Fortran77
6362 || lang == DW_LANG_Fortran90
6363 || lang == DW_LANG_Fortran95);
6366 /* Return TRUE if the language is Java. */
6371 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6373 return lang == DW_LANG_Java;
6376 /* Return TRUE if the language is Ada. */
6381 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6383 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6386 /* Remove the specified attribute if present. */
6389 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6397 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6398 if (a->dw_attr == attr_kind)
6400 if (AT_class (a) == dw_val_class_str)
6401 if (a->dw_attr_val.v.val_str->refcount)
6402 a->dw_attr_val.v.val_str->refcount--;
6404 /* VEC_ordered_remove should help reduce the number of abbrevs
6406 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6411 /* Remove CHILD from its parent. PREV must have the property that
6412 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6415 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6417 gcc_assert (child->die_parent == prev->die_parent);
6418 gcc_assert (prev->die_sib == child);
6421 gcc_assert (child->die_parent->die_child == child);
6425 prev->die_sib = child->die_sib;
6426 if (child->die_parent->die_child == child)
6427 child->die_parent->die_child = prev;
6430 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6434 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6440 dw_die_ref prev = c;
6442 while (c->die_tag == tag)
6444 remove_child_with_prev (c, prev);
6445 /* Might have removed every child. */
6446 if (c == c->die_sib)
6450 } while (c != die->die_child);
6453 /* Add a CHILD_DIE as the last child of DIE. */
6456 add_child_die (dw_die_ref die, dw_die_ref child_die)
6458 /* FIXME this should probably be an assert. */
6459 if (! die || ! child_die)
6461 gcc_assert (die != child_die);
6463 child_die->die_parent = die;
6466 child_die->die_sib = die->die_child->die_sib;
6467 die->die_child->die_sib = child_die;
6470 child_die->die_sib = child_die;
6471 die->die_child = child_die;
6474 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6475 is the specification, to the end of PARENT's list of children.
6476 This is done by removing and re-adding it. */
6479 splice_child_die (dw_die_ref parent, dw_die_ref child)
6483 /* We want the declaration DIE from inside the class, not the
6484 specification DIE at toplevel. */
6485 if (child->die_parent != parent)
6487 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6493 gcc_assert (child->die_parent == parent
6494 || (child->die_parent
6495 == get_AT_ref (parent, DW_AT_specification)));
6497 for (p = child->die_parent->die_child; ; p = p->die_sib)
6498 if (p->die_sib == child)
6500 remove_child_with_prev (child, p);
6504 add_child_die (parent, child);
6507 /* Return a pointer to a newly created DIE node. */
6509 static inline dw_die_ref
6510 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6512 dw_die_ref die = GGC_CNEW (die_node);
6514 die->die_tag = tag_value;
6516 if (parent_die != NULL)
6517 add_child_die (parent_die, die);
6520 limbo_die_node *limbo_node;
6522 limbo_node = GGC_CNEW (limbo_die_node);
6523 limbo_node->die = die;
6524 limbo_node->created_for = t;
6525 limbo_node->next = limbo_die_list;
6526 limbo_die_list = limbo_node;
6532 /* Return the DIE associated with the given type specifier. */
6534 static inline dw_die_ref
6535 lookup_type_die (tree type)
6537 return TYPE_SYMTAB_DIE (type);
6540 /* Equate a DIE to a given type specifier. */
6543 equate_type_number_to_die (tree type, dw_die_ref type_die)
6545 TYPE_SYMTAB_DIE (type) = type_die;
6548 /* Returns a hash value for X (which really is a die_struct). */
6551 decl_die_table_hash (const void *x)
6553 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6556 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6559 decl_die_table_eq (const void *x, const void *y)
6561 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6564 /* Return the DIE associated with a given declaration. */
6566 static inline dw_die_ref
6567 lookup_decl_die (tree decl)
6569 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6572 /* Returns a hash value for X (which really is a var_loc_list). */
6575 decl_loc_table_hash (const void *x)
6577 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6580 /* Return nonzero if decl_id of var_loc_list X is the same as
6584 decl_loc_table_eq (const void *x, const void *y)
6586 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6589 /* Return the var_loc list associated with a given declaration. */
6591 static inline var_loc_list *
6592 lookup_decl_loc (const_tree decl)
6594 return (var_loc_list *)
6595 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6598 /* Equate a DIE to a particular declaration. */
6601 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6603 unsigned int decl_id = DECL_UID (decl);
6606 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6608 decl_die->decl_id = decl_id;
6611 /* Add a variable location node to the linked list for DECL. */
6614 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6616 unsigned int decl_id = DECL_UID (decl);
6620 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6623 temp = GGC_CNEW (var_loc_list);
6624 temp->decl_id = decl_id;
6628 temp = (var_loc_list *) *slot;
6632 /* If the current location is the same as the end of the list,
6633 and either both or neither of the locations is uninitialized,
6634 we have nothing to do. */
6635 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6636 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6637 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6638 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6639 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6640 == VAR_INIT_STATUS_UNINITIALIZED)
6641 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6642 == VAR_INIT_STATUS_UNINITIALIZED))))
6644 /* Add LOC to the end of list and update LAST. */
6645 temp->last->next = loc;
6649 /* Do not add empty location to the beginning of the list. */
6650 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
6657 /* Keep track of the number of spaces used to indent the
6658 output of the debugging routines that print the structure of
6659 the DIE internal representation. */
6660 static int print_indent;
6662 /* Indent the line the number of spaces given by print_indent. */
6665 print_spaces (FILE *outfile)
6667 fprintf (outfile, "%*s", print_indent, "");
6670 /* Print the information associated with a given DIE, and its children.
6671 This routine is a debugging aid only. */
6674 print_die (dw_die_ref die, FILE *outfile)
6680 print_spaces (outfile);
6681 fprintf (outfile, "DIE %4ld: %s\n",
6682 die->die_offset, dwarf_tag_name (die->die_tag));
6683 print_spaces (outfile);
6684 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6685 fprintf (outfile, " offset: %ld\n", die->die_offset);
6687 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6689 print_spaces (outfile);
6690 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6692 switch (AT_class (a))
6694 case dw_val_class_addr:
6695 fprintf (outfile, "address");
6697 case dw_val_class_offset:
6698 fprintf (outfile, "offset");
6700 case dw_val_class_loc:
6701 fprintf (outfile, "location descriptor");
6703 case dw_val_class_loc_list:
6704 fprintf (outfile, "location list -> label:%s",
6705 AT_loc_list (a)->ll_symbol);
6707 case dw_val_class_range_list:
6708 fprintf (outfile, "range list");
6710 case dw_val_class_const:
6711 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6713 case dw_val_class_unsigned_const:
6714 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6716 case dw_val_class_long_long:
6717 fprintf (outfile, "constant (%lu,%lu)",
6718 a->dw_attr_val.v.val_long_long.hi,
6719 a->dw_attr_val.v.val_long_long.low);
6721 case dw_val_class_vec:
6722 fprintf (outfile, "floating-point or vector constant");
6724 case dw_val_class_flag:
6725 fprintf (outfile, "%u", AT_flag (a));
6727 case dw_val_class_die_ref:
6728 if (AT_ref (a) != NULL)
6730 if (AT_ref (a)->die_symbol)
6731 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
6733 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6736 fprintf (outfile, "die -> <null>");
6738 case dw_val_class_lbl_id:
6739 case dw_val_class_lineptr:
6740 case dw_val_class_macptr:
6741 fprintf (outfile, "label: %s", AT_lbl (a));
6743 case dw_val_class_str:
6744 if (AT_string (a) != NULL)
6745 fprintf (outfile, "\"%s\"", AT_string (a));
6747 fprintf (outfile, "<null>");
6749 case dw_val_class_file:
6750 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6751 AT_file (a)->emitted_number);
6757 fprintf (outfile, "\n");
6760 if (die->die_child != NULL)
6763 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6766 if (print_indent == 0)
6767 fprintf (outfile, "\n");
6770 /* Print the contents of the source code line number correspondence table.
6771 This routine is a debugging aid only. */
6774 print_dwarf_line_table (FILE *outfile)
6777 dw_line_info_ref line_info;
6779 fprintf (outfile, "\n\nDWARF source line information\n");
6780 for (i = 1; i < line_info_table_in_use; i++)
6782 line_info = &line_info_table[i];
6783 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6784 line_info->dw_file_num,
6785 line_info->dw_line_num);
6788 fprintf (outfile, "\n\n");
6791 /* Print the information collected for a given DIE. */
6794 debug_dwarf_die (dw_die_ref die)
6796 print_die (die, stderr);
6799 /* Print all DWARF information collected for the compilation unit.
6800 This routine is a debugging aid only. */
6806 print_die (comp_unit_die, stderr);
6807 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6808 print_dwarf_line_table (stderr);
6811 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6812 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6813 DIE that marks the start of the DIEs for this include file. */
6816 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6818 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6819 dw_die_ref new_unit = gen_compile_unit_die (filename);
6821 new_unit->die_sib = old_unit;
6825 /* Close an include-file CU and reopen the enclosing one. */
6828 pop_compile_unit (dw_die_ref old_unit)
6830 dw_die_ref new_unit = old_unit->die_sib;
6832 old_unit->die_sib = NULL;
6836 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6837 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6839 /* Calculate the checksum of a location expression. */
6842 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6844 CHECKSUM (loc->dw_loc_opc);
6845 CHECKSUM (loc->dw_loc_oprnd1);
6846 CHECKSUM (loc->dw_loc_oprnd2);
6849 /* Calculate the checksum of an attribute. */
6852 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6854 dw_loc_descr_ref loc;
6857 CHECKSUM (at->dw_attr);
6859 /* We don't care that this was compiled with a different compiler
6860 snapshot; if the output is the same, that's what matters. */
6861 if (at->dw_attr == DW_AT_producer)
6864 switch (AT_class (at))
6866 case dw_val_class_const:
6867 CHECKSUM (at->dw_attr_val.v.val_int);
6869 case dw_val_class_unsigned_const:
6870 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6872 case dw_val_class_long_long:
6873 CHECKSUM (at->dw_attr_val.v.val_long_long);
6875 case dw_val_class_vec:
6876 CHECKSUM (at->dw_attr_val.v.val_vec);
6878 case dw_val_class_flag:
6879 CHECKSUM (at->dw_attr_val.v.val_flag);
6881 case dw_val_class_str:
6882 CHECKSUM_STRING (AT_string (at));
6885 case dw_val_class_addr:
6887 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6888 CHECKSUM_STRING (XSTR (r, 0));
6891 case dw_val_class_offset:
6892 CHECKSUM (at->dw_attr_val.v.val_offset);
6895 case dw_val_class_loc:
6896 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6897 loc_checksum (loc, ctx);
6900 case dw_val_class_die_ref:
6901 die_checksum (AT_ref (at), ctx, mark);
6904 case dw_val_class_fde_ref:
6905 case dw_val_class_lbl_id:
6906 case dw_val_class_lineptr:
6907 case dw_val_class_macptr:
6910 case dw_val_class_file:
6911 CHECKSUM_STRING (AT_file (at)->filename);
6919 /* Calculate the checksum of a DIE. */
6922 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6928 /* To avoid infinite recursion. */
6931 CHECKSUM (die->die_mark);
6934 die->die_mark = ++(*mark);
6936 CHECKSUM (die->die_tag);
6938 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6939 attr_checksum (a, ctx, mark);
6941 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6945 #undef CHECKSUM_STRING
6947 /* Do the location expressions look same? */
6949 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6951 return loc1->dw_loc_opc == loc2->dw_loc_opc
6952 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6953 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6956 /* Do the values look the same? */
6958 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6960 dw_loc_descr_ref loc1, loc2;
6963 if (v1->val_class != v2->val_class)
6966 switch (v1->val_class)
6968 case dw_val_class_const:
6969 return v1->v.val_int == v2->v.val_int;
6970 case dw_val_class_unsigned_const:
6971 return v1->v.val_unsigned == v2->v.val_unsigned;
6972 case dw_val_class_long_long:
6973 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6974 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6975 case dw_val_class_vec:
6976 if (v1->v.val_vec.length != v2->v.val_vec.length
6977 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6979 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6980 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6983 case dw_val_class_flag:
6984 return v1->v.val_flag == v2->v.val_flag;
6985 case dw_val_class_str:
6986 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6988 case dw_val_class_addr:
6989 r1 = v1->v.val_addr;
6990 r2 = v2->v.val_addr;
6991 if (GET_CODE (r1) != GET_CODE (r2))
6993 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6994 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6996 case dw_val_class_offset:
6997 return v1->v.val_offset == v2->v.val_offset;
6999 case dw_val_class_loc:
7000 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7002 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7003 if (!same_loc_p (loc1, loc2, mark))
7005 return !loc1 && !loc2;
7007 case dw_val_class_die_ref:
7008 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7010 case dw_val_class_fde_ref:
7011 case dw_val_class_lbl_id:
7012 case dw_val_class_lineptr:
7013 case dw_val_class_macptr:
7016 case dw_val_class_file:
7017 return v1->v.val_file == v2->v.val_file;
7024 /* Do the attributes look the same? */
7027 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7029 if (at1->dw_attr != at2->dw_attr)
7032 /* We don't care that this was compiled with a different compiler
7033 snapshot; if the output is the same, that's what matters. */
7034 if (at1->dw_attr == DW_AT_producer)
7037 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7040 /* Do the dies look the same? */
7043 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7049 /* To avoid infinite recursion. */
7051 return die1->die_mark == die2->die_mark;
7052 die1->die_mark = die2->die_mark = ++(*mark);
7054 if (die1->die_tag != die2->die_tag)
7057 if (VEC_length (dw_attr_node, die1->die_attr)
7058 != VEC_length (dw_attr_node, die2->die_attr))
7061 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7062 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7065 c1 = die1->die_child;
7066 c2 = die2->die_child;
7075 if (!same_die_p (c1, c2, mark))
7079 if (c1 == die1->die_child)
7081 if (c2 == die2->die_child)
7091 /* Do the dies look the same? Wrapper around same_die_p. */
7094 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7097 int ret = same_die_p (die1, die2, &mark);
7099 unmark_all_dies (die1);
7100 unmark_all_dies (die2);
7105 /* The prefix to attach to symbols on DIEs in the current comdat debug
7107 static char *comdat_symbol_id;
7109 /* The index of the current symbol within the current comdat CU. */
7110 static unsigned int comdat_symbol_number;
7112 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7113 children, and set comdat_symbol_id accordingly. */
7116 compute_section_prefix (dw_die_ref unit_die)
7118 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7119 const char *base = die_name ? lbasename (die_name) : "anonymous";
7120 char *name = XALLOCAVEC (char, strlen (base) + 64);
7123 unsigned char checksum[16];
7126 /* Compute the checksum of the DIE, then append part of it as hex digits to
7127 the name filename of the unit. */
7129 md5_init_ctx (&ctx);
7131 die_checksum (unit_die, &ctx, &mark);
7132 unmark_all_dies (unit_die);
7133 md5_finish_ctx (&ctx, checksum);
7135 sprintf (name, "%s.", base);
7136 clean_symbol_name (name);
7138 p = name + strlen (name);
7139 for (i = 0; i < 4; i++)
7141 sprintf (p, "%.2x", checksum[i]);
7145 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7146 comdat_symbol_number = 0;
7149 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7152 is_type_die (dw_die_ref die)
7154 switch (die->die_tag)
7156 case DW_TAG_array_type:
7157 case DW_TAG_class_type:
7158 case DW_TAG_interface_type:
7159 case DW_TAG_enumeration_type:
7160 case DW_TAG_pointer_type:
7161 case DW_TAG_reference_type:
7162 case DW_TAG_string_type:
7163 case DW_TAG_structure_type:
7164 case DW_TAG_subroutine_type:
7165 case DW_TAG_union_type:
7166 case DW_TAG_ptr_to_member_type:
7167 case DW_TAG_set_type:
7168 case DW_TAG_subrange_type:
7169 case DW_TAG_base_type:
7170 case DW_TAG_const_type:
7171 case DW_TAG_file_type:
7172 case DW_TAG_packed_type:
7173 case DW_TAG_volatile_type:
7174 case DW_TAG_typedef:
7181 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7182 Basically, we want to choose the bits that are likely to be shared between
7183 compilations (types) and leave out the bits that are specific to individual
7184 compilations (functions). */
7187 is_comdat_die (dw_die_ref c)
7189 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7190 we do for stabs. The advantage is a greater likelihood of sharing between
7191 objects that don't include headers in the same order (and therefore would
7192 put the base types in a different comdat). jason 8/28/00 */
7194 if (c->die_tag == DW_TAG_base_type)
7197 if (c->die_tag == DW_TAG_pointer_type
7198 || c->die_tag == DW_TAG_reference_type
7199 || c->die_tag == DW_TAG_const_type
7200 || c->die_tag == DW_TAG_volatile_type)
7202 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7204 return t ? is_comdat_die (t) : 0;
7207 return is_type_die (c);
7210 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7211 compilation unit. */
7214 is_symbol_die (dw_die_ref c)
7216 return (is_type_die (c)
7217 || (get_AT (c, DW_AT_declaration)
7218 && !get_AT (c, DW_AT_specification))
7219 || c->die_tag == DW_TAG_namespace
7220 || c->die_tag == DW_TAG_module);
7224 gen_internal_sym (const char *prefix)
7228 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7229 return xstrdup (buf);
7232 /* Assign symbols to all worthy DIEs under DIE. */
7235 assign_symbol_names (dw_die_ref die)
7239 if (is_symbol_die (die))
7241 if (comdat_symbol_id)
7243 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7245 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7246 comdat_symbol_id, comdat_symbol_number++);
7247 die->die_symbol = xstrdup (p);
7250 die->die_symbol = gen_internal_sym ("LDIE");
7253 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7256 struct cu_hash_table_entry
7259 unsigned min_comdat_num, max_comdat_num;
7260 struct cu_hash_table_entry *next;
7263 /* Routines to manipulate hash table of CUs. */
7265 htab_cu_hash (const void *of)
7267 const struct cu_hash_table_entry *const entry =
7268 (const struct cu_hash_table_entry *) of;
7270 return htab_hash_string (entry->cu->die_symbol);
7274 htab_cu_eq (const void *of1, const void *of2)
7276 const struct cu_hash_table_entry *const entry1 =
7277 (const struct cu_hash_table_entry *) of1;
7278 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7280 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7284 htab_cu_del (void *what)
7286 struct cu_hash_table_entry *next,
7287 *entry = (struct cu_hash_table_entry *) what;
7297 /* Check whether we have already seen this CU and set up SYM_NUM
7300 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7302 struct cu_hash_table_entry dummy;
7303 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7305 dummy.max_comdat_num = 0;
7307 slot = (struct cu_hash_table_entry **)
7308 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7312 for (; entry; last = entry, entry = entry->next)
7314 if (same_die_p_wrap (cu, entry->cu))
7320 *sym_num = entry->min_comdat_num;
7324 entry = XCNEW (struct cu_hash_table_entry);
7326 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7327 entry->next = *slot;
7333 /* Record SYM_NUM to record of CU in HTABLE. */
7335 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7337 struct cu_hash_table_entry **slot, *entry;
7339 slot = (struct cu_hash_table_entry **)
7340 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7344 entry->max_comdat_num = sym_num;
7347 /* Traverse the DIE (which is always comp_unit_die), and set up
7348 additional compilation units for each of the include files we see
7349 bracketed by BINCL/EINCL. */
7352 break_out_includes (dw_die_ref die)
7355 dw_die_ref unit = NULL;
7356 limbo_die_node *node, **pnode;
7357 htab_t cu_hash_table;
7361 dw_die_ref prev = c;
7363 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7364 || (unit && is_comdat_die (c)))
7366 dw_die_ref next = c->die_sib;
7368 /* This DIE is for a secondary CU; remove it from the main one. */
7369 remove_child_with_prev (c, prev);
7371 if (c->die_tag == DW_TAG_GNU_BINCL)
7372 unit = push_new_compile_unit (unit, c);
7373 else if (c->die_tag == DW_TAG_GNU_EINCL)
7374 unit = pop_compile_unit (unit);
7376 add_child_die (unit, c);
7378 if (c == die->die_child)
7381 } while (c != die->die_child);
7384 /* We can only use this in debugging, since the frontend doesn't check
7385 to make sure that we leave every include file we enter. */
7389 assign_symbol_names (die);
7390 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7391 for (node = limbo_die_list, pnode = &limbo_die_list;
7397 compute_section_prefix (node->die);
7398 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7399 &comdat_symbol_number);
7400 assign_symbol_names (node->die);
7402 *pnode = node->next;
7405 pnode = &node->next;
7406 record_comdat_symbol_number (node->die, cu_hash_table,
7407 comdat_symbol_number);
7410 htab_delete (cu_hash_table);
7413 /* Traverse the DIE and add a sibling attribute if it may have the
7414 effect of speeding up access to siblings. To save some space,
7415 avoid generating sibling attributes for DIE's without children. */
7418 add_sibling_attributes (dw_die_ref die)
7422 if (! die->die_child)
7425 if (die->die_parent && die != die->die_parent->die_child)
7426 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7428 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7431 /* Output all location lists for the DIE and its children. */
7434 output_location_lists (dw_die_ref die)
7440 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7441 if (AT_class (a) == dw_val_class_loc_list)
7442 output_loc_list (AT_loc_list (a));
7444 FOR_EACH_CHILD (die, c, output_location_lists (c));
7447 /* The format of each DIE (and its attribute value pairs) is encoded in an
7448 abbreviation table. This routine builds the abbreviation table and assigns
7449 a unique abbreviation id for each abbreviation entry. The children of each
7450 die are visited recursively. */
7453 build_abbrev_table (dw_die_ref die)
7455 unsigned long abbrev_id;
7456 unsigned int n_alloc;
7461 /* Scan the DIE references, and mark as external any that refer to
7462 DIEs from other CUs (i.e. those which are not marked). */
7463 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7464 if (AT_class (a) == dw_val_class_die_ref
7465 && AT_ref (a)->die_mark == 0)
7467 gcc_assert (AT_ref (a)->die_symbol);
7469 set_AT_ref_external (a, 1);
7472 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7474 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7475 dw_attr_ref die_a, abbrev_a;
7479 if (abbrev->die_tag != die->die_tag)
7481 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7484 if (VEC_length (dw_attr_node, abbrev->die_attr)
7485 != VEC_length (dw_attr_node, die->die_attr))
7488 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7490 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7491 if ((abbrev_a->dw_attr != die_a->dw_attr)
7492 || (value_format (abbrev_a) != value_format (die_a)))
7502 if (abbrev_id >= abbrev_die_table_in_use)
7504 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7506 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7507 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7510 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7511 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7512 abbrev_die_table_allocated = n_alloc;
7515 ++abbrev_die_table_in_use;
7516 abbrev_die_table[abbrev_id] = die;
7519 die->die_abbrev = abbrev_id;
7520 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7523 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7526 constant_size (unsigned HOST_WIDE_INT value)
7533 log = floor_log2 (value);
7536 log = 1 << (floor_log2 (log) + 1);
7541 /* Return the size of a DIE as it is represented in the
7542 .debug_info section. */
7544 static unsigned long
7545 size_of_die (dw_die_ref die)
7547 unsigned long size = 0;
7551 size += size_of_uleb128 (die->die_abbrev);
7552 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7554 switch (AT_class (a))
7556 case dw_val_class_addr:
7557 size += DWARF2_ADDR_SIZE;
7559 case dw_val_class_offset:
7560 size += DWARF_OFFSET_SIZE;
7562 case dw_val_class_loc:
7564 unsigned long lsize = size_of_locs (AT_loc (a));
7567 size += constant_size (lsize);
7571 case dw_val_class_loc_list:
7572 size += DWARF_OFFSET_SIZE;
7574 case dw_val_class_range_list:
7575 size += DWARF_OFFSET_SIZE;
7577 case dw_val_class_const:
7578 size += size_of_sleb128 (AT_int (a));
7580 case dw_val_class_unsigned_const:
7581 size += constant_size (AT_unsigned (a));
7583 case dw_val_class_long_long:
7584 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7586 case dw_val_class_vec:
7587 size += constant_size (a->dw_attr_val.v.val_vec.length
7588 * a->dw_attr_val.v.val_vec.elt_size)
7589 + a->dw_attr_val.v.val_vec.length
7590 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7592 case dw_val_class_flag:
7595 case dw_val_class_die_ref:
7596 if (AT_ref_external (a))
7597 size += DWARF2_ADDR_SIZE;
7599 size += DWARF_OFFSET_SIZE;
7601 case dw_val_class_fde_ref:
7602 size += DWARF_OFFSET_SIZE;
7604 case dw_val_class_lbl_id:
7605 size += DWARF2_ADDR_SIZE;
7607 case dw_val_class_lineptr:
7608 case dw_val_class_macptr:
7609 size += DWARF_OFFSET_SIZE;
7611 case dw_val_class_str:
7612 if (AT_string_form (a) == DW_FORM_strp)
7613 size += DWARF_OFFSET_SIZE;
7615 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7617 case dw_val_class_file:
7618 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7628 /* Size the debugging information associated with a given DIE. Visits the
7629 DIE's children recursively. Updates the global variable next_die_offset, on
7630 each time through. Uses the current value of next_die_offset to update the
7631 die_offset field in each DIE. */
7634 calc_die_sizes (dw_die_ref die)
7638 die->die_offset = next_die_offset;
7639 next_die_offset += size_of_die (die);
7641 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7643 if (die->die_child != NULL)
7644 /* Count the null byte used to terminate sibling lists. */
7645 next_die_offset += 1;
7648 /* Set the marks for a die and its children. We do this so
7649 that we know whether or not a reference needs to use FORM_ref_addr; only
7650 DIEs in the same CU will be marked. We used to clear out the offset
7651 and use that as the flag, but ran into ordering problems. */
7654 mark_dies (dw_die_ref die)
7658 gcc_assert (!die->die_mark);
7661 FOR_EACH_CHILD (die, c, mark_dies (c));
7664 /* Clear the marks for a die and its children. */
7667 unmark_dies (dw_die_ref die)
7671 gcc_assert (die->die_mark);
7674 FOR_EACH_CHILD (die, c, unmark_dies (c));
7677 /* Clear the marks for a die, its children and referred dies. */
7680 unmark_all_dies (dw_die_ref die)
7690 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7692 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7693 if (AT_class (a) == dw_val_class_die_ref)
7694 unmark_all_dies (AT_ref (a));
7697 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7698 generated for the compilation unit. */
7700 static unsigned long
7701 size_of_pubnames (VEC (pubname_entry, gc) * names)
7707 size = DWARF_PUBNAMES_HEADER_SIZE;
7708 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7709 if (names != pubtype_table
7710 || p->die->die_offset != 0
7711 || !flag_eliminate_unused_debug_types)
7712 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7714 size += DWARF_OFFSET_SIZE;
7718 /* Return the size of the information in the .debug_aranges section. */
7720 static unsigned long
7721 size_of_aranges (void)
7725 size = DWARF_ARANGES_HEADER_SIZE;
7727 /* Count the address/length pair for this compilation unit. */
7728 if (text_section_used)
7729 size += 2 * DWARF2_ADDR_SIZE;
7730 if (cold_text_section_used)
7731 size += 2 * DWARF2_ADDR_SIZE;
7732 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7734 /* Count the two zero words used to terminated the address range table. */
7735 size += 2 * DWARF2_ADDR_SIZE;
7739 /* Select the encoding of an attribute value. */
7741 static enum dwarf_form
7742 value_format (dw_attr_ref a)
7744 switch (a->dw_attr_val.val_class)
7746 case dw_val_class_addr:
7747 return DW_FORM_addr;
7748 case dw_val_class_range_list:
7749 case dw_val_class_offset:
7750 case dw_val_class_loc_list:
7751 switch (DWARF_OFFSET_SIZE)
7754 return DW_FORM_data4;
7756 return DW_FORM_data8;
7760 case dw_val_class_loc:
7761 switch (constant_size (size_of_locs (AT_loc (a))))
7764 return DW_FORM_block1;
7766 return DW_FORM_block2;
7770 case dw_val_class_const:
7771 return DW_FORM_sdata;
7772 case dw_val_class_unsigned_const:
7773 switch (constant_size (AT_unsigned (a)))
7776 return DW_FORM_data1;
7778 return DW_FORM_data2;
7780 return DW_FORM_data4;
7782 return DW_FORM_data8;
7786 case dw_val_class_long_long:
7787 return DW_FORM_block1;
7788 case dw_val_class_vec:
7789 switch (constant_size (a->dw_attr_val.v.val_vec.length
7790 * a->dw_attr_val.v.val_vec.elt_size))
7793 return DW_FORM_block1;
7795 return DW_FORM_block2;
7797 return DW_FORM_block4;
7801 case dw_val_class_flag:
7802 return DW_FORM_flag;
7803 case dw_val_class_die_ref:
7804 if (AT_ref_external (a))
7805 return DW_FORM_ref_addr;
7808 case dw_val_class_fde_ref:
7809 return DW_FORM_data;
7810 case dw_val_class_lbl_id:
7811 return DW_FORM_addr;
7812 case dw_val_class_lineptr:
7813 case dw_val_class_macptr:
7814 return DW_FORM_data;
7815 case dw_val_class_str:
7816 return AT_string_form (a);
7817 case dw_val_class_file:
7818 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7821 return DW_FORM_data1;
7823 return DW_FORM_data2;
7825 return DW_FORM_data4;
7835 /* Output the encoding of an attribute value. */
7838 output_value_format (dw_attr_ref a)
7840 enum dwarf_form form = value_format (a);
7842 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7845 /* Output the .debug_abbrev section which defines the DIE abbreviation
7849 output_abbrev_section (void)
7851 unsigned long abbrev_id;
7853 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7855 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7859 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7860 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7861 dwarf_tag_name (abbrev->die_tag));
7863 if (abbrev->die_child != NULL)
7864 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7866 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7868 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7871 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7872 dwarf_attr_name (a_attr->dw_attr));
7873 output_value_format (a_attr);
7876 dw2_asm_output_data (1, 0, NULL);
7877 dw2_asm_output_data (1, 0, NULL);
7880 /* Terminate the table. */
7881 dw2_asm_output_data (1, 0, NULL);
7884 /* Output a symbol we can use to refer to this DIE from another CU. */
7887 output_die_symbol (dw_die_ref die)
7889 char *sym = die->die_symbol;
7894 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7895 /* We make these global, not weak; if the target doesn't support
7896 .linkonce, it doesn't support combining the sections, so debugging
7898 targetm.asm_out.globalize_label (asm_out_file, sym);
7900 ASM_OUTPUT_LABEL (asm_out_file, sym);
7903 /* Return a new location list, given the begin and end range, and the
7904 expression. gensym tells us whether to generate a new internal symbol for
7905 this location list node, which is done for the head of the list only. */
7907 static inline dw_loc_list_ref
7908 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7909 const char *section, unsigned int gensym)
7911 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7913 retlist->begin = begin;
7915 retlist->expr = expr;
7916 retlist->section = section;
7918 retlist->ll_symbol = gen_internal_sym ("LLST");
7923 /* Add a location description expression to a location list. */
7926 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7927 const char *begin, const char *end,
7928 const char *section)
7932 /* Find the end of the chain. */
7933 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7936 /* Add a new location list node to the list. */
7937 *d = new_loc_list (descr, begin, end, section, 0);
7940 /* Output the location list given to us. */
7943 output_loc_list (dw_loc_list_ref list_head)
7945 dw_loc_list_ref curr = list_head;
7947 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7949 /* Walk the location list, and output each range + expression. */
7950 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7953 /* Don't output an entry that starts and ends at the same address. */
7954 if (strcmp (curr->begin, curr->end) == 0)
7956 if (!have_multiple_function_sections)
7958 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7959 "Location list begin address (%s)",
7960 list_head->ll_symbol);
7961 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7962 "Location list end address (%s)",
7963 list_head->ll_symbol);
7967 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7968 "Location list begin address (%s)",
7969 list_head->ll_symbol);
7970 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7971 "Location list end address (%s)",
7972 list_head->ll_symbol);
7974 size = size_of_locs (curr->expr);
7976 /* Output the block length for this list of location operations. */
7977 gcc_assert (size <= 0xffff);
7978 dw2_asm_output_data (2, size, "%s", "Location expression size");
7980 output_loc_sequence (curr->expr);
7983 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7984 "Location list terminator begin (%s)",
7985 list_head->ll_symbol);
7986 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7987 "Location list terminator end (%s)",
7988 list_head->ll_symbol);
7991 /* Output the DIE and its attributes. Called recursively to generate
7992 the definitions of each child DIE. */
7995 output_die (dw_die_ref die)
8002 /* If someone in another CU might refer to us, set up a symbol for
8003 them to point to. */
8004 if (die->die_symbol)
8005 output_die_symbol (die);
8007 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8008 (unsigned long)die->die_offset,
8009 dwarf_tag_name (die->die_tag));
8011 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8013 const char *name = dwarf_attr_name (a->dw_attr);
8015 switch (AT_class (a))
8017 case dw_val_class_addr:
8018 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8021 case dw_val_class_offset:
8022 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8026 case dw_val_class_range_list:
8028 char *p = strchr (ranges_section_label, '\0');
8030 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8031 a->dw_attr_val.v.val_offset);
8032 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8033 debug_ranges_section, "%s", name);
8038 case dw_val_class_loc:
8039 size = size_of_locs (AT_loc (a));
8041 /* Output the block length for this list of location operations. */
8042 dw2_asm_output_data (constant_size (size), size, "%s", name);
8044 output_loc_sequence (AT_loc (a));
8047 case dw_val_class_const:
8048 /* ??? It would be slightly more efficient to use a scheme like is
8049 used for unsigned constants below, but gdb 4.x does not sign
8050 extend. Gdb 5.x does sign extend. */
8051 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8054 case dw_val_class_unsigned_const:
8055 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8056 AT_unsigned (a), "%s", name);
8059 case dw_val_class_long_long:
8061 unsigned HOST_WIDE_INT first, second;
8063 dw2_asm_output_data (1,
8064 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8067 if (WORDS_BIG_ENDIAN)
8069 first = a->dw_attr_val.v.val_long_long.hi;
8070 second = a->dw_attr_val.v.val_long_long.low;
8074 first = a->dw_attr_val.v.val_long_long.low;
8075 second = a->dw_attr_val.v.val_long_long.hi;
8078 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8079 first, "long long constant");
8080 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8085 case dw_val_class_vec:
8087 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8088 unsigned int len = a->dw_attr_val.v.val_vec.length;
8092 dw2_asm_output_data (constant_size (len * elt_size),
8093 len * elt_size, "%s", name);
8094 if (elt_size > sizeof (HOST_WIDE_INT))
8099 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8102 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8103 "fp or vector constant word %u", i);
8107 case dw_val_class_flag:
8108 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8111 case dw_val_class_loc_list:
8113 char *sym = AT_loc_list (a)->ll_symbol;
8116 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8121 case dw_val_class_die_ref:
8122 if (AT_ref_external (a))
8124 char *sym = AT_ref (a)->die_symbol;
8127 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8132 gcc_assert (AT_ref (a)->die_offset);
8133 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8138 case dw_val_class_fde_ref:
8142 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8143 a->dw_attr_val.v.val_fde_index * 2);
8144 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8149 case dw_val_class_lbl_id:
8150 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8153 case dw_val_class_lineptr:
8154 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8155 debug_line_section, "%s", name);
8158 case dw_val_class_macptr:
8159 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8160 debug_macinfo_section, "%s", name);
8163 case dw_val_class_str:
8164 if (AT_string_form (a) == DW_FORM_strp)
8165 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8166 a->dw_attr_val.v.val_str->label,
8168 "%s: \"%s\"", name, AT_string (a));
8170 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8173 case dw_val_class_file:
8175 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8177 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8178 a->dw_attr_val.v.val_file->filename);
8187 FOR_EACH_CHILD (die, c, output_die (c));
8189 /* Add null byte to terminate sibling list. */
8190 if (die->die_child != NULL)
8191 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8192 (unsigned long) die->die_offset);
8195 /* Output the compilation unit that appears at the beginning of the
8196 .debug_info section, and precedes the DIE descriptions. */
8199 output_compilation_unit_header (void)
8201 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8202 dw2_asm_output_data (4, 0xffffffff,
8203 "Initial length escape value indicating 64-bit DWARF extension");
8204 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8205 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8206 "Length of Compilation Unit Info");
8207 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8208 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8209 debug_abbrev_section,
8210 "Offset Into Abbrev. Section");
8211 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8214 /* Output the compilation unit DIE and its children. */
8217 output_comp_unit (dw_die_ref die, int output_if_empty)
8219 const char *secname;
8222 /* Unless we are outputting main CU, we may throw away empty ones. */
8223 if (!output_if_empty && die->die_child == NULL)
8226 /* Even if there are no children of this DIE, we must output the information
8227 about the compilation unit. Otherwise, on an empty translation unit, we
8228 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8229 will then complain when examining the file. First mark all the DIEs in
8230 this CU so we know which get local refs. */
8233 build_abbrev_table (die);
8235 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8236 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8237 calc_die_sizes (die);
8239 oldsym = die->die_symbol;
8242 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8244 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8246 die->die_symbol = NULL;
8247 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8250 switch_to_section (debug_info_section);
8252 /* Output debugging information. */
8253 output_compilation_unit_header ();
8256 /* Leave the marks on the main CU, so we can check them in
8261 die->die_symbol = oldsym;
8265 /* Return the DWARF2/3 pubname associated with a decl. */
8268 dwarf2_name (tree decl, int scope)
8270 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8273 /* Add a new entry to .debug_pubnames if appropriate. */
8276 add_pubname_string (const char *str, dw_die_ref die)
8281 e.name = xstrdup (str);
8282 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8286 add_pubname (tree decl, dw_die_ref die)
8289 if (TREE_PUBLIC (decl))
8290 add_pubname_string (dwarf2_name (decl, 1), die);
8293 /* Add a new entry to .debug_pubtypes if appropriate. */
8296 add_pubtype (tree decl, dw_die_ref die)
8301 if ((TREE_PUBLIC (decl)
8302 || die->die_parent == comp_unit_die)
8303 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8308 if (TYPE_NAME (decl))
8310 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8311 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8312 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8313 && DECL_NAME (TYPE_NAME (decl)))
8314 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8316 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8320 e.name = xstrdup (dwarf2_name (decl, 1));
8322 /* If we don't have a name for the type, there's no point in adding
8324 if (e.name && e.name[0] != '\0')
8325 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8329 /* Output the public names table used to speed up access to externally
8330 visible names; or the public types table used to find type definitions. */
8333 output_pubnames (VEC (pubname_entry, gc) * names)
8336 unsigned long pubnames_length = size_of_pubnames (names);
8339 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8340 dw2_asm_output_data (4, 0xffffffff,
8341 "Initial length escape value indicating 64-bit DWARF extension");
8342 if (names == pubname_table)
8343 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8344 "Length of Public Names Info");
8346 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8347 "Length of Public Type Names Info");
8348 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8349 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8351 "Offset of Compilation Unit Info");
8352 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8353 "Compilation Unit Length");
8355 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8357 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8358 if (names == pubname_table)
8359 gcc_assert (pub->die->die_mark);
8361 if (names != pubtype_table
8362 || pub->die->die_offset != 0
8363 || !flag_eliminate_unused_debug_types)
8365 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8368 dw2_asm_output_nstring (pub->name, -1, "external name");
8372 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8375 /* Add a new entry to .debug_aranges if appropriate. */
8378 add_arange (tree decl, dw_die_ref die)
8380 if (! DECL_SECTION_NAME (decl))
8383 if (arange_table_in_use == arange_table_allocated)
8385 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8386 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8387 arange_table_allocated);
8388 memset (arange_table + arange_table_in_use, 0,
8389 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8392 arange_table[arange_table_in_use++] = die;
8395 /* Output the information that goes into the .debug_aranges table.
8396 Namely, define the beginning and ending address range of the
8397 text section generated for this compilation unit. */
8400 output_aranges (void)
8403 unsigned long aranges_length = size_of_aranges ();
8405 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8406 dw2_asm_output_data (4, 0xffffffff,
8407 "Initial length escape value indicating 64-bit DWARF extension");
8408 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8409 "Length of Address Ranges Info");
8410 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8411 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8413 "Offset of Compilation Unit Info");
8414 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8415 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8417 /* We need to align to twice the pointer size here. */
8418 if (DWARF_ARANGES_PAD_SIZE)
8420 /* Pad using a 2 byte words so that padding is correct for any
8422 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8423 2 * DWARF2_ADDR_SIZE);
8424 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8425 dw2_asm_output_data (2, 0, NULL);
8428 /* It is necessary not to output these entries if the sections were
8429 not used; if the sections were not used, the length will be 0 and
8430 the address may end up as 0 if the section is discarded by ld
8431 --gc-sections, leaving an invalid (0, 0) entry that can be
8432 confused with the terminator. */
8433 if (text_section_used)
8435 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8436 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8437 text_section_label, "Length");
8439 if (cold_text_section_used)
8441 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8443 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8444 cold_text_section_label, "Length");
8447 for (i = 0; i < arange_table_in_use; i++)
8449 dw_die_ref die = arange_table[i];
8451 /* We shouldn't see aranges for DIEs outside of the main CU. */
8452 gcc_assert (die->die_mark);
8454 if (die->die_tag == DW_TAG_subprogram)
8456 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8458 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8459 get_AT_low_pc (die), "Length");
8463 /* A static variable; extract the symbol from DW_AT_location.
8464 Note that this code isn't currently hit, as we only emit
8465 aranges for functions (jason 9/23/99). */
8466 dw_attr_ref a = get_AT (die, DW_AT_location);
8467 dw_loc_descr_ref loc;
8469 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8472 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8474 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8475 loc->dw_loc_oprnd1.v.val_addr, "Address");
8476 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8477 get_AT_unsigned (die, DW_AT_byte_size),
8482 /* Output the terminator words. */
8483 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8484 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8487 /* Add a new entry to .debug_ranges. Return the offset at which it
8491 add_ranges_num (int num)
8493 unsigned int in_use = ranges_table_in_use;
8495 if (in_use == ranges_table_allocated)
8497 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8498 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8499 ranges_table_allocated);
8500 memset (ranges_table + ranges_table_in_use, 0,
8501 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8504 ranges_table[in_use].num = num;
8505 ranges_table_in_use = in_use + 1;
8507 return in_use * 2 * DWARF2_ADDR_SIZE;
8510 /* Add a new entry to .debug_ranges corresponding to a block, or a
8511 range terminator if BLOCK is NULL. */
8514 add_ranges (const_tree block)
8516 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8519 /* Add a new entry to .debug_ranges corresponding to a pair of
8523 add_ranges_by_labels (const char *begin, const char *end)
8525 unsigned int in_use = ranges_by_label_in_use;
8527 if (in_use == ranges_by_label_allocated)
8529 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8530 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8532 ranges_by_label_allocated);
8533 memset (ranges_by_label + ranges_by_label_in_use, 0,
8534 RANGES_TABLE_INCREMENT
8535 * sizeof (struct dw_ranges_by_label_struct));
8538 ranges_by_label[in_use].begin = begin;
8539 ranges_by_label[in_use].end = end;
8540 ranges_by_label_in_use = in_use + 1;
8542 return add_ranges_num (-(int)in_use - 1);
8546 output_ranges (void)
8549 static const char *const start_fmt = "Offset 0x%x";
8550 const char *fmt = start_fmt;
8552 for (i = 0; i < ranges_table_in_use; i++)
8554 int block_num = ranges_table[i].num;
8558 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8559 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8561 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8562 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8564 /* If all code is in the text section, then the compilation
8565 unit base address defaults to DW_AT_low_pc, which is the
8566 base of the text section. */
8567 if (!have_multiple_function_sections)
8569 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8571 fmt, i * 2 * DWARF2_ADDR_SIZE);
8572 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8573 text_section_label, NULL);
8576 /* Otherwise, the compilation unit base address is zero,
8577 which allows us to use absolute addresses, and not worry
8578 about whether the target supports cross-section
8582 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8583 fmt, i * 2 * DWARF2_ADDR_SIZE);
8584 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8590 /* Negative block_num stands for an index into ranges_by_label. */
8591 else if (block_num < 0)
8593 int lab_idx = - block_num - 1;
8595 if (!have_multiple_function_sections)
8599 /* If we ever use add_ranges_by_labels () for a single
8600 function section, all we have to do is to take out
8602 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8603 ranges_by_label[lab_idx].begin,
8605 fmt, i * 2 * DWARF2_ADDR_SIZE);
8606 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8607 ranges_by_label[lab_idx].end,
8608 text_section_label, NULL);
8613 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8614 ranges_by_label[lab_idx].begin,
8615 fmt, i * 2 * DWARF2_ADDR_SIZE);
8616 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8617 ranges_by_label[lab_idx].end,
8623 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8624 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8630 /* Data structure containing information about input files. */
8633 const char *path; /* Complete file name. */
8634 const char *fname; /* File name part. */
8635 int length; /* Length of entire string. */
8636 struct dwarf_file_data * file_idx; /* Index in input file table. */
8637 int dir_idx; /* Index in directory table. */
8640 /* Data structure containing information about directories with source
8644 const char *path; /* Path including directory name. */
8645 int length; /* Path length. */
8646 int prefix; /* Index of directory entry which is a prefix. */
8647 int count; /* Number of files in this directory. */
8648 int dir_idx; /* Index of directory used as base. */
8651 /* Callback function for file_info comparison. We sort by looking at
8652 the directories in the path. */
8655 file_info_cmp (const void *p1, const void *p2)
8657 const struct file_info *const s1 = (const struct file_info *) p1;
8658 const struct file_info *const s2 = (const struct file_info *) p2;
8659 const unsigned char *cp1;
8660 const unsigned char *cp2;
8662 /* Take care of file names without directories. We need to make sure that
8663 we return consistent values to qsort since some will get confused if
8664 we return the same value when identical operands are passed in opposite
8665 orders. So if neither has a directory, return 0 and otherwise return
8666 1 or -1 depending on which one has the directory. */
8667 if ((s1->path == s1->fname || s2->path == s2->fname))
8668 return (s2->path == s2->fname) - (s1->path == s1->fname);
8670 cp1 = (const unsigned char *) s1->path;
8671 cp2 = (const unsigned char *) s2->path;
8677 /* Reached the end of the first path? If so, handle like above. */
8678 if ((cp1 == (const unsigned char *) s1->fname)
8679 || (cp2 == (const unsigned char *) s2->fname))
8680 return ((cp2 == (const unsigned char *) s2->fname)
8681 - (cp1 == (const unsigned char *) s1->fname));
8683 /* Character of current path component the same? */
8684 else if (*cp1 != *cp2)
8689 struct file_name_acquire_data
8691 struct file_info *files;
8696 /* Traversal function for the hash table. */
8699 file_name_acquire (void ** slot, void *data)
8701 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8702 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8703 struct file_info *fi;
8706 gcc_assert (fnad->max_files >= d->emitted_number);
8708 if (! d->emitted_number)
8711 gcc_assert (fnad->max_files != fnad->used_files);
8713 fi = fnad->files + fnad->used_files++;
8715 /* Skip all leading "./". */
8717 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8720 /* Create a new array entry. */
8722 fi->length = strlen (f);
8725 /* Search for the file name part. */
8726 f = strrchr (f, DIR_SEPARATOR);
8727 #if defined (DIR_SEPARATOR_2)
8729 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8733 if (f == NULL || f < g)
8739 fi->fname = f == NULL ? fi->path : f + 1;
8743 /* Output the directory table and the file name table. We try to minimize
8744 the total amount of memory needed. A heuristic is used to avoid large
8745 slowdowns with many input files. */
8748 output_file_names (void)
8750 struct file_name_acquire_data fnad;
8752 struct file_info *files;
8753 struct dir_info *dirs;
8762 if (!last_emitted_file)
8764 dw2_asm_output_data (1, 0, "End directory table");
8765 dw2_asm_output_data (1, 0, "End file name table");
8769 numfiles = last_emitted_file->emitted_number;
8771 /* Allocate the various arrays we need. */
8772 files = XALLOCAVEC (struct file_info, numfiles);
8773 dirs = XALLOCAVEC (struct dir_info, numfiles);
8776 fnad.used_files = 0;
8777 fnad.max_files = numfiles;
8778 htab_traverse (file_table, file_name_acquire, &fnad);
8779 gcc_assert (fnad.used_files == fnad.max_files);
8781 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8783 /* Find all the different directories used. */
8784 dirs[0].path = files[0].path;
8785 dirs[0].length = files[0].fname - files[0].path;
8786 dirs[0].prefix = -1;
8788 dirs[0].dir_idx = 0;
8789 files[0].dir_idx = 0;
8792 for (i = 1; i < numfiles; i++)
8793 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8794 && memcmp (dirs[ndirs - 1].path, files[i].path,
8795 dirs[ndirs - 1].length) == 0)
8797 /* Same directory as last entry. */
8798 files[i].dir_idx = ndirs - 1;
8799 ++dirs[ndirs - 1].count;
8805 /* This is a new directory. */
8806 dirs[ndirs].path = files[i].path;
8807 dirs[ndirs].length = files[i].fname - files[i].path;
8808 dirs[ndirs].count = 1;
8809 dirs[ndirs].dir_idx = ndirs;
8810 files[i].dir_idx = ndirs;
8812 /* Search for a prefix. */
8813 dirs[ndirs].prefix = -1;
8814 for (j = 0; j < ndirs; j++)
8815 if (dirs[j].length < dirs[ndirs].length
8816 && dirs[j].length > 1
8817 && (dirs[ndirs].prefix == -1
8818 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8819 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8820 dirs[ndirs].prefix = j;
8825 /* Now to the actual work. We have to find a subset of the directories which
8826 allow expressing the file name using references to the directory table
8827 with the least amount of characters. We do not do an exhaustive search
8828 where we would have to check out every combination of every single
8829 possible prefix. Instead we use a heuristic which provides nearly optimal
8830 results in most cases and never is much off. */
8831 saved = XALLOCAVEC (int, ndirs);
8832 savehere = XALLOCAVEC (int, ndirs);
8834 memset (saved, '\0', ndirs * sizeof (saved[0]));
8835 for (i = 0; i < ndirs; i++)
8840 /* We can always save some space for the current directory. But this
8841 does not mean it will be enough to justify adding the directory. */
8842 savehere[i] = dirs[i].length;
8843 total = (savehere[i] - saved[i]) * dirs[i].count;
8845 for (j = i + 1; j < ndirs; j++)
8848 if (saved[j] < dirs[i].length)
8850 /* Determine whether the dirs[i] path is a prefix of the
8855 while (k != -1 && k != (int) i)
8860 /* Yes it is. We can possibly save some memory by
8861 writing the filenames in dirs[j] relative to
8863 savehere[j] = dirs[i].length;
8864 total += (savehere[j] - saved[j]) * dirs[j].count;
8869 /* Check whether we can save enough to justify adding the dirs[i]
8871 if (total > dirs[i].length + 1)
8873 /* It's worthwhile adding. */
8874 for (j = i; j < ndirs; j++)
8875 if (savehere[j] > 0)
8877 /* Remember how much we saved for this directory so far. */
8878 saved[j] = savehere[j];
8880 /* Remember the prefix directory. */
8881 dirs[j].dir_idx = i;
8886 /* Emit the directory name table. */
8888 idx_offset = dirs[0].length > 0 ? 1 : 0;
8889 for (i = 1 - idx_offset; i < ndirs; i++)
8890 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8891 "Directory Entry: 0x%x", i + idx_offset);
8893 dw2_asm_output_data (1, 0, "End directory table");
8895 /* We have to emit them in the order of emitted_number since that's
8896 used in the debug info generation. To do this efficiently we
8897 generate a back-mapping of the indices first. */
8898 backmap = XALLOCAVEC (int, numfiles);
8899 for (i = 0; i < numfiles; i++)
8900 backmap[files[i].file_idx->emitted_number - 1] = i;
8902 /* Now write all the file names. */
8903 for (i = 0; i < numfiles; i++)
8905 int file_idx = backmap[i];
8906 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8908 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8909 "File Entry: 0x%x", (unsigned) i + 1);
8911 /* Include directory index. */
8912 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8914 /* Modification time. */
8915 dw2_asm_output_data_uleb128 (0, NULL);
8917 /* File length in bytes. */
8918 dw2_asm_output_data_uleb128 (0, NULL);
8921 dw2_asm_output_data (1, 0, "End file name table");
8925 /* Output the source line number correspondence information. This
8926 information goes into the .debug_line section. */
8929 output_line_info (void)
8931 char l1[20], l2[20], p1[20], p2[20];
8932 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8933 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8936 unsigned long lt_index;
8937 unsigned long current_line;
8940 unsigned long current_file;
8941 unsigned long function;
8943 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8944 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8945 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8946 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8948 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8949 dw2_asm_output_data (4, 0xffffffff,
8950 "Initial length escape value indicating 64-bit DWARF extension");
8951 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8952 "Length of Source Line Info");
8953 ASM_OUTPUT_LABEL (asm_out_file, l1);
8955 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8956 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8957 ASM_OUTPUT_LABEL (asm_out_file, p1);
8959 /* Define the architecture-dependent minimum instruction length (in
8960 bytes). In this implementation of DWARF, this field is used for
8961 information purposes only. Since GCC generates assembly language,
8962 we have no a priori knowledge of how many instruction bytes are
8963 generated for each source line, and therefore can use only the
8964 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8965 commands. Accordingly, we fix this as `1', which is "correct
8966 enough" for all architectures, and don't let the target override. */
8967 dw2_asm_output_data (1, 1,
8968 "Minimum Instruction Length");
8970 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8971 "Default is_stmt_start flag");
8972 dw2_asm_output_data (1, DWARF_LINE_BASE,
8973 "Line Base Value (Special Opcodes)");
8974 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8975 "Line Range Value (Special Opcodes)");
8976 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8977 "Special Opcode Base");
8979 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8983 case DW_LNS_advance_pc:
8984 case DW_LNS_advance_line:
8985 case DW_LNS_set_file:
8986 case DW_LNS_set_column:
8987 case DW_LNS_fixed_advance_pc:
8995 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8999 /* Write out the information about the files we use. */
9000 output_file_names ();
9001 ASM_OUTPUT_LABEL (asm_out_file, p2);
9003 /* We used to set the address register to the first location in the text
9004 section here, but that didn't accomplish anything since we already
9005 have a line note for the opening brace of the first function. */
9007 /* Generate the line number to PC correspondence table, encoded as
9008 a series of state machine operations. */
9012 if (cfun && in_cold_section_p)
9013 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9015 strcpy (prev_line_label, text_section_label);
9016 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9018 dw_line_info_ref line_info = &line_info_table[lt_index];
9021 /* Disable this optimization for now; GDB wants to see two line notes
9022 at the beginning of a function so it can find the end of the
9025 /* Don't emit anything for redundant notes. Just updating the
9026 address doesn't accomplish anything, because we already assume
9027 that anything after the last address is this line. */
9028 if (line_info->dw_line_num == current_line
9029 && line_info->dw_file_num == current_file)
9033 /* Emit debug info for the address of the current line.
9035 Unfortunately, we have little choice here currently, and must always
9036 use the most general form. GCC does not know the address delta
9037 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9038 attributes which will give an upper bound on the address range. We
9039 could perhaps use length attributes to determine when it is safe to
9040 use DW_LNS_fixed_advance_pc. */
9042 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9045 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9046 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9047 "DW_LNS_fixed_advance_pc");
9048 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9052 /* This can handle any delta. This takes
9053 4+DWARF2_ADDR_SIZE bytes. */
9054 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9055 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9056 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9057 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9060 strcpy (prev_line_label, line_label);
9062 /* Emit debug info for the source file of the current line, if
9063 different from the previous line. */
9064 if (line_info->dw_file_num != current_file)
9066 current_file = line_info->dw_file_num;
9067 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9068 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9071 /* Emit debug info for the current line number, choosing the encoding
9072 that uses the least amount of space. */
9073 if (line_info->dw_line_num != current_line)
9075 line_offset = line_info->dw_line_num - current_line;
9076 line_delta = line_offset - DWARF_LINE_BASE;
9077 current_line = line_info->dw_line_num;
9078 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9079 /* This can handle deltas from -10 to 234, using the current
9080 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9082 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9083 "line %lu", current_line);
9086 /* This can handle any delta. This takes at least 4 bytes,
9087 depending on the value being encoded. */
9088 dw2_asm_output_data (1, DW_LNS_advance_line,
9089 "advance to line %lu", current_line);
9090 dw2_asm_output_data_sleb128 (line_offset, NULL);
9091 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9095 /* We still need to start a new row, so output a copy insn. */
9096 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9099 /* Emit debug info for the address of the end of the function. */
9102 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9103 "DW_LNS_fixed_advance_pc");
9104 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9108 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9109 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9110 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9111 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9114 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9115 dw2_asm_output_data_uleb128 (1, NULL);
9116 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9121 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9123 dw_separate_line_info_ref line_info
9124 = &separate_line_info_table[lt_index];
9127 /* Don't emit anything for redundant notes. */
9128 if (line_info->dw_line_num == current_line
9129 && line_info->dw_file_num == current_file
9130 && line_info->function == function)
9134 /* Emit debug info for the address of the current line. If this is
9135 a new function, or the first line of a function, then we need
9136 to handle it differently. */
9137 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9139 if (function != line_info->function)
9141 function = line_info->function;
9143 /* Set the address register to the first line in the function. */
9144 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9145 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9146 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9147 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9151 /* ??? See the DW_LNS_advance_pc comment above. */
9154 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9155 "DW_LNS_fixed_advance_pc");
9156 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9160 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9161 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9162 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9163 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9167 strcpy (prev_line_label, line_label);
9169 /* Emit debug info for the source file of the current line, if
9170 different from the previous line. */
9171 if (line_info->dw_file_num != current_file)
9173 current_file = line_info->dw_file_num;
9174 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9175 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9178 /* Emit debug info for the current line number, choosing the encoding
9179 that uses the least amount of space. */
9180 if (line_info->dw_line_num != current_line)
9182 line_offset = line_info->dw_line_num - current_line;
9183 line_delta = line_offset - DWARF_LINE_BASE;
9184 current_line = line_info->dw_line_num;
9185 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9186 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9187 "line %lu", current_line);
9190 dw2_asm_output_data (1, DW_LNS_advance_line,
9191 "advance to line %lu", current_line);
9192 dw2_asm_output_data_sleb128 (line_offset, NULL);
9193 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9197 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9205 /* If we're done with a function, end its sequence. */
9206 if (lt_index == separate_line_info_table_in_use
9207 || separate_line_info_table[lt_index].function != function)
9212 /* Emit debug info for the address of the end of the function. */
9213 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9216 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9217 "DW_LNS_fixed_advance_pc");
9218 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9222 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9223 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9224 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9225 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9228 /* Output the marker for the end of this sequence. */
9229 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9230 dw2_asm_output_data_uleb128 (1, NULL);
9231 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9235 /* Output the marker for the end of the line number info. */
9236 ASM_OUTPUT_LABEL (asm_out_file, l2);
9239 /* Given a pointer to a tree node for some base type, return a pointer to
9240 a DIE that describes the given type.
9242 This routine must only be called for GCC type nodes that correspond to
9243 Dwarf base (fundamental) types. */
9246 base_type_die (tree type)
9248 dw_die_ref base_type_result;
9249 enum dwarf_type encoding;
9251 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9254 switch (TREE_CODE (type))
9257 if (TYPE_STRING_FLAG (type))
9259 if (TYPE_UNSIGNED (type))
9260 encoding = DW_ATE_unsigned_char;
9262 encoding = DW_ATE_signed_char;
9264 else if (TYPE_UNSIGNED (type))
9265 encoding = DW_ATE_unsigned;
9267 encoding = DW_ATE_signed;
9271 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9272 encoding = DW_ATE_decimal_float;
9274 encoding = DW_ATE_float;
9277 case FIXED_POINT_TYPE:
9278 if (TYPE_UNSIGNED (type))
9279 encoding = DW_ATE_unsigned_fixed;
9281 encoding = DW_ATE_signed_fixed;
9284 /* Dwarf2 doesn't know anything about complex ints, so use
9285 a user defined type for it. */
9287 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9288 encoding = DW_ATE_complex_float;
9290 encoding = DW_ATE_lo_user;
9294 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9295 encoding = DW_ATE_boolean;
9299 /* No other TREE_CODEs are Dwarf fundamental types. */
9303 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9305 /* This probably indicates a bug. */
9306 if (! TYPE_NAME (type))
9307 add_name_attribute (base_type_result, "__unknown__");
9309 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9310 int_size_in_bytes (type));
9311 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9313 return base_type_result;
9316 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9317 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9320 is_base_type (tree type)
9322 switch (TREE_CODE (type))
9328 case FIXED_POINT_TYPE:
9336 case QUAL_UNION_TYPE:
9341 case REFERENCE_TYPE:
9354 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9355 node, return the size in bits for the type if it is a constant, or else
9356 return the alignment for the type if the type's size is not constant, or
9357 else return BITS_PER_WORD if the type actually turns out to be an
9360 static inline unsigned HOST_WIDE_INT
9361 simple_type_size_in_bits (const_tree type)
9363 if (TREE_CODE (type) == ERROR_MARK)
9364 return BITS_PER_WORD;
9365 else if (TYPE_SIZE (type) == NULL_TREE)
9367 else if (host_integerp (TYPE_SIZE (type), 1))
9368 return tree_low_cst (TYPE_SIZE (type), 1);
9370 return TYPE_ALIGN (type);
9373 /* Return true if the debug information for the given type should be
9374 emitted as a subrange type. */
9377 is_subrange_type (const_tree type)
9379 tree subtype = TREE_TYPE (type);
9381 /* Subrange types are identified by the fact that they are integer
9382 types, and that they have a subtype which is either an integer type
9383 or an enumeral type. */
9385 if (TREE_CODE (type) != INTEGER_TYPE
9386 || subtype == NULL_TREE)
9389 if (TREE_CODE (subtype) != INTEGER_TYPE
9390 && TREE_CODE (subtype) != ENUMERAL_TYPE
9391 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9394 if (TREE_CODE (type) == TREE_CODE (subtype)
9395 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9396 && TYPE_MIN_VALUE (type) != NULL
9397 && TYPE_MIN_VALUE (subtype) != NULL
9398 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9399 && TYPE_MAX_VALUE (type) != NULL
9400 && TYPE_MAX_VALUE (subtype) != NULL
9401 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9403 /* The type and its subtype have the same representation. If in
9404 addition the two types also have the same name, then the given
9405 type is not a subrange type, but rather a plain base type. */
9406 /* FIXME: brobecker/2004-03-22:
9407 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9408 therefore be sufficient to check the TYPE_SIZE node pointers
9409 rather than checking the actual size. Unfortunately, we have
9410 found some cases, such as in the Ada "integer" type, where
9411 this is not the case. Until this problem is solved, we need to
9412 keep checking the actual size. */
9413 tree type_name = TYPE_NAME (type);
9414 tree subtype_name = TYPE_NAME (subtype);
9416 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9417 type_name = DECL_NAME (type_name);
9419 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9420 subtype_name = DECL_NAME (subtype_name);
9422 if (type_name == subtype_name)
9429 /* Given a pointer to a tree node for a subrange type, return a pointer
9430 to a DIE that describes the given type. */
9433 subrange_type_die (tree type, dw_die_ref context_die)
9435 dw_die_ref subrange_die;
9436 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9438 if (context_die == NULL)
9439 context_die = comp_unit_die;
9441 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9443 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9445 /* The size of the subrange type and its base type do not match,
9446 so we need to generate a size attribute for the subrange type. */
9447 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9450 if (TYPE_MIN_VALUE (type) != NULL)
9451 add_bound_info (subrange_die, DW_AT_lower_bound,
9452 TYPE_MIN_VALUE (type));
9453 if (TYPE_MAX_VALUE (type) != NULL)
9454 add_bound_info (subrange_die, DW_AT_upper_bound,
9455 TYPE_MAX_VALUE (type));
9457 return subrange_die;
9460 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9461 entry that chains various modifiers in front of the given type. */
9464 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9465 dw_die_ref context_die)
9467 enum tree_code code = TREE_CODE (type);
9468 dw_die_ref mod_type_die;
9469 dw_die_ref sub_die = NULL;
9470 tree item_type = NULL;
9471 tree qualified_type;
9474 if (code == ERROR_MARK)
9477 /* See if we already have the appropriately qualified variant of
9480 = get_qualified_type (type,
9481 ((is_const_type ? TYPE_QUAL_CONST : 0)
9482 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9484 /* If we do, then we can just use its DIE, if it exists. */
9487 mod_type_die = lookup_type_die (qualified_type);
9489 return mod_type_die;
9492 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9494 /* Handle C typedef types. */
9495 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9497 tree dtype = TREE_TYPE (name);
9499 if (qualified_type == dtype)
9501 /* For a named type, use the typedef. */
9502 gen_type_die (qualified_type, context_die);
9503 return lookup_type_die (qualified_type);
9505 else if (is_const_type < TYPE_READONLY (dtype)
9506 || is_volatile_type < TYPE_VOLATILE (dtype)
9507 || (is_const_type <= TYPE_READONLY (dtype)
9508 && is_volatile_type <= TYPE_VOLATILE (dtype)
9509 && DECL_ORIGINAL_TYPE (name) != type))
9510 /* cv-unqualified version of named type. Just use the unnamed
9511 type to which it refers. */
9512 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9513 is_const_type, is_volatile_type,
9515 /* Else cv-qualified version of named type; fall through. */
9520 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9521 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9523 else if (is_volatile_type)
9525 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9526 sub_die = modified_type_die (type, 0, 0, context_die);
9528 else if (code == POINTER_TYPE)
9530 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9531 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9532 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9533 item_type = TREE_TYPE (type);
9535 else if (code == REFERENCE_TYPE)
9537 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9538 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9539 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9540 item_type = TREE_TYPE (type);
9542 else if (is_subrange_type (type))
9544 mod_type_die = subrange_type_die (type, context_die);
9545 item_type = TREE_TYPE (type);
9547 else if (is_base_type (type))
9548 mod_type_die = base_type_die (type);
9551 gen_type_die (type, context_die);
9553 /* We have to get the type_main_variant here (and pass that to the
9554 `lookup_type_die' routine) because the ..._TYPE node we have
9555 might simply be a *copy* of some original type node (where the
9556 copy was created to help us keep track of typedef names) and
9557 that copy might have a different TYPE_UID from the original
9559 if (TREE_CODE (type) != VECTOR_TYPE)
9560 return lookup_type_die (type_main_variant (type));
9562 /* Vectors have the debugging information in the type,
9563 not the main variant. */
9564 return lookup_type_die (type);
9567 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9568 don't output a DW_TAG_typedef, since there isn't one in the
9569 user's program; just attach a DW_AT_name to the type. */
9571 && (TREE_CODE (name) != TYPE_DECL
9572 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9574 if (TREE_CODE (name) == TYPE_DECL)
9575 /* Could just call add_name_and_src_coords_attributes here,
9576 but since this is a builtin type it doesn't have any
9577 useful source coordinates anyway. */
9578 name = DECL_NAME (name);
9579 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9583 equate_type_number_to_die (qualified_type, mod_type_die);
9586 /* We must do this after the equate_type_number_to_die call, in case
9587 this is a recursive type. This ensures that the modified_type_die
9588 recursion will terminate even if the type is recursive. Recursive
9589 types are possible in Ada. */
9590 sub_die = modified_type_die (item_type,
9591 TYPE_READONLY (item_type),
9592 TYPE_VOLATILE (item_type),
9595 if (sub_die != NULL)
9596 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9598 return mod_type_die;
9601 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9602 an enumerated type. */
9605 type_is_enum (const_tree type)
9607 return TREE_CODE (type) == ENUMERAL_TYPE;
9610 /* Return the DBX register number described by a given RTL node. */
9613 dbx_reg_number (const_rtx rtl)
9615 unsigned regno = REGNO (rtl);
9617 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9619 #ifdef LEAF_REG_REMAP
9620 if (current_function_uses_only_leaf_regs)
9622 int leaf_reg = LEAF_REG_REMAP (regno);
9624 regno = (unsigned) leaf_reg;
9628 return DBX_REGISTER_NUMBER (regno);
9631 /* Optionally add a DW_OP_piece term to a location description expression.
9632 DW_OP_piece is only added if the location description expression already
9633 doesn't end with DW_OP_piece. */
9636 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9638 dw_loc_descr_ref loc;
9640 if (*list_head != NULL)
9642 /* Find the end of the chain. */
9643 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9646 if (loc->dw_loc_opc != DW_OP_piece)
9647 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9651 /* Return a location descriptor that designates a machine register or
9652 zero if there is none. */
9654 static dw_loc_descr_ref
9655 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9659 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9662 regs = targetm.dwarf_register_span (rtl);
9664 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9665 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9667 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9670 /* Return a location descriptor that designates a machine register for
9671 a given hard register number. */
9673 static dw_loc_descr_ref
9674 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9676 dw_loc_descr_ref reg_loc_descr = new_reg_loc_descr (regno, 0);
9678 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9679 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9681 return reg_loc_descr;
9684 /* Given an RTL of a register, return a location descriptor that
9685 designates a value that spans more than one register. */
9687 static dw_loc_descr_ref
9688 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9689 enum var_init_status initialized)
9693 dw_loc_descr_ref loc_result = NULL;
9696 #ifdef LEAF_REG_REMAP
9697 if (current_function_uses_only_leaf_regs)
9699 int leaf_reg = LEAF_REG_REMAP (reg);
9701 reg = (unsigned) leaf_reg;
9704 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9705 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9707 /* Simple, contiguous registers. */
9708 if (regs == NULL_RTX)
9710 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9717 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9718 VAR_INIT_STATUS_INITIALIZED);
9719 add_loc_descr (&loc_result, t);
9720 add_loc_descr_op_piece (&loc_result, size);
9726 /* Now onto stupid register sets in non contiguous locations. */
9728 gcc_assert (GET_CODE (regs) == PARALLEL);
9730 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9733 for (i = 0; i < XVECLEN (regs, 0); ++i)
9737 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9738 VAR_INIT_STATUS_INITIALIZED);
9739 add_loc_descr (&loc_result, t);
9740 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9741 add_loc_descr_op_piece (&loc_result, size);
9744 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9745 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9749 #endif /* DWARF2_DEBUGGING_INFO */
9751 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9753 /* Return a location descriptor that designates a constant. */
9755 static dw_loc_descr_ref
9756 int_loc_descriptor (HOST_WIDE_INT i)
9758 enum dwarf_location_atom op;
9760 /* Pick the smallest representation of a constant, rather than just
9761 defaulting to the LEB encoding. */
9765 op = DW_OP_lit0 + i;
9768 else if (i <= 0xffff)
9770 else if (HOST_BITS_PER_WIDE_INT == 32
9780 else if (i >= -0x8000)
9782 else if (HOST_BITS_PER_WIDE_INT == 32
9783 || i >= -0x80000000)
9789 return new_loc_descr (op, i, 0);
9793 #ifdef DWARF2_DEBUGGING_INFO
9795 /* Return a location descriptor that designates a base+offset location. */
9797 static dw_loc_descr_ref
9798 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9799 enum var_init_status initialized)
9802 dw_loc_descr_ref result;
9803 dw_fde_ref fde = current_fde ();
9805 /* We only use "frame base" when we're sure we're talking about the
9806 post-prologue local stack frame. We do this by *not* running
9807 register elimination until this point, and recognizing the special
9808 argument pointer and soft frame pointer rtx's. */
9809 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9811 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9815 if (GET_CODE (elim) == PLUS)
9817 offset += INTVAL (XEXP (elim, 1));
9818 elim = XEXP (elim, 0);
9820 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9821 && (elim == hard_frame_pointer_rtx
9822 || elim == stack_pointer_rtx))
9823 || elim == (frame_pointer_needed
9824 ? hard_frame_pointer_rtx
9825 : stack_pointer_rtx));
9827 /* If drap register is used to align stack, use frame
9828 pointer + offset to access stack variables. If stack
9829 is aligned without drap, use stack pointer + offset to
9830 access stack variables. */
9831 if (crtl->stack_realign_tried
9832 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9833 && reg == frame_pointer_rtx)
9836 = DWARF_FRAME_REGNUM (cfa.indirect
9837 ? HARD_FRAME_POINTER_REGNUM
9838 : STACK_POINTER_REGNUM);
9839 return new_reg_loc_descr (base_reg, offset);
9842 offset += frame_pointer_fb_offset;
9843 return new_loc_descr (DW_OP_fbreg, offset, 0);
9847 && fde->drap_reg != INVALID_REGNUM
9848 && (fde->drap_reg == REGNO (reg)
9849 || fde->vdrap_reg == REGNO (reg)))
9851 /* Use cfa+offset to represent the location of arguments passed
9852 on stack when drap is used to align stack. */
9853 return new_loc_descr (DW_OP_fbreg, offset, 0);
9856 regno = dbx_reg_number (reg);
9858 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9860 result = new_loc_descr (DW_OP_bregx, regno, offset);
9862 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9863 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9868 /* Return true if this RTL expression describes a base+offset calculation. */
9871 is_based_loc (const_rtx rtl)
9873 return (GET_CODE (rtl) == PLUS
9874 && ((REG_P (XEXP (rtl, 0))
9875 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9876 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9879 /* Return a descriptor that describes the concatenation of N locations
9880 used to form the address of a memory location. */
9882 static dw_loc_descr_ref
9883 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9884 enum var_init_status initialized)
9887 dw_loc_descr_ref cc_loc_result = NULL;
9888 unsigned int n = XVECLEN (concatn, 0);
9890 for (i = 0; i < n; ++i)
9892 dw_loc_descr_ref ref;
9893 rtx x = XVECEXP (concatn, 0, i);
9895 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9899 add_loc_descr (&cc_loc_result, ref);
9900 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9903 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9904 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9906 return cc_loc_result;
9909 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
9912 static dw_loc_descr_ref
9913 tls_mem_loc_descriptor (rtx mem)
9916 dw_loc_descr_ref loc_result, loc_result2;
9918 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
9921 base = get_base_address (MEM_EXPR (mem));
9923 || TREE_CODE (base) != VAR_DECL
9924 || !DECL_THREAD_LOCAL_P (base))
9927 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
9928 if (loc_result == NULL)
9931 if (INTVAL (MEM_OFFSET (mem)))
9933 if (INTVAL (MEM_OFFSET (mem)) >= 0)
9934 add_loc_descr (&loc_result,
9935 new_loc_descr (DW_OP_plus_uconst,
9936 INTVAL (MEM_OFFSET (mem)), 0));
9939 loc_result2 = mem_loc_descriptor (MEM_OFFSET (mem), GET_MODE (mem),
9940 VAR_INIT_STATUS_INITIALIZED);
9941 if (loc_result2 == 0)
9943 add_loc_descr (&loc_result, loc_result2);
9944 add_loc_descr (&loc_result, new_loc_descr (DW_OP_plus, 0, 0));
9951 /* The following routine converts the RTL for a variable or parameter
9952 (resident in memory) into an equivalent Dwarf representation of a
9953 mechanism for getting the address of that same variable onto the top of a
9954 hypothetical "address evaluation" stack.
9956 When creating memory location descriptors, we are effectively transforming
9957 the RTL for a memory-resident object into its Dwarf postfix expression
9958 equivalent. This routine recursively descends an RTL tree, turning
9959 it into Dwarf postfix code as it goes.
9961 MODE is the mode of the memory reference, needed to handle some
9962 autoincrement addressing modes.
9964 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9965 location list for RTL.
9967 Return 0 if we can't represent the location. */
9969 static dw_loc_descr_ref
9970 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9971 enum var_init_status initialized)
9973 dw_loc_descr_ref mem_loc_result = NULL;
9974 enum dwarf_location_atom op;
9976 /* Note that for a dynamically sized array, the location we will generate a
9977 description of here will be the lowest numbered location which is
9978 actually within the array. That's *not* necessarily the same as the
9979 zeroth element of the array. */
9981 rtl = targetm.delegitimize_address (rtl);
9983 switch (GET_CODE (rtl))
9988 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9989 just fall into the SUBREG code. */
9991 /* ... fall through ... */
9994 /* The case of a subreg may arise when we have a local (register)
9995 variable or a formal (register) parameter which doesn't quite fill
9996 up an entire register. For now, just assume that it is
9997 legitimate to make the Dwarf info refer to the whole register which
9998 contains the given subreg. */
9999 rtl = XEXP (rtl, 0);
10001 /* ... fall through ... */
10004 /* Whenever a register number forms a part of the description of the
10005 method for calculating the (dynamic) address of a memory resident
10006 object, DWARF rules require the register number be referred to as
10007 a "base register". This distinction is not based in any way upon
10008 what category of register the hardware believes the given register
10009 belongs to. This is strictly DWARF terminology we're dealing with
10010 here. Note that in cases where the location of a memory-resident
10011 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10012 OP_CONST (0)) the actual DWARF location descriptor that we generate
10013 may just be OP_BASEREG (basereg). This may look deceptively like
10014 the object in question was allocated to a register (rather than in
10015 memory) so DWARF consumers need to be aware of the subtle
10016 distinction between OP_REG and OP_BASEREG. */
10017 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10018 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10019 else if (stack_realign_drap
10021 && crtl->args.internal_arg_pointer == rtl
10022 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10024 /* If RTL is internal_arg_pointer, which has been optimized
10025 out, use DRAP instead. */
10026 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10027 VAR_INIT_STATUS_INITIALIZED);
10032 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10033 VAR_INIT_STATUS_INITIALIZED);
10034 if (mem_loc_result == NULL)
10035 mem_loc_result = tls_mem_loc_descriptor (rtl);
10036 if (mem_loc_result != 0)
10037 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10041 rtl = XEXP (rtl, 1);
10043 /* ... fall through ... */
10046 /* Some ports can transform a symbol ref into a label ref, because
10047 the symbol ref is too far away and has to be dumped into a constant
10051 /* Alternatively, the symbol in the constant pool might be referenced
10052 by a different symbol. */
10053 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10056 rtx tmp = get_pool_constant_mark (rtl, &marked);
10058 if (GET_CODE (tmp) == SYMBOL_REF)
10061 if (CONSTANT_POOL_ADDRESS_P (tmp))
10062 get_pool_constant_mark (tmp, &marked);
10067 /* If all references to this pool constant were optimized away,
10068 it was not output and thus we can't represent it.
10069 FIXME: might try to use DW_OP_const_value here, though
10070 DW_OP_piece complicates it. */
10075 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10076 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10077 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10078 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10082 /* Extract the PLUS expression nested inside and fall into
10083 PLUS code below. */
10084 rtl = XEXP (rtl, 1);
10089 /* Turn these into a PLUS expression and fall into the PLUS code
10091 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10092 GEN_INT (GET_CODE (rtl) == PRE_INC
10093 ? GET_MODE_UNIT_SIZE (mode)
10094 : -GET_MODE_UNIT_SIZE (mode)));
10096 /* ... fall through ... */
10100 if (is_based_loc (rtl))
10101 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10102 INTVAL (XEXP (rtl, 1)),
10103 VAR_INIT_STATUS_INITIALIZED);
10106 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10107 VAR_INIT_STATUS_INITIALIZED);
10108 if (mem_loc_result == 0)
10111 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
10112 && INTVAL (XEXP (rtl, 1)) >= 0)
10113 add_loc_descr (&mem_loc_result,
10114 new_loc_descr (DW_OP_plus_uconst,
10115 INTVAL (XEXP (rtl, 1)), 0));
10118 dw_loc_descr_ref mem_loc_result2
10119 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10120 VAR_INIT_STATUS_INITIALIZED);
10121 if (mem_loc_result2 == 0)
10123 add_loc_descr (&mem_loc_result, mem_loc_result2);
10124 add_loc_descr (&mem_loc_result,
10125 new_loc_descr (DW_OP_plus, 0, 0));
10130 /* If a pseudo-reg is optimized away, it is possible for it to
10131 be replaced with a MEM containing a multiply or shift. */
10150 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10151 VAR_INIT_STATUS_INITIALIZED);
10152 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10153 VAR_INIT_STATUS_INITIALIZED);
10155 if (op0 == 0 || op1 == 0)
10158 mem_loc_result = op0;
10159 add_loc_descr (&mem_loc_result, op1);
10160 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10165 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10169 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10170 VAR_INIT_STATUS_INITIALIZED);
10174 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10175 can't express it in the debug info. This can happen e.g. with some
10180 gcc_unreachable ();
10183 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10184 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10186 return mem_loc_result;
10189 /* Return a descriptor that describes the concatenation of two locations.
10190 This is typically a complex variable. */
10192 static dw_loc_descr_ref
10193 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10195 dw_loc_descr_ref cc_loc_result = NULL;
10196 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10197 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10199 if (x0_ref == 0 || x1_ref == 0)
10202 cc_loc_result = x0_ref;
10203 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10205 add_loc_descr (&cc_loc_result, x1_ref);
10206 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10208 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10209 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10211 return cc_loc_result;
10214 /* Return a descriptor that describes the concatenation of N
10217 static dw_loc_descr_ref
10218 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10221 dw_loc_descr_ref cc_loc_result = NULL;
10222 unsigned int n = XVECLEN (concatn, 0);
10224 for (i = 0; i < n; ++i)
10226 dw_loc_descr_ref ref;
10227 rtx x = XVECEXP (concatn, 0, i);
10229 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10233 add_loc_descr (&cc_loc_result, ref);
10234 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10237 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10238 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10240 return cc_loc_result;
10243 /* Output a proper Dwarf location descriptor for a variable or parameter
10244 which is either allocated in a register or in a memory location. For a
10245 register, we just generate an OP_REG and the register number. For a
10246 memory location we provide a Dwarf postfix expression describing how to
10247 generate the (dynamic) address of the object onto the address stack.
10249 If we don't know how to describe it, return 0. */
10251 static dw_loc_descr_ref
10252 loc_descriptor (rtx rtl, enum var_init_status initialized)
10254 dw_loc_descr_ref loc_result = NULL;
10256 switch (GET_CODE (rtl))
10259 /* The case of a subreg may arise when we have a local (register)
10260 variable or a formal (register) parameter which doesn't quite fill
10261 up an entire register. For now, just assume that it is
10262 legitimate to make the Dwarf info refer to the whole register which
10263 contains the given subreg. */
10264 rtl = SUBREG_REG (rtl);
10266 /* ... fall through ... */
10269 loc_result = reg_loc_descriptor (rtl, initialized);
10273 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10275 if (loc_result == NULL)
10276 loc_result = tls_mem_loc_descriptor (rtl);
10280 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10285 loc_result = concatn_loc_descriptor (rtl, initialized);
10290 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10292 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10296 rtl = XEXP (rtl, 1);
10301 rtvec par_elems = XVEC (rtl, 0);
10302 int num_elem = GET_NUM_ELEM (par_elems);
10303 enum machine_mode mode;
10306 /* Create the first one, so we have something to add to. */
10307 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10309 if (loc_result == NULL)
10311 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10312 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10313 for (i = 1; i < num_elem; i++)
10315 dw_loc_descr_ref temp;
10317 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10321 add_loc_descr (&loc_result, temp);
10322 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10323 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10329 gcc_unreachable ();
10335 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10336 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10337 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10338 top-level invocation, and we require the address of LOC; is 0 if we require
10339 the value of LOC. */
10341 static dw_loc_descr_ref
10342 loc_descriptor_from_tree_1 (tree loc, int want_address)
10344 dw_loc_descr_ref ret, ret1;
10345 int have_address = 0;
10346 enum dwarf_location_atom op;
10348 /* ??? Most of the time we do not take proper care for sign/zero
10349 extending the values properly. Hopefully this won't be a real
10352 switch (TREE_CODE (loc))
10357 case PLACEHOLDER_EXPR:
10358 /* This case involves extracting fields from an object to determine the
10359 position of other fields. We don't try to encode this here. The
10360 only user of this is Ada, which encodes the needed information using
10361 the names of types. */
10367 case PREINCREMENT_EXPR:
10368 case PREDECREMENT_EXPR:
10369 case POSTINCREMENT_EXPR:
10370 case POSTDECREMENT_EXPR:
10371 /* There are no opcodes for these operations. */
10375 /* If we already want an address, there's nothing we can do. */
10379 /* Otherwise, process the argument and look for the address. */
10380 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10383 if (DECL_THREAD_LOCAL_P (loc))
10387 unsigned second_op;
10389 if (targetm.have_tls)
10391 /* If this is not defined, we have no way to emit the
10393 if (!targetm.asm_out.output_dwarf_dtprel)
10396 /* The way DW_OP_GNU_push_tls_address is specified, we
10397 can only look up addresses of objects in the current
10399 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
10401 first_op = INTERNAL_DW_OP_tls_addr;
10402 second_op = DW_OP_GNU_push_tls_address;
10406 if (!targetm.emutls.debug_form_tls_address)
10408 loc = emutls_decl (loc);
10409 first_op = DW_OP_addr;
10410 second_op = DW_OP_form_tls_address;
10413 rtl = rtl_for_decl_location (loc);
10414 if (rtl == NULL_RTX)
10419 rtl = XEXP (rtl, 0);
10420 if (! CONSTANT_P (rtl))
10423 ret = new_loc_descr (first_op, 0, 0);
10424 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10425 ret->dw_loc_oprnd1.v.val_addr = rtl;
10427 ret1 = new_loc_descr (second_op, 0, 0);
10428 add_loc_descr (&ret, ret1);
10436 if (DECL_HAS_VALUE_EXPR_P (loc))
10437 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10442 case FUNCTION_DECL:
10444 rtx rtl = rtl_for_decl_location (loc);
10446 if (rtl == NULL_RTX)
10448 else if (GET_CODE (rtl) == CONST_INT)
10450 HOST_WIDE_INT val = INTVAL (rtl);
10451 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10452 val &= GET_MODE_MASK (DECL_MODE (loc));
10453 ret = int_loc_descriptor (val);
10455 else if (GET_CODE (rtl) == CONST_STRING)
10457 else if (CONSTANT_P (rtl))
10459 ret = new_loc_descr (DW_OP_addr, 0, 0);
10460 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10461 ret->dw_loc_oprnd1.v.val_addr = rtl;
10465 enum machine_mode mode;
10467 /* Certain constructs can only be represented at top-level. */
10468 if (want_address == 2)
10469 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10471 mode = GET_MODE (rtl);
10474 rtl = XEXP (rtl, 0);
10477 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10483 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10487 case COMPOUND_EXPR:
10488 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10491 case VIEW_CONVERT_EXPR:
10494 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10496 case COMPONENT_REF:
10497 case BIT_FIELD_REF:
10499 case ARRAY_RANGE_REF:
10502 HOST_WIDE_INT bitsize, bitpos, bytepos;
10503 enum machine_mode mode;
10505 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10507 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10508 &unsignedp, &volatilep, false);
10513 ret = loc_descriptor_from_tree_1 (obj, 1);
10515 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10518 if (offset != NULL_TREE)
10520 /* Variable offset. */
10521 ret1 = loc_descriptor_from_tree_1 (offset, 0);
10524 add_loc_descr (&ret, ret1);
10525 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10528 bytepos = bitpos / BITS_PER_UNIT;
10530 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10531 else if (bytepos < 0)
10533 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10534 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10542 if (host_integerp (loc, 0))
10543 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10550 /* Get an RTL for this, if something has been emitted. */
10551 rtx rtl = lookup_constant_def (loc);
10552 enum machine_mode mode;
10554 if (!rtl || !MEM_P (rtl))
10556 mode = GET_MODE (rtl);
10557 rtl = XEXP (rtl, 0);
10558 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10563 case TRUTH_AND_EXPR:
10564 case TRUTH_ANDIF_EXPR:
10569 case TRUTH_XOR_EXPR:
10574 case TRUTH_OR_EXPR:
10575 case TRUTH_ORIF_EXPR:
10580 case FLOOR_DIV_EXPR:
10581 case CEIL_DIV_EXPR:
10582 case ROUND_DIV_EXPR:
10583 case TRUNC_DIV_EXPR:
10591 case FLOOR_MOD_EXPR:
10592 case CEIL_MOD_EXPR:
10593 case ROUND_MOD_EXPR:
10594 case TRUNC_MOD_EXPR:
10607 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10610 case POINTER_PLUS_EXPR:
10612 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10613 && host_integerp (TREE_OPERAND (loc, 1), 0))
10615 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10619 add_loc_descr (&ret,
10620 new_loc_descr (DW_OP_plus_uconst,
10621 tree_low_cst (TREE_OPERAND (loc, 1),
10631 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10638 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10645 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10652 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10667 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10668 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10669 if (ret == 0 || ret1 == 0)
10672 add_loc_descr (&ret, ret1);
10673 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10676 case TRUTH_NOT_EXPR:
10690 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10694 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10700 const enum tree_code code =
10701 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10703 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10704 build2 (code, integer_type_node,
10705 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10706 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10709 /* ... fall through ... */
10713 dw_loc_descr_ref lhs
10714 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10715 dw_loc_descr_ref rhs
10716 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10717 dw_loc_descr_ref bra_node, jump_node, tmp;
10719 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10720 if (ret == 0 || lhs == 0 || rhs == 0)
10723 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10724 add_loc_descr (&ret, bra_node);
10726 add_loc_descr (&ret, rhs);
10727 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10728 add_loc_descr (&ret, jump_node);
10730 add_loc_descr (&ret, lhs);
10731 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10732 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10734 /* ??? Need a node to point the skip at. Use a nop. */
10735 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10736 add_loc_descr (&ret, tmp);
10737 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10738 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10742 case FIX_TRUNC_EXPR:
10746 /* Leave front-end specific codes as simply unknown. This comes
10747 up, for instance, with the C STMT_EXPR. */
10748 if ((unsigned int) TREE_CODE (loc)
10749 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10752 #ifdef ENABLE_CHECKING
10753 /* Otherwise this is a generic code; we should just lists all of
10754 these explicitly. We forgot one. */
10755 gcc_unreachable ();
10757 /* In a release build, we want to degrade gracefully: better to
10758 generate incomplete debugging information than to crash. */
10763 /* Show if we can't fill the request for an address. */
10764 if (want_address && !have_address)
10767 /* If we've got an address and don't want one, dereference. */
10768 if (!want_address && have_address && ret)
10770 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10772 if (size > DWARF2_ADDR_SIZE || size == -1)
10774 else if (size == DWARF2_ADDR_SIZE)
10777 op = DW_OP_deref_size;
10779 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10785 static inline dw_loc_descr_ref
10786 loc_descriptor_from_tree (tree loc)
10788 return loc_descriptor_from_tree_1 (loc, 2);
10791 /* Given a value, round it up to the lowest multiple of `boundary'
10792 which is not less than the value itself. */
10794 static inline HOST_WIDE_INT
10795 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10797 return (((value + boundary - 1) / boundary) * boundary);
10800 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10801 pointer to the declared type for the relevant field variable, or return
10802 `integer_type_node' if the given node turns out to be an
10803 ERROR_MARK node. */
10806 field_type (const_tree decl)
10810 if (TREE_CODE (decl) == ERROR_MARK)
10811 return integer_type_node;
10813 type = DECL_BIT_FIELD_TYPE (decl);
10814 if (type == NULL_TREE)
10815 type = TREE_TYPE (decl);
10820 /* Given a pointer to a tree node, return the alignment in bits for
10821 it, or else return BITS_PER_WORD if the node actually turns out to
10822 be an ERROR_MARK node. */
10824 static inline unsigned
10825 simple_type_align_in_bits (const_tree type)
10827 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10830 static inline unsigned
10831 simple_decl_align_in_bits (const_tree decl)
10833 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10836 /* Return the result of rounding T up to ALIGN. */
10838 static inline HOST_WIDE_INT
10839 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10841 /* We must be careful if T is negative because HOST_WIDE_INT can be
10842 either "above" or "below" unsigned int as per the C promotion
10843 rules, depending on the host, thus making the signedness of the
10844 direct multiplication and division unpredictable. */
10845 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10851 return (HOST_WIDE_INT) u;
10854 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10855 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10856 or return 0 if we are unable to determine what that offset is, either
10857 because the argument turns out to be a pointer to an ERROR_MARK node, or
10858 because the offset is actually variable. (We can't handle the latter case
10861 static HOST_WIDE_INT
10862 field_byte_offset (const_tree decl)
10864 HOST_WIDE_INT object_offset_in_bits;
10865 HOST_WIDE_INT bitpos_int;
10867 if (TREE_CODE (decl) == ERROR_MARK)
10870 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10872 /* We cannot yet cope with fields whose positions are variable, so
10873 for now, when we see such things, we simply return 0. Someday, we may
10874 be able to handle such cases, but it will be damn difficult. */
10875 if (! host_integerp (bit_position (decl), 0))
10878 bitpos_int = int_bit_position (decl);
10880 #ifdef PCC_BITFIELD_TYPE_MATTERS
10881 if (PCC_BITFIELD_TYPE_MATTERS)
10884 tree field_size_tree;
10885 HOST_WIDE_INT deepest_bitpos;
10886 unsigned HOST_WIDE_INT field_size_in_bits;
10887 unsigned int type_align_in_bits;
10888 unsigned int decl_align_in_bits;
10889 unsigned HOST_WIDE_INT type_size_in_bits;
10891 type = field_type (decl);
10892 field_size_tree = DECL_SIZE (decl);
10894 /* The size could be unspecified if there was an error, or for
10895 a flexible array member. */
10896 if (! field_size_tree)
10897 field_size_tree = bitsize_zero_node;
10899 /* If we don't know the size of the field, pretend it's a full word. */
10900 if (host_integerp (field_size_tree, 1))
10901 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10903 field_size_in_bits = BITS_PER_WORD;
10905 type_size_in_bits = simple_type_size_in_bits (type);
10906 type_align_in_bits = simple_type_align_in_bits (type);
10907 decl_align_in_bits = simple_decl_align_in_bits (decl);
10909 /* The GCC front-end doesn't make any attempt to keep track of the
10910 starting bit offset (relative to the start of the containing
10911 structure type) of the hypothetical "containing object" for a
10912 bit-field. Thus, when computing the byte offset value for the
10913 start of the "containing object" of a bit-field, we must deduce
10914 this information on our own. This can be rather tricky to do in
10915 some cases. For example, handling the following structure type
10916 definition when compiling for an i386/i486 target (which only
10917 aligns long long's to 32-bit boundaries) can be very tricky:
10919 struct S { int field1; long long field2:31; };
10921 Fortunately, there is a simple rule-of-thumb which can be used
10922 in such cases. When compiling for an i386/i486, GCC will
10923 allocate 8 bytes for the structure shown above. It decides to
10924 do this based upon one simple rule for bit-field allocation.
10925 GCC allocates each "containing object" for each bit-field at
10926 the first (i.e. lowest addressed) legitimate alignment boundary
10927 (based upon the required minimum alignment for the declared
10928 type of the field) which it can possibly use, subject to the
10929 condition that there is still enough available space remaining
10930 in the containing object (when allocated at the selected point)
10931 to fully accommodate all of the bits of the bit-field itself.
10933 This simple rule makes it obvious why GCC allocates 8 bytes for
10934 each object of the structure type shown above. When looking
10935 for a place to allocate the "containing object" for `field2',
10936 the compiler simply tries to allocate a 64-bit "containing
10937 object" at each successive 32-bit boundary (starting at zero)
10938 until it finds a place to allocate that 64- bit field such that
10939 at least 31 contiguous (and previously unallocated) bits remain
10940 within that selected 64 bit field. (As it turns out, for the
10941 example above, the compiler finds it is OK to allocate the
10942 "containing object" 64-bit field at bit-offset zero within the
10945 Here we attempt to work backwards from the limited set of facts
10946 we're given, and we try to deduce from those facts, where GCC
10947 must have believed that the containing object started (within
10948 the structure type). The value we deduce is then used (by the
10949 callers of this routine) to generate DW_AT_location and
10950 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10951 the case of DW_AT_location, regular fields as well). */
10953 /* Figure out the bit-distance from the start of the structure to
10954 the "deepest" bit of the bit-field. */
10955 deepest_bitpos = bitpos_int + field_size_in_bits;
10957 /* This is the tricky part. Use some fancy footwork to deduce
10958 where the lowest addressed bit of the containing object must
10960 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10962 /* Round up to type_align by default. This works best for
10964 object_offset_in_bits
10965 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10967 if (object_offset_in_bits > bitpos_int)
10969 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10971 /* Round up to decl_align instead. */
10972 object_offset_in_bits
10973 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10978 object_offset_in_bits = bitpos_int;
10980 return object_offset_in_bits / BITS_PER_UNIT;
10983 /* The following routines define various Dwarf attributes and any data
10984 associated with them. */
10986 /* Add a location description attribute value to a DIE.
10988 This emits location attributes suitable for whole variables and
10989 whole parameters. Note that the location attributes for struct fields are
10990 generated by the routine `data_member_location_attribute' below. */
10993 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10994 dw_loc_descr_ref descr)
10997 add_AT_loc (die, attr_kind, descr);
11000 /* Attach the specialized form of location attribute used for data members of
11001 struct and union types. In the special case of a FIELD_DECL node which
11002 represents a bit-field, the "offset" part of this special location
11003 descriptor must indicate the distance in bytes from the lowest-addressed
11004 byte of the containing struct or union type to the lowest-addressed byte of
11005 the "containing object" for the bit-field. (See the `field_byte_offset'
11008 For any given bit-field, the "containing object" is a hypothetical object
11009 (of some integral or enum type) within which the given bit-field lives. The
11010 type of this hypothetical "containing object" is always the same as the
11011 declared type of the individual bit-field itself (for GCC anyway... the
11012 DWARF spec doesn't actually mandate this). Note that it is the size (in
11013 bytes) of the hypothetical "containing object" which will be given in the
11014 DW_AT_byte_size attribute for this bit-field. (See the
11015 `byte_size_attribute' function below.) It is also used when calculating the
11016 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11017 function below.) */
11020 add_data_member_location_attribute (dw_die_ref die, tree decl)
11022 HOST_WIDE_INT offset;
11023 dw_loc_descr_ref loc_descr = 0;
11025 if (TREE_CODE (decl) == TREE_BINFO)
11027 /* We're working on the TAG_inheritance for a base class. */
11028 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11030 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11031 aren't at a fixed offset from all (sub)objects of the same
11032 type. We need to extract the appropriate offset from our
11033 vtable. The following dwarf expression means
11035 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11037 This is specific to the V3 ABI, of course. */
11039 dw_loc_descr_ref tmp;
11041 /* Make a copy of the object address. */
11042 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11043 add_loc_descr (&loc_descr, tmp);
11045 /* Extract the vtable address. */
11046 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11047 add_loc_descr (&loc_descr, tmp);
11049 /* Calculate the address of the offset. */
11050 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11051 gcc_assert (offset < 0);
11053 tmp = int_loc_descriptor (-offset);
11054 add_loc_descr (&loc_descr, tmp);
11055 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11056 add_loc_descr (&loc_descr, tmp);
11058 /* Extract the offset. */
11059 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11060 add_loc_descr (&loc_descr, tmp);
11062 /* Add it to the object address. */
11063 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11064 add_loc_descr (&loc_descr, tmp);
11067 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11070 offset = field_byte_offset (decl);
11074 enum dwarf_location_atom op;
11076 /* The DWARF2 standard says that we should assume that the structure
11077 address is already on the stack, so we can specify a structure field
11078 address by using DW_OP_plus_uconst. */
11080 #ifdef MIPS_DEBUGGING_INFO
11081 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11082 operator correctly. It works only if we leave the offset on the
11086 op = DW_OP_plus_uconst;
11089 loc_descr = new_loc_descr (op, offset, 0);
11092 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11095 /* Writes integer values to dw_vec_const array. */
11098 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11102 *dest++ = val & 0xff;
11108 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11110 static HOST_WIDE_INT
11111 extract_int (const unsigned char *src, unsigned int size)
11113 HOST_WIDE_INT val = 0;
11119 val |= *--src & 0xff;
11125 /* Writes floating point values to dw_vec_const array. */
11128 insert_float (const_rtx rtl, unsigned char *array)
11130 REAL_VALUE_TYPE rv;
11134 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11135 real_to_target (val, &rv, GET_MODE (rtl));
11137 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11138 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11140 insert_int (val[i], 4, array);
11145 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11146 does not have a "location" either in memory or in a register. These
11147 things can arise in GNU C when a constant is passed as an actual parameter
11148 to an inlined function. They can also arise in C++ where declared
11149 constants do not necessarily get memory "homes". */
11152 add_const_value_attribute (dw_die_ref die, rtx rtl)
11154 switch (GET_CODE (rtl))
11158 HOST_WIDE_INT val = INTVAL (rtl);
11161 add_AT_int (die, DW_AT_const_value, val);
11163 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11168 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11169 floating-point constant. A CONST_DOUBLE is used whenever the
11170 constant requires more than one word in order to be adequately
11171 represented. We output CONST_DOUBLEs as blocks. */
11173 enum machine_mode mode = GET_MODE (rtl);
11175 if (SCALAR_FLOAT_MODE_P (mode))
11177 unsigned int length = GET_MODE_SIZE (mode);
11178 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11180 insert_float (rtl, array);
11181 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11185 /* ??? We really should be using HOST_WIDE_INT throughout. */
11186 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11188 add_AT_long_long (die, DW_AT_const_value,
11189 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11196 enum machine_mode mode = GET_MODE (rtl);
11197 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11198 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11199 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11203 switch (GET_MODE_CLASS (mode))
11205 case MODE_VECTOR_INT:
11206 for (i = 0, p = array; i < length; i++, p += elt_size)
11208 rtx elt = CONST_VECTOR_ELT (rtl, i);
11209 HOST_WIDE_INT lo, hi;
11211 switch (GET_CODE (elt))
11219 lo = CONST_DOUBLE_LOW (elt);
11220 hi = CONST_DOUBLE_HIGH (elt);
11224 gcc_unreachable ();
11227 if (elt_size <= sizeof (HOST_WIDE_INT))
11228 insert_int (lo, elt_size, p);
11231 unsigned char *p0 = p;
11232 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11234 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11235 if (WORDS_BIG_ENDIAN)
11240 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11241 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11246 case MODE_VECTOR_FLOAT:
11247 for (i = 0, p = array; i < length; i++, p += elt_size)
11249 rtx elt = CONST_VECTOR_ELT (rtl, i);
11250 insert_float (elt, p);
11255 gcc_unreachable ();
11258 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11263 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11269 add_AT_addr (die, DW_AT_const_value, rtl);
11270 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11274 /* In cases where an inlined instance of an inline function is passed
11275 the address of an `auto' variable (which is local to the caller) we
11276 can get a situation where the DECL_RTL of the artificial local
11277 variable (for the inlining) which acts as a stand-in for the
11278 corresponding formal parameter (of the inline function) will look
11279 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11280 exactly a compile-time constant expression, but it isn't the address
11281 of the (artificial) local variable either. Rather, it represents the
11282 *value* which the artificial local variable always has during its
11283 lifetime. We currently have no way to represent such quasi-constant
11284 values in Dwarf, so for now we just punt and generate nothing. */
11288 /* No other kinds of rtx should be possible here. */
11289 gcc_unreachable ();
11294 /* Determine whether the evaluation of EXPR references any variables
11295 or functions which aren't otherwise used (and therefore may not be
11298 reference_to_unused (tree * tp, int * walk_subtrees,
11299 void * data ATTRIBUTE_UNUSED)
11301 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11302 *walk_subtrees = 0;
11304 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11305 && ! TREE_ASM_WRITTEN (*tp))
11307 /* ??? The C++ FE emits debug information for using decls, so
11308 putting gcc_unreachable here falls over. See PR31899. For now
11309 be conservative. */
11310 else if (!cgraph_global_info_ready
11311 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11313 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11315 struct varpool_node *node = varpool_node (*tp);
11319 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11320 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11322 struct cgraph_node *node = cgraph_node (*tp);
11323 if (node->process || TREE_ASM_WRITTEN (*tp))
11326 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11332 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11333 for use in a later add_const_value_attribute call. */
11336 rtl_for_decl_init (tree init, tree type)
11338 rtx rtl = NULL_RTX;
11340 /* If a variable is initialized with a string constant without embedded
11341 zeros, build CONST_STRING. */
11342 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11344 tree enttype = TREE_TYPE (type);
11345 tree domain = TYPE_DOMAIN (type);
11346 enum machine_mode mode = TYPE_MODE (enttype);
11348 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11350 && integer_zerop (TYPE_MIN_VALUE (domain))
11351 && compare_tree_int (TYPE_MAX_VALUE (domain),
11352 TREE_STRING_LENGTH (init) - 1) == 0
11353 && ((size_t) TREE_STRING_LENGTH (init)
11354 == strlen (TREE_STRING_POINTER (init)) + 1))
11355 rtl = gen_rtx_CONST_STRING (VOIDmode,
11356 ggc_strdup (TREE_STRING_POINTER (init)));
11358 /* Other aggregates, and complex values, could be represented using
11360 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11362 /* Vectors only work if their mode is supported by the target.
11363 FIXME: generic vectors ought to work too. */
11364 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11366 /* If the initializer is something that we know will expand into an
11367 immediate RTL constant, expand it now. We must be careful not to
11368 reference variables which won't be output. */
11369 else if (initializer_constant_valid_p (init, type)
11370 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11372 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11374 if (TREE_CODE (type) == VECTOR_TYPE)
11375 switch (TREE_CODE (init))
11380 if (TREE_CONSTANT (init))
11382 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11383 bool constant_p = true;
11385 unsigned HOST_WIDE_INT ix;
11387 /* Even when ctor is constant, it might contain non-*_CST
11388 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11389 belong into VECTOR_CST nodes. */
11390 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11391 if (!CONSTANT_CLASS_P (value))
11393 constant_p = false;
11399 init = build_vector_from_ctor (type, elts);
11409 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11411 /* If expand_expr returns a MEM, it wasn't immediate. */
11412 gcc_assert (!rtl || !MEM_P (rtl));
11418 /* Generate RTL for the variable DECL to represent its location. */
11421 rtl_for_decl_location (tree decl)
11425 /* Here we have to decide where we are going to say the parameter "lives"
11426 (as far as the debugger is concerned). We only have a couple of
11427 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11429 DECL_RTL normally indicates where the parameter lives during most of the
11430 activation of the function. If optimization is enabled however, this
11431 could be either NULL or else a pseudo-reg. Both of those cases indicate
11432 that the parameter doesn't really live anywhere (as far as the code
11433 generation parts of GCC are concerned) during most of the function's
11434 activation. That will happen (for example) if the parameter is never
11435 referenced within the function.
11437 We could just generate a location descriptor here for all non-NULL
11438 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11439 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11440 where DECL_RTL is NULL or is a pseudo-reg.
11442 Note however that we can only get away with using DECL_INCOMING_RTL as
11443 a backup substitute for DECL_RTL in certain limited cases. In cases
11444 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11445 we can be sure that the parameter was passed using the same type as it is
11446 declared to have within the function, and that its DECL_INCOMING_RTL
11447 points us to a place where a value of that type is passed.
11449 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11450 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11451 because in these cases DECL_INCOMING_RTL points us to a value of some
11452 type which is *different* from the type of the parameter itself. Thus,
11453 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11454 such cases, the debugger would end up (for example) trying to fetch a
11455 `float' from a place which actually contains the first part of a
11456 `double'. That would lead to really incorrect and confusing
11457 output at debug-time.
11459 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11460 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11461 are a couple of exceptions however. On little-endian machines we can
11462 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11463 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11464 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11465 when (on a little-endian machine) a non-prototyped function has a
11466 parameter declared to be of type `short' or `char'. In such cases,
11467 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11468 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11469 passed `int' value. If the debugger then uses that address to fetch
11470 a `short' or a `char' (on a little-endian machine) the result will be
11471 the correct data, so we allow for such exceptional cases below.
11473 Note that our goal here is to describe the place where the given formal
11474 parameter lives during most of the function's activation (i.e. between the
11475 end of the prologue and the start of the epilogue). We'll do that as best
11476 as we can. Note however that if the given formal parameter is modified
11477 sometime during the execution of the function, then a stack backtrace (at
11478 debug-time) will show the function as having been called with the *new*
11479 value rather than the value which was originally passed in. This happens
11480 rarely enough that it is not a major problem, but it *is* a problem, and
11481 I'd like to fix it.
11483 A future version of dwarf2out.c may generate two additional attributes for
11484 any given DW_TAG_formal_parameter DIE which will describe the "passed
11485 type" and the "passed location" for the given formal parameter in addition
11486 to the attributes we now generate to indicate the "declared type" and the
11487 "active location" for each parameter. This additional set of attributes
11488 could be used by debuggers for stack backtraces. Separately, note that
11489 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11490 This happens (for example) for inlined-instances of inline function formal
11491 parameters which are never referenced. This really shouldn't be
11492 happening. All PARM_DECL nodes should get valid non-NULL
11493 DECL_INCOMING_RTL values. FIXME. */
11495 /* Use DECL_RTL as the "location" unless we find something better. */
11496 rtl = DECL_RTL_IF_SET (decl);
11498 /* When generating abstract instances, ignore everything except
11499 constants, symbols living in memory, and symbols living in
11500 fixed registers. */
11501 if (! reload_completed)
11504 && (CONSTANT_P (rtl)
11506 && CONSTANT_P (XEXP (rtl, 0)))
11508 && TREE_CODE (decl) == VAR_DECL
11509 && TREE_STATIC (decl))))
11511 rtl = targetm.delegitimize_address (rtl);
11516 else if (TREE_CODE (decl) == PARM_DECL)
11518 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11520 tree declared_type = TREE_TYPE (decl);
11521 tree passed_type = DECL_ARG_TYPE (decl);
11522 enum machine_mode dmode = TYPE_MODE (declared_type);
11523 enum machine_mode pmode = TYPE_MODE (passed_type);
11525 /* This decl represents a formal parameter which was optimized out.
11526 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11527 all cases where (rtl == NULL_RTX) just below. */
11528 if (dmode == pmode)
11529 rtl = DECL_INCOMING_RTL (decl);
11530 else if (SCALAR_INT_MODE_P (dmode)
11531 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11532 && DECL_INCOMING_RTL (decl))
11534 rtx inc = DECL_INCOMING_RTL (decl);
11537 else if (MEM_P (inc))
11539 if (BYTES_BIG_ENDIAN)
11540 rtl = adjust_address_nv (inc, dmode,
11541 GET_MODE_SIZE (pmode)
11542 - GET_MODE_SIZE (dmode));
11549 /* If the parm was passed in registers, but lives on the stack, then
11550 make a big endian correction if the mode of the type of the
11551 parameter is not the same as the mode of the rtl. */
11552 /* ??? This is the same series of checks that are made in dbxout.c before
11553 we reach the big endian correction code there. It isn't clear if all
11554 of these checks are necessary here, but keeping them all is the safe
11556 else if (MEM_P (rtl)
11557 && XEXP (rtl, 0) != const0_rtx
11558 && ! CONSTANT_P (XEXP (rtl, 0))
11559 /* Not passed in memory. */
11560 && !MEM_P (DECL_INCOMING_RTL (decl))
11561 /* Not passed by invisible reference. */
11562 && (!REG_P (XEXP (rtl, 0))
11563 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11564 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11565 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11566 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11569 /* Big endian correction check. */
11570 && BYTES_BIG_ENDIAN
11571 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11572 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11575 int offset = (UNITS_PER_WORD
11576 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11578 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11579 plus_constant (XEXP (rtl, 0), offset));
11582 else if (TREE_CODE (decl) == VAR_DECL
11585 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11586 && BYTES_BIG_ENDIAN)
11588 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11589 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11591 /* If a variable is declared "register" yet is smaller than
11592 a register, then if we store the variable to memory, it
11593 looks like we're storing a register-sized value, when in
11594 fact we are not. We need to adjust the offset of the
11595 storage location to reflect the actual value's bytes,
11596 else gdb will not be able to display it. */
11598 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11599 plus_constant (XEXP (rtl, 0), rsize-dsize));
11602 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11603 and will have been substituted directly into all expressions that use it.
11604 C does not have such a concept, but C++ and other languages do. */
11605 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11606 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11609 rtl = targetm.delegitimize_address (rtl);
11611 /* If we don't look past the constant pool, we risk emitting a
11612 reference to a constant pool entry that isn't referenced from
11613 code, and thus is not emitted. */
11615 rtl = avoid_constant_pool_reference (rtl);
11620 /* We need to figure out what section we should use as the base for the
11621 address ranges where a given location is valid.
11622 1. If this particular DECL has a section associated with it, use that.
11623 2. If this function has a section associated with it, use that.
11624 3. Otherwise, use the text section.
11625 XXX: If you split a variable across multiple sections, we won't notice. */
11627 static const char *
11628 secname_for_decl (const_tree decl)
11630 const char *secname;
11632 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11634 tree sectree = DECL_SECTION_NAME (decl);
11635 secname = TREE_STRING_POINTER (sectree);
11637 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11639 tree sectree = DECL_SECTION_NAME (current_function_decl);
11640 secname = TREE_STRING_POINTER (sectree);
11642 else if (cfun && in_cold_section_p)
11643 secname = crtl->subsections.cold_section_label;
11645 secname = text_section_label;
11650 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
11651 returned. If so, the decl for the COMMON block is returned, and the
11652 value is the offset into the common block for the symbol. */
11655 fortran_common (tree decl, HOST_WIDE_INT *value)
11657 tree val_expr, cvar;
11658 enum machine_mode mode;
11659 HOST_WIDE_INT bitsize, bitpos;
11661 int volatilep = 0, unsignedp = 0;
11663 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11664 it does not have a value (the offset into the common area), or if it
11665 is thread local (as opposed to global) then it isn't common, and shouldn't
11666 be handled as such. */
11667 if (TREE_CODE (decl) != VAR_DECL
11668 || !TREE_PUBLIC (decl)
11669 || !TREE_STATIC (decl)
11670 || !DECL_HAS_VALUE_EXPR_P (decl)
11674 val_expr = DECL_VALUE_EXPR (decl);
11675 if (TREE_CODE (val_expr) != COMPONENT_REF)
11678 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11679 &mode, &unsignedp, &volatilep, true);
11681 if (cvar == NULL_TREE
11682 || TREE_CODE (cvar) != VAR_DECL
11683 || DECL_ARTIFICIAL (cvar)
11684 || !TREE_PUBLIC (cvar))
11688 if (offset != NULL)
11690 if (!host_integerp (offset, 0))
11692 *value = tree_low_cst (offset, 0);
11695 *value += bitpos / BITS_PER_UNIT;
11700 /* Dereference a location expression LOC if DECL is passed by invisible
11703 static dw_loc_descr_ref
11704 loc_by_reference (dw_loc_descr_ref loc, tree decl)
11706 HOST_WIDE_INT size;
11707 enum dwarf_location_atom op;
11712 if ((TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != RESULT_DECL)
11713 || !DECL_BY_REFERENCE (decl))
11716 size = int_size_in_bytes (TREE_TYPE (decl));
11717 if (size > DWARF2_ADDR_SIZE || size == -1)
11719 else if (size == DWARF2_ADDR_SIZE)
11722 op = DW_OP_deref_size;
11723 add_loc_descr (&loc, new_loc_descr (op, size, 0));
11727 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11728 data attribute for a variable or a parameter. We generate the
11729 DW_AT_const_value attribute only in those cases where the given variable
11730 or parameter does not have a true "location" either in memory or in a
11731 register. This can happen (for example) when a constant is passed as an
11732 actual argument in a call to an inline function. (It's possible that
11733 these things can crop up in other ways also.) Note that one type of
11734 constant value which can be passed into an inlined function is a constant
11735 pointer. This can happen for example if an actual argument in an inlined
11736 function call evaluates to a compile-time constant address. */
11739 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11740 enum dwarf_attribute attr)
11743 dw_loc_descr_ref descr;
11744 var_loc_list *loc_list;
11745 struct var_loc_node *node;
11746 if (TREE_CODE (decl) == ERROR_MARK)
11749 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11750 || TREE_CODE (decl) == RESULT_DECL);
11752 /* See if we possibly have multiple locations for this variable. */
11753 loc_list = lookup_decl_loc (decl);
11755 /* If it truly has multiple locations, the first and last node will
11757 if (loc_list && loc_list->first != loc_list->last)
11759 const char *endname, *secname;
11760 dw_loc_list_ref list;
11762 enum var_init_status initialized;
11764 /* Now that we know what section we are using for a base,
11765 actually construct the list of locations.
11766 The first location information is what is passed to the
11767 function that creates the location list, and the remaining
11768 locations just get added on to that list.
11769 Note that we only know the start address for a location
11770 (IE location changes), so to build the range, we use
11771 the range [current location start, next location start].
11772 This means we have to special case the last node, and generate
11773 a range of [last location start, end of function label]. */
11775 node = loc_list->first;
11776 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11777 secname = secname_for_decl (decl);
11779 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11780 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11782 initialized = VAR_INIT_STATUS_INITIALIZED;
11784 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
11785 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
11788 for (; node->next; node = node->next)
11789 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11791 /* The variable has a location between NODE->LABEL and
11792 NODE->NEXT->LABEL. */
11793 enum var_init_status initialized =
11794 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11795 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11796 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11798 add_loc_descr_to_loc_list (&list, descr,
11799 node->label, node->next->label, secname);
11802 /* If the variable has a location at the last label
11803 it keeps its location until the end of function. */
11804 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11806 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11807 enum var_init_status initialized =
11808 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11810 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11811 if (!current_function_decl)
11812 endname = text_end_label;
11815 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11816 current_function_funcdef_no);
11817 endname = ggc_strdup (label_id);
11819 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11821 add_loc_descr_to_loc_list (&list, descr,
11822 node->label, endname, secname);
11825 /* Finally, add the location list to the DIE, and we are done. */
11826 add_AT_loc_list (die, attr, list);
11830 /* Try to get some constant RTL for this decl, and use that as the value of
11833 rtl = rtl_for_decl_location (decl);
11834 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11836 add_const_value_attribute (die, rtl);
11840 /* If we have tried to generate the location otherwise, and it
11841 didn't work out (we wouldn't be here if we did), and we have a one entry
11842 location list, try generating a location from that. */
11843 if (loc_list && loc_list->first)
11845 enum var_init_status status;
11846 node = loc_list->first;
11847 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11848 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11851 descr = loc_by_reference (descr, decl);
11852 add_AT_location_description (die, attr, descr);
11857 /* We couldn't get any rtl, so try directly generating the location
11858 description from the tree. */
11859 descr = loc_descriptor_from_tree (decl);
11862 descr = loc_by_reference (descr, decl);
11863 add_AT_location_description (die, attr, descr);
11866 /* None of that worked, so it must not really have a location;
11867 try adding a constant value attribute from the DECL_INITIAL. */
11868 tree_add_const_value_attribute (die, decl);
11871 /* Add VARIABLE and DIE into deferred locations list. */
11874 defer_location (tree variable, dw_die_ref die)
11876 deferred_locations entry;
11877 entry.variable = variable;
11879 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
11882 /* Helper function for tree_add_const_value_attribute. Natively encode
11883 initializer INIT into an array. Return true if successful. */
11886 native_encode_initializer (tree init, unsigned char *array, int size)
11890 if (init == NULL_TREE)
11894 switch (TREE_CODE (init))
11897 type = TREE_TYPE (init);
11898 if (TREE_CODE (type) == ARRAY_TYPE)
11900 tree enttype = TREE_TYPE (type);
11901 enum machine_mode mode = TYPE_MODE (enttype);
11903 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
11905 if (int_size_in_bytes (type) != size)
11907 if (size > TREE_STRING_LENGTH (init))
11909 memcpy (array, TREE_STRING_POINTER (init),
11910 TREE_STRING_LENGTH (init));
11911 memset (array + TREE_STRING_LENGTH (init),
11912 '\0', size - TREE_STRING_LENGTH (init));
11915 memcpy (array, TREE_STRING_POINTER (init), size);
11920 type = TREE_TYPE (init);
11921 if (int_size_in_bytes (type) != size)
11923 if (TREE_CODE (type) == ARRAY_TYPE)
11925 HOST_WIDE_INT min_index;
11926 unsigned HOST_WIDE_INT cnt;
11927 int curpos = 0, fieldsize;
11928 constructor_elt *ce;
11930 if (TYPE_DOMAIN (type) == NULL_TREE
11931 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
11934 fieldsize = int_size_in_bytes (TREE_TYPE (type));
11935 if (fieldsize <= 0)
11938 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
11939 memset (array, '\0', size);
11941 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
11944 tree val = ce->value;
11945 tree index = ce->index;
11947 if (index && TREE_CODE (index) == RANGE_EXPR)
11948 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
11951 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
11956 if (!native_encode_initializer (val, array + pos, fieldsize))
11959 curpos = pos + fieldsize;
11960 if (index && TREE_CODE (index) == RANGE_EXPR)
11962 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
11963 - tree_low_cst (TREE_OPERAND (index, 0), 0);
11967 memcpy (array + curpos, array + pos, fieldsize);
11968 curpos += fieldsize;
11971 gcc_assert (curpos <= size);
11975 else if (TREE_CODE (type) == RECORD_TYPE
11976 || TREE_CODE (type) == UNION_TYPE)
11978 tree field = NULL_TREE;
11979 unsigned HOST_WIDE_INT cnt;
11980 constructor_elt *ce;
11982 if (int_size_in_bytes (type) != size)
11985 if (TREE_CODE (type) == RECORD_TYPE)
11986 field = TYPE_FIELDS (type);
11989 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
11990 cnt++, field = field ? TREE_CHAIN (field) : 0)
11992 tree val = ce->value;
11993 int pos, fieldsize;
11995 if (ce->index != 0)
12001 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12004 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12005 && TYPE_DOMAIN (TREE_TYPE (field))
12006 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12008 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12009 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12011 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12012 pos = int_byte_position (field);
12013 gcc_assert (pos + fieldsize <= size);
12015 && !native_encode_initializer (val, array + pos, fieldsize))
12021 case VIEW_CONVERT_EXPR:
12022 case NON_LVALUE_EXPR:
12023 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12025 return native_encode_expr (init, array, size) == size;
12029 /* If we don't have a copy of this variable in memory for some reason (such
12030 as a C++ member constant that doesn't have an out-of-line definition),
12031 we should tell the debugger about the constant value. */
12034 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12037 tree type = TREE_TYPE (decl);
12040 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12043 init = DECL_INITIAL (decl);
12044 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12049 rtl = rtl_for_decl_init (init, type);
12051 add_const_value_attribute (var_die, rtl);
12052 /* If the host and target are sane, try harder. */
12053 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12054 && initializer_constant_valid_p (init, type))
12056 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12057 if (size > 0 && (int) size == size)
12059 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12061 if (native_encode_initializer (init, array, size))
12062 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12067 /* Convert the CFI instructions for the current function into a
12068 location list. This is used for DW_AT_frame_base when we targeting
12069 a dwarf2 consumer that does not support the dwarf3
12070 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12073 static dw_loc_list_ref
12074 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12077 dw_loc_list_ref list, *list_tail;
12079 dw_cfa_location last_cfa, next_cfa;
12080 const char *start_label, *last_label, *section;
12082 fde = current_fde ();
12083 gcc_assert (fde != NULL);
12085 section = secname_for_decl (current_function_decl);
12089 next_cfa.reg = INVALID_REGNUM;
12090 next_cfa.offset = 0;
12091 next_cfa.indirect = 0;
12092 next_cfa.base_offset = 0;
12094 start_label = fde->dw_fde_begin;
12096 /* ??? Bald assumption that the CIE opcode list does not contain
12097 advance opcodes. */
12098 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12099 lookup_cfa_1 (cfi, &next_cfa);
12101 last_cfa = next_cfa;
12102 last_label = start_label;
12104 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12105 switch (cfi->dw_cfi_opc)
12107 case DW_CFA_set_loc:
12108 case DW_CFA_advance_loc1:
12109 case DW_CFA_advance_loc2:
12110 case DW_CFA_advance_loc4:
12111 if (!cfa_equal_p (&last_cfa, &next_cfa))
12113 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12114 start_label, last_label, section,
12117 list_tail = &(*list_tail)->dw_loc_next;
12118 last_cfa = next_cfa;
12119 start_label = last_label;
12121 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12124 case DW_CFA_advance_loc:
12125 /* The encoding is complex enough that we should never emit this. */
12126 case DW_CFA_remember_state:
12127 case DW_CFA_restore_state:
12128 /* We don't handle these two in this function. It would be possible
12129 if it were to be required. */
12130 gcc_unreachable ();
12133 lookup_cfa_1 (cfi, &next_cfa);
12137 if (!cfa_equal_p (&last_cfa, &next_cfa))
12139 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12140 start_label, last_label, section,
12142 list_tail = &(*list_tail)->dw_loc_next;
12143 start_label = last_label;
12145 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12146 start_label, fde->dw_fde_end, section,
12152 /* Compute a displacement from the "steady-state frame pointer" to the
12153 frame base (often the same as the CFA), and store it in
12154 frame_pointer_fb_offset. OFFSET is added to the displacement
12155 before the latter is negated. */
12158 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12162 #ifdef FRAME_POINTER_CFA_OFFSET
12163 reg = frame_pointer_rtx;
12164 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12166 reg = arg_pointer_rtx;
12167 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12170 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12171 if (GET_CODE (elim) == PLUS)
12173 offset += INTVAL (XEXP (elim, 1));
12174 elim = XEXP (elim, 0);
12177 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12178 && (elim == hard_frame_pointer_rtx
12179 || elim == stack_pointer_rtx))
12180 || elim == (frame_pointer_needed
12181 ? hard_frame_pointer_rtx
12182 : stack_pointer_rtx));
12184 frame_pointer_fb_offset = -offset;
12187 /* Generate a DW_AT_name attribute given some string value to be included as
12188 the value of the attribute. */
12191 add_name_attribute (dw_die_ref die, const char *name_string)
12193 if (name_string != NULL && *name_string != 0)
12195 if (demangle_name_func)
12196 name_string = (*demangle_name_func) (name_string);
12198 add_AT_string (die, DW_AT_name, name_string);
12202 /* Generate a DW_AT_comp_dir attribute for DIE. */
12205 add_comp_dir_attribute (dw_die_ref die)
12207 const char *wd = get_src_pwd ();
12209 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12212 /* Given a tree node describing an array bound (either lower or upper) output
12213 a representation for that bound. */
12216 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12218 switch (TREE_CODE (bound))
12223 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12225 if (! host_integerp (bound, 0)
12226 || (bound_attr == DW_AT_lower_bound
12227 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12228 || (is_fortran () && integer_onep (bound)))))
12229 /* Use the default. */
12232 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12236 case VIEW_CONVERT_EXPR:
12237 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
12247 dw_die_ref decl_die = lookup_decl_die (bound);
12248 dw_loc_descr_ref loc;
12250 /* ??? Can this happen, or should the variable have been bound
12251 first? Probably it can, since I imagine that we try to create
12252 the types of parameters in the order in which they exist in
12253 the list, and won't have created a forward reference to a
12254 later parameter. */
12255 if (decl_die != NULL)
12256 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12259 loc = loc_descriptor_from_tree_1 (bound, 0);
12260 add_AT_location_description (subrange_die, bound_attr, loc);
12267 /* Otherwise try to create a stack operation procedure to
12268 evaluate the value of the array bound. */
12270 dw_die_ref ctx, decl_die;
12271 dw_loc_descr_ref loc;
12273 loc = loc_descriptor_from_tree (bound);
12277 if (current_function_decl == 0)
12278 ctx = comp_unit_die;
12280 ctx = lookup_decl_die (current_function_decl);
12282 decl_die = new_die (DW_TAG_variable, ctx, bound);
12283 add_AT_flag (decl_die, DW_AT_artificial, 1);
12284 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12285 add_AT_loc (decl_die, DW_AT_location, loc);
12287 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12293 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12294 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12295 Note that the block of subscript information for an array type also
12296 includes information about the element type of the given array type. */
12299 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12301 unsigned dimension_number;
12303 dw_die_ref subrange_die;
12305 for (dimension_number = 0;
12306 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12307 type = TREE_TYPE (type), dimension_number++)
12309 tree domain = TYPE_DOMAIN (type);
12311 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12314 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12315 and (in GNU C only) variable bounds. Handle all three forms
12317 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12320 /* We have an array type with specified bounds. */
12321 lower = TYPE_MIN_VALUE (domain);
12322 upper = TYPE_MAX_VALUE (domain);
12324 /* Define the index type. */
12325 if (TREE_TYPE (domain))
12327 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12328 TREE_TYPE field. We can't emit debug info for this
12329 because it is an unnamed integral type. */
12330 if (TREE_CODE (domain) == INTEGER_TYPE
12331 && TYPE_NAME (domain) == NULL_TREE
12332 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12333 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12336 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12340 /* ??? If upper is NULL, the array has unspecified length,
12341 but it does have a lower bound. This happens with Fortran
12343 Since the debugger is definitely going to need to know N
12344 to produce useful results, go ahead and output the lower
12345 bound solo, and hope the debugger can cope. */
12347 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12349 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12352 /* Otherwise we have an array type with an unspecified length. The
12353 DWARF-2 spec does not say how to handle this; let's just leave out the
12359 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12363 switch (TREE_CODE (tree_node))
12368 case ENUMERAL_TYPE:
12371 case QUAL_UNION_TYPE:
12372 size = int_size_in_bytes (tree_node);
12375 /* For a data member of a struct or union, the DW_AT_byte_size is
12376 generally given as the number of bytes normally allocated for an
12377 object of the *declared* type of the member itself. This is true
12378 even for bit-fields. */
12379 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12382 gcc_unreachable ();
12385 /* Note that `size' might be -1 when we get to this point. If it is, that
12386 indicates that the byte size of the entity in question is variable. We
12387 have no good way of expressing this fact in Dwarf at the present time,
12388 so just let the -1 pass on through. */
12389 add_AT_unsigned (die, DW_AT_byte_size, size);
12392 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12393 which specifies the distance in bits from the highest order bit of the
12394 "containing object" for the bit-field to the highest order bit of the
12397 For any given bit-field, the "containing object" is a hypothetical object
12398 (of some integral or enum type) within which the given bit-field lives. The
12399 type of this hypothetical "containing object" is always the same as the
12400 declared type of the individual bit-field itself. The determination of the
12401 exact location of the "containing object" for a bit-field is rather
12402 complicated. It's handled by the `field_byte_offset' function (above).
12404 Note that it is the size (in bytes) of the hypothetical "containing object"
12405 which will be given in the DW_AT_byte_size attribute for this bit-field.
12406 (See `byte_size_attribute' above). */
12409 add_bit_offset_attribute (dw_die_ref die, tree decl)
12411 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12412 tree type = DECL_BIT_FIELD_TYPE (decl);
12413 HOST_WIDE_INT bitpos_int;
12414 HOST_WIDE_INT highest_order_object_bit_offset;
12415 HOST_WIDE_INT highest_order_field_bit_offset;
12416 HOST_WIDE_INT unsigned bit_offset;
12418 /* Must be a field and a bit field. */
12419 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12421 /* We can't yet handle bit-fields whose offsets are variable, so if we
12422 encounter such things, just return without generating any attribute
12423 whatsoever. Likewise for variable or too large size. */
12424 if (! host_integerp (bit_position (decl), 0)
12425 || ! host_integerp (DECL_SIZE (decl), 1))
12428 bitpos_int = int_bit_position (decl);
12430 /* Note that the bit offset is always the distance (in bits) from the
12431 highest-order bit of the "containing object" to the highest-order bit of
12432 the bit-field itself. Since the "high-order end" of any object or field
12433 is different on big-endian and little-endian machines, the computation
12434 below must take account of these differences. */
12435 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12436 highest_order_field_bit_offset = bitpos_int;
12438 if (! BYTES_BIG_ENDIAN)
12440 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12441 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12445 = (! BYTES_BIG_ENDIAN
12446 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12447 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12449 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12452 /* For a FIELD_DECL node which represents a bit field, output an attribute
12453 which specifies the length in bits of the given field. */
12456 add_bit_size_attribute (dw_die_ref die, tree decl)
12458 /* Must be a field and a bit field. */
12459 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12460 && DECL_BIT_FIELD_TYPE (decl));
12462 if (host_integerp (DECL_SIZE (decl), 1))
12463 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12466 /* If the compiled language is ANSI C, then add a 'prototyped'
12467 attribute, if arg types are given for the parameters of a function. */
12470 add_prototyped_attribute (dw_die_ref die, tree func_type)
12472 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12473 && TYPE_ARG_TYPES (func_type) != NULL)
12474 add_AT_flag (die, DW_AT_prototyped, 1);
12477 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12478 by looking in either the type declaration or object declaration
12481 static inline dw_die_ref
12482 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12484 dw_die_ref origin_die = NULL;
12486 if (TREE_CODE (origin) != FUNCTION_DECL)
12488 /* We may have gotten separated from the block for the inlined
12489 function, if we're in an exception handler or some such; make
12490 sure that the abstract function has been written out.
12492 Doing this for nested functions is wrong, however; functions are
12493 distinct units, and our context might not even be inline. */
12497 fn = TYPE_STUB_DECL (fn);
12499 fn = decl_function_context (fn);
12501 dwarf2out_abstract_function (fn);
12504 if (DECL_P (origin))
12505 origin_die = lookup_decl_die (origin);
12506 else if (TYPE_P (origin))
12507 origin_die = lookup_type_die (origin);
12509 /* XXX: Functions that are never lowered don't always have correct block
12510 trees (in the case of java, they simply have no block tree, in some other
12511 languages). For these functions, there is nothing we can really do to
12512 output correct debug info for inlined functions in all cases. Rather
12513 than die, we'll just produce deficient debug info now, in that we will
12514 have variables without a proper abstract origin. In the future, when all
12515 functions are lowered, we should re-add a gcc_assert (origin_die)
12519 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12523 /* We do not currently support the pure_virtual attribute. */
12526 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12528 if (DECL_VINDEX (func_decl))
12530 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12532 if (host_integerp (DECL_VINDEX (func_decl), 0))
12533 add_AT_loc (die, DW_AT_vtable_elem_location,
12534 new_loc_descr (DW_OP_constu,
12535 tree_low_cst (DECL_VINDEX (func_decl), 0),
12538 /* GNU extension: Record what type this method came from originally. */
12539 if (debug_info_level > DINFO_LEVEL_TERSE)
12540 add_AT_die_ref (die, DW_AT_containing_type,
12541 lookup_type_die (DECL_CONTEXT (func_decl)));
12545 /* Add source coordinate attributes for the given decl. */
12548 add_src_coords_attributes (dw_die_ref die, tree decl)
12550 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12552 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12553 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12556 /* Add a DW_AT_name attribute and source coordinate attribute for the
12557 given decl, but only if it actually has a name. */
12560 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12564 decl_name = DECL_NAME (decl);
12565 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12567 add_name_attribute (die, dwarf2_name (decl, 0));
12568 if (! DECL_ARTIFICIAL (decl))
12569 add_src_coords_attributes (die, decl);
12571 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12572 && TREE_PUBLIC (decl)
12573 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12574 && !DECL_ABSTRACT (decl)
12575 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12577 add_AT_string (die, DW_AT_MIPS_linkage_name,
12578 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12581 #ifdef VMS_DEBUGGING_INFO
12582 /* Get the function's name, as described by its RTL. This may be different
12583 from the DECL_NAME name used in the source file. */
12584 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12586 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12587 XEXP (DECL_RTL (decl), 0));
12588 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12593 /* Push a new declaration scope. */
12596 push_decl_scope (tree scope)
12598 VEC_safe_push (tree, gc, decl_scope_table, scope);
12601 /* Pop a declaration scope. */
12604 pop_decl_scope (void)
12606 VEC_pop (tree, decl_scope_table);
12609 /* Return the DIE for the scope that immediately contains this type.
12610 Non-named types get global scope. Named types nested in other
12611 types get their containing scope if it's open, or global scope
12612 otherwise. All other types (i.e. function-local named types) get
12613 the current active scope. */
12616 scope_die_for (tree t, dw_die_ref context_die)
12618 dw_die_ref scope_die = NULL;
12619 tree containing_scope;
12622 /* Non-types always go in the current scope. */
12623 gcc_assert (TYPE_P (t));
12625 containing_scope = TYPE_CONTEXT (t);
12627 /* Use the containing namespace if it was passed in (for a declaration). */
12628 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12630 if (context_die == lookup_decl_die (containing_scope))
12633 containing_scope = NULL_TREE;
12636 /* Ignore function type "scopes" from the C frontend. They mean that
12637 a tagged type is local to a parmlist of a function declarator, but
12638 that isn't useful to DWARF. */
12639 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12640 containing_scope = NULL_TREE;
12642 if (containing_scope == NULL_TREE)
12643 scope_die = comp_unit_die;
12644 else if (TYPE_P (containing_scope))
12646 /* For types, we can just look up the appropriate DIE. But
12647 first we check to see if we're in the middle of emitting it
12648 so we know where the new DIE should go. */
12649 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12650 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12655 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12656 || TREE_ASM_WRITTEN (containing_scope));
12658 /* If none of the current dies are suitable, we get file scope. */
12659 scope_die = comp_unit_die;
12662 scope_die = lookup_type_die (containing_scope);
12665 scope_die = context_die;
12670 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12673 local_scope_p (dw_die_ref context_die)
12675 for (; context_die; context_die = context_die->die_parent)
12676 if (context_die->die_tag == DW_TAG_inlined_subroutine
12677 || context_die->die_tag == DW_TAG_subprogram)
12683 /* Returns nonzero if CONTEXT_DIE is a class. */
12686 class_scope_p (dw_die_ref context_die)
12688 return (context_die
12689 && (context_die->die_tag == DW_TAG_structure_type
12690 || context_die->die_tag == DW_TAG_class_type
12691 || context_die->die_tag == DW_TAG_interface_type
12692 || context_die->die_tag == DW_TAG_union_type));
12695 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12696 whether or not to treat a DIE in this context as a declaration. */
12699 class_or_namespace_scope_p (dw_die_ref context_die)
12701 return (class_scope_p (context_die)
12702 || (context_die && context_die->die_tag == DW_TAG_namespace));
12705 /* Many forms of DIEs require a "type description" attribute. This
12706 routine locates the proper "type descriptor" die for the type given
12707 by 'type', and adds a DW_AT_type attribute below the given die. */
12710 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12711 int decl_volatile, dw_die_ref context_die)
12713 enum tree_code code = TREE_CODE (type);
12714 dw_die_ref type_die = NULL;
12716 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12717 or fixed-point type, use the inner type. This is because we have no
12718 support for unnamed types in base_type_die. This can happen if this is
12719 an Ada subrange type. Correct solution is emit a subrange type die. */
12720 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12721 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12722 type = TREE_TYPE (type), code = TREE_CODE (type);
12724 if (code == ERROR_MARK
12725 /* Handle a special case. For functions whose return type is void, we
12726 generate *no* type attribute. (Note that no object may have type
12727 `void', so this only applies to function return types). */
12728 || code == VOID_TYPE)
12731 type_die = modified_type_die (type,
12732 decl_const || TYPE_READONLY (type),
12733 decl_volatile || TYPE_VOLATILE (type),
12736 if (type_die != NULL)
12737 add_AT_die_ref (object_die, DW_AT_type, type_die);
12740 /* Given an object die, add the calling convention attribute for the
12741 function call type. */
12743 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12745 enum dwarf_calling_convention value = DW_CC_normal;
12747 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12749 /* DWARF doesn't provide a way to identify a program's source-level
12750 entry point. DW_AT_calling_convention attributes are only meant
12751 to describe functions' calling conventions. However, lacking a
12752 better way to signal the Fortran main program, we use this for the
12753 time being, following existing custom. */
12755 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12756 value = DW_CC_program;
12758 /* Only add the attribute if the backend requests it, and
12759 is not DW_CC_normal. */
12760 if (value && (value != DW_CC_normal))
12761 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12764 /* Given a tree pointer to a struct, class, union, or enum type node, return
12765 a pointer to the (string) tag name for the given type, or zero if the type
12766 was declared without a tag. */
12768 static const char *
12769 type_tag (const_tree type)
12771 const char *name = 0;
12773 if (TYPE_NAME (type) != 0)
12777 /* Find the IDENTIFIER_NODE for the type name. */
12778 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12779 t = TYPE_NAME (type);
12781 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12782 a TYPE_DECL node, regardless of whether or not a `typedef' was
12784 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12785 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12787 /* We want to be extra verbose. Don't call dwarf_name if
12788 DECL_NAME isn't set. The default hook for decl_printable_name
12789 doesn't like that, and in this context it's correct to return
12790 0, instead of "<anonymous>" or the like. */
12791 if (DECL_NAME (TYPE_NAME (type)))
12792 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12795 /* Now get the name as a string, or invent one. */
12796 if (!name && t != 0)
12797 name = IDENTIFIER_POINTER (t);
12800 return (name == 0 || *name == '\0') ? 0 : name;
12803 /* Return the type associated with a data member, make a special check
12804 for bit field types. */
12807 member_declared_type (const_tree member)
12809 return (DECL_BIT_FIELD_TYPE (member)
12810 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12813 /* Get the decl's label, as described by its RTL. This may be different
12814 from the DECL_NAME name used in the source file. */
12817 static const char *
12818 decl_start_label (tree decl)
12821 const char *fnname;
12823 x = DECL_RTL (decl);
12824 gcc_assert (MEM_P (x));
12827 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12829 fnname = XSTR (x, 0);
12834 /* These routines generate the internal representation of the DIE's for
12835 the compilation unit. Debugging information is collected by walking
12836 the declaration trees passed in from dwarf2out_decl(). */
12839 gen_array_type_die (tree type, dw_die_ref context_die)
12841 dw_die_ref scope_die = scope_die_for (type, context_die);
12842 dw_die_ref array_die;
12844 /* GNU compilers represent multidimensional array types as sequences of one
12845 dimensional array types whose element types are themselves array types.
12846 We sometimes squish that down to a single array_type DIE with multiple
12847 subscripts in the Dwarf debugging info. The draft Dwarf specification
12848 say that we are allowed to do this kind of compression in C, because
12849 there is no difference between an array of arrays and a multidimensional
12850 array. We don't do this for Ada to remain as close as possible to the
12851 actual representation, which is especially important against the language
12852 flexibilty wrt arrays of variable size. */
12854 bool collapse_nested_arrays = !is_ada ();
12857 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
12858 DW_TAG_string_type doesn't have DW_AT_type attribute). */
12859 if (TYPE_STRING_FLAG (type)
12860 && TREE_CODE (type) == ARRAY_TYPE
12862 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
12864 HOST_WIDE_INT size;
12866 array_die = new_die (DW_TAG_string_type, scope_die, type);
12867 add_name_attribute (array_die, type_tag (type));
12868 equate_type_number_to_die (type, array_die);
12869 size = int_size_in_bytes (type);
12871 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12872 else if (TYPE_DOMAIN (type) != NULL_TREE
12873 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
12874 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
12876 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
12877 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
12879 size = int_size_in_bytes (TREE_TYPE (szdecl));
12880 if (loc && size > 0)
12882 add_AT_loc (array_die, DW_AT_string_length, loc);
12883 if (size != DWARF2_ADDR_SIZE)
12884 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12890 /* ??? The SGI dwarf reader fails for array of array of enum types
12891 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12892 array type comes before the outer array type. We thus call gen_type_die
12893 before we new_die and must prevent nested array types collapsing for this
12896 #ifdef MIPS_DEBUGGING_INFO
12897 gen_type_die (TREE_TYPE (type), context_die);
12898 collapse_nested_arrays = false;
12901 array_die = new_die (DW_TAG_array_type, scope_die, type);
12902 add_name_attribute (array_die, type_tag (type));
12903 equate_type_number_to_die (type, array_die);
12905 if (TREE_CODE (type) == VECTOR_TYPE)
12907 /* The frontend feeds us a representation for the vector as a struct
12908 containing an array. Pull out the array type. */
12909 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12910 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12913 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12915 && TREE_CODE (type) == ARRAY_TYPE
12916 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
12917 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
12918 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12921 /* We default the array ordering. SDB will probably do
12922 the right things even if DW_AT_ordering is not present. It's not even
12923 an issue until we start to get into multidimensional arrays anyway. If
12924 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12925 then we'll have to put the DW_AT_ordering attribute back in. (But if
12926 and when we find out that we need to put these in, we will only do so
12927 for multidimensional arrays. */
12928 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
12931 #ifdef MIPS_DEBUGGING_INFO
12932 /* The SGI compilers handle arrays of unknown bound by setting
12933 AT_declaration and not emitting any subrange DIEs. */
12934 if (! TYPE_DOMAIN (type))
12935 add_AT_flag (array_die, DW_AT_declaration, 1);
12938 add_subscript_info (array_die, type, collapse_nested_arrays);
12940 /* Add representation of the type of the elements of this array type and
12941 emit the corresponding DIE if we haven't done it already. */
12942 element_type = TREE_TYPE (type);
12943 if (collapse_nested_arrays)
12944 while (TREE_CODE (element_type) == ARRAY_TYPE)
12946 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
12948 element_type = TREE_TYPE (element_type);
12951 #ifndef MIPS_DEBUGGING_INFO
12952 gen_type_die (element_type, context_die);
12955 add_type_attribute (array_die, element_type, 0, 0, context_die);
12957 if (get_AT (array_die, DW_AT_name))
12958 add_pubtype (type, array_die);
12961 static dw_loc_descr_ref
12962 descr_info_loc (tree val, tree base_decl)
12964 HOST_WIDE_INT size;
12965 dw_loc_descr_ref loc, loc2;
12966 enum dwarf_location_atom op;
12968 if (val == base_decl)
12969 return new_loc_descr (DW_OP_push_object_address, 0, 0);
12971 switch (TREE_CODE (val))
12974 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12976 return loc_descriptor_from_tree_1 (val, 0);
12978 if (host_integerp (val, 0))
12979 return int_loc_descriptor (tree_low_cst (val, 0));
12982 size = int_size_in_bytes (TREE_TYPE (val));
12985 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12988 if (size == DWARF2_ADDR_SIZE)
12989 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
12991 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
12993 case POINTER_PLUS_EXPR:
12995 if (host_integerp (TREE_OPERAND (val, 1), 1)
12996 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
12999 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13002 add_loc_descr (&loc,
13003 new_loc_descr (DW_OP_plus_uconst,
13004 tree_low_cst (TREE_OPERAND (val, 1),
13011 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13014 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13017 add_loc_descr (&loc, loc2);
13018 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13040 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13041 tree val, tree base_decl)
13043 dw_loc_descr_ref loc;
13045 if (host_integerp (val, 0))
13047 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13051 loc = descr_info_loc (val, base_decl);
13055 add_AT_loc (die, attr, loc);
13058 /* This routine generates DIE for array with hidden descriptor, details
13059 are filled into *info by a langhook. */
13062 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13063 dw_die_ref context_die)
13065 dw_die_ref scope_die = scope_die_for (type, context_die);
13066 dw_die_ref array_die;
13069 array_die = new_die (DW_TAG_array_type, scope_die, type);
13070 add_name_attribute (array_die, type_tag (type));
13071 equate_type_number_to_die (type, array_die);
13073 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13075 && info->ndimensions >= 2)
13076 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13078 if (info->data_location)
13079 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13081 if (info->associated)
13082 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13084 if (info->allocated)
13085 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13088 for (dim = 0; dim < info->ndimensions; dim++)
13090 dw_die_ref subrange_die
13091 = new_die (DW_TAG_subrange_type, array_die, NULL);
13093 if (info->dimen[dim].lower_bound)
13095 /* If it is the default value, omit it. */
13096 if ((is_c_family () || is_java ())
13097 && integer_zerop (info->dimen[dim].lower_bound))
13099 else if (is_fortran ()
13100 && integer_onep (info->dimen[dim].lower_bound))
13103 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13104 info->dimen[dim].lower_bound,
13107 if (info->dimen[dim].upper_bound)
13108 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13109 info->dimen[dim].upper_bound,
13111 if (info->dimen[dim].stride)
13112 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13113 info->dimen[dim].stride,
13117 gen_type_die (info->element_type, context_die);
13118 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13120 if (get_AT (array_die, DW_AT_name))
13121 add_pubtype (type, array_die);
13126 gen_entry_point_die (tree decl, dw_die_ref context_die)
13128 tree origin = decl_ultimate_origin (decl);
13129 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13131 if (origin != NULL)
13132 add_abstract_origin_attribute (decl_die, origin);
13135 add_name_and_src_coords_attributes (decl_die, decl);
13136 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13137 0, 0, context_die);
13140 if (DECL_ABSTRACT (decl))
13141 equate_decl_number_to_die (decl, decl_die);
13143 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13147 /* Walk through the list of incomplete types again, trying once more to
13148 emit full debugging info for them. */
13151 retry_incomplete_types (void)
13155 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13156 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13159 /* Determine what tag to use for a record type. */
13161 static enum dwarf_tag
13162 record_type_tag (tree type)
13164 if (! lang_hooks.types.classify_record)
13165 return DW_TAG_structure_type;
13167 switch (lang_hooks.types.classify_record (type))
13169 case RECORD_IS_STRUCT:
13170 return DW_TAG_structure_type;
13172 case RECORD_IS_CLASS:
13173 return DW_TAG_class_type;
13175 case RECORD_IS_INTERFACE:
13176 return DW_TAG_interface_type;
13179 gcc_unreachable ();
13183 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13184 include all of the information about the enumeration values also. Each
13185 enumerated type name/value is listed as a child of the enumerated type
13189 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13191 dw_die_ref type_die = lookup_type_die (type);
13193 if (type_die == NULL)
13195 type_die = new_die (DW_TAG_enumeration_type,
13196 scope_die_for (type, context_die), type);
13197 equate_type_number_to_die (type, type_die);
13198 add_name_attribute (type_die, type_tag (type));
13200 else if (! TYPE_SIZE (type))
13203 remove_AT (type_die, DW_AT_declaration);
13205 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13206 given enum type is incomplete, do not generate the DW_AT_byte_size
13207 attribute or the DW_AT_element_list attribute. */
13208 if (TYPE_SIZE (type))
13212 TREE_ASM_WRITTEN (type) = 1;
13213 add_byte_size_attribute (type_die, type);
13214 if (TYPE_STUB_DECL (type) != NULL_TREE)
13215 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13217 /* If the first reference to this type was as the return type of an
13218 inline function, then it may not have a parent. Fix this now. */
13219 if (type_die->die_parent == NULL)
13220 add_child_die (scope_die_for (type, context_die), type_die);
13222 for (link = TYPE_VALUES (type);
13223 link != NULL; link = TREE_CHAIN (link))
13225 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13226 tree value = TREE_VALUE (link);
13228 add_name_attribute (enum_die,
13229 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
13231 if (TREE_CODE (value) == CONST_DECL)
13232 value = DECL_INITIAL (value);
13234 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
13235 /* DWARF2 does not provide a way of indicating whether or
13236 not enumeration constants are signed or unsigned. GDB
13237 always assumes the values are signed, so we output all
13238 values as if they were signed. That means that
13239 enumeration constants with very large unsigned values
13240 will appear to have negative values in the debugger. */
13241 add_AT_int (enum_die, DW_AT_const_value,
13242 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
13246 add_AT_flag (type_die, DW_AT_declaration, 1);
13248 if (get_AT (type_die, DW_AT_name))
13249 add_pubtype (type, type_die);
13254 /* Generate a DIE to represent either a real live formal parameter decl or to
13255 represent just the type of some formal parameter position in some function
13258 Note that this routine is a bit unusual because its argument may be a
13259 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13260 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13261 node. If it's the former then this function is being called to output a
13262 DIE to represent a formal parameter object (or some inlining thereof). If
13263 it's the latter, then this function is only being called to output a
13264 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13265 argument type of some subprogram type. */
13268 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
13270 tree node_or_origin = node ? node : origin;
13271 dw_die_ref parm_die
13272 = new_die (DW_TAG_formal_parameter, context_die, node);
13274 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
13276 case tcc_declaration:
13278 origin = decl_ultimate_origin (node);
13279 if (origin != NULL)
13280 add_abstract_origin_attribute (parm_die, origin);
13283 tree type = TREE_TYPE (node);
13284 add_name_and_src_coords_attributes (parm_die, node);
13285 if (DECL_BY_REFERENCE (node))
13286 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13289 add_type_attribute (parm_die, type,
13290 TREE_READONLY (node),
13291 TREE_THIS_VOLATILE (node),
13293 if (DECL_ARTIFICIAL (node))
13294 add_AT_flag (parm_die, DW_AT_artificial, 1);
13298 equate_decl_number_to_die (node, parm_die);
13299 if (! DECL_ABSTRACT (node_or_origin))
13300 add_location_or_const_value_attribute (parm_die, node_or_origin,
13306 /* We were called with some kind of a ..._TYPE node. */
13307 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
13311 gcc_unreachable ();
13317 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13318 at the end of an (ANSI prototyped) formal parameters list. */
13321 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13323 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13326 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13327 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13328 parameters as specified in some function type specification (except for
13329 those which appear as part of a function *definition*). */
13332 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13335 tree formal_type = NULL;
13336 tree first_parm_type;
13339 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13341 arg = DECL_ARGUMENTS (function_or_method_type);
13342 function_or_method_type = TREE_TYPE (function_or_method_type);
13347 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13349 /* Make our first pass over the list of formal parameter types and output a
13350 DW_TAG_formal_parameter DIE for each one. */
13351 for (link = first_parm_type; link; )
13353 dw_die_ref parm_die;
13355 formal_type = TREE_VALUE (link);
13356 if (formal_type == void_type_node)
13359 /* Output a (nameless) DIE to represent the formal parameter itself. */
13360 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
13361 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13362 && link == first_parm_type)
13363 || (arg && DECL_ARTIFICIAL (arg)))
13364 add_AT_flag (parm_die, DW_AT_artificial, 1);
13366 link = TREE_CHAIN (link);
13368 arg = TREE_CHAIN (arg);
13371 /* If this function type has an ellipsis, add a
13372 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13373 if (formal_type != void_type_node)
13374 gen_unspecified_parameters_die (function_or_method_type, context_die);
13376 /* Make our second (and final) pass over the list of formal parameter types
13377 and output DIEs to represent those types (as necessary). */
13378 for (link = TYPE_ARG_TYPES (function_or_method_type);
13379 link && TREE_VALUE (link);
13380 link = TREE_CHAIN (link))
13381 gen_type_die (TREE_VALUE (link), context_die);
13384 /* We want to generate the DIE for TYPE so that we can generate the
13385 die for MEMBER, which has been defined; we will need to refer back
13386 to the member declaration nested within TYPE. If we're trying to
13387 generate minimal debug info for TYPE, processing TYPE won't do the
13388 trick; we need to attach the member declaration by hand. */
13391 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13393 gen_type_die (type, context_die);
13395 /* If we're trying to avoid duplicate debug info, we may not have
13396 emitted the member decl for this function. Emit it now. */
13397 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13398 && ! lookup_decl_die (member))
13400 dw_die_ref type_die;
13401 gcc_assert (!decl_ultimate_origin (member));
13403 push_decl_scope (type);
13404 type_die = lookup_type_die (type);
13405 if (TREE_CODE (member) == FUNCTION_DECL)
13406 gen_subprogram_die (member, type_die);
13407 else if (TREE_CODE (member) == FIELD_DECL)
13409 /* Ignore the nameless fields that are used to skip bits but handle
13410 C++ anonymous unions and structs. */
13411 if (DECL_NAME (member) != NULL_TREE
13412 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13413 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13415 gen_type_die (member_declared_type (member), type_die);
13416 gen_field_die (member, type_die);
13420 gen_variable_die (member, NULL_TREE, type_die);
13426 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13427 may later generate inlined and/or out-of-line instances of. */
13430 dwarf2out_abstract_function (tree decl)
13432 dw_die_ref old_die;
13435 int was_abstract = DECL_ABSTRACT (decl);
13437 /* Make sure we have the actual abstract inline, not a clone. */
13438 decl = DECL_ORIGIN (decl);
13440 old_die = lookup_decl_die (decl);
13441 if (old_die && get_AT (old_die, DW_AT_inline))
13442 /* We've already generated the abstract instance. */
13445 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13446 we don't get confused by DECL_ABSTRACT. */
13447 if (debug_info_level > DINFO_LEVEL_TERSE)
13449 context = decl_class_context (decl);
13451 gen_type_die_for_member
13452 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13455 /* Pretend we've just finished compiling this function. */
13456 save_fn = current_function_decl;
13457 current_function_decl = decl;
13458 push_cfun (DECL_STRUCT_FUNCTION (decl));
13460 set_decl_abstract_flags (decl, 1);
13461 dwarf2out_decl (decl);
13462 if (! was_abstract)
13463 set_decl_abstract_flags (decl, 0);
13465 current_function_decl = save_fn;
13469 /* Helper function of premark_used_types() which gets called through
13470 htab_traverse_resize().
13472 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13473 marked as unused by prune_unused_types. */
13475 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13480 type = (tree) *slot;
13481 die = lookup_type_die (type);
13483 die->die_perennial_p = 1;
13487 /* Mark all members of used_types_hash as perennial. */
13489 premark_used_types (void)
13491 if (cfun && cfun->used_types_hash)
13492 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13495 /* Generate a DIE to represent a declared function (either file-scope or
13499 gen_subprogram_die (tree decl, dw_die_ref context_die)
13501 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13502 tree origin = decl_ultimate_origin (decl);
13503 dw_die_ref subr_die;
13506 dw_die_ref old_die = lookup_decl_die (decl);
13507 int declaration = (current_function_decl != decl
13508 || class_or_namespace_scope_p (context_die));
13510 premark_used_types ();
13512 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13513 started to generate the abstract instance of an inline, decided to output
13514 its containing class, and proceeded to emit the declaration of the inline
13515 from the member list for the class. If so, DECLARATION takes priority;
13516 we'll get back to the abstract instance when done with the class. */
13518 /* The class-scope declaration DIE must be the primary DIE. */
13519 if (origin && declaration && class_or_namespace_scope_p (context_die))
13522 gcc_assert (!old_die);
13525 /* Now that the C++ front end lazily declares artificial member fns, we
13526 might need to retrofit the declaration into its class. */
13527 if (!declaration && !origin && !old_die
13528 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13529 && !class_or_namespace_scope_p (context_die)
13530 && debug_info_level > DINFO_LEVEL_TERSE)
13531 old_die = force_decl_die (decl);
13533 if (origin != NULL)
13535 gcc_assert (!declaration || local_scope_p (context_die));
13537 /* Fixup die_parent for the abstract instance of a nested
13538 inline function. */
13539 if (old_die && old_die->die_parent == NULL)
13540 add_child_die (context_die, old_die);
13542 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13543 add_abstract_origin_attribute (subr_die, origin);
13547 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13548 struct dwarf_file_data * file_index = lookup_filename (s.file);
13550 if (!get_AT_flag (old_die, DW_AT_declaration)
13551 /* We can have a normal definition following an inline one in the
13552 case of redefinition of GNU C extern inlines.
13553 It seems reasonable to use AT_specification in this case. */
13554 && !get_AT (old_die, DW_AT_inline))
13556 /* Detect and ignore this case, where we are trying to output
13557 something we have already output. */
13561 /* If the definition comes from the same place as the declaration,
13562 maybe use the old DIE. We always want the DIE for this function
13563 that has the *_pc attributes to be under comp_unit_die so the
13564 debugger can find it. We also need to do this for abstract
13565 instances of inlines, since the spec requires the out-of-line copy
13566 to have the same parent. For local class methods, this doesn't
13567 apply; we just use the old DIE. */
13568 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13569 && (DECL_ARTIFICIAL (decl)
13570 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13571 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13572 == (unsigned) s.line))))
13574 subr_die = old_die;
13576 /* Clear out the declaration attribute and the formal parameters.
13577 Do not remove all children, because it is possible that this
13578 declaration die was forced using force_decl_die(). In such
13579 cases die that forced declaration die (e.g. TAG_imported_module)
13580 is one of the children that we do not want to remove. */
13581 remove_AT (subr_die, DW_AT_declaration);
13582 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13586 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13587 add_AT_specification (subr_die, old_die);
13588 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13589 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13590 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13591 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13596 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13598 if (TREE_PUBLIC (decl))
13599 add_AT_flag (subr_die, DW_AT_external, 1);
13601 add_name_and_src_coords_attributes (subr_die, decl);
13602 if (debug_info_level > DINFO_LEVEL_TERSE)
13604 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13605 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13606 0, 0, context_die);
13609 add_pure_or_virtual_attribute (subr_die, decl);
13610 if (DECL_ARTIFICIAL (decl))
13611 add_AT_flag (subr_die, DW_AT_artificial, 1);
13613 if (TREE_PROTECTED (decl))
13614 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13615 else if (TREE_PRIVATE (decl))
13616 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13621 if (!old_die || !get_AT (old_die, DW_AT_inline))
13623 add_AT_flag (subr_die, DW_AT_declaration, 1);
13625 /* If this is an explicit function declaration then generate
13626 a DW_AT_explicit attribute. */
13627 if (lang_hooks.decls.function_decl_explicit_p (decl))
13628 add_AT_flag (subr_die, DW_AT_explicit, 1);
13630 /* The first time we see a member function, it is in the context of
13631 the class to which it belongs. We make sure of this by emitting
13632 the class first. The next time is the definition, which is
13633 handled above. The two may come from the same source text.
13635 Note that force_decl_die() forces function declaration die. It is
13636 later reused to represent definition. */
13637 equate_decl_number_to_die (decl, subr_die);
13640 else if (DECL_ABSTRACT (decl))
13642 if (DECL_DECLARED_INLINE_P (decl))
13644 if (cgraph_function_possibly_inlined_p (decl))
13645 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13647 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13651 if (cgraph_function_possibly_inlined_p (decl))
13652 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13654 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13657 if (DECL_DECLARED_INLINE_P (decl)
13658 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13659 add_AT_flag (subr_die, DW_AT_artificial, 1);
13661 equate_decl_number_to_die (decl, subr_die);
13663 else if (!DECL_EXTERNAL (decl))
13665 HOST_WIDE_INT cfa_fb_offset;
13667 if (!old_die || !get_AT (old_die, DW_AT_inline))
13668 equate_decl_number_to_die (decl, subr_die);
13670 if (!flag_reorder_blocks_and_partition)
13672 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13673 current_function_funcdef_no);
13674 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13675 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13676 current_function_funcdef_no);
13677 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13679 add_pubname (decl, subr_die);
13680 add_arange (decl, subr_die);
13683 { /* Do nothing for now; maybe need to duplicate die, one for
13684 hot section and one for cold section, then use the hot/cold
13685 section begin/end labels to generate the aranges... */
13687 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13688 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13689 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13690 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13692 add_pubname (decl, subr_die);
13693 add_arange (decl, subr_die);
13694 add_arange (decl, subr_die);
13698 #ifdef MIPS_DEBUGGING_INFO
13699 /* Add a reference to the FDE for this routine. */
13700 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13703 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13705 /* We define the "frame base" as the function's CFA. This is more
13706 convenient for several reasons: (1) It's stable across the prologue
13707 and epilogue, which makes it better than just a frame pointer,
13708 (2) With dwarf3, there exists a one-byte encoding that allows us
13709 to reference the .debug_frame data by proxy, but failing that,
13710 (3) We can at least reuse the code inspection and interpretation
13711 code that determines the CFA position at various points in the
13713 /* ??? Use some command-line or configury switch to enable the use
13714 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13715 consumers that understand it; fall back to "pure" dwarf2 and
13716 convert the CFA data into a location list. */
13718 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13719 if (list->dw_loc_next)
13720 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13722 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13725 /* Compute a displacement from the "steady-state frame pointer" to
13726 the CFA. The former is what all stack slots and argument slots
13727 will reference in the rtl; the later is what we've told the
13728 debugger about. We'll need to adjust all frame_base references
13729 by this displacement. */
13730 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13732 if (cfun->static_chain_decl)
13733 add_AT_location_description (subr_die, DW_AT_static_link,
13734 loc_descriptor_from_tree (cfun->static_chain_decl));
13737 /* Now output descriptions of the arguments for this function. This gets
13738 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13739 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13740 `...' at the end of the formal parameter list. In order to find out if
13741 there was a trailing ellipsis or not, we must instead look at the type
13742 associated with the FUNCTION_DECL. This will be a node of type
13743 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13744 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13745 an ellipsis at the end. */
13747 /* In the case where we are describing a mere function declaration, all we
13748 need to do here (and all we *can* do here) is to describe the *types* of
13749 its formal parameters. */
13750 if (debug_info_level <= DINFO_LEVEL_TERSE)
13752 else if (declaration)
13753 gen_formal_types_die (decl, subr_die);
13756 /* Generate DIEs to represent all known formal parameters. */
13757 tree arg_decls = DECL_ARGUMENTS (decl);
13760 /* When generating DIEs, generate the unspecified_parameters DIE
13761 instead if we come across the arg "__builtin_va_alist" */
13762 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13763 if (TREE_CODE (parm) == PARM_DECL)
13765 if (DECL_NAME (parm)
13766 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13767 "__builtin_va_alist"))
13768 gen_unspecified_parameters_die (parm, subr_die);
13770 gen_decl_die (parm, NULL, subr_die);
13773 /* Decide whether we need an unspecified_parameters DIE at the end.
13774 There are 2 more cases to do this for: 1) the ansi ... declaration -
13775 this is detectable when the end of the arg list is not a
13776 void_type_node 2) an unprototyped function declaration (not a
13777 definition). This just means that we have no info about the
13778 parameters at all. */
13779 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13780 if (fn_arg_types != NULL)
13782 /* This is the prototyped case, check for.... */
13783 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13784 gen_unspecified_parameters_die (decl, subr_die);
13786 else if (DECL_INITIAL (decl) == NULL_TREE)
13787 gen_unspecified_parameters_die (decl, subr_die);
13790 /* Output Dwarf info for all of the stuff within the body of the function
13791 (if it has one - it may be just a declaration). */
13792 outer_scope = DECL_INITIAL (decl);
13794 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13795 a function. This BLOCK actually represents the outermost binding contour
13796 for the function, i.e. the contour in which the function's formal
13797 parameters and labels get declared. Curiously, it appears that the front
13798 end doesn't actually put the PARM_DECL nodes for the current function onto
13799 the BLOCK_VARS list for this outer scope, but are strung off of the
13800 DECL_ARGUMENTS list for the function instead.
13802 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13803 the LABEL_DECL nodes for the function however, and we output DWARF info
13804 for those in decls_for_scope. Just within the `outer_scope' there will be
13805 a BLOCK node representing the function's outermost pair of curly braces,
13806 and any blocks used for the base and member initializers of a C++
13807 constructor function. */
13808 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13810 /* Emit a DW_TAG_variable DIE for a named return value. */
13811 if (DECL_NAME (DECL_RESULT (decl)))
13812 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
13814 current_function_has_inlines = 0;
13815 decls_for_scope (outer_scope, subr_die, 0);
13817 #if 0 && defined (MIPS_DEBUGGING_INFO)
13818 if (current_function_has_inlines)
13820 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13821 if (! comp_unit_has_inlines)
13823 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13824 comp_unit_has_inlines = 1;
13829 /* Add the calling convention attribute if requested. */
13830 add_calling_convention_attribute (subr_die, decl);
13834 /* Returns a hash value for X (which really is a die_struct). */
13837 common_block_die_table_hash (const void *x)
13839 const_dw_die_ref d = (const_dw_die_ref) x;
13840 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
13843 /* Return nonzero if decl_id and die_parent of die_struct X is the same
13844 as decl_id and die_parent of die_struct Y. */
13847 common_block_die_table_eq (const void *x, const void *y)
13849 const_dw_die_ref d = (const_dw_die_ref) x;
13850 const_dw_die_ref e = (const_dw_die_ref) y;
13851 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
13854 /* Generate a DIE to represent a declared data object.
13855 Either DECL or ORIGIN must be non-null. */
13858 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
13862 tree decl_or_origin = decl ? decl : origin;
13863 dw_die_ref var_die;
13864 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
13865 dw_die_ref origin_die;
13866 int declaration = (DECL_EXTERNAL (decl_or_origin)
13867 /* If DECL is COMDAT and has not actually been
13868 emitted, we cannot take its address; there
13869 might end up being no definition anywhere in
13870 the program. For example, consider the C++
13874 struct S { static const int i = 7; };
13879 int f() { return S<int>::i; }
13881 Here, S<int>::i is not DECL_EXTERNAL, but no
13882 definition is required, so the compiler will
13883 not emit a definition. */
13884 || (TREE_CODE (decl_or_origin) == VAR_DECL
13885 && DECL_COMDAT (decl_or_origin)
13886 && !TREE_ASM_WRITTEN (decl_or_origin))
13887 || class_or_namespace_scope_p (context_die));
13890 origin = decl_ultimate_origin (decl);
13892 com_decl = fortran_common (decl_or_origin, &off);
13894 /* Symbol in common gets emitted as a child of the common block, in the form
13895 of a data member. */
13899 dw_die_ref com_die;
13900 dw_loc_descr_ref loc;
13901 die_node com_die_arg;
13903 var_die = lookup_decl_die (decl_or_origin);
13906 if (get_AT (var_die, DW_AT_location) == NULL)
13908 loc = loc_descriptor_from_tree (com_decl);
13913 /* Optimize the common case. */
13914 if (loc->dw_loc_opc == DW_OP_addr
13915 && loc->dw_loc_next == NULL
13916 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
13918 loc->dw_loc_oprnd1.v.val_addr
13919 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
13921 add_loc_descr (&loc,
13922 new_loc_descr (DW_OP_plus_uconst,
13925 add_AT_loc (var_die, DW_AT_location, loc);
13926 remove_AT (var_die, DW_AT_declaration);
13932 if (common_block_die_table == NULL)
13933 common_block_die_table
13934 = htab_create_ggc (10, common_block_die_table_hash,
13935 common_block_die_table_eq, NULL);
13937 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
13938 com_die_arg.decl_id = DECL_UID (com_decl);
13939 com_die_arg.die_parent = context_die;
13940 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
13941 loc = loc_descriptor_from_tree (com_decl);
13942 if (com_die == NULL)
13945 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
13948 com_die = new_die (DW_TAG_common_block, context_die, decl);
13949 add_name_and_src_coords_attributes (com_die, com_decl);
13952 add_AT_loc (com_die, DW_AT_location, loc);
13953 /* Avoid sharing the same loc descriptor between
13954 DW_TAG_common_block and DW_TAG_variable. */
13955 loc = loc_descriptor_from_tree (com_decl);
13957 else if (DECL_EXTERNAL (decl))
13958 add_AT_flag (com_die, DW_AT_declaration, 1);
13959 add_pubname_string (cnam, com_die); /* ??? needed? */
13960 com_die->decl_id = DECL_UID (com_decl);
13961 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
13962 *slot = (void *) com_die;
13964 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
13966 add_AT_loc (com_die, DW_AT_location, loc);
13967 loc = loc_descriptor_from_tree (com_decl);
13968 remove_AT (com_die, DW_AT_declaration);
13970 var_die = new_die (DW_TAG_variable, com_die, decl);
13971 add_name_and_src_coords_attributes (var_die, decl);
13972 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
13973 TREE_THIS_VOLATILE (decl), context_die);
13974 add_AT_flag (var_die, DW_AT_external, 1);
13979 /* Optimize the common case. */
13980 if (loc->dw_loc_opc == DW_OP_addr
13981 && loc->dw_loc_next == NULL
13982 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
13983 loc->dw_loc_oprnd1.v.val_addr
13984 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
13986 add_loc_descr (&loc, new_loc_descr (DW_OP_plus_uconst,
13989 add_AT_loc (var_die, DW_AT_location, loc);
13991 else if (DECL_EXTERNAL (decl))
13992 add_AT_flag (var_die, DW_AT_declaration, 1);
13993 equate_decl_number_to_die (decl, var_die);
13997 /* If the compiler emitted a definition for the DECL declaration
13998 and if we already emitted a DIE for it, don't emit a second
13999 DIE for it again. */
14002 && old_die->die_parent == context_die)
14005 /* For static data members, the declaration in the class is supposed
14006 to have DW_TAG_member tag; the specification should still be
14007 DW_TAG_variable referencing the DW_TAG_member DIE. */
14008 if (declaration && class_scope_p (context_die))
14009 var_die = new_die (DW_TAG_member, context_die, decl);
14011 var_die = new_die (DW_TAG_variable, context_die, decl);
14014 if (origin != NULL)
14015 origin_die = add_abstract_origin_attribute (var_die, origin);
14017 /* Loop unrolling can create multiple blocks that refer to the same
14018 static variable, so we must test for the DW_AT_declaration flag.
14020 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14021 copy decls and set the DECL_ABSTRACT flag on them instead of
14024 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14026 ??? The declare_in_namespace support causes us to get two DIEs for one
14027 variable, both of which are declarations. We want to avoid considering
14028 one to be a specification, so we must test that this DIE is not a
14030 else if (old_die && TREE_STATIC (decl) && ! declaration
14031 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14033 /* This is a definition of a C++ class level static. */
14034 add_AT_specification (var_die, old_die);
14035 if (DECL_NAME (decl))
14037 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14038 struct dwarf_file_data * file_index = lookup_filename (s.file);
14040 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14041 add_AT_file (var_die, DW_AT_decl_file, file_index);
14043 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14044 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14049 tree type = TREE_TYPE (decl);
14051 add_name_and_src_coords_attributes (var_die, decl);
14052 if ((TREE_CODE (decl) == PARM_DECL
14053 || TREE_CODE (decl) == RESULT_DECL)
14054 && DECL_BY_REFERENCE (decl))
14055 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14057 add_type_attribute (var_die, type, TREE_READONLY (decl),
14058 TREE_THIS_VOLATILE (decl), context_die);
14060 if (TREE_PUBLIC (decl))
14061 add_AT_flag (var_die, DW_AT_external, 1);
14063 if (DECL_ARTIFICIAL (decl))
14064 add_AT_flag (var_die, DW_AT_artificial, 1);
14066 if (TREE_PROTECTED (decl))
14067 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14068 else if (TREE_PRIVATE (decl))
14069 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14073 add_AT_flag (var_die, DW_AT_declaration, 1);
14075 if (decl && (DECL_ABSTRACT (decl) || declaration))
14076 equate_decl_number_to_die (decl, var_die);
14079 && (! DECL_ABSTRACT (decl_or_origin)
14080 /* Local static vars are shared between all clones/inlines,
14081 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14083 || (TREE_CODE (decl_or_origin) == VAR_DECL
14084 && TREE_STATIC (decl_or_origin)
14085 && DECL_RTL_SET_P (decl_or_origin)))
14086 /* When abstract origin already has DW_AT_location attribute, no need
14087 to add it again. */
14088 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14090 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14091 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14092 defer_location (decl_or_origin, var_die);
14094 add_location_or_const_value_attribute (var_die,
14097 add_pubname (decl_or_origin, var_die);
14100 tree_add_const_value_attribute (var_die, decl_or_origin);
14103 /* Generate a DIE to represent a named constant. */
14106 gen_const_die (tree decl, dw_die_ref context_die)
14108 dw_die_ref const_die;
14109 tree type = TREE_TYPE (decl);
14111 const_die = new_die (DW_TAG_constant, context_die, decl);
14112 add_name_and_src_coords_attributes (const_die, decl);
14113 add_type_attribute (const_die, type, 1, 0, context_die);
14114 if (TREE_PUBLIC (decl))
14115 add_AT_flag (const_die, DW_AT_external, 1);
14116 if (DECL_ARTIFICIAL (decl))
14117 add_AT_flag (const_die, DW_AT_artificial, 1);
14118 tree_add_const_value_attribute (const_die, decl);
14121 /* Generate a DIE to represent a label identifier. */
14124 gen_label_die (tree decl, dw_die_ref context_die)
14126 tree origin = decl_ultimate_origin (decl);
14127 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14129 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14131 if (origin != NULL)
14132 add_abstract_origin_attribute (lbl_die, origin);
14134 add_name_and_src_coords_attributes (lbl_die, decl);
14136 if (DECL_ABSTRACT (decl))
14137 equate_decl_number_to_die (decl, lbl_die);
14140 insn = DECL_RTL_IF_SET (decl);
14142 /* Deleted labels are programmer specified labels which have been
14143 eliminated because of various optimizations. We still emit them
14144 here so that it is possible to put breakpoints on them. */
14148 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14150 /* When optimization is enabled (via -O) some parts of the compiler
14151 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14152 represent source-level labels which were explicitly declared by
14153 the user. This really shouldn't be happening though, so catch
14154 it if it ever does happen. */
14155 gcc_assert (!INSN_DELETED_P (insn));
14157 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14158 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14163 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14164 attributes to the DIE for a block STMT, to describe where the inlined
14165 function was called from. This is similar to add_src_coords_attributes. */
14168 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14170 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14172 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14173 add_AT_unsigned (die, DW_AT_call_line, s.line);
14177 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14178 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14181 add_high_low_attributes (tree stmt, dw_die_ref die)
14183 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14185 if (BLOCK_FRAGMENT_CHAIN (stmt))
14189 if (inlined_function_outer_scope_p (stmt))
14191 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14192 BLOCK_NUMBER (stmt));
14193 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14196 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14198 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14201 add_ranges (chain);
14202 chain = BLOCK_FRAGMENT_CHAIN (chain);
14209 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14210 BLOCK_NUMBER (stmt));
14211 add_AT_lbl_id (die, DW_AT_low_pc, label);
14212 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14213 BLOCK_NUMBER (stmt));
14214 add_AT_lbl_id (die, DW_AT_high_pc, label);
14218 /* Generate a DIE for a lexical block. */
14221 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14223 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14225 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14226 add_high_low_attributes (stmt, stmt_die);
14228 decls_for_scope (stmt, stmt_die, depth);
14231 /* Generate a DIE for an inlined subprogram. */
14234 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
14236 tree decl = block_ultimate_origin (stmt);
14238 /* Emit info for the abstract instance first, if we haven't yet. We
14239 must emit this even if the block is abstract, otherwise when we
14240 emit the block below (or elsewhere), we may end up trying to emit
14241 a die whose origin die hasn't been emitted, and crashing. */
14242 dwarf2out_abstract_function (decl);
14244 if (! BLOCK_ABSTRACT (stmt))
14246 dw_die_ref subr_die
14247 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
14249 add_abstract_origin_attribute (subr_die, decl);
14250 if (TREE_ASM_WRITTEN (stmt))
14251 add_high_low_attributes (stmt, subr_die);
14252 add_call_src_coords_attributes (stmt, subr_die);
14254 decls_for_scope (stmt, subr_die, depth);
14255 current_function_has_inlines = 1;
14258 /* We may get here if we're the outer block of function A that was
14259 inlined into function B that was inlined into function C. When
14260 generating debugging info for C, dwarf2out_abstract_function(B)
14261 would mark all inlined blocks as abstract, including this one.
14262 So, we wouldn't (and shouldn't) expect labels to be generated
14263 for this one. Instead, just emit debugging info for
14264 declarations within the block. This is particularly important
14265 in the case of initializers of arguments passed from B to us:
14266 if they're statement expressions containing declarations, we
14267 wouldn't generate dies for their abstract variables, and then,
14268 when generating dies for the real variables, we'd die (pun
14270 gen_lexical_block_die (stmt, context_die, depth);
14273 /* Generate a DIE for a field in a record, or structure. */
14276 gen_field_die (tree decl, dw_die_ref context_die)
14278 dw_die_ref decl_die;
14280 if (TREE_TYPE (decl) == error_mark_node)
14283 decl_die = new_die (DW_TAG_member, context_die, decl);
14284 add_name_and_src_coords_attributes (decl_die, decl);
14285 add_type_attribute (decl_die, member_declared_type (decl),
14286 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
14289 if (DECL_BIT_FIELD_TYPE (decl))
14291 add_byte_size_attribute (decl_die, decl);
14292 add_bit_size_attribute (decl_die, decl);
14293 add_bit_offset_attribute (decl_die, decl);
14296 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
14297 add_data_member_location_attribute (decl_die, decl);
14299 if (DECL_ARTIFICIAL (decl))
14300 add_AT_flag (decl_die, DW_AT_artificial, 1);
14302 if (TREE_PROTECTED (decl))
14303 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
14304 else if (TREE_PRIVATE (decl))
14305 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
14307 /* Equate decl number to die, so that we can look up this decl later on. */
14308 equate_decl_number_to_die (decl, decl_die);
14312 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14313 Use modified_type_die instead.
14314 We keep this code here just in case these types of DIEs may be needed to
14315 represent certain things in other languages (e.g. Pascal) someday. */
14318 gen_pointer_type_die (tree type, dw_die_ref context_die)
14321 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
14323 equate_type_number_to_die (type, ptr_die);
14324 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14325 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14328 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14329 Use modified_type_die instead.
14330 We keep this code here just in case these types of DIEs may be needed to
14331 represent certain things in other languages (e.g. Pascal) someday. */
14334 gen_reference_type_die (tree type, dw_die_ref context_die)
14337 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
14339 equate_type_number_to_die (type, ref_die);
14340 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
14341 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14345 /* Generate a DIE for a pointer to a member type. */
14348 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14351 = new_die (DW_TAG_ptr_to_member_type,
14352 scope_die_for (type, context_die), type);
14354 equate_type_number_to_die (type, ptr_die);
14355 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14356 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14357 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14360 /* Generate the DIE for the compilation unit. */
14363 gen_compile_unit_die (const char *filename)
14366 char producer[250];
14367 const char *language_string = lang_hooks.name;
14370 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14374 add_name_attribute (die, filename);
14375 /* Don't add cwd for <built-in>. */
14376 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14377 add_comp_dir_attribute (die);
14380 sprintf (producer, "%s %s", language_string, version_string);
14382 #ifdef MIPS_DEBUGGING_INFO
14383 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14384 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14385 not appear in the producer string, the debugger reaches the conclusion
14386 that the object file is stripped and has no debugging information.
14387 To get the MIPS/SGI debugger to believe that there is debugging
14388 information in the object file, we add a -g to the producer string. */
14389 if (debug_info_level > DINFO_LEVEL_TERSE)
14390 strcat (producer, " -g");
14393 add_AT_string (die, DW_AT_producer, producer);
14395 if (strcmp (language_string, "GNU C++") == 0)
14396 language = DW_LANG_C_plus_plus;
14397 else if (strcmp (language_string, "GNU Ada") == 0)
14398 language = DW_LANG_Ada95;
14399 else if (strcmp (language_string, "GNU F77") == 0)
14400 language = DW_LANG_Fortran77;
14401 else if (strcmp (language_string, "GNU Fortran") == 0)
14402 language = DW_LANG_Fortran95;
14403 else if (strcmp (language_string, "GNU Pascal") == 0)
14404 language = DW_LANG_Pascal83;
14405 else if (strcmp (language_string, "GNU Java") == 0)
14406 language = DW_LANG_Java;
14407 else if (strcmp (language_string, "GNU Objective-C") == 0)
14408 language = DW_LANG_ObjC;
14409 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14410 language = DW_LANG_ObjC_plus_plus;
14412 language = DW_LANG_C89;
14414 add_AT_unsigned (die, DW_AT_language, language);
14418 /* Generate the DIE for a base class. */
14421 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14423 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14425 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14426 add_data_member_location_attribute (die, binfo);
14428 if (BINFO_VIRTUAL_P (binfo))
14429 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14431 if (access == access_public_node)
14432 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14433 else if (access == access_protected_node)
14434 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14437 /* Generate a DIE for a class member. */
14440 gen_member_die (tree type, dw_die_ref context_die)
14443 tree binfo = TYPE_BINFO (type);
14446 /* If this is not an incomplete type, output descriptions of each of its
14447 members. Note that as we output the DIEs necessary to represent the
14448 members of this record or union type, we will also be trying to output
14449 DIEs to represent the *types* of those members. However the `type'
14450 function (above) will specifically avoid generating type DIEs for member
14451 types *within* the list of member DIEs for this (containing) type except
14452 for those types (of members) which are explicitly marked as also being
14453 members of this (containing) type themselves. The g++ front- end can
14454 force any given type to be treated as a member of some other (containing)
14455 type by setting the TYPE_CONTEXT of the given (member) type to point to
14456 the TREE node representing the appropriate (containing) type. */
14458 /* First output info about the base classes. */
14461 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14465 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14466 gen_inheritance_die (base,
14467 (accesses ? VEC_index (tree, accesses, i)
14468 : access_public_node), context_die);
14471 /* Now output info about the data members and type members. */
14472 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14474 /* If we thought we were generating minimal debug info for TYPE
14475 and then changed our minds, some of the member declarations
14476 may have already been defined. Don't define them again, but
14477 do put them in the right order. */
14479 child = lookup_decl_die (member);
14481 splice_child_die (context_die, child);
14483 gen_decl_die (member, NULL, context_die);
14486 /* Now output info about the function members (if any). */
14487 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14489 /* Don't include clones in the member list. */
14490 if (DECL_ABSTRACT_ORIGIN (member))
14493 child = lookup_decl_die (member);
14495 splice_child_die (context_die, child);
14497 gen_decl_die (member, NULL, context_die);
14501 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14502 is set, we pretend that the type was never defined, so we only get the
14503 member DIEs needed by later specification DIEs. */
14506 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14507 enum debug_info_usage usage)
14509 dw_die_ref type_die = lookup_type_die (type);
14510 dw_die_ref scope_die = 0;
14512 int complete = (TYPE_SIZE (type)
14513 && (! TYPE_STUB_DECL (type)
14514 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14515 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14516 complete = complete && should_emit_struct_debug (type, usage);
14518 if (type_die && ! complete)
14521 if (TYPE_CONTEXT (type) != NULL_TREE
14522 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14523 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14526 scope_die = scope_die_for (type, context_die);
14528 if (! type_die || (nested && scope_die == comp_unit_die))
14529 /* First occurrence of type or toplevel definition of nested class. */
14531 dw_die_ref old_die = type_die;
14533 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14534 ? record_type_tag (type) : DW_TAG_union_type,
14536 equate_type_number_to_die (type, type_die);
14538 add_AT_specification (type_die, old_die);
14540 add_name_attribute (type_die, type_tag (type));
14543 remove_AT (type_die, DW_AT_declaration);
14545 /* If this type has been completed, then give it a byte_size attribute and
14546 then give a list of members. */
14547 if (complete && !ns_decl)
14549 /* Prevent infinite recursion in cases where the type of some member of
14550 this type is expressed in terms of this type itself. */
14551 TREE_ASM_WRITTEN (type) = 1;
14552 add_byte_size_attribute (type_die, type);
14553 if (TYPE_STUB_DECL (type) != NULL_TREE)
14554 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14556 /* If the first reference to this type was as the return type of an
14557 inline function, then it may not have a parent. Fix this now. */
14558 if (type_die->die_parent == NULL)
14559 add_child_die (scope_die, type_die);
14561 push_decl_scope (type);
14562 gen_member_die (type, type_die);
14565 /* GNU extension: Record what type our vtable lives in. */
14566 if (TYPE_VFIELD (type))
14568 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14570 gen_type_die (vtype, context_die);
14571 add_AT_die_ref (type_die, DW_AT_containing_type,
14572 lookup_type_die (vtype));
14577 add_AT_flag (type_die, DW_AT_declaration, 1);
14579 /* We don't need to do this for function-local types. */
14580 if (TYPE_STUB_DECL (type)
14581 && ! decl_function_context (TYPE_STUB_DECL (type)))
14582 VEC_safe_push (tree, gc, incomplete_types, type);
14585 if (get_AT (type_die, DW_AT_name))
14586 add_pubtype (type, type_die);
14589 /* Generate a DIE for a subroutine _type_. */
14592 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14594 tree return_type = TREE_TYPE (type);
14595 dw_die_ref subr_die
14596 = new_die (DW_TAG_subroutine_type,
14597 scope_die_for (type, context_die), type);
14599 equate_type_number_to_die (type, subr_die);
14600 add_prototyped_attribute (subr_die, type);
14601 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14602 gen_formal_types_die (type, subr_die);
14604 if (get_AT (subr_die, DW_AT_name))
14605 add_pubtype (type, subr_die);
14608 /* Generate a DIE for a type definition. */
14611 gen_typedef_die (tree decl, dw_die_ref context_die)
14613 dw_die_ref type_die;
14616 if (TREE_ASM_WRITTEN (decl))
14619 TREE_ASM_WRITTEN (decl) = 1;
14620 type_die = new_die (DW_TAG_typedef, context_die, decl);
14621 origin = decl_ultimate_origin (decl);
14622 if (origin != NULL)
14623 add_abstract_origin_attribute (type_die, origin);
14628 add_name_and_src_coords_attributes (type_die, decl);
14629 if (DECL_ORIGINAL_TYPE (decl))
14631 type = DECL_ORIGINAL_TYPE (decl);
14633 gcc_assert (type != TREE_TYPE (decl));
14634 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14637 type = TREE_TYPE (decl);
14639 add_type_attribute (type_die, type, TREE_READONLY (decl),
14640 TREE_THIS_VOLATILE (decl), context_die);
14643 if (DECL_ABSTRACT (decl))
14644 equate_decl_number_to_die (decl, type_die);
14646 if (get_AT (type_die, DW_AT_name))
14647 add_pubtype (decl, type_die);
14650 /* Generate a type description DIE. */
14653 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14654 enum debug_info_usage usage)
14657 struct array_descr_info info;
14659 if (type == NULL_TREE || type == error_mark_node)
14662 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14663 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14665 if (TREE_ASM_WRITTEN (type))
14668 /* Prevent broken recursion; we can't hand off to the same type. */
14669 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14671 TREE_ASM_WRITTEN (type) = 1;
14672 gen_decl_die (TYPE_NAME (type), NULL, context_die);
14676 /* If this is an array type with hidden descriptor, handle it first. */
14677 if (!TREE_ASM_WRITTEN (type)
14678 && lang_hooks.types.get_array_descr_info
14679 && lang_hooks.types.get_array_descr_info (type, &info))
14681 gen_descr_array_type_die (type, &info, context_die);
14682 TREE_ASM_WRITTEN (type) = 1;
14686 /* We are going to output a DIE to represent the unqualified version
14687 of this type (i.e. without any const or volatile qualifiers) so
14688 get the main variant (i.e. the unqualified version) of this type
14689 now. (Vectors are special because the debugging info is in the
14690 cloned type itself). */
14691 if (TREE_CODE (type) != VECTOR_TYPE)
14692 type = type_main_variant (type);
14694 if (TREE_ASM_WRITTEN (type))
14697 switch (TREE_CODE (type))
14703 case REFERENCE_TYPE:
14704 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14705 ensures that the gen_type_die recursion will terminate even if the
14706 type is recursive. Recursive types are possible in Ada. */
14707 /* ??? We could perhaps do this for all types before the switch
14709 TREE_ASM_WRITTEN (type) = 1;
14711 /* For these types, all that is required is that we output a DIE (or a
14712 set of DIEs) to represent the "basis" type. */
14713 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14714 DINFO_USAGE_IND_USE);
14718 /* This code is used for C++ pointer-to-data-member types.
14719 Output a description of the relevant class type. */
14720 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
14721 DINFO_USAGE_IND_USE);
14723 /* Output a description of the type of the object pointed to. */
14724 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14725 DINFO_USAGE_IND_USE);
14727 /* Now output a DIE to represent this pointer-to-data-member type
14729 gen_ptr_to_mbr_type_die (type, context_die);
14732 case FUNCTION_TYPE:
14733 /* Force out return type (in case it wasn't forced out already). */
14734 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14735 DINFO_USAGE_DIR_USE);
14736 gen_subroutine_type_die (type, context_die);
14740 /* Force out return type (in case it wasn't forced out already). */
14741 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14742 DINFO_USAGE_DIR_USE);
14743 gen_subroutine_type_die (type, context_die);
14747 gen_array_type_die (type, context_die);
14751 gen_array_type_die (type, context_die);
14754 case ENUMERAL_TYPE:
14757 case QUAL_UNION_TYPE:
14758 /* If this is a nested type whose containing class hasn't been written
14759 out yet, writing it out will cover this one, too. This does not apply
14760 to instantiations of member class templates; they need to be added to
14761 the containing class as they are generated. FIXME: This hurts the
14762 idea of combining type decls from multiple TUs, since we can't predict
14763 what set of template instantiations we'll get. */
14764 if (TYPE_CONTEXT (type)
14765 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14766 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
14768 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
14770 if (TREE_ASM_WRITTEN (type))
14773 /* If that failed, attach ourselves to the stub. */
14774 push_decl_scope (TYPE_CONTEXT (type));
14775 context_die = lookup_type_die (TYPE_CONTEXT (type));
14780 context_die = declare_in_namespace (type, context_die);
14784 if (TREE_CODE (type) == ENUMERAL_TYPE)
14786 /* This might have been written out by the call to
14787 declare_in_namespace. */
14788 if (!TREE_ASM_WRITTEN (type))
14789 gen_enumeration_type_die (type, context_die);
14792 gen_struct_or_union_type_die (type, context_die, usage);
14797 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14798 it up if it is ever completed. gen_*_type_die will set it for us
14799 when appropriate. */
14805 case FIXED_POINT_TYPE:
14808 /* No DIEs needed for fundamental types. */
14812 /* No Dwarf representation currently defined. */
14816 gcc_unreachable ();
14819 TREE_ASM_WRITTEN (type) = 1;
14823 gen_type_die (tree type, dw_die_ref context_die)
14825 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14828 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14829 things which are local to the given block. */
14832 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14834 int must_output_die = 0;
14837 /* Ignore blocks that are NULL. */
14838 if (stmt == NULL_TREE)
14841 inlined_func = inlined_function_outer_scope_p (stmt);
14843 /* If the block is one fragment of a non-contiguous block, do not
14844 process the variables, since they will have been done by the
14845 origin block. Do process subblocks. */
14846 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14850 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14851 gen_block_die (sub, context_die, depth + 1);
14856 /* Determine if we need to output any Dwarf DIEs at all to represent this
14859 /* The outer scopes for inlinings *must* always be represented. We
14860 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14861 must_output_die = 1;
14864 /* Determine if this block directly contains any "significant"
14865 local declarations which we will need to output DIEs for. */
14866 if (debug_info_level > DINFO_LEVEL_TERSE)
14867 /* We are not in terse mode so *any* local declaration counts
14868 as being a "significant" one. */
14869 must_output_die = ((BLOCK_VARS (stmt) != NULL
14870 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
14871 && (TREE_USED (stmt)
14872 || TREE_ASM_WRITTEN (stmt)
14873 || BLOCK_ABSTRACT (stmt)));
14874 else if ((TREE_USED (stmt)
14875 || TREE_ASM_WRITTEN (stmt)
14876 || BLOCK_ABSTRACT (stmt))
14877 && !dwarf2out_ignore_block (stmt))
14878 must_output_die = 1;
14881 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14882 DIE for any block which contains no significant local declarations at
14883 all. Rather, in such cases we just call `decls_for_scope' so that any
14884 needed Dwarf info for any sub-blocks will get properly generated. Note
14885 that in terse mode, our definition of what constitutes a "significant"
14886 local declaration gets restricted to include only inlined function
14887 instances and local (nested) function definitions. */
14888 if (must_output_die)
14891 gen_inlined_subroutine_die (stmt, context_die, depth);
14893 gen_lexical_block_die (stmt, context_die, depth);
14896 decls_for_scope (stmt, context_die, depth);
14899 /* Process variable DECL (or variable with origin ORIGIN) within
14900 block STMT and add it to CONTEXT_DIE. */
14902 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
14905 tree decl_or_origin = decl ? decl : origin;
14906 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
14908 if (ultimate_origin)
14909 origin = ultimate_origin;
14911 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
14912 die = lookup_decl_die (decl_or_origin);
14913 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
14914 && TYPE_DECL_IS_STUB (decl_or_origin))
14915 die = lookup_type_die (TREE_TYPE (decl_or_origin));
14919 if (die != NULL && die->die_parent == NULL)
14920 add_child_die (context_die, die);
14921 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
14922 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
14923 stmt, context_die);
14925 gen_decl_die (decl, origin, context_die);
14928 /* Generate all of the decls declared within a given scope and (recursively)
14929 all of its sub-blocks. */
14932 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
14938 /* Ignore NULL blocks. */
14939 if (stmt == NULL_TREE)
14942 /* Output the DIEs to represent all of the data objects and typedefs
14943 declared directly within this block but not within any nested
14944 sub-blocks. Also, nested function and tag DIEs have been
14945 generated with a parent of NULL; fix that up now. */
14946 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
14947 process_scope_var (stmt, decl, NULL_TREE, context_die);
14948 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
14949 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
14952 /* If we're at -g1, we're not interested in subblocks. */
14953 if (debug_info_level <= DINFO_LEVEL_TERSE)
14956 /* Output the DIEs to represent all sub-blocks (and the items declared
14957 therein) of this block. */
14958 for (subblocks = BLOCK_SUBBLOCKS (stmt);
14960 subblocks = BLOCK_CHAIN (subblocks))
14961 gen_block_die (subblocks, context_die, depth + 1);
14964 /* Is this a typedef we can avoid emitting? */
14967 is_redundant_typedef (const_tree decl)
14969 if (TYPE_DECL_IS_STUB (decl))
14972 if (DECL_ARTIFICIAL (decl)
14973 && DECL_CONTEXT (decl)
14974 && is_tagged_type (DECL_CONTEXT (decl))
14975 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
14976 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
14977 /* Also ignore the artificial member typedef for the class name. */
14983 /* Returns the DIE for a context. */
14985 static inline dw_die_ref
14986 get_context_die (tree context)
14990 /* Find die that represents this context. */
14991 if (TYPE_P (context))
14992 return force_type_die (context);
14994 return force_decl_die (context);
14996 return comp_unit_die;
14999 /* Returns the DIE for decl. A DIE will always be returned. */
15002 force_decl_die (tree decl)
15004 dw_die_ref decl_die;
15005 unsigned saved_external_flag;
15006 tree save_fn = NULL_TREE;
15007 decl_die = lookup_decl_die (decl);
15010 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15012 decl_die = lookup_decl_die (decl);
15016 switch (TREE_CODE (decl))
15018 case FUNCTION_DECL:
15019 /* Clear current_function_decl, so that gen_subprogram_die thinks
15020 that this is a declaration. At this point, we just want to force
15021 declaration die. */
15022 save_fn = current_function_decl;
15023 current_function_decl = NULL_TREE;
15024 gen_subprogram_die (decl, context_die);
15025 current_function_decl = save_fn;
15029 /* Set external flag to force declaration die. Restore it after
15030 gen_decl_die() call. */
15031 saved_external_flag = DECL_EXTERNAL (decl);
15032 DECL_EXTERNAL (decl) = 1;
15033 gen_decl_die (decl, NULL, context_die);
15034 DECL_EXTERNAL (decl) = saved_external_flag;
15037 case NAMESPACE_DECL:
15038 dwarf2out_decl (decl);
15042 gcc_unreachable ();
15045 /* We should be able to find the DIE now. */
15047 decl_die = lookup_decl_die (decl);
15048 gcc_assert (decl_die);
15054 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15055 always returned. */
15058 force_type_die (tree type)
15060 dw_die_ref type_die;
15062 type_die = lookup_type_die (type);
15065 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15067 type_die = modified_type_die (type, TYPE_READONLY (type),
15068 TYPE_VOLATILE (type), context_die);
15069 gcc_assert (type_die);
15074 /* Force out any required namespaces to be able to output DECL,
15075 and return the new context_die for it, if it's changed. */
15078 setup_namespace_context (tree thing, dw_die_ref context_die)
15080 tree context = (DECL_P (thing)
15081 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15082 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15083 /* Force out the namespace. */
15084 context_die = force_decl_die (context);
15086 return context_die;
15089 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15090 type) within its namespace, if appropriate.
15092 For compatibility with older debuggers, namespace DIEs only contain
15093 declarations; all definitions are emitted at CU scope. */
15096 declare_in_namespace (tree thing, dw_die_ref context_die)
15098 dw_die_ref ns_context;
15100 if (debug_info_level <= DINFO_LEVEL_TERSE)
15101 return context_die;
15103 /* If this decl is from an inlined function, then don't try to emit it in its
15104 namespace, as we will get confused. It would have already been emitted
15105 when the abstract instance of the inline function was emitted anyways. */
15106 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15107 return context_die;
15109 ns_context = setup_namespace_context (thing, context_die);
15111 if (ns_context != context_die)
15115 if (DECL_P (thing))
15116 gen_decl_die (thing, NULL, ns_context);
15118 gen_type_die (thing, ns_context);
15120 return context_die;
15123 /* Generate a DIE for a namespace or namespace alias. */
15126 gen_namespace_die (tree decl, dw_die_ref context_die)
15128 dw_die_ref namespace_die;
15130 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15131 they are an alias of. */
15132 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15134 /* Output a real namespace or module. */
15135 context_die = setup_namespace_context (decl, comp_unit_die);
15136 namespace_die = new_die (is_fortran ()
15137 ? DW_TAG_module : DW_TAG_namespace,
15138 context_die, decl);
15139 /* For Fortran modules defined in different CU don't add src coords. */
15140 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15141 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15143 add_name_and_src_coords_attributes (namespace_die, decl);
15144 if (DECL_EXTERNAL (decl))
15145 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15146 equate_decl_number_to_die (decl, namespace_die);
15150 /* Output a namespace alias. */
15152 /* Force out the namespace we are an alias of, if necessary. */
15153 dw_die_ref origin_die
15154 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15156 if (DECL_CONTEXT (decl) == NULL_TREE
15157 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15158 context_die = setup_namespace_context (decl, comp_unit_die);
15159 /* Now create the namespace alias DIE. */
15160 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15161 add_name_and_src_coords_attributes (namespace_die, decl);
15162 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15163 equate_decl_number_to_die (decl, namespace_die);
15167 /* Generate Dwarf debug information for a decl described by DECL. */
15170 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15172 tree decl_or_origin = decl ? decl : origin;
15173 tree class_origin = NULL;
15175 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15178 switch (TREE_CODE (decl_or_origin))
15184 if (!is_fortran ())
15186 /* The individual enumerators of an enum type get output when we output
15187 the Dwarf representation of the relevant enum type itself. */
15191 /* Emit its type. */
15192 gen_type_die (TREE_TYPE (decl), context_die);
15194 /* And its containing namespace. */
15195 context_die = declare_in_namespace (decl, context_die);
15197 gen_const_die (decl, context_die);
15200 case FUNCTION_DECL:
15201 /* Don't output any DIEs to represent mere function declarations,
15202 unless they are class members or explicit block externs. */
15203 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15204 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15205 && (current_function_decl == NULL_TREE
15206 || DECL_ARTIFICIAL (decl_or_origin)))
15211 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15212 on local redeclarations of global functions. That seems broken. */
15213 if (current_function_decl != decl)
15214 /* This is only a declaration. */;
15217 /* If we're emitting a clone, emit info for the abstract instance. */
15218 if (origin || DECL_ORIGIN (decl) != decl)
15219 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
15221 /* If we're emitting an out-of-line copy of an inline function,
15222 emit info for the abstract instance and set up to refer to it. */
15223 else if (cgraph_function_possibly_inlined_p (decl)
15224 && ! DECL_ABSTRACT (decl)
15225 && ! class_or_namespace_scope_p (context_die)
15226 /* dwarf2out_abstract_function won't emit a die if this is just
15227 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15228 that case, because that works only if we have a die. */
15229 && DECL_INITIAL (decl) != NULL_TREE)
15231 dwarf2out_abstract_function (decl);
15232 set_decl_origin_self (decl);
15235 /* Otherwise we're emitting the primary DIE for this decl. */
15236 else if (debug_info_level > DINFO_LEVEL_TERSE)
15238 /* Before we describe the FUNCTION_DECL itself, make sure that we
15239 have described its return type. */
15240 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15242 /* And its virtual context. */
15243 if (DECL_VINDEX (decl) != NULL_TREE)
15244 gen_type_die (DECL_CONTEXT (decl), context_die);
15246 /* And its containing type. */
15248 origin = decl_class_context (decl);
15249 if (origin != NULL_TREE)
15250 gen_type_die_for_member (origin, decl, context_die);
15252 /* And its containing namespace. */
15253 context_die = declare_in_namespace (decl, context_die);
15256 /* Now output a DIE to represent the function itself. */
15258 gen_subprogram_die (decl, context_die);
15262 /* If we are in terse mode, don't generate any DIEs to represent any
15263 actual typedefs. */
15264 if (debug_info_level <= DINFO_LEVEL_TERSE)
15267 /* In the special case of a TYPE_DECL node representing the declaration
15268 of some type tag, if the given TYPE_DECL is marked as having been
15269 instantiated from some other (original) TYPE_DECL node (e.g. one which
15270 was generated within the original definition of an inline function) we
15271 used to generate a special (abbreviated) DW_TAG_structure_type,
15272 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15273 should be actually referencing those DIEs, as variable DIEs with that
15274 type would be emitted already in the abstract origin, so it was always
15275 removed during unused type prunning. Don't add anything in this
15277 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
15280 if (is_redundant_typedef (decl))
15281 gen_type_die (TREE_TYPE (decl), context_die);
15283 /* Output a DIE to represent the typedef itself. */
15284 gen_typedef_die (decl, context_die);
15288 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15289 gen_label_die (decl, context_die);
15294 /* If we are in terse mode, don't generate any DIEs to represent any
15295 variable declarations or definitions. */
15296 if (debug_info_level <= DINFO_LEVEL_TERSE)
15299 /* Output any DIEs that are needed to specify the type of this data
15301 if (TREE_CODE (decl_or_origin) == RESULT_DECL
15302 && DECL_BY_REFERENCE (decl_or_origin))
15303 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15305 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15307 /* And its containing type. */
15308 class_origin = decl_class_context (decl_or_origin);
15309 if (class_origin != NULL_TREE)
15310 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
15312 /* And its containing namespace. */
15313 context_die = declare_in_namespace (decl_or_origin, context_die);
15315 /* Now output the DIE to represent the data object itself. This gets
15316 complicated because of the possibility that the VAR_DECL really
15317 represents an inlined instance of a formal parameter for an inline
15320 origin = decl_ultimate_origin (decl);
15321 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15322 gen_formal_parameter_die (decl, origin, context_die);
15324 gen_variable_die (decl, origin, context_die);
15328 /* Ignore the nameless fields that are used to skip bits but handle C++
15329 anonymous unions and structs. */
15330 if (DECL_NAME (decl) != NULL_TREE
15331 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15332 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15334 gen_type_die (member_declared_type (decl), context_die);
15335 gen_field_die (decl, context_die);
15340 if (DECL_BY_REFERENCE (decl_or_origin))
15341 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15343 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15344 gen_formal_parameter_die (decl, origin, context_die);
15347 case NAMESPACE_DECL:
15348 case IMPORTED_DECL:
15349 gen_namespace_die (decl, context_die);
15353 /* Probably some frontend-internal decl. Assume we don't care. */
15354 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15359 /* Output debug information for global decl DECL. Called from toplev.c after
15360 compilation proper has finished. */
15363 dwarf2out_global_decl (tree decl)
15365 /* Output DWARF2 information for file-scope tentative data object
15366 declarations, file-scope (extern) function declarations (which
15367 had no corresponding body) and file-scope tagged type declarations
15368 and definitions which have not yet been forced out. */
15369 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15370 dwarf2out_decl (decl);
15373 /* Output debug information for type decl DECL. Called from toplev.c
15374 and from language front ends (to record built-in types). */
15376 dwarf2out_type_decl (tree decl, int local)
15379 dwarf2out_decl (decl);
15382 /* Output debug information for imported module or decl DECL.
15383 NAME is non-NULL name in the lexical block if the decl has been renamed.
15384 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15385 that DECL belongs to.
15386 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15388 dwarf2out_imported_module_or_decl_1 (tree decl,
15390 tree lexical_block,
15391 dw_die_ref lexical_block_die)
15393 expanded_location xloc;
15394 dw_die_ref imported_die = NULL;
15395 dw_die_ref at_import_die;
15397 if (TREE_CODE (decl) == IMPORTED_DECL)
15399 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
15400 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
15404 xloc = expand_location (input_location);
15406 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15408 if (is_base_type (TREE_TYPE (decl)))
15409 at_import_die = base_type_die (TREE_TYPE (decl));
15411 at_import_die = force_type_die (TREE_TYPE (decl));
15412 /* For namespace N { typedef void T; } using N::T; base_type_die
15413 returns NULL, but DW_TAG_imported_declaration requires
15414 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15415 if (!at_import_die)
15417 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15418 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15419 at_import_die = lookup_type_die (TREE_TYPE (decl));
15420 gcc_assert (at_import_die);
15425 at_import_die = lookup_decl_die (decl);
15426 if (!at_import_die)
15428 /* If we're trying to avoid duplicate debug info, we may not have
15429 emitted the member decl for this field. Emit it now. */
15430 if (TREE_CODE (decl) == FIELD_DECL)
15432 tree type = DECL_CONTEXT (decl);
15434 if (TYPE_CONTEXT (type)
15435 && TYPE_P (TYPE_CONTEXT (type))
15436 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15437 DINFO_USAGE_DIR_USE))
15439 gen_type_die_for_member (type, decl,
15440 get_context_die (TYPE_CONTEXT (type)));
15442 at_import_die = force_decl_die (decl);
15446 if (TREE_CODE (decl) == NAMESPACE_DECL)
15447 imported_die = new_die (DW_TAG_imported_module,
15451 imported_die = new_die (DW_TAG_imported_declaration,
15455 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15456 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15458 add_AT_string (imported_die, DW_AT_name,
15459 IDENTIFIER_POINTER (name));
15460 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15463 /* Output debug information for imported module or decl DECL.
15464 NAME is non-NULL name in context if the decl has been renamed.
15465 CHILD is true if decl is one of the renamed decls as part of
15466 importing whole module. */
15469 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15472 /* dw_die_ref at_import_die; */
15473 dw_die_ref scope_die;
15475 if (debug_info_level <= DINFO_LEVEL_TERSE)
15480 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15481 We need decl DIE for reference and scope die. First, get DIE for the decl
15484 /* Get the scope die for decl context. Use comp_unit_die for global module
15485 or decl. If die is not found for non globals, force new die. */
15487 && TYPE_P (context)
15488 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15490 scope_die = get_context_die (context);
15494 gcc_assert (scope_die->die_child);
15495 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15496 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15497 scope_die = scope_die->die_child;
15500 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15501 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
15505 /* Write the debugging output for DECL. */
15508 dwarf2out_decl (tree decl)
15510 dw_die_ref context_die = comp_unit_die;
15512 switch (TREE_CODE (decl))
15517 case FUNCTION_DECL:
15518 /* What we would really like to do here is to filter out all mere
15519 file-scope declarations of file-scope functions which are never
15520 referenced later within this translation unit (and keep all of ones
15521 that *are* referenced later on) but we aren't clairvoyant, so we have
15522 no idea which functions will be referenced in the future (i.e. later
15523 on within the current translation unit). So here we just ignore all
15524 file-scope function declarations which are not also definitions. If
15525 and when the debugger needs to know something about these functions,
15526 it will have to hunt around and find the DWARF information associated
15527 with the definition of the function.
15529 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15530 nodes represent definitions and which ones represent mere
15531 declarations. We have to check DECL_INITIAL instead. That's because
15532 the C front-end supports some weird semantics for "extern inline"
15533 function definitions. These can get inlined within the current
15534 translation unit (and thus, we need to generate Dwarf info for their
15535 abstract instances so that the Dwarf info for the concrete inlined
15536 instances can have something to refer to) but the compiler never
15537 generates any out-of-lines instances of such things (despite the fact
15538 that they *are* definitions).
15540 The important point is that the C front-end marks these "extern
15541 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15542 them anyway. Note that the C++ front-end also plays some similar games
15543 for inline function definitions appearing within include files which
15544 also contain `#pragma interface' pragmas. */
15545 if (DECL_INITIAL (decl) == NULL_TREE)
15548 /* If we're a nested function, initially use a parent of NULL; if we're
15549 a plain function, this will be fixed up in decls_for_scope. If
15550 we're a method, it will be ignored, since we already have a DIE. */
15551 if (decl_function_context (decl)
15552 /* But if we're in terse mode, we don't care about scope. */
15553 && debug_info_level > DINFO_LEVEL_TERSE)
15554 context_die = NULL;
15558 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15559 declaration and if the declaration was never even referenced from
15560 within this entire compilation unit. We suppress these DIEs in
15561 order to save space in the .debug section (by eliminating entries
15562 which are probably useless). Note that we must not suppress
15563 block-local extern declarations (whether used or not) because that
15564 would screw-up the debugger's name lookup mechanism and cause it to
15565 miss things which really ought to be in scope at a given point. */
15566 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15569 /* For local statics lookup proper context die. */
15570 if (TREE_STATIC (decl) && decl_function_context (decl))
15571 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15573 /* If we are in terse mode, don't generate any DIEs to represent any
15574 variable declarations or definitions. */
15575 if (debug_info_level <= DINFO_LEVEL_TERSE)
15580 if (debug_info_level <= DINFO_LEVEL_TERSE)
15582 if (!is_fortran ())
15584 if (TREE_STATIC (decl) && decl_function_context (decl))
15585 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15588 case NAMESPACE_DECL:
15589 case IMPORTED_DECL:
15590 if (debug_info_level <= DINFO_LEVEL_TERSE)
15592 if (lookup_decl_die (decl) != NULL)
15597 /* Don't emit stubs for types unless they are needed by other DIEs. */
15598 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15601 /* Don't bother trying to generate any DIEs to represent any of the
15602 normal built-in types for the language we are compiling. */
15603 if (DECL_IS_BUILTIN (decl))
15605 /* OK, we need to generate one for `bool' so GDB knows what type
15606 comparisons have. */
15608 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15609 && ! DECL_IGNORED_P (decl))
15610 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15615 /* If we are in terse mode, don't generate any DIEs for types. */
15616 if (debug_info_level <= DINFO_LEVEL_TERSE)
15619 /* If we're a function-scope tag, initially use a parent of NULL;
15620 this will be fixed up in decls_for_scope. */
15621 if (decl_function_context (decl))
15622 context_die = NULL;
15630 gen_decl_die (decl, NULL, context_die);
15633 /* Output a marker (i.e. a label) for the beginning of the generated code for
15634 a lexical block. */
15637 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15638 unsigned int blocknum)
15640 switch_to_section (current_function_section ());
15641 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15644 /* Output a marker (i.e. a label) for the end of the generated code for a
15648 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15650 switch_to_section (current_function_section ());
15651 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15654 /* Returns nonzero if it is appropriate not to emit any debugging
15655 information for BLOCK, because it doesn't contain any instructions.
15657 Don't allow this for blocks with nested functions or local classes
15658 as we would end up with orphans, and in the presence of scheduling
15659 we may end up calling them anyway. */
15662 dwarf2out_ignore_block (const_tree block)
15667 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15668 if (TREE_CODE (decl) == FUNCTION_DECL
15669 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15671 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
15673 decl = BLOCK_NONLOCALIZED_VAR (block, i);
15674 if (TREE_CODE (decl) == FUNCTION_DECL
15675 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15682 /* Hash table routines for file_hash. */
15685 file_table_eq (const void *p1_p, const void *p2_p)
15687 const struct dwarf_file_data *const p1 =
15688 (const struct dwarf_file_data *) p1_p;
15689 const char *const p2 = (const char *) p2_p;
15690 return strcmp (p1->filename, p2) == 0;
15694 file_table_hash (const void *p_p)
15696 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15697 return htab_hash_string (p->filename);
15700 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15701 dwarf2out.c) and return its "index". The index of each (known) filename is
15702 just a unique number which is associated with only that one filename. We
15703 need such numbers for the sake of generating labels (in the .debug_sfnames
15704 section) and references to those files numbers (in the .debug_srcinfo
15705 and.debug_macinfo sections). If the filename given as an argument is not
15706 found in our current list, add it to the list and assign it the next
15707 available unique index number. In order to speed up searches, we remember
15708 the index of the filename was looked up last. This handles the majority of
15711 static struct dwarf_file_data *
15712 lookup_filename (const char *file_name)
15715 struct dwarf_file_data * created;
15717 /* Check to see if the file name that was searched on the previous
15718 call matches this file name. If so, return the index. */
15719 if (file_table_last_lookup
15720 && (file_name == file_table_last_lookup->filename
15721 || strcmp (file_table_last_lookup->filename, file_name) == 0))
15722 return file_table_last_lookup;
15724 /* Didn't match the previous lookup, search the table. */
15725 slot = htab_find_slot_with_hash (file_table, file_name,
15726 htab_hash_string (file_name), INSERT);
15728 return (struct dwarf_file_data *) *slot;
15730 created = GGC_NEW (struct dwarf_file_data);
15731 created->filename = file_name;
15732 created->emitted_number = 0;
15737 /* If the assembler will construct the file table, then translate the compiler
15738 internal file table number into the assembler file table number, and emit
15739 a .file directive if we haven't already emitted one yet. The file table
15740 numbers are different because we prune debug info for unused variables and
15741 types, which may include filenames. */
15744 maybe_emit_file (struct dwarf_file_data * fd)
15746 if (! fd->emitted_number)
15748 if (last_emitted_file)
15749 fd->emitted_number = last_emitted_file->emitted_number + 1;
15751 fd->emitted_number = 1;
15752 last_emitted_file = fd;
15754 if (DWARF2_ASM_LINE_DEBUG_INFO)
15756 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
15757 output_quoted_string (asm_out_file,
15758 remap_debug_filename (fd->filename));
15759 fputc ('\n', asm_out_file);
15763 return fd->emitted_number;
15766 /* Called by the final INSN scan whenever we see a var location. We
15767 use it to drop labels in the right places, and throw the location in
15768 our lookup table. */
15771 dwarf2out_var_location (rtx loc_note)
15773 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
15774 struct var_loc_node *newloc;
15776 static rtx last_insn;
15777 static const char *last_label;
15780 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
15782 prev_insn = PREV_INSN (loc_note);
15784 newloc = GGC_CNEW (struct var_loc_node);
15785 /* If the insn we processed last time is the previous insn
15786 and it is also a var location note, use the label we emitted
15788 if (last_insn != NULL_RTX
15789 && last_insn == prev_insn
15790 && NOTE_P (prev_insn)
15791 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
15793 newloc->label = last_label;
15797 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
15798 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
15800 newloc->label = ggc_strdup (loclabel);
15802 newloc->var_loc_note = loc_note;
15803 newloc->next = NULL;
15805 if (cfun && in_cold_section_p)
15806 newloc->section_label = crtl->subsections.cold_section_label;
15808 newloc->section_label = text_section_label;
15810 last_insn = loc_note;
15811 last_label = newloc->label;
15812 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15813 add_var_loc_to_decl (decl, newloc);
15816 /* We need to reset the locations at the beginning of each
15817 function. We can't do this in the end_function hook, because the
15818 declarations that use the locations won't have been output when
15819 that hook is called. Also compute have_multiple_function_sections here. */
15822 dwarf2out_begin_function (tree fun)
15824 htab_empty (decl_loc_table);
15826 if (function_section (fun) != text_section)
15827 have_multiple_function_sections = true;
15829 dwarf2out_note_section_used ();
15832 /* Output a label to mark the beginning of a source code line entry
15833 and record information relating to this source line, in
15834 'line_info_table' for later output of the .debug_line section. */
15837 dwarf2out_source_line (unsigned int line, const char *filename)
15839 if (debug_info_level >= DINFO_LEVEL_NORMAL
15842 int file_num = maybe_emit_file (lookup_filename (filename));
15844 switch_to_section (current_function_section ());
15846 /* If requested, emit something human-readable. */
15847 if (flag_debug_asm)
15848 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15851 if (DWARF2_ASM_LINE_DEBUG_INFO)
15853 /* Emit the .loc directive understood by GNU as. */
15854 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15856 /* Indicate that line number info exists. */
15857 line_info_table_in_use++;
15859 else if (function_section (current_function_decl) != text_section)
15861 dw_separate_line_info_ref line_info;
15862 targetm.asm_out.internal_label (asm_out_file,
15863 SEPARATE_LINE_CODE_LABEL,
15864 separate_line_info_table_in_use);
15866 /* Expand the line info table if necessary. */
15867 if (separate_line_info_table_in_use
15868 == separate_line_info_table_allocated)
15870 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15871 separate_line_info_table
15872 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15873 separate_line_info_table,
15874 separate_line_info_table_allocated);
15875 memset (separate_line_info_table
15876 + separate_line_info_table_in_use,
15878 (LINE_INFO_TABLE_INCREMENT
15879 * sizeof (dw_separate_line_info_entry)));
15882 /* Add the new entry at the end of the line_info_table. */
15884 = &separate_line_info_table[separate_line_info_table_in_use++];
15885 line_info->dw_file_num = file_num;
15886 line_info->dw_line_num = line;
15887 line_info->function = current_function_funcdef_no;
15891 dw_line_info_ref line_info;
15893 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
15894 line_info_table_in_use);
15896 /* Expand the line info table if necessary. */
15897 if (line_info_table_in_use == line_info_table_allocated)
15899 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15901 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
15902 line_info_table_allocated);
15903 memset (line_info_table + line_info_table_in_use, 0,
15904 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
15907 /* Add the new entry at the end of the line_info_table. */
15908 line_info = &line_info_table[line_info_table_in_use++];
15909 line_info->dw_file_num = file_num;
15910 line_info->dw_line_num = line;
15915 /* Record the beginning of a new source file. */
15918 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
15920 if (flag_eliminate_dwarf2_dups)
15922 /* Record the beginning of the file for break_out_includes. */
15923 dw_die_ref bincl_die;
15925 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
15926 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
15929 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15931 int file_num = maybe_emit_file (lookup_filename (filename));
15933 switch_to_section (debug_macinfo_section);
15934 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
15935 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
15938 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
15942 /* Record the end of a source file. */
15945 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
15947 if (flag_eliminate_dwarf2_dups)
15948 /* Record the end of the file for break_out_includes. */
15949 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
15951 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15953 switch_to_section (debug_macinfo_section);
15954 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
15958 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15959 the tail part of the directive line, i.e. the part which is past the
15960 initial whitespace, #, whitespace, directive-name, whitespace part. */
15963 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
15964 const char *buffer ATTRIBUTE_UNUSED)
15966 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15968 switch_to_section (debug_macinfo_section);
15969 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
15970 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15971 dw2_asm_output_nstring (buffer, -1, "The macro");
15975 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15976 the tail part of the directive line, i.e. the part which is past the
15977 initial whitespace, #, whitespace, directive-name, whitespace part. */
15980 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
15981 const char *buffer ATTRIBUTE_UNUSED)
15983 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15985 switch_to_section (debug_macinfo_section);
15986 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
15987 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15988 dw2_asm_output_nstring (buffer, -1, "The macro");
15992 /* Set up for Dwarf output at the start of compilation. */
15995 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
15997 /* Allocate the file_table. */
15998 file_table = htab_create_ggc (50, file_table_hash,
15999 file_table_eq, NULL);
16001 /* Allocate the decl_die_table. */
16002 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16003 decl_die_table_eq, NULL);
16005 /* Allocate the decl_loc_table. */
16006 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16007 decl_loc_table_eq, NULL);
16009 /* Allocate the initial hunk of the decl_scope_table. */
16010 decl_scope_table = VEC_alloc (tree, gc, 256);
16012 /* Allocate the initial hunk of the abbrev_die_table. */
16013 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16014 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16015 /* Zero-th entry is allocated, but unused. */
16016 abbrev_die_table_in_use = 1;
16018 /* Allocate the initial hunk of the line_info_table. */
16019 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16020 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16022 /* Zero-th entry is allocated, but unused. */
16023 line_info_table_in_use = 1;
16025 /* Allocate the pubtypes and pubnames vectors. */
16026 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16027 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16029 /* Generate the initial DIE for the .debug section. Note that the (string)
16030 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16031 will (typically) be a relative pathname and that this pathname should be
16032 taken as being relative to the directory from which the compiler was
16033 invoked when the given (base) source file was compiled. We will fill
16034 in this value in dwarf2out_finish. */
16035 comp_unit_die = gen_compile_unit_die (NULL);
16037 incomplete_types = VEC_alloc (tree, gc, 64);
16039 used_rtx_array = VEC_alloc (rtx, gc, 32);
16041 debug_info_section = get_section (DEBUG_INFO_SECTION,
16042 SECTION_DEBUG, NULL);
16043 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16044 SECTION_DEBUG, NULL);
16045 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16046 SECTION_DEBUG, NULL);
16047 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16048 SECTION_DEBUG, NULL);
16049 debug_line_section = get_section (DEBUG_LINE_SECTION,
16050 SECTION_DEBUG, NULL);
16051 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16052 SECTION_DEBUG, NULL);
16053 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16054 SECTION_DEBUG, NULL);
16055 #ifdef DEBUG_PUBTYPES_SECTION
16056 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16057 SECTION_DEBUG, NULL);
16059 debug_str_section = get_section (DEBUG_STR_SECTION,
16060 DEBUG_STR_SECTION_FLAGS, NULL);
16061 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16062 SECTION_DEBUG, NULL);
16063 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16064 SECTION_DEBUG, NULL);
16066 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16067 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16068 DEBUG_ABBREV_SECTION_LABEL, 0);
16069 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16070 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16071 COLD_TEXT_SECTION_LABEL, 0);
16072 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16074 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16075 DEBUG_INFO_SECTION_LABEL, 0);
16076 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16077 DEBUG_LINE_SECTION_LABEL, 0);
16078 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16079 DEBUG_RANGES_SECTION_LABEL, 0);
16080 switch_to_section (debug_abbrev_section);
16081 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16082 switch_to_section (debug_info_section);
16083 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16084 switch_to_section (debug_line_section);
16085 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16087 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16089 switch_to_section (debug_macinfo_section);
16090 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16091 DEBUG_MACINFO_SECTION_LABEL, 0);
16092 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16095 switch_to_section (text_section);
16096 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16097 if (flag_reorder_blocks_and_partition)
16099 cold_text_section = unlikely_text_section ();
16100 switch_to_section (cold_text_section);
16101 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16105 /* A helper function for dwarf2out_finish called through
16106 ht_forall. Emit one queued .debug_str string. */
16109 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16111 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16113 if (node->form == DW_FORM_strp)
16115 switch_to_section (debug_str_section);
16116 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16117 assemble_string (node->str, strlen (node->str) + 1);
16123 #if ENABLE_ASSERT_CHECKING
16124 /* Verify that all marks are clear. */
16127 verify_marks_clear (dw_die_ref die)
16131 gcc_assert (! die->die_mark);
16132 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16134 #endif /* ENABLE_ASSERT_CHECKING */
16136 /* Clear the marks for a die and its children.
16137 Be cool if the mark isn't set. */
16140 prune_unmark_dies (dw_die_ref die)
16146 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16149 /* Given DIE that we're marking as used, find any other dies
16150 it references as attributes and mark them as used. */
16153 prune_unused_types_walk_attribs (dw_die_ref die)
16158 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16160 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16162 /* A reference to another DIE.
16163 Make sure that it will get emitted. */
16164 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16166 /* Set the string's refcount to 0 so that prune_unused_types_mark
16167 accounts properly for it. */
16168 if (AT_class (a) == dw_val_class_str)
16169 a->dw_attr_val.v.val_str->refcount = 0;
16174 /* Mark DIE as being used. If DOKIDS is true, then walk down
16175 to DIE's children. */
16178 prune_unused_types_mark (dw_die_ref die, int dokids)
16182 if (die->die_mark == 0)
16184 /* We haven't done this node yet. Mark it as used. */
16187 /* We also have to mark its parents as used.
16188 (But we don't want to mark our parents' kids due to this.) */
16189 if (die->die_parent)
16190 prune_unused_types_mark (die->die_parent, 0);
16192 /* Mark any referenced nodes. */
16193 prune_unused_types_walk_attribs (die);
16195 /* If this node is a specification,
16196 also mark the definition, if it exists. */
16197 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
16198 prune_unused_types_mark (die->die_definition, 1);
16201 if (dokids && die->die_mark != 2)
16203 /* We need to walk the children, but haven't done so yet.
16204 Remember that we've walked the kids. */
16207 /* If this is an array type, we need to make sure our
16208 kids get marked, even if they're types. */
16209 if (die->die_tag == DW_TAG_array_type)
16210 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
16212 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16216 /* For local classes, look if any static member functions were emitted
16217 and if so, mark them. */
16220 prune_unused_types_walk_local_classes (dw_die_ref die)
16224 if (die->die_mark == 2)
16227 switch (die->die_tag)
16229 case DW_TAG_structure_type:
16230 case DW_TAG_union_type:
16231 case DW_TAG_class_type:
16234 case DW_TAG_subprogram:
16235 if (!get_AT_flag (die, DW_AT_declaration)
16236 || die->die_definition != NULL)
16237 prune_unused_types_mark (die, 1);
16244 /* Mark children. */
16245 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
16248 /* Walk the tree DIE and mark types that we actually use. */
16251 prune_unused_types_walk (dw_die_ref die)
16255 /* Don't do anything if this node is already marked and
16256 children have been marked as well. */
16257 if (die->die_mark == 2)
16260 switch (die->die_tag)
16262 case DW_TAG_structure_type:
16263 case DW_TAG_union_type:
16264 case DW_TAG_class_type:
16265 if (die->die_perennial_p)
16268 for (c = die->die_parent; c; c = c->die_parent)
16269 if (c->die_tag == DW_TAG_subprogram)
16272 /* Finding used static member functions inside of classes
16273 is needed just for local classes, because for other classes
16274 static member function DIEs with DW_AT_specification
16275 are emitted outside of the DW_TAG_*_type. If we ever change
16276 it, we'd need to call this even for non-local classes. */
16278 prune_unused_types_walk_local_classes (die);
16280 /* It's a type node --- don't mark it. */
16283 case DW_TAG_const_type:
16284 case DW_TAG_packed_type:
16285 case DW_TAG_pointer_type:
16286 case DW_TAG_reference_type:
16287 case DW_TAG_volatile_type:
16288 case DW_TAG_typedef:
16289 case DW_TAG_array_type:
16290 case DW_TAG_interface_type:
16291 case DW_TAG_friend:
16292 case DW_TAG_variant_part:
16293 case DW_TAG_enumeration_type:
16294 case DW_TAG_subroutine_type:
16295 case DW_TAG_string_type:
16296 case DW_TAG_set_type:
16297 case DW_TAG_subrange_type:
16298 case DW_TAG_ptr_to_member_type:
16299 case DW_TAG_file_type:
16300 if (die->die_perennial_p)
16303 /* It's a type node --- don't mark it. */
16307 /* Mark everything else. */
16311 if (die->die_mark == 0)
16315 /* Now, mark any dies referenced from here. */
16316 prune_unused_types_walk_attribs (die);
16321 /* Mark children. */
16322 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16325 /* Increment the string counts on strings referred to from DIE's
16329 prune_unused_types_update_strings (dw_die_ref die)
16334 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16335 if (AT_class (a) == dw_val_class_str)
16337 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
16339 /* Avoid unnecessarily putting strings that are used less than
16340 twice in the hash table. */
16342 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
16345 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
16346 htab_hash_string (s->str),
16348 gcc_assert (*slot == NULL);
16354 /* Remove from the tree DIE any dies that aren't marked. */
16357 prune_unused_types_prune (dw_die_ref die)
16361 gcc_assert (die->die_mark);
16362 prune_unused_types_update_strings (die);
16364 if (! die->die_child)
16367 c = die->die_child;
16369 dw_die_ref prev = c;
16370 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
16371 if (c == die->die_child)
16373 /* No marked children between 'prev' and the end of the list. */
16375 /* No marked children at all. */
16376 die->die_child = NULL;
16379 prev->die_sib = c->die_sib;
16380 die->die_child = prev;
16385 if (c != prev->die_sib)
16387 prune_unused_types_prune (c);
16388 } while (c != die->die_child);
16392 /* Remove dies representing declarations that we never use. */
16395 prune_unused_types (void)
16398 limbo_die_node *node;
16401 #if ENABLE_ASSERT_CHECKING
16402 /* All the marks should already be clear. */
16403 verify_marks_clear (comp_unit_die);
16404 for (node = limbo_die_list; node; node = node->next)
16405 verify_marks_clear (node->die);
16406 #endif /* ENABLE_ASSERT_CHECKING */
16408 /* Set the mark on nodes that are actually used. */
16409 prune_unused_types_walk (comp_unit_die);
16410 for (node = limbo_die_list; node; node = node->next)
16411 prune_unused_types_walk (node->die);
16413 /* Also set the mark on nodes referenced from the
16414 pubname_table or arange_table. */
16415 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
16416 prune_unused_types_mark (pub->die, 1);
16417 for (i = 0; i < arange_table_in_use; i++)
16418 prune_unused_types_mark (arange_table[i], 1);
16420 /* Get rid of nodes that aren't marked; and update the string counts. */
16421 if (debug_str_hash)
16422 htab_empty (debug_str_hash);
16423 prune_unused_types_prune (comp_unit_die);
16424 for (node = limbo_die_list; node; node = node->next)
16425 prune_unused_types_prune (node->die);
16427 /* Leave the marks clear. */
16428 prune_unmark_dies (comp_unit_die);
16429 for (node = limbo_die_list; node; node = node->next)
16430 prune_unmark_dies (node->die);
16433 /* Set the parameter to true if there are any relative pathnames in
16436 file_table_relative_p (void ** slot, void *param)
16438 bool *p = (bool *) param;
16439 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16440 if (!IS_ABSOLUTE_PATH (d->filename))
16448 /* Output stuff that dwarf requires at the end of every file,
16449 and generate the DWARF-2 debugging info. */
16452 dwarf2out_finish (const char *filename)
16454 limbo_die_node *node, *next_node;
16455 dw_die_ref die = 0;
16458 /* Add the name for the main input file now. We delayed this from
16459 dwarf2out_init to avoid complications with PCH. */
16460 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
16461 if (!IS_ABSOLUTE_PATH (filename))
16462 add_comp_dir_attribute (comp_unit_die);
16463 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
16466 htab_traverse (file_table, file_table_relative_p, &p);
16468 add_comp_dir_attribute (comp_unit_die);
16471 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
16473 add_location_or_const_value_attribute (
16474 VEC_index (deferred_locations, deferred_locations_list, i)->die,
16475 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
16479 /* Traverse the limbo die list, and add parent/child links. The only
16480 dies without parents that should be here are concrete instances of
16481 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16482 For concrete instances, we can get the parent die from the abstract
16484 for (node = limbo_die_list; node; node = next_node)
16486 next_node = node->next;
16489 if (die->die_parent == NULL)
16491 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
16494 add_child_die (origin->die_parent, die);
16495 else if (die == comp_unit_die)
16497 else if (errorcount > 0 || sorrycount > 0)
16498 /* It's OK to be confused by errors in the input. */
16499 add_child_die (comp_unit_die, die);
16502 /* In certain situations, the lexical block containing a
16503 nested function can be optimized away, which results
16504 in the nested function die being orphaned. Likewise
16505 with the return type of that nested function. Force
16506 this to be a child of the containing function.
16508 It may happen that even the containing function got fully
16509 inlined and optimized out. In that case we are lost and
16510 assign the empty child. This should not be big issue as
16511 the function is likely unreachable too. */
16512 tree context = NULL_TREE;
16514 gcc_assert (node->created_for);
16516 if (DECL_P (node->created_for))
16517 context = DECL_CONTEXT (node->created_for);
16518 else if (TYPE_P (node->created_for))
16519 context = TYPE_CONTEXT (node->created_for);
16521 gcc_assert (context
16522 && (TREE_CODE (context) == FUNCTION_DECL
16523 || TREE_CODE (context) == NAMESPACE_DECL));
16525 origin = lookup_decl_die (context);
16527 add_child_die (origin, die);
16529 add_child_die (comp_unit_die, die);
16534 limbo_die_list = NULL;
16536 /* Walk through the list of incomplete types again, trying once more to
16537 emit full debugging info for them. */
16538 retry_incomplete_types ();
16540 if (flag_eliminate_unused_debug_types)
16541 prune_unused_types ();
16543 /* Generate separate CUs for each of the include files we've seen.
16544 They will go into limbo_die_list. */
16545 if (flag_eliminate_dwarf2_dups)
16546 break_out_includes (comp_unit_die);
16548 /* Traverse the DIE's and add add sibling attributes to those DIE's
16549 that have children. */
16550 add_sibling_attributes (comp_unit_die);
16551 for (node = limbo_die_list; node; node = node->next)
16552 add_sibling_attributes (node->die);
16554 /* Output a terminator label for the .text section. */
16555 switch_to_section (text_section);
16556 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16557 if (flag_reorder_blocks_and_partition)
16559 switch_to_section (unlikely_text_section ());
16560 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16563 /* We can only use the low/high_pc attributes if all of the code was
16565 if (!have_multiple_function_sections)
16567 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16568 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16573 unsigned fde_idx = 0;
16575 /* We need to give .debug_loc and .debug_ranges an appropriate
16576 "base address". Use zero so that these addresses become
16577 absolute. Historically, we've emitted the unexpected
16578 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16579 Emit both to give time for other tools to adapt. */
16580 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16581 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16583 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16584 add_ranges_by_labels (text_section_label,
16586 if (flag_reorder_blocks_and_partition)
16587 add_ranges_by_labels (cold_text_section_label,
16590 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16592 dw_fde_ref fde = &fde_table[fde_idx];
16594 if (fde->dw_fde_switched_sections)
16596 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16597 fde->dw_fde_hot_section_end_label);
16598 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16599 fde->dw_fde_unlikely_section_end_label);
16602 add_ranges_by_labels (fde->dw_fde_begin,
16609 /* Output location list section if necessary. */
16610 if (have_location_lists)
16612 /* Output the location lists info. */
16613 switch_to_section (debug_loc_section);
16614 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16615 DEBUG_LOC_SECTION_LABEL, 0);
16616 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16617 output_location_lists (die);
16620 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16621 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16622 debug_line_section_label);
16624 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16625 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16627 /* Output all of the compilation units. We put the main one last so that
16628 the offsets are available to output_pubnames. */
16629 for (node = limbo_die_list; node; node = node->next)
16630 output_comp_unit (node->die, 0);
16632 /* Output the main compilation unit if non-empty or if .debug_macinfo
16633 has been emitted. */
16634 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
16636 /* Output the abbreviation table. */
16637 switch_to_section (debug_abbrev_section);
16638 output_abbrev_section ();
16640 /* Output public names table if necessary. */
16641 if (!VEC_empty (pubname_entry, pubname_table))
16643 switch_to_section (debug_pubnames_section);
16644 output_pubnames (pubname_table);
16647 #ifdef DEBUG_PUBTYPES_SECTION
16648 /* Output public types table if necessary. */
16649 if (!VEC_empty (pubname_entry, pubtype_table))
16651 switch_to_section (debug_pubtypes_section);
16652 output_pubnames (pubtype_table);
16656 /* Output the address range information. We only put functions in the arange
16657 table, so don't write it out if we don't have any. */
16658 if (fde_table_in_use)
16660 switch_to_section (debug_aranges_section);
16664 /* Output ranges section if necessary. */
16665 if (ranges_table_in_use)
16667 switch_to_section (debug_ranges_section);
16668 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16672 /* Output the source line correspondence table. We must do this
16673 even if there is no line information. Otherwise, on an empty
16674 translation unit, we will generate a present, but empty,
16675 .debug_info section. IRIX 6.5 `nm' will then complain when
16676 examining the file. This is done late so that any filenames
16677 used by the debug_info section are marked as 'used'. */
16678 if (! DWARF2_ASM_LINE_DEBUG_INFO)
16680 switch_to_section (debug_line_section);
16681 output_line_info ();
16684 /* Have to end the macro section. */
16685 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16687 switch_to_section (debug_macinfo_section);
16688 dw2_asm_output_data (1, 0, "End compilation unit");
16691 /* If we emitted any DW_FORM_strp form attribute, output the string
16693 if (debug_str_hash)
16694 htab_traverse (debug_str_hash, output_indirect_string, NULL);
16698 /* This should never be used, but its address is needed for comparisons. */
16699 const struct gcc_debug_hooks dwarf2_debug_hooks;
16701 #endif /* DWARF2_DEBUGGING_INFO */
16703 #include "gt-dwarf2out.h"