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"
77 #include "elf/dwarf2.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 *, int, bool);
96 static rtx last_var_location_insn;
99 #ifndef DWARF2_FRAME_INFO
100 # ifdef DWARF2_DEBUGGING_INFO
101 # define DWARF2_FRAME_INFO \
102 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
104 # define DWARF2_FRAME_INFO 0
108 /* Map register numbers held in the call frame info that gcc has
109 collected using DWARF_FRAME_REGNUM to those that should be output in
110 .debug_frame and .eh_frame. */
111 #ifndef DWARF2_FRAME_REG_OUT
112 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
115 /* Save the result of dwarf2out_do_frame across PCH. */
116 static GTY(()) bool saved_do_cfi_asm = 0;
118 /* Decide whether we want to emit frame unwind information for the current
122 dwarf2out_do_frame (void)
124 /* We want to emit correct CFA location expressions or lists, so we
125 have to return true if we're going to output debug info, even if
126 we're not going to output frame or unwind info. */
127 return (write_symbols == DWARF2_DEBUG
128 || write_symbols == VMS_AND_DWARF2_DEBUG
129 || DWARF2_FRAME_INFO || saved_do_cfi_asm
130 #ifdef DWARF2_UNWIND_INFO
131 || (DWARF2_UNWIND_INFO
132 && (flag_unwind_tables
133 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
138 /* Decide whether to emit frame unwind via assembler directives. */
141 dwarf2out_do_cfi_asm (void)
145 #ifdef MIPS_DEBUGGING_INFO
148 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
150 if (saved_do_cfi_asm || !eh_personality_libfunc)
152 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
155 /* Make sure the personality encoding is one the assembler can support.
156 In particular, aligned addresses can't be handled. */
157 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
158 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
160 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
161 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
164 saved_do_cfi_asm = true;
168 /* The size of the target's pointer type. */
170 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
173 /* Array of RTXes referenced by the debugging information, which therefore
174 must be kept around forever. */
175 static GTY(()) VEC(rtx,gc) *used_rtx_array;
177 /* A pointer to the base of a list of incomplete types which might be
178 completed at some later time. incomplete_types_list needs to be a
179 VEC(tree,gc) because we want to tell the garbage collector about
181 static GTY(()) VEC(tree,gc) *incomplete_types;
183 /* A pointer to the base of a table of references to declaration
184 scopes. This table is a display which tracks the nesting
185 of declaration scopes at the current scope and containing
186 scopes. This table is used to find the proper place to
187 define type declaration DIE's. */
188 static GTY(()) VEC(tree,gc) *decl_scope_table;
190 /* Pointers to various DWARF2 sections. */
191 static GTY(()) section *debug_info_section;
192 static GTY(()) section *debug_abbrev_section;
193 static GTY(()) section *debug_aranges_section;
194 static GTY(()) section *debug_macinfo_section;
195 static GTY(()) section *debug_line_section;
196 static GTY(()) section *debug_loc_section;
197 static GTY(()) section *debug_pubnames_section;
198 static GTY(()) section *debug_pubtypes_section;
199 static GTY(()) section *debug_str_section;
200 static GTY(()) section *debug_ranges_section;
201 static GTY(()) section *debug_frame_section;
203 /* How to start an assembler comment. */
204 #ifndef ASM_COMMENT_START
205 #define ASM_COMMENT_START ";#"
208 typedef struct dw_cfi_struct *dw_cfi_ref;
209 typedef struct dw_fde_struct *dw_fde_ref;
210 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
212 /* Call frames are described using a sequence of Call Frame
213 Information instructions. The register number, offset
214 and address fields are provided as possible operands;
215 their use is selected by the opcode field. */
217 enum dw_cfi_oprnd_type {
219 dw_cfi_oprnd_reg_num,
225 typedef union GTY(()) dw_cfi_oprnd_struct {
226 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
227 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
228 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
229 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
233 typedef struct GTY(()) dw_cfi_struct {
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 GTY(()) cfa_loc {
249 HOST_WIDE_INT offset;
250 HOST_WIDE_INT base_offset;
252 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
253 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
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 GTY(()) dw_fde_struct {
264 const char *dw_fde_begin;
265 const char *dw_fde_current_label;
266 const char *dw_fde_end;
267 const char *dw_fde_hot_section_label;
268 const char *dw_fde_hot_section_end_label;
269 const char *dw_fde_unlikely_section_label;
270 const char *dw_fde_unlikely_section_end_label;
271 bool dw_fde_switched_sections;
272 dw_cfi_ref dw_fde_cfi;
273 unsigned funcdef_number;
274 HOST_WIDE_INT stack_realignment;
275 /* Dynamic realign argument pointer register. */
276 unsigned int drap_reg;
277 /* Virtual dynamic realign argument pointer register. */
278 unsigned int vdrap_reg;
279 unsigned all_throwers_are_sibcalls : 1;
280 unsigned nothrow : 1;
281 unsigned uses_eh_lsda : 1;
282 /* Whether we did stack realign in this call frame. */
283 unsigned stack_realign : 1;
284 /* Whether dynamic realign argument pointer register has been saved. */
285 unsigned drap_reg_saved: 1;
289 /* Maximum size (in bytes) of an artificially generated label. */
290 #define MAX_ARTIFICIAL_LABEL_BYTES 30
292 /* The size of addresses as they appear in the Dwarf 2 data.
293 Some architectures use word addresses to refer to code locations,
294 but Dwarf 2 info always uses byte addresses. On such machines,
295 Dwarf 2 addresses need to be larger than the architecture's
297 #ifndef DWARF2_ADDR_SIZE
298 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
301 /* The size in bytes of a DWARF field indicating an offset or length
302 relative to a debug info section, specified to be 4 bytes in the
303 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
306 #ifndef DWARF_OFFSET_SIZE
307 #define DWARF_OFFSET_SIZE 4
310 /* According to the (draft) DWARF 3 specification, the initial length
311 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
312 bytes are 0xffffffff, followed by the length stored in the next 8
315 However, the SGI/MIPS ABI uses an initial length which is equal to
316 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
318 #ifndef DWARF_INITIAL_LENGTH_SIZE
319 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
322 /* Round SIZE up to the nearest BOUNDARY. */
323 #define DWARF_ROUND(SIZE,BOUNDARY) \
324 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
326 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
327 #ifndef DWARF_CIE_DATA_ALIGNMENT
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
331 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
335 /* CIE identifier. */
336 #if HOST_BITS_PER_WIDE_INT >= 64
337 #define DWARF_CIE_ID \
338 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
340 #define DWARF_CIE_ID DW_CIE_ID
343 /* A pointer to the base of a table that contains frame description
344 information for each routine. */
345 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
347 /* Number of elements currently allocated for fde_table. */
348 static GTY(()) unsigned fde_table_allocated;
350 /* Number of elements in fde_table currently in use. */
351 static GTY(()) unsigned fde_table_in_use;
353 /* Size (in elements) of increments by which we may expand the
355 #define FDE_TABLE_INCREMENT 256
357 /* Get the current fde_table entry we should use. */
359 static inline dw_fde_ref
362 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
365 /* A list of call frame insns for the CIE. */
366 static GTY(()) dw_cfi_ref cie_cfi_head;
368 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
369 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
370 attribute that accelerates the lookup of the FDE associated
371 with the subprogram. This variable holds the table index of the FDE
372 associated with the current function (body) definition. */
373 static unsigned current_funcdef_fde;
376 struct GTY(()) indirect_string_node {
378 unsigned int refcount;
379 enum dwarf_form form;
383 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
385 static GTY(()) int dw2_string_counter;
386 static GTY(()) unsigned long dwarf2out_cfi_label_num;
388 /* True if the compilation unit places functions in more than one section. */
389 static GTY(()) bool have_multiple_function_sections = false;
391 /* Whether the default text and cold text sections have been used at all. */
393 static GTY(()) bool text_section_used = false;
394 static GTY(()) bool cold_text_section_used = false;
396 /* The default cold text section. */
397 static GTY(()) section *cold_text_section;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
401 /* Forward declarations for functions defined in this file. */
403 static char *stripattributes (const char *);
404 static const char *dwarf_cfi_name (unsigned);
405 static dw_cfi_ref new_cfi (void);
406 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
407 static void add_fde_cfi (const char *, dw_cfi_ref);
408 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
409 static void lookup_cfa (dw_cfa_location *);
410 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
411 #ifdef DWARF2_UNWIND_INFO
412 static void initial_return_save (rtx);
414 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
416 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
417 static void output_cfi_directive (dw_cfi_ref);
418 static void output_call_frame_info (int);
419 static void dwarf2out_note_section_used (void);
420 static void dwarf2out_stack_adjust (rtx, bool);
421 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
422 static void flush_queued_reg_saves (void);
423 static bool clobbers_queued_reg_save (const_rtx);
424 static void dwarf2out_frame_debug_expr (rtx, const char *);
426 /* Support for complex CFA locations. */
427 static void output_cfa_loc (dw_cfi_ref);
428 static void output_cfa_loc_raw (dw_cfi_ref);
429 static void get_cfa_from_loc_descr (dw_cfa_location *,
430 struct dw_loc_descr_struct *);
431 static struct dw_loc_descr_struct *build_cfa_loc
432 (dw_cfa_location *, HOST_WIDE_INT);
433 static struct dw_loc_descr_struct *build_cfa_aligned_loc
434 (HOST_WIDE_INT, HOST_WIDE_INT);
435 static void def_cfa_1 (const char *, dw_cfa_location *);
437 /* How to start an assembler comment. */
438 #ifndef ASM_COMMENT_START
439 #define ASM_COMMENT_START ";#"
442 /* Data and reference forms for relocatable data. */
443 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
444 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
446 #ifndef DEBUG_FRAME_SECTION
447 #define DEBUG_FRAME_SECTION ".debug_frame"
450 #ifndef FUNC_BEGIN_LABEL
451 #define FUNC_BEGIN_LABEL "LFB"
454 #ifndef FUNC_END_LABEL
455 #define FUNC_END_LABEL "LFE"
458 #ifndef FRAME_BEGIN_LABEL
459 #define FRAME_BEGIN_LABEL "Lframe"
461 #define CIE_AFTER_SIZE_LABEL "LSCIE"
462 #define CIE_END_LABEL "LECIE"
463 #define FDE_LABEL "LSFDE"
464 #define FDE_AFTER_SIZE_LABEL "LASFDE"
465 #define FDE_END_LABEL "LEFDE"
466 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
467 #define LINE_NUMBER_END_LABEL "LELT"
468 #define LN_PROLOG_AS_LABEL "LASLTP"
469 #define LN_PROLOG_END_LABEL "LELTP"
470 #define DIE_LABEL_PREFIX "DW"
472 /* The DWARF 2 CFA column which tracks the return address. Normally this
473 is the column for PC, or the first column after all of the hard
475 #ifndef DWARF_FRAME_RETURN_COLUMN
477 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
479 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
483 /* The mapping from gcc register number to DWARF 2 CFA column number. By
484 default, we just provide columns for all registers. */
485 #ifndef DWARF_FRAME_REGNUM
486 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
489 /* Hook used by __throw. */
492 expand_builtin_dwarf_sp_column (void)
494 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
495 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
498 /* Return a pointer to a copy of the section string name S with all
499 attributes stripped off, and an asterisk prepended (for assemble_name). */
502 stripattributes (const char *s)
504 char *stripped = XNEWVEC (char, strlen (s) + 2);
509 while (*s && *s != ',')
516 /* MEM is a memory reference for the register size table, each element of
517 which has mode MODE. Initialize column C as a return address column. */
520 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
522 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
523 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
524 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
527 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
529 static inline HOST_WIDE_INT
530 div_data_align (HOST_WIDE_INT off)
532 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
533 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
537 /* Return true if we need a signed version of a given opcode
538 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
541 need_data_align_sf_opcode (HOST_WIDE_INT off)
543 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
546 /* Generate code to initialize the register size table. */
549 expand_builtin_init_dwarf_reg_sizes (tree address)
552 enum machine_mode mode = TYPE_MODE (char_type_node);
553 rtx addr = expand_normal (address);
554 rtx mem = gen_rtx_MEM (BLKmode, addr);
555 bool wrote_return_column = false;
557 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
559 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
561 if (rnum < DWARF_FRAME_REGISTERS)
563 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
564 enum machine_mode save_mode = reg_raw_mode[i];
567 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
568 save_mode = choose_hard_reg_mode (i, 1, true);
569 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
571 if (save_mode == VOIDmode)
573 wrote_return_column = true;
575 size = GET_MODE_SIZE (save_mode);
579 emit_move_insn (adjust_address (mem, mode, offset),
580 gen_int_mode (size, mode));
584 if (!wrote_return_column)
585 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
587 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
588 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
591 targetm.init_dwarf_reg_sizes_extra (address);
594 /* Convert a DWARF call frame info. operation to its string name */
597 dwarf_cfi_name (unsigned int cfi_opc)
601 case DW_CFA_advance_loc:
602 return "DW_CFA_advance_loc";
604 return "DW_CFA_offset";
606 return "DW_CFA_restore";
610 return "DW_CFA_set_loc";
611 case DW_CFA_advance_loc1:
612 return "DW_CFA_advance_loc1";
613 case DW_CFA_advance_loc2:
614 return "DW_CFA_advance_loc2";
615 case DW_CFA_advance_loc4:
616 return "DW_CFA_advance_loc4";
617 case DW_CFA_offset_extended:
618 return "DW_CFA_offset_extended";
619 case DW_CFA_restore_extended:
620 return "DW_CFA_restore_extended";
621 case DW_CFA_undefined:
622 return "DW_CFA_undefined";
623 case DW_CFA_same_value:
624 return "DW_CFA_same_value";
625 case DW_CFA_register:
626 return "DW_CFA_register";
627 case DW_CFA_remember_state:
628 return "DW_CFA_remember_state";
629 case DW_CFA_restore_state:
630 return "DW_CFA_restore_state";
632 return "DW_CFA_def_cfa";
633 case DW_CFA_def_cfa_register:
634 return "DW_CFA_def_cfa_register";
635 case DW_CFA_def_cfa_offset:
636 return "DW_CFA_def_cfa_offset";
639 case DW_CFA_def_cfa_expression:
640 return "DW_CFA_def_cfa_expression";
641 case DW_CFA_expression:
642 return "DW_CFA_expression";
643 case DW_CFA_offset_extended_sf:
644 return "DW_CFA_offset_extended_sf";
645 case DW_CFA_def_cfa_sf:
646 return "DW_CFA_def_cfa_sf";
647 case DW_CFA_def_cfa_offset_sf:
648 return "DW_CFA_def_cfa_offset_sf";
650 /* SGI/MIPS specific */
651 case DW_CFA_MIPS_advance_loc8:
652 return "DW_CFA_MIPS_advance_loc8";
655 case DW_CFA_GNU_window_save:
656 return "DW_CFA_GNU_window_save";
657 case DW_CFA_GNU_args_size:
658 return "DW_CFA_GNU_args_size";
659 case DW_CFA_GNU_negative_offset_extended:
660 return "DW_CFA_GNU_negative_offset_extended";
663 return "DW_CFA_<unknown>";
667 /* Return a pointer to a newly allocated Call Frame Instruction. */
669 static inline dw_cfi_ref
672 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
674 cfi->dw_cfi_next = NULL;
675 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
676 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
681 /* Add a Call Frame Instruction to list of instructions. */
684 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
687 dw_fde_ref fde = current_fde ();
689 /* When DRAP is used, CFA is defined with an expression. Redefine
690 CFA may lead to a different CFA value. */
691 /* ??? Of course, this heuristic fails when we're annotating epilogues,
692 because of course we'll always want to redefine the CFA back to the
693 stack pointer on the way out. Where should we move this check? */
694 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
695 switch (cfi->dw_cfi_opc)
697 case DW_CFA_def_cfa_register:
698 case DW_CFA_def_cfa_offset:
699 case DW_CFA_def_cfa_offset_sf:
701 case DW_CFA_def_cfa_sf:
708 /* Find the end of the chain. */
709 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
715 /* Generate a new label for the CFI info to refer to. FORCE is true
716 if a label needs to be output even when using .cfi_* directives. */
719 dwarf2out_cfi_label (bool force)
721 static char label[20];
723 if (!force && dwarf2out_do_cfi_asm ())
725 /* In this case, we will be emitting the asm directive instead of
726 the label, so just return a placeholder to keep the rest of the
728 strcpy (label, "<do not output>");
732 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
733 ASM_OUTPUT_LABEL (asm_out_file, label);
739 /* True if remember_state should be emitted before following CFI directive. */
740 static bool emit_cfa_remember;
742 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
743 or to the CIE if LABEL is NULL. */
746 add_fde_cfi (const char *label, dw_cfi_ref cfi)
748 dw_cfi_ref *list_head;
750 if (emit_cfa_remember)
752 dw_cfi_ref cfi_remember;
754 /* Emit the state save. */
755 emit_cfa_remember = false;
756 cfi_remember = new_cfi ();
757 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
758 add_fde_cfi (label, cfi_remember);
761 list_head = &cie_cfi_head;
763 if (dwarf2out_do_cfi_asm ())
767 dw_fde_ref fde = current_fde ();
769 gcc_assert (fde != NULL);
771 /* We still have to add the cfi to the list so that lookup_cfa
772 works later on. When -g2 and above we even need to force
773 emitting of CFI labels and add to list a DW_CFA_set_loc for
774 convert_cfa_to_fb_loc_list purposes. If we're generating
775 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
776 convert_cfa_to_fb_loc_list. */
777 if (dwarf_version == 2
778 && debug_info_level > DINFO_LEVEL_TERSE
779 && (write_symbols == DWARF2_DEBUG
780 || write_symbols == VMS_AND_DWARF2_DEBUG))
782 switch (cfi->dw_cfi_opc)
784 case DW_CFA_def_cfa_offset:
785 case DW_CFA_def_cfa_offset_sf:
786 case DW_CFA_def_cfa_register:
788 case DW_CFA_def_cfa_sf:
789 case DW_CFA_def_cfa_expression:
790 case DW_CFA_restore_state:
791 if (*label == 0 || strcmp (label, "<do not output>") == 0)
792 label = dwarf2out_cfi_label (true);
794 if (fde->dw_fde_current_label == NULL
795 || strcmp (label, fde->dw_fde_current_label) != 0)
799 label = xstrdup (label);
801 /* Set the location counter to the new label. */
803 /* It doesn't metter whether DW_CFA_set_loc
804 or DW_CFA_advance_loc4 is added here, those aren't
805 emitted into assembly, only looked up by
806 convert_cfa_to_fb_loc_list. */
807 xcfi->dw_cfi_opc = DW_CFA_set_loc;
808 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
809 add_cfi (&fde->dw_fde_cfi, xcfi);
810 fde->dw_fde_current_label = label;
818 output_cfi_directive (cfi);
820 list_head = &fde->dw_fde_cfi;
822 /* ??? If this is a CFI for the CIE, we don't emit. This
823 assumes that the standard CIE contents that the assembler
824 uses matches the standard CIE contents that the compiler
825 uses. This is probably a bad assumption. I'm not quite
826 sure how to address this for now. */
830 dw_fde_ref fde = current_fde ();
832 gcc_assert (fde != NULL);
835 label = dwarf2out_cfi_label (false);
837 if (fde->dw_fde_current_label == NULL
838 || strcmp (label, fde->dw_fde_current_label) != 0)
842 label = xstrdup (label);
844 /* Set the location counter to the new label. */
846 /* If we have a current label, advance from there, otherwise
847 set the location directly using set_loc. */
848 xcfi->dw_cfi_opc = fde->dw_fde_current_label
849 ? DW_CFA_advance_loc4
851 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
852 add_cfi (&fde->dw_fde_cfi, xcfi);
854 fde->dw_fde_current_label = label;
857 list_head = &fde->dw_fde_cfi;
860 add_cfi (list_head, cfi);
863 /* Subroutine of lookup_cfa. */
866 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
868 switch (cfi->dw_cfi_opc)
870 case DW_CFA_def_cfa_offset:
871 case DW_CFA_def_cfa_offset_sf:
872 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
874 case DW_CFA_def_cfa_register:
875 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
878 case DW_CFA_def_cfa_sf:
879 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
880 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
882 case DW_CFA_def_cfa_expression:
883 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
886 case DW_CFA_remember_state:
887 gcc_assert (!remember->in_use);
889 remember->in_use = 1;
891 case DW_CFA_restore_state:
892 gcc_assert (remember->in_use);
894 remember->in_use = 0;
902 /* Find the previous value for the CFA. */
905 lookup_cfa (dw_cfa_location *loc)
909 dw_cfa_location remember;
911 memset (loc, 0, sizeof (*loc));
912 loc->reg = INVALID_REGNUM;
915 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
916 lookup_cfa_1 (cfi, loc, &remember);
918 fde = current_fde ();
920 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
921 lookup_cfa_1 (cfi, loc, &remember);
924 /* The current rule for calculating the DWARF2 canonical frame address. */
925 static dw_cfa_location cfa;
927 /* The register used for saving registers to the stack, and its offset
929 static dw_cfa_location cfa_store;
931 /* The current save location around an epilogue. */
932 static dw_cfa_location cfa_remember;
934 /* The running total of the size of arguments pushed onto the stack. */
935 static HOST_WIDE_INT args_size;
937 /* The last args_size we actually output. */
938 static HOST_WIDE_INT old_args_size;
940 /* Entry point to update the canonical frame address (CFA).
941 LABEL is passed to add_fde_cfi. The value of CFA is now to be
942 calculated from REG+OFFSET. */
945 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
952 def_cfa_1 (label, &loc);
955 /* Determine if two dw_cfa_location structures define the same data. */
958 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
960 return (loc1->reg == loc2->reg
961 && loc1->offset == loc2->offset
962 && loc1->indirect == loc2->indirect
963 && (loc1->indirect == 0
964 || loc1->base_offset == loc2->base_offset));
967 /* This routine does the actual work. The CFA is now calculated from
968 the dw_cfa_location structure. */
971 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
974 dw_cfa_location old_cfa, loc;
979 if (cfa_store.reg == loc.reg && loc.indirect == 0)
980 cfa_store.offset = loc.offset;
982 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
983 lookup_cfa (&old_cfa);
985 /* If nothing changed, no need to issue any call frame instructions. */
986 if (cfa_equal_p (&loc, &old_cfa))
991 if (loc.reg == old_cfa.reg && !loc.indirect)
993 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
994 the CFA register did not change but the offset did. The data
995 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
996 in the assembler via the .cfi_def_cfa_offset directive. */
997 if (need_data_align_sf_opcode (loc.offset))
998 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1000 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1001 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1004 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1005 else if (loc.offset == old_cfa.offset
1006 && old_cfa.reg != INVALID_REGNUM
1009 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1010 indicating the CFA register has changed to <register> but the
1011 offset has not changed. */
1012 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1013 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1017 else if (loc.indirect == 0)
1019 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1020 indicating the CFA register has changed to <register> with
1021 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1022 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1024 if (need_data_align_sf_opcode (loc.offset))
1025 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1027 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1028 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1029 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1033 /* Construct a DW_CFA_def_cfa_expression instruction to
1034 calculate the CFA using a full location expression since no
1035 register-offset pair is available. */
1036 struct dw_loc_descr_struct *loc_list;
1038 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1039 loc_list = build_cfa_loc (&loc, 0);
1040 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1043 add_fde_cfi (label, cfi);
1046 /* Add the CFI for saving a register. REG is the CFA column number.
1047 LABEL is passed to add_fde_cfi.
1048 If SREG is -1, the register is saved at OFFSET from the CFA;
1049 otherwise it is saved in SREG. */
1052 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1054 dw_cfi_ref cfi = new_cfi ();
1055 dw_fde_ref fde = current_fde ();
1057 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1059 /* When stack is aligned, store REG using DW_CFA_expression with
1062 && fde->stack_realign
1063 && sreg == INVALID_REGNUM)
1065 cfi->dw_cfi_opc = DW_CFA_expression;
1066 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1067 cfi->dw_cfi_oprnd1.dw_cfi_loc
1068 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1070 else if (sreg == INVALID_REGNUM)
1072 if (need_data_align_sf_opcode (offset))
1073 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1074 else if (reg & ~0x3f)
1075 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1077 cfi->dw_cfi_opc = DW_CFA_offset;
1078 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1080 else if (sreg == reg)
1081 cfi->dw_cfi_opc = DW_CFA_same_value;
1084 cfi->dw_cfi_opc = DW_CFA_register;
1085 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1088 add_fde_cfi (label, cfi);
1091 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1092 This CFI tells the unwinder that it needs to restore the window registers
1093 from the previous frame's window save area.
1095 ??? Perhaps we should note in the CIE where windows are saved (instead of
1096 assuming 0(cfa)) and what registers are in the window. */
1099 dwarf2out_window_save (const char *label)
1101 dw_cfi_ref cfi = new_cfi ();
1103 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1104 add_fde_cfi (label, cfi);
1107 /* Add a CFI to update the running total of the size of arguments
1108 pushed onto the stack. */
1111 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1115 if (size == old_args_size)
1118 old_args_size = size;
1121 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1122 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1123 add_fde_cfi (label, cfi);
1126 /* Entry point for saving a register to the stack. REG is the GCC register
1127 number. LABEL and OFFSET are passed to reg_save. */
1130 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1132 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1135 /* Entry point for saving the return address in the stack.
1136 LABEL and OFFSET are passed to reg_save. */
1139 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1141 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1144 /* Entry point for saving the return address in a register.
1145 LABEL and SREG are passed to reg_save. */
1148 dwarf2out_return_reg (const char *label, unsigned int sreg)
1150 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1153 #ifdef DWARF2_UNWIND_INFO
1154 /* Record the initial position of the return address. RTL is
1155 INCOMING_RETURN_ADDR_RTX. */
1158 initial_return_save (rtx rtl)
1160 unsigned int reg = INVALID_REGNUM;
1161 HOST_WIDE_INT offset = 0;
1163 switch (GET_CODE (rtl))
1166 /* RA is in a register. */
1167 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1171 /* RA is on the stack. */
1172 rtl = XEXP (rtl, 0);
1173 switch (GET_CODE (rtl))
1176 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1181 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1182 offset = INTVAL (XEXP (rtl, 1));
1186 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1187 offset = -INTVAL (XEXP (rtl, 1));
1197 /* The return address is at some offset from any value we can
1198 actually load. For instance, on the SPARC it is in %i7+8. Just
1199 ignore the offset for now; it doesn't matter for unwinding frames. */
1200 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1201 initial_return_save (XEXP (rtl, 0));
1208 if (reg != DWARF_FRAME_RETURN_COLUMN)
1209 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1213 /* Given a SET, calculate the amount of stack adjustment it
1216 static HOST_WIDE_INT
1217 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1218 HOST_WIDE_INT cur_offset)
1220 const_rtx src = SET_SRC (pattern);
1221 const_rtx dest = SET_DEST (pattern);
1222 HOST_WIDE_INT offset = 0;
1225 if (dest == stack_pointer_rtx)
1227 code = GET_CODE (src);
1229 /* Assume (set (reg sp) (reg whatever)) sets args_size
1231 if (code == REG && src != stack_pointer_rtx)
1233 offset = -cur_args_size;
1234 #ifndef STACK_GROWS_DOWNWARD
1237 return offset - cur_offset;
1240 if (! (code == PLUS || code == MINUS)
1241 || XEXP (src, 0) != stack_pointer_rtx
1242 || !CONST_INT_P (XEXP (src, 1)))
1245 /* (set (reg sp) (plus (reg sp) (const_int))) */
1246 offset = INTVAL (XEXP (src, 1));
1252 if (MEM_P (src) && !MEM_P (dest))
1256 /* (set (mem (pre_dec (reg sp))) (foo)) */
1257 src = XEXP (dest, 0);
1258 code = GET_CODE (src);
1264 if (XEXP (src, 0) == stack_pointer_rtx)
1266 rtx val = XEXP (XEXP (src, 1), 1);
1267 /* We handle only adjustments by constant amount. */
1268 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1269 && CONST_INT_P (val));
1270 offset = -INTVAL (val);
1277 if (XEXP (src, 0) == stack_pointer_rtx)
1279 offset = GET_MODE_SIZE (GET_MODE (dest));
1286 if (XEXP (src, 0) == stack_pointer_rtx)
1288 offset = -GET_MODE_SIZE (GET_MODE (dest));
1303 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1304 indexed by INSN_UID. */
1306 static HOST_WIDE_INT *barrier_args_size;
1308 /* Helper function for compute_barrier_args_size. Handle one insn. */
1310 static HOST_WIDE_INT
1311 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1312 VEC (rtx, heap) **next)
1314 HOST_WIDE_INT offset = 0;
1317 if (! RTX_FRAME_RELATED_P (insn))
1319 if (prologue_epilogue_contains (insn))
1321 else if (GET_CODE (PATTERN (insn)) == SET)
1322 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1323 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1324 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1326 /* There may be stack adjustments inside compound insns. Search
1328 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1329 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1330 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1331 cur_args_size, offset);
1336 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1340 expr = XEXP (expr, 0);
1341 if (GET_CODE (expr) == PARALLEL
1342 || GET_CODE (expr) == SEQUENCE)
1343 for (i = 1; i < XVECLEN (expr, 0); i++)
1345 rtx elem = XVECEXP (expr, 0, i);
1347 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1348 offset += stack_adjust_offset (elem, cur_args_size, offset);
1353 #ifndef STACK_GROWS_DOWNWARD
1357 cur_args_size += offset;
1358 if (cur_args_size < 0)
1363 rtx dest = JUMP_LABEL (insn);
1367 if (barrier_args_size [INSN_UID (dest)] < 0)
1369 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1370 VEC_safe_push (rtx, heap, *next, dest);
1375 return cur_args_size;
1378 /* Walk the whole function and compute args_size on BARRIERs. */
1381 compute_barrier_args_size (void)
1383 int max_uid = get_max_uid (), i;
1385 VEC (rtx, heap) *worklist, *next, *tmp;
1387 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1388 for (i = 0; i < max_uid; i++)
1389 barrier_args_size[i] = -1;
1391 worklist = VEC_alloc (rtx, heap, 20);
1392 next = VEC_alloc (rtx, heap, 20);
1393 insn = get_insns ();
1394 barrier_args_size[INSN_UID (insn)] = 0;
1395 VEC_quick_push (rtx, worklist, insn);
1398 while (!VEC_empty (rtx, worklist))
1400 rtx prev, body, first_insn;
1401 HOST_WIDE_INT cur_args_size;
1403 first_insn = insn = VEC_pop (rtx, worklist);
1404 cur_args_size = barrier_args_size[INSN_UID (insn)];
1405 prev = prev_nonnote_insn (insn);
1406 if (prev && BARRIER_P (prev))
1407 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1409 for (; insn; insn = NEXT_INSN (insn))
1411 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1413 if (BARRIER_P (insn))
1418 if (insn == first_insn)
1420 else if (barrier_args_size[INSN_UID (insn)] < 0)
1422 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1427 /* The insns starting with this label have been
1428 already scanned or are in the worklist. */
1433 body = PATTERN (insn);
1434 if (GET_CODE (body) == SEQUENCE)
1436 HOST_WIDE_INT dest_args_size = cur_args_size;
1437 for (i = 1; i < XVECLEN (body, 0); i++)
1438 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1439 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1441 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1442 dest_args_size, &next);
1445 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1446 cur_args_size, &next);
1448 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1449 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1450 dest_args_size, &next);
1453 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1454 cur_args_size, &next);
1458 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1462 if (VEC_empty (rtx, next))
1465 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1469 VEC_truncate (rtx, next, 0);
1472 VEC_free (rtx, heap, worklist);
1473 VEC_free (rtx, heap, next);
1477 /* Check INSN to see if it looks like a push or a stack adjustment, and
1478 make a note of it if it does. EH uses this information to find out how
1479 much extra space it needs to pop off the stack. */
1482 dwarf2out_stack_adjust (rtx insn, bool after_p)
1484 HOST_WIDE_INT offset;
1488 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1489 with this function. Proper support would require all frame-related
1490 insns to be marked, and to be able to handle saving state around
1491 epilogues textually in the middle of the function. */
1492 if (prologue_epilogue_contains (insn))
1495 /* If INSN is an instruction from target of an annulled branch, the
1496 effects are for the target only and so current argument size
1497 shouldn't change at all. */
1499 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1500 && INSN_FROM_TARGET_P (insn))
1503 /* If only calls can throw, and we have a frame pointer,
1504 save up adjustments until we see the CALL_INSN. */
1505 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1507 if (CALL_P (insn) && !after_p)
1509 /* Extract the size of the args from the CALL rtx itself. */
1510 insn = PATTERN (insn);
1511 if (GET_CODE (insn) == PARALLEL)
1512 insn = XVECEXP (insn, 0, 0);
1513 if (GET_CODE (insn) == SET)
1514 insn = SET_SRC (insn);
1515 gcc_assert (GET_CODE (insn) == CALL);
1516 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1521 if (CALL_P (insn) && !after_p)
1523 if (!flag_asynchronous_unwind_tables)
1524 dwarf2out_args_size ("", args_size);
1527 else if (BARRIER_P (insn))
1529 /* Don't call compute_barrier_args_size () if the only
1530 BARRIER is at the end of function. */
1531 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1532 compute_barrier_args_size ();
1533 if (barrier_args_size == NULL)
1537 offset = barrier_args_size[INSN_UID (insn)];
1542 offset -= args_size;
1543 #ifndef STACK_GROWS_DOWNWARD
1547 else if (GET_CODE (PATTERN (insn)) == SET)
1548 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1549 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1550 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1552 /* There may be stack adjustments inside compound insns. Search
1554 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1555 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1556 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1565 label = dwarf2out_cfi_label (false);
1566 dwarf2out_args_size_adjust (offset, label);
1569 /* Adjust args_size based on stack adjustment OFFSET. */
1572 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1574 if (cfa.reg == STACK_POINTER_REGNUM)
1575 cfa.offset += offset;
1577 if (cfa_store.reg == STACK_POINTER_REGNUM)
1578 cfa_store.offset += offset;
1580 #ifndef STACK_GROWS_DOWNWARD
1584 args_size += offset;
1588 def_cfa_1 (label, &cfa);
1589 if (flag_asynchronous_unwind_tables)
1590 dwarf2out_args_size (label, args_size);
1595 /* We delay emitting a register save until either (a) we reach the end
1596 of the prologue or (b) the register is clobbered. This clusters
1597 register saves so that there are fewer pc advances. */
1599 struct GTY(()) queued_reg_save {
1600 struct queued_reg_save *next;
1602 HOST_WIDE_INT cfa_offset;
1606 static GTY(()) struct queued_reg_save *queued_reg_saves;
1608 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1609 struct GTY(()) reg_saved_in_data {
1614 /* A list of registers saved in other registers.
1615 The list intentionally has a small maximum capacity of 4; if your
1616 port needs more than that, you might consider implementing a
1617 more efficient data structure. */
1618 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1619 static GTY(()) size_t num_regs_saved_in_regs;
1621 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1622 static const char *last_reg_save_label;
1624 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1625 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1628 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1630 struct queued_reg_save *q;
1632 /* Duplicates waste space, but it's also necessary to remove them
1633 for correctness, since the queue gets output in reverse
1635 for (q = queued_reg_saves; q != NULL; q = q->next)
1636 if (REGNO (q->reg) == REGNO (reg))
1641 q = GGC_NEW (struct queued_reg_save);
1642 q->next = queued_reg_saves;
1643 queued_reg_saves = q;
1647 q->cfa_offset = offset;
1648 q->saved_reg = sreg;
1650 last_reg_save_label = label;
1653 /* Output all the entries in QUEUED_REG_SAVES. */
1656 flush_queued_reg_saves (void)
1658 struct queued_reg_save *q;
1660 for (q = queued_reg_saves; q; q = q->next)
1663 unsigned int reg, sreg;
1665 for (i = 0; i < num_regs_saved_in_regs; i++)
1666 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1668 if (q->saved_reg && i == num_regs_saved_in_regs)
1670 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1671 num_regs_saved_in_regs++;
1673 if (i != num_regs_saved_in_regs)
1675 regs_saved_in_regs[i].orig_reg = q->reg;
1676 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1679 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1681 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1683 sreg = INVALID_REGNUM;
1684 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1687 queued_reg_saves = NULL;
1688 last_reg_save_label = NULL;
1691 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1692 location for? Or, does it clobber a register which we've previously
1693 said that some other register is saved in, and for which we now
1694 have a new location for? */
1697 clobbers_queued_reg_save (const_rtx insn)
1699 struct queued_reg_save *q;
1701 for (q = queued_reg_saves; q; q = q->next)
1704 if (modified_in_p (q->reg, insn))
1706 for (i = 0; i < num_regs_saved_in_regs; i++)
1707 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1708 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1715 /* Entry point for saving the first register into the second. */
1718 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1721 unsigned int regno, sregno;
1723 for (i = 0; i < num_regs_saved_in_regs; i++)
1724 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1726 if (i == num_regs_saved_in_regs)
1728 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1729 num_regs_saved_in_regs++;
1731 regs_saved_in_regs[i].orig_reg = reg;
1732 regs_saved_in_regs[i].saved_in_reg = sreg;
1734 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1735 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1736 reg_save (label, regno, sregno, 0);
1739 /* What register, if any, is currently saved in REG? */
1742 reg_saved_in (rtx reg)
1744 unsigned int regn = REGNO (reg);
1746 struct queued_reg_save *q;
1748 for (q = queued_reg_saves; q; q = q->next)
1749 if (q->saved_reg && regn == REGNO (q->saved_reg))
1752 for (i = 0; i < num_regs_saved_in_regs; i++)
1753 if (regs_saved_in_regs[i].saved_in_reg
1754 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1755 return regs_saved_in_regs[i].orig_reg;
1761 /* A temporary register holding an integral value used in adjusting SP
1762 or setting up the store_reg. The "offset" field holds the integer
1763 value, not an offset. */
1764 static dw_cfa_location cfa_temp;
1766 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1769 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1771 memset (&cfa, 0, sizeof (cfa));
1773 switch (GET_CODE (pat))
1776 cfa.reg = REGNO (XEXP (pat, 0));
1777 cfa.offset = INTVAL (XEXP (pat, 1));
1781 cfa.reg = REGNO (pat);
1785 /* Recurse and define an expression. */
1789 def_cfa_1 (label, &cfa);
1792 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1795 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1799 gcc_assert (GET_CODE (pat) == SET);
1800 dest = XEXP (pat, 0);
1801 src = XEXP (pat, 1);
1803 switch (GET_CODE (src))
1806 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1807 cfa.offset -= INTVAL (XEXP (src, 1));
1817 cfa.reg = REGNO (dest);
1818 gcc_assert (cfa.indirect == 0);
1820 def_cfa_1 (label, &cfa);
1823 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1826 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1828 HOST_WIDE_INT offset;
1829 rtx src, addr, span;
1831 src = XEXP (set, 1);
1832 addr = XEXP (set, 0);
1833 gcc_assert (MEM_P (addr));
1834 addr = XEXP (addr, 0);
1836 /* As documented, only consider extremely simple addresses. */
1837 switch (GET_CODE (addr))
1840 gcc_assert (REGNO (addr) == cfa.reg);
1841 offset = -cfa.offset;
1844 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1845 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1851 span = targetm.dwarf_register_span (src);
1853 /* ??? We'd like to use queue_reg_save, but we need to come up with
1854 a different flushing heuristic for epilogues. */
1856 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1859 /* We have a PARALLEL describing where the contents of SRC live.
1860 Queue register saves for each piece of the PARALLEL. */
1863 HOST_WIDE_INT span_offset = offset;
1865 gcc_assert (GET_CODE (span) == PARALLEL);
1867 limit = XVECLEN (span, 0);
1868 for (par_index = 0; par_index < limit; par_index++)
1870 rtx elem = XVECEXP (span, 0, par_index);
1872 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1873 INVALID_REGNUM, span_offset);
1874 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1879 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1882 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1885 unsigned sregno, dregno;
1887 src = XEXP (set, 1);
1888 dest = XEXP (set, 0);
1891 sregno = DWARF_FRAME_RETURN_COLUMN;
1893 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1895 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1897 /* ??? We'd like to use queue_reg_save, but we need to come up with
1898 a different flushing heuristic for epilogues. */
1899 reg_save (label, sregno, dregno, 0);
1902 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1905 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1907 dw_cfi_ref cfi = new_cfi ();
1908 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1910 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1911 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1913 add_fde_cfi (label, cfi);
1916 /* Record call frame debugging information for an expression EXPR,
1917 which either sets SP or FP (adjusting how we calculate the frame
1918 address) or saves a register to the stack or another register.
1919 LABEL indicates the address of EXPR.
1921 This function encodes a state machine mapping rtxes to actions on
1922 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1923 users need not read the source code.
1925 The High-Level Picture
1927 Changes in the register we use to calculate the CFA: Currently we
1928 assume that if you copy the CFA register into another register, we
1929 should take the other one as the new CFA register; this seems to
1930 work pretty well. If it's wrong for some target, it's simple
1931 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1933 Changes in the register we use for saving registers to the stack:
1934 This is usually SP, but not always. Again, we deduce that if you
1935 copy SP into another register (and SP is not the CFA register),
1936 then the new register is the one we will be using for register
1937 saves. This also seems to work.
1939 Register saves: There's not much guesswork about this one; if
1940 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1941 register save, and the register used to calculate the destination
1942 had better be the one we think we're using for this purpose.
1943 It's also assumed that a copy from a call-saved register to another
1944 register is saving that register if RTX_FRAME_RELATED_P is set on
1945 that instruction. If the copy is from a call-saved register to
1946 the *same* register, that means that the register is now the same
1947 value as in the caller.
1949 Except: If the register being saved is the CFA register, and the
1950 offset is nonzero, we are saving the CFA, so we assume we have to
1951 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1952 the intent is to save the value of SP from the previous frame.
1954 In addition, if a register has previously been saved to a different
1957 Invariants / Summaries of Rules
1959 cfa current rule for calculating the CFA. It usually
1960 consists of a register and an offset.
1961 cfa_store register used by prologue code to save things to the stack
1962 cfa_store.offset is the offset from the value of
1963 cfa_store.reg to the actual CFA
1964 cfa_temp register holding an integral value. cfa_temp.offset
1965 stores the value, which will be used to adjust the
1966 stack pointer. cfa_temp is also used like cfa_store,
1967 to track stores to the stack via fp or a temp reg.
1969 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1970 with cfa.reg as the first operand changes the cfa.reg and its
1971 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1974 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1975 expression yielding a constant. This sets cfa_temp.reg
1976 and cfa_temp.offset.
1978 Rule 5: Create a new register cfa_store used to save items to the
1981 Rules 10-14: Save a register to the stack. Define offset as the
1982 difference of the original location and cfa_store's
1983 location (or cfa_temp's location if cfa_temp is used).
1985 Rules 16-20: If AND operation happens on sp in prologue, we assume
1986 stack is realigned. We will use a group of DW_OP_XXX
1987 expressions to represent the location of the stored
1988 register instead of CFA+offset.
1992 "{a,b}" indicates a choice of a xor b.
1993 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1996 (set <reg1> <reg2>:cfa.reg)
1997 effects: cfa.reg = <reg1>
1998 cfa.offset unchanged
1999 cfa_temp.reg = <reg1>
2000 cfa_temp.offset = cfa.offset
2003 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2004 {<const_int>,<reg>:cfa_temp.reg}))
2005 effects: cfa.reg = sp if fp used
2006 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2007 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2008 if cfa_store.reg==sp
2011 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2012 effects: cfa.reg = fp
2013 cfa_offset += +/- <const_int>
2016 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2017 constraints: <reg1> != fp
2019 effects: cfa.reg = <reg1>
2020 cfa_temp.reg = <reg1>
2021 cfa_temp.offset = cfa.offset
2024 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2025 constraints: <reg1> != fp
2027 effects: cfa_store.reg = <reg1>
2028 cfa_store.offset = cfa.offset - cfa_temp.offset
2031 (set <reg> <const_int>)
2032 effects: cfa_temp.reg = <reg>
2033 cfa_temp.offset = <const_int>
2036 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2037 effects: cfa_temp.reg = <reg1>
2038 cfa_temp.offset |= <const_int>
2041 (set <reg> (high <exp>))
2045 (set <reg> (lo_sum <exp> <const_int>))
2046 effects: cfa_temp.reg = <reg>
2047 cfa_temp.offset = <const_int>
2050 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2051 effects: cfa_store.offset -= <const_int>
2052 cfa.offset = cfa_store.offset if cfa.reg == sp
2054 cfa.base_offset = -cfa_store.offset
2057 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2058 effects: cfa_store.offset += -/+ mode_size(mem)
2059 cfa.offset = cfa_store.offset if cfa.reg == sp
2061 cfa.base_offset = -cfa_store.offset
2064 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2067 effects: cfa.reg = <reg1>
2068 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2071 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2072 effects: cfa.reg = <reg1>
2073 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2076 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2077 effects: cfa.reg = <reg1>
2078 cfa.base_offset = -cfa_temp.offset
2079 cfa_temp.offset -= mode_size(mem)
2082 (set <reg> {unspec, unspec_volatile})
2083 effects: target-dependent
2086 (set sp (and: sp <const_int>))
2087 constraints: cfa_store.reg == sp
2088 effects: current_fde.stack_realign = 1
2089 cfa_store.offset = 0
2090 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2093 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2094 effects: cfa_store.offset += -/+ mode_size(mem)
2097 (set (mem ({pre_inc, pre_dec} sp)) fp)
2098 constraints: fde->stack_realign == 1
2099 effects: cfa_store.offset = 0
2100 cfa.reg != HARD_FRAME_POINTER_REGNUM
2103 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2104 constraints: fde->stack_realign == 1
2106 && cfa.indirect == 0
2107 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2108 effects: Use DW_CFA_def_cfa_expression to define cfa
2109 cfa.reg == fde->drap_reg
2112 (set reg fde->drap_reg)
2113 constraints: fde->vdrap_reg == INVALID_REGNUM
2114 effects: fde->vdrap_reg = reg.
2115 (set mem fde->drap_reg)
2116 constraints: fde->drap_reg_saved == 1
2120 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2122 rtx src, dest, span;
2123 HOST_WIDE_INT offset;
2126 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2127 the PARALLEL independently. The first element is always processed if
2128 it is a SET. This is for backward compatibility. Other elements
2129 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2130 flag is set in them. */
2131 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2134 int limit = XVECLEN (expr, 0);
2137 /* PARALLELs have strict read-modify-write semantics, so we
2138 ought to evaluate every rvalue before changing any lvalue.
2139 It's cumbersome to do that in general, but there's an
2140 easy approximation that is enough for all current users:
2141 handle register saves before register assignments. */
2142 if (GET_CODE (expr) == PARALLEL)
2143 for (par_index = 0; par_index < limit; par_index++)
2145 elem = XVECEXP (expr, 0, par_index);
2146 if (GET_CODE (elem) == SET
2147 && MEM_P (SET_DEST (elem))
2148 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2149 dwarf2out_frame_debug_expr (elem, label);
2152 for (par_index = 0; par_index < limit; par_index++)
2154 elem = XVECEXP (expr, 0, par_index);
2155 if (GET_CODE (elem) == SET
2156 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2157 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2158 dwarf2out_frame_debug_expr (elem, label);
2159 else if (GET_CODE (elem) == SET
2161 && !RTX_FRAME_RELATED_P (elem))
2163 /* Stack adjustment combining might combine some post-prologue
2164 stack adjustment into a prologue stack adjustment. */
2165 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2168 dwarf2out_args_size_adjust (offset, label);
2174 gcc_assert (GET_CODE (expr) == SET);
2176 src = SET_SRC (expr);
2177 dest = SET_DEST (expr);
2181 rtx rsi = reg_saved_in (src);
2186 fde = current_fde ();
2190 && fde->drap_reg == REGNO (src)
2191 && (fde->drap_reg_saved
2195 /* If we are saving dynamic realign argument pointer to a
2196 register, the destination is virtual dynamic realign
2197 argument pointer. It may be used to access argument. */
2200 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2201 fde->vdrap_reg = REGNO (dest);
2206 switch (GET_CODE (dest))
2209 switch (GET_CODE (src))
2211 /* Setting FP from SP. */
2213 if (cfa.reg == (unsigned) REGNO (src))
2216 /* Update the CFA rule wrt SP or FP. Make sure src is
2217 relative to the current CFA register.
2219 We used to require that dest be either SP or FP, but the
2220 ARM copies SP to a temporary register, and from there to
2221 FP. So we just rely on the backends to only set
2222 RTX_FRAME_RELATED_P on appropriate insns. */
2223 cfa.reg = REGNO (dest);
2224 cfa_temp.reg = cfa.reg;
2225 cfa_temp.offset = cfa.offset;
2229 /* Saving a register in a register. */
2230 gcc_assert (!fixed_regs [REGNO (dest)]
2231 /* For the SPARC and its register window. */
2232 || (DWARF_FRAME_REGNUM (REGNO (src))
2233 == DWARF_FRAME_RETURN_COLUMN));
2235 /* After stack is aligned, we can only save SP in FP
2236 if drap register is used. In this case, we have
2237 to restore stack pointer with the CFA value and we
2238 don't generate this DWARF information. */
2240 && fde->stack_realign
2241 && REGNO (src) == STACK_POINTER_REGNUM)
2242 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2243 && fde->drap_reg != INVALID_REGNUM
2244 && cfa.reg != REGNO (src));
2246 queue_reg_save (label, src, dest, 0);
2253 if (dest == stack_pointer_rtx)
2257 switch (GET_CODE (XEXP (src, 1)))
2260 offset = INTVAL (XEXP (src, 1));
2263 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2265 offset = cfa_temp.offset;
2271 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2273 /* Restoring SP from FP in the epilogue. */
2274 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2275 cfa.reg = STACK_POINTER_REGNUM;
2277 else if (GET_CODE (src) == LO_SUM)
2278 /* Assume we've set the source reg of the LO_SUM from sp. */
2281 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2283 if (GET_CODE (src) != MINUS)
2285 if (cfa.reg == STACK_POINTER_REGNUM)
2286 cfa.offset += offset;
2287 if (cfa_store.reg == STACK_POINTER_REGNUM)
2288 cfa_store.offset += offset;
2290 else if (dest == hard_frame_pointer_rtx)
2293 /* Either setting the FP from an offset of the SP,
2294 or adjusting the FP */
2295 gcc_assert (frame_pointer_needed);
2297 gcc_assert (REG_P (XEXP (src, 0))
2298 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2299 && CONST_INT_P (XEXP (src, 1)));
2300 offset = INTVAL (XEXP (src, 1));
2301 if (GET_CODE (src) != MINUS)
2303 cfa.offset += offset;
2304 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2308 gcc_assert (GET_CODE (src) != MINUS);
2311 if (REG_P (XEXP (src, 0))
2312 && REGNO (XEXP (src, 0)) == cfa.reg
2313 && CONST_INT_P (XEXP (src, 1)))
2315 /* Setting a temporary CFA register that will be copied
2316 into the FP later on. */
2317 offset = - INTVAL (XEXP (src, 1));
2318 cfa.offset += offset;
2319 cfa.reg = REGNO (dest);
2320 /* Or used to save regs to the stack. */
2321 cfa_temp.reg = cfa.reg;
2322 cfa_temp.offset = cfa.offset;
2326 else if (REG_P (XEXP (src, 0))
2327 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2328 && XEXP (src, 1) == stack_pointer_rtx)
2330 /* Setting a scratch register that we will use instead
2331 of SP for saving registers to the stack. */
2332 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2333 cfa_store.reg = REGNO (dest);
2334 cfa_store.offset = cfa.offset - cfa_temp.offset;
2338 else if (GET_CODE (src) == LO_SUM
2339 && CONST_INT_P (XEXP (src, 1)))
2341 cfa_temp.reg = REGNO (dest);
2342 cfa_temp.offset = INTVAL (XEXP (src, 1));
2351 cfa_temp.reg = REGNO (dest);
2352 cfa_temp.offset = INTVAL (src);
2357 gcc_assert (REG_P (XEXP (src, 0))
2358 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2359 && CONST_INT_P (XEXP (src, 1)));
2361 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2362 cfa_temp.reg = REGNO (dest);
2363 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2366 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2367 which will fill in all of the bits. */
2374 case UNSPEC_VOLATILE:
2375 gcc_assert (targetm.dwarf_handle_frame_unspec);
2376 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2381 /* If this AND operation happens on stack pointer in prologue,
2382 we assume the stack is realigned and we extract the
2384 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2386 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2387 fde->stack_realign = 1;
2388 fde->stack_realignment = INTVAL (XEXP (src, 1));
2389 cfa_store.offset = 0;
2391 if (cfa.reg != STACK_POINTER_REGNUM
2392 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2393 fde->drap_reg = cfa.reg;
2401 def_cfa_1 (label, &cfa);
2406 /* Saving a register to the stack. Make sure dest is relative to the
2408 switch (GET_CODE (XEXP (dest, 0)))
2413 /* We can't handle variable size modifications. */
2414 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2416 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2418 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2419 && cfa_store.reg == STACK_POINTER_REGNUM);
2421 cfa_store.offset += offset;
2422 if (cfa.reg == STACK_POINTER_REGNUM)
2423 cfa.offset = cfa_store.offset;
2425 offset = -cfa_store.offset;
2431 offset = GET_MODE_SIZE (GET_MODE (dest));
2432 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2435 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2436 == STACK_POINTER_REGNUM)
2437 && cfa_store.reg == STACK_POINTER_REGNUM);
2439 cfa_store.offset += offset;
2441 /* Rule 18: If stack is aligned, we will use FP as a
2442 reference to represent the address of the stored
2445 && fde->stack_realign
2446 && src == hard_frame_pointer_rtx)
2448 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2449 cfa_store.offset = 0;
2452 if (cfa.reg == STACK_POINTER_REGNUM)
2453 cfa.offset = cfa_store.offset;
2455 offset = -cfa_store.offset;
2459 /* With an offset. */
2466 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2467 && REG_P (XEXP (XEXP (dest, 0), 0)));
2468 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2469 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2472 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2474 if (cfa_store.reg == (unsigned) regno)
2475 offset -= cfa_store.offset;
2478 gcc_assert (cfa_temp.reg == (unsigned) regno);
2479 offset -= cfa_temp.offset;
2485 /* Without an offset. */
2488 int regno = REGNO (XEXP (dest, 0));
2490 if (cfa_store.reg == (unsigned) regno)
2491 offset = -cfa_store.offset;
2494 gcc_assert (cfa_temp.reg == (unsigned) regno);
2495 offset = -cfa_temp.offset;
2502 gcc_assert (cfa_temp.reg
2503 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2504 offset = -cfa_temp.offset;
2505 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2513 /* If the source operand of this MEM operation is not a
2514 register, basically the source is return address. Here
2515 we only care how much stack grew and we don't save it. */
2519 if (REGNO (src) != STACK_POINTER_REGNUM
2520 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2521 && (unsigned) REGNO (src) == cfa.reg)
2523 /* We're storing the current CFA reg into the stack. */
2525 if (cfa.offset == 0)
2528 /* If stack is aligned, putting CFA reg into stack means
2529 we can no longer use reg + offset to represent CFA.
2530 Here we use DW_CFA_def_cfa_expression instead. The
2531 result of this expression equals to the original CFA
2534 && fde->stack_realign
2535 && cfa.indirect == 0
2536 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2538 dw_cfa_location cfa_exp;
2540 gcc_assert (fde->drap_reg == cfa.reg);
2542 cfa_exp.indirect = 1;
2543 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2544 cfa_exp.base_offset = offset;
2547 fde->drap_reg_saved = 1;
2549 def_cfa_1 (label, &cfa_exp);
2553 /* If the source register is exactly the CFA, assume
2554 we're saving SP like any other register; this happens
2556 def_cfa_1 (label, &cfa);
2557 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2562 /* Otherwise, we'll need to look in the stack to
2563 calculate the CFA. */
2564 rtx x = XEXP (dest, 0);
2568 gcc_assert (REG_P (x));
2570 cfa.reg = REGNO (x);
2571 cfa.base_offset = offset;
2573 def_cfa_1 (label, &cfa);
2578 def_cfa_1 (label, &cfa);
2580 span = targetm.dwarf_register_span (src);
2583 queue_reg_save (label, src, NULL_RTX, offset);
2586 /* We have a PARALLEL describing where the contents of SRC
2587 live. Queue register saves for each piece of the
2591 HOST_WIDE_INT span_offset = offset;
2593 gcc_assert (GET_CODE (span) == PARALLEL);
2595 limit = XVECLEN (span, 0);
2596 for (par_index = 0; par_index < limit; par_index++)
2598 rtx elem = XVECEXP (span, 0, par_index);
2600 queue_reg_save (label, elem, NULL_RTX, span_offset);
2601 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2612 /* Record call frame debugging information for INSN, which either
2613 sets SP or FP (adjusting how we calculate the frame address) or saves a
2614 register to the stack. If INSN is NULL_RTX, initialize our state.
2616 If AFTER_P is false, we're being called before the insn is emitted,
2617 otherwise after. Call instructions get invoked twice. */
2620 dwarf2out_frame_debug (rtx insn, bool after_p)
2624 bool handled_one = false;
2626 if (insn == NULL_RTX)
2630 /* Flush any queued register saves. */
2631 flush_queued_reg_saves ();
2633 /* Set up state for generating call frame debug info. */
2636 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2638 cfa.reg = STACK_POINTER_REGNUM;
2641 cfa_temp.offset = 0;
2643 for (i = 0; i < num_regs_saved_in_regs; i++)
2645 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2646 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2648 num_regs_saved_in_regs = 0;
2650 if (barrier_args_size)
2652 XDELETEVEC (barrier_args_size);
2653 barrier_args_size = NULL;
2658 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2659 flush_queued_reg_saves ();
2661 if (! RTX_FRAME_RELATED_P (insn))
2663 if (!ACCUMULATE_OUTGOING_ARGS)
2664 dwarf2out_stack_adjust (insn, after_p);
2668 label = dwarf2out_cfi_label (false);
2670 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2671 switch (REG_NOTE_KIND (note))
2673 case REG_FRAME_RELATED_EXPR:
2674 insn = XEXP (note, 0);
2677 case REG_CFA_DEF_CFA:
2678 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2682 case REG_CFA_ADJUST_CFA:
2687 if (GET_CODE (n) == PARALLEL)
2688 n = XVECEXP (n, 0, 0);
2690 dwarf2out_frame_debug_adjust_cfa (n, label);
2694 case REG_CFA_OFFSET:
2697 n = single_set (insn);
2698 dwarf2out_frame_debug_cfa_offset (n, label);
2702 case REG_CFA_REGISTER:
2707 if (GET_CODE (n) == PARALLEL)
2708 n = XVECEXP (n, 0, 0);
2710 dwarf2out_frame_debug_cfa_register (n, label);
2714 case REG_CFA_RESTORE:
2719 if (GET_CODE (n) == PARALLEL)
2720 n = XVECEXP (n, 0, 0);
2723 dwarf2out_frame_debug_cfa_restore (n, label);
2733 insn = PATTERN (insn);
2735 dwarf2out_frame_debug_expr (insn, label);
2738 /* Determine if we need to save and restore CFI information around this
2739 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2740 we do need to save/restore, then emit the save now, and insert a
2741 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2744 dwarf2out_begin_epilogue (rtx insn)
2746 bool saw_frp = false;
2749 /* Scan forward to the return insn, noticing if there are possible
2750 frame related insns. */
2751 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2756 /* Look for both regular and sibcalls to end the block. */
2757 if (returnjump_p (i))
2759 if (CALL_P (i) && SIBLING_CALL_P (i))
2762 if (RTX_FRAME_RELATED_P (i))
2766 /* If the port doesn't emit epilogue unwind info, we don't need a
2767 save/restore pair. */
2771 /* Otherwise, search forward to see if the return insn was the last
2772 basic block of the function. If so, we don't need save/restore. */
2773 gcc_assert (i != NULL);
2774 i = next_real_insn (i);
2778 /* Insert the restore before that next real insn in the stream, and before
2779 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2780 properly nested. This should be after any label or alignment. This
2781 will be pushed into the CFI stream by the function below. */
2784 rtx p = PREV_INSN (i);
2787 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2791 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2793 emit_cfa_remember = true;
2795 /* And emulate the state save. */
2796 gcc_assert (!cfa_remember.in_use);
2798 cfa_remember.in_use = 1;
2801 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2804 dwarf2out_frame_debug_restore_state (void)
2806 dw_cfi_ref cfi = new_cfi ();
2807 const char *label = dwarf2out_cfi_label (false);
2809 cfi->dw_cfi_opc = DW_CFA_restore_state;
2810 add_fde_cfi (label, cfi);
2812 gcc_assert (cfa_remember.in_use);
2814 cfa_remember.in_use = 0;
2819 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2820 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2821 (enum dwarf_call_frame_info cfi);
2823 static enum dw_cfi_oprnd_type
2824 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2829 case DW_CFA_GNU_window_save:
2830 case DW_CFA_remember_state:
2831 case DW_CFA_restore_state:
2832 return dw_cfi_oprnd_unused;
2834 case DW_CFA_set_loc:
2835 case DW_CFA_advance_loc1:
2836 case DW_CFA_advance_loc2:
2837 case DW_CFA_advance_loc4:
2838 case DW_CFA_MIPS_advance_loc8:
2839 return dw_cfi_oprnd_addr;
2842 case DW_CFA_offset_extended:
2843 case DW_CFA_def_cfa:
2844 case DW_CFA_offset_extended_sf:
2845 case DW_CFA_def_cfa_sf:
2846 case DW_CFA_restore:
2847 case DW_CFA_restore_extended:
2848 case DW_CFA_undefined:
2849 case DW_CFA_same_value:
2850 case DW_CFA_def_cfa_register:
2851 case DW_CFA_register:
2852 return dw_cfi_oprnd_reg_num;
2854 case DW_CFA_def_cfa_offset:
2855 case DW_CFA_GNU_args_size:
2856 case DW_CFA_def_cfa_offset_sf:
2857 return dw_cfi_oprnd_offset;
2859 case DW_CFA_def_cfa_expression:
2860 case DW_CFA_expression:
2861 return dw_cfi_oprnd_loc;
2868 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2869 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2870 (enum dwarf_call_frame_info cfi);
2872 static enum dw_cfi_oprnd_type
2873 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2877 case DW_CFA_def_cfa:
2878 case DW_CFA_def_cfa_sf:
2880 case DW_CFA_offset_extended_sf:
2881 case DW_CFA_offset_extended:
2882 return dw_cfi_oprnd_offset;
2884 case DW_CFA_register:
2885 return dw_cfi_oprnd_reg_num;
2888 return dw_cfi_oprnd_unused;
2892 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2894 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2895 switch to the data section instead, and write out a synthetic label
2899 switch_to_eh_frame_section (void)
2903 #ifdef EH_FRAME_SECTION_NAME
2904 if (eh_frame_section == 0)
2908 if (EH_TABLES_CAN_BE_READ_ONLY)
2914 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2916 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2918 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2920 flags = ((! flag_pic
2921 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2922 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2923 && (per_encoding & 0x70) != DW_EH_PE_absptr
2924 && (per_encoding & 0x70) != DW_EH_PE_aligned
2925 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2926 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2927 ? 0 : SECTION_WRITE);
2930 flags = SECTION_WRITE;
2931 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2935 if (eh_frame_section)
2936 switch_to_section (eh_frame_section);
2939 /* We have no special eh_frame section. Put the information in
2940 the data section and emit special labels to guide collect2. */
2941 switch_to_section (data_section);
2942 label = get_file_function_name ("F");
2943 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2944 targetm.asm_out.globalize_label (asm_out_file,
2945 IDENTIFIER_POINTER (label));
2946 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2950 /* Output a Call Frame Information opcode and its operand(s). */
2953 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2958 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2959 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2960 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2961 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2962 ((unsigned HOST_WIDE_INT)
2963 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2964 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2966 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2967 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2968 "DW_CFA_offset, column 0x%lx", r);
2969 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2970 dw2_asm_output_data_uleb128 (off, NULL);
2972 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2974 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2975 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2976 "DW_CFA_restore, column 0x%lx", r);
2980 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2981 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2983 switch (cfi->dw_cfi_opc)
2985 case DW_CFA_set_loc:
2987 dw2_asm_output_encoded_addr_rtx (
2988 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2989 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2992 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2993 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2994 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2997 case DW_CFA_advance_loc1:
2998 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2999 fde->dw_fde_current_label, NULL);
3000 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3003 case DW_CFA_advance_loc2:
3004 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3005 fde->dw_fde_current_label, NULL);
3006 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3009 case DW_CFA_advance_loc4:
3010 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3011 fde->dw_fde_current_label, NULL);
3012 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3015 case DW_CFA_MIPS_advance_loc8:
3016 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3017 fde->dw_fde_current_label, NULL);
3018 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3021 case DW_CFA_offset_extended:
3022 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3023 dw2_asm_output_data_uleb128 (r, NULL);
3024 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3025 dw2_asm_output_data_uleb128 (off, NULL);
3028 case DW_CFA_def_cfa:
3029 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3030 dw2_asm_output_data_uleb128 (r, NULL);
3031 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3034 case DW_CFA_offset_extended_sf:
3035 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3036 dw2_asm_output_data_uleb128 (r, NULL);
3037 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3038 dw2_asm_output_data_sleb128 (off, NULL);
3041 case DW_CFA_def_cfa_sf:
3042 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3043 dw2_asm_output_data_uleb128 (r, NULL);
3044 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3045 dw2_asm_output_data_sleb128 (off, NULL);
3048 case DW_CFA_restore_extended:
3049 case DW_CFA_undefined:
3050 case DW_CFA_same_value:
3051 case DW_CFA_def_cfa_register:
3052 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3053 dw2_asm_output_data_uleb128 (r, NULL);
3056 case DW_CFA_register:
3057 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3058 dw2_asm_output_data_uleb128 (r, NULL);
3059 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3060 dw2_asm_output_data_uleb128 (r, NULL);
3063 case DW_CFA_def_cfa_offset:
3064 case DW_CFA_GNU_args_size:
3065 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3068 case DW_CFA_def_cfa_offset_sf:
3069 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3070 dw2_asm_output_data_sleb128 (off, NULL);
3073 case DW_CFA_GNU_window_save:
3076 case DW_CFA_def_cfa_expression:
3077 case DW_CFA_expression:
3078 output_cfa_loc (cfi);
3081 case DW_CFA_GNU_negative_offset_extended:
3082 /* Obsoleted by DW_CFA_offset_extended_sf. */
3091 /* Similar, but do it via assembler directives instead. */
3094 output_cfi_directive (dw_cfi_ref cfi)
3096 unsigned long r, r2;
3098 switch (cfi->dw_cfi_opc)
3100 case DW_CFA_advance_loc:
3101 case DW_CFA_advance_loc1:
3102 case DW_CFA_advance_loc2:
3103 case DW_CFA_advance_loc4:
3104 case DW_CFA_MIPS_advance_loc8:
3105 case DW_CFA_set_loc:
3106 /* Should only be created by add_fde_cfi in a code path not
3107 followed when emitting via directives. The assembler is
3108 going to take care of this for us. */
3112 case DW_CFA_offset_extended:
3113 case DW_CFA_offset_extended_sf:
3114 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3115 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3116 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3119 case DW_CFA_restore:
3120 case DW_CFA_restore_extended:
3121 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3122 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3125 case DW_CFA_undefined:
3126 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3127 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3130 case DW_CFA_same_value:
3131 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3132 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3135 case DW_CFA_def_cfa:
3136 case DW_CFA_def_cfa_sf:
3137 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3138 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3139 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3142 case DW_CFA_def_cfa_register:
3143 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3144 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3147 case DW_CFA_register:
3148 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3149 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3150 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3153 case DW_CFA_def_cfa_offset:
3154 case DW_CFA_def_cfa_offset_sf:
3155 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3156 HOST_WIDE_INT_PRINT_DEC"\n",
3157 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3160 case DW_CFA_remember_state:
3161 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3163 case DW_CFA_restore_state:
3164 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3167 case DW_CFA_GNU_args_size:
3168 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3169 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3171 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3172 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3173 fputc ('\n', asm_out_file);
3176 case DW_CFA_GNU_window_save:
3177 fprintf (asm_out_file, "\t.cfi_window_save\n");
3180 case DW_CFA_def_cfa_expression:
3181 case DW_CFA_expression:
3182 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3183 output_cfa_loc_raw (cfi);
3184 fputc ('\n', asm_out_file);
3192 /* Output the call frame information used to record information
3193 that relates to calculating the frame pointer, and records the
3194 location of saved registers. */
3197 output_call_frame_info (int for_eh)
3202 char l1[20], l2[20], section_start_label[20];
3203 bool any_lsda_needed = false;
3204 char augmentation[6];
3205 int augmentation_size;
3206 int fde_encoding = DW_EH_PE_absptr;
3207 int per_encoding = DW_EH_PE_absptr;
3208 int lsda_encoding = DW_EH_PE_absptr;
3212 /* Don't emit a CIE if there won't be any FDEs. */
3213 if (fde_table_in_use == 0)
3216 /* Nothing to do if the assembler's doing it all. */
3217 if (dwarf2out_do_cfi_asm ())
3220 /* If we make FDEs linkonce, we may have to emit an empty label for
3221 an FDE that wouldn't otherwise be emitted. We want to avoid
3222 having an FDE kept around when the function it refers to is
3223 discarded. Example where this matters: a primary function
3224 template in C++ requires EH information, but an explicit
3225 specialization doesn't. */
3226 if (TARGET_USES_WEAK_UNWIND_INFO
3227 && ! flag_asynchronous_unwind_tables
3230 for (i = 0; i < fde_table_in_use; i++)
3231 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3232 && !fde_table[i].uses_eh_lsda
3233 && ! DECL_WEAK (fde_table[i].decl))
3234 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3235 for_eh, /* empty */ 1);
3237 /* If we don't have any functions we'll want to unwind out of, don't
3238 emit any EH unwind information. Note that if exceptions aren't
3239 enabled, we won't have collected nothrow information, and if we
3240 asked for asynchronous tables, we always want this info. */
3243 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3245 for (i = 0; i < fde_table_in_use; i++)
3246 if (fde_table[i].uses_eh_lsda)
3247 any_eh_needed = any_lsda_needed = true;
3248 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3249 any_eh_needed = true;
3250 else if (! fde_table[i].nothrow
3251 && ! fde_table[i].all_throwers_are_sibcalls)
3252 any_eh_needed = true;
3254 if (! any_eh_needed)
3258 /* We're going to be generating comments, so turn on app. */
3263 switch_to_eh_frame_section ();
3266 if (!debug_frame_section)
3267 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3268 SECTION_DEBUG, NULL);
3269 switch_to_section (debug_frame_section);
3272 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3273 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3275 /* Output the CIE. */
3276 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3277 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3278 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3279 dw2_asm_output_data (4, 0xffffffff,
3280 "Initial length escape value indicating 64-bit DWARF extension");
3281 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3282 "Length of Common Information Entry");
3283 ASM_OUTPUT_LABEL (asm_out_file, l1);
3285 /* Now that the CIE pointer is PC-relative for EH,
3286 use 0 to identify the CIE. */
3287 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3288 (for_eh ? 0 : DWARF_CIE_ID),
3289 "CIE Identifier Tag");
3291 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3292 use CIE version 1, unless that would produce incorrect results
3293 due to overflowing the return register column. */
3294 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3296 if (return_reg >= 256 || dwarf_version > 2)
3298 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3300 augmentation[0] = 0;
3301 augmentation_size = 0;
3307 z Indicates that a uleb128 is present to size the
3308 augmentation section.
3309 L Indicates the encoding (and thus presence) of
3310 an LSDA pointer in the FDE augmentation.
3311 R Indicates a non-default pointer encoding for
3313 P Indicates the presence of an encoding + language
3314 personality routine in the CIE augmentation. */
3316 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3317 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3318 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3320 p = augmentation + 1;
3321 if (eh_personality_libfunc)
3324 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3325 assemble_external_libcall (eh_personality_libfunc);
3327 if (any_lsda_needed)
3330 augmentation_size += 1;
3332 if (fde_encoding != DW_EH_PE_absptr)
3335 augmentation_size += 1;
3337 if (p > augmentation + 1)
3339 augmentation[0] = 'z';
3343 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3344 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
3346 int offset = ( 4 /* Length */
3348 + 1 /* CIE version */
3349 + strlen (augmentation) + 1 /* Augmentation */
3350 + size_of_uleb128 (1) /* Code alignment */
3351 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3353 + 1 /* Augmentation size */
3354 + 1 /* Personality encoding */ );
3355 int pad = -offset & (PTR_SIZE - 1);
3357 augmentation_size += pad;
3359 /* Augmentations should be small, so there's scarce need to
3360 iterate for a solution. Die if we exceed one uleb128 byte. */
3361 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3365 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3366 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3367 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3368 "CIE Data Alignment Factor");
3370 if (dw_cie_version == 1)
3371 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3373 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3375 if (augmentation[0])
3377 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3378 if (eh_personality_libfunc)
3380 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3381 eh_data_format_name (per_encoding));
3382 dw2_asm_output_encoded_addr_rtx (per_encoding,
3383 eh_personality_libfunc,
3387 if (any_lsda_needed)
3388 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3389 eh_data_format_name (lsda_encoding));
3391 if (fde_encoding != DW_EH_PE_absptr)
3392 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3393 eh_data_format_name (fde_encoding));
3396 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3397 output_cfi (cfi, NULL, for_eh);
3399 /* Pad the CIE out to an address sized boundary. */
3400 ASM_OUTPUT_ALIGN (asm_out_file,
3401 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3402 ASM_OUTPUT_LABEL (asm_out_file, l2);
3404 /* Loop through all of the FDE's. */
3405 for (i = 0; i < fde_table_in_use; i++)
3407 fde = &fde_table[i];
3409 /* Don't emit EH unwind info for leaf functions that don't need it. */
3410 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3411 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3412 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3413 && !fde->uses_eh_lsda)
3416 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
3417 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
3418 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
3419 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
3420 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3421 dw2_asm_output_data (4, 0xffffffff,
3422 "Initial length escape value indicating 64-bit DWARF extension");
3423 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3425 ASM_OUTPUT_LABEL (asm_out_file, l1);
3428 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3430 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3431 debug_frame_section, "FDE CIE offset");
3435 if (fde->dw_fde_switched_sections)
3437 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
3438 fde->dw_fde_unlikely_section_label);
3439 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
3440 fde->dw_fde_hot_section_label);
3441 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3442 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3443 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3444 "FDE initial location");
3445 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3446 fde->dw_fde_hot_section_end_label,
3447 fde->dw_fde_hot_section_label,
3448 "FDE address range");
3449 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3450 "FDE initial location");
3451 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3452 fde->dw_fde_unlikely_section_end_label,
3453 fde->dw_fde_unlikely_section_label,
3454 "FDE address range");
3458 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3459 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3460 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3463 "FDE initial location");
3464 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3465 fde->dw_fde_end, fde->dw_fde_begin,
3466 "FDE address range");
3471 if (fde->dw_fde_switched_sections)
3473 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3474 fde->dw_fde_hot_section_label,
3475 "FDE initial location");
3476 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3477 fde->dw_fde_hot_section_end_label,
3478 fde->dw_fde_hot_section_label,
3479 "FDE address range");
3480 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3481 fde->dw_fde_unlikely_section_label,
3482 "FDE initial location");
3483 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3484 fde->dw_fde_unlikely_section_end_label,
3485 fde->dw_fde_unlikely_section_label,
3486 "FDE address range");
3490 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3491 "FDE initial location");
3492 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3493 fde->dw_fde_end, fde->dw_fde_begin,
3494 "FDE address range");
3498 if (augmentation[0])
3500 if (any_lsda_needed)
3502 int size = size_of_encoded_value (lsda_encoding);
3504 if (lsda_encoding == DW_EH_PE_aligned)
3506 int offset = ( 4 /* Length */
3507 + 4 /* CIE offset */
3508 + 2 * size_of_encoded_value (fde_encoding)
3509 + 1 /* Augmentation size */ );
3510 int pad = -offset & (PTR_SIZE - 1);
3513 gcc_assert (size_of_uleb128 (size) == 1);
3516 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3518 if (fde->uses_eh_lsda)
3520 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3521 fde->funcdef_number);
3522 dw2_asm_output_encoded_addr_rtx (
3523 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3524 false, "Language Specific Data Area");
3528 if (lsda_encoding == DW_EH_PE_aligned)
3529 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3531 (size_of_encoded_value (lsda_encoding), 0,
3532 "Language Specific Data Area (none)");
3536 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3539 /* Loop through the Call Frame Instructions associated with
3541 fde->dw_fde_current_label = fde->dw_fde_begin;
3542 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3543 output_cfi (cfi, fde, for_eh);
3545 /* Pad the FDE out to an address sized boundary. */
3546 ASM_OUTPUT_ALIGN (asm_out_file,
3547 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3548 ASM_OUTPUT_LABEL (asm_out_file, l2);
3551 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3552 dw2_asm_output_data (4, 0, "End of Table");
3553 #ifdef MIPS_DEBUGGING_INFO
3554 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3555 get a value of 0. Putting .align 0 after the label fixes it. */
3556 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3559 /* Turn off app to make assembly quicker. */
3564 /* Output a marker (i.e. a label) for the beginning of a function, before
3568 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3569 const char *file ATTRIBUTE_UNUSED)
3571 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3575 current_function_func_begin_label = NULL;
3577 #ifdef TARGET_UNWIND_INFO
3578 /* ??? current_function_func_begin_label is also used by except.c
3579 for call-site information. We must emit this label if it might
3581 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3582 && ! dwarf2out_do_frame ())
3585 if (! dwarf2out_do_frame ())
3589 switch_to_section (function_section (current_function_decl));
3590 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3591 current_function_funcdef_no);
3592 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3593 current_function_funcdef_no);
3594 dup_label = xstrdup (label);
3595 current_function_func_begin_label = dup_label;
3597 #ifdef TARGET_UNWIND_INFO
3598 /* We can elide the fde allocation if we're not emitting debug info. */
3599 if (! dwarf2out_do_frame ())
3603 /* Expand the fde table if necessary. */
3604 if (fde_table_in_use == fde_table_allocated)
3606 fde_table_allocated += FDE_TABLE_INCREMENT;
3607 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3608 memset (fde_table + fde_table_in_use, 0,
3609 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3612 /* Record the FDE associated with this function. */
3613 current_funcdef_fde = fde_table_in_use;
3615 /* Add the new FDE at the end of the fde_table. */
3616 fde = &fde_table[fde_table_in_use++];
3617 fde->decl = current_function_decl;
3618 fde->dw_fde_begin = dup_label;
3619 fde->dw_fde_current_label = dup_label;
3620 fde->dw_fde_hot_section_label = NULL;
3621 fde->dw_fde_hot_section_end_label = NULL;
3622 fde->dw_fde_unlikely_section_label = NULL;
3623 fde->dw_fde_unlikely_section_end_label = NULL;
3624 fde->dw_fde_switched_sections = false;
3625 fde->dw_fde_end = NULL;
3626 fde->dw_fde_cfi = NULL;
3627 fde->funcdef_number = current_function_funcdef_no;
3628 fde->nothrow = crtl->nothrow;
3629 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3630 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3631 fde->drap_reg = INVALID_REGNUM;
3632 fde->vdrap_reg = INVALID_REGNUM;
3634 args_size = old_args_size = 0;
3636 /* We only want to output line number information for the genuine dwarf2
3637 prologue case, not the eh frame case. */
3638 #ifdef DWARF2_DEBUGGING_INFO
3640 dwarf2out_source_line (line, file, 0, true);
3643 if (dwarf2out_do_cfi_asm ())
3648 fprintf (asm_out_file, "\t.cfi_startproc\n");
3650 if (eh_personality_libfunc)
3652 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3653 ref = eh_personality_libfunc;
3655 /* ??? The GAS support isn't entirely consistent. We have to
3656 handle indirect support ourselves, but PC-relative is done
3657 in the assembler. Further, the assembler can't handle any
3658 of the weirder relocation types. */
3659 if (enc & DW_EH_PE_indirect)
3660 ref = dw2_force_const_mem (ref, true);
3662 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3663 output_addr_const (asm_out_file, ref);
3664 fputc ('\n', asm_out_file);
3667 if (crtl->uses_eh_lsda)
3671 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3672 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3673 current_function_funcdef_no);
3674 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3675 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3677 if (enc & DW_EH_PE_indirect)
3678 ref = dw2_force_const_mem (ref, true);
3680 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3681 output_addr_const (asm_out_file, ref);
3682 fputc ('\n', asm_out_file);
3687 /* Output a marker (i.e. a label) for the absolute end of the generated code
3688 for a function definition. This gets called *after* the epilogue code has
3692 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3693 const char *file ATTRIBUTE_UNUSED)
3696 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3698 #ifdef DWARF2_DEBUGGING_INFO
3699 last_var_location_insn = NULL_RTX;
3702 if (dwarf2out_do_cfi_asm ())
3703 fprintf (asm_out_file, "\t.cfi_endproc\n");
3705 /* Output a label to mark the endpoint of the code generated for this
3707 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3708 current_function_funcdef_no);
3709 ASM_OUTPUT_LABEL (asm_out_file, label);
3710 fde = current_fde ();
3711 gcc_assert (fde != NULL);
3712 fde->dw_fde_end = xstrdup (label);
3716 dwarf2out_frame_init (void)
3718 /* Allocate the initial hunk of the fde_table. */
3719 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3720 fde_table_allocated = FDE_TABLE_INCREMENT;
3721 fde_table_in_use = 0;
3723 /* Generate the CFA instructions common to all FDE's. Do it now for the
3724 sake of lookup_cfa. */
3726 /* On entry, the Canonical Frame Address is at SP. */
3727 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3729 #ifdef DWARF2_UNWIND_INFO
3730 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3731 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3736 dwarf2out_frame_finish (void)
3738 /* Output call frame information. */
3739 if (DWARF2_FRAME_INFO)
3740 output_call_frame_info (0);
3742 #ifndef TARGET_UNWIND_INFO
3743 /* Output another copy for the unwinder. */
3744 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3745 output_call_frame_info (1);
3749 /* Note that the current function section is being used for code. */
3752 dwarf2out_note_section_used (void)
3754 section *sec = current_function_section ();
3755 if (sec == text_section)
3756 text_section_used = true;
3757 else if (sec == cold_text_section)
3758 cold_text_section_used = true;
3762 dwarf2out_switch_text_section (void)
3764 dw_fde_ref fde = current_fde ();
3766 gcc_assert (cfun && fde);
3768 fde->dw_fde_switched_sections = true;
3769 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3770 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3771 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3772 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3773 have_multiple_function_sections = true;
3775 /* Reset the current label on switching text sections, so that we
3776 don't attempt to advance_loc4 between labels in different sections. */
3777 fde->dw_fde_current_label = NULL;
3779 /* There is no need to mark used sections when not debugging. */
3780 if (cold_text_section != NULL)
3781 dwarf2out_note_section_used ();
3785 /* And now, the subset of the debugging information support code necessary
3786 for emitting location expressions. */
3788 /* Data about a single source file. */
3789 struct GTY(()) dwarf_file_data {
3790 const char * filename;
3794 typedef struct dw_val_struct *dw_val_ref;
3795 typedef struct die_struct *dw_die_ref;
3796 typedef const struct die_struct *const_dw_die_ref;
3797 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3798 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3800 typedef struct GTY(()) deferred_locations_struct
3804 } deferred_locations;
3806 DEF_VEC_O(deferred_locations);
3807 DEF_VEC_ALLOC_O(deferred_locations,gc);
3809 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
3811 /* Each DIE may have a series of attribute/value pairs. Values
3812 can take on several forms. The forms that are used in this
3813 implementation are listed below. */
3818 dw_val_class_offset,
3820 dw_val_class_loc_list,
3821 dw_val_class_range_list,
3823 dw_val_class_unsigned_const,
3824 dw_val_class_long_long,
3827 dw_val_class_die_ref,
3828 dw_val_class_fde_ref,
3829 dw_val_class_lbl_id,
3830 dw_val_class_lineptr,
3832 dw_val_class_macptr,
3836 /* Describe a double word constant value. */
3837 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3839 typedef struct GTY(()) dw_long_long_struct {
3845 /* Describe a floating point constant value, or a vector constant value. */
3847 typedef struct GTY(()) dw_vec_struct {
3848 unsigned char * GTY((length ("%h.length"))) array;
3854 /* The dw_val_node describes an attribute's value, as it is
3855 represented internally. */
3857 typedef struct GTY(()) dw_val_struct {
3858 enum dw_val_class val_class;
3859 union dw_val_struct_union
3861 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3862 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3863 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3864 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3865 HOST_WIDE_INT GTY ((default)) val_int;
3866 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3867 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3868 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3869 struct dw_val_die_union
3873 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3874 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3875 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3876 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3877 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3878 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3880 GTY ((desc ("%1.val_class"))) v;
3884 /* Locations in memory are described using a sequence of stack machine
3887 typedef struct GTY(()) dw_loc_descr_struct {
3888 dw_loc_descr_ref dw_loc_next;
3889 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
3890 /* Used to distinguish DW_OP_addr with a direct symbol relocation
3891 from DW_OP_addr with a dtp-relative symbol relocation. */
3892 unsigned int dtprel : 1;
3894 dw_val_node dw_loc_oprnd1;
3895 dw_val_node dw_loc_oprnd2;
3899 /* Location lists are ranges + location descriptions for that range,
3900 so you can track variables that are in different places over
3901 their entire life. */
3902 typedef struct GTY(()) dw_loc_list_struct {
3903 dw_loc_list_ref dw_loc_next;
3904 const char *begin; /* Label for begin address of range */
3905 const char *end; /* Label for end address of range */
3906 char *ll_symbol; /* Label for beginning of location list.
3907 Only on head of list */
3908 const char *section; /* Section this loclist is relative to */
3909 dw_loc_descr_ref expr;
3912 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3914 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3916 /* Convert a DWARF stack opcode into its string name. */
3919 dwarf_stack_op_name (unsigned int op)
3924 return "DW_OP_addr";
3926 return "DW_OP_deref";
3928 return "DW_OP_const1u";
3930 return "DW_OP_const1s";
3932 return "DW_OP_const2u";
3934 return "DW_OP_const2s";
3936 return "DW_OP_const4u";
3938 return "DW_OP_const4s";
3940 return "DW_OP_const8u";
3942 return "DW_OP_const8s";
3944 return "DW_OP_constu";
3946 return "DW_OP_consts";
3950 return "DW_OP_drop";
3952 return "DW_OP_over";
3954 return "DW_OP_pick";
3956 return "DW_OP_swap";
3960 return "DW_OP_xderef";
3968 return "DW_OP_minus";
3980 return "DW_OP_plus";
3981 case DW_OP_plus_uconst:
3982 return "DW_OP_plus_uconst";
3988 return "DW_OP_shra";
4006 return "DW_OP_skip";
4008 return "DW_OP_lit0";
4010 return "DW_OP_lit1";
4012 return "DW_OP_lit2";
4014 return "DW_OP_lit3";
4016 return "DW_OP_lit4";
4018 return "DW_OP_lit5";
4020 return "DW_OP_lit6";
4022 return "DW_OP_lit7";
4024 return "DW_OP_lit8";
4026 return "DW_OP_lit9";
4028 return "DW_OP_lit10";
4030 return "DW_OP_lit11";
4032 return "DW_OP_lit12";
4034 return "DW_OP_lit13";
4036 return "DW_OP_lit14";
4038 return "DW_OP_lit15";
4040 return "DW_OP_lit16";
4042 return "DW_OP_lit17";
4044 return "DW_OP_lit18";
4046 return "DW_OP_lit19";
4048 return "DW_OP_lit20";
4050 return "DW_OP_lit21";
4052 return "DW_OP_lit22";
4054 return "DW_OP_lit23";
4056 return "DW_OP_lit24";
4058 return "DW_OP_lit25";
4060 return "DW_OP_lit26";
4062 return "DW_OP_lit27";
4064 return "DW_OP_lit28";
4066 return "DW_OP_lit29";
4068 return "DW_OP_lit30";
4070 return "DW_OP_lit31";
4072 return "DW_OP_reg0";
4074 return "DW_OP_reg1";
4076 return "DW_OP_reg2";
4078 return "DW_OP_reg3";
4080 return "DW_OP_reg4";
4082 return "DW_OP_reg5";
4084 return "DW_OP_reg6";
4086 return "DW_OP_reg7";
4088 return "DW_OP_reg8";
4090 return "DW_OP_reg9";
4092 return "DW_OP_reg10";
4094 return "DW_OP_reg11";
4096 return "DW_OP_reg12";
4098 return "DW_OP_reg13";
4100 return "DW_OP_reg14";
4102 return "DW_OP_reg15";
4104 return "DW_OP_reg16";
4106 return "DW_OP_reg17";
4108 return "DW_OP_reg18";
4110 return "DW_OP_reg19";
4112 return "DW_OP_reg20";
4114 return "DW_OP_reg21";
4116 return "DW_OP_reg22";
4118 return "DW_OP_reg23";
4120 return "DW_OP_reg24";
4122 return "DW_OP_reg25";
4124 return "DW_OP_reg26";
4126 return "DW_OP_reg27";
4128 return "DW_OP_reg28";
4130 return "DW_OP_reg29";
4132 return "DW_OP_reg30";
4134 return "DW_OP_reg31";
4136 return "DW_OP_breg0";
4138 return "DW_OP_breg1";
4140 return "DW_OP_breg2";
4142 return "DW_OP_breg3";
4144 return "DW_OP_breg4";
4146 return "DW_OP_breg5";
4148 return "DW_OP_breg6";
4150 return "DW_OP_breg7";
4152 return "DW_OP_breg8";
4154 return "DW_OP_breg9";
4156 return "DW_OP_breg10";
4158 return "DW_OP_breg11";
4160 return "DW_OP_breg12";
4162 return "DW_OP_breg13";
4164 return "DW_OP_breg14";
4166 return "DW_OP_breg15";
4168 return "DW_OP_breg16";
4170 return "DW_OP_breg17";
4172 return "DW_OP_breg18";
4174 return "DW_OP_breg19";
4176 return "DW_OP_breg20";
4178 return "DW_OP_breg21";
4180 return "DW_OP_breg22";
4182 return "DW_OP_breg23";
4184 return "DW_OP_breg24";
4186 return "DW_OP_breg25";
4188 return "DW_OP_breg26";
4190 return "DW_OP_breg27";
4192 return "DW_OP_breg28";
4194 return "DW_OP_breg29";
4196 return "DW_OP_breg30";
4198 return "DW_OP_breg31";
4200 return "DW_OP_regx";
4202 return "DW_OP_fbreg";
4204 return "DW_OP_bregx";
4206 return "DW_OP_piece";
4207 case DW_OP_deref_size:
4208 return "DW_OP_deref_size";
4209 case DW_OP_xderef_size:
4210 return "DW_OP_xderef_size";
4214 case DW_OP_push_object_address:
4215 return "DW_OP_push_object_address";
4217 return "DW_OP_call2";
4219 return "DW_OP_call4";
4220 case DW_OP_call_ref:
4221 return "DW_OP_call_ref";
4222 case DW_OP_form_tls_address:
4223 return "DW_OP_form_tls_address";
4224 case DW_OP_call_frame_cfa:
4225 return "DW_OP_call_frame_cfa";
4226 case DW_OP_bit_piece:
4227 return "DW_OP_bit_piece";
4229 case DW_OP_GNU_push_tls_address:
4230 return "DW_OP_GNU_push_tls_address";
4231 case DW_OP_GNU_uninit:
4232 return "DW_OP_GNU_uninit";
4233 case DW_OP_GNU_encoded_addr:
4234 return "DW_OP_GNU_encoded_addr";
4237 return "OP_<unknown>";
4241 /* Return a pointer to a newly allocated location description. Location
4242 descriptions are simple expression terms that can be strung
4243 together to form more complicated location (address) descriptions. */
4245 static inline dw_loc_descr_ref
4246 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4247 unsigned HOST_WIDE_INT oprnd2)
4249 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4251 descr->dw_loc_opc = op;
4252 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4253 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4254 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4255 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4260 /* Return a pointer to a newly allocated location description for
4263 static inline dw_loc_descr_ref
4264 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4267 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4270 return new_loc_descr (DW_OP_bregx, reg, offset);
4273 /* Add a location description term to a location description expression. */
4276 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4278 dw_loc_descr_ref *d;
4280 /* Find the end of the chain. */
4281 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4287 /* Add a constant OFFSET to a location expression. */
4290 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4292 dw_loc_descr_ref loc;
4295 gcc_assert (*list_head != NULL);
4300 /* Find the end of the chain. */
4301 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4305 if (loc->dw_loc_opc == DW_OP_fbreg
4306 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4307 p = &loc->dw_loc_oprnd1.v.val_int;
4308 else if (loc->dw_loc_opc == DW_OP_bregx)
4309 p = &loc->dw_loc_oprnd2.v.val_int;
4311 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4312 offset. Don't optimize if an signed integer overflow would happen. */
4314 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4315 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4318 else if (offset > 0)
4319 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4323 loc->dw_loc_next = int_loc_descriptor (offset);
4324 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4328 /* Return the size of a location descriptor. */
4330 static unsigned long
4331 size_of_loc_descr (dw_loc_descr_ref loc)
4333 unsigned long size = 1;
4335 switch (loc->dw_loc_opc)
4338 size += DWARF2_ADDR_SIZE;
4357 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4360 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4365 case DW_OP_plus_uconst:
4366 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4404 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4407 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4410 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4413 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4414 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4417 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4419 case DW_OP_deref_size:
4420 case DW_OP_xderef_size:
4429 case DW_OP_call_ref:
4430 size += DWARF2_ADDR_SIZE;
4439 /* Return the size of a series of location descriptors. */
4441 static unsigned long
4442 size_of_locs (dw_loc_descr_ref loc)
4447 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4448 field, to avoid writing to a PCH file. */
4449 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4451 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4453 size += size_of_loc_descr (l);
4458 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4460 l->dw_loc_addr = size;
4461 size += size_of_loc_descr (l);
4467 /* Output location description stack opcode's operands (if any). */
4470 output_loc_operands (dw_loc_descr_ref loc)
4472 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4473 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4475 switch (loc->dw_loc_opc)
4477 #ifdef DWARF2_DEBUGGING_INFO
4480 dw2_asm_output_data (2, val1->v.val_int, NULL);
4484 dw2_asm_output_data (4, val1->v.val_int, NULL);
4488 gcc_assert (HOST_BITS_PER_LONG >= 64);
4489 dw2_asm_output_data (8, val1->v.val_int, NULL);
4496 gcc_assert (val1->val_class == dw_val_class_loc);
4497 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4499 dw2_asm_output_data (2, offset, NULL);
4511 /* We currently don't make any attempt to make sure these are
4512 aligned properly like we do for the main unwind info, so
4513 don't support emitting things larger than a byte if we're
4514 only doing unwinding. */
4519 dw2_asm_output_data (1, val1->v.val_int, NULL);
4522 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4525 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4528 dw2_asm_output_data (1, val1->v.val_int, NULL);
4530 case DW_OP_plus_uconst:
4531 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4565 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4568 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4571 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4574 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4575 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4578 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4580 case DW_OP_deref_size:
4581 case DW_OP_xderef_size:
4582 dw2_asm_output_data (1, val1->v.val_int, NULL);
4588 if (targetm.asm_out.output_dwarf_dtprel)
4590 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4593 fputc ('\n', asm_out_file);
4600 #ifdef DWARF2_DEBUGGING_INFO
4601 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4609 /* Other codes have no operands. */
4614 /* Output a sequence of location operations. */
4617 output_loc_sequence (dw_loc_descr_ref loc)
4619 for (; loc != NULL; loc = loc->dw_loc_next)
4621 /* Output the opcode. */
4622 dw2_asm_output_data (1, loc->dw_loc_opc,
4623 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4625 /* Output the operand(s) (if any). */
4626 output_loc_operands (loc);
4630 /* Output location description stack opcode's operands (if any).
4631 The output is single bytes on a line, suitable for .cfi_escape. */
4634 output_loc_operands_raw (dw_loc_descr_ref loc)
4636 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4637 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4639 switch (loc->dw_loc_opc)
4642 /* We cannot output addresses in .cfi_escape, only bytes. */
4648 case DW_OP_deref_size:
4649 case DW_OP_xderef_size:
4650 fputc (',', asm_out_file);
4651 dw2_asm_output_data_raw (1, val1->v.val_int);
4656 fputc (',', asm_out_file);
4657 dw2_asm_output_data_raw (2, val1->v.val_int);
4662 fputc (',', asm_out_file);
4663 dw2_asm_output_data_raw (4, val1->v.val_int);
4668 gcc_assert (HOST_BITS_PER_LONG >= 64);
4669 fputc (',', asm_out_file);
4670 dw2_asm_output_data_raw (8, val1->v.val_int);
4678 gcc_assert (val1->val_class == dw_val_class_loc);
4679 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4681 fputc (',', asm_out_file);
4682 dw2_asm_output_data_raw (2, offset);
4687 case DW_OP_plus_uconst:
4690 fputc (',', asm_out_file);
4691 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4728 fputc (',', asm_out_file);
4729 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4733 fputc (',', asm_out_file);
4734 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4735 fputc (',', asm_out_file);
4736 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4740 /* Other codes have no operands. */
4746 output_loc_sequence_raw (dw_loc_descr_ref loc)
4750 /* Output the opcode. */
4751 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4752 output_loc_operands_raw (loc);
4754 if (!loc->dw_loc_next)
4756 loc = loc->dw_loc_next;
4758 fputc (',', asm_out_file);
4762 /* This routine will generate the correct assembly data for a location
4763 description based on a cfi entry with a complex address. */
4766 output_cfa_loc (dw_cfi_ref cfi)
4768 dw_loc_descr_ref loc;
4771 if (cfi->dw_cfi_opc == DW_CFA_expression)
4772 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4774 /* Output the size of the block. */
4775 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4776 size = size_of_locs (loc);
4777 dw2_asm_output_data_uleb128 (size, NULL);
4779 /* Now output the operations themselves. */
4780 output_loc_sequence (loc);
4783 /* Similar, but used for .cfi_escape. */
4786 output_cfa_loc_raw (dw_cfi_ref cfi)
4788 dw_loc_descr_ref loc;
4791 if (cfi->dw_cfi_opc == DW_CFA_expression)
4792 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4794 /* Output the size of the block. */
4795 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4796 size = size_of_locs (loc);
4797 dw2_asm_output_data_uleb128_raw (size);
4798 fputc (',', asm_out_file);
4800 /* Now output the operations themselves. */
4801 output_loc_sequence_raw (loc);
4804 /* This function builds a dwarf location descriptor sequence from a
4805 dw_cfa_location, adding the given OFFSET to the result of the
4808 static struct dw_loc_descr_struct *
4809 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4811 struct dw_loc_descr_struct *head, *tmp;
4813 offset += cfa->offset;
4817 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4818 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4819 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4820 add_loc_descr (&head, tmp);
4823 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4824 add_loc_descr (&head, tmp);
4828 head = new_reg_loc_descr (cfa->reg, offset);
4833 /* This function builds a dwarf location descriptor sequence for
4834 the address at OFFSET from the CFA when stack is aligned to
4837 static struct dw_loc_descr_struct *
4838 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4840 struct dw_loc_descr_struct *head;
4841 unsigned int dwarf_fp
4842 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4844 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4845 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4847 head = new_reg_loc_descr (dwarf_fp, 0);
4848 add_loc_descr (&head, int_loc_descriptor (alignment));
4849 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4850 loc_descr_plus_const (&head, offset);
4853 head = new_reg_loc_descr (dwarf_fp, offset);
4857 /* This function fills in aa dw_cfa_location structure from a dwarf location
4858 descriptor sequence. */
4861 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4863 struct dw_loc_descr_struct *ptr;
4865 cfa->base_offset = 0;
4869 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4871 enum dwarf_location_atom op = ptr->dw_loc_opc;
4907 cfa->reg = op - DW_OP_reg0;
4910 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4944 cfa->reg = op - DW_OP_breg0;
4945 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4948 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4949 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4954 case DW_OP_plus_uconst:
4955 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4958 internal_error ("DW_LOC_OP %s not implemented",
4959 dwarf_stack_op_name (ptr->dw_loc_opc));
4963 #endif /* .debug_frame support */
4965 /* And now, the support for symbolic debugging information. */
4966 #ifdef DWARF2_DEBUGGING_INFO
4968 /* .debug_str support. */
4969 static int output_indirect_string (void **, void *);
4971 static void dwarf2out_init (const char *);
4972 static void dwarf2out_finish (const char *);
4973 static void dwarf2out_define (unsigned int, const char *);
4974 static void dwarf2out_undef (unsigned int, const char *);
4975 static void dwarf2out_start_source_file (unsigned, const char *);
4976 static void dwarf2out_end_source_file (unsigned);
4977 static void dwarf2out_begin_block (unsigned, unsigned);
4978 static void dwarf2out_end_block (unsigned, unsigned);
4979 static bool dwarf2out_ignore_block (const_tree);
4980 static void dwarf2out_global_decl (tree);
4981 static void dwarf2out_type_decl (tree, int);
4982 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
4983 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
4985 static void dwarf2out_abstract_function (tree);
4986 static void dwarf2out_var_location (rtx);
4987 static void dwarf2out_begin_function (tree);
4988 static void dwarf2out_set_name (tree, tree);
4990 /* The debug hooks structure. */
4992 const struct gcc_debug_hooks dwarf2_debug_hooks =
4998 dwarf2out_start_source_file,
4999 dwarf2out_end_source_file,
5000 dwarf2out_begin_block,
5001 dwarf2out_end_block,
5002 dwarf2out_ignore_block,
5003 dwarf2out_source_line,
5004 dwarf2out_begin_prologue,
5005 debug_nothing_int_charstar, /* end_prologue */
5006 dwarf2out_end_epilogue,
5007 dwarf2out_begin_function,
5008 debug_nothing_int, /* end_function */
5009 dwarf2out_decl, /* function_decl */
5010 dwarf2out_global_decl,
5011 dwarf2out_type_decl, /* type_decl */
5012 dwarf2out_imported_module_or_decl,
5013 debug_nothing_tree, /* deferred_inline_function */
5014 /* The DWARF 2 backend tries to reduce debugging bloat by not
5015 emitting the abstract description of inline functions until
5016 something tries to reference them. */
5017 dwarf2out_abstract_function, /* outlining_inline_function */
5018 debug_nothing_rtx, /* label */
5019 debug_nothing_int, /* handle_pch */
5020 dwarf2out_var_location,
5021 dwarf2out_switch_text_section,
5023 1 /* start_end_main_source_file */
5027 /* NOTE: In the comments in this file, many references are made to
5028 "Debugging Information Entries". This term is abbreviated as `DIE'
5029 throughout the remainder of this file. */
5031 /* An internal representation of the DWARF output is built, and then
5032 walked to generate the DWARF debugging info. The walk of the internal
5033 representation is done after the entire program has been compiled.
5034 The types below are used to describe the internal representation. */
5036 /* Various DIE's use offsets relative to the beginning of the
5037 .debug_info section to refer to each other. */
5039 typedef long int dw_offset;
5041 /* Define typedefs here to avoid circular dependencies. */
5043 typedef struct dw_attr_struct *dw_attr_ref;
5044 typedef struct dw_line_info_struct *dw_line_info_ref;
5045 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5046 typedef struct pubname_struct *pubname_ref;
5047 typedef struct dw_ranges_struct *dw_ranges_ref;
5048 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5050 /* Each entry in the line_info_table maintains the file and
5051 line number associated with the label generated for that
5052 entry. The label gives the PC value associated with
5053 the line number entry. */
5055 typedef struct GTY(()) dw_line_info_struct {
5056 unsigned long dw_file_num;
5057 unsigned long dw_line_num;
5061 /* Line information for functions in separate sections; each one gets its
5063 typedef struct GTY(()) dw_separate_line_info_struct {
5064 unsigned long dw_file_num;
5065 unsigned long dw_line_num;
5066 unsigned long function;
5068 dw_separate_line_info_entry;
5070 /* Each DIE attribute has a field specifying the attribute kind,
5071 a link to the next attribute in the chain, and an attribute value.
5072 Attributes are typically linked below the DIE they modify. */
5074 typedef struct GTY(()) dw_attr_struct {
5075 enum dwarf_attribute dw_attr;
5076 dw_val_node dw_attr_val;
5080 DEF_VEC_O(dw_attr_node);
5081 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5083 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5084 The children of each node form a circular list linked by
5085 die_sib. die_child points to the node *before* the "first" child node. */
5087 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5088 enum dwarf_tag die_tag;
5090 VEC(dw_attr_node,gc) * die_attr;
5091 dw_die_ref die_parent;
5092 dw_die_ref die_child;
5094 dw_die_ref die_definition; /* ref from a specification to its definition */
5095 dw_offset die_offset;
5096 unsigned long die_abbrev;
5098 /* Die is used and must not be pruned as unused. */
5099 int die_perennial_p;
5100 unsigned int decl_id;
5104 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5105 #define FOR_EACH_CHILD(die, c, expr) do { \
5106 c = die->die_child; \
5110 } while (c != die->die_child); \
5113 /* The pubname structure */
5115 typedef struct GTY(()) pubname_struct {
5121 DEF_VEC_O(pubname_entry);
5122 DEF_VEC_ALLOC_O(pubname_entry, gc);
5124 struct GTY(()) dw_ranges_struct {
5125 /* If this is positive, it's a block number, otherwise it's a
5126 bitwise-negated index into dw_ranges_by_label. */
5130 struct GTY(()) dw_ranges_by_label_struct {
5135 /* The limbo die list structure. */
5136 typedef struct GTY(()) limbo_die_struct {
5139 struct limbo_die_struct *next;
5143 /* How to start an assembler comment. */
5144 #ifndef ASM_COMMENT_START
5145 #define ASM_COMMENT_START ";#"
5148 /* Define a macro which returns nonzero for a TYPE_DECL which was
5149 implicitly generated for a tagged type.
5151 Note that unlike the gcc front end (which generates a NULL named
5152 TYPE_DECL node for each complete tagged type, each array type, and
5153 each function type node created) the g++ front end generates a
5154 _named_ TYPE_DECL node for each tagged type node created.
5155 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5156 generate a DW_TAG_typedef DIE for them. */
5158 #define TYPE_DECL_IS_STUB(decl) \
5159 (DECL_NAME (decl) == NULL_TREE \
5160 || (DECL_ARTIFICIAL (decl) \
5161 && is_tagged_type (TREE_TYPE (decl)) \
5162 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5163 /* This is necessary for stub decls that \
5164 appear in nested inline functions. */ \
5165 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5166 && (decl_ultimate_origin (decl) \
5167 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5169 /* Information concerning the compilation unit's programming
5170 language, and compiler version. */
5172 /* Fixed size portion of the DWARF compilation unit header. */
5173 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5174 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5176 /* Fixed size portion of public names info. */
5177 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5179 /* Fixed size portion of the address range info. */
5180 #define DWARF_ARANGES_HEADER_SIZE \
5181 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5182 DWARF2_ADDR_SIZE * 2) \
5183 - DWARF_INITIAL_LENGTH_SIZE)
5185 /* Size of padding portion in the address range info. It must be
5186 aligned to twice the pointer size. */
5187 #define DWARF_ARANGES_PAD_SIZE \
5188 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5189 DWARF2_ADDR_SIZE * 2) \
5190 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5192 /* Use assembler line directives if available. */
5193 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5194 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5195 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5197 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5201 /* Minimum line offset in a special line info. opcode.
5202 This value was chosen to give a reasonable range of values. */
5203 #define DWARF_LINE_BASE -10
5205 /* First special line opcode - leave room for the standard opcodes. */
5206 #define DWARF_LINE_OPCODE_BASE 10
5208 /* Range of line offsets in a special line info. opcode. */
5209 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5211 /* Flag that indicates the initial value of the is_stmt_start flag.
5212 In the present implementation, we do not mark any lines as
5213 the beginning of a source statement, because that information
5214 is not made available by the GCC front-end. */
5215 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5217 #ifdef DWARF2_DEBUGGING_INFO
5218 /* This location is used by calc_die_sizes() to keep track
5219 the offset of each DIE within the .debug_info section. */
5220 static unsigned long next_die_offset;
5223 /* Record the root of the DIE's built for the current compilation unit. */
5224 static GTY(()) dw_die_ref comp_unit_die;
5226 /* A list of DIEs with a NULL parent waiting to be relocated. */
5227 static GTY(()) limbo_die_node *limbo_die_list;
5229 /* A list of DIEs for which we may have to generate
5230 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5232 static GTY(()) limbo_die_node *deferred_asm_name;
5234 /* Filenames referenced by this compilation unit. */
5235 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5237 /* A hash table of references to DIE's that describe declarations.
5238 The key is a DECL_UID() which is a unique number identifying each decl. */
5239 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5241 /* A hash table of references to DIE's that describe COMMON blocks.
5242 The key is DECL_UID() ^ die_parent. */
5243 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5245 /* Node of the variable location list. */
5246 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5247 rtx GTY (()) var_loc_note;
5248 const char * GTY (()) label;
5249 const char * GTY (()) section_label;
5250 struct var_loc_node * GTY (()) next;
5253 /* Variable location list. */
5254 struct GTY (()) var_loc_list_def {
5255 struct var_loc_node * GTY (()) first;
5257 /* Do not mark the last element of the chained list because
5258 it is marked through the chain. */
5259 struct var_loc_node * GTY ((skip ("%h"))) last;
5261 /* DECL_UID of the variable decl. */
5262 unsigned int decl_id;
5264 typedef struct var_loc_list_def var_loc_list;
5267 /* Table of decl location linked lists. */
5268 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5270 /* A pointer to the base of a list of references to DIE's that
5271 are uniquely identified by their tag, presence/absence of
5272 children DIE's, and list of attribute/value pairs. */
5273 static GTY((length ("abbrev_die_table_allocated")))
5274 dw_die_ref *abbrev_die_table;
5276 /* Number of elements currently allocated for abbrev_die_table. */
5277 static GTY(()) unsigned abbrev_die_table_allocated;
5279 /* Number of elements in type_die_table currently in use. */
5280 static GTY(()) unsigned abbrev_die_table_in_use;
5282 /* Size (in elements) of increments by which we may expand the
5283 abbrev_die_table. */
5284 #define ABBREV_DIE_TABLE_INCREMENT 256
5286 /* A pointer to the base of a table that contains line information
5287 for each source code line in .text in the compilation unit. */
5288 static GTY((length ("line_info_table_allocated")))
5289 dw_line_info_ref line_info_table;
5291 /* Number of elements currently allocated for line_info_table. */
5292 static GTY(()) unsigned line_info_table_allocated;
5294 /* Number of elements in line_info_table currently in use. */
5295 static GTY(()) unsigned line_info_table_in_use;
5297 /* A pointer to the base of a table that contains line information
5298 for each source code line outside of .text in the compilation unit. */
5299 static GTY ((length ("separate_line_info_table_allocated")))
5300 dw_separate_line_info_ref separate_line_info_table;
5302 /* Number of elements currently allocated for separate_line_info_table. */
5303 static GTY(()) unsigned separate_line_info_table_allocated;
5305 /* Number of elements in separate_line_info_table currently in use. */
5306 static GTY(()) unsigned separate_line_info_table_in_use;
5308 /* Size (in elements) of increments by which we may expand the
5310 #define LINE_INFO_TABLE_INCREMENT 1024
5312 /* A pointer to the base of a table that contains a list of publicly
5313 accessible names. */
5314 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5316 /* A pointer to the base of a table that contains a list of publicly
5317 accessible types. */
5318 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5320 /* Array of dies for which we should generate .debug_arange info. */
5321 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5323 /* Number of elements currently allocated for arange_table. */
5324 static GTY(()) unsigned arange_table_allocated;
5326 /* Number of elements in arange_table currently in use. */
5327 static GTY(()) unsigned arange_table_in_use;
5329 /* Size (in elements) of increments by which we may expand the
5331 #define ARANGE_TABLE_INCREMENT 64
5333 /* Array of dies for which we should generate .debug_ranges info. */
5334 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5336 /* Number of elements currently allocated for ranges_table. */
5337 static GTY(()) unsigned ranges_table_allocated;
5339 /* Number of elements in ranges_table currently in use. */
5340 static GTY(()) unsigned ranges_table_in_use;
5342 /* Array of pairs of labels referenced in ranges_table. */
5343 static GTY ((length ("ranges_by_label_allocated")))
5344 dw_ranges_by_label_ref ranges_by_label;
5346 /* Number of elements currently allocated for ranges_by_label. */
5347 static GTY(()) unsigned ranges_by_label_allocated;
5349 /* Number of elements in ranges_by_label currently in use. */
5350 static GTY(()) unsigned ranges_by_label_in_use;
5352 /* Size (in elements) of increments by which we may expand the
5354 #define RANGES_TABLE_INCREMENT 64
5356 /* Whether we have location lists that need outputting */
5357 static GTY(()) bool have_location_lists;
5359 /* Unique label counter. */
5360 static GTY(()) unsigned int loclabel_num;
5362 #ifdef DWARF2_DEBUGGING_INFO
5363 /* Record whether the function being analyzed contains inlined functions. */
5364 static int current_function_has_inlines;
5366 #if 0 && defined (MIPS_DEBUGGING_INFO)
5367 static int comp_unit_has_inlines;
5370 /* The last file entry emitted by maybe_emit_file(). */
5371 static GTY(()) struct dwarf_file_data * last_emitted_file;
5373 /* Number of internal labels generated by gen_internal_sym(). */
5374 static GTY(()) int label_num;
5376 /* Cached result of previous call to lookup_filename. */
5377 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5379 #ifdef DWARF2_DEBUGGING_INFO
5381 /* Offset from the "steady-state frame pointer" to the frame base,
5382 within the current function. */
5383 static HOST_WIDE_INT frame_pointer_fb_offset;
5385 /* Forward declarations for functions defined in this file. */
5387 static int is_pseudo_reg (const_rtx);
5388 static tree type_main_variant (tree);
5389 static int is_tagged_type (const_tree);
5390 static const char *dwarf_tag_name (unsigned);
5391 static const char *dwarf_attr_name (unsigned);
5392 static const char *dwarf_form_name (unsigned);
5393 static tree decl_ultimate_origin (const_tree);
5394 static tree decl_class_context (tree);
5395 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5396 static inline enum dw_val_class AT_class (dw_attr_ref);
5397 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5398 static inline unsigned AT_flag (dw_attr_ref);
5399 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5400 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5401 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5402 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5403 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
5405 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5406 unsigned int, unsigned char *);
5407 static hashval_t debug_str_do_hash (const void *);
5408 static int debug_str_eq (const void *, const void *);
5409 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5410 static inline const char *AT_string (dw_attr_ref);
5411 static enum dwarf_form AT_string_form (dw_attr_ref);
5412 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5413 static void add_AT_specification (dw_die_ref, dw_die_ref);
5414 static inline dw_die_ref AT_ref (dw_attr_ref);
5415 static inline int AT_ref_external (dw_attr_ref);
5416 static inline void set_AT_ref_external (dw_attr_ref, int);
5417 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5418 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5419 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5420 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5422 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5423 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5424 static inline rtx AT_addr (dw_attr_ref);
5425 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5426 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5427 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5428 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5429 unsigned HOST_WIDE_INT);
5430 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5432 static inline const char *AT_lbl (dw_attr_ref);
5433 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5434 static const char *get_AT_low_pc (dw_die_ref);
5435 static const char *get_AT_hi_pc (dw_die_ref);
5436 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5437 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5438 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5439 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5440 static bool is_c_family (void);
5441 static bool is_cxx (void);
5442 static bool is_java (void);
5443 static bool is_fortran (void);
5444 static bool is_ada (void);
5445 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5446 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5447 static void add_child_die (dw_die_ref, dw_die_ref);
5448 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5449 static dw_die_ref lookup_type_die (tree);
5450 static void equate_type_number_to_die (tree, dw_die_ref);
5451 static hashval_t decl_die_table_hash (const void *);
5452 static int decl_die_table_eq (const void *, const void *);
5453 static dw_die_ref lookup_decl_die (tree);
5454 static hashval_t common_block_die_table_hash (const void *);
5455 static int common_block_die_table_eq (const void *, const void *);
5456 static hashval_t decl_loc_table_hash (const void *);
5457 static int decl_loc_table_eq (const void *, const void *);
5458 static var_loc_list *lookup_decl_loc (const_tree);
5459 static void equate_decl_number_to_die (tree, dw_die_ref);
5460 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5461 static void print_spaces (FILE *);
5462 static void print_die (dw_die_ref, FILE *);
5463 static void print_dwarf_line_table (FILE *);
5464 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5465 static dw_die_ref pop_compile_unit (dw_die_ref);
5466 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5467 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5468 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5469 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5470 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5471 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5472 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5473 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5474 static void compute_section_prefix (dw_die_ref);
5475 static int is_type_die (dw_die_ref);
5476 static int is_comdat_die (dw_die_ref);
5477 static int is_symbol_die (dw_die_ref);
5478 static void assign_symbol_names (dw_die_ref);
5479 static void break_out_includes (dw_die_ref);
5480 static hashval_t htab_cu_hash (const void *);
5481 static int htab_cu_eq (const void *, const void *);
5482 static void htab_cu_del (void *);
5483 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5484 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5485 static void add_sibling_attributes (dw_die_ref);
5486 static void build_abbrev_table (dw_die_ref);
5487 static void output_location_lists (dw_die_ref);
5488 static int constant_size (unsigned HOST_WIDE_INT);
5489 static unsigned long size_of_die (dw_die_ref);
5490 static void calc_die_sizes (dw_die_ref);
5491 static void mark_dies (dw_die_ref);
5492 static void unmark_dies (dw_die_ref);
5493 static void unmark_all_dies (dw_die_ref);
5494 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5495 static unsigned long size_of_aranges (void);
5496 static enum dwarf_form value_format (dw_attr_ref);
5497 static void output_value_format (dw_attr_ref);
5498 static void output_abbrev_section (void);
5499 static void output_die_symbol (dw_die_ref);
5500 static void output_die (dw_die_ref);
5501 static void output_compilation_unit_header (void);
5502 static void output_comp_unit (dw_die_ref, int);
5503 static const char *dwarf2_name (tree, int);
5504 static void add_pubname (tree, dw_die_ref);
5505 static void add_pubname_string (const char *, dw_die_ref);
5506 static void add_pubtype (tree, dw_die_ref);
5507 static void output_pubnames (VEC (pubname_entry,gc) *);
5508 static void add_arange (tree, dw_die_ref);
5509 static void output_aranges (void);
5510 static unsigned int add_ranges_num (int);
5511 static unsigned int add_ranges (const_tree);
5512 static unsigned int add_ranges_by_labels (const char *, const char *);
5513 static void output_ranges (void);
5514 static void output_line_info (void);
5515 static void output_file_names (void);
5516 static dw_die_ref base_type_die (tree);
5517 static int is_base_type (tree);
5518 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5519 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5520 static int type_is_enum (const_tree);
5521 static unsigned int dbx_reg_number (const_rtx);
5522 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5523 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5524 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5525 enum var_init_status);
5526 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5527 enum var_init_status);
5528 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5529 enum var_init_status);
5530 static int is_based_loc (const_rtx);
5531 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5532 enum var_init_status);
5533 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5534 enum var_init_status);
5535 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5536 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5537 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5538 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5539 static tree field_type (const_tree);
5540 static unsigned int simple_type_align_in_bits (const_tree);
5541 static unsigned int simple_decl_align_in_bits (const_tree);
5542 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5543 static HOST_WIDE_INT field_byte_offset (const_tree);
5544 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5546 static void add_data_member_location_attribute (dw_die_ref, tree);
5547 static void add_const_value_attribute (dw_die_ref, rtx);
5548 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5549 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5550 static void insert_float (const_rtx, unsigned char *);
5551 static rtx rtl_for_decl_location (tree);
5552 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5553 enum dwarf_attribute);
5554 static void tree_add_const_value_attribute (dw_die_ref, tree);
5555 static void add_name_attribute (dw_die_ref, const char *);
5556 static void add_comp_dir_attribute (dw_die_ref);
5557 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5558 static void add_subscript_info (dw_die_ref, tree, bool);
5559 static void add_byte_size_attribute (dw_die_ref, tree);
5560 static void add_bit_offset_attribute (dw_die_ref, tree);
5561 static void add_bit_size_attribute (dw_die_ref, tree);
5562 static void add_prototyped_attribute (dw_die_ref, tree);
5563 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5564 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5565 static void add_src_coords_attributes (dw_die_ref, tree);
5566 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5567 static void push_decl_scope (tree);
5568 static void pop_decl_scope (void);
5569 static dw_die_ref scope_die_for (tree, dw_die_ref);
5570 static inline int local_scope_p (dw_die_ref);
5571 static inline int class_scope_p (dw_die_ref);
5572 static inline int class_or_namespace_scope_p (dw_die_ref);
5573 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5574 static void add_calling_convention_attribute (dw_die_ref, tree);
5575 static const char *type_tag (const_tree);
5576 static tree member_declared_type (const_tree);
5578 static const char *decl_start_label (tree);
5580 static void gen_array_type_die (tree, dw_die_ref);
5581 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5583 static void gen_entry_point_die (tree, dw_die_ref);
5585 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5586 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5587 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5588 static void gen_formal_types_die (tree, dw_die_ref);
5589 static void gen_subprogram_die (tree, dw_die_ref);
5590 static void gen_variable_die (tree, tree, dw_die_ref);
5591 static void gen_const_die (tree, dw_die_ref);
5592 static void gen_label_die (tree, dw_die_ref);
5593 static void gen_lexical_block_die (tree, dw_die_ref, int);
5594 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5595 static void gen_field_die (tree, dw_die_ref);
5596 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5597 static dw_die_ref gen_compile_unit_die (const char *);
5598 static void gen_inheritance_die (tree, tree, dw_die_ref);
5599 static void gen_member_die (tree, dw_die_ref);
5600 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5601 enum debug_info_usage);
5602 static void gen_subroutine_type_die (tree, dw_die_ref);
5603 static void gen_typedef_die (tree, dw_die_ref);
5604 static void gen_type_die (tree, dw_die_ref);
5605 static void gen_block_die (tree, dw_die_ref, int);
5606 static void decls_for_scope (tree, dw_die_ref, int);
5607 static int is_redundant_typedef (const_tree);
5608 static void gen_namespace_die (tree, dw_die_ref);
5609 static void gen_decl_die (tree, tree, dw_die_ref);
5610 static dw_die_ref force_decl_die (tree);
5611 static dw_die_ref force_type_die (tree);
5612 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5613 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5614 static struct dwarf_file_data * lookup_filename (const char *);
5615 static void retry_incomplete_types (void);
5616 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5617 static void splice_child_die (dw_die_ref, dw_die_ref);
5618 static int file_info_cmp (const void *, const void *);
5619 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5620 const char *, const char *, unsigned);
5621 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5622 const char *, const char *,
5624 static void output_loc_list (dw_loc_list_ref);
5625 static char *gen_internal_sym (const char *);
5627 static void prune_unmark_dies (dw_die_ref);
5628 static void prune_unused_types_mark (dw_die_ref, int);
5629 static void prune_unused_types_walk (dw_die_ref);
5630 static void prune_unused_types_walk_attribs (dw_die_ref);
5631 static void prune_unused_types_prune (dw_die_ref);
5632 static void prune_unused_types (void);
5633 static int maybe_emit_file (struct dwarf_file_data *fd);
5635 /* Section names used to hold DWARF debugging information. */
5636 #ifndef DEBUG_INFO_SECTION
5637 #define DEBUG_INFO_SECTION ".debug_info"
5639 #ifndef DEBUG_ABBREV_SECTION
5640 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5642 #ifndef DEBUG_ARANGES_SECTION
5643 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5645 #ifndef DEBUG_MACINFO_SECTION
5646 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5648 #ifndef DEBUG_LINE_SECTION
5649 #define DEBUG_LINE_SECTION ".debug_line"
5651 #ifndef DEBUG_LOC_SECTION
5652 #define DEBUG_LOC_SECTION ".debug_loc"
5654 #ifndef DEBUG_PUBNAMES_SECTION
5655 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5657 #ifndef DEBUG_PUBTYPES_SECTION
5658 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
5660 #ifndef DEBUG_STR_SECTION
5661 #define DEBUG_STR_SECTION ".debug_str"
5663 #ifndef DEBUG_RANGES_SECTION
5664 #define DEBUG_RANGES_SECTION ".debug_ranges"
5667 /* Standard ELF section names for compiled code and data. */
5668 #ifndef TEXT_SECTION_NAME
5669 #define TEXT_SECTION_NAME ".text"
5672 /* Section flags for .debug_str section. */
5673 #define DEBUG_STR_SECTION_FLAGS \
5674 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5675 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5678 /* Labels we insert at beginning sections we can reference instead of
5679 the section names themselves. */
5681 #ifndef TEXT_SECTION_LABEL
5682 #define TEXT_SECTION_LABEL "Ltext"
5684 #ifndef COLD_TEXT_SECTION_LABEL
5685 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5687 #ifndef DEBUG_LINE_SECTION_LABEL
5688 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5690 #ifndef DEBUG_INFO_SECTION_LABEL
5691 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5693 #ifndef DEBUG_ABBREV_SECTION_LABEL
5694 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5696 #ifndef DEBUG_LOC_SECTION_LABEL
5697 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5699 #ifndef DEBUG_RANGES_SECTION_LABEL
5700 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5702 #ifndef DEBUG_MACINFO_SECTION_LABEL
5703 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5706 /* Definitions of defaults for formats and names of various special
5707 (artificial) labels which may be generated within this file (when the -g
5708 options is used and DWARF2_DEBUGGING_INFO is in effect.
5709 If necessary, these may be overridden from within the tm.h file, but
5710 typically, overriding these defaults is unnecessary. */
5712 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5713 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5714 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5715 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5716 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5717 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5718 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5719 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5720 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5721 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5723 #ifndef TEXT_END_LABEL
5724 #define TEXT_END_LABEL "Letext"
5726 #ifndef COLD_END_LABEL
5727 #define COLD_END_LABEL "Letext_cold"
5729 #ifndef BLOCK_BEGIN_LABEL
5730 #define BLOCK_BEGIN_LABEL "LBB"
5732 #ifndef BLOCK_END_LABEL
5733 #define BLOCK_END_LABEL "LBE"
5735 #ifndef LINE_CODE_LABEL
5736 #define LINE_CODE_LABEL "LM"
5738 #ifndef SEPARATE_LINE_CODE_LABEL
5739 #define SEPARATE_LINE_CODE_LABEL "LSM"
5743 /* We allow a language front-end to designate a function that is to be
5744 called to "demangle" any name before it is put into a DIE. */
5746 static const char *(*demangle_name_func) (const char *);
5749 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5751 demangle_name_func = func;
5754 /* Test if rtl node points to a pseudo register. */
5757 is_pseudo_reg (const_rtx rtl)
5759 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5760 || (GET_CODE (rtl) == SUBREG
5761 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5764 /* Return a reference to a type, with its const and volatile qualifiers
5768 type_main_variant (tree type)
5770 type = TYPE_MAIN_VARIANT (type);
5772 /* ??? There really should be only one main variant among any group of
5773 variants of a given type (and all of the MAIN_VARIANT values for all
5774 members of the group should point to that one type) but sometimes the C
5775 front-end messes this up for array types, so we work around that bug
5777 if (TREE_CODE (type) == ARRAY_TYPE)
5778 while (type != TYPE_MAIN_VARIANT (type))
5779 type = TYPE_MAIN_VARIANT (type);
5784 /* Return nonzero if the given type node represents a tagged type. */
5787 is_tagged_type (const_tree type)
5789 enum tree_code code = TREE_CODE (type);
5791 return (code == RECORD_TYPE || code == UNION_TYPE
5792 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5795 /* Convert a DIE tag into its string name. */
5798 dwarf_tag_name (unsigned int tag)
5802 case DW_TAG_padding:
5803 return "DW_TAG_padding";
5804 case DW_TAG_array_type:
5805 return "DW_TAG_array_type";
5806 case DW_TAG_class_type:
5807 return "DW_TAG_class_type";
5808 case DW_TAG_entry_point:
5809 return "DW_TAG_entry_point";
5810 case DW_TAG_enumeration_type:
5811 return "DW_TAG_enumeration_type";
5812 case DW_TAG_formal_parameter:
5813 return "DW_TAG_formal_parameter";
5814 case DW_TAG_imported_declaration:
5815 return "DW_TAG_imported_declaration";
5817 return "DW_TAG_label";
5818 case DW_TAG_lexical_block:
5819 return "DW_TAG_lexical_block";
5821 return "DW_TAG_member";
5822 case DW_TAG_pointer_type:
5823 return "DW_TAG_pointer_type";
5824 case DW_TAG_reference_type:
5825 return "DW_TAG_reference_type";
5826 case DW_TAG_compile_unit:
5827 return "DW_TAG_compile_unit";
5828 case DW_TAG_string_type:
5829 return "DW_TAG_string_type";
5830 case DW_TAG_structure_type:
5831 return "DW_TAG_structure_type";
5832 case DW_TAG_subroutine_type:
5833 return "DW_TAG_subroutine_type";
5834 case DW_TAG_typedef:
5835 return "DW_TAG_typedef";
5836 case DW_TAG_union_type:
5837 return "DW_TAG_union_type";
5838 case DW_TAG_unspecified_parameters:
5839 return "DW_TAG_unspecified_parameters";
5840 case DW_TAG_variant:
5841 return "DW_TAG_variant";
5842 case DW_TAG_common_block:
5843 return "DW_TAG_common_block";
5844 case DW_TAG_common_inclusion:
5845 return "DW_TAG_common_inclusion";
5846 case DW_TAG_inheritance:
5847 return "DW_TAG_inheritance";
5848 case DW_TAG_inlined_subroutine:
5849 return "DW_TAG_inlined_subroutine";
5851 return "DW_TAG_module";
5852 case DW_TAG_ptr_to_member_type:
5853 return "DW_TAG_ptr_to_member_type";
5854 case DW_TAG_set_type:
5855 return "DW_TAG_set_type";
5856 case DW_TAG_subrange_type:
5857 return "DW_TAG_subrange_type";
5858 case DW_TAG_with_stmt:
5859 return "DW_TAG_with_stmt";
5860 case DW_TAG_access_declaration:
5861 return "DW_TAG_access_declaration";
5862 case DW_TAG_base_type:
5863 return "DW_TAG_base_type";
5864 case DW_TAG_catch_block:
5865 return "DW_TAG_catch_block";
5866 case DW_TAG_const_type:
5867 return "DW_TAG_const_type";
5868 case DW_TAG_constant:
5869 return "DW_TAG_constant";
5870 case DW_TAG_enumerator:
5871 return "DW_TAG_enumerator";
5872 case DW_TAG_file_type:
5873 return "DW_TAG_file_type";
5875 return "DW_TAG_friend";
5876 case DW_TAG_namelist:
5877 return "DW_TAG_namelist";
5878 case DW_TAG_namelist_item:
5879 return "DW_TAG_namelist_item";
5880 case DW_TAG_packed_type:
5881 return "DW_TAG_packed_type";
5882 case DW_TAG_subprogram:
5883 return "DW_TAG_subprogram";
5884 case DW_TAG_template_type_param:
5885 return "DW_TAG_template_type_param";
5886 case DW_TAG_template_value_param:
5887 return "DW_TAG_template_value_param";
5888 case DW_TAG_thrown_type:
5889 return "DW_TAG_thrown_type";
5890 case DW_TAG_try_block:
5891 return "DW_TAG_try_block";
5892 case DW_TAG_variant_part:
5893 return "DW_TAG_variant_part";
5894 case DW_TAG_variable:
5895 return "DW_TAG_variable";
5896 case DW_TAG_volatile_type:
5897 return "DW_TAG_volatile_type";
5898 case DW_TAG_dwarf_procedure:
5899 return "DW_TAG_dwarf_procedure";
5900 case DW_TAG_restrict_type:
5901 return "DW_TAG_restrict_type";
5902 case DW_TAG_interface_type:
5903 return "DW_TAG_interface_type";
5904 case DW_TAG_namespace:
5905 return "DW_TAG_namespace";
5906 case DW_TAG_imported_module:
5907 return "DW_TAG_imported_module";
5908 case DW_TAG_unspecified_type:
5909 return "DW_TAG_unspecified_type";
5910 case DW_TAG_partial_unit:
5911 return "DW_TAG_partial_unit";
5912 case DW_TAG_imported_unit:
5913 return "DW_TAG_imported_unit";
5914 case DW_TAG_condition:
5915 return "DW_TAG_condition";
5916 case DW_TAG_shared_type:
5917 return "DW_TAG_shared_type";
5918 case DW_TAG_MIPS_loop:
5919 return "DW_TAG_MIPS_loop";
5920 case DW_TAG_format_label:
5921 return "DW_TAG_format_label";
5922 case DW_TAG_function_template:
5923 return "DW_TAG_function_template";
5924 case DW_TAG_class_template:
5925 return "DW_TAG_class_template";
5926 case DW_TAG_GNU_BINCL:
5927 return "DW_TAG_GNU_BINCL";
5928 case DW_TAG_GNU_EINCL:
5929 return "DW_TAG_GNU_EINCL";
5931 return "DW_TAG_<unknown>";
5935 /* Convert a DWARF attribute code into its string name. */
5938 dwarf_attr_name (unsigned int attr)
5943 return "DW_AT_sibling";
5944 case DW_AT_location:
5945 return "DW_AT_location";
5947 return "DW_AT_name";
5948 case DW_AT_ordering:
5949 return "DW_AT_ordering";
5950 case DW_AT_subscr_data:
5951 return "DW_AT_subscr_data";
5952 case DW_AT_byte_size:
5953 return "DW_AT_byte_size";
5954 case DW_AT_bit_offset:
5955 return "DW_AT_bit_offset";
5956 case DW_AT_bit_size:
5957 return "DW_AT_bit_size";
5958 case DW_AT_element_list:
5959 return "DW_AT_element_list";
5960 case DW_AT_stmt_list:
5961 return "DW_AT_stmt_list";
5963 return "DW_AT_low_pc";
5965 return "DW_AT_high_pc";
5966 case DW_AT_language:
5967 return "DW_AT_language";
5969 return "DW_AT_member";
5971 return "DW_AT_discr";
5972 case DW_AT_discr_value:
5973 return "DW_AT_discr_value";
5974 case DW_AT_visibility:
5975 return "DW_AT_visibility";
5977 return "DW_AT_import";
5978 case DW_AT_string_length:
5979 return "DW_AT_string_length";
5980 case DW_AT_common_reference:
5981 return "DW_AT_common_reference";
5982 case DW_AT_comp_dir:
5983 return "DW_AT_comp_dir";
5984 case DW_AT_const_value:
5985 return "DW_AT_const_value";
5986 case DW_AT_containing_type:
5987 return "DW_AT_containing_type";
5988 case DW_AT_default_value:
5989 return "DW_AT_default_value";
5991 return "DW_AT_inline";
5992 case DW_AT_is_optional:
5993 return "DW_AT_is_optional";
5994 case DW_AT_lower_bound:
5995 return "DW_AT_lower_bound";
5996 case DW_AT_producer:
5997 return "DW_AT_producer";
5998 case DW_AT_prototyped:
5999 return "DW_AT_prototyped";
6000 case DW_AT_return_addr:
6001 return "DW_AT_return_addr";
6002 case DW_AT_start_scope:
6003 return "DW_AT_start_scope";
6004 case DW_AT_bit_stride:
6005 return "DW_AT_bit_stride";
6006 case DW_AT_upper_bound:
6007 return "DW_AT_upper_bound";
6008 case DW_AT_abstract_origin:
6009 return "DW_AT_abstract_origin";
6010 case DW_AT_accessibility:
6011 return "DW_AT_accessibility";
6012 case DW_AT_address_class:
6013 return "DW_AT_address_class";
6014 case DW_AT_artificial:
6015 return "DW_AT_artificial";
6016 case DW_AT_base_types:
6017 return "DW_AT_base_types";
6018 case DW_AT_calling_convention:
6019 return "DW_AT_calling_convention";
6021 return "DW_AT_count";
6022 case DW_AT_data_member_location:
6023 return "DW_AT_data_member_location";
6024 case DW_AT_decl_column:
6025 return "DW_AT_decl_column";
6026 case DW_AT_decl_file:
6027 return "DW_AT_decl_file";
6028 case DW_AT_decl_line:
6029 return "DW_AT_decl_line";
6030 case DW_AT_declaration:
6031 return "DW_AT_declaration";
6032 case DW_AT_discr_list:
6033 return "DW_AT_discr_list";
6034 case DW_AT_encoding:
6035 return "DW_AT_encoding";
6036 case DW_AT_external:
6037 return "DW_AT_external";
6038 case DW_AT_explicit:
6039 return "DW_AT_explicit";
6040 case DW_AT_frame_base:
6041 return "DW_AT_frame_base";
6043 return "DW_AT_friend";
6044 case DW_AT_identifier_case:
6045 return "DW_AT_identifier_case";
6046 case DW_AT_macro_info:
6047 return "DW_AT_macro_info";
6048 case DW_AT_namelist_items:
6049 return "DW_AT_namelist_items";
6050 case DW_AT_priority:
6051 return "DW_AT_priority";
6053 return "DW_AT_segment";
6054 case DW_AT_specification:
6055 return "DW_AT_specification";
6056 case DW_AT_static_link:
6057 return "DW_AT_static_link";
6059 return "DW_AT_type";
6060 case DW_AT_use_location:
6061 return "DW_AT_use_location";
6062 case DW_AT_variable_parameter:
6063 return "DW_AT_variable_parameter";
6064 case DW_AT_virtuality:
6065 return "DW_AT_virtuality";
6066 case DW_AT_vtable_elem_location:
6067 return "DW_AT_vtable_elem_location";
6069 case DW_AT_allocated:
6070 return "DW_AT_allocated";
6071 case DW_AT_associated:
6072 return "DW_AT_associated";
6073 case DW_AT_data_location:
6074 return "DW_AT_data_location";
6075 case DW_AT_byte_stride:
6076 return "DW_AT_byte_stride";
6077 case DW_AT_entry_pc:
6078 return "DW_AT_entry_pc";
6079 case DW_AT_use_UTF8:
6080 return "DW_AT_use_UTF8";
6081 case DW_AT_extension:
6082 return "DW_AT_extension";
6084 return "DW_AT_ranges";
6085 case DW_AT_trampoline:
6086 return "DW_AT_trampoline";
6087 case DW_AT_call_column:
6088 return "DW_AT_call_column";
6089 case DW_AT_call_file:
6090 return "DW_AT_call_file";
6091 case DW_AT_call_line:
6092 return "DW_AT_call_line";
6094 case DW_AT_MIPS_fde:
6095 return "DW_AT_MIPS_fde";
6096 case DW_AT_MIPS_loop_begin:
6097 return "DW_AT_MIPS_loop_begin";
6098 case DW_AT_MIPS_tail_loop_begin:
6099 return "DW_AT_MIPS_tail_loop_begin";
6100 case DW_AT_MIPS_epilog_begin:
6101 return "DW_AT_MIPS_epilog_begin";
6102 case DW_AT_MIPS_loop_unroll_factor:
6103 return "DW_AT_MIPS_loop_unroll_factor";
6104 case DW_AT_MIPS_software_pipeline_depth:
6105 return "DW_AT_MIPS_software_pipeline_depth";
6106 case DW_AT_MIPS_linkage_name:
6107 return "DW_AT_MIPS_linkage_name";
6108 case DW_AT_MIPS_stride:
6109 return "DW_AT_MIPS_stride";
6110 case DW_AT_MIPS_abstract_name:
6111 return "DW_AT_MIPS_abstract_name";
6112 case DW_AT_MIPS_clone_origin:
6113 return "DW_AT_MIPS_clone_origin";
6114 case DW_AT_MIPS_has_inlines:
6115 return "DW_AT_MIPS_has_inlines";
6117 case DW_AT_sf_names:
6118 return "DW_AT_sf_names";
6119 case DW_AT_src_info:
6120 return "DW_AT_src_info";
6121 case DW_AT_mac_info:
6122 return "DW_AT_mac_info";
6123 case DW_AT_src_coords:
6124 return "DW_AT_src_coords";
6125 case DW_AT_body_begin:
6126 return "DW_AT_body_begin";
6127 case DW_AT_body_end:
6128 return "DW_AT_body_end";
6129 case DW_AT_GNU_vector:
6130 return "DW_AT_GNU_vector";
6132 case DW_AT_VMS_rtnbeg_pd_address:
6133 return "DW_AT_VMS_rtnbeg_pd_address";
6136 return "DW_AT_<unknown>";
6140 /* Convert a DWARF value form code into its string name. */
6143 dwarf_form_name (unsigned int form)
6148 return "DW_FORM_addr";
6149 case DW_FORM_block2:
6150 return "DW_FORM_block2";
6151 case DW_FORM_block4:
6152 return "DW_FORM_block4";
6154 return "DW_FORM_data2";
6156 return "DW_FORM_data4";
6158 return "DW_FORM_data8";
6159 case DW_FORM_string:
6160 return "DW_FORM_string";
6162 return "DW_FORM_block";
6163 case DW_FORM_block1:
6164 return "DW_FORM_block1";
6166 return "DW_FORM_data1";
6168 return "DW_FORM_flag";
6170 return "DW_FORM_sdata";
6172 return "DW_FORM_strp";
6174 return "DW_FORM_udata";
6175 case DW_FORM_ref_addr:
6176 return "DW_FORM_ref_addr";
6178 return "DW_FORM_ref1";
6180 return "DW_FORM_ref2";
6182 return "DW_FORM_ref4";
6184 return "DW_FORM_ref8";
6185 case DW_FORM_ref_udata:
6186 return "DW_FORM_ref_udata";
6187 case DW_FORM_indirect:
6188 return "DW_FORM_indirect";
6190 return "DW_FORM_<unknown>";
6194 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6195 instance of an inlined instance of a decl which is local to an inline
6196 function, so we have to trace all of the way back through the origin chain
6197 to find out what sort of node actually served as the original seed for the
6201 decl_ultimate_origin (const_tree decl)
6203 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6206 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6207 nodes in the function to point to themselves; ignore that if
6208 we're trying to output the abstract instance of this function. */
6209 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6212 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6213 most distant ancestor, this should never happen. */
6214 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6216 return DECL_ABSTRACT_ORIGIN (decl);
6219 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6220 of a virtual function may refer to a base class, so we check the 'this'
6224 decl_class_context (tree decl)
6226 tree context = NULL_TREE;
6228 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6229 context = DECL_CONTEXT (decl);
6231 context = TYPE_MAIN_VARIANT
6232 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6234 if (context && !TYPE_P (context))
6235 context = NULL_TREE;
6240 /* Add an attribute/value pair to a DIE. */
6243 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6245 /* Maybe this should be an assert? */
6249 if (die->die_attr == NULL)
6250 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6251 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6254 static inline enum dw_val_class
6255 AT_class (dw_attr_ref a)
6257 return a->dw_attr_val.val_class;
6260 /* Add a flag value attribute to a DIE. */
6263 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6267 attr.dw_attr = attr_kind;
6268 attr.dw_attr_val.val_class = dw_val_class_flag;
6269 attr.dw_attr_val.v.val_flag = flag;
6270 add_dwarf_attr (die, &attr);
6273 static inline unsigned
6274 AT_flag (dw_attr_ref a)
6276 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6277 return a->dw_attr_val.v.val_flag;
6280 /* Add a signed integer attribute value to a DIE. */
6283 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6287 attr.dw_attr = attr_kind;
6288 attr.dw_attr_val.val_class = dw_val_class_const;
6289 attr.dw_attr_val.v.val_int = int_val;
6290 add_dwarf_attr (die, &attr);
6293 static inline HOST_WIDE_INT
6294 AT_int (dw_attr_ref a)
6296 gcc_assert (a && AT_class (a) == dw_val_class_const);
6297 return a->dw_attr_val.v.val_int;
6300 /* Add an unsigned integer attribute value to a DIE. */
6303 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6304 unsigned HOST_WIDE_INT unsigned_val)
6308 attr.dw_attr = attr_kind;
6309 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6310 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6311 add_dwarf_attr (die, &attr);
6314 static inline unsigned HOST_WIDE_INT
6315 AT_unsigned (dw_attr_ref a)
6317 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6318 return a->dw_attr_val.v.val_unsigned;
6321 /* Add an unsigned double integer attribute value to a DIE. */
6324 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6325 long unsigned int val_hi, long unsigned int val_low)
6329 attr.dw_attr = attr_kind;
6330 attr.dw_attr_val.val_class = dw_val_class_long_long;
6331 attr.dw_attr_val.v.val_long_long.hi = val_hi;
6332 attr.dw_attr_val.v.val_long_long.low = val_low;
6333 add_dwarf_attr (die, &attr);
6336 /* Add a floating point attribute value to a DIE and return it. */
6339 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6340 unsigned int length, unsigned int elt_size, unsigned char *array)
6344 attr.dw_attr = attr_kind;
6345 attr.dw_attr_val.val_class = dw_val_class_vec;
6346 attr.dw_attr_val.v.val_vec.length = length;
6347 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6348 attr.dw_attr_val.v.val_vec.array = array;
6349 add_dwarf_attr (die, &attr);
6352 /* Hash and equality functions for debug_str_hash. */
6355 debug_str_do_hash (const void *x)
6357 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6361 debug_str_eq (const void *x1, const void *x2)
6363 return strcmp ((((const struct indirect_string_node *)x1)->str),
6364 (const char *)x2) == 0;
6367 static struct indirect_string_node *
6368 find_AT_string (const char *str)
6370 struct indirect_string_node *node;
6373 if (! debug_str_hash)
6374 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6375 debug_str_eq, NULL);
6377 slot = htab_find_slot_with_hash (debug_str_hash, str,
6378 htab_hash_string (str), INSERT);
6381 node = (struct indirect_string_node *)
6382 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6383 node->str = ggc_strdup (str);
6387 node = (struct indirect_string_node *) *slot;
6393 /* Add a string attribute value to a DIE. */
6396 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6399 struct indirect_string_node *node;
6401 node = find_AT_string (str);
6403 attr.dw_attr = attr_kind;
6404 attr.dw_attr_val.val_class = dw_val_class_str;
6405 attr.dw_attr_val.v.val_str = node;
6406 add_dwarf_attr (die, &attr);
6409 static inline const char *
6410 AT_string (dw_attr_ref a)
6412 gcc_assert (a && AT_class (a) == dw_val_class_str);
6413 return a->dw_attr_val.v.val_str->str;
6416 /* Find out whether a string should be output inline in DIE
6417 or out-of-line in .debug_str section. */
6419 static enum dwarf_form
6420 AT_string_form (dw_attr_ref a)
6422 struct indirect_string_node *node;
6426 gcc_assert (a && AT_class (a) == dw_val_class_str);
6428 node = a->dw_attr_val.v.val_str;
6432 len = strlen (node->str) + 1;
6434 /* If the string is shorter or equal to the size of the reference, it is
6435 always better to put it inline. */
6436 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6437 return node->form = DW_FORM_string;
6439 /* If we cannot expect the linker to merge strings in .debug_str
6440 section, only put it into .debug_str if it is worth even in this
6442 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
6443 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
6444 return node->form = DW_FORM_string;
6446 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6447 ++dw2_string_counter;
6448 node->label = xstrdup (label);
6450 return node->form = DW_FORM_strp;
6453 /* Add a DIE reference attribute value to a DIE. */
6456 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6460 attr.dw_attr = attr_kind;
6461 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6462 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6463 attr.dw_attr_val.v.val_die_ref.external = 0;
6464 add_dwarf_attr (die, &attr);
6467 /* Add an AT_specification attribute to a DIE, and also make the back
6468 pointer from the specification to the definition. */
6471 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6473 add_AT_die_ref (die, DW_AT_specification, targ_die);
6474 gcc_assert (!targ_die->die_definition);
6475 targ_die->die_definition = die;
6478 static inline dw_die_ref
6479 AT_ref (dw_attr_ref a)
6481 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6482 return a->dw_attr_val.v.val_die_ref.die;
6486 AT_ref_external (dw_attr_ref a)
6488 if (a && AT_class (a) == dw_val_class_die_ref)
6489 return a->dw_attr_val.v.val_die_ref.external;
6495 set_AT_ref_external (dw_attr_ref a, int i)
6497 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6498 a->dw_attr_val.v.val_die_ref.external = i;
6501 /* Add an FDE reference attribute value to a DIE. */
6504 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6508 attr.dw_attr = attr_kind;
6509 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6510 attr.dw_attr_val.v.val_fde_index = targ_fde;
6511 add_dwarf_attr (die, &attr);
6514 /* Add a location description attribute value to a DIE. */
6517 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6521 attr.dw_attr = attr_kind;
6522 attr.dw_attr_val.val_class = dw_val_class_loc;
6523 attr.dw_attr_val.v.val_loc = loc;
6524 add_dwarf_attr (die, &attr);
6527 static inline dw_loc_descr_ref
6528 AT_loc (dw_attr_ref a)
6530 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6531 return a->dw_attr_val.v.val_loc;
6535 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6539 attr.dw_attr = attr_kind;
6540 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6541 attr.dw_attr_val.v.val_loc_list = loc_list;
6542 add_dwarf_attr (die, &attr);
6543 have_location_lists = true;
6546 static inline dw_loc_list_ref
6547 AT_loc_list (dw_attr_ref a)
6549 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6550 return a->dw_attr_val.v.val_loc_list;
6553 /* Add an address constant attribute value to a DIE. */
6556 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6560 attr.dw_attr = attr_kind;
6561 attr.dw_attr_val.val_class = dw_val_class_addr;
6562 attr.dw_attr_val.v.val_addr = addr;
6563 add_dwarf_attr (die, &attr);
6566 /* Get the RTX from to an address DIE attribute. */
6569 AT_addr (dw_attr_ref a)
6571 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6572 return a->dw_attr_val.v.val_addr;
6575 /* Add a file attribute value to a DIE. */
6578 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6579 struct dwarf_file_data *fd)
6583 attr.dw_attr = attr_kind;
6584 attr.dw_attr_val.val_class = dw_val_class_file;
6585 attr.dw_attr_val.v.val_file = fd;
6586 add_dwarf_attr (die, &attr);
6589 /* Get the dwarf_file_data from a file DIE attribute. */
6591 static inline struct dwarf_file_data *
6592 AT_file (dw_attr_ref a)
6594 gcc_assert (a && AT_class (a) == dw_val_class_file);
6595 return a->dw_attr_val.v.val_file;
6598 /* Add a label identifier attribute value to a DIE. */
6601 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6605 attr.dw_attr = attr_kind;
6606 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6607 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6608 add_dwarf_attr (die, &attr);
6611 /* Add a section offset attribute value to a DIE, an offset into the
6612 debug_line section. */
6615 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6620 attr.dw_attr = attr_kind;
6621 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6622 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6623 add_dwarf_attr (die, &attr);
6626 /* Add a section offset attribute value to a DIE, an offset into the
6627 debug_macinfo section. */
6630 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6635 attr.dw_attr = attr_kind;
6636 attr.dw_attr_val.val_class = dw_val_class_macptr;
6637 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6638 add_dwarf_attr (die, &attr);
6641 /* Add an offset attribute value to a DIE. */
6644 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6645 unsigned HOST_WIDE_INT offset)
6649 attr.dw_attr = attr_kind;
6650 attr.dw_attr_val.val_class = dw_val_class_offset;
6651 attr.dw_attr_val.v.val_offset = offset;
6652 add_dwarf_attr (die, &attr);
6655 /* Add an range_list attribute value to a DIE. */
6658 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6659 long unsigned int offset)
6663 attr.dw_attr = attr_kind;
6664 attr.dw_attr_val.val_class = dw_val_class_range_list;
6665 attr.dw_attr_val.v.val_offset = offset;
6666 add_dwarf_attr (die, &attr);
6669 static inline const char *
6670 AT_lbl (dw_attr_ref a)
6672 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6673 || AT_class (a) == dw_val_class_lineptr
6674 || AT_class (a) == dw_val_class_macptr));
6675 return a->dw_attr_val.v.val_lbl_id;
6678 /* Get the attribute of type attr_kind. */
6681 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6685 dw_die_ref spec = NULL;
6690 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6691 if (a->dw_attr == attr_kind)
6693 else if (a->dw_attr == DW_AT_specification
6694 || a->dw_attr == DW_AT_abstract_origin)
6698 return get_AT (spec, attr_kind);
6703 /* Return the "low pc" attribute value, typically associated with a subprogram
6704 DIE. Return null if the "low pc" attribute is either not present, or if it
6705 cannot be represented as an assembler label identifier. */
6707 static inline const char *
6708 get_AT_low_pc (dw_die_ref die)
6710 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6712 return a ? AT_lbl (a) : NULL;
6715 /* Return the "high pc" attribute value, typically associated with a subprogram
6716 DIE. Return null if the "high pc" attribute is either not present, or if it
6717 cannot be represented as an assembler label identifier. */
6719 static inline const char *
6720 get_AT_hi_pc (dw_die_ref die)
6722 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6724 return a ? AT_lbl (a) : NULL;
6727 /* Return the value of the string attribute designated by ATTR_KIND, or
6728 NULL if it is not present. */
6730 static inline const char *
6731 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6733 dw_attr_ref a = get_AT (die, attr_kind);
6735 return a ? AT_string (a) : NULL;
6738 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6739 if it is not present. */
6742 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6744 dw_attr_ref a = get_AT (die, attr_kind);
6746 return a ? AT_flag (a) : 0;
6749 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6750 if it is not present. */
6752 static inline unsigned
6753 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6755 dw_attr_ref a = get_AT (die, attr_kind);
6757 return a ? AT_unsigned (a) : 0;
6760 static inline dw_die_ref
6761 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6763 dw_attr_ref a = get_AT (die, attr_kind);
6765 return a ? AT_ref (a) : NULL;
6768 static inline struct dwarf_file_data *
6769 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6771 dw_attr_ref a = get_AT (die, attr_kind);
6773 return a ? AT_file (a) : NULL;
6776 /* Return TRUE if the language is C or C++. */
6781 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6783 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6784 || lang == DW_LANG_C99
6785 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6788 /* Return TRUE if the language is C++. */
6793 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6795 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6798 /* Return TRUE if the language is Fortran. */
6803 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6805 return (lang == DW_LANG_Fortran77
6806 || lang == DW_LANG_Fortran90
6807 || lang == DW_LANG_Fortran95);
6810 /* Return TRUE if the language is Java. */
6815 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6817 return lang == DW_LANG_Java;
6820 /* Return TRUE if the language is Ada. */
6825 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6827 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6830 /* Remove the specified attribute if present. */
6833 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6841 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6842 if (a->dw_attr == attr_kind)
6844 if (AT_class (a) == dw_val_class_str)
6845 if (a->dw_attr_val.v.val_str->refcount)
6846 a->dw_attr_val.v.val_str->refcount--;
6848 /* VEC_ordered_remove should help reduce the number of abbrevs
6850 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6855 /* Remove CHILD from its parent. PREV must have the property that
6856 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6859 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6861 gcc_assert (child->die_parent == prev->die_parent);
6862 gcc_assert (prev->die_sib == child);
6865 gcc_assert (child->die_parent->die_child == child);
6869 prev->die_sib = child->die_sib;
6870 if (child->die_parent->die_child == child)
6871 child->die_parent->die_child = prev;
6874 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6878 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6884 dw_die_ref prev = c;
6886 while (c->die_tag == tag)
6888 remove_child_with_prev (c, prev);
6889 /* Might have removed every child. */
6890 if (c == c->die_sib)
6894 } while (c != die->die_child);
6897 /* Add a CHILD_DIE as the last child of DIE. */
6900 add_child_die (dw_die_ref die, dw_die_ref child_die)
6902 /* FIXME this should probably be an assert. */
6903 if (! die || ! child_die)
6905 gcc_assert (die != child_die);
6907 child_die->die_parent = die;
6910 child_die->die_sib = die->die_child->die_sib;
6911 die->die_child->die_sib = child_die;
6914 child_die->die_sib = child_die;
6915 die->die_child = child_die;
6918 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6919 is the specification, to the end of PARENT's list of children.
6920 This is done by removing and re-adding it. */
6923 splice_child_die (dw_die_ref parent, dw_die_ref child)
6927 /* We want the declaration DIE from inside the class, not the
6928 specification DIE at toplevel. */
6929 if (child->die_parent != parent)
6931 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6937 gcc_assert (child->die_parent == parent
6938 || (child->die_parent
6939 == get_AT_ref (parent, DW_AT_specification)));
6941 for (p = child->die_parent->die_child; ; p = p->die_sib)
6942 if (p->die_sib == child)
6944 remove_child_with_prev (child, p);
6948 add_child_die (parent, child);
6951 /* Return a pointer to a newly created DIE node. */
6953 static inline dw_die_ref
6954 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6956 dw_die_ref die = GGC_CNEW (die_node);
6958 die->die_tag = tag_value;
6960 if (parent_die != NULL)
6961 add_child_die (parent_die, die);
6964 limbo_die_node *limbo_node;
6966 limbo_node = GGC_CNEW (limbo_die_node);
6967 limbo_node->die = die;
6968 limbo_node->created_for = t;
6969 limbo_node->next = limbo_die_list;
6970 limbo_die_list = limbo_node;
6976 /* Return the DIE associated with the given type specifier. */
6978 static inline dw_die_ref
6979 lookup_type_die (tree type)
6981 return TYPE_SYMTAB_DIE (type);
6984 /* Equate a DIE to a given type specifier. */
6987 equate_type_number_to_die (tree type, dw_die_ref type_die)
6989 TYPE_SYMTAB_DIE (type) = type_die;
6992 /* Returns a hash value for X (which really is a die_struct). */
6995 decl_die_table_hash (const void *x)
6997 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7000 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7003 decl_die_table_eq (const void *x, const void *y)
7005 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7008 /* Return the DIE associated with a given declaration. */
7010 static inline dw_die_ref
7011 lookup_decl_die (tree decl)
7013 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7016 /* Returns a hash value for X (which really is a var_loc_list). */
7019 decl_loc_table_hash (const void *x)
7021 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7024 /* Return nonzero if decl_id of var_loc_list X is the same as
7028 decl_loc_table_eq (const void *x, const void *y)
7030 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7033 /* Return the var_loc list associated with a given declaration. */
7035 static inline var_loc_list *
7036 lookup_decl_loc (const_tree decl)
7038 return (var_loc_list *)
7039 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7042 /* Equate a DIE to a particular declaration. */
7045 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7047 unsigned int decl_id = DECL_UID (decl);
7050 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7052 decl_die->decl_id = decl_id;
7055 /* Add a variable location node to the linked list for DECL. */
7058 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7060 unsigned int decl_id = DECL_UID (decl);
7064 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7067 temp = GGC_CNEW (var_loc_list);
7068 temp->decl_id = decl_id;
7072 temp = (var_loc_list *) *slot;
7076 /* If the current location is the same as the end of the list,
7077 and either both or neither of the locations is uninitialized,
7078 we have nothing to do. */
7079 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7080 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7081 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7082 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7083 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7084 == VAR_INIT_STATUS_UNINITIALIZED)
7085 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7086 == VAR_INIT_STATUS_UNINITIALIZED))))
7088 /* Add LOC to the end of list and update LAST. */
7089 temp->last->next = loc;
7093 /* Do not add empty location to the beginning of the list. */
7094 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7101 /* Keep track of the number of spaces used to indent the
7102 output of the debugging routines that print the structure of
7103 the DIE internal representation. */
7104 static int print_indent;
7106 /* Indent the line the number of spaces given by print_indent. */
7109 print_spaces (FILE *outfile)
7111 fprintf (outfile, "%*s", print_indent, "");
7114 /* Print the information associated with a given DIE, and its children.
7115 This routine is a debugging aid only. */
7118 print_die (dw_die_ref die, FILE *outfile)
7124 print_spaces (outfile);
7125 fprintf (outfile, "DIE %4ld: %s\n",
7126 die->die_offset, dwarf_tag_name (die->die_tag));
7127 print_spaces (outfile);
7128 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7129 fprintf (outfile, " offset: %ld\n", die->die_offset);
7131 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7133 print_spaces (outfile);
7134 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7136 switch (AT_class (a))
7138 case dw_val_class_addr:
7139 fprintf (outfile, "address");
7141 case dw_val_class_offset:
7142 fprintf (outfile, "offset");
7144 case dw_val_class_loc:
7145 fprintf (outfile, "location descriptor");
7147 case dw_val_class_loc_list:
7148 fprintf (outfile, "location list -> label:%s",
7149 AT_loc_list (a)->ll_symbol);
7151 case dw_val_class_range_list:
7152 fprintf (outfile, "range list");
7154 case dw_val_class_const:
7155 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7157 case dw_val_class_unsigned_const:
7158 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7160 case dw_val_class_long_long:
7161 fprintf (outfile, "constant (%lu,%lu)",
7162 a->dw_attr_val.v.val_long_long.hi,
7163 a->dw_attr_val.v.val_long_long.low);
7165 case dw_val_class_vec:
7166 fprintf (outfile, "floating-point or vector constant");
7168 case dw_val_class_flag:
7169 fprintf (outfile, "%u", AT_flag (a));
7171 case dw_val_class_die_ref:
7172 if (AT_ref (a) != NULL)
7174 if (AT_ref (a)->die_symbol)
7175 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7177 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7180 fprintf (outfile, "die -> <null>");
7182 case dw_val_class_lbl_id:
7183 case dw_val_class_lineptr:
7184 case dw_val_class_macptr:
7185 fprintf (outfile, "label: %s", AT_lbl (a));
7187 case dw_val_class_str:
7188 if (AT_string (a) != NULL)
7189 fprintf (outfile, "\"%s\"", AT_string (a));
7191 fprintf (outfile, "<null>");
7193 case dw_val_class_file:
7194 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7195 AT_file (a)->emitted_number);
7201 fprintf (outfile, "\n");
7204 if (die->die_child != NULL)
7207 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7210 if (print_indent == 0)
7211 fprintf (outfile, "\n");
7214 /* Print the contents of the source code line number correspondence table.
7215 This routine is a debugging aid only. */
7218 print_dwarf_line_table (FILE *outfile)
7221 dw_line_info_ref line_info;
7223 fprintf (outfile, "\n\nDWARF source line information\n");
7224 for (i = 1; i < line_info_table_in_use; i++)
7226 line_info = &line_info_table[i];
7227 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7228 line_info->dw_file_num,
7229 line_info->dw_line_num);
7232 fprintf (outfile, "\n\n");
7235 /* Print the information collected for a given DIE. */
7238 debug_dwarf_die (dw_die_ref die)
7240 print_die (die, stderr);
7243 /* Print all DWARF information collected for the compilation unit.
7244 This routine is a debugging aid only. */
7250 print_die (comp_unit_die, stderr);
7251 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7252 print_dwarf_line_table (stderr);
7255 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7256 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7257 DIE that marks the start of the DIEs for this include file. */
7260 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7262 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7263 dw_die_ref new_unit = gen_compile_unit_die (filename);
7265 new_unit->die_sib = old_unit;
7269 /* Close an include-file CU and reopen the enclosing one. */
7272 pop_compile_unit (dw_die_ref old_unit)
7274 dw_die_ref new_unit = old_unit->die_sib;
7276 old_unit->die_sib = NULL;
7280 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7281 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7283 /* Calculate the checksum of a location expression. */
7286 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7290 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7292 CHECKSUM (loc->dw_loc_oprnd1);
7293 CHECKSUM (loc->dw_loc_oprnd2);
7296 /* Calculate the checksum of an attribute. */
7299 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7301 dw_loc_descr_ref loc;
7304 CHECKSUM (at->dw_attr);
7306 /* We don't care that this was compiled with a different compiler
7307 snapshot; if the output is the same, that's what matters. */
7308 if (at->dw_attr == DW_AT_producer)
7311 switch (AT_class (at))
7313 case dw_val_class_const:
7314 CHECKSUM (at->dw_attr_val.v.val_int);
7316 case dw_val_class_unsigned_const:
7317 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7319 case dw_val_class_long_long:
7320 CHECKSUM (at->dw_attr_val.v.val_long_long);
7322 case dw_val_class_vec:
7323 CHECKSUM (at->dw_attr_val.v.val_vec);
7325 case dw_val_class_flag:
7326 CHECKSUM (at->dw_attr_val.v.val_flag);
7328 case dw_val_class_str:
7329 CHECKSUM_STRING (AT_string (at));
7332 case dw_val_class_addr:
7334 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7335 CHECKSUM_STRING (XSTR (r, 0));
7338 case dw_val_class_offset:
7339 CHECKSUM (at->dw_attr_val.v.val_offset);
7342 case dw_val_class_loc:
7343 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7344 loc_checksum (loc, ctx);
7347 case dw_val_class_die_ref:
7348 die_checksum (AT_ref (at), ctx, mark);
7351 case dw_val_class_fde_ref:
7352 case dw_val_class_lbl_id:
7353 case dw_val_class_lineptr:
7354 case dw_val_class_macptr:
7357 case dw_val_class_file:
7358 CHECKSUM_STRING (AT_file (at)->filename);
7366 /* Calculate the checksum of a DIE. */
7369 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7375 /* To avoid infinite recursion. */
7378 CHECKSUM (die->die_mark);
7381 die->die_mark = ++(*mark);
7383 CHECKSUM (die->die_tag);
7385 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7386 attr_checksum (a, ctx, mark);
7388 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7392 #undef CHECKSUM_STRING
7394 /* Do the location expressions look same? */
7396 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7398 return loc1->dw_loc_opc == loc2->dw_loc_opc
7399 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7400 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7403 /* Do the values look the same? */
7405 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7407 dw_loc_descr_ref loc1, loc2;
7410 if (v1->val_class != v2->val_class)
7413 switch (v1->val_class)
7415 case dw_val_class_const:
7416 return v1->v.val_int == v2->v.val_int;
7417 case dw_val_class_unsigned_const:
7418 return v1->v.val_unsigned == v2->v.val_unsigned;
7419 case dw_val_class_long_long:
7420 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
7421 && v1->v.val_long_long.low == v2->v.val_long_long.low;
7422 case dw_val_class_vec:
7423 if (v1->v.val_vec.length != v2->v.val_vec.length
7424 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7426 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7427 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7430 case dw_val_class_flag:
7431 return v1->v.val_flag == v2->v.val_flag;
7432 case dw_val_class_str:
7433 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7435 case dw_val_class_addr:
7436 r1 = v1->v.val_addr;
7437 r2 = v2->v.val_addr;
7438 if (GET_CODE (r1) != GET_CODE (r2))
7440 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7441 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7443 case dw_val_class_offset:
7444 return v1->v.val_offset == v2->v.val_offset;
7446 case dw_val_class_loc:
7447 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7449 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7450 if (!same_loc_p (loc1, loc2, mark))
7452 return !loc1 && !loc2;
7454 case dw_val_class_die_ref:
7455 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7457 case dw_val_class_fde_ref:
7458 case dw_val_class_lbl_id:
7459 case dw_val_class_lineptr:
7460 case dw_val_class_macptr:
7463 case dw_val_class_file:
7464 return v1->v.val_file == v2->v.val_file;
7471 /* Do the attributes look the same? */
7474 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7476 if (at1->dw_attr != at2->dw_attr)
7479 /* We don't care that this was compiled with a different compiler
7480 snapshot; if the output is the same, that's what matters. */
7481 if (at1->dw_attr == DW_AT_producer)
7484 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7487 /* Do the dies look the same? */
7490 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7496 /* To avoid infinite recursion. */
7498 return die1->die_mark == die2->die_mark;
7499 die1->die_mark = die2->die_mark = ++(*mark);
7501 if (die1->die_tag != die2->die_tag)
7504 if (VEC_length (dw_attr_node, die1->die_attr)
7505 != VEC_length (dw_attr_node, die2->die_attr))
7508 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7509 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7512 c1 = die1->die_child;
7513 c2 = die2->die_child;
7522 if (!same_die_p (c1, c2, mark))
7526 if (c1 == die1->die_child)
7528 if (c2 == die2->die_child)
7538 /* Do the dies look the same? Wrapper around same_die_p. */
7541 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7544 int ret = same_die_p (die1, die2, &mark);
7546 unmark_all_dies (die1);
7547 unmark_all_dies (die2);
7552 /* The prefix to attach to symbols on DIEs in the current comdat debug
7554 static char *comdat_symbol_id;
7556 /* The index of the current symbol within the current comdat CU. */
7557 static unsigned int comdat_symbol_number;
7559 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7560 children, and set comdat_symbol_id accordingly. */
7563 compute_section_prefix (dw_die_ref unit_die)
7565 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7566 const char *base = die_name ? lbasename (die_name) : "anonymous";
7567 char *name = XALLOCAVEC (char, strlen (base) + 64);
7570 unsigned char checksum[16];
7573 /* Compute the checksum of the DIE, then append part of it as hex digits to
7574 the name filename of the unit. */
7576 md5_init_ctx (&ctx);
7578 die_checksum (unit_die, &ctx, &mark);
7579 unmark_all_dies (unit_die);
7580 md5_finish_ctx (&ctx, checksum);
7582 sprintf (name, "%s.", base);
7583 clean_symbol_name (name);
7585 p = name + strlen (name);
7586 for (i = 0; i < 4; i++)
7588 sprintf (p, "%.2x", checksum[i]);
7592 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7593 comdat_symbol_number = 0;
7596 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7599 is_type_die (dw_die_ref die)
7601 switch (die->die_tag)
7603 case DW_TAG_array_type:
7604 case DW_TAG_class_type:
7605 case DW_TAG_interface_type:
7606 case DW_TAG_enumeration_type:
7607 case DW_TAG_pointer_type:
7608 case DW_TAG_reference_type:
7609 case DW_TAG_string_type:
7610 case DW_TAG_structure_type:
7611 case DW_TAG_subroutine_type:
7612 case DW_TAG_union_type:
7613 case DW_TAG_ptr_to_member_type:
7614 case DW_TAG_set_type:
7615 case DW_TAG_subrange_type:
7616 case DW_TAG_base_type:
7617 case DW_TAG_const_type:
7618 case DW_TAG_file_type:
7619 case DW_TAG_packed_type:
7620 case DW_TAG_volatile_type:
7621 case DW_TAG_typedef:
7628 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7629 Basically, we want to choose the bits that are likely to be shared between
7630 compilations (types) and leave out the bits that are specific to individual
7631 compilations (functions). */
7634 is_comdat_die (dw_die_ref c)
7636 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7637 we do for stabs. The advantage is a greater likelihood of sharing between
7638 objects that don't include headers in the same order (and therefore would
7639 put the base types in a different comdat). jason 8/28/00 */
7641 if (c->die_tag == DW_TAG_base_type)
7644 if (c->die_tag == DW_TAG_pointer_type
7645 || c->die_tag == DW_TAG_reference_type
7646 || c->die_tag == DW_TAG_const_type
7647 || c->die_tag == DW_TAG_volatile_type)
7649 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7651 return t ? is_comdat_die (t) : 0;
7654 return is_type_die (c);
7657 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7658 compilation unit. */
7661 is_symbol_die (dw_die_ref c)
7663 return (is_type_die (c)
7664 || (get_AT (c, DW_AT_declaration)
7665 && !get_AT (c, DW_AT_specification))
7666 || c->die_tag == DW_TAG_namespace
7667 || c->die_tag == DW_TAG_module);
7671 gen_internal_sym (const char *prefix)
7675 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7676 return xstrdup (buf);
7679 /* Assign symbols to all worthy DIEs under DIE. */
7682 assign_symbol_names (dw_die_ref die)
7686 if (is_symbol_die (die))
7688 if (comdat_symbol_id)
7690 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7692 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7693 comdat_symbol_id, comdat_symbol_number++);
7694 die->die_symbol = xstrdup (p);
7697 die->die_symbol = gen_internal_sym ("LDIE");
7700 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7703 struct cu_hash_table_entry
7706 unsigned min_comdat_num, max_comdat_num;
7707 struct cu_hash_table_entry *next;
7710 /* Routines to manipulate hash table of CUs. */
7712 htab_cu_hash (const void *of)
7714 const struct cu_hash_table_entry *const entry =
7715 (const struct cu_hash_table_entry *) of;
7717 return htab_hash_string (entry->cu->die_symbol);
7721 htab_cu_eq (const void *of1, const void *of2)
7723 const struct cu_hash_table_entry *const entry1 =
7724 (const struct cu_hash_table_entry *) of1;
7725 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7727 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7731 htab_cu_del (void *what)
7733 struct cu_hash_table_entry *next,
7734 *entry = (struct cu_hash_table_entry *) what;
7744 /* Check whether we have already seen this CU and set up SYM_NUM
7747 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7749 struct cu_hash_table_entry dummy;
7750 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7752 dummy.max_comdat_num = 0;
7754 slot = (struct cu_hash_table_entry **)
7755 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7759 for (; entry; last = entry, entry = entry->next)
7761 if (same_die_p_wrap (cu, entry->cu))
7767 *sym_num = entry->min_comdat_num;
7771 entry = XCNEW (struct cu_hash_table_entry);
7773 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7774 entry->next = *slot;
7780 /* Record SYM_NUM to record of CU in HTABLE. */
7782 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7784 struct cu_hash_table_entry **slot, *entry;
7786 slot = (struct cu_hash_table_entry **)
7787 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7791 entry->max_comdat_num = sym_num;
7794 /* Traverse the DIE (which is always comp_unit_die), and set up
7795 additional compilation units for each of the include files we see
7796 bracketed by BINCL/EINCL. */
7799 break_out_includes (dw_die_ref die)
7802 dw_die_ref unit = NULL;
7803 limbo_die_node *node, **pnode;
7804 htab_t cu_hash_table;
7808 dw_die_ref prev = c;
7810 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7811 || (unit && is_comdat_die (c)))
7813 dw_die_ref next = c->die_sib;
7815 /* This DIE is for a secondary CU; remove it from the main one. */
7816 remove_child_with_prev (c, prev);
7818 if (c->die_tag == DW_TAG_GNU_BINCL)
7819 unit = push_new_compile_unit (unit, c);
7820 else if (c->die_tag == DW_TAG_GNU_EINCL)
7821 unit = pop_compile_unit (unit);
7823 add_child_die (unit, c);
7825 if (c == die->die_child)
7828 } while (c != die->die_child);
7831 /* We can only use this in debugging, since the frontend doesn't check
7832 to make sure that we leave every include file we enter. */
7836 assign_symbol_names (die);
7837 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7838 for (node = limbo_die_list, pnode = &limbo_die_list;
7844 compute_section_prefix (node->die);
7845 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7846 &comdat_symbol_number);
7847 assign_symbol_names (node->die);
7849 *pnode = node->next;
7852 pnode = &node->next;
7853 record_comdat_symbol_number (node->die, cu_hash_table,
7854 comdat_symbol_number);
7857 htab_delete (cu_hash_table);
7860 /* Traverse the DIE and add a sibling attribute if it may have the
7861 effect of speeding up access to siblings. To save some space,
7862 avoid generating sibling attributes for DIE's without children. */
7865 add_sibling_attributes (dw_die_ref die)
7869 if (! die->die_child)
7872 if (die->die_parent && die != die->die_parent->die_child)
7873 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7875 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7878 /* Output all location lists for the DIE and its children. */
7881 output_location_lists (dw_die_ref die)
7887 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7888 if (AT_class (a) == dw_val_class_loc_list)
7889 output_loc_list (AT_loc_list (a));
7891 FOR_EACH_CHILD (die, c, output_location_lists (c));
7894 /* The format of each DIE (and its attribute value pairs) is encoded in an
7895 abbreviation table. This routine builds the abbreviation table and assigns
7896 a unique abbreviation id for each abbreviation entry. The children of each
7897 die are visited recursively. */
7900 build_abbrev_table (dw_die_ref die)
7902 unsigned long abbrev_id;
7903 unsigned int n_alloc;
7908 /* Scan the DIE references, and mark as external any that refer to
7909 DIEs from other CUs (i.e. those which are not marked). */
7910 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7911 if (AT_class (a) == dw_val_class_die_ref
7912 && AT_ref (a)->die_mark == 0)
7914 gcc_assert (AT_ref (a)->die_symbol);
7915 set_AT_ref_external (a, 1);
7918 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7920 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7921 dw_attr_ref die_a, abbrev_a;
7925 if (abbrev->die_tag != die->die_tag)
7927 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7930 if (VEC_length (dw_attr_node, abbrev->die_attr)
7931 != VEC_length (dw_attr_node, die->die_attr))
7934 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7936 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7937 if ((abbrev_a->dw_attr != die_a->dw_attr)
7938 || (value_format (abbrev_a) != value_format (die_a)))
7948 if (abbrev_id >= abbrev_die_table_in_use)
7950 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7952 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7953 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7956 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7957 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7958 abbrev_die_table_allocated = n_alloc;
7961 ++abbrev_die_table_in_use;
7962 abbrev_die_table[abbrev_id] = die;
7965 die->die_abbrev = abbrev_id;
7966 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7969 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7972 constant_size (unsigned HOST_WIDE_INT value)
7979 log = floor_log2 (value);
7982 log = 1 << (floor_log2 (log) + 1);
7987 /* Return the size of a DIE as it is represented in the
7988 .debug_info section. */
7990 static unsigned long
7991 size_of_die (dw_die_ref die)
7993 unsigned long size = 0;
7997 size += size_of_uleb128 (die->die_abbrev);
7998 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8000 switch (AT_class (a))
8002 case dw_val_class_addr:
8003 size += DWARF2_ADDR_SIZE;
8005 case dw_val_class_offset:
8006 size += DWARF_OFFSET_SIZE;
8008 case dw_val_class_loc:
8010 unsigned long lsize = size_of_locs (AT_loc (a));
8013 size += constant_size (lsize);
8017 case dw_val_class_loc_list:
8018 size += DWARF_OFFSET_SIZE;
8020 case dw_val_class_range_list:
8021 size += DWARF_OFFSET_SIZE;
8023 case dw_val_class_const:
8024 size += size_of_sleb128 (AT_int (a));
8026 case dw_val_class_unsigned_const:
8027 size += constant_size (AT_unsigned (a));
8029 case dw_val_class_long_long:
8030 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
8032 case dw_val_class_vec:
8033 size += constant_size (a->dw_attr_val.v.val_vec.length
8034 * a->dw_attr_val.v.val_vec.elt_size)
8035 + a->dw_attr_val.v.val_vec.length
8036 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8038 case dw_val_class_flag:
8041 case dw_val_class_die_ref:
8042 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8043 whereas in DWARF3 it's always sized as an offset. */
8044 if (AT_ref_external (a) && dwarf_version == 2)
8045 size += DWARF2_ADDR_SIZE;
8047 size += DWARF_OFFSET_SIZE;
8049 case dw_val_class_fde_ref:
8050 size += DWARF_OFFSET_SIZE;
8052 case dw_val_class_lbl_id:
8053 size += DWARF2_ADDR_SIZE;
8055 case dw_val_class_lineptr:
8056 case dw_val_class_macptr:
8057 size += DWARF_OFFSET_SIZE;
8059 case dw_val_class_str:
8060 if (AT_string_form (a) == DW_FORM_strp)
8061 size += DWARF_OFFSET_SIZE;
8063 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8065 case dw_val_class_file:
8066 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8076 /* Size the debugging information associated with a given DIE. Visits the
8077 DIE's children recursively. Updates the global variable next_die_offset, on
8078 each time through. Uses the current value of next_die_offset to update the
8079 die_offset field in each DIE. */
8082 calc_die_sizes (dw_die_ref die)
8086 die->die_offset = next_die_offset;
8087 next_die_offset += size_of_die (die);
8089 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8091 if (die->die_child != NULL)
8092 /* Count the null byte used to terminate sibling lists. */
8093 next_die_offset += 1;
8096 /* Set the marks for a die and its children. We do this so
8097 that we know whether or not a reference needs to use FORM_ref_addr; only
8098 DIEs in the same CU will be marked. We used to clear out the offset
8099 and use that as the flag, but ran into ordering problems. */
8102 mark_dies (dw_die_ref die)
8106 gcc_assert (!die->die_mark);
8109 FOR_EACH_CHILD (die, c, mark_dies (c));
8112 /* Clear the marks for a die and its children. */
8115 unmark_dies (dw_die_ref die)
8119 gcc_assert (die->die_mark);
8122 FOR_EACH_CHILD (die, c, unmark_dies (c));
8125 /* Clear the marks for a die, its children and referred dies. */
8128 unmark_all_dies (dw_die_ref die)
8138 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8140 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8141 if (AT_class (a) == dw_val_class_die_ref)
8142 unmark_all_dies (AT_ref (a));
8145 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8146 generated for the compilation unit. */
8148 static unsigned long
8149 size_of_pubnames (VEC (pubname_entry, gc) * names)
8155 size = DWARF_PUBNAMES_HEADER_SIZE;
8156 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8157 if (names != pubtype_table
8158 || p->die->die_offset != 0
8159 || !flag_eliminate_unused_debug_types)
8160 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8162 size += DWARF_OFFSET_SIZE;
8166 /* Return the size of the information in the .debug_aranges section. */
8168 static unsigned long
8169 size_of_aranges (void)
8173 size = DWARF_ARANGES_HEADER_SIZE;
8175 /* Count the address/length pair for this compilation unit. */
8176 if (text_section_used)
8177 size += 2 * DWARF2_ADDR_SIZE;
8178 if (cold_text_section_used)
8179 size += 2 * DWARF2_ADDR_SIZE;
8180 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8182 /* Count the two zero words used to terminated the address range table. */
8183 size += 2 * DWARF2_ADDR_SIZE;
8187 /* Select the encoding of an attribute value. */
8189 static enum dwarf_form
8190 value_format (dw_attr_ref a)
8192 switch (a->dw_attr_val.val_class)
8194 case dw_val_class_addr:
8195 return DW_FORM_addr;
8196 case dw_val_class_range_list:
8197 case dw_val_class_offset:
8198 case dw_val_class_loc_list:
8199 switch (DWARF_OFFSET_SIZE)
8202 return DW_FORM_data4;
8204 return DW_FORM_data8;
8208 case dw_val_class_loc:
8209 switch (constant_size (size_of_locs (AT_loc (a))))
8212 return DW_FORM_block1;
8214 return DW_FORM_block2;
8218 case dw_val_class_const:
8219 return DW_FORM_sdata;
8220 case dw_val_class_unsigned_const:
8221 switch (constant_size (AT_unsigned (a)))
8224 return DW_FORM_data1;
8226 return DW_FORM_data2;
8228 return DW_FORM_data4;
8230 return DW_FORM_data8;
8234 case dw_val_class_long_long:
8235 return DW_FORM_block1;
8236 case dw_val_class_vec:
8237 switch (constant_size (a->dw_attr_val.v.val_vec.length
8238 * a->dw_attr_val.v.val_vec.elt_size))
8241 return DW_FORM_block1;
8243 return DW_FORM_block2;
8245 return DW_FORM_block4;
8249 case dw_val_class_flag:
8250 return DW_FORM_flag;
8251 case dw_val_class_die_ref:
8252 if (AT_ref_external (a))
8253 return DW_FORM_ref_addr;
8256 case dw_val_class_fde_ref:
8257 return DW_FORM_data;
8258 case dw_val_class_lbl_id:
8259 return DW_FORM_addr;
8260 case dw_val_class_lineptr:
8261 case dw_val_class_macptr:
8262 return DW_FORM_data;
8263 case dw_val_class_str:
8264 return AT_string_form (a);
8265 case dw_val_class_file:
8266 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8269 return DW_FORM_data1;
8271 return DW_FORM_data2;
8273 return DW_FORM_data4;
8283 /* Output the encoding of an attribute value. */
8286 output_value_format (dw_attr_ref a)
8288 enum dwarf_form form = value_format (a);
8290 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8293 /* Output the .debug_abbrev section which defines the DIE abbreviation
8297 output_abbrev_section (void)
8299 unsigned long abbrev_id;
8301 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8303 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8307 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8308 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8309 dwarf_tag_name (abbrev->die_tag));
8311 if (abbrev->die_child != NULL)
8312 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8314 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8316 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8319 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8320 dwarf_attr_name (a_attr->dw_attr));
8321 output_value_format (a_attr);
8324 dw2_asm_output_data (1, 0, NULL);
8325 dw2_asm_output_data (1, 0, NULL);
8328 /* Terminate the table. */
8329 dw2_asm_output_data (1, 0, NULL);
8332 /* Output a symbol we can use to refer to this DIE from another CU. */
8335 output_die_symbol (dw_die_ref die)
8337 char *sym = die->die_symbol;
8342 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8343 /* We make these global, not weak; if the target doesn't support
8344 .linkonce, it doesn't support combining the sections, so debugging
8346 targetm.asm_out.globalize_label (asm_out_file, sym);
8348 ASM_OUTPUT_LABEL (asm_out_file, sym);
8351 /* Return a new location list, given the begin and end range, and the
8352 expression. gensym tells us whether to generate a new internal symbol for
8353 this location list node, which is done for the head of the list only. */
8355 static inline dw_loc_list_ref
8356 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8357 const char *section, unsigned int gensym)
8359 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8361 retlist->begin = begin;
8363 retlist->expr = expr;
8364 retlist->section = section;
8366 retlist->ll_symbol = gen_internal_sym ("LLST");
8371 /* Add a location description expression to a location list. */
8374 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8375 const char *begin, const char *end,
8376 const char *section)
8380 /* Find the end of the chain. */
8381 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8384 /* Add a new location list node to the list. */
8385 *d = new_loc_list (descr, begin, end, section, 0);
8388 /* Output the location list given to us. */
8391 output_loc_list (dw_loc_list_ref list_head)
8393 dw_loc_list_ref curr = list_head;
8395 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8397 /* Walk the location list, and output each range + expression. */
8398 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8401 /* Don't output an entry that starts and ends at the same address. */
8402 if (strcmp (curr->begin, curr->end) == 0)
8404 if (!have_multiple_function_sections)
8406 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8407 "Location list begin address (%s)",
8408 list_head->ll_symbol);
8409 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8410 "Location list end address (%s)",
8411 list_head->ll_symbol);
8415 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8416 "Location list begin address (%s)",
8417 list_head->ll_symbol);
8418 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8419 "Location list end address (%s)",
8420 list_head->ll_symbol);
8422 size = size_of_locs (curr->expr);
8424 /* Output the block length for this list of location operations. */
8425 gcc_assert (size <= 0xffff);
8426 dw2_asm_output_data (2, size, "%s", "Location expression size");
8428 output_loc_sequence (curr->expr);
8431 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8432 "Location list terminator begin (%s)",
8433 list_head->ll_symbol);
8434 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8435 "Location list terminator end (%s)",
8436 list_head->ll_symbol);
8439 /* Output the DIE and its attributes. Called recursively to generate
8440 the definitions of each child DIE. */
8443 output_die (dw_die_ref die)
8450 /* If someone in another CU might refer to us, set up a symbol for
8451 them to point to. */
8452 if (die->die_symbol)
8453 output_die_symbol (die);
8455 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8456 (unsigned long)die->die_offset,
8457 dwarf_tag_name (die->die_tag));
8459 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8461 const char *name = dwarf_attr_name (a->dw_attr);
8463 switch (AT_class (a))
8465 case dw_val_class_addr:
8466 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8469 case dw_val_class_offset:
8470 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8474 case dw_val_class_range_list:
8476 char *p = strchr (ranges_section_label, '\0');
8478 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8479 a->dw_attr_val.v.val_offset);
8480 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8481 debug_ranges_section, "%s", name);
8486 case dw_val_class_loc:
8487 size = size_of_locs (AT_loc (a));
8489 /* Output the block length for this list of location operations. */
8490 dw2_asm_output_data (constant_size (size), size, "%s", name);
8492 output_loc_sequence (AT_loc (a));
8495 case dw_val_class_const:
8496 /* ??? It would be slightly more efficient to use a scheme like is
8497 used for unsigned constants below, but gdb 4.x does not sign
8498 extend. Gdb 5.x does sign extend. */
8499 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8502 case dw_val_class_unsigned_const:
8503 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8504 AT_unsigned (a), "%s", name);
8507 case dw_val_class_long_long:
8509 unsigned HOST_WIDE_INT first, second;
8511 dw2_asm_output_data (1,
8512 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8515 if (WORDS_BIG_ENDIAN)
8517 first = a->dw_attr_val.v.val_long_long.hi;
8518 second = a->dw_attr_val.v.val_long_long.low;
8522 first = a->dw_attr_val.v.val_long_long.low;
8523 second = a->dw_attr_val.v.val_long_long.hi;
8526 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8527 first, "long long constant");
8528 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8533 case dw_val_class_vec:
8535 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8536 unsigned int len = a->dw_attr_val.v.val_vec.length;
8540 dw2_asm_output_data (constant_size (len * elt_size),
8541 len * elt_size, "%s", name);
8542 if (elt_size > sizeof (HOST_WIDE_INT))
8547 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8550 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8551 "fp or vector constant word %u", i);
8555 case dw_val_class_flag:
8556 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8559 case dw_val_class_loc_list:
8561 char *sym = AT_loc_list (a)->ll_symbol;
8564 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8569 case dw_val_class_die_ref:
8570 if (AT_ref_external (a))
8572 char *sym = AT_ref (a)->die_symbol;
8577 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8578 length, whereas in DWARF3 it's always sized as an offset. */
8579 if (dwarf_version == 2)
8580 size = DWARF2_ADDR_SIZE;
8582 size = DWARF_OFFSET_SIZE;
8583 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
8587 gcc_assert (AT_ref (a)->die_offset);
8588 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8593 case dw_val_class_fde_ref:
8597 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8598 a->dw_attr_val.v.val_fde_index * 2);
8599 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8604 case dw_val_class_lbl_id:
8605 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8608 case dw_val_class_lineptr:
8609 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8610 debug_line_section, "%s", name);
8613 case dw_val_class_macptr:
8614 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8615 debug_macinfo_section, "%s", name);
8618 case dw_val_class_str:
8619 if (AT_string_form (a) == DW_FORM_strp)
8620 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8621 a->dw_attr_val.v.val_str->label,
8623 "%s: \"%s\"", name, AT_string (a));
8625 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8628 case dw_val_class_file:
8630 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8632 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8633 a->dw_attr_val.v.val_file->filename);
8642 FOR_EACH_CHILD (die, c, output_die (c));
8644 /* Add null byte to terminate sibling list. */
8645 if (die->die_child != NULL)
8646 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8647 (unsigned long) die->die_offset);
8650 /* Output the compilation unit that appears at the beginning of the
8651 .debug_info section, and precedes the DIE descriptions. */
8654 output_compilation_unit_header (void)
8656 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8657 dw2_asm_output_data (4, 0xffffffff,
8658 "Initial length escape value indicating 64-bit DWARF extension");
8659 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8660 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8661 "Length of Compilation Unit Info");
8662 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
8663 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8664 debug_abbrev_section,
8665 "Offset Into Abbrev. Section");
8666 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8669 /* Output the compilation unit DIE and its children. */
8672 output_comp_unit (dw_die_ref die, int output_if_empty)
8674 const char *secname;
8677 /* Unless we are outputting main CU, we may throw away empty ones. */
8678 if (!output_if_empty && die->die_child == NULL)
8681 /* Even if there are no children of this DIE, we must output the information
8682 about the compilation unit. Otherwise, on an empty translation unit, we
8683 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8684 will then complain when examining the file. First mark all the DIEs in
8685 this CU so we know which get local refs. */
8688 build_abbrev_table (die);
8690 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8691 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8692 calc_die_sizes (die);
8694 oldsym = die->die_symbol;
8697 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8699 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8701 die->die_symbol = NULL;
8702 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8705 switch_to_section (debug_info_section);
8707 /* Output debugging information. */
8708 output_compilation_unit_header ();
8711 /* Leave the marks on the main CU, so we can check them in
8716 die->die_symbol = oldsym;
8720 /* Return the DWARF2/3 pubname associated with a decl. */
8723 dwarf2_name (tree decl, int scope)
8725 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8728 /* Add a new entry to .debug_pubnames if appropriate. */
8731 add_pubname_string (const char *str, dw_die_ref die)
8736 e.name = xstrdup (str);
8737 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8741 add_pubname (tree decl, dw_die_ref die)
8743 if (TREE_PUBLIC (decl))
8744 add_pubname_string (dwarf2_name (decl, 1), die);
8747 /* Add a new entry to .debug_pubtypes if appropriate. */
8750 add_pubtype (tree decl, dw_die_ref die)
8755 if ((TREE_PUBLIC (decl)
8756 || die->die_parent == comp_unit_die)
8757 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8762 if (TYPE_NAME (decl))
8764 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8765 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8766 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8767 && DECL_NAME (TYPE_NAME (decl)))
8768 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8770 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8774 e.name = xstrdup (dwarf2_name (decl, 1));
8776 /* If we don't have a name for the type, there's no point in adding
8778 if (e.name && e.name[0] != '\0')
8779 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8783 /* Output the public names table used to speed up access to externally
8784 visible names; or the public types table used to find type definitions. */
8787 output_pubnames (VEC (pubname_entry, gc) * names)
8790 unsigned long pubnames_length = size_of_pubnames (names);
8793 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8794 dw2_asm_output_data (4, 0xffffffff,
8795 "Initial length escape value indicating 64-bit DWARF extension");
8796 if (names == pubname_table)
8797 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8798 "Length of Public Names Info");
8800 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8801 "Length of Public Type Names Info");
8802 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8803 dw2_asm_output_data (2, 2, "DWARF Version");
8804 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8806 "Offset of Compilation Unit Info");
8807 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8808 "Compilation Unit Length");
8810 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8812 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8813 if (names == pubname_table)
8814 gcc_assert (pub->die->die_mark);
8816 if (names != pubtype_table
8817 || pub->die->die_offset != 0
8818 || !flag_eliminate_unused_debug_types)
8820 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8823 dw2_asm_output_nstring (pub->name, -1, "external name");
8827 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8830 /* Add a new entry to .debug_aranges if appropriate. */
8833 add_arange (tree decl, dw_die_ref die)
8835 if (! DECL_SECTION_NAME (decl))
8838 if (arange_table_in_use == arange_table_allocated)
8840 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8841 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8842 arange_table_allocated);
8843 memset (arange_table + arange_table_in_use, 0,
8844 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8847 arange_table[arange_table_in_use++] = die;
8850 /* Output the information that goes into the .debug_aranges table.
8851 Namely, define the beginning and ending address range of the
8852 text section generated for this compilation unit. */
8855 output_aranges (void)
8858 unsigned long aranges_length = size_of_aranges ();
8860 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8861 dw2_asm_output_data (4, 0xffffffff,
8862 "Initial length escape value indicating 64-bit DWARF extension");
8863 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8864 "Length of Address Ranges Info");
8865 /* Version number for aranges is still 2, even in DWARF3. */
8866 dw2_asm_output_data (2, 2, "DWARF Version");
8867 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8869 "Offset of Compilation Unit Info");
8870 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8871 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8873 /* We need to align to twice the pointer size here. */
8874 if (DWARF_ARANGES_PAD_SIZE)
8876 /* Pad using a 2 byte words so that padding is correct for any
8878 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8879 2 * DWARF2_ADDR_SIZE);
8880 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8881 dw2_asm_output_data (2, 0, NULL);
8884 /* It is necessary not to output these entries if the sections were
8885 not used; if the sections were not used, the length will be 0 and
8886 the address may end up as 0 if the section is discarded by ld
8887 --gc-sections, leaving an invalid (0, 0) entry that can be
8888 confused with the terminator. */
8889 if (text_section_used)
8891 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8892 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8893 text_section_label, "Length");
8895 if (cold_text_section_used)
8897 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8899 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8900 cold_text_section_label, "Length");
8903 for (i = 0; i < arange_table_in_use; i++)
8905 dw_die_ref die = arange_table[i];
8907 /* We shouldn't see aranges for DIEs outside of the main CU. */
8908 gcc_assert (die->die_mark);
8910 if (die->die_tag == DW_TAG_subprogram)
8912 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8914 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8915 get_AT_low_pc (die), "Length");
8919 /* A static variable; extract the symbol from DW_AT_location.
8920 Note that this code isn't currently hit, as we only emit
8921 aranges for functions (jason 9/23/99). */
8922 dw_attr_ref a = get_AT (die, DW_AT_location);
8923 dw_loc_descr_ref loc;
8925 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8928 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8930 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8931 loc->dw_loc_oprnd1.v.val_addr, "Address");
8932 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8933 get_AT_unsigned (die, DW_AT_byte_size),
8938 /* Output the terminator words. */
8939 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8940 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8943 /* Add a new entry to .debug_ranges. Return the offset at which it
8947 add_ranges_num (int num)
8949 unsigned int in_use = ranges_table_in_use;
8951 if (in_use == ranges_table_allocated)
8953 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8954 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8955 ranges_table_allocated);
8956 memset (ranges_table + ranges_table_in_use, 0,
8957 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8960 ranges_table[in_use].num = num;
8961 ranges_table_in_use = in_use + 1;
8963 return in_use * 2 * DWARF2_ADDR_SIZE;
8966 /* Add a new entry to .debug_ranges corresponding to a block, or a
8967 range terminator if BLOCK is NULL. */
8970 add_ranges (const_tree block)
8972 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8975 /* Add a new entry to .debug_ranges corresponding to a pair of
8979 add_ranges_by_labels (const char *begin, const char *end)
8981 unsigned int in_use = ranges_by_label_in_use;
8983 if (in_use == ranges_by_label_allocated)
8985 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8986 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8988 ranges_by_label_allocated);
8989 memset (ranges_by_label + ranges_by_label_in_use, 0,
8990 RANGES_TABLE_INCREMENT
8991 * sizeof (struct dw_ranges_by_label_struct));
8994 ranges_by_label[in_use].begin = begin;
8995 ranges_by_label[in_use].end = end;
8996 ranges_by_label_in_use = in_use + 1;
8998 return add_ranges_num (-(int)in_use - 1);
9002 output_ranges (void)
9005 static const char *const start_fmt = "Offset 0x%x";
9006 const char *fmt = start_fmt;
9008 for (i = 0; i < ranges_table_in_use; i++)
9010 int block_num = ranges_table[i].num;
9014 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9015 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9017 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9018 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9020 /* If all code is in the text section, then the compilation
9021 unit base address defaults to DW_AT_low_pc, which is the
9022 base of the text section. */
9023 if (!have_multiple_function_sections)
9025 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9027 fmt, i * 2 * DWARF2_ADDR_SIZE);
9028 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9029 text_section_label, NULL);
9032 /* Otherwise, the compilation unit base address is zero,
9033 which allows us to use absolute addresses, and not worry
9034 about whether the target supports cross-section
9038 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9039 fmt, i * 2 * DWARF2_ADDR_SIZE);
9040 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9046 /* Negative block_num stands for an index into ranges_by_label. */
9047 else if (block_num < 0)
9049 int lab_idx = - block_num - 1;
9051 if (!have_multiple_function_sections)
9055 /* If we ever use add_ranges_by_labels () for a single
9056 function section, all we have to do is to take out
9058 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9059 ranges_by_label[lab_idx].begin,
9061 fmt, i * 2 * DWARF2_ADDR_SIZE);
9062 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9063 ranges_by_label[lab_idx].end,
9064 text_section_label, NULL);
9069 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9070 ranges_by_label[lab_idx].begin,
9071 fmt, i * 2 * DWARF2_ADDR_SIZE);
9072 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9073 ranges_by_label[lab_idx].end,
9079 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9080 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9086 /* Data structure containing information about input files. */
9089 const char *path; /* Complete file name. */
9090 const char *fname; /* File name part. */
9091 int length; /* Length of entire string. */
9092 struct dwarf_file_data * file_idx; /* Index in input file table. */
9093 int dir_idx; /* Index in directory table. */
9096 /* Data structure containing information about directories with source
9100 const char *path; /* Path including directory name. */
9101 int length; /* Path length. */
9102 int prefix; /* Index of directory entry which is a prefix. */
9103 int count; /* Number of files in this directory. */
9104 int dir_idx; /* Index of directory used as base. */
9107 /* Callback function for file_info comparison. We sort by looking at
9108 the directories in the path. */
9111 file_info_cmp (const void *p1, const void *p2)
9113 const struct file_info *const s1 = (const struct file_info *) p1;
9114 const struct file_info *const s2 = (const struct file_info *) p2;
9115 const unsigned char *cp1;
9116 const unsigned char *cp2;
9118 /* Take care of file names without directories. We need to make sure that
9119 we return consistent values to qsort since some will get confused if
9120 we return the same value when identical operands are passed in opposite
9121 orders. So if neither has a directory, return 0 and otherwise return
9122 1 or -1 depending on which one has the directory. */
9123 if ((s1->path == s1->fname || s2->path == s2->fname))
9124 return (s2->path == s2->fname) - (s1->path == s1->fname);
9126 cp1 = (const unsigned char *) s1->path;
9127 cp2 = (const unsigned char *) s2->path;
9133 /* Reached the end of the first path? If so, handle like above. */
9134 if ((cp1 == (const unsigned char *) s1->fname)
9135 || (cp2 == (const unsigned char *) s2->fname))
9136 return ((cp2 == (const unsigned char *) s2->fname)
9137 - (cp1 == (const unsigned char *) s1->fname));
9139 /* Character of current path component the same? */
9140 else if (*cp1 != *cp2)
9145 struct file_name_acquire_data
9147 struct file_info *files;
9152 /* Traversal function for the hash table. */
9155 file_name_acquire (void ** slot, void *data)
9157 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9158 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9159 struct file_info *fi;
9162 gcc_assert (fnad->max_files >= d->emitted_number);
9164 if (! d->emitted_number)
9167 gcc_assert (fnad->max_files != fnad->used_files);
9169 fi = fnad->files + fnad->used_files++;
9171 /* Skip all leading "./". */
9173 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9176 /* Create a new array entry. */
9178 fi->length = strlen (f);
9181 /* Search for the file name part. */
9182 f = strrchr (f, DIR_SEPARATOR);
9183 #if defined (DIR_SEPARATOR_2)
9185 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9189 if (f == NULL || f < g)
9195 fi->fname = f == NULL ? fi->path : f + 1;
9199 /* Output the directory table and the file name table. We try to minimize
9200 the total amount of memory needed. A heuristic is used to avoid large
9201 slowdowns with many input files. */
9204 output_file_names (void)
9206 struct file_name_acquire_data fnad;
9208 struct file_info *files;
9209 struct dir_info *dirs;
9218 if (!last_emitted_file)
9220 dw2_asm_output_data (1, 0, "End directory table");
9221 dw2_asm_output_data (1, 0, "End file name table");
9225 numfiles = last_emitted_file->emitted_number;
9227 /* Allocate the various arrays we need. */
9228 files = XALLOCAVEC (struct file_info, numfiles);
9229 dirs = XALLOCAVEC (struct dir_info, numfiles);
9232 fnad.used_files = 0;
9233 fnad.max_files = numfiles;
9234 htab_traverse (file_table, file_name_acquire, &fnad);
9235 gcc_assert (fnad.used_files == fnad.max_files);
9237 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9239 /* Find all the different directories used. */
9240 dirs[0].path = files[0].path;
9241 dirs[0].length = files[0].fname - files[0].path;
9242 dirs[0].prefix = -1;
9244 dirs[0].dir_idx = 0;
9245 files[0].dir_idx = 0;
9248 for (i = 1; i < numfiles; i++)
9249 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9250 && memcmp (dirs[ndirs - 1].path, files[i].path,
9251 dirs[ndirs - 1].length) == 0)
9253 /* Same directory as last entry. */
9254 files[i].dir_idx = ndirs - 1;
9255 ++dirs[ndirs - 1].count;
9261 /* This is a new directory. */
9262 dirs[ndirs].path = files[i].path;
9263 dirs[ndirs].length = files[i].fname - files[i].path;
9264 dirs[ndirs].count = 1;
9265 dirs[ndirs].dir_idx = ndirs;
9266 files[i].dir_idx = ndirs;
9268 /* Search for a prefix. */
9269 dirs[ndirs].prefix = -1;
9270 for (j = 0; j < ndirs; j++)
9271 if (dirs[j].length < dirs[ndirs].length
9272 && dirs[j].length > 1
9273 && (dirs[ndirs].prefix == -1
9274 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9275 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9276 dirs[ndirs].prefix = j;
9281 /* Now to the actual work. We have to find a subset of the directories which
9282 allow expressing the file name using references to the directory table
9283 with the least amount of characters. We do not do an exhaustive search
9284 where we would have to check out every combination of every single
9285 possible prefix. Instead we use a heuristic which provides nearly optimal
9286 results in most cases and never is much off. */
9287 saved = XALLOCAVEC (int, ndirs);
9288 savehere = XALLOCAVEC (int, ndirs);
9290 memset (saved, '\0', ndirs * sizeof (saved[0]));
9291 for (i = 0; i < ndirs; i++)
9296 /* We can always save some space for the current directory. But this
9297 does not mean it will be enough to justify adding the directory. */
9298 savehere[i] = dirs[i].length;
9299 total = (savehere[i] - saved[i]) * dirs[i].count;
9301 for (j = i + 1; j < ndirs; j++)
9304 if (saved[j] < dirs[i].length)
9306 /* Determine whether the dirs[i] path is a prefix of the
9311 while (k != -1 && k != (int) i)
9316 /* Yes it is. We can possibly save some memory by
9317 writing the filenames in dirs[j] relative to
9319 savehere[j] = dirs[i].length;
9320 total += (savehere[j] - saved[j]) * dirs[j].count;
9325 /* Check whether we can save enough to justify adding the dirs[i]
9327 if (total > dirs[i].length + 1)
9329 /* It's worthwhile adding. */
9330 for (j = i; j < ndirs; j++)
9331 if (savehere[j] > 0)
9333 /* Remember how much we saved for this directory so far. */
9334 saved[j] = savehere[j];
9336 /* Remember the prefix directory. */
9337 dirs[j].dir_idx = i;
9342 /* Emit the directory name table. */
9344 idx_offset = dirs[0].length > 0 ? 1 : 0;
9345 for (i = 1 - idx_offset; i < ndirs; i++)
9346 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
9347 "Directory Entry: 0x%x", i + idx_offset);
9349 dw2_asm_output_data (1, 0, "End directory table");
9351 /* We have to emit them in the order of emitted_number since that's
9352 used in the debug info generation. To do this efficiently we
9353 generate a back-mapping of the indices first. */
9354 backmap = XALLOCAVEC (int, numfiles);
9355 for (i = 0; i < numfiles; i++)
9356 backmap[files[i].file_idx->emitted_number - 1] = i;
9358 /* Now write all the file names. */
9359 for (i = 0; i < numfiles; i++)
9361 int file_idx = backmap[i];
9362 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9364 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9365 "File Entry: 0x%x", (unsigned) i + 1);
9367 /* Include directory index. */
9368 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9370 /* Modification time. */
9371 dw2_asm_output_data_uleb128 (0, NULL);
9373 /* File length in bytes. */
9374 dw2_asm_output_data_uleb128 (0, NULL);
9377 dw2_asm_output_data (1, 0, "End file name table");
9381 /* Output the source line number correspondence information. This
9382 information goes into the .debug_line section. */
9385 output_line_info (void)
9387 char l1[20], l2[20], p1[20], p2[20];
9388 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9389 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9392 unsigned long lt_index;
9393 unsigned long current_line;
9396 unsigned long current_file;
9397 unsigned long function;
9399 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9400 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9401 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9402 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9404 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9405 dw2_asm_output_data (4, 0xffffffff,
9406 "Initial length escape value indicating 64-bit DWARF extension");
9407 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9408 "Length of Source Line Info");
9409 ASM_OUTPUT_LABEL (asm_out_file, l1);
9411 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9412 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9413 ASM_OUTPUT_LABEL (asm_out_file, p1);
9415 /* Define the architecture-dependent minimum instruction length (in
9416 bytes). In this implementation of DWARF, this field is used for
9417 information purposes only. Since GCC generates assembly language,
9418 we have no a priori knowledge of how many instruction bytes are
9419 generated for each source line, and therefore can use only the
9420 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9421 commands. Accordingly, we fix this as `1', which is "correct
9422 enough" for all architectures, and don't let the target override. */
9423 dw2_asm_output_data (1, 1,
9424 "Minimum Instruction Length");
9426 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9427 "Default is_stmt_start flag");
9428 dw2_asm_output_data (1, DWARF_LINE_BASE,
9429 "Line Base Value (Special Opcodes)");
9430 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9431 "Line Range Value (Special Opcodes)");
9432 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9433 "Special Opcode Base");
9435 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9439 case DW_LNS_advance_pc:
9440 case DW_LNS_advance_line:
9441 case DW_LNS_set_file:
9442 case DW_LNS_set_column:
9443 case DW_LNS_fixed_advance_pc:
9451 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9455 /* Write out the information about the files we use. */
9456 output_file_names ();
9457 ASM_OUTPUT_LABEL (asm_out_file, p2);
9459 /* We used to set the address register to the first location in the text
9460 section here, but that didn't accomplish anything since we already
9461 have a line note for the opening brace of the first function. */
9463 /* Generate the line number to PC correspondence table, encoded as
9464 a series of state machine operations. */
9468 if (cfun && in_cold_section_p)
9469 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9471 strcpy (prev_line_label, text_section_label);
9472 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9474 dw_line_info_ref line_info = &line_info_table[lt_index];
9477 /* Disable this optimization for now; GDB wants to see two line notes
9478 at the beginning of a function so it can find the end of the
9481 /* Don't emit anything for redundant notes. Just updating the
9482 address doesn't accomplish anything, because we already assume
9483 that anything after the last address is this line. */
9484 if (line_info->dw_line_num == current_line
9485 && line_info->dw_file_num == current_file)
9489 /* Emit debug info for the address of the current line.
9491 Unfortunately, we have little choice here currently, and must always
9492 use the most general form. GCC does not know the address delta
9493 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9494 attributes which will give an upper bound on the address range. We
9495 could perhaps use length attributes to determine when it is safe to
9496 use DW_LNS_fixed_advance_pc. */
9498 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9501 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9502 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9503 "DW_LNS_fixed_advance_pc");
9504 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9508 /* This can handle any delta. This takes
9509 4+DWARF2_ADDR_SIZE bytes. */
9510 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9511 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9512 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9513 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9516 strcpy (prev_line_label, line_label);
9518 /* Emit debug info for the source file of the current line, if
9519 different from the previous line. */
9520 if (line_info->dw_file_num != current_file)
9522 current_file = line_info->dw_file_num;
9523 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9524 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9527 /* Emit debug info for the current line number, choosing the encoding
9528 that uses the least amount of space. */
9529 if (line_info->dw_line_num != current_line)
9531 line_offset = line_info->dw_line_num - current_line;
9532 line_delta = line_offset - DWARF_LINE_BASE;
9533 current_line = line_info->dw_line_num;
9534 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9535 /* This can handle deltas from -10 to 234, using the current
9536 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9538 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9539 "line %lu", current_line);
9542 /* This can handle any delta. This takes at least 4 bytes,
9543 depending on the value being encoded. */
9544 dw2_asm_output_data (1, DW_LNS_advance_line,
9545 "advance to line %lu", current_line);
9546 dw2_asm_output_data_sleb128 (line_offset, NULL);
9547 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9551 /* We still need to start a new row, so output a copy insn. */
9552 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9555 /* Emit debug info for the address of the end of the function. */
9558 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9559 "DW_LNS_fixed_advance_pc");
9560 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9564 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9565 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9566 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9567 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9570 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9571 dw2_asm_output_data_uleb128 (1, NULL);
9572 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9577 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9579 dw_separate_line_info_ref line_info
9580 = &separate_line_info_table[lt_index];
9583 /* Don't emit anything for redundant notes. */
9584 if (line_info->dw_line_num == current_line
9585 && line_info->dw_file_num == current_file
9586 && line_info->function == function)
9590 /* Emit debug info for the address of the current line. If this is
9591 a new function, or the first line of a function, then we need
9592 to handle it differently. */
9593 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9595 if (function != line_info->function)
9597 function = line_info->function;
9599 /* Set the address register to the first line in the function. */
9600 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9601 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9602 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9603 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9607 /* ??? See the DW_LNS_advance_pc comment above. */
9610 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9611 "DW_LNS_fixed_advance_pc");
9612 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9616 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9617 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9618 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9619 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9623 strcpy (prev_line_label, line_label);
9625 /* Emit debug info for the source file of the current line, if
9626 different from the previous line. */
9627 if (line_info->dw_file_num != current_file)
9629 current_file = line_info->dw_file_num;
9630 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9631 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9634 /* Emit debug info for the current line number, choosing the encoding
9635 that uses the least amount of space. */
9636 if (line_info->dw_line_num != current_line)
9638 line_offset = line_info->dw_line_num - current_line;
9639 line_delta = line_offset - DWARF_LINE_BASE;
9640 current_line = line_info->dw_line_num;
9641 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9642 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9643 "line %lu", current_line);
9646 dw2_asm_output_data (1, DW_LNS_advance_line,
9647 "advance to line %lu", current_line);
9648 dw2_asm_output_data_sleb128 (line_offset, NULL);
9649 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9653 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9661 /* If we're done with a function, end its sequence. */
9662 if (lt_index == separate_line_info_table_in_use
9663 || separate_line_info_table[lt_index].function != function)
9668 /* Emit debug info for the address of the end of the function. */
9669 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9672 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9673 "DW_LNS_fixed_advance_pc");
9674 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9678 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9679 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9680 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9681 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9684 /* Output the marker for the end of this sequence. */
9685 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9686 dw2_asm_output_data_uleb128 (1, NULL);
9687 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9691 /* Output the marker for the end of the line number info. */
9692 ASM_OUTPUT_LABEL (asm_out_file, l2);
9695 /* Given a pointer to a tree node for some base type, return a pointer to
9696 a DIE that describes the given type.
9698 This routine must only be called for GCC type nodes that correspond to
9699 Dwarf base (fundamental) types. */
9702 base_type_die (tree type)
9704 dw_die_ref base_type_result;
9705 enum dwarf_type encoding;
9707 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9710 /* If this is a subtype that should not be emitted as a subrange type,
9711 use the base type. See subrange_type_for_debug_p. */
9712 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9713 type = TREE_TYPE (type);
9715 switch (TREE_CODE (type))
9718 if (TYPE_STRING_FLAG (type))
9720 if (TYPE_UNSIGNED (type))
9721 encoding = DW_ATE_unsigned_char;
9723 encoding = DW_ATE_signed_char;
9725 else if (TYPE_UNSIGNED (type))
9726 encoding = DW_ATE_unsigned;
9728 encoding = DW_ATE_signed;
9732 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9733 encoding = DW_ATE_decimal_float;
9735 encoding = DW_ATE_float;
9738 case FIXED_POINT_TYPE:
9739 if (TYPE_UNSIGNED (type))
9740 encoding = DW_ATE_unsigned_fixed;
9742 encoding = DW_ATE_signed_fixed;
9745 /* Dwarf2 doesn't know anything about complex ints, so use
9746 a user defined type for it. */
9748 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9749 encoding = DW_ATE_complex_float;
9751 encoding = DW_ATE_lo_user;
9755 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9756 encoding = DW_ATE_boolean;
9760 /* No other TREE_CODEs are Dwarf fundamental types. */
9764 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9766 /* This probably indicates a bug. */
9767 if (! TYPE_NAME (type))
9768 add_name_attribute (base_type_result, "__unknown__");
9770 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9771 int_size_in_bytes (type));
9772 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9774 return base_type_result;
9777 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9778 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9781 is_base_type (tree type)
9783 switch (TREE_CODE (type))
9789 case FIXED_POINT_TYPE:
9797 case QUAL_UNION_TYPE:
9802 case REFERENCE_TYPE:
9815 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9816 node, return the size in bits for the type if it is a constant, or else
9817 return the alignment for the type if the type's size is not constant, or
9818 else return BITS_PER_WORD if the type actually turns out to be an
9821 static inline unsigned HOST_WIDE_INT
9822 simple_type_size_in_bits (const_tree type)
9824 if (TREE_CODE (type) == ERROR_MARK)
9825 return BITS_PER_WORD;
9826 else if (TYPE_SIZE (type) == NULL_TREE)
9828 else if (host_integerp (TYPE_SIZE (type), 1))
9829 return tree_low_cst (TYPE_SIZE (type), 1);
9831 return TYPE_ALIGN (type);
9834 /* Given a pointer to a tree node for a subrange type, return a pointer
9835 to a DIE that describes the given type. */
9838 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9840 dw_die_ref subrange_die;
9841 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9843 if (context_die == NULL)
9844 context_die = comp_unit_die;
9846 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9848 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9850 /* The size of the subrange type and its base type do not match,
9851 so we need to generate a size attribute for the subrange type. */
9852 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9856 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9858 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9860 return subrange_die;
9863 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9864 entry that chains various modifiers in front of the given type. */
9867 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9868 dw_die_ref context_die)
9870 enum tree_code code = TREE_CODE (type);
9871 dw_die_ref mod_type_die;
9872 dw_die_ref sub_die = NULL;
9873 tree item_type = NULL;
9874 tree qualified_type;
9875 tree name, low, high;
9877 if (code == ERROR_MARK)
9880 /* See if we already have the appropriately qualified variant of
9883 = get_qualified_type (type,
9884 ((is_const_type ? TYPE_QUAL_CONST : 0)
9885 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9887 /* If we do, then we can just use its DIE, if it exists. */
9890 mod_type_die = lookup_type_die (qualified_type);
9892 return mod_type_die;
9895 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9897 /* Handle C typedef types. */
9898 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9900 tree dtype = TREE_TYPE (name);
9902 if (qualified_type == dtype)
9904 /* For a named type, use the typedef. */
9905 gen_type_die (qualified_type, context_die);
9906 return lookup_type_die (qualified_type);
9908 else if (is_const_type < TYPE_READONLY (dtype)
9909 || is_volatile_type < TYPE_VOLATILE (dtype)
9910 || (is_const_type <= TYPE_READONLY (dtype)
9911 && is_volatile_type <= TYPE_VOLATILE (dtype)
9912 && DECL_ORIGINAL_TYPE (name) != type))
9913 /* cv-unqualified version of named type. Just use the unnamed
9914 type to which it refers. */
9915 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9916 is_const_type, is_volatile_type,
9918 /* Else cv-qualified version of named type; fall through. */
9923 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9924 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9926 else if (is_volatile_type)
9928 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9929 sub_die = modified_type_die (type, 0, 0, context_die);
9931 else if (code == POINTER_TYPE)
9933 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9934 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9935 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9936 item_type = TREE_TYPE (type);
9938 else if (code == REFERENCE_TYPE)
9940 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9941 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9942 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9943 item_type = TREE_TYPE (type);
9945 else if (code == INTEGER_TYPE
9946 && TREE_TYPE (type) != NULL_TREE
9947 && subrange_type_for_debug_p (type, &low, &high))
9949 mod_type_die = subrange_type_die (type, low, high, context_die);
9950 item_type = TREE_TYPE (type);
9952 else if (is_base_type (type))
9953 mod_type_die = base_type_die (type);
9956 gen_type_die (type, context_die);
9958 /* We have to get the type_main_variant here (and pass that to the
9959 `lookup_type_die' routine) because the ..._TYPE node we have
9960 might simply be a *copy* of some original type node (where the
9961 copy was created to help us keep track of typedef names) and
9962 that copy might have a different TYPE_UID from the original
9964 if (TREE_CODE (type) != VECTOR_TYPE)
9965 return lookup_type_die (type_main_variant (type));
9967 /* Vectors have the debugging information in the type,
9968 not the main variant. */
9969 return lookup_type_die (type);
9972 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9973 don't output a DW_TAG_typedef, since there isn't one in the
9974 user's program; just attach a DW_AT_name to the type. */
9976 && (TREE_CODE (name) != TYPE_DECL
9977 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9979 if (TREE_CODE (name) == TYPE_DECL)
9980 /* Could just call add_name_and_src_coords_attributes here,
9981 but since this is a builtin type it doesn't have any
9982 useful source coordinates anyway. */
9983 name = DECL_NAME (name);
9984 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9988 equate_type_number_to_die (qualified_type, mod_type_die);
9991 /* We must do this after the equate_type_number_to_die call, in case
9992 this is a recursive type. This ensures that the modified_type_die
9993 recursion will terminate even if the type is recursive. Recursive
9994 types are possible in Ada. */
9995 sub_die = modified_type_die (item_type,
9996 TYPE_READONLY (item_type),
9997 TYPE_VOLATILE (item_type),
10000 if (sub_die != NULL)
10001 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10003 return mod_type_die;
10006 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10007 an enumerated type. */
10010 type_is_enum (const_tree type)
10012 return TREE_CODE (type) == ENUMERAL_TYPE;
10015 /* Return the DBX register number described by a given RTL node. */
10017 static unsigned int
10018 dbx_reg_number (const_rtx rtl)
10020 unsigned regno = REGNO (rtl);
10022 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10024 #ifdef LEAF_REG_REMAP
10025 if (current_function_uses_only_leaf_regs)
10027 int leaf_reg = LEAF_REG_REMAP (regno);
10028 if (leaf_reg != -1)
10029 regno = (unsigned) leaf_reg;
10033 return DBX_REGISTER_NUMBER (regno);
10036 /* Optionally add a DW_OP_piece term to a location description expression.
10037 DW_OP_piece is only added if the location description expression already
10038 doesn't end with DW_OP_piece. */
10041 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10043 dw_loc_descr_ref loc;
10045 if (*list_head != NULL)
10047 /* Find the end of the chain. */
10048 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10051 if (loc->dw_loc_opc != DW_OP_piece)
10052 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10056 /* Return a location descriptor that designates a machine register or
10057 zero if there is none. */
10059 static dw_loc_descr_ref
10060 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10064 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10067 regs = targetm.dwarf_register_span (rtl);
10069 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10070 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10072 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10075 /* Return a location descriptor that designates a machine register for
10076 a given hard register number. */
10078 static dw_loc_descr_ref
10079 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10081 dw_loc_descr_ref reg_loc_descr;
10085 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10087 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10089 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10090 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10092 return reg_loc_descr;
10095 /* Given an RTL of a register, return a location descriptor that
10096 designates a value that spans more than one register. */
10098 static dw_loc_descr_ref
10099 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10100 enum var_init_status initialized)
10102 int nregs, size, i;
10104 dw_loc_descr_ref loc_result = NULL;
10107 #ifdef LEAF_REG_REMAP
10108 if (current_function_uses_only_leaf_regs)
10110 int leaf_reg = LEAF_REG_REMAP (reg);
10111 if (leaf_reg != -1)
10112 reg = (unsigned) leaf_reg;
10115 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10116 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10118 /* Simple, contiguous registers. */
10119 if (regs == NULL_RTX)
10121 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10126 dw_loc_descr_ref t;
10128 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10129 VAR_INIT_STATUS_INITIALIZED);
10130 add_loc_descr (&loc_result, t);
10131 add_loc_descr_op_piece (&loc_result, size);
10137 /* Now onto stupid register sets in non contiguous locations. */
10139 gcc_assert (GET_CODE (regs) == PARALLEL);
10141 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10144 for (i = 0; i < XVECLEN (regs, 0); ++i)
10146 dw_loc_descr_ref t;
10148 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10149 VAR_INIT_STATUS_INITIALIZED);
10150 add_loc_descr (&loc_result, t);
10151 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10152 add_loc_descr_op_piece (&loc_result, size);
10155 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10156 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10160 #endif /* DWARF2_DEBUGGING_INFO */
10162 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10164 /* Return a location descriptor that designates a constant. */
10166 static dw_loc_descr_ref
10167 int_loc_descriptor (HOST_WIDE_INT i)
10169 enum dwarf_location_atom op;
10171 /* Pick the smallest representation of a constant, rather than just
10172 defaulting to the LEB encoding. */
10176 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10177 else if (i <= 0xff)
10178 op = DW_OP_const1u;
10179 else if (i <= 0xffff)
10180 op = DW_OP_const2u;
10181 else if (HOST_BITS_PER_WIDE_INT == 32
10182 || i <= 0xffffffff)
10183 op = DW_OP_const4u;
10190 op = DW_OP_const1s;
10191 else if (i >= -0x8000)
10192 op = DW_OP_const2s;
10193 else if (HOST_BITS_PER_WIDE_INT == 32
10194 || i >= -0x80000000)
10195 op = DW_OP_const4s;
10200 return new_loc_descr (op, i, 0);
10204 #ifdef DWARF2_DEBUGGING_INFO
10206 /* Return a location descriptor that designates a base+offset location. */
10208 static dw_loc_descr_ref
10209 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10210 enum var_init_status initialized)
10212 unsigned int regno;
10213 dw_loc_descr_ref result;
10214 dw_fde_ref fde = current_fde ();
10216 /* We only use "frame base" when we're sure we're talking about the
10217 post-prologue local stack frame. We do this by *not* running
10218 register elimination until this point, and recognizing the special
10219 argument pointer and soft frame pointer rtx's. */
10220 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10222 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10226 if (GET_CODE (elim) == PLUS)
10228 offset += INTVAL (XEXP (elim, 1));
10229 elim = XEXP (elim, 0);
10231 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10232 && (elim == hard_frame_pointer_rtx
10233 || elim == stack_pointer_rtx))
10234 || elim == (frame_pointer_needed
10235 ? hard_frame_pointer_rtx
10236 : stack_pointer_rtx));
10238 /* If drap register is used to align stack, use frame
10239 pointer + offset to access stack variables. If stack
10240 is aligned without drap, use stack pointer + offset to
10241 access stack variables. */
10242 if (crtl->stack_realign_tried
10243 && cfa.reg == HARD_FRAME_POINTER_REGNUM
10244 && reg == frame_pointer_rtx)
10247 = DWARF_FRAME_REGNUM (cfa.indirect
10248 ? HARD_FRAME_POINTER_REGNUM
10249 : STACK_POINTER_REGNUM);
10250 return new_reg_loc_descr (base_reg, offset);
10253 offset += frame_pointer_fb_offset;
10254 return new_loc_descr (DW_OP_fbreg, offset, 0);
10258 && fde->drap_reg != INVALID_REGNUM
10259 && (fde->drap_reg == REGNO (reg)
10260 || fde->vdrap_reg == REGNO (reg)))
10262 /* Use cfa+offset to represent the location of arguments passed
10263 on stack when drap is used to align stack. */
10264 return new_loc_descr (DW_OP_fbreg, offset, 0);
10267 regno = dbx_reg_number (reg);
10269 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10272 result = new_loc_descr (DW_OP_bregx, regno, offset);
10274 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10275 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10280 /* Return true if this RTL expression describes a base+offset calculation. */
10283 is_based_loc (const_rtx rtl)
10285 return (GET_CODE (rtl) == PLUS
10286 && ((REG_P (XEXP (rtl, 0))
10287 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10288 && CONST_INT_P (XEXP (rtl, 1)))));
10291 /* Return a descriptor that describes the concatenation of N locations
10292 used to form the address of a memory location. */
10294 static dw_loc_descr_ref
10295 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10296 enum var_init_status initialized)
10299 dw_loc_descr_ref cc_loc_result = NULL;
10300 unsigned int n = XVECLEN (concatn, 0);
10302 for (i = 0; i < n; ++i)
10304 dw_loc_descr_ref ref;
10305 rtx x = XVECEXP (concatn, 0, i);
10307 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10311 add_loc_descr (&cc_loc_result, ref);
10312 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10315 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10316 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10318 return cc_loc_result;
10321 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10324 static dw_loc_descr_ref
10325 tls_mem_loc_descriptor (rtx mem)
10328 dw_loc_descr_ref loc_result;
10330 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10333 base = get_base_address (MEM_EXPR (mem));
10335 || TREE_CODE (base) != VAR_DECL
10336 || !DECL_THREAD_LOCAL_P (base))
10339 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
10340 if (loc_result == NULL)
10343 if (INTVAL (MEM_OFFSET (mem)))
10344 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
10349 /* The following routine converts the RTL for a variable or parameter
10350 (resident in memory) into an equivalent Dwarf representation of a
10351 mechanism for getting the address of that same variable onto the top of a
10352 hypothetical "address evaluation" stack.
10354 When creating memory location descriptors, we are effectively transforming
10355 the RTL for a memory-resident object into its Dwarf postfix expression
10356 equivalent. This routine recursively descends an RTL tree, turning
10357 it into Dwarf postfix code as it goes.
10359 MODE is the mode of the memory reference, needed to handle some
10360 autoincrement addressing modes.
10362 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10363 location list for RTL.
10365 Return 0 if we can't represent the location. */
10367 static dw_loc_descr_ref
10368 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
10369 enum var_init_status initialized)
10371 dw_loc_descr_ref mem_loc_result = NULL;
10372 enum dwarf_location_atom op;
10374 /* Note that for a dynamically sized array, the location we will generate a
10375 description of here will be the lowest numbered location which is
10376 actually within the array. That's *not* necessarily the same as the
10377 zeroth element of the array. */
10379 rtl = targetm.delegitimize_address (rtl);
10381 switch (GET_CODE (rtl))
10386 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10387 just fall into the SUBREG code. */
10389 /* ... fall through ... */
10392 /* The case of a subreg may arise when we have a local (register)
10393 variable or a formal (register) parameter which doesn't quite fill
10394 up an entire register. For now, just assume that it is
10395 legitimate to make the Dwarf info refer to the whole register which
10396 contains the given subreg. */
10397 rtl = XEXP (rtl, 0);
10399 /* ... fall through ... */
10402 /* Whenever a register number forms a part of the description of the
10403 method for calculating the (dynamic) address of a memory resident
10404 object, DWARF rules require the register number be referred to as
10405 a "base register". This distinction is not based in any way upon
10406 what category of register the hardware believes the given register
10407 belongs to. This is strictly DWARF terminology we're dealing with
10408 here. Note that in cases where the location of a memory-resident
10409 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10410 OP_CONST (0)) the actual DWARF location descriptor that we generate
10411 may just be OP_BASEREG (basereg). This may look deceptively like
10412 the object in question was allocated to a register (rather than in
10413 memory) so DWARF consumers need to be aware of the subtle
10414 distinction between OP_REG and OP_BASEREG. */
10415 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10416 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10417 else if (stack_realign_drap
10419 && crtl->args.internal_arg_pointer == rtl
10420 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10422 /* If RTL is internal_arg_pointer, which has been optimized
10423 out, use DRAP instead. */
10424 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10425 VAR_INIT_STATUS_INITIALIZED);
10430 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10431 VAR_INIT_STATUS_INITIALIZED);
10432 if (mem_loc_result == NULL)
10433 mem_loc_result = tls_mem_loc_descriptor (rtl);
10434 if (mem_loc_result != 0)
10435 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10439 rtl = XEXP (rtl, 1);
10441 /* ... fall through ... */
10444 /* Some ports can transform a symbol ref into a label ref, because
10445 the symbol ref is too far away and has to be dumped into a constant
10449 /* Alternatively, the symbol in the constant pool might be referenced
10450 by a different symbol. */
10451 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10454 rtx tmp = get_pool_constant_mark (rtl, &marked);
10456 if (GET_CODE (tmp) == SYMBOL_REF)
10459 if (CONSTANT_POOL_ADDRESS_P (tmp))
10460 get_pool_constant_mark (tmp, &marked);
10465 /* If all references to this pool constant were optimized away,
10466 it was not output and thus we can't represent it.
10467 FIXME: might try to use DW_OP_const_value here, though
10468 DW_OP_piece complicates it. */
10473 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10474 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10475 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10476 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10480 /* Extract the PLUS expression nested inside and fall into
10481 PLUS code below. */
10482 rtl = XEXP (rtl, 1);
10487 /* Turn these into a PLUS expression and fall into the PLUS code
10489 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10490 GEN_INT (GET_CODE (rtl) == PRE_INC
10491 ? GET_MODE_UNIT_SIZE (mode)
10492 : -GET_MODE_UNIT_SIZE (mode)));
10494 /* ... fall through ... */
10498 if (is_based_loc (rtl))
10499 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10500 INTVAL (XEXP (rtl, 1)),
10501 VAR_INIT_STATUS_INITIALIZED);
10504 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10505 VAR_INIT_STATUS_INITIALIZED);
10506 if (mem_loc_result == 0)
10509 if (CONST_INT_P (XEXP (rtl, 1)))
10510 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
10513 dw_loc_descr_ref mem_loc_result2
10514 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10515 VAR_INIT_STATUS_INITIALIZED);
10516 if (mem_loc_result2 == 0)
10518 add_loc_descr (&mem_loc_result, mem_loc_result2);
10519 add_loc_descr (&mem_loc_result,
10520 new_loc_descr (DW_OP_plus, 0, 0));
10525 /* If a pseudo-reg is optimized away, it is possible for it to
10526 be replaced with a MEM containing a multiply or shift. */
10545 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10546 VAR_INIT_STATUS_INITIALIZED);
10547 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10548 VAR_INIT_STATUS_INITIALIZED);
10550 if (op0 == 0 || op1 == 0)
10553 mem_loc_result = op0;
10554 add_loc_descr (&mem_loc_result, op1);
10555 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10560 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10564 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10565 VAR_INIT_STATUS_INITIALIZED);
10569 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10570 can't express it in the debug info. This can happen e.g. with some
10575 gcc_unreachable ();
10578 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10579 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10581 return mem_loc_result;
10584 /* Return a descriptor that describes the concatenation of two locations.
10585 This is typically a complex variable. */
10587 static dw_loc_descr_ref
10588 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10590 dw_loc_descr_ref cc_loc_result = NULL;
10591 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10592 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10594 if (x0_ref == 0 || x1_ref == 0)
10597 cc_loc_result = x0_ref;
10598 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10600 add_loc_descr (&cc_loc_result, x1_ref);
10601 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10603 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10604 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10606 return cc_loc_result;
10609 /* Return a descriptor that describes the concatenation of N
10612 static dw_loc_descr_ref
10613 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10616 dw_loc_descr_ref cc_loc_result = NULL;
10617 unsigned int n = XVECLEN (concatn, 0);
10619 for (i = 0; i < n; ++i)
10621 dw_loc_descr_ref ref;
10622 rtx x = XVECEXP (concatn, 0, i);
10624 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10628 add_loc_descr (&cc_loc_result, ref);
10629 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10632 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10633 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10635 return cc_loc_result;
10638 /* Output a proper Dwarf location descriptor for a variable or parameter
10639 which is either allocated in a register or in a memory location. For a
10640 register, we just generate an OP_REG and the register number. For a
10641 memory location we provide a Dwarf postfix expression describing how to
10642 generate the (dynamic) address of the object onto the address stack.
10644 If we don't know how to describe it, return 0. */
10646 static dw_loc_descr_ref
10647 loc_descriptor (rtx rtl, enum var_init_status initialized)
10649 dw_loc_descr_ref loc_result = NULL;
10651 switch (GET_CODE (rtl))
10654 /* The case of a subreg may arise when we have a local (register)
10655 variable or a formal (register) parameter which doesn't quite fill
10656 up an entire register. For now, just assume that it is
10657 legitimate to make the Dwarf info refer to the whole register which
10658 contains the given subreg. */
10659 rtl = SUBREG_REG (rtl);
10661 /* ... fall through ... */
10664 loc_result = reg_loc_descriptor (rtl, initialized);
10668 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10670 if (loc_result == NULL)
10671 loc_result = tls_mem_loc_descriptor (rtl);
10675 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10680 loc_result = concatn_loc_descriptor (rtl, initialized);
10685 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10687 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10691 rtl = XEXP (rtl, 1);
10696 rtvec par_elems = XVEC (rtl, 0);
10697 int num_elem = GET_NUM_ELEM (par_elems);
10698 enum machine_mode mode;
10701 /* Create the first one, so we have something to add to. */
10702 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10704 if (loc_result == NULL)
10706 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10707 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10708 for (i = 1; i < num_elem; i++)
10710 dw_loc_descr_ref temp;
10712 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10716 add_loc_descr (&loc_result, temp);
10717 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10718 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10724 gcc_unreachable ();
10730 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10731 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10732 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10733 top-level invocation, and we require the address of LOC; is 0 if we require
10734 the value of LOC. */
10736 static dw_loc_descr_ref
10737 loc_descriptor_from_tree_1 (tree loc, int want_address)
10739 dw_loc_descr_ref ret, ret1;
10740 int have_address = 0;
10741 enum dwarf_location_atom op;
10743 /* ??? Most of the time we do not take proper care for sign/zero
10744 extending the values properly. Hopefully this won't be a real
10747 switch (TREE_CODE (loc))
10752 case PLACEHOLDER_EXPR:
10753 /* This case involves extracting fields from an object to determine the
10754 position of other fields. We don't try to encode this here. The
10755 only user of this is Ada, which encodes the needed information using
10756 the names of types. */
10762 case PREINCREMENT_EXPR:
10763 case PREDECREMENT_EXPR:
10764 case POSTINCREMENT_EXPR:
10765 case POSTDECREMENT_EXPR:
10766 /* There are no opcodes for these operations. */
10770 /* If we already want an address, there's nothing we can do. */
10774 /* Otherwise, process the argument and look for the address. */
10775 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10778 if (DECL_THREAD_LOCAL_P (loc))
10781 enum dwarf_location_atom first_op;
10782 enum dwarf_location_atom second_op;
10783 bool dtprel = false;
10785 if (targetm.have_tls)
10787 /* If this is not defined, we have no way to emit the
10789 if (!targetm.asm_out.output_dwarf_dtprel)
10792 /* The way DW_OP_GNU_push_tls_address is specified, we
10793 can only look up addresses of objects in the current
10795 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
10797 first_op = DW_OP_addr;
10799 second_op = DW_OP_GNU_push_tls_address;
10803 if (!targetm.emutls.debug_form_tls_address)
10805 loc = emutls_decl (loc);
10806 first_op = DW_OP_addr;
10807 second_op = DW_OP_form_tls_address;
10810 rtl = rtl_for_decl_location (loc);
10811 if (rtl == NULL_RTX)
10816 rtl = XEXP (rtl, 0);
10817 if (! CONSTANT_P (rtl))
10820 ret = new_loc_descr (first_op, 0, 0);
10821 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10822 ret->dw_loc_oprnd1.v.val_addr = rtl;
10823 ret->dtprel = dtprel;
10825 ret1 = new_loc_descr (second_op, 0, 0);
10826 add_loc_descr (&ret, ret1);
10834 if (DECL_HAS_VALUE_EXPR_P (loc))
10835 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10840 case FUNCTION_DECL:
10842 rtx rtl = rtl_for_decl_location (loc);
10844 if (rtl == NULL_RTX)
10846 else if (CONST_INT_P (rtl))
10848 HOST_WIDE_INT val = INTVAL (rtl);
10849 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10850 val &= GET_MODE_MASK (DECL_MODE (loc));
10851 ret = int_loc_descriptor (val);
10853 else if (GET_CODE (rtl) == CONST_STRING)
10855 else if (CONSTANT_P (rtl))
10857 ret = new_loc_descr (DW_OP_addr, 0, 0);
10858 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10859 ret->dw_loc_oprnd1.v.val_addr = rtl;
10863 enum machine_mode mode;
10865 /* Certain constructs can only be represented at top-level. */
10866 if (want_address == 2)
10867 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10869 mode = GET_MODE (rtl);
10872 rtl = XEXP (rtl, 0);
10875 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10881 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10885 case COMPOUND_EXPR:
10886 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10889 case VIEW_CONVERT_EXPR:
10892 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10894 case COMPONENT_REF:
10895 case BIT_FIELD_REF:
10897 case ARRAY_RANGE_REF:
10900 HOST_WIDE_INT bitsize, bitpos, bytepos;
10901 enum machine_mode mode;
10903 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10905 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10906 &unsignedp, &volatilep, false);
10911 ret = loc_descriptor_from_tree_1 (obj, 1);
10913 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10916 if (offset != NULL_TREE)
10918 /* Variable offset. */
10919 ret1 = loc_descriptor_from_tree_1 (offset, 0);
10922 add_loc_descr (&ret, ret1);
10923 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10926 bytepos = bitpos / BITS_PER_UNIT;
10927 loc_descr_plus_const (&ret, bytepos);
10934 if (host_integerp (loc, 0))
10935 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10942 /* Get an RTL for this, if something has been emitted. */
10943 rtx rtl = lookup_constant_def (loc);
10944 enum machine_mode mode;
10946 if (!rtl || !MEM_P (rtl))
10948 mode = GET_MODE (rtl);
10949 rtl = XEXP (rtl, 0);
10950 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10955 case TRUTH_AND_EXPR:
10956 case TRUTH_ANDIF_EXPR:
10961 case TRUTH_XOR_EXPR:
10966 case TRUTH_OR_EXPR:
10967 case TRUTH_ORIF_EXPR:
10972 case FLOOR_DIV_EXPR:
10973 case CEIL_DIV_EXPR:
10974 case ROUND_DIV_EXPR:
10975 case TRUNC_DIV_EXPR:
10983 case FLOOR_MOD_EXPR:
10984 case CEIL_MOD_EXPR:
10985 case ROUND_MOD_EXPR:
10986 case TRUNC_MOD_EXPR:
10999 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
11002 case POINTER_PLUS_EXPR:
11004 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
11005 && host_integerp (TREE_OPERAND (loc, 1), 0))
11007 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11011 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
11019 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11026 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11033 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11040 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11055 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11056 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11057 if (ret == 0 || ret1 == 0)
11060 add_loc_descr (&ret, ret1);
11061 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11064 case TRUTH_NOT_EXPR:
11078 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11082 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11088 const enum tree_code code =
11089 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
11091 loc = build3 (COND_EXPR, TREE_TYPE (loc),
11092 build2 (code, integer_type_node,
11093 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
11094 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
11097 /* ... fall through ... */
11101 dw_loc_descr_ref lhs
11102 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11103 dw_loc_descr_ref rhs
11104 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
11105 dw_loc_descr_ref bra_node, jump_node, tmp;
11107 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11108 if (ret == 0 || lhs == 0 || rhs == 0)
11111 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11112 add_loc_descr (&ret, bra_node);
11114 add_loc_descr (&ret, rhs);
11115 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
11116 add_loc_descr (&ret, jump_node);
11118 add_loc_descr (&ret, lhs);
11119 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11120 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
11122 /* ??? Need a node to point the skip at. Use a nop. */
11123 tmp = new_loc_descr (DW_OP_nop, 0, 0);
11124 add_loc_descr (&ret, tmp);
11125 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11126 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
11130 case FIX_TRUNC_EXPR:
11134 /* Leave front-end specific codes as simply unknown. This comes
11135 up, for instance, with the C STMT_EXPR. */
11136 if ((unsigned int) TREE_CODE (loc)
11137 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
11140 #ifdef ENABLE_CHECKING
11141 /* Otherwise this is a generic code; we should just lists all of
11142 these explicitly. We forgot one. */
11143 gcc_unreachable ();
11145 /* In a release build, we want to degrade gracefully: better to
11146 generate incomplete debugging information than to crash. */
11151 /* Show if we can't fill the request for an address. */
11152 if (want_address && !have_address)
11155 /* If we've got an address and don't want one, dereference. */
11156 if (!want_address && have_address && ret)
11158 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
11160 if (size > DWARF2_ADDR_SIZE || size == -1)
11162 else if (size == DWARF2_ADDR_SIZE)
11165 op = DW_OP_deref_size;
11167 add_loc_descr (&ret, new_loc_descr (op, size, 0));
11173 static inline dw_loc_descr_ref
11174 loc_descriptor_from_tree (tree loc)
11176 return loc_descriptor_from_tree_1 (loc, 2);
11179 /* Given a value, round it up to the lowest multiple of `boundary'
11180 which is not less than the value itself. */
11182 static inline HOST_WIDE_INT
11183 ceiling (HOST_WIDE_INT value, unsigned int boundary)
11185 return (((value + boundary - 1) / boundary) * boundary);
11188 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
11189 pointer to the declared type for the relevant field variable, or return
11190 `integer_type_node' if the given node turns out to be an
11191 ERROR_MARK node. */
11194 field_type (const_tree decl)
11198 if (TREE_CODE (decl) == ERROR_MARK)
11199 return integer_type_node;
11201 type = DECL_BIT_FIELD_TYPE (decl);
11202 if (type == NULL_TREE)
11203 type = TREE_TYPE (decl);
11208 /* Given a pointer to a tree node, return the alignment in bits for
11209 it, or else return BITS_PER_WORD if the node actually turns out to
11210 be an ERROR_MARK node. */
11212 static inline unsigned
11213 simple_type_align_in_bits (const_tree type)
11215 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
11218 static inline unsigned
11219 simple_decl_align_in_bits (const_tree decl)
11221 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
11224 /* Return the result of rounding T up to ALIGN. */
11226 static inline HOST_WIDE_INT
11227 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
11229 /* We must be careful if T is negative because HOST_WIDE_INT can be
11230 either "above" or "below" unsigned int as per the C promotion
11231 rules, depending on the host, thus making the signedness of the
11232 direct multiplication and division unpredictable. */
11233 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
11239 return (HOST_WIDE_INT) u;
11242 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
11243 lowest addressed byte of the "containing object" for the given FIELD_DECL,
11244 or return 0 if we are unable to determine what that offset is, either
11245 because the argument turns out to be a pointer to an ERROR_MARK node, or
11246 because the offset is actually variable. (We can't handle the latter case
11249 static HOST_WIDE_INT
11250 field_byte_offset (const_tree decl)
11252 HOST_WIDE_INT object_offset_in_bits;
11253 HOST_WIDE_INT bitpos_int;
11255 if (TREE_CODE (decl) == ERROR_MARK)
11258 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
11260 /* We cannot yet cope with fields whose positions are variable, so
11261 for now, when we see such things, we simply return 0. Someday, we may
11262 be able to handle such cases, but it will be damn difficult. */
11263 if (! host_integerp (bit_position (decl), 0))
11266 bitpos_int = int_bit_position (decl);
11268 #ifdef PCC_BITFIELD_TYPE_MATTERS
11269 if (PCC_BITFIELD_TYPE_MATTERS)
11272 tree field_size_tree;
11273 HOST_WIDE_INT deepest_bitpos;
11274 unsigned HOST_WIDE_INT field_size_in_bits;
11275 unsigned int type_align_in_bits;
11276 unsigned int decl_align_in_bits;
11277 unsigned HOST_WIDE_INT type_size_in_bits;
11279 type = field_type (decl);
11280 type_size_in_bits = simple_type_size_in_bits (type);
11281 type_align_in_bits = simple_type_align_in_bits (type);
11283 field_size_tree = DECL_SIZE (decl);
11285 /* The size could be unspecified if there was an error, or for
11286 a flexible array member. */
11287 if (!field_size_tree)
11288 field_size_tree = bitsize_zero_node;
11290 /* If the size of the field is not constant, use the type size. */
11291 if (host_integerp (field_size_tree, 1))
11292 field_size_in_bits = tree_low_cst (field_size_tree, 1);
11294 field_size_in_bits = type_size_in_bits;
11296 decl_align_in_bits = simple_decl_align_in_bits (decl);
11298 /* The GCC front-end doesn't make any attempt to keep track of the
11299 starting bit offset (relative to the start of the containing
11300 structure type) of the hypothetical "containing object" for a
11301 bit-field. Thus, when computing the byte offset value for the
11302 start of the "containing object" of a bit-field, we must deduce
11303 this information on our own. This can be rather tricky to do in
11304 some cases. For example, handling the following structure type
11305 definition when compiling for an i386/i486 target (which only
11306 aligns long long's to 32-bit boundaries) can be very tricky:
11308 struct S { int field1; long long field2:31; };
11310 Fortunately, there is a simple rule-of-thumb which can be used
11311 in such cases. When compiling for an i386/i486, GCC will
11312 allocate 8 bytes for the structure shown above. It decides to
11313 do this based upon one simple rule for bit-field allocation.
11314 GCC allocates each "containing object" for each bit-field at
11315 the first (i.e. lowest addressed) legitimate alignment boundary
11316 (based upon the required minimum alignment for the declared
11317 type of the field) which it can possibly use, subject to the
11318 condition that there is still enough available space remaining
11319 in the containing object (when allocated at the selected point)
11320 to fully accommodate all of the bits of the bit-field itself.
11322 This simple rule makes it obvious why GCC allocates 8 bytes for
11323 each object of the structure type shown above. When looking
11324 for a place to allocate the "containing object" for `field2',
11325 the compiler simply tries to allocate a 64-bit "containing
11326 object" at each successive 32-bit boundary (starting at zero)
11327 until it finds a place to allocate that 64- bit field such that
11328 at least 31 contiguous (and previously unallocated) bits remain
11329 within that selected 64 bit field. (As it turns out, for the
11330 example above, the compiler finds it is OK to allocate the
11331 "containing object" 64-bit field at bit-offset zero within the
11334 Here we attempt to work backwards from the limited set of facts
11335 we're given, and we try to deduce from those facts, where GCC
11336 must have believed that the containing object started (within
11337 the structure type). The value we deduce is then used (by the
11338 callers of this routine) to generate DW_AT_location and
11339 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11340 the case of DW_AT_location, regular fields as well). */
11342 /* Figure out the bit-distance from the start of the structure to
11343 the "deepest" bit of the bit-field. */
11344 deepest_bitpos = bitpos_int + field_size_in_bits;
11346 /* This is the tricky part. Use some fancy footwork to deduce
11347 where the lowest addressed bit of the containing object must
11349 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11351 /* Round up to type_align by default. This works best for
11353 object_offset_in_bits
11354 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
11356 if (object_offset_in_bits > bitpos_int)
11358 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11360 /* Round up to decl_align instead. */
11361 object_offset_in_bits
11362 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
11367 object_offset_in_bits = bitpos_int;
11369 return object_offset_in_bits / BITS_PER_UNIT;
11372 /* The following routines define various Dwarf attributes and any data
11373 associated with them. */
11375 /* Add a location description attribute value to a DIE.
11377 This emits location attributes suitable for whole variables and
11378 whole parameters. Note that the location attributes for struct fields are
11379 generated by the routine `data_member_location_attribute' below. */
11382 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
11383 dw_loc_descr_ref descr)
11386 add_AT_loc (die, attr_kind, descr);
11389 /* Attach the specialized form of location attribute used for data members of
11390 struct and union types. In the special case of a FIELD_DECL node which
11391 represents a bit-field, the "offset" part of this special location
11392 descriptor must indicate the distance in bytes from the lowest-addressed
11393 byte of the containing struct or union type to the lowest-addressed byte of
11394 the "containing object" for the bit-field. (See the `field_byte_offset'
11397 For any given bit-field, the "containing object" is a hypothetical object
11398 (of some integral or enum type) within which the given bit-field lives. The
11399 type of this hypothetical "containing object" is always the same as the
11400 declared type of the individual bit-field itself (for GCC anyway... the
11401 DWARF spec doesn't actually mandate this). Note that it is the size (in
11402 bytes) of the hypothetical "containing object" which will be given in the
11403 DW_AT_byte_size attribute for this bit-field. (See the
11404 `byte_size_attribute' function below.) It is also used when calculating the
11405 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11406 function below.) */
11409 add_data_member_location_attribute (dw_die_ref die, tree decl)
11411 HOST_WIDE_INT offset;
11412 dw_loc_descr_ref loc_descr = 0;
11414 if (TREE_CODE (decl) == TREE_BINFO)
11416 /* We're working on the TAG_inheritance for a base class. */
11417 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11419 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11420 aren't at a fixed offset from all (sub)objects of the same
11421 type. We need to extract the appropriate offset from our
11422 vtable. The following dwarf expression means
11424 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11426 This is specific to the V3 ABI, of course. */
11428 dw_loc_descr_ref tmp;
11430 /* Make a copy of the object address. */
11431 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11432 add_loc_descr (&loc_descr, tmp);
11434 /* Extract the vtable address. */
11435 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11436 add_loc_descr (&loc_descr, tmp);
11438 /* Calculate the address of the offset. */
11439 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11440 gcc_assert (offset < 0);
11442 tmp = int_loc_descriptor (-offset);
11443 add_loc_descr (&loc_descr, tmp);
11444 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11445 add_loc_descr (&loc_descr, tmp);
11447 /* Extract the offset. */
11448 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11449 add_loc_descr (&loc_descr, tmp);
11451 /* Add it to the object address. */
11452 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11453 add_loc_descr (&loc_descr, tmp);
11456 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11459 offset = field_byte_offset (decl);
11463 enum dwarf_location_atom op;
11465 /* The DWARF2 standard says that we should assume that the structure
11466 address is already on the stack, so we can specify a structure field
11467 address by using DW_OP_plus_uconst. */
11469 #ifdef MIPS_DEBUGGING_INFO
11470 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11471 operator correctly. It works only if we leave the offset on the
11475 op = DW_OP_plus_uconst;
11478 loc_descr = new_loc_descr (op, offset, 0);
11481 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11484 /* Writes integer values to dw_vec_const array. */
11487 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11491 *dest++ = val & 0xff;
11497 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11499 static HOST_WIDE_INT
11500 extract_int (const unsigned char *src, unsigned int size)
11502 HOST_WIDE_INT val = 0;
11508 val |= *--src & 0xff;
11514 /* Writes floating point values to dw_vec_const array. */
11517 insert_float (const_rtx rtl, unsigned char *array)
11519 REAL_VALUE_TYPE rv;
11523 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11524 real_to_target (val, &rv, GET_MODE (rtl));
11526 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11527 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11529 insert_int (val[i], 4, array);
11534 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11535 does not have a "location" either in memory or in a register. These
11536 things can arise in GNU C when a constant is passed as an actual parameter
11537 to an inlined function. They can also arise in C++ where declared
11538 constants do not necessarily get memory "homes". */
11541 add_const_value_attribute (dw_die_ref die, rtx rtl)
11543 switch (GET_CODE (rtl))
11547 HOST_WIDE_INT val = INTVAL (rtl);
11550 add_AT_int (die, DW_AT_const_value, val);
11552 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11557 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11558 floating-point constant. A CONST_DOUBLE is used whenever the
11559 constant requires more than one word in order to be adequately
11560 represented. We output CONST_DOUBLEs as blocks. */
11562 enum machine_mode mode = GET_MODE (rtl);
11564 if (SCALAR_FLOAT_MODE_P (mode))
11566 unsigned int length = GET_MODE_SIZE (mode);
11567 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11569 insert_float (rtl, array);
11570 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11574 /* ??? We really should be using HOST_WIDE_INT throughout. */
11575 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11577 add_AT_long_long (die, DW_AT_const_value,
11578 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11585 enum machine_mode mode = GET_MODE (rtl);
11586 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11587 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11588 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11592 switch (GET_MODE_CLASS (mode))
11594 case MODE_VECTOR_INT:
11595 for (i = 0, p = array; i < length; i++, p += elt_size)
11597 rtx elt = CONST_VECTOR_ELT (rtl, i);
11598 HOST_WIDE_INT lo, hi;
11600 switch (GET_CODE (elt))
11608 lo = CONST_DOUBLE_LOW (elt);
11609 hi = CONST_DOUBLE_HIGH (elt);
11613 gcc_unreachable ();
11616 if (elt_size <= sizeof (HOST_WIDE_INT))
11617 insert_int (lo, elt_size, p);
11620 unsigned char *p0 = p;
11621 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11623 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11624 if (WORDS_BIG_ENDIAN)
11629 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11630 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11635 case MODE_VECTOR_FLOAT:
11636 for (i = 0, p = array; i < length; i++, p += elt_size)
11638 rtx elt = CONST_VECTOR_ELT (rtl, i);
11639 insert_float (elt, p);
11644 gcc_unreachable ();
11647 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11652 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11658 add_AT_addr (die, DW_AT_const_value, rtl);
11659 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11663 /* In cases where an inlined instance of an inline function is passed
11664 the address of an `auto' variable (which is local to the caller) we
11665 can get a situation where the DECL_RTL of the artificial local
11666 variable (for the inlining) which acts as a stand-in for the
11667 corresponding formal parameter (of the inline function) will look
11668 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11669 exactly a compile-time constant expression, but it isn't the address
11670 of the (artificial) local variable either. Rather, it represents the
11671 *value* which the artificial local variable always has during its
11672 lifetime. We currently have no way to represent such quasi-constant
11673 values in Dwarf, so for now we just punt and generate nothing. */
11677 /* No other kinds of rtx should be possible here. */
11678 gcc_unreachable ();
11683 /* Determine whether the evaluation of EXPR references any variables
11684 or functions which aren't otherwise used (and therefore may not be
11687 reference_to_unused (tree * tp, int * walk_subtrees,
11688 void * data ATTRIBUTE_UNUSED)
11690 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11691 *walk_subtrees = 0;
11693 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11694 && ! TREE_ASM_WRITTEN (*tp))
11696 /* ??? The C++ FE emits debug information for using decls, so
11697 putting gcc_unreachable here falls over. See PR31899. For now
11698 be conservative. */
11699 else if (!cgraph_global_info_ready
11700 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11702 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11704 struct varpool_node *node = varpool_node (*tp);
11708 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11709 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11711 struct cgraph_node *node = cgraph_node (*tp);
11712 if (node->process || TREE_ASM_WRITTEN (*tp))
11715 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11721 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11722 for use in a later add_const_value_attribute call. */
11725 rtl_for_decl_init (tree init, tree type)
11727 rtx rtl = NULL_RTX;
11729 /* If a variable is initialized with a string constant without embedded
11730 zeros, build CONST_STRING. */
11731 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11733 tree enttype = TREE_TYPE (type);
11734 tree domain = TYPE_DOMAIN (type);
11735 enum machine_mode mode = TYPE_MODE (enttype);
11737 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11739 && integer_zerop (TYPE_MIN_VALUE (domain))
11740 && compare_tree_int (TYPE_MAX_VALUE (domain),
11741 TREE_STRING_LENGTH (init) - 1) == 0
11742 && ((size_t) TREE_STRING_LENGTH (init)
11743 == strlen (TREE_STRING_POINTER (init)) + 1))
11744 rtl = gen_rtx_CONST_STRING (VOIDmode,
11745 ggc_strdup (TREE_STRING_POINTER (init)));
11747 /* Other aggregates, and complex values, could be represented using
11749 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11751 /* Vectors only work if their mode is supported by the target.
11752 FIXME: generic vectors ought to work too. */
11753 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11755 /* If the initializer is something that we know will expand into an
11756 immediate RTL constant, expand it now. We must be careful not to
11757 reference variables which won't be output. */
11758 else if (initializer_constant_valid_p (init, type)
11759 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11761 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11763 if (TREE_CODE (type) == VECTOR_TYPE)
11764 switch (TREE_CODE (init))
11769 if (TREE_CONSTANT (init))
11771 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11772 bool constant_p = true;
11774 unsigned HOST_WIDE_INT ix;
11776 /* Even when ctor is constant, it might contain non-*_CST
11777 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11778 belong into VECTOR_CST nodes. */
11779 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11780 if (!CONSTANT_CLASS_P (value))
11782 constant_p = false;
11788 init = build_vector_from_ctor (type, elts);
11798 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11800 /* If expand_expr returns a MEM, it wasn't immediate. */
11801 gcc_assert (!rtl || !MEM_P (rtl));
11807 /* Generate RTL for the variable DECL to represent its location. */
11810 rtl_for_decl_location (tree decl)
11814 /* Here we have to decide where we are going to say the parameter "lives"
11815 (as far as the debugger is concerned). We only have a couple of
11816 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11818 DECL_RTL normally indicates where the parameter lives during most of the
11819 activation of the function. If optimization is enabled however, this
11820 could be either NULL or else a pseudo-reg. Both of those cases indicate
11821 that the parameter doesn't really live anywhere (as far as the code
11822 generation parts of GCC are concerned) during most of the function's
11823 activation. That will happen (for example) if the parameter is never
11824 referenced within the function.
11826 We could just generate a location descriptor here for all non-NULL
11827 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11828 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11829 where DECL_RTL is NULL or is a pseudo-reg.
11831 Note however that we can only get away with using DECL_INCOMING_RTL as
11832 a backup substitute for DECL_RTL in certain limited cases. In cases
11833 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11834 we can be sure that the parameter was passed using the same type as it is
11835 declared to have within the function, and that its DECL_INCOMING_RTL
11836 points us to a place where a value of that type is passed.
11838 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11839 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11840 because in these cases DECL_INCOMING_RTL points us to a value of some
11841 type which is *different* from the type of the parameter itself. Thus,
11842 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11843 such cases, the debugger would end up (for example) trying to fetch a
11844 `float' from a place which actually contains the first part of a
11845 `double'. That would lead to really incorrect and confusing
11846 output at debug-time.
11848 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11849 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11850 are a couple of exceptions however. On little-endian machines we can
11851 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11852 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11853 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11854 when (on a little-endian machine) a non-prototyped function has a
11855 parameter declared to be of type `short' or `char'. In such cases,
11856 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11857 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11858 passed `int' value. If the debugger then uses that address to fetch
11859 a `short' or a `char' (on a little-endian machine) the result will be
11860 the correct data, so we allow for such exceptional cases below.
11862 Note that our goal here is to describe the place where the given formal
11863 parameter lives during most of the function's activation (i.e. between the
11864 end of the prologue and the start of the epilogue). We'll do that as best
11865 as we can. Note however that if the given formal parameter is modified
11866 sometime during the execution of the function, then a stack backtrace (at
11867 debug-time) will show the function as having been called with the *new*
11868 value rather than the value which was originally passed in. This happens
11869 rarely enough that it is not a major problem, but it *is* a problem, and
11870 I'd like to fix it.
11872 A future version of dwarf2out.c may generate two additional attributes for
11873 any given DW_TAG_formal_parameter DIE which will describe the "passed
11874 type" and the "passed location" for the given formal parameter in addition
11875 to the attributes we now generate to indicate the "declared type" and the
11876 "active location" for each parameter. This additional set of attributes
11877 could be used by debuggers for stack backtraces. Separately, note that
11878 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11879 This happens (for example) for inlined-instances of inline function formal
11880 parameters which are never referenced. This really shouldn't be
11881 happening. All PARM_DECL nodes should get valid non-NULL
11882 DECL_INCOMING_RTL values. FIXME. */
11884 /* Use DECL_RTL as the "location" unless we find something better. */
11885 rtl = DECL_RTL_IF_SET (decl);
11887 /* When generating abstract instances, ignore everything except
11888 constants, symbols living in memory, and symbols living in
11889 fixed registers. */
11890 if (! reload_completed)
11893 && (CONSTANT_P (rtl)
11895 && CONSTANT_P (XEXP (rtl, 0)))
11897 && TREE_CODE (decl) == VAR_DECL
11898 && TREE_STATIC (decl))))
11900 rtl = targetm.delegitimize_address (rtl);
11905 else if (TREE_CODE (decl) == PARM_DECL)
11907 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11909 tree declared_type = TREE_TYPE (decl);
11910 tree passed_type = DECL_ARG_TYPE (decl);
11911 enum machine_mode dmode = TYPE_MODE (declared_type);
11912 enum machine_mode pmode = TYPE_MODE (passed_type);
11914 /* This decl represents a formal parameter which was optimized out.
11915 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11916 all cases where (rtl == NULL_RTX) just below. */
11917 if (dmode == pmode)
11918 rtl = DECL_INCOMING_RTL (decl);
11919 else if (SCALAR_INT_MODE_P (dmode)
11920 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11921 && DECL_INCOMING_RTL (decl))
11923 rtx inc = DECL_INCOMING_RTL (decl);
11926 else if (MEM_P (inc))
11928 if (BYTES_BIG_ENDIAN)
11929 rtl = adjust_address_nv (inc, dmode,
11930 GET_MODE_SIZE (pmode)
11931 - GET_MODE_SIZE (dmode));
11938 /* If the parm was passed in registers, but lives on the stack, then
11939 make a big endian correction if the mode of the type of the
11940 parameter is not the same as the mode of the rtl. */
11941 /* ??? This is the same series of checks that are made in dbxout.c before
11942 we reach the big endian correction code there. It isn't clear if all
11943 of these checks are necessary here, but keeping them all is the safe
11945 else if (MEM_P (rtl)
11946 && XEXP (rtl, 0) != const0_rtx
11947 && ! CONSTANT_P (XEXP (rtl, 0))
11948 /* Not passed in memory. */
11949 && !MEM_P (DECL_INCOMING_RTL (decl))
11950 /* Not passed by invisible reference. */
11951 && (!REG_P (XEXP (rtl, 0))
11952 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11953 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11954 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11955 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11958 /* Big endian correction check. */
11959 && BYTES_BIG_ENDIAN
11960 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11961 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11964 int offset = (UNITS_PER_WORD
11965 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11967 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11968 plus_constant (XEXP (rtl, 0), offset));
11971 else if (TREE_CODE (decl) == VAR_DECL
11974 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11975 && BYTES_BIG_ENDIAN)
11977 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11978 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11980 /* If a variable is declared "register" yet is smaller than
11981 a register, then if we store the variable to memory, it
11982 looks like we're storing a register-sized value, when in
11983 fact we are not. We need to adjust the offset of the
11984 storage location to reflect the actual value's bytes,
11985 else gdb will not be able to display it. */
11987 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11988 plus_constant (XEXP (rtl, 0), rsize-dsize));
11991 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11992 and will have been substituted directly into all expressions that use it.
11993 C does not have such a concept, but C++ and other languages do. */
11994 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11995 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11998 rtl = targetm.delegitimize_address (rtl);
12000 /* If we don't look past the constant pool, we risk emitting a
12001 reference to a constant pool entry that isn't referenced from
12002 code, and thus is not emitted. */
12004 rtl = avoid_constant_pool_reference (rtl);
12009 /* We need to figure out what section we should use as the base for the
12010 address ranges where a given location is valid.
12011 1. If this particular DECL has a section associated with it, use that.
12012 2. If this function has a section associated with it, use that.
12013 3. Otherwise, use the text section.
12014 XXX: If you split a variable across multiple sections, we won't notice. */
12016 static const char *
12017 secname_for_decl (const_tree decl)
12019 const char *secname;
12021 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12023 tree sectree = DECL_SECTION_NAME (decl);
12024 secname = TREE_STRING_POINTER (sectree);
12026 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12028 tree sectree = DECL_SECTION_NAME (current_function_decl);
12029 secname = TREE_STRING_POINTER (sectree);
12031 else if (cfun && in_cold_section_p)
12032 secname = crtl->subsections.cold_section_label;
12034 secname = text_section_label;
12039 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
12040 returned. If so, the decl for the COMMON block is returned, and the
12041 value is the offset into the common block for the symbol. */
12044 fortran_common (tree decl, HOST_WIDE_INT *value)
12046 tree val_expr, cvar;
12047 enum machine_mode mode;
12048 HOST_WIDE_INT bitsize, bitpos;
12050 int volatilep = 0, unsignedp = 0;
12052 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
12053 it does not have a value (the offset into the common area), or if it
12054 is thread local (as opposed to global) then it isn't common, and shouldn't
12055 be handled as such. */
12056 if (TREE_CODE (decl) != VAR_DECL
12057 || !TREE_PUBLIC (decl)
12058 || !TREE_STATIC (decl)
12059 || !DECL_HAS_VALUE_EXPR_P (decl)
12063 val_expr = DECL_VALUE_EXPR (decl);
12064 if (TREE_CODE (val_expr) != COMPONENT_REF)
12067 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
12068 &mode, &unsignedp, &volatilep, true);
12070 if (cvar == NULL_TREE
12071 || TREE_CODE (cvar) != VAR_DECL
12072 || DECL_ARTIFICIAL (cvar)
12073 || !TREE_PUBLIC (cvar))
12077 if (offset != NULL)
12079 if (!host_integerp (offset, 0))
12081 *value = tree_low_cst (offset, 0);
12084 *value += bitpos / BITS_PER_UNIT;
12089 /* Dereference a location expression LOC if DECL is passed by invisible
12092 static dw_loc_descr_ref
12093 loc_by_reference (dw_loc_descr_ref loc, tree decl)
12095 HOST_WIDE_INT size;
12096 enum dwarf_location_atom op;
12101 if ((TREE_CODE (decl) != PARM_DECL
12102 && TREE_CODE (decl) != RESULT_DECL
12103 && TREE_CODE (decl) != VAR_DECL)
12104 || !DECL_BY_REFERENCE (decl))
12107 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12108 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12109 location expression is considered to be address of a memory location,
12110 rather than the register itself. */
12111 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
12112 || loc->dw_loc_opc == DW_OP_regx)
12113 && (loc->dw_loc_next == NULL
12114 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
12115 && loc->dw_loc_next->dw_loc_next == NULL)))
12117 if (loc->dw_loc_opc == DW_OP_regx)
12119 loc->dw_loc_opc = DW_OP_bregx;
12120 loc->dw_loc_oprnd2.v.val_int = 0;
12125 = (enum dwarf_location_atom)
12126 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12127 loc->dw_loc_oprnd1.v.val_int = 0;
12132 size = int_size_in_bytes (TREE_TYPE (decl));
12133 if (size > DWARF2_ADDR_SIZE || size == -1)
12135 else if (size == DWARF2_ADDR_SIZE)
12138 op = DW_OP_deref_size;
12139 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12143 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
12144 data attribute for a variable or a parameter. We generate the
12145 DW_AT_const_value attribute only in those cases where the given variable
12146 or parameter does not have a true "location" either in memory or in a
12147 register. This can happen (for example) when a constant is passed as an
12148 actual argument in a call to an inline function. (It's possible that
12149 these things can crop up in other ways also.) Note that one type of
12150 constant value which can be passed into an inlined function is a constant
12151 pointer. This can happen for example if an actual argument in an inlined
12152 function call evaluates to a compile-time constant address. */
12155 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
12156 enum dwarf_attribute attr)
12159 dw_loc_descr_ref descr;
12160 var_loc_list *loc_list;
12161 struct var_loc_node *node;
12162 if (TREE_CODE (decl) == ERROR_MARK)
12165 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
12166 || TREE_CODE (decl) == RESULT_DECL);
12168 /* See if we possibly have multiple locations for this variable. */
12169 loc_list = lookup_decl_loc (decl);
12171 /* If it truly has multiple locations, the first and last node will
12173 if (loc_list && loc_list->first != loc_list->last)
12175 const char *endname, *secname;
12176 dw_loc_list_ref list;
12178 enum var_init_status initialized;
12180 /* Now that we know what section we are using for a base,
12181 actually construct the list of locations.
12182 The first location information is what is passed to the
12183 function that creates the location list, and the remaining
12184 locations just get added on to that list.
12185 Note that we only know the start address for a location
12186 (IE location changes), so to build the range, we use
12187 the range [current location start, next location start].
12188 This means we have to special case the last node, and generate
12189 a range of [last location start, end of function label]. */
12191 node = loc_list->first;
12192 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12193 secname = secname_for_decl (decl);
12195 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12196 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12198 initialized = VAR_INIT_STATUS_INITIALIZED;
12200 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
12201 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12204 for (; node->next; node = node->next)
12205 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12207 /* The variable has a location between NODE->LABEL and
12208 NODE->NEXT->LABEL. */
12209 enum var_init_status initialized =
12210 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12211 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12212 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12214 add_loc_descr_to_loc_list (&list, descr,
12215 node->label, node->next->label, secname);
12218 /* If the variable has a location at the last label
12219 it keeps its location until the end of function. */
12220 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12222 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12223 enum var_init_status initialized =
12224 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12226 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12227 if (!current_function_decl)
12228 endname = text_end_label;
12231 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12232 current_function_funcdef_no);
12233 endname = ggc_strdup (label_id);
12235 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12237 add_loc_descr_to_loc_list (&list, descr,
12238 node->label, endname, secname);
12241 /* Finally, add the location list to the DIE, and we are done. */
12242 add_AT_loc_list (die, attr, list);
12246 /* Try to get some constant RTL for this decl, and use that as the value of
12249 rtl = rtl_for_decl_location (decl);
12250 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
12252 add_const_value_attribute (die, rtl);
12256 /* If we have tried to generate the location otherwise, and it
12257 didn't work out (we wouldn't be here if we did), and we have a one entry
12258 location list, try generating a location from that. */
12259 if (loc_list && loc_list->first)
12261 enum var_init_status status;
12262 node = loc_list->first;
12263 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12264 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
12267 descr = loc_by_reference (descr, decl);
12268 add_AT_location_description (die, attr, descr);
12273 /* We couldn't get any rtl, so try directly generating the location
12274 description from the tree. */
12275 descr = loc_descriptor_from_tree (decl);
12278 descr = loc_by_reference (descr, decl);
12279 add_AT_location_description (die, attr, descr);
12282 /* None of that worked, so it must not really have a location;
12283 try adding a constant value attribute from the DECL_INITIAL. */
12284 tree_add_const_value_attribute (die, decl);
12287 /* Add VARIABLE and DIE into deferred locations list. */
12290 defer_location (tree variable, dw_die_ref die)
12292 deferred_locations entry;
12293 entry.variable = variable;
12295 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
12298 /* Helper function for tree_add_const_value_attribute. Natively encode
12299 initializer INIT into an array. Return true if successful. */
12302 native_encode_initializer (tree init, unsigned char *array, int size)
12306 if (init == NULL_TREE)
12310 switch (TREE_CODE (init))
12313 type = TREE_TYPE (init);
12314 if (TREE_CODE (type) == ARRAY_TYPE)
12316 tree enttype = TREE_TYPE (type);
12317 enum machine_mode mode = TYPE_MODE (enttype);
12319 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
12321 if (int_size_in_bytes (type) != size)
12323 if (size > TREE_STRING_LENGTH (init))
12325 memcpy (array, TREE_STRING_POINTER (init),
12326 TREE_STRING_LENGTH (init));
12327 memset (array + TREE_STRING_LENGTH (init),
12328 '\0', size - TREE_STRING_LENGTH (init));
12331 memcpy (array, TREE_STRING_POINTER (init), size);
12336 type = TREE_TYPE (init);
12337 if (int_size_in_bytes (type) != size)
12339 if (TREE_CODE (type) == ARRAY_TYPE)
12341 HOST_WIDE_INT min_index;
12342 unsigned HOST_WIDE_INT cnt;
12343 int curpos = 0, fieldsize;
12344 constructor_elt *ce;
12346 if (TYPE_DOMAIN (type) == NULL_TREE
12347 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
12350 fieldsize = int_size_in_bytes (TREE_TYPE (type));
12351 if (fieldsize <= 0)
12354 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
12355 memset (array, '\0', size);
12357 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12360 tree val = ce->value;
12361 tree index = ce->index;
12363 if (index && TREE_CODE (index) == RANGE_EXPR)
12364 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
12367 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
12372 if (!native_encode_initializer (val, array + pos, fieldsize))
12375 curpos = pos + fieldsize;
12376 if (index && TREE_CODE (index) == RANGE_EXPR)
12378 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
12379 - tree_low_cst (TREE_OPERAND (index, 0), 0);
12383 memcpy (array + curpos, array + pos, fieldsize);
12384 curpos += fieldsize;
12387 gcc_assert (curpos <= size);
12391 else if (TREE_CODE (type) == RECORD_TYPE
12392 || TREE_CODE (type) == UNION_TYPE)
12394 tree field = NULL_TREE;
12395 unsigned HOST_WIDE_INT cnt;
12396 constructor_elt *ce;
12398 if (int_size_in_bytes (type) != size)
12401 if (TREE_CODE (type) == RECORD_TYPE)
12402 field = TYPE_FIELDS (type);
12405 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12406 cnt++, field = field ? TREE_CHAIN (field) : 0)
12408 tree val = ce->value;
12409 int pos, fieldsize;
12411 if (ce->index != 0)
12417 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12420 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12421 && TYPE_DOMAIN (TREE_TYPE (field))
12422 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12424 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12425 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12427 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12428 pos = int_byte_position (field);
12429 gcc_assert (pos + fieldsize <= size);
12431 && !native_encode_initializer (val, array + pos, fieldsize))
12437 case VIEW_CONVERT_EXPR:
12438 case NON_LVALUE_EXPR:
12439 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12441 return native_encode_expr (init, array, size) == size;
12445 /* If we don't have a copy of this variable in memory for some reason (such
12446 as a C++ member constant that doesn't have an out-of-line definition),
12447 we should tell the debugger about the constant value. */
12450 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12453 tree type = TREE_TYPE (decl);
12456 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12459 init = DECL_INITIAL (decl);
12460 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12465 rtl = rtl_for_decl_init (init, type);
12467 add_const_value_attribute (var_die, rtl);
12468 /* If the host and target are sane, try harder. */
12469 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12470 && initializer_constant_valid_p (init, type))
12472 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12473 if (size > 0 && (int) size == size)
12475 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12477 if (native_encode_initializer (init, array, size))
12478 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12483 /* Convert the CFI instructions for the current function into a
12484 location list. This is used for DW_AT_frame_base when we targeting
12485 a dwarf2 consumer that does not support the dwarf3
12486 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12489 static dw_loc_list_ref
12490 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12493 dw_loc_list_ref list, *list_tail;
12495 dw_cfa_location last_cfa, next_cfa;
12496 const char *start_label, *last_label, *section;
12497 dw_cfa_location remember;
12499 fde = current_fde ();
12500 gcc_assert (fde != NULL);
12502 section = secname_for_decl (current_function_decl);
12506 memset (&next_cfa, 0, sizeof (next_cfa));
12507 next_cfa.reg = INVALID_REGNUM;
12508 remember = next_cfa;
12510 start_label = fde->dw_fde_begin;
12512 /* ??? Bald assumption that the CIE opcode list does not contain
12513 advance opcodes. */
12514 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12515 lookup_cfa_1 (cfi, &next_cfa, &remember);
12517 last_cfa = next_cfa;
12518 last_label = start_label;
12520 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12521 switch (cfi->dw_cfi_opc)
12523 case DW_CFA_set_loc:
12524 case DW_CFA_advance_loc1:
12525 case DW_CFA_advance_loc2:
12526 case DW_CFA_advance_loc4:
12527 if (!cfa_equal_p (&last_cfa, &next_cfa))
12529 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12530 start_label, last_label, section,
12533 list_tail = &(*list_tail)->dw_loc_next;
12534 last_cfa = next_cfa;
12535 start_label = last_label;
12537 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12540 case DW_CFA_advance_loc:
12541 /* The encoding is complex enough that we should never emit this. */
12542 gcc_unreachable ();
12545 lookup_cfa_1 (cfi, &next_cfa, &remember);
12549 if (!cfa_equal_p (&last_cfa, &next_cfa))
12551 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12552 start_label, last_label, section,
12554 list_tail = &(*list_tail)->dw_loc_next;
12555 start_label = last_label;
12557 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12558 start_label, fde->dw_fde_end, section,
12564 /* Compute a displacement from the "steady-state frame pointer" to the
12565 frame base (often the same as the CFA), and store it in
12566 frame_pointer_fb_offset. OFFSET is added to the displacement
12567 before the latter is negated. */
12570 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12574 #ifdef FRAME_POINTER_CFA_OFFSET
12575 reg = frame_pointer_rtx;
12576 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12578 reg = arg_pointer_rtx;
12579 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12582 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12583 if (GET_CODE (elim) == PLUS)
12585 offset += INTVAL (XEXP (elim, 1));
12586 elim = XEXP (elim, 0);
12589 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12590 && (elim == hard_frame_pointer_rtx
12591 || elim == stack_pointer_rtx))
12592 || elim == (frame_pointer_needed
12593 ? hard_frame_pointer_rtx
12594 : stack_pointer_rtx));
12596 frame_pointer_fb_offset = -offset;
12599 /* Generate a DW_AT_name attribute given some string value to be included as
12600 the value of the attribute. */
12603 add_name_attribute (dw_die_ref die, const char *name_string)
12605 if (name_string != NULL && *name_string != 0)
12607 if (demangle_name_func)
12608 name_string = (*demangle_name_func) (name_string);
12610 add_AT_string (die, DW_AT_name, name_string);
12614 /* Generate a DW_AT_comp_dir attribute for DIE. */
12617 add_comp_dir_attribute (dw_die_ref die)
12619 const char *wd = get_src_pwd ();
12621 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12624 /* Given a tree node describing an array bound (either lower or upper) output
12625 a representation for that bound. */
12628 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12630 switch (TREE_CODE (bound))
12635 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12637 if (! host_integerp (bound, 0)
12638 || (bound_attr == DW_AT_lower_bound
12639 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12640 || (is_fortran () && integer_onep (bound)))))
12641 /* Use the default. */
12644 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12648 case VIEW_CONVERT_EXPR:
12649 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
12659 dw_die_ref decl_die = lookup_decl_die (bound);
12660 dw_loc_descr_ref loc;
12662 /* ??? Can this happen, or should the variable have been bound
12663 first? Probably it can, since I imagine that we try to create
12664 the types of parameters in the order in which they exist in
12665 the list, and won't have created a forward reference to a
12666 later parameter. */
12667 if (decl_die != NULL)
12668 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12671 loc = loc_descriptor_from_tree_1 (bound, 0);
12672 add_AT_location_description (subrange_die, bound_attr, loc);
12679 /* Otherwise try to create a stack operation procedure to
12680 evaluate the value of the array bound. */
12682 dw_die_ref ctx, decl_die;
12683 dw_loc_descr_ref loc;
12685 loc = loc_descriptor_from_tree (bound);
12689 if (current_function_decl == 0)
12690 ctx = comp_unit_die;
12692 ctx = lookup_decl_die (current_function_decl);
12694 decl_die = new_die (DW_TAG_variable, ctx, bound);
12695 add_AT_flag (decl_die, DW_AT_artificial, 1);
12696 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12697 add_AT_loc (decl_die, DW_AT_location, loc);
12699 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12705 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12706 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12707 Note that the block of subscript information for an array type also
12708 includes information about the element type of the given array type. */
12711 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12713 unsigned dimension_number;
12715 dw_die_ref subrange_die;
12717 for (dimension_number = 0;
12718 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12719 type = TREE_TYPE (type), dimension_number++)
12721 tree domain = TYPE_DOMAIN (type);
12723 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12726 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12727 and (in GNU C only) variable bounds. Handle all three forms
12729 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12732 /* We have an array type with specified bounds. */
12733 lower = TYPE_MIN_VALUE (domain);
12734 upper = TYPE_MAX_VALUE (domain);
12736 /* Define the index type. */
12737 if (TREE_TYPE (domain))
12739 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12740 TREE_TYPE field. We can't emit debug info for this
12741 because it is an unnamed integral type. */
12742 if (TREE_CODE (domain) == INTEGER_TYPE
12743 && TYPE_NAME (domain) == NULL_TREE
12744 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12745 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12748 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12752 /* ??? If upper is NULL, the array has unspecified length,
12753 but it does have a lower bound. This happens with Fortran
12755 Since the debugger is definitely going to need to know N
12756 to produce useful results, go ahead and output the lower
12757 bound solo, and hope the debugger can cope. */
12759 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12761 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12764 /* Otherwise we have an array type with an unspecified length. The
12765 DWARF-2 spec does not say how to handle this; let's just leave out the
12771 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12775 switch (TREE_CODE (tree_node))
12780 case ENUMERAL_TYPE:
12783 case QUAL_UNION_TYPE:
12784 size = int_size_in_bytes (tree_node);
12787 /* For a data member of a struct or union, the DW_AT_byte_size is
12788 generally given as the number of bytes normally allocated for an
12789 object of the *declared* type of the member itself. This is true
12790 even for bit-fields. */
12791 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12794 gcc_unreachable ();
12797 /* Note that `size' might be -1 when we get to this point. If it is, that
12798 indicates that the byte size of the entity in question is variable. We
12799 have no good way of expressing this fact in Dwarf at the present time,
12800 so just let the -1 pass on through. */
12801 add_AT_unsigned (die, DW_AT_byte_size, size);
12804 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12805 which specifies the distance in bits from the highest order bit of the
12806 "containing object" for the bit-field to the highest order bit of the
12809 For any given bit-field, the "containing object" is a hypothetical object
12810 (of some integral or enum type) within which the given bit-field lives. The
12811 type of this hypothetical "containing object" is always the same as the
12812 declared type of the individual bit-field itself. The determination of the
12813 exact location of the "containing object" for a bit-field is rather
12814 complicated. It's handled by the `field_byte_offset' function (above).
12816 Note that it is the size (in bytes) of the hypothetical "containing object"
12817 which will be given in the DW_AT_byte_size attribute for this bit-field.
12818 (See `byte_size_attribute' above). */
12821 add_bit_offset_attribute (dw_die_ref die, tree decl)
12823 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12824 tree type = DECL_BIT_FIELD_TYPE (decl);
12825 HOST_WIDE_INT bitpos_int;
12826 HOST_WIDE_INT highest_order_object_bit_offset;
12827 HOST_WIDE_INT highest_order_field_bit_offset;
12828 HOST_WIDE_INT unsigned bit_offset;
12830 /* Must be a field and a bit field. */
12831 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12833 /* We can't yet handle bit-fields whose offsets are variable, so if we
12834 encounter such things, just return without generating any attribute
12835 whatsoever. Likewise for variable or too large size. */
12836 if (! host_integerp (bit_position (decl), 0)
12837 || ! host_integerp (DECL_SIZE (decl), 1))
12840 bitpos_int = int_bit_position (decl);
12842 /* Note that the bit offset is always the distance (in bits) from the
12843 highest-order bit of the "containing object" to the highest-order bit of
12844 the bit-field itself. Since the "high-order end" of any object or field
12845 is different on big-endian and little-endian machines, the computation
12846 below must take account of these differences. */
12847 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12848 highest_order_field_bit_offset = bitpos_int;
12850 if (! BYTES_BIG_ENDIAN)
12852 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12853 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12857 = (! BYTES_BIG_ENDIAN
12858 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12859 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12861 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12864 /* For a FIELD_DECL node which represents a bit field, output an attribute
12865 which specifies the length in bits of the given field. */
12868 add_bit_size_attribute (dw_die_ref die, tree decl)
12870 /* Must be a field and a bit field. */
12871 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12872 && DECL_BIT_FIELD_TYPE (decl));
12874 if (host_integerp (DECL_SIZE (decl), 1))
12875 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12878 /* If the compiled language is ANSI C, then add a 'prototyped'
12879 attribute, if arg types are given for the parameters of a function. */
12882 add_prototyped_attribute (dw_die_ref die, tree func_type)
12884 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12885 && TYPE_ARG_TYPES (func_type) != NULL)
12886 add_AT_flag (die, DW_AT_prototyped, 1);
12889 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12890 by looking in either the type declaration or object declaration
12893 static inline dw_die_ref
12894 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12896 dw_die_ref origin_die = NULL;
12898 if (TREE_CODE (origin) != FUNCTION_DECL)
12900 /* We may have gotten separated from the block for the inlined
12901 function, if we're in an exception handler or some such; make
12902 sure that the abstract function has been written out.
12904 Doing this for nested functions is wrong, however; functions are
12905 distinct units, and our context might not even be inline. */
12909 fn = TYPE_STUB_DECL (fn);
12911 fn = decl_function_context (fn);
12913 dwarf2out_abstract_function (fn);
12916 if (DECL_P (origin))
12917 origin_die = lookup_decl_die (origin);
12918 else if (TYPE_P (origin))
12919 origin_die = lookup_type_die (origin);
12921 /* XXX: Functions that are never lowered don't always have correct block
12922 trees (in the case of java, they simply have no block tree, in some other
12923 languages). For these functions, there is nothing we can really do to
12924 output correct debug info for inlined functions in all cases. Rather
12925 than die, we'll just produce deficient debug info now, in that we will
12926 have variables without a proper abstract origin. In the future, when all
12927 functions are lowered, we should re-add a gcc_assert (origin_die)
12931 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12935 /* We do not currently support the pure_virtual attribute. */
12938 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12940 if (DECL_VINDEX (func_decl))
12942 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12944 if (host_integerp (DECL_VINDEX (func_decl), 0))
12945 add_AT_loc (die, DW_AT_vtable_elem_location,
12946 new_loc_descr (DW_OP_constu,
12947 tree_low_cst (DECL_VINDEX (func_decl), 0),
12950 /* GNU extension: Record what type this method came from originally. */
12951 if (debug_info_level > DINFO_LEVEL_TERSE)
12952 add_AT_die_ref (die, DW_AT_containing_type,
12953 lookup_type_die (DECL_CONTEXT (func_decl)));
12957 /* Add source coordinate attributes for the given decl. */
12960 add_src_coords_attributes (dw_die_ref die, tree decl)
12962 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12964 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12965 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12968 /* Add a DW_AT_name attribute and source coordinate attribute for the
12969 given decl, but only if it actually has a name. */
12972 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12976 decl_name = DECL_NAME (decl);
12977 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12979 add_name_attribute (die, dwarf2_name (decl, 0));
12980 if (! DECL_ARTIFICIAL (decl))
12981 add_src_coords_attributes (die, decl);
12983 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12984 && TREE_PUBLIC (decl)
12985 && !DECL_ABSTRACT (decl)
12986 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12989 /* Defer until we have an assembler name set. */
12990 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
12992 limbo_die_node *asm_name;
12994 asm_name = GGC_CNEW (limbo_die_node);
12995 asm_name->die = die;
12996 asm_name->created_for = decl;
12997 asm_name->next = deferred_asm_name;
12998 deferred_asm_name = asm_name;
13000 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
13001 add_AT_string (die, DW_AT_MIPS_linkage_name,
13002 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
13006 #ifdef VMS_DEBUGGING_INFO
13007 /* Get the function's name, as described by its RTL. This may be different
13008 from the DECL_NAME name used in the source file. */
13009 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
13011 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
13012 XEXP (DECL_RTL (decl), 0));
13013 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
13018 /* Push a new declaration scope. */
13021 push_decl_scope (tree scope)
13023 VEC_safe_push (tree, gc, decl_scope_table, scope);
13026 /* Pop a declaration scope. */
13029 pop_decl_scope (void)
13031 VEC_pop (tree, decl_scope_table);
13034 /* Return the DIE for the scope that immediately contains this type.
13035 Non-named types get global scope. Named types nested in other
13036 types get their containing scope if it's open, or global scope
13037 otherwise. All other types (i.e. function-local named types) get
13038 the current active scope. */
13041 scope_die_for (tree t, dw_die_ref context_die)
13043 dw_die_ref scope_die = NULL;
13044 tree containing_scope;
13047 /* Non-types always go in the current scope. */
13048 gcc_assert (TYPE_P (t));
13050 containing_scope = TYPE_CONTEXT (t);
13052 /* Use the containing namespace if it was passed in (for a declaration). */
13053 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
13055 if (context_die == lookup_decl_die (containing_scope))
13058 containing_scope = NULL_TREE;
13061 /* Ignore function type "scopes" from the C frontend. They mean that
13062 a tagged type is local to a parmlist of a function declarator, but
13063 that isn't useful to DWARF. */
13064 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
13065 containing_scope = NULL_TREE;
13067 if (containing_scope == NULL_TREE)
13068 scope_die = comp_unit_die;
13069 else if (TYPE_P (containing_scope))
13071 /* For types, we can just look up the appropriate DIE. But
13072 first we check to see if we're in the middle of emitting it
13073 so we know where the new DIE should go. */
13074 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
13075 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
13080 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
13081 || TREE_ASM_WRITTEN (containing_scope));
13083 /* If none of the current dies are suitable, we get file scope. */
13084 scope_die = comp_unit_die;
13087 scope_die = lookup_type_die (containing_scope);
13090 scope_die = context_die;
13095 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
13098 local_scope_p (dw_die_ref context_die)
13100 for (; context_die; context_die = context_die->die_parent)
13101 if (context_die->die_tag == DW_TAG_inlined_subroutine
13102 || context_die->die_tag == DW_TAG_subprogram)
13108 /* Returns nonzero if CONTEXT_DIE is a class. */
13111 class_scope_p (dw_die_ref context_die)
13113 return (context_die
13114 && (context_die->die_tag == DW_TAG_structure_type
13115 || context_die->die_tag == DW_TAG_class_type
13116 || context_die->die_tag == DW_TAG_interface_type
13117 || context_die->die_tag == DW_TAG_union_type));
13120 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
13121 whether or not to treat a DIE in this context as a declaration. */
13124 class_or_namespace_scope_p (dw_die_ref context_die)
13126 return (class_scope_p (context_die)
13127 || (context_die && context_die->die_tag == DW_TAG_namespace));
13130 /* Many forms of DIEs require a "type description" attribute. This
13131 routine locates the proper "type descriptor" die for the type given
13132 by 'type', and adds a DW_AT_type attribute below the given die. */
13135 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
13136 int decl_volatile, dw_die_ref context_die)
13138 enum tree_code code = TREE_CODE (type);
13139 dw_die_ref type_die = NULL;
13141 /* ??? If this type is an unnamed subrange type of an integral, floating-point
13142 or fixed-point type, use the inner type. This is because we have no
13143 support for unnamed types in base_type_die. This can happen if this is
13144 an Ada subrange type. Correct solution is emit a subrange type die. */
13145 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
13146 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
13147 type = TREE_TYPE (type), code = TREE_CODE (type);
13149 if (code == ERROR_MARK
13150 /* Handle a special case. For functions whose return type is void, we
13151 generate *no* type attribute. (Note that no object may have type
13152 `void', so this only applies to function return types). */
13153 || code == VOID_TYPE)
13156 type_die = modified_type_die (type,
13157 decl_const || TYPE_READONLY (type),
13158 decl_volatile || TYPE_VOLATILE (type),
13161 if (type_die != NULL)
13162 add_AT_die_ref (object_die, DW_AT_type, type_die);
13165 /* Given an object die, add the calling convention attribute for the
13166 function call type. */
13168 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
13170 enum dwarf_calling_convention value = DW_CC_normal;
13172 value = ((enum dwarf_calling_convention)
13173 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
13175 /* DWARF doesn't provide a way to identify a program's source-level
13176 entry point. DW_AT_calling_convention attributes are only meant
13177 to describe functions' calling conventions. However, lacking a
13178 better way to signal the Fortran main program, we use this for the
13179 time being, following existing custom. */
13181 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
13182 value = DW_CC_program;
13184 /* Only add the attribute if the backend requests it, and
13185 is not DW_CC_normal. */
13186 if (value && (value != DW_CC_normal))
13187 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
13190 /* Given a tree pointer to a struct, class, union, or enum type node, return
13191 a pointer to the (string) tag name for the given type, or zero if the type
13192 was declared without a tag. */
13194 static const char *
13195 type_tag (const_tree type)
13197 const char *name = 0;
13199 if (TYPE_NAME (type) != 0)
13203 /* Find the IDENTIFIER_NODE for the type name. */
13204 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
13205 t = TYPE_NAME (type);
13207 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
13208 a TYPE_DECL node, regardless of whether or not a `typedef' was
13210 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13211 && ! DECL_IGNORED_P (TYPE_NAME (type)))
13213 /* We want to be extra verbose. Don't call dwarf_name if
13214 DECL_NAME isn't set. The default hook for decl_printable_name
13215 doesn't like that, and in this context it's correct to return
13216 0, instead of "<anonymous>" or the like. */
13217 if (DECL_NAME (TYPE_NAME (type)))
13218 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
13221 /* Now get the name as a string, or invent one. */
13222 if (!name && t != 0)
13223 name = IDENTIFIER_POINTER (t);
13226 return (name == 0 || *name == '\0') ? 0 : name;
13229 /* Return the type associated with a data member, make a special check
13230 for bit field types. */
13233 member_declared_type (const_tree member)
13235 return (DECL_BIT_FIELD_TYPE (member)
13236 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
13239 /* Get the decl's label, as described by its RTL. This may be different
13240 from the DECL_NAME name used in the source file. */
13243 static const char *
13244 decl_start_label (tree decl)
13247 const char *fnname;
13249 x = DECL_RTL (decl);
13250 gcc_assert (MEM_P (x));
13253 gcc_assert (GET_CODE (x) == SYMBOL_REF);
13255 fnname = XSTR (x, 0);
13260 /* These routines generate the internal representation of the DIE's for
13261 the compilation unit. Debugging information is collected by walking
13262 the declaration trees passed in from dwarf2out_decl(). */
13265 gen_array_type_die (tree type, dw_die_ref context_die)
13267 dw_die_ref scope_die = scope_die_for (type, context_die);
13268 dw_die_ref array_die;
13270 /* GNU compilers represent multidimensional array types as sequences of one
13271 dimensional array types whose element types are themselves array types.
13272 We sometimes squish that down to a single array_type DIE with multiple
13273 subscripts in the Dwarf debugging info. The draft Dwarf specification
13274 say that we are allowed to do this kind of compression in C, because
13275 there is no difference between an array of arrays and a multidimensional
13276 array. We don't do this for Ada to remain as close as possible to the
13277 actual representation, which is especially important against the language
13278 flexibilty wrt arrays of variable size. */
13280 bool collapse_nested_arrays = !is_ada ();
13283 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
13284 DW_TAG_string_type doesn't have DW_AT_type attribute). */
13285 if (TYPE_STRING_FLAG (type)
13286 && TREE_CODE (type) == ARRAY_TYPE
13288 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
13290 HOST_WIDE_INT size;
13292 array_die = new_die (DW_TAG_string_type, scope_die, type);
13293 add_name_attribute (array_die, type_tag (type));
13294 equate_type_number_to_die (type, array_die);
13295 size = int_size_in_bytes (type);
13297 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13298 else if (TYPE_DOMAIN (type) != NULL_TREE
13299 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
13300 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
13302 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
13303 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
13305 size = int_size_in_bytes (TREE_TYPE (szdecl));
13306 if (loc && size > 0)
13308 add_AT_loc (array_die, DW_AT_string_length, loc);
13309 if (size != DWARF2_ADDR_SIZE)
13310 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13316 /* ??? The SGI dwarf reader fails for array of array of enum types
13317 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
13318 array type comes before the outer array type. We thus call gen_type_die
13319 before we new_die and must prevent nested array types collapsing for this
13322 #ifdef MIPS_DEBUGGING_INFO
13323 gen_type_die (TREE_TYPE (type), context_die);
13324 collapse_nested_arrays = false;
13327 array_die = new_die (DW_TAG_array_type, scope_die, type);
13328 add_name_attribute (array_die, type_tag (type));
13329 equate_type_number_to_die (type, array_die);
13331 if (TREE_CODE (type) == VECTOR_TYPE)
13333 /* The frontend feeds us a representation for the vector as a struct
13334 containing an array. Pull out the array type. */
13335 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
13336 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
13339 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13341 && TREE_CODE (type) == ARRAY_TYPE
13342 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
13343 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
13344 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13347 /* We default the array ordering. SDB will probably do
13348 the right things even if DW_AT_ordering is not present. It's not even
13349 an issue until we start to get into multidimensional arrays anyway. If
13350 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
13351 then we'll have to put the DW_AT_ordering attribute back in. (But if
13352 and when we find out that we need to put these in, we will only do so
13353 for multidimensional arrays. */
13354 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
13357 #ifdef MIPS_DEBUGGING_INFO
13358 /* The SGI compilers handle arrays of unknown bound by setting
13359 AT_declaration and not emitting any subrange DIEs. */
13360 if (! TYPE_DOMAIN (type))
13361 add_AT_flag (array_die, DW_AT_declaration, 1);
13364 add_subscript_info (array_die, type, collapse_nested_arrays);
13366 /* Add representation of the type of the elements of this array type and
13367 emit the corresponding DIE if we haven't done it already. */
13368 element_type = TREE_TYPE (type);
13369 if (collapse_nested_arrays)
13370 while (TREE_CODE (element_type) == ARRAY_TYPE)
13372 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
13374 element_type = TREE_TYPE (element_type);
13377 #ifndef MIPS_DEBUGGING_INFO
13378 gen_type_die (element_type, context_die);
13381 add_type_attribute (array_die, element_type, 0, 0, context_die);
13383 if (get_AT (array_die, DW_AT_name))
13384 add_pubtype (type, array_die);
13387 static dw_loc_descr_ref
13388 descr_info_loc (tree val, tree base_decl)
13390 HOST_WIDE_INT size;
13391 dw_loc_descr_ref loc, loc2;
13392 enum dwarf_location_atom op;
13394 if (val == base_decl)
13395 return new_loc_descr (DW_OP_push_object_address, 0, 0);
13397 switch (TREE_CODE (val))
13400 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13402 return loc_descriptor_from_tree_1 (val, 0);
13404 if (host_integerp (val, 0))
13405 return int_loc_descriptor (tree_low_cst (val, 0));
13408 size = int_size_in_bytes (TREE_TYPE (val));
13411 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13414 if (size == DWARF2_ADDR_SIZE)
13415 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
13417 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
13419 case POINTER_PLUS_EXPR:
13421 if (host_integerp (TREE_OPERAND (val, 1), 1)
13422 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
13425 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13428 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
13434 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13437 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13440 add_loc_descr (&loc, loc2);
13441 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13463 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13464 tree val, tree base_decl)
13466 dw_loc_descr_ref loc;
13468 if (host_integerp (val, 0))
13470 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13474 loc = descr_info_loc (val, base_decl);
13478 add_AT_loc (die, attr, loc);
13481 /* This routine generates DIE for array with hidden descriptor, details
13482 are filled into *info by a langhook. */
13485 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13486 dw_die_ref context_die)
13488 dw_die_ref scope_die = scope_die_for (type, context_die);
13489 dw_die_ref array_die;
13492 array_die = new_die (DW_TAG_array_type, scope_die, type);
13493 add_name_attribute (array_die, type_tag (type));
13494 equate_type_number_to_die (type, array_die);
13496 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13498 && info->ndimensions >= 2)
13499 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13501 if (info->data_location)
13502 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13504 if (info->associated)
13505 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13507 if (info->allocated)
13508 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13511 for (dim = 0; dim < info->ndimensions; dim++)
13513 dw_die_ref subrange_die
13514 = new_die (DW_TAG_subrange_type, array_die, NULL);
13516 if (info->dimen[dim].lower_bound)
13518 /* If it is the default value, omit it. */
13519 if ((is_c_family () || is_java ())
13520 && integer_zerop (info->dimen[dim].lower_bound))
13522 else if (is_fortran ()
13523 && integer_onep (info->dimen[dim].lower_bound))
13526 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13527 info->dimen[dim].lower_bound,
13530 if (info->dimen[dim].upper_bound)
13531 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13532 info->dimen[dim].upper_bound,
13534 if (info->dimen[dim].stride)
13535 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13536 info->dimen[dim].stride,
13540 gen_type_die (info->element_type, context_die);
13541 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13543 if (get_AT (array_die, DW_AT_name))
13544 add_pubtype (type, array_die);
13549 gen_entry_point_die (tree decl, dw_die_ref context_die)
13551 tree origin = decl_ultimate_origin (decl);
13552 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13554 if (origin != NULL)
13555 add_abstract_origin_attribute (decl_die, origin);
13558 add_name_and_src_coords_attributes (decl_die, decl);
13559 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13560 0, 0, context_die);
13563 if (DECL_ABSTRACT (decl))
13564 equate_decl_number_to_die (decl, decl_die);
13566 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13570 /* Walk through the list of incomplete types again, trying once more to
13571 emit full debugging info for them. */
13574 retry_incomplete_types (void)
13578 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13579 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13582 /* Determine what tag to use for a record type. */
13584 static enum dwarf_tag
13585 record_type_tag (tree type)
13587 if (! lang_hooks.types.classify_record)
13588 return DW_TAG_structure_type;
13590 switch (lang_hooks.types.classify_record (type))
13592 case RECORD_IS_STRUCT:
13593 return DW_TAG_structure_type;
13595 case RECORD_IS_CLASS:
13596 return DW_TAG_class_type;
13598 case RECORD_IS_INTERFACE:
13599 return DW_TAG_interface_type;
13602 gcc_unreachable ();
13606 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13607 include all of the information about the enumeration values also. Each
13608 enumerated type name/value is listed as a child of the enumerated type
13612 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13614 dw_die_ref type_die = lookup_type_die (type);
13616 if (type_die == NULL)
13618 type_die = new_die (DW_TAG_enumeration_type,
13619 scope_die_for (type, context_die), type);
13620 equate_type_number_to_die (type, type_die);
13621 add_name_attribute (type_die, type_tag (type));
13623 else if (! TYPE_SIZE (type))
13626 remove_AT (type_die, DW_AT_declaration);
13628 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13629 given enum type is incomplete, do not generate the DW_AT_byte_size
13630 attribute or the DW_AT_element_list attribute. */
13631 if (TYPE_SIZE (type))
13635 TREE_ASM_WRITTEN (type) = 1;
13636 add_byte_size_attribute (type_die, type);
13637 if (TYPE_STUB_DECL (type) != NULL_TREE)
13638 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13640 /* If the first reference to this type was as the return type of an
13641 inline function, then it may not have a parent. Fix this now. */
13642 if (type_die->die_parent == NULL)
13643 add_child_die (scope_die_for (type, context_die), type_die);
13645 for (link = TYPE_VALUES (type);
13646 link != NULL; link = TREE_CHAIN (link))
13648 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13649 tree value = TREE_VALUE (link);
13651 add_name_attribute (enum_die,
13652 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
13654 if (TREE_CODE (value) == CONST_DECL)
13655 value = DECL_INITIAL (value);
13657 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
13658 /* DWARF2 does not provide a way of indicating whether or
13659 not enumeration constants are signed or unsigned. GDB
13660 always assumes the values are signed, so we output all
13661 values as if they were signed. That means that
13662 enumeration constants with very large unsigned values
13663 will appear to have negative values in the debugger. */
13664 add_AT_int (enum_die, DW_AT_const_value,
13665 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
13669 add_AT_flag (type_die, DW_AT_declaration, 1);
13671 if (get_AT (type_die, DW_AT_name))
13672 add_pubtype (type, type_die);
13677 /* Generate a DIE to represent either a real live formal parameter decl or to
13678 represent just the type of some formal parameter position in some function
13681 Note that this routine is a bit unusual because its argument may be a
13682 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13683 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13684 node. If it's the former then this function is being called to output a
13685 DIE to represent a formal parameter object (or some inlining thereof). If
13686 it's the latter, then this function is only being called to output a
13687 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13688 argument type of some subprogram type. */
13691 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
13693 tree node_or_origin = node ? node : origin;
13694 dw_die_ref parm_die
13695 = new_die (DW_TAG_formal_parameter, context_die, node);
13697 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
13699 case tcc_declaration:
13701 origin = decl_ultimate_origin (node);
13702 if (origin != NULL)
13703 add_abstract_origin_attribute (parm_die, origin);
13706 tree type = TREE_TYPE (node);
13707 add_name_and_src_coords_attributes (parm_die, node);
13708 if (DECL_BY_REFERENCE (node))
13709 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13712 add_type_attribute (parm_die, type,
13713 TREE_READONLY (node),
13714 TREE_THIS_VOLATILE (node),
13716 if (DECL_ARTIFICIAL (node))
13717 add_AT_flag (parm_die, DW_AT_artificial, 1);
13721 equate_decl_number_to_die (node, parm_die);
13722 if (! DECL_ABSTRACT (node_or_origin))
13723 add_location_or_const_value_attribute (parm_die, node_or_origin,
13729 /* We were called with some kind of a ..._TYPE node. */
13730 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
13734 gcc_unreachable ();
13740 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13741 at the end of an (ANSI prototyped) formal parameters list. */
13744 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13746 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13749 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13750 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13751 parameters as specified in some function type specification (except for
13752 those which appear as part of a function *definition*). */
13755 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13758 tree formal_type = NULL;
13759 tree first_parm_type;
13762 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13764 arg = DECL_ARGUMENTS (function_or_method_type);
13765 function_or_method_type = TREE_TYPE (function_or_method_type);
13770 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13772 /* Make our first pass over the list of formal parameter types and output a
13773 DW_TAG_formal_parameter DIE for each one. */
13774 for (link = first_parm_type; link; )
13776 dw_die_ref parm_die;
13778 formal_type = TREE_VALUE (link);
13779 if (formal_type == void_type_node)
13782 /* Output a (nameless) DIE to represent the formal parameter itself. */
13783 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
13784 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13785 && link == first_parm_type)
13786 || (arg && DECL_ARTIFICIAL (arg)))
13787 add_AT_flag (parm_die, DW_AT_artificial, 1);
13789 link = TREE_CHAIN (link);
13791 arg = TREE_CHAIN (arg);
13794 /* If this function type has an ellipsis, add a
13795 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13796 if (formal_type != void_type_node)
13797 gen_unspecified_parameters_die (function_or_method_type, context_die);
13799 /* Make our second (and final) pass over the list of formal parameter types
13800 and output DIEs to represent those types (as necessary). */
13801 for (link = TYPE_ARG_TYPES (function_or_method_type);
13802 link && TREE_VALUE (link);
13803 link = TREE_CHAIN (link))
13804 gen_type_die (TREE_VALUE (link), context_die);
13807 /* We want to generate the DIE for TYPE so that we can generate the
13808 die for MEMBER, which has been defined; we will need to refer back
13809 to the member declaration nested within TYPE. If we're trying to
13810 generate minimal debug info for TYPE, processing TYPE won't do the
13811 trick; we need to attach the member declaration by hand. */
13814 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13816 gen_type_die (type, context_die);
13818 /* If we're trying to avoid duplicate debug info, we may not have
13819 emitted the member decl for this function. Emit it now. */
13820 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13821 && ! lookup_decl_die (member))
13823 dw_die_ref type_die;
13824 gcc_assert (!decl_ultimate_origin (member));
13826 push_decl_scope (type);
13827 type_die = lookup_type_die (type);
13828 if (TREE_CODE (member) == FUNCTION_DECL)
13829 gen_subprogram_die (member, type_die);
13830 else if (TREE_CODE (member) == FIELD_DECL)
13832 /* Ignore the nameless fields that are used to skip bits but handle
13833 C++ anonymous unions and structs. */
13834 if (DECL_NAME (member) != NULL_TREE
13835 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13836 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13838 gen_type_die (member_declared_type (member), type_die);
13839 gen_field_die (member, type_die);
13843 gen_variable_die (member, NULL_TREE, type_die);
13849 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13850 may later generate inlined and/or out-of-line instances of. */
13853 dwarf2out_abstract_function (tree decl)
13855 dw_die_ref old_die;
13858 int was_abstract = DECL_ABSTRACT (decl);
13860 /* Make sure we have the actual abstract inline, not a clone. */
13861 decl = DECL_ORIGIN (decl);
13862 htab_empty (decl_loc_table);
13864 old_die = lookup_decl_die (decl);
13865 if (old_die && get_AT (old_die, DW_AT_inline))
13866 /* We've already generated the abstract instance. */
13869 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13870 we don't get confused by DECL_ABSTRACT. */
13871 if (debug_info_level > DINFO_LEVEL_TERSE)
13873 context = decl_class_context (decl);
13875 gen_type_die_for_member
13876 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13879 /* Pretend we've just finished compiling this function. */
13880 save_fn = current_function_decl;
13881 current_function_decl = decl;
13882 push_cfun (DECL_STRUCT_FUNCTION (decl));
13884 set_decl_abstract_flags (decl, 1);
13885 dwarf2out_decl (decl);
13886 if (! was_abstract)
13887 set_decl_abstract_flags (decl, 0);
13889 current_function_decl = save_fn;
13893 /* Helper function of premark_used_types() which gets called through
13894 htab_traverse_resize().
13896 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13897 marked as unused by prune_unused_types. */
13899 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13904 type = (tree) *slot;
13905 die = lookup_type_die (type);
13907 die->die_perennial_p = 1;
13911 /* Mark all members of used_types_hash as perennial. */
13913 premark_used_types (void)
13915 if (cfun && cfun->used_types_hash)
13916 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13919 /* Generate a DIE to represent a declared function (either file-scope or
13923 gen_subprogram_die (tree decl, dw_die_ref context_die)
13925 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13926 tree origin = decl_ultimate_origin (decl);
13927 dw_die_ref subr_die;
13930 dw_die_ref old_die = lookup_decl_die (decl);
13931 int declaration = (current_function_decl != decl
13932 || class_or_namespace_scope_p (context_die));
13934 premark_used_types ();
13936 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13937 started to generate the abstract instance of an inline, decided to output
13938 its containing class, and proceeded to emit the declaration of the inline
13939 from the member list for the class. If so, DECLARATION takes priority;
13940 we'll get back to the abstract instance when done with the class. */
13942 /* The class-scope declaration DIE must be the primary DIE. */
13943 if (origin && declaration && class_or_namespace_scope_p (context_die))
13946 gcc_assert (!old_die);
13949 /* Now that the C++ front end lazily declares artificial member fns, we
13950 might need to retrofit the declaration into its class. */
13951 if (!declaration && !origin && !old_die
13952 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13953 && !class_or_namespace_scope_p (context_die)
13954 && debug_info_level > DINFO_LEVEL_TERSE)
13955 old_die = force_decl_die (decl);
13957 if (origin != NULL)
13959 gcc_assert (!declaration || local_scope_p (context_die));
13961 /* Fixup die_parent for the abstract instance of a nested
13962 inline function. */
13963 if (old_die && old_die->die_parent == NULL)
13964 add_child_die (context_die, old_die);
13966 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13967 add_abstract_origin_attribute (subr_die, origin);
13971 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13972 struct dwarf_file_data * file_index = lookup_filename (s.file);
13974 if (!get_AT_flag (old_die, DW_AT_declaration)
13975 /* We can have a normal definition following an inline one in the
13976 case of redefinition of GNU C extern inlines.
13977 It seems reasonable to use AT_specification in this case. */
13978 && !get_AT (old_die, DW_AT_inline))
13980 /* Detect and ignore this case, where we are trying to output
13981 something we have already output. */
13985 /* If the definition comes from the same place as the declaration,
13986 maybe use the old DIE. We always want the DIE for this function
13987 that has the *_pc attributes to be under comp_unit_die so the
13988 debugger can find it. We also need to do this for abstract
13989 instances of inlines, since the spec requires the out-of-line copy
13990 to have the same parent. For local class methods, this doesn't
13991 apply; we just use the old DIE. */
13992 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13993 && (DECL_ARTIFICIAL (decl)
13994 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13995 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13996 == (unsigned) s.line))))
13998 subr_die = old_die;
14000 /* Clear out the declaration attribute and the formal parameters.
14001 Do not remove all children, because it is possible that this
14002 declaration die was forced using force_decl_die(). In such
14003 cases die that forced declaration die (e.g. TAG_imported_module)
14004 is one of the children that we do not want to remove. */
14005 remove_AT (subr_die, DW_AT_declaration);
14006 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
14010 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14011 add_AT_specification (subr_die, old_die);
14012 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14013 add_AT_file (subr_die, DW_AT_decl_file, file_index);
14014 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14015 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
14020 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14022 if (TREE_PUBLIC (decl))
14023 add_AT_flag (subr_die, DW_AT_external, 1);
14025 add_name_and_src_coords_attributes (subr_die, decl);
14026 if (debug_info_level > DINFO_LEVEL_TERSE)
14028 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
14029 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
14030 0, 0, context_die);
14033 add_pure_or_virtual_attribute (subr_die, decl);
14034 if (DECL_ARTIFICIAL (decl))
14035 add_AT_flag (subr_die, DW_AT_artificial, 1);
14037 if (TREE_PROTECTED (decl))
14038 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
14039 else if (TREE_PRIVATE (decl))
14040 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
14045 if (!old_die || !get_AT (old_die, DW_AT_inline))
14047 add_AT_flag (subr_die, DW_AT_declaration, 1);
14049 /* If this is an explicit function declaration then generate
14050 a DW_AT_explicit attribute. */
14051 if (lang_hooks.decls.function_decl_explicit_p (decl))
14052 add_AT_flag (subr_die, DW_AT_explicit, 1);
14054 /* The first time we see a member function, it is in the context of
14055 the class to which it belongs. We make sure of this by emitting
14056 the class first. The next time is the definition, which is
14057 handled above. The two may come from the same source text.
14059 Note that force_decl_die() forces function declaration die. It is
14060 later reused to represent definition. */
14061 equate_decl_number_to_die (decl, subr_die);
14064 else if (DECL_ABSTRACT (decl))
14066 if (DECL_DECLARED_INLINE_P (decl))
14068 if (cgraph_function_possibly_inlined_p (decl))
14069 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
14071 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
14075 if (cgraph_function_possibly_inlined_p (decl))
14076 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
14078 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
14081 if (DECL_DECLARED_INLINE_P (decl)
14082 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
14083 add_AT_flag (subr_die, DW_AT_artificial, 1);
14085 equate_decl_number_to_die (decl, subr_die);
14087 else if (!DECL_EXTERNAL (decl))
14089 HOST_WIDE_INT cfa_fb_offset;
14091 if (!old_die || !get_AT (old_die, DW_AT_inline))
14092 equate_decl_number_to_die (decl, subr_die);
14094 if (!flag_reorder_blocks_and_partition)
14096 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
14097 current_function_funcdef_no);
14098 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
14099 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14100 current_function_funcdef_no);
14101 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
14103 add_pubname (decl, subr_die);
14104 add_arange (decl, subr_die);
14107 { /* Do nothing for now; maybe need to duplicate die, one for
14108 hot section and one for cold section, then use the hot/cold
14109 section begin/end labels to generate the aranges... */
14111 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
14112 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
14113 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
14114 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
14116 add_pubname (decl, subr_die);
14117 add_arange (decl, subr_die);
14118 add_arange (decl, subr_die);
14122 #ifdef MIPS_DEBUGGING_INFO
14123 /* Add a reference to the FDE for this routine. */
14124 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
14127 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
14129 /* We define the "frame base" as the function's CFA. This is more
14130 convenient for several reasons: (1) It's stable across the prologue
14131 and epilogue, which makes it better than just a frame pointer,
14132 (2) With dwarf3, there exists a one-byte encoding that allows us
14133 to reference the .debug_frame data by proxy, but failing that,
14134 (3) We can at least reuse the code inspection and interpretation
14135 code that determines the CFA position at various points in the
14137 if (dwarf_version >= 3)
14139 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
14140 add_AT_loc (subr_die, DW_AT_frame_base, op);
14144 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
14145 if (list->dw_loc_next)
14146 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
14148 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
14151 /* Compute a displacement from the "steady-state frame pointer" to
14152 the CFA. The former is what all stack slots and argument slots
14153 will reference in the rtl; the later is what we've told the
14154 debugger about. We'll need to adjust all frame_base references
14155 by this displacement. */
14156 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
14158 if (cfun->static_chain_decl)
14159 add_AT_location_description (subr_die, DW_AT_static_link,
14160 loc_descriptor_from_tree (cfun->static_chain_decl));
14163 /* Now output descriptions of the arguments for this function. This gets
14164 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
14165 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
14166 `...' at the end of the formal parameter list. In order to find out if
14167 there was a trailing ellipsis or not, we must instead look at the type
14168 associated with the FUNCTION_DECL. This will be a node of type
14169 FUNCTION_TYPE. If the chain of type nodes hanging off of this
14170 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
14171 an ellipsis at the end. */
14173 /* In the case where we are describing a mere function declaration, all we
14174 need to do here (and all we *can* do here) is to describe the *types* of
14175 its formal parameters. */
14176 if (debug_info_level <= DINFO_LEVEL_TERSE)
14178 else if (declaration)
14179 gen_formal_types_die (decl, subr_die);
14182 /* Generate DIEs to represent all known formal parameters. */
14183 tree arg_decls = DECL_ARGUMENTS (decl);
14186 /* When generating DIEs, generate the unspecified_parameters DIE
14187 instead if we come across the arg "__builtin_va_alist" */
14188 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
14189 if (TREE_CODE (parm) == PARM_DECL)
14191 if (DECL_NAME (parm)
14192 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
14193 "__builtin_va_alist"))
14194 gen_unspecified_parameters_die (parm, subr_die);
14196 gen_decl_die (parm, NULL, subr_die);
14199 /* Decide whether we need an unspecified_parameters DIE at the end.
14200 There are 2 more cases to do this for: 1) the ansi ... declaration -
14201 this is detectable when the end of the arg list is not a
14202 void_type_node 2) an unprototyped function declaration (not a
14203 definition). This just means that we have no info about the
14204 parameters at all. */
14205 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
14206 if (fn_arg_types != NULL)
14208 /* This is the prototyped case, check for.... */
14209 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
14210 gen_unspecified_parameters_die (decl, subr_die);
14212 else if (DECL_INITIAL (decl) == NULL_TREE)
14213 gen_unspecified_parameters_die (decl, subr_die);
14216 /* Output Dwarf info for all of the stuff within the body of the function
14217 (if it has one - it may be just a declaration). */
14218 outer_scope = DECL_INITIAL (decl);
14220 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
14221 a function. This BLOCK actually represents the outermost binding contour
14222 for the function, i.e. the contour in which the function's formal
14223 parameters and labels get declared. Curiously, it appears that the front
14224 end doesn't actually put the PARM_DECL nodes for the current function onto
14225 the BLOCK_VARS list for this outer scope, but are strung off of the
14226 DECL_ARGUMENTS list for the function instead.
14228 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
14229 the LABEL_DECL nodes for the function however, and we output DWARF info
14230 for those in decls_for_scope. Just within the `outer_scope' there will be
14231 a BLOCK node representing the function's outermost pair of curly braces,
14232 and any blocks used for the base and member initializers of a C++
14233 constructor function. */
14234 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
14236 /* Emit a DW_TAG_variable DIE for a named return value. */
14237 if (DECL_NAME (DECL_RESULT (decl)))
14238 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
14240 current_function_has_inlines = 0;
14241 decls_for_scope (outer_scope, subr_die, 0);
14243 #if 0 && defined (MIPS_DEBUGGING_INFO)
14244 if (current_function_has_inlines)
14246 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
14247 if (! comp_unit_has_inlines)
14249 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
14250 comp_unit_has_inlines = 1;
14255 /* Add the calling convention attribute if requested. */
14256 add_calling_convention_attribute (subr_die, decl);
14260 /* Returns a hash value for X (which really is a die_struct). */
14263 common_block_die_table_hash (const void *x)
14265 const_dw_die_ref d = (const_dw_die_ref) x;
14266 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
14269 /* Return nonzero if decl_id and die_parent of die_struct X is the same
14270 as decl_id and die_parent of die_struct Y. */
14273 common_block_die_table_eq (const void *x, const void *y)
14275 const_dw_die_ref d = (const_dw_die_ref) x;
14276 const_dw_die_ref e = (const_dw_die_ref) y;
14277 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
14280 /* Generate a DIE to represent a declared data object.
14281 Either DECL or ORIGIN must be non-null. */
14284 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
14288 tree decl_or_origin = decl ? decl : origin;
14289 dw_die_ref var_die;
14290 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
14291 dw_die_ref origin_die;
14292 int declaration = (DECL_EXTERNAL (decl_or_origin)
14293 /* If DECL is COMDAT and has not actually been
14294 emitted, we cannot take its address; there
14295 might end up being no definition anywhere in
14296 the program. For example, consider the C++
14300 struct S { static const int i = 7; };
14305 int f() { return S<int>::i; }
14307 Here, S<int>::i is not DECL_EXTERNAL, but no
14308 definition is required, so the compiler will
14309 not emit a definition. */
14310 || (TREE_CODE (decl_or_origin) == VAR_DECL
14311 && DECL_COMDAT (decl_or_origin)
14312 && !TREE_ASM_WRITTEN (decl_or_origin))
14313 || class_or_namespace_scope_p (context_die));
14316 origin = decl_ultimate_origin (decl);
14318 com_decl = fortran_common (decl_or_origin, &off);
14320 /* Symbol in common gets emitted as a child of the common block, in the form
14321 of a data member. */
14325 dw_die_ref com_die;
14326 dw_loc_descr_ref loc;
14327 die_node com_die_arg;
14329 var_die = lookup_decl_die (decl_or_origin);
14332 if (get_AT (var_die, DW_AT_location) == NULL)
14334 loc = loc_descriptor_from_tree (com_decl);
14339 /* Optimize the common case. */
14340 if (loc->dw_loc_opc == DW_OP_addr
14341 && loc->dw_loc_next == NULL
14342 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
14344 loc->dw_loc_oprnd1.v.val_addr
14345 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14347 loc_descr_plus_const (&loc, off);
14349 add_AT_loc (var_die, DW_AT_location, loc);
14350 remove_AT (var_die, DW_AT_declaration);
14356 if (common_block_die_table == NULL)
14357 common_block_die_table
14358 = htab_create_ggc (10, common_block_die_table_hash,
14359 common_block_die_table_eq, NULL);
14361 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
14362 com_die_arg.decl_id = DECL_UID (com_decl);
14363 com_die_arg.die_parent = context_die;
14364 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
14365 loc = loc_descriptor_from_tree (com_decl);
14366 if (com_die == NULL)
14369 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
14372 com_die = new_die (DW_TAG_common_block, context_die, decl);
14373 add_name_and_src_coords_attributes (com_die, com_decl);
14376 add_AT_loc (com_die, DW_AT_location, loc);
14377 /* Avoid sharing the same loc descriptor between
14378 DW_TAG_common_block and DW_TAG_variable. */
14379 loc = loc_descriptor_from_tree (com_decl);
14381 else if (DECL_EXTERNAL (decl))
14382 add_AT_flag (com_die, DW_AT_declaration, 1);
14383 add_pubname_string (cnam, com_die); /* ??? needed? */
14384 com_die->decl_id = DECL_UID (com_decl);
14385 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
14386 *slot = (void *) com_die;
14388 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
14390 add_AT_loc (com_die, DW_AT_location, loc);
14391 loc = loc_descriptor_from_tree (com_decl);
14392 remove_AT (com_die, DW_AT_declaration);
14394 var_die = new_die (DW_TAG_variable, com_die, decl);
14395 add_name_and_src_coords_attributes (var_die, decl);
14396 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
14397 TREE_THIS_VOLATILE (decl), context_die);
14398 add_AT_flag (var_die, DW_AT_external, 1);
14403 /* Optimize the common case. */
14404 if (loc->dw_loc_opc == DW_OP_addr
14405 && loc->dw_loc_next == NULL
14406 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
14407 loc->dw_loc_oprnd1.v.val_addr
14408 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14410 loc_descr_plus_const (&loc, off);
14412 add_AT_loc (var_die, DW_AT_location, loc);
14414 else if (DECL_EXTERNAL (decl))
14415 add_AT_flag (var_die, DW_AT_declaration, 1);
14416 equate_decl_number_to_die (decl, var_die);
14420 /* If the compiler emitted a definition for the DECL declaration
14421 and if we already emitted a DIE for it, don't emit a second
14422 DIE for it again. */
14425 && old_die->die_parent == context_die)
14428 /* For static data members, the declaration in the class is supposed
14429 to have DW_TAG_member tag; the specification should still be
14430 DW_TAG_variable referencing the DW_TAG_member DIE. */
14431 if (declaration && class_scope_p (context_die))
14432 var_die = new_die (DW_TAG_member, context_die, decl);
14434 var_die = new_die (DW_TAG_variable, context_die, decl);
14437 if (origin != NULL)
14438 origin_die = add_abstract_origin_attribute (var_die, origin);
14440 /* Loop unrolling can create multiple blocks that refer to the same
14441 static variable, so we must test for the DW_AT_declaration flag.
14443 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14444 copy decls and set the DECL_ABSTRACT flag on them instead of
14447 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14449 ??? The declare_in_namespace support causes us to get two DIEs for one
14450 variable, both of which are declarations. We want to avoid considering
14451 one to be a specification, so we must test that this DIE is not a
14453 else if (old_die && TREE_STATIC (decl) && ! declaration
14454 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14456 /* This is a definition of a C++ class level static. */
14457 add_AT_specification (var_die, old_die);
14458 if (DECL_NAME (decl))
14460 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14461 struct dwarf_file_data * file_index = lookup_filename (s.file);
14463 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14464 add_AT_file (var_die, DW_AT_decl_file, file_index);
14466 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14467 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14472 tree type = TREE_TYPE (decl);
14474 add_name_and_src_coords_attributes (var_die, decl);
14475 if ((TREE_CODE (decl) == PARM_DECL
14476 || TREE_CODE (decl) == RESULT_DECL
14477 || TREE_CODE (decl) == VAR_DECL)
14478 && DECL_BY_REFERENCE (decl))
14479 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14481 add_type_attribute (var_die, type, TREE_READONLY (decl),
14482 TREE_THIS_VOLATILE (decl), context_die);
14484 if (TREE_PUBLIC (decl))
14485 add_AT_flag (var_die, DW_AT_external, 1);
14487 if (DECL_ARTIFICIAL (decl))
14488 add_AT_flag (var_die, DW_AT_artificial, 1);
14490 if (TREE_PROTECTED (decl))
14491 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14492 else if (TREE_PRIVATE (decl))
14493 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14497 add_AT_flag (var_die, DW_AT_declaration, 1);
14499 if (decl && (DECL_ABSTRACT (decl) || declaration))
14500 equate_decl_number_to_die (decl, var_die);
14503 && (! DECL_ABSTRACT (decl_or_origin)
14504 /* Local static vars are shared between all clones/inlines,
14505 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14507 || (TREE_CODE (decl_or_origin) == VAR_DECL
14508 && TREE_STATIC (decl_or_origin)
14509 && DECL_RTL_SET_P (decl_or_origin)))
14510 /* When abstract origin already has DW_AT_location attribute, no need
14511 to add it again. */
14512 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14514 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14515 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14516 defer_location (decl_or_origin, var_die);
14518 add_location_or_const_value_attribute (var_die,
14521 add_pubname (decl_or_origin, var_die);
14524 tree_add_const_value_attribute (var_die, decl_or_origin);
14527 /* Generate a DIE to represent a named constant. */
14530 gen_const_die (tree decl, dw_die_ref context_die)
14532 dw_die_ref const_die;
14533 tree type = TREE_TYPE (decl);
14535 const_die = new_die (DW_TAG_constant, context_die, decl);
14536 add_name_and_src_coords_attributes (const_die, decl);
14537 add_type_attribute (const_die, type, 1, 0, context_die);
14538 if (TREE_PUBLIC (decl))
14539 add_AT_flag (const_die, DW_AT_external, 1);
14540 if (DECL_ARTIFICIAL (decl))
14541 add_AT_flag (const_die, DW_AT_artificial, 1);
14542 tree_add_const_value_attribute (const_die, decl);
14545 /* Generate a DIE to represent a label identifier. */
14548 gen_label_die (tree decl, dw_die_ref context_die)
14550 tree origin = decl_ultimate_origin (decl);
14551 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14553 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14555 if (origin != NULL)
14556 add_abstract_origin_attribute (lbl_die, origin);
14558 add_name_and_src_coords_attributes (lbl_die, decl);
14560 if (DECL_ABSTRACT (decl))
14561 equate_decl_number_to_die (decl, lbl_die);
14564 insn = DECL_RTL_IF_SET (decl);
14566 /* Deleted labels are programmer specified labels which have been
14567 eliminated because of various optimizations. We still emit them
14568 here so that it is possible to put breakpoints on them. */
14572 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14574 /* When optimization is enabled (via -O) some parts of the compiler
14575 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14576 represent source-level labels which were explicitly declared by
14577 the user. This really shouldn't be happening though, so catch
14578 it if it ever does happen. */
14579 gcc_assert (!INSN_DELETED_P (insn));
14581 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14582 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14587 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14588 attributes to the DIE for a block STMT, to describe where the inlined
14589 function was called from. This is similar to add_src_coords_attributes. */
14592 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14594 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14596 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14597 add_AT_unsigned (die, DW_AT_call_line, s.line);
14601 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14602 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14605 add_high_low_attributes (tree stmt, dw_die_ref die)
14607 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14609 if (BLOCK_FRAGMENT_CHAIN (stmt))
14613 if (inlined_function_outer_scope_p (stmt))
14615 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14616 BLOCK_NUMBER (stmt));
14617 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14620 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14622 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14625 add_ranges (chain);
14626 chain = BLOCK_FRAGMENT_CHAIN (chain);
14633 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14634 BLOCK_NUMBER (stmt));
14635 add_AT_lbl_id (die, DW_AT_low_pc, label);
14636 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14637 BLOCK_NUMBER (stmt));
14638 add_AT_lbl_id (die, DW_AT_high_pc, label);
14642 /* Generate a DIE for a lexical block. */
14645 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14647 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14649 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14650 add_high_low_attributes (stmt, stmt_die);
14652 decls_for_scope (stmt, stmt_die, depth);
14655 /* Generate a DIE for an inlined subprogram. */
14658 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
14660 tree decl = block_ultimate_origin (stmt);
14662 /* Emit info for the abstract instance first, if we haven't yet. We
14663 must emit this even if the block is abstract, otherwise when we
14664 emit the block below (or elsewhere), we may end up trying to emit
14665 a die whose origin die hasn't been emitted, and crashing. */
14666 dwarf2out_abstract_function (decl);
14668 if (! BLOCK_ABSTRACT (stmt))
14670 dw_die_ref subr_die
14671 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
14673 add_abstract_origin_attribute (subr_die, decl);
14674 if (TREE_ASM_WRITTEN (stmt))
14675 add_high_low_attributes (stmt, subr_die);
14676 add_call_src_coords_attributes (stmt, subr_die);
14678 decls_for_scope (stmt, subr_die, depth);
14679 current_function_has_inlines = 1;
14682 /* We may get here if we're the outer block of function A that was
14683 inlined into function B that was inlined into function C. When
14684 generating debugging info for C, dwarf2out_abstract_function(B)
14685 would mark all inlined blocks as abstract, including this one.
14686 So, we wouldn't (and shouldn't) expect labels to be generated
14687 for this one. Instead, just emit debugging info for
14688 declarations within the block. This is particularly important
14689 in the case of initializers of arguments passed from B to us:
14690 if they're statement expressions containing declarations, we
14691 wouldn't generate dies for their abstract variables, and then,
14692 when generating dies for the real variables, we'd die (pun
14694 gen_lexical_block_die (stmt, context_die, depth);
14697 /* Generate a DIE for a field in a record, or structure. */
14700 gen_field_die (tree decl, dw_die_ref context_die)
14702 dw_die_ref decl_die;
14704 if (TREE_TYPE (decl) == error_mark_node)
14707 decl_die = new_die (DW_TAG_member, context_die, decl);
14708 add_name_and_src_coords_attributes (decl_die, decl);
14709 add_type_attribute (decl_die, member_declared_type (decl),
14710 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
14713 if (DECL_BIT_FIELD_TYPE (decl))
14715 add_byte_size_attribute (decl_die, decl);
14716 add_bit_size_attribute (decl_die, decl);
14717 add_bit_offset_attribute (decl_die, decl);
14720 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
14721 add_data_member_location_attribute (decl_die, decl);
14723 if (DECL_ARTIFICIAL (decl))
14724 add_AT_flag (decl_die, DW_AT_artificial, 1);
14726 if (TREE_PROTECTED (decl))
14727 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
14728 else if (TREE_PRIVATE (decl))
14729 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
14731 /* Equate decl number to die, so that we can look up this decl later on. */
14732 equate_decl_number_to_die (decl, decl_die);
14736 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14737 Use modified_type_die instead.
14738 We keep this code here just in case these types of DIEs may be needed to
14739 represent certain things in other languages (e.g. Pascal) someday. */
14742 gen_pointer_type_die (tree type, dw_die_ref context_die)
14745 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
14747 equate_type_number_to_die (type, ptr_die);
14748 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14749 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14752 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14753 Use modified_type_die instead.
14754 We keep this code here just in case these types of DIEs may be needed to
14755 represent certain things in other languages (e.g. Pascal) someday. */
14758 gen_reference_type_die (tree type, dw_die_ref context_die)
14761 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
14763 equate_type_number_to_die (type, ref_die);
14764 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
14765 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14769 /* Generate a DIE for a pointer to a member type. */
14772 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14775 = new_die (DW_TAG_ptr_to_member_type,
14776 scope_die_for (type, context_die), type);
14778 equate_type_number_to_die (type, ptr_die);
14779 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14780 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14781 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14784 /* Generate the DIE for the compilation unit. */
14787 gen_compile_unit_die (const char *filename)
14790 char producer[250];
14791 const char *language_string = lang_hooks.name;
14794 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14798 add_name_attribute (die, filename);
14799 /* Don't add cwd for <built-in>. */
14800 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14801 add_comp_dir_attribute (die);
14804 sprintf (producer, "%s %s", language_string, version_string);
14806 #ifdef MIPS_DEBUGGING_INFO
14807 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14808 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14809 not appear in the producer string, the debugger reaches the conclusion
14810 that the object file is stripped and has no debugging information.
14811 To get the MIPS/SGI debugger to believe that there is debugging
14812 information in the object file, we add a -g to the producer string. */
14813 if (debug_info_level > DINFO_LEVEL_TERSE)
14814 strcat (producer, " -g");
14817 add_AT_string (die, DW_AT_producer, producer);
14819 if (strcmp (language_string, "GNU C++") == 0)
14820 language = DW_LANG_C_plus_plus;
14821 else if (strcmp (language_string, "GNU Ada") == 0)
14822 language = DW_LANG_Ada95;
14823 else if (strcmp (language_string, "GNU F77") == 0)
14824 language = DW_LANG_Fortran77;
14825 else if (strcmp (language_string, "GNU Fortran") == 0)
14826 language = DW_LANG_Fortran95;
14827 else if (strcmp (language_string, "GNU Pascal") == 0)
14828 language = DW_LANG_Pascal83;
14829 else if (strcmp (language_string, "GNU Java") == 0)
14830 language = DW_LANG_Java;
14831 else if (strcmp (language_string, "GNU Objective-C") == 0)
14832 language = DW_LANG_ObjC;
14833 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14834 language = DW_LANG_ObjC_plus_plus;
14836 language = DW_LANG_C89;
14838 add_AT_unsigned (die, DW_AT_language, language);
14842 /* Generate the DIE for a base class. */
14845 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14847 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14849 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14850 add_data_member_location_attribute (die, binfo);
14852 if (BINFO_VIRTUAL_P (binfo))
14853 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14855 if (access == access_public_node)
14856 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14857 else if (access == access_protected_node)
14858 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14861 /* Generate a DIE for a class member. */
14864 gen_member_die (tree type, dw_die_ref context_die)
14867 tree binfo = TYPE_BINFO (type);
14870 /* If this is not an incomplete type, output descriptions of each of its
14871 members. Note that as we output the DIEs necessary to represent the
14872 members of this record or union type, we will also be trying to output
14873 DIEs to represent the *types* of those members. However the `type'
14874 function (above) will specifically avoid generating type DIEs for member
14875 types *within* the list of member DIEs for this (containing) type except
14876 for those types (of members) which are explicitly marked as also being
14877 members of this (containing) type themselves. The g++ front- end can
14878 force any given type to be treated as a member of some other (containing)
14879 type by setting the TYPE_CONTEXT of the given (member) type to point to
14880 the TREE node representing the appropriate (containing) type. */
14882 /* First output info about the base classes. */
14885 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14889 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14890 gen_inheritance_die (base,
14891 (accesses ? VEC_index (tree, accesses, i)
14892 : access_public_node), context_die);
14895 /* Now output info about the data members and type members. */
14896 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14898 /* If we thought we were generating minimal debug info for TYPE
14899 and then changed our minds, some of the member declarations
14900 may have already been defined. Don't define them again, but
14901 do put them in the right order. */
14903 child = lookup_decl_die (member);
14905 splice_child_die (context_die, child);
14907 gen_decl_die (member, NULL, context_die);
14910 /* Now output info about the function members (if any). */
14911 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14913 /* Don't include clones in the member list. */
14914 if (DECL_ABSTRACT_ORIGIN (member))
14917 child = lookup_decl_die (member);
14919 splice_child_die (context_die, child);
14921 gen_decl_die (member, NULL, context_die);
14925 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14926 is set, we pretend that the type was never defined, so we only get the
14927 member DIEs needed by later specification DIEs. */
14930 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14931 enum debug_info_usage usage)
14933 dw_die_ref type_die = lookup_type_die (type);
14934 dw_die_ref scope_die = 0;
14936 int complete = (TYPE_SIZE (type)
14937 && (! TYPE_STUB_DECL (type)
14938 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14939 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14940 complete = complete && should_emit_struct_debug (type, usage);
14942 if (type_die && ! complete)
14945 if (TYPE_CONTEXT (type) != NULL_TREE
14946 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14947 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14950 scope_die = scope_die_for (type, context_die);
14952 if (! type_die || (nested && scope_die == comp_unit_die))
14953 /* First occurrence of type or toplevel definition of nested class. */
14955 dw_die_ref old_die = type_die;
14957 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14958 ? record_type_tag (type) : DW_TAG_union_type,
14960 equate_type_number_to_die (type, type_die);
14962 add_AT_specification (type_die, old_die);
14964 add_name_attribute (type_die, type_tag (type));
14967 remove_AT (type_die, DW_AT_declaration);
14969 /* If this type has been completed, then give it a byte_size attribute and
14970 then give a list of members. */
14971 if (complete && !ns_decl)
14973 /* Prevent infinite recursion in cases where the type of some member of
14974 this type is expressed in terms of this type itself. */
14975 TREE_ASM_WRITTEN (type) = 1;
14976 add_byte_size_attribute (type_die, type);
14977 if (TYPE_STUB_DECL (type) != NULL_TREE)
14978 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14980 /* If the first reference to this type was as the return type of an
14981 inline function, then it may not have a parent. Fix this now. */
14982 if (type_die->die_parent == NULL)
14983 add_child_die (scope_die, type_die);
14985 push_decl_scope (type);
14986 gen_member_die (type, type_die);
14989 /* GNU extension: Record what type our vtable lives in. */
14990 if (TYPE_VFIELD (type))
14992 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14994 gen_type_die (vtype, context_die);
14995 add_AT_die_ref (type_die, DW_AT_containing_type,
14996 lookup_type_die (vtype));
15001 add_AT_flag (type_die, DW_AT_declaration, 1);
15003 /* We don't need to do this for function-local types. */
15004 if (TYPE_STUB_DECL (type)
15005 && ! decl_function_context (TYPE_STUB_DECL (type)))
15006 VEC_safe_push (tree, gc, incomplete_types, type);
15009 if (get_AT (type_die, DW_AT_name))
15010 add_pubtype (type, type_die);
15013 /* Generate a DIE for a subroutine _type_. */
15016 gen_subroutine_type_die (tree type, dw_die_ref context_die)
15018 tree return_type = TREE_TYPE (type);
15019 dw_die_ref subr_die
15020 = new_die (DW_TAG_subroutine_type,
15021 scope_die_for (type, context_die), type);
15023 equate_type_number_to_die (type, subr_die);
15024 add_prototyped_attribute (subr_die, type);
15025 add_type_attribute (subr_die, return_type, 0, 0, context_die);
15026 gen_formal_types_die (type, subr_die);
15028 if (get_AT (subr_die, DW_AT_name))
15029 add_pubtype (type, subr_die);
15032 /* Generate a DIE for a type definition. */
15035 gen_typedef_die (tree decl, dw_die_ref context_die)
15037 dw_die_ref type_die;
15040 if (TREE_ASM_WRITTEN (decl))
15043 TREE_ASM_WRITTEN (decl) = 1;
15044 type_die = new_die (DW_TAG_typedef, context_die, decl);
15045 origin = decl_ultimate_origin (decl);
15046 if (origin != NULL)
15047 add_abstract_origin_attribute (type_die, origin);
15052 add_name_and_src_coords_attributes (type_die, decl);
15053 if (DECL_ORIGINAL_TYPE (decl))
15055 type = DECL_ORIGINAL_TYPE (decl);
15057 gcc_assert (type != TREE_TYPE (decl));
15058 equate_type_number_to_die (TREE_TYPE (decl), type_die);
15061 type = TREE_TYPE (decl);
15063 add_type_attribute (type_die, type, TREE_READONLY (decl),
15064 TREE_THIS_VOLATILE (decl), context_die);
15067 if (DECL_ABSTRACT (decl))
15068 equate_decl_number_to_die (decl, type_die);
15070 if (get_AT (type_die, DW_AT_name))
15071 add_pubtype (decl, type_die);
15074 /* Generate a type description DIE. */
15077 gen_type_die_with_usage (tree type, dw_die_ref context_die,
15078 enum debug_info_usage usage)
15081 struct array_descr_info info;
15083 if (type == NULL_TREE || type == error_mark_node)
15086 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
15087 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
15089 if (TREE_ASM_WRITTEN (type))
15092 /* Prevent broken recursion; we can't hand off to the same type. */
15093 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
15095 /* Use the DIE of the containing namespace as the parent DIE of
15096 the type description DIE we want to generate. */
15097 if (DECL_CONTEXT (TYPE_NAME (type))
15098 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
15099 context_die = lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type)));
15101 TREE_ASM_WRITTEN (type) = 1;
15102 gen_decl_die (TYPE_NAME (type), NULL, context_die);
15106 /* If this is an array type with hidden descriptor, handle it first. */
15107 if (!TREE_ASM_WRITTEN (type)
15108 && lang_hooks.types.get_array_descr_info
15109 && lang_hooks.types.get_array_descr_info (type, &info))
15111 gen_descr_array_type_die (type, &info, context_die);
15112 TREE_ASM_WRITTEN (type) = 1;
15116 /* We are going to output a DIE to represent the unqualified version
15117 of this type (i.e. without any const or volatile qualifiers) so
15118 get the main variant (i.e. the unqualified version) of this type
15119 now. (Vectors are special because the debugging info is in the
15120 cloned type itself). */
15121 if (TREE_CODE (type) != VECTOR_TYPE)
15122 type = type_main_variant (type);
15124 if (TREE_ASM_WRITTEN (type))
15127 switch (TREE_CODE (type))
15133 case REFERENCE_TYPE:
15134 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
15135 ensures that the gen_type_die recursion will terminate even if the
15136 type is recursive. Recursive types are possible in Ada. */
15137 /* ??? We could perhaps do this for all types before the switch
15139 TREE_ASM_WRITTEN (type) = 1;
15141 /* For these types, all that is required is that we output a DIE (or a
15142 set of DIEs) to represent the "basis" type. */
15143 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15144 DINFO_USAGE_IND_USE);
15148 /* This code is used for C++ pointer-to-data-member types.
15149 Output a description of the relevant class type. */
15150 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
15151 DINFO_USAGE_IND_USE);
15153 /* Output a description of the type of the object pointed to. */
15154 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15155 DINFO_USAGE_IND_USE);
15157 /* Now output a DIE to represent this pointer-to-data-member type
15159 gen_ptr_to_mbr_type_die (type, context_die);
15162 case FUNCTION_TYPE:
15163 /* Force out return type (in case it wasn't forced out already). */
15164 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15165 DINFO_USAGE_DIR_USE);
15166 gen_subroutine_type_die (type, context_die);
15170 /* Force out return type (in case it wasn't forced out already). */
15171 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15172 DINFO_USAGE_DIR_USE);
15173 gen_subroutine_type_die (type, context_die);
15177 gen_array_type_die (type, context_die);
15181 gen_array_type_die (type, context_die);
15184 case ENUMERAL_TYPE:
15187 case QUAL_UNION_TYPE:
15188 /* If this is a nested type whose containing class hasn't been written
15189 out yet, writing it out will cover this one, too. This does not apply
15190 to instantiations of member class templates; they need to be added to
15191 the containing class as they are generated. FIXME: This hurts the
15192 idea of combining type decls from multiple TUs, since we can't predict
15193 what set of template instantiations we'll get. */
15194 if (TYPE_CONTEXT (type)
15195 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
15196 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
15198 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
15200 if (TREE_ASM_WRITTEN (type))
15203 /* If that failed, attach ourselves to the stub. */
15204 push_decl_scope (TYPE_CONTEXT (type));
15205 context_die = lookup_type_die (TYPE_CONTEXT (type));
15210 context_die = declare_in_namespace (type, context_die);
15214 if (TREE_CODE (type) == ENUMERAL_TYPE)
15216 /* This might have been written out by the call to
15217 declare_in_namespace. */
15218 if (!TREE_ASM_WRITTEN (type))
15219 gen_enumeration_type_die (type, context_die);
15222 gen_struct_or_union_type_die (type, context_die, usage);
15227 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
15228 it up if it is ever completed. gen_*_type_die will set it for us
15229 when appropriate. */
15235 case FIXED_POINT_TYPE:
15238 /* No DIEs needed for fundamental types. */
15242 /* No Dwarf representation currently defined. */
15246 gcc_unreachable ();
15249 TREE_ASM_WRITTEN (type) = 1;
15253 gen_type_die (tree type, dw_die_ref context_die)
15255 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
15258 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
15259 things which are local to the given block. */
15262 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
15264 int must_output_die = 0;
15267 /* Ignore blocks that are NULL. */
15268 if (stmt == NULL_TREE)
15271 inlined_func = inlined_function_outer_scope_p (stmt);
15273 /* If the block is one fragment of a non-contiguous block, do not
15274 process the variables, since they will have been done by the
15275 origin block. Do process subblocks. */
15276 if (BLOCK_FRAGMENT_ORIGIN (stmt))
15280 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
15281 gen_block_die (sub, context_die, depth + 1);
15286 /* Determine if we need to output any Dwarf DIEs at all to represent this
15289 /* The outer scopes for inlinings *must* always be represented. We
15290 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
15291 must_output_die = 1;
15294 /* Determine if this block directly contains any "significant"
15295 local declarations which we will need to output DIEs for. */
15296 if (debug_info_level > DINFO_LEVEL_TERSE)
15297 /* We are not in terse mode so *any* local declaration counts
15298 as being a "significant" one. */
15299 must_output_die = ((BLOCK_VARS (stmt) != NULL
15300 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
15301 && (TREE_USED (stmt)
15302 || TREE_ASM_WRITTEN (stmt)
15303 || BLOCK_ABSTRACT (stmt)));
15304 else if ((TREE_USED (stmt)
15305 || TREE_ASM_WRITTEN (stmt)
15306 || BLOCK_ABSTRACT (stmt))
15307 && !dwarf2out_ignore_block (stmt))
15308 must_output_die = 1;
15311 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
15312 DIE for any block which contains no significant local declarations at
15313 all. Rather, in such cases we just call `decls_for_scope' so that any
15314 needed Dwarf info for any sub-blocks will get properly generated. Note
15315 that in terse mode, our definition of what constitutes a "significant"
15316 local declaration gets restricted to include only inlined function
15317 instances and local (nested) function definitions. */
15318 if (must_output_die)
15321 gen_inlined_subroutine_die (stmt, context_die, depth);
15323 gen_lexical_block_die (stmt, context_die, depth);
15326 decls_for_scope (stmt, context_die, depth);
15329 /* Process variable DECL (or variable with origin ORIGIN) within
15330 block STMT and add it to CONTEXT_DIE. */
15332 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
15335 tree decl_or_origin = decl ? decl : origin;
15336 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
15338 if (ultimate_origin)
15339 origin = ultimate_origin;
15341 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
15342 die = lookup_decl_die (decl_or_origin);
15343 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
15344 && TYPE_DECL_IS_STUB (decl_or_origin))
15345 die = lookup_type_die (TREE_TYPE (decl_or_origin));
15349 if (die != NULL && die->die_parent == NULL)
15350 add_child_die (context_die, die);
15351 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
15352 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
15353 stmt, context_die);
15355 gen_decl_die (decl, origin, context_die);
15358 /* Generate all of the decls declared within a given scope and (recursively)
15359 all of its sub-blocks. */
15362 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
15368 /* Ignore NULL blocks. */
15369 if (stmt == NULL_TREE)
15372 /* Output the DIEs to represent all of the data objects and typedefs
15373 declared directly within this block but not within any nested
15374 sub-blocks. Also, nested function and tag DIEs have been
15375 generated with a parent of NULL; fix that up now. */
15376 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
15377 process_scope_var (stmt, decl, NULL_TREE, context_die);
15378 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
15379 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
15382 /* If we're at -g1, we're not interested in subblocks. */
15383 if (debug_info_level <= DINFO_LEVEL_TERSE)
15386 /* Output the DIEs to represent all sub-blocks (and the items declared
15387 therein) of this block. */
15388 for (subblocks = BLOCK_SUBBLOCKS (stmt);
15390 subblocks = BLOCK_CHAIN (subblocks))
15391 gen_block_die (subblocks, context_die, depth + 1);
15394 /* Is this a typedef we can avoid emitting? */
15397 is_redundant_typedef (const_tree decl)
15399 if (TYPE_DECL_IS_STUB (decl))
15402 if (DECL_ARTIFICIAL (decl)
15403 && DECL_CONTEXT (decl)
15404 && is_tagged_type (DECL_CONTEXT (decl))
15405 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
15406 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
15407 /* Also ignore the artificial member typedef for the class name. */
15413 /* Returns the DIE for a context. */
15415 static inline dw_die_ref
15416 get_context_die (tree context)
15420 /* Find die that represents this context. */
15421 if (TYPE_P (context))
15422 return force_type_die (context);
15424 return force_decl_die (context);
15426 return comp_unit_die;
15429 /* Returns the DIE for decl. A DIE will always be returned. */
15432 force_decl_die (tree decl)
15434 dw_die_ref decl_die;
15435 unsigned saved_external_flag;
15436 tree save_fn = NULL_TREE;
15437 decl_die = lookup_decl_die (decl);
15440 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15442 decl_die = lookup_decl_die (decl);
15446 switch (TREE_CODE (decl))
15448 case FUNCTION_DECL:
15449 /* Clear current_function_decl, so that gen_subprogram_die thinks
15450 that this is a declaration. At this point, we just want to force
15451 declaration die. */
15452 save_fn = current_function_decl;
15453 current_function_decl = NULL_TREE;
15454 gen_subprogram_die (decl, context_die);
15455 current_function_decl = save_fn;
15459 /* Set external flag to force declaration die. Restore it after
15460 gen_decl_die() call. */
15461 saved_external_flag = DECL_EXTERNAL (decl);
15462 DECL_EXTERNAL (decl) = 1;
15463 gen_decl_die (decl, NULL, context_die);
15464 DECL_EXTERNAL (decl) = saved_external_flag;
15467 case NAMESPACE_DECL:
15468 dwarf2out_decl (decl);
15472 gcc_unreachable ();
15475 /* We should be able to find the DIE now. */
15477 decl_die = lookup_decl_die (decl);
15478 gcc_assert (decl_die);
15484 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15485 always returned. */
15488 force_type_die (tree type)
15490 dw_die_ref type_die;
15492 type_die = lookup_type_die (type);
15495 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15497 type_die = modified_type_die (type, TYPE_READONLY (type),
15498 TYPE_VOLATILE (type), context_die);
15499 gcc_assert (type_die);
15504 /* Force out any required namespaces to be able to output DECL,
15505 and return the new context_die for it, if it's changed. */
15508 setup_namespace_context (tree thing, dw_die_ref context_die)
15510 tree context = (DECL_P (thing)
15511 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15512 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15513 /* Force out the namespace. */
15514 context_die = force_decl_die (context);
15516 return context_die;
15519 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15520 type) within its namespace, if appropriate.
15522 For compatibility with older debuggers, namespace DIEs only contain
15523 declarations; all definitions are emitted at CU scope. */
15526 declare_in_namespace (tree thing, dw_die_ref context_die)
15528 dw_die_ref ns_context;
15530 if (debug_info_level <= DINFO_LEVEL_TERSE)
15531 return context_die;
15533 /* If this decl is from an inlined function, then don't try to emit it in its
15534 namespace, as we will get confused. It would have already been emitted
15535 when the abstract instance of the inline function was emitted anyways. */
15536 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15537 return context_die;
15539 ns_context = setup_namespace_context (thing, context_die);
15541 if (ns_context != context_die)
15545 if (DECL_P (thing))
15546 gen_decl_die (thing, NULL, ns_context);
15548 gen_type_die (thing, ns_context);
15550 return context_die;
15553 /* Generate a DIE for a namespace or namespace alias. */
15556 gen_namespace_die (tree decl, dw_die_ref context_die)
15558 dw_die_ref namespace_die;
15560 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15561 they are an alias of. */
15562 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15564 /* Output a real namespace or module. */
15565 context_die = setup_namespace_context (decl, comp_unit_die);
15566 namespace_die = new_die (is_fortran ()
15567 ? DW_TAG_module : DW_TAG_namespace,
15568 context_die, decl);
15569 /* For Fortran modules defined in different CU don't add src coords. */
15570 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15571 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15573 add_name_and_src_coords_attributes (namespace_die, decl);
15574 if (DECL_EXTERNAL (decl))
15575 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15576 equate_decl_number_to_die (decl, namespace_die);
15580 /* Output a namespace alias. */
15582 /* Force out the namespace we are an alias of, if necessary. */
15583 dw_die_ref origin_die
15584 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15586 if (DECL_CONTEXT (decl) == NULL_TREE
15587 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15588 context_die = setup_namespace_context (decl, comp_unit_die);
15589 /* Now create the namespace alias DIE. */
15590 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15591 add_name_and_src_coords_attributes (namespace_die, decl);
15592 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15593 equate_decl_number_to_die (decl, namespace_die);
15597 /* Generate Dwarf debug information for a decl described by DECL. */
15600 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15602 tree decl_or_origin = decl ? decl : origin;
15603 tree class_origin = NULL;
15605 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15608 switch (TREE_CODE (decl_or_origin))
15614 if (!is_fortran ())
15616 /* The individual enumerators of an enum type get output when we output
15617 the Dwarf representation of the relevant enum type itself. */
15621 /* Emit its type. */
15622 gen_type_die (TREE_TYPE (decl), context_die);
15624 /* And its containing namespace. */
15625 context_die = declare_in_namespace (decl, context_die);
15627 gen_const_die (decl, context_die);
15630 case FUNCTION_DECL:
15631 /* Don't output any DIEs to represent mere function declarations,
15632 unless they are class members or explicit block externs. */
15633 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15634 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15635 && (current_function_decl == NULL_TREE
15636 || DECL_ARTIFICIAL (decl_or_origin)))
15641 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15642 on local redeclarations of global functions. That seems broken. */
15643 if (current_function_decl != decl)
15644 /* This is only a declaration. */;
15647 /* If we're emitting a clone, emit info for the abstract instance. */
15648 if (origin || DECL_ORIGIN (decl) != decl)
15649 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
15651 /* If we're emitting an out-of-line copy of an inline function,
15652 emit info for the abstract instance and set up to refer to it. */
15653 else if (cgraph_function_possibly_inlined_p (decl)
15654 && ! DECL_ABSTRACT (decl)
15655 && ! class_or_namespace_scope_p (context_die)
15656 /* dwarf2out_abstract_function won't emit a die if this is just
15657 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15658 that case, because that works only if we have a die. */
15659 && DECL_INITIAL (decl) != NULL_TREE)
15661 dwarf2out_abstract_function (decl);
15662 set_decl_origin_self (decl);
15665 /* Otherwise we're emitting the primary DIE for this decl. */
15666 else if (debug_info_level > DINFO_LEVEL_TERSE)
15668 /* Before we describe the FUNCTION_DECL itself, make sure that we
15669 have described its return type. */
15670 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15672 /* And its virtual context. */
15673 if (DECL_VINDEX (decl) != NULL_TREE)
15674 gen_type_die (DECL_CONTEXT (decl), context_die);
15676 /* And its containing type. */
15678 origin = decl_class_context (decl);
15679 if (origin != NULL_TREE)
15680 gen_type_die_for_member (origin, decl, context_die);
15682 /* And its containing namespace. */
15683 context_die = declare_in_namespace (decl, context_die);
15686 /* Now output a DIE to represent the function itself. */
15688 gen_subprogram_die (decl, context_die);
15692 /* If we are in terse mode, don't generate any DIEs to represent any
15693 actual typedefs. */
15694 if (debug_info_level <= DINFO_LEVEL_TERSE)
15697 /* In the special case of a TYPE_DECL node representing the declaration
15698 of some type tag, if the given TYPE_DECL is marked as having been
15699 instantiated from some other (original) TYPE_DECL node (e.g. one which
15700 was generated within the original definition of an inline function) we
15701 used to generate a special (abbreviated) DW_TAG_structure_type,
15702 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15703 should be actually referencing those DIEs, as variable DIEs with that
15704 type would be emitted already in the abstract origin, so it was always
15705 removed during unused type prunning. Don't add anything in this
15707 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
15710 if (is_redundant_typedef (decl))
15711 gen_type_die (TREE_TYPE (decl), context_die);
15713 /* Output a DIE to represent the typedef itself. */
15714 gen_typedef_die (decl, context_die);
15718 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15719 gen_label_die (decl, context_die);
15724 /* If we are in terse mode, don't generate any DIEs to represent any
15725 variable declarations or definitions. */
15726 if (debug_info_level <= DINFO_LEVEL_TERSE)
15729 /* Output any DIEs that are needed to specify the type of this data
15731 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
15732 || TREE_CODE (decl_or_origin) == VAR_DECL)
15733 && DECL_BY_REFERENCE (decl_or_origin))
15734 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15736 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15738 /* And its containing type. */
15739 class_origin = decl_class_context (decl_or_origin);
15740 if (class_origin != NULL_TREE)
15741 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
15743 /* And its containing namespace. */
15744 context_die = declare_in_namespace (decl_or_origin, context_die);
15746 /* Now output the DIE to represent the data object itself. This gets
15747 complicated because of the possibility that the VAR_DECL really
15748 represents an inlined instance of a formal parameter for an inline
15751 origin = decl_ultimate_origin (decl);
15752 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15753 gen_formal_parameter_die (decl, origin, context_die);
15755 gen_variable_die (decl, origin, context_die);
15759 /* Ignore the nameless fields that are used to skip bits but handle C++
15760 anonymous unions and structs. */
15761 if (DECL_NAME (decl) != NULL_TREE
15762 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15763 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15765 gen_type_die (member_declared_type (decl), context_die);
15766 gen_field_die (decl, context_die);
15771 if (DECL_BY_REFERENCE (decl_or_origin))
15772 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15774 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15775 gen_formal_parameter_die (decl, origin, context_die);
15778 case NAMESPACE_DECL:
15779 case IMPORTED_DECL:
15780 gen_namespace_die (decl, context_die);
15784 /* Probably some frontend-internal decl. Assume we don't care. */
15785 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15790 /* Output debug information for global decl DECL. Called from toplev.c after
15791 compilation proper has finished. */
15794 dwarf2out_global_decl (tree decl)
15796 /* Output DWARF2 information for file-scope tentative data object
15797 declarations, file-scope (extern) function declarations (which
15798 had no corresponding body) and file-scope tagged type declarations
15799 and definitions which have not yet been forced out. */
15800 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15801 dwarf2out_decl (decl);
15804 /* Output debug information for type decl DECL. Called from toplev.c
15805 and from language front ends (to record built-in types). */
15807 dwarf2out_type_decl (tree decl, int local)
15810 dwarf2out_decl (decl);
15813 /* Output debug information for imported module or decl DECL.
15814 NAME is non-NULL name in the lexical block if the decl has been renamed.
15815 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15816 that DECL belongs to.
15817 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15819 dwarf2out_imported_module_or_decl_1 (tree decl,
15821 tree lexical_block,
15822 dw_die_ref lexical_block_die)
15824 expanded_location xloc;
15825 dw_die_ref imported_die = NULL;
15826 dw_die_ref at_import_die;
15828 if (TREE_CODE (decl) == IMPORTED_DECL)
15830 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
15831 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
15835 xloc = expand_location (input_location);
15837 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15839 if (is_base_type (TREE_TYPE (decl)))
15840 at_import_die = base_type_die (TREE_TYPE (decl));
15842 at_import_die = force_type_die (TREE_TYPE (decl));
15843 /* For namespace N { typedef void T; } using N::T; base_type_die
15844 returns NULL, but DW_TAG_imported_declaration requires
15845 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15846 if (!at_import_die)
15848 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15849 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15850 at_import_die = lookup_type_die (TREE_TYPE (decl));
15851 gcc_assert (at_import_die);
15856 at_import_die = lookup_decl_die (decl);
15857 if (!at_import_die)
15859 /* If we're trying to avoid duplicate debug info, we may not have
15860 emitted the member decl for this field. Emit it now. */
15861 if (TREE_CODE (decl) == FIELD_DECL)
15863 tree type = DECL_CONTEXT (decl);
15865 if (TYPE_CONTEXT (type)
15866 && TYPE_P (TYPE_CONTEXT (type))
15867 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15868 DINFO_USAGE_DIR_USE))
15870 gen_type_die_for_member (type, decl,
15871 get_context_die (TYPE_CONTEXT (type)));
15873 at_import_die = force_decl_die (decl);
15877 if (TREE_CODE (decl) == NAMESPACE_DECL)
15878 imported_die = new_die (DW_TAG_imported_module,
15882 imported_die = new_die (DW_TAG_imported_declaration,
15886 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15887 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15889 add_AT_string (imported_die, DW_AT_name,
15890 IDENTIFIER_POINTER (name));
15891 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15894 /* Output debug information for imported module or decl DECL.
15895 NAME is non-NULL name in context if the decl has been renamed.
15896 CHILD is true if decl is one of the renamed decls as part of
15897 importing whole module. */
15900 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15903 /* dw_die_ref at_import_die; */
15904 dw_die_ref scope_die;
15906 if (debug_info_level <= DINFO_LEVEL_TERSE)
15911 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15912 We need decl DIE for reference and scope die. First, get DIE for the decl
15915 /* Get the scope die for decl context. Use comp_unit_die for global module
15916 or decl. If die is not found for non globals, force new die. */
15918 && TYPE_P (context)
15919 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15921 scope_die = get_context_die (context);
15925 gcc_assert (scope_die->die_child);
15926 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15927 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15928 scope_die = scope_die->die_child;
15931 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15932 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
15936 /* Write the debugging output for DECL. */
15939 dwarf2out_decl (tree decl)
15941 dw_die_ref context_die = comp_unit_die;
15943 switch (TREE_CODE (decl))
15948 case FUNCTION_DECL:
15949 /* What we would really like to do here is to filter out all mere
15950 file-scope declarations of file-scope functions which are never
15951 referenced later within this translation unit (and keep all of ones
15952 that *are* referenced later on) but we aren't clairvoyant, so we have
15953 no idea which functions will be referenced in the future (i.e. later
15954 on within the current translation unit). So here we just ignore all
15955 file-scope function declarations which are not also definitions. If
15956 and when the debugger needs to know something about these functions,
15957 it will have to hunt around and find the DWARF information associated
15958 with the definition of the function.
15960 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15961 nodes represent definitions and which ones represent mere
15962 declarations. We have to check DECL_INITIAL instead. That's because
15963 the C front-end supports some weird semantics for "extern inline"
15964 function definitions. These can get inlined within the current
15965 translation unit (and thus, we need to generate Dwarf info for their
15966 abstract instances so that the Dwarf info for the concrete inlined
15967 instances can have something to refer to) but the compiler never
15968 generates any out-of-lines instances of such things (despite the fact
15969 that they *are* definitions).
15971 The important point is that the C front-end marks these "extern
15972 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15973 them anyway. Note that the C++ front-end also plays some similar games
15974 for inline function definitions appearing within include files which
15975 also contain `#pragma interface' pragmas. */
15976 if (DECL_INITIAL (decl) == NULL_TREE)
15979 /* If we're a nested function, initially use a parent of NULL; if we're
15980 a plain function, this will be fixed up in decls_for_scope. If
15981 we're a method, it will be ignored, since we already have a DIE. */
15982 if (decl_function_context (decl)
15983 /* But if we're in terse mode, we don't care about scope. */
15984 && debug_info_level > DINFO_LEVEL_TERSE)
15985 context_die = NULL;
15989 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15990 declaration and if the declaration was never even referenced from
15991 within this entire compilation unit. We suppress these DIEs in
15992 order to save space in the .debug section (by eliminating entries
15993 which are probably useless). Note that we must not suppress
15994 block-local extern declarations (whether used or not) because that
15995 would screw-up the debugger's name lookup mechanism and cause it to
15996 miss things which really ought to be in scope at a given point. */
15997 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
16000 /* For local statics lookup proper context die. */
16001 if (TREE_STATIC (decl) && decl_function_context (decl))
16002 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16004 /* If we are in terse mode, don't generate any DIEs to represent any
16005 variable declarations or definitions. */
16006 if (debug_info_level <= DINFO_LEVEL_TERSE)
16011 if (debug_info_level <= DINFO_LEVEL_TERSE)
16013 if (!is_fortran ())
16015 if (TREE_STATIC (decl) && decl_function_context (decl))
16016 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16019 case NAMESPACE_DECL:
16020 case IMPORTED_DECL:
16021 if (debug_info_level <= DINFO_LEVEL_TERSE)
16023 if (lookup_decl_die (decl) != NULL)
16028 /* Don't emit stubs for types unless they are needed by other DIEs. */
16029 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
16032 /* Don't bother trying to generate any DIEs to represent any of the
16033 normal built-in types for the language we are compiling. */
16034 if (DECL_IS_BUILTIN (decl))
16036 /* OK, we need to generate one for `bool' so GDB knows what type
16037 comparisons have. */
16039 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
16040 && ! DECL_IGNORED_P (decl))
16041 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
16046 /* If we are in terse mode, don't generate any DIEs for types. */
16047 if (debug_info_level <= DINFO_LEVEL_TERSE)
16050 /* If we're a function-scope tag, initially use a parent of NULL;
16051 this will be fixed up in decls_for_scope. */
16052 if (decl_function_context (decl))
16053 context_die = NULL;
16061 gen_decl_die (decl, NULL, context_die);
16064 /* Output a marker (i.e. a label) for the beginning of the generated code for
16065 a lexical block. */
16068 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
16069 unsigned int blocknum)
16071 switch_to_section (current_function_section ());
16072 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
16075 /* Output a marker (i.e. a label) for the end of the generated code for a
16079 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
16081 switch_to_section (current_function_section ());
16082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
16085 /* Returns nonzero if it is appropriate not to emit any debugging
16086 information for BLOCK, because it doesn't contain any instructions.
16088 Don't allow this for blocks with nested functions or local classes
16089 as we would end up with orphans, and in the presence of scheduling
16090 we may end up calling them anyway. */
16093 dwarf2out_ignore_block (const_tree block)
16098 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
16099 if (TREE_CODE (decl) == FUNCTION_DECL
16100 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16102 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
16104 decl = BLOCK_NONLOCALIZED_VAR (block, i);
16105 if (TREE_CODE (decl) == FUNCTION_DECL
16106 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16113 /* Hash table routines for file_hash. */
16116 file_table_eq (const void *p1_p, const void *p2_p)
16118 const struct dwarf_file_data *const p1 =
16119 (const struct dwarf_file_data *) p1_p;
16120 const char *const p2 = (const char *) p2_p;
16121 return strcmp (p1->filename, p2) == 0;
16125 file_table_hash (const void *p_p)
16127 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
16128 return htab_hash_string (p->filename);
16131 /* Lookup FILE_NAME (in the list of filenames that we know about here in
16132 dwarf2out.c) and return its "index". The index of each (known) filename is
16133 just a unique number which is associated with only that one filename. We
16134 need such numbers for the sake of generating labels (in the .debug_sfnames
16135 section) and references to those files numbers (in the .debug_srcinfo
16136 and.debug_macinfo sections). If the filename given as an argument is not
16137 found in our current list, add it to the list and assign it the next
16138 available unique index number. In order to speed up searches, we remember
16139 the index of the filename was looked up last. This handles the majority of
16142 static struct dwarf_file_data *
16143 lookup_filename (const char *file_name)
16146 struct dwarf_file_data * created;
16148 /* Check to see if the file name that was searched on the previous
16149 call matches this file name. If so, return the index. */
16150 if (file_table_last_lookup
16151 && (file_name == file_table_last_lookup->filename
16152 || strcmp (file_table_last_lookup->filename, file_name) == 0))
16153 return file_table_last_lookup;
16155 /* Didn't match the previous lookup, search the table. */
16156 slot = htab_find_slot_with_hash (file_table, file_name,
16157 htab_hash_string (file_name), INSERT);
16159 return (struct dwarf_file_data *) *slot;
16161 created = GGC_NEW (struct dwarf_file_data);
16162 created->filename = file_name;
16163 created->emitted_number = 0;
16168 /* If the assembler will construct the file table, then translate the compiler
16169 internal file table number into the assembler file table number, and emit
16170 a .file directive if we haven't already emitted one yet. The file table
16171 numbers are different because we prune debug info for unused variables and
16172 types, which may include filenames. */
16175 maybe_emit_file (struct dwarf_file_data * fd)
16177 if (! fd->emitted_number)
16179 if (last_emitted_file)
16180 fd->emitted_number = last_emitted_file->emitted_number + 1;
16182 fd->emitted_number = 1;
16183 last_emitted_file = fd;
16185 if (DWARF2_ASM_LINE_DEBUG_INFO)
16187 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
16188 output_quoted_string (asm_out_file,
16189 remap_debug_filename (fd->filename));
16190 fputc ('\n', asm_out_file);
16194 return fd->emitted_number;
16197 /* Replace DW_AT_name for the decl with name. */
16200 dwarf2out_set_name (tree decl, tree name)
16205 die = TYPE_SYMTAB_DIE (decl);
16209 attr = get_AT (die, DW_AT_name);
16212 struct indirect_string_node *node;
16214 node = find_AT_string (dwarf2_name (name, 0));
16215 /* replace the string. */
16216 attr->dw_attr_val.v.val_str = node;
16220 add_name_attribute (die, dwarf2_name (name, 0));
16223 /* Called by the final INSN scan whenever we see a var location. We
16224 use it to drop labels in the right places, and throw the location in
16225 our lookup table. */
16228 dwarf2out_var_location (rtx loc_note)
16230 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
16231 struct var_loc_node *newloc;
16233 static const char *last_label;
16234 static bool last_in_cold_section_p;
16237 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
16240 next_real = next_real_insn (loc_note);
16241 /* If there are no instructions which would be affected by this note,
16242 don't do anything. */
16243 if (next_real == NULL_RTX)
16246 newloc = GGC_CNEW (struct var_loc_node);
16247 /* If there were no real insns between note we processed last time
16248 and this note, use the label we emitted last time. */
16249 if (last_var_location_insn != NULL_RTX
16250 && last_var_location_insn == next_real
16251 && last_in_cold_section_p == in_cold_section_p)
16252 newloc->label = last_label;
16255 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
16256 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
16258 newloc->label = ggc_strdup (loclabel);
16260 newloc->var_loc_note = loc_note;
16261 newloc->next = NULL;
16263 if (cfun && in_cold_section_p)
16264 newloc->section_label = crtl->subsections.cold_section_label;
16266 newloc->section_label = text_section_label;
16268 last_var_location_insn = next_real;
16269 last_label = newloc->label;
16270 last_in_cold_section_p = in_cold_section_p;
16271 decl = NOTE_VAR_LOCATION_DECL (loc_note);
16272 add_var_loc_to_decl (decl, newloc);
16275 /* We need to reset the locations at the beginning of each
16276 function. We can't do this in the end_function hook, because the
16277 declarations that use the locations won't have been output when
16278 that hook is called. Also compute have_multiple_function_sections here. */
16281 dwarf2out_begin_function (tree fun)
16283 htab_empty (decl_loc_table);
16285 if (function_section (fun) != text_section)
16286 have_multiple_function_sections = true;
16288 dwarf2out_note_section_used ();
16291 /* Output a label to mark the beginning of a source code line entry
16292 and record information relating to this source line, in
16293 'line_info_table' for later output of the .debug_line section. */
16296 dwarf2out_source_line (unsigned int line, const char *filename,
16297 int discriminator, bool is_stmt)
16299 static bool last_is_stmt = true;
16301 if (debug_info_level >= DINFO_LEVEL_NORMAL
16304 int file_num = maybe_emit_file (lookup_filename (filename));
16306 switch_to_section (current_function_section ());
16308 /* If requested, emit something human-readable. */
16309 if (flag_debug_asm)
16310 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
16313 if (DWARF2_ASM_LINE_DEBUG_INFO)
16315 /* Emit the .loc directive understood by GNU as. */
16316 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
16317 if (is_stmt != last_is_stmt)
16319 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
16320 last_is_stmt = is_stmt;
16322 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
16323 fprintf (asm_out_file, " discriminator %d", discriminator);
16324 fputc ('\n', asm_out_file);
16326 /* Indicate that line number info exists. */
16327 line_info_table_in_use++;
16329 else if (function_section (current_function_decl) != text_section)
16331 dw_separate_line_info_ref line_info;
16332 targetm.asm_out.internal_label (asm_out_file,
16333 SEPARATE_LINE_CODE_LABEL,
16334 separate_line_info_table_in_use);
16336 /* Expand the line info table if necessary. */
16337 if (separate_line_info_table_in_use
16338 == separate_line_info_table_allocated)
16340 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16341 separate_line_info_table
16342 = GGC_RESIZEVEC (dw_separate_line_info_entry,
16343 separate_line_info_table,
16344 separate_line_info_table_allocated);
16345 memset (separate_line_info_table
16346 + separate_line_info_table_in_use,
16348 (LINE_INFO_TABLE_INCREMENT
16349 * sizeof (dw_separate_line_info_entry)));
16352 /* Add the new entry at the end of the line_info_table. */
16354 = &separate_line_info_table[separate_line_info_table_in_use++];
16355 line_info->dw_file_num = file_num;
16356 line_info->dw_line_num = line;
16357 line_info->function = current_function_funcdef_no;
16361 dw_line_info_ref line_info;
16363 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
16364 line_info_table_in_use);
16366 /* Expand the line info table if necessary. */
16367 if (line_info_table_in_use == line_info_table_allocated)
16369 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16371 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
16372 line_info_table_allocated);
16373 memset (line_info_table + line_info_table_in_use, 0,
16374 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
16377 /* Add the new entry at the end of the line_info_table. */
16378 line_info = &line_info_table[line_info_table_in_use++];
16379 line_info->dw_file_num = file_num;
16380 line_info->dw_line_num = line;
16385 /* Record the beginning of a new source file. */
16388 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
16390 if (flag_eliminate_dwarf2_dups)
16392 /* Record the beginning of the file for break_out_includes. */
16393 dw_die_ref bincl_die;
16395 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
16396 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
16399 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16401 int file_num = maybe_emit_file (lookup_filename (filename));
16403 switch_to_section (debug_macinfo_section);
16404 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
16405 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
16408 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
16412 /* Record the end of a source file. */
16415 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
16417 if (flag_eliminate_dwarf2_dups)
16418 /* Record the end of the file for break_out_includes. */
16419 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
16421 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16423 switch_to_section (debug_macinfo_section);
16424 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
16428 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16429 the tail part of the directive line, i.e. the part which is past the
16430 initial whitespace, #, whitespace, directive-name, whitespace part. */
16433 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
16434 const char *buffer ATTRIBUTE_UNUSED)
16436 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16438 switch_to_section (debug_macinfo_section);
16439 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
16440 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16441 dw2_asm_output_nstring (buffer, -1, "The macro");
16445 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16446 the tail part of the directive line, i.e. the part which is past the
16447 initial whitespace, #, whitespace, directive-name, whitespace part. */
16450 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
16451 const char *buffer ATTRIBUTE_UNUSED)
16453 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16455 switch_to_section (debug_macinfo_section);
16456 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
16457 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16458 dw2_asm_output_nstring (buffer, -1, "The macro");
16462 /* Set up for Dwarf output at the start of compilation. */
16465 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
16467 /* Allocate the file_table. */
16468 file_table = htab_create_ggc (50, file_table_hash,
16469 file_table_eq, NULL);
16471 /* Allocate the decl_die_table. */
16472 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16473 decl_die_table_eq, NULL);
16475 /* Allocate the decl_loc_table. */
16476 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16477 decl_loc_table_eq, NULL);
16479 /* Allocate the initial hunk of the decl_scope_table. */
16480 decl_scope_table = VEC_alloc (tree, gc, 256);
16482 /* Allocate the initial hunk of the abbrev_die_table. */
16483 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16484 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16485 /* Zero-th entry is allocated, but unused. */
16486 abbrev_die_table_in_use = 1;
16488 /* Allocate the initial hunk of the line_info_table. */
16489 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16490 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16492 /* Zero-th entry is allocated, but unused. */
16493 line_info_table_in_use = 1;
16495 /* Allocate the pubtypes and pubnames vectors. */
16496 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16497 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16499 /* Generate the initial DIE for the .debug section. Note that the (string)
16500 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16501 will (typically) be a relative pathname and that this pathname should be
16502 taken as being relative to the directory from which the compiler was
16503 invoked when the given (base) source file was compiled. We will fill
16504 in this value in dwarf2out_finish. */
16505 comp_unit_die = gen_compile_unit_die (NULL);
16507 incomplete_types = VEC_alloc (tree, gc, 64);
16509 used_rtx_array = VEC_alloc (rtx, gc, 32);
16511 debug_info_section = get_section (DEBUG_INFO_SECTION,
16512 SECTION_DEBUG, NULL);
16513 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16514 SECTION_DEBUG, NULL);
16515 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16516 SECTION_DEBUG, NULL);
16517 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16518 SECTION_DEBUG, NULL);
16519 debug_line_section = get_section (DEBUG_LINE_SECTION,
16520 SECTION_DEBUG, NULL);
16521 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16522 SECTION_DEBUG, NULL);
16523 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16524 SECTION_DEBUG, NULL);
16525 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16526 SECTION_DEBUG, NULL);
16527 debug_str_section = get_section (DEBUG_STR_SECTION,
16528 DEBUG_STR_SECTION_FLAGS, NULL);
16529 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16530 SECTION_DEBUG, NULL);
16531 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16532 SECTION_DEBUG, NULL);
16534 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16535 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16536 DEBUG_ABBREV_SECTION_LABEL, 0);
16537 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16538 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16539 COLD_TEXT_SECTION_LABEL, 0);
16540 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16542 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16543 DEBUG_INFO_SECTION_LABEL, 0);
16544 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16545 DEBUG_LINE_SECTION_LABEL, 0);
16546 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16547 DEBUG_RANGES_SECTION_LABEL, 0);
16548 switch_to_section (debug_abbrev_section);
16549 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16550 switch_to_section (debug_info_section);
16551 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16552 switch_to_section (debug_line_section);
16553 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16555 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16557 switch_to_section (debug_macinfo_section);
16558 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16559 DEBUG_MACINFO_SECTION_LABEL, 0);
16560 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16563 switch_to_section (text_section);
16564 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16565 if (flag_reorder_blocks_and_partition)
16567 cold_text_section = unlikely_text_section ();
16568 switch_to_section (cold_text_section);
16569 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16573 /* A helper function for dwarf2out_finish called through
16574 ht_forall. Emit one queued .debug_str string. */
16577 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16579 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16581 if (node->form == DW_FORM_strp)
16583 switch_to_section (debug_str_section);
16584 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16585 assemble_string (node->str, strlen (node->str) + 1);
16591 #if ENABLE_ASSERT_CHECKING
16592 /* Verify that all marks are clear. */
16595 verify_marks_clear (dw_die_ref die)
16599 gcc_assert (! die->die_mark);
16600 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16602 #endif /* ENABLE_ASSERT_CHECKING */
16604 /* Clear the marks for a die and its children.
16605 Be cool if the mark isn't set. */
16608 prune_unmark_dies (dw_die_ref die)
16614 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16617 /* Given DIE that we're marking as used, find any other dies
16618 it references as attributes and mark them as used. */
16621 prune_unused_types_walk_attribs (dw_die_ref die)
16626 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16628 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16630 /* A reference to another DIE.
16631 Make sure that it will get emitted. */
16632 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16634 /* Set the string's refcount to 0 so that prune_unused_types_mark
16635 accounts properly for it. */
16636 if (AT_class (a) == dw_val_class_str)
16637 a->dw_attr_val.v.val_str->refcount = 0;
16642 /* Mark DIE as being used. If DOKIDS is true, then walk down
16643 to DIE's children. */
16646 prune_unused_types_mark (dw_die_ref die, int dokids)
16650 if (die->die_mark == 0)
16652 /* We haven't done this node yet. Mark it as used. */
16655 /* We also have to mark its parents as used.
16656 (But we don't want to mark our parents' kids due to this.) */
16657 if (die->die_parent)
16658 prune_unused_types_mark (die->die_parent, 0);
16660 /* Mark any referenced nodes. */
16661 prune_unused_types_walk_attribs (die);
16663 /* If this node is a specification,
16664 also mark the definition, if it exists. */
16665 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
16666 prune_unused_types_mark (die->die_definition, 1);
16669 if (dokids && die->die_mark != 2)
16671 /* We need to walk the children, but haven't done so yet.
16672 Remember that we've walked the kids. */
16675 /* If this is an array type, we need to make sure our
16676 kids get marked, even if they're types. */
16677 if (die->die_tag == DW_TAG_array_type)
16678 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
16680 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16684 /* For local classes, look if any static member functions were emitted
16685 and if so, mark them. */
16688 prune_unused_types_walk_local_classes (dw_die_ref die)
16692 if (die->die_mark == 2)
16695 switch (die->die_tag)
16697 case DW_TAG_structure_type:
16698 case DW_TAG_union_type:
16699 case DW_TAG_class_type:
16702 case DW_TAG_subprogram:
16703 if (!get_AT_flag (die, DW_AT_declaration)
16704 || die->die_definition != NULL)
16705 prune_unused_types_mark (die, 1);
16712 /* Mark children. */
16713 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
16716 /* Walk the tree DIE and mark types that we actually use. */
16719 prune_unused_types_walk (dw_die_ref die)
16723 /* Don't do anything if this node is already marked and
16724 children have been marked as well. */
16725 if (die->die_mark == 2)
16728 switch (die->die_tag)
16730 case DW_TAG_structure_type:
16731 case DW_TAG_union_type:
16732 case DW_TAG_class_type:
16733 if (die->die_perennial_p)
16736 for (c = die->die_parent; c; c = c->die_parent)
16737 if (c->die_tag == DW_TAG_subprogram)
16740 /* Finding used static member functions inside of classes
16741 is needed just for local classes, because for other classes
16742 static member function DIEs with DW_AT_specification
16743 are emitted outside of the DW_TAG_*_type. If we ever change
16744 it, we'd need to call this even for non-local classes. */
16746 prune_unused_types_walk_local_classes (die);
16748 /* It's a type node --- don't mark it. */
16751 case DW_TAG_const_type:
16752 case DW_TAG_packed_type:
16753 case DW_TAG_pointer_type:
16754 case DW_TAG_reference_type:
16755 case DW_TAG_volatile_type:
16756 case DW_TAG_typedef:
16757 case DW_TAG_array_type:
16758 case DW_TAG_interface_type:
16759 case DW_TAG_friend:
16760 case DW_TAG_variant_part:
16761 case DW_TAG_enumeration_type:
16762 case DW_TAG_subroutine_type:
16763 case DW_TAG_string_type:
16764 case DW_TAG_set_type:
16765 case DW_TAG_subrange_type:
16766 case DW_TAG_ptr_to_member_type:
16767 case DW_TAG_file_type:
16768 if (die->die_perennial_p)
16771 /* It's a type node --- don't mark it. */
16775 /* Mark everything else. */
16779 if (die->die_mark == 0)
16783 /* Now, mark any dies referenced from here. */
16784 prune_unused_types_walk_attribs (die);
16789 /* Mark children. */
16790 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16793 /* Increment the string counts on strings referred to from DIE's
16797 prune_unused_types_update_strings (dw_die_ref die)
16802 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16803 if (AT_class (a) == dw_val_class_str)
16805 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
16807 /* Avoid unnecessarily putting strings that are used less than
16808 twice in the hash table. */
16810 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
16813 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
16814 htab_hash_string (s->str),
16816 gcc_assert (*slot == NULL);
16822 /* Remove from the tree DIE any dies that aren't marked. */
16825 prune_unused_types_prune (dw_die_ref die)
16829 gcc_assert (die->die_mark);
16830 prune_unused_types_update_strings (die);
16832 if (! die->die_child)
16835 c = die->die_child;
16837 dw_die_ref prev = c;
16838 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
16839 if (c == die->die_child)
16841 /* No marked children between 'prev' and the end of the list. */
16843 /* No marked children at all. */
16844 die->die_child = NULL;
16847 prev->die_sib = c->die_sib;
16848 die->die_child = prev;
16853 if (c != prev->die_sib)
16855 prune_unused_types_prune (c);
16856 } while (c != die->die_child);
16860 /* Remove dies representing declarations that we never use. */
16863 prune_unused_types (void)
16866 limbo_die_node *node;
16869 #if ENABLE_ASSERT_CHECKING
16870 /* All the marks should already be clear. */
16871 verify_marks_clear (comp_unit_die);
16872 for (node = limbo_die_list; node; node = node->next)
16873 verify_marks_clear (node->die);
16874 #endif /* ENABLE_ASSERT_CHECKING */
16876 /* Set the mark on nodes that are actually used. */
16877 prune_unused_types_walk (comp_unit_die);
16878 for (node = limbo_die_list; node; node = node->next)
16879 prune_unused_types_walk (node->die);
16881 /* Also set the mark on nodes referenced from the
16882 pubname_table or arange_table. */
16883 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
16884 prune_unused_types_mark (pub->die, 1);
16885 for (i = 0; i < arange_table_in_use; i++)
16886 prune_unused_types_mark (arange_table[i], 1);
16888 /* Get rid of nodes that aren't marked; and update the string counts. */
16889 if (debug_str_hash)
16890 htab_empty (debug_str_hash);
16891 prune_unused_types_prune (comp_unit_die);
16892 for (node = limbo_die_list; node; node = node->next)
16893 prune_unused_types_prune (node->die);
16895 /* Leave the marks clear. */
16896 prune_unmark_dies (comp_unit_die);
16897 for (node = limbo_die_list; node; node = node->next)
16898 prune_unmark_dies (node->die);
16901 /* Set the parameter to true if there are any relative pathnames in
16904 file_table_relative_p (void ** slot, void *param)
16906 bool *p = (bool *) param;
16907 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16908 if (!IS_ABSOLUTE_PATH (d->filename))
16916 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
16917 to the location it would have been added, should we know its
16918 DECL_ASSEMBLER_NAME when we added other attributes. This will
16919 probably improve compactness of debug info, removing equivalent
16920 abbrevs, and hide any differences caused by deferring the
16921 computation of the assembler name, triggered by e.g. PCH. */
16924 move_linkage_attr (dw_die_ref die)
16926 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
16927 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
16929 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
16933 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
16935 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
16939 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
16941 VEC_pop (dw_attr_node, die->die_attr);
16942 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
16946 /* Output stuff that dwarf requires at the end of every file,
16947 and generate the DWARF-2 debugging info. */
16950 dwarf2out_finish (const char *filename)
16952 limbo_die_node *node, *next_node;
16953 dw_die_ref die = 0;
16956 /* Add the name for the main input file now. We delayed this from
16957 dwarf2out_init to avoid complications with PCH. */
16958 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
16959 if (!IS_ABSOLUTE_PATH (filename))
16960 add_comp_dir_attribute (comp_unit_die);
16961 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
16964 htab_traverse (file_table, file_table_relative_p, &p);
16966 add_comp_dir_attribute (comp_unit_die);
16969 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
16971 add_location_or_const_value_attribute (
16972 VEC_index (deferred_locations, deferred_locations_list, i)->die,
16973 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
16977 /* Traverse the limbo die list, and add parent/child links. The only
16978 dies without parents that should be here are concrete instances of
16979 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16980 For concrete instances, we can get the parent die from the abstract
16982 for (node = limbo_die_list; node; node = next_node)
16984 next_node = node->next;
16987 if (die->die_parent == NULL)
16989 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
16992 add_child_die (origin->die_parent, die);
16993 else if (die == comp_unit_die)
16995 else if (errorcount > 0 || sorrycount > 0)
16996 /* It's OK to be confused by errors in the input. */
16997 add_child_die (comp_unit_die, die);
17000 /* In certain situations, the lexical block containing a
17001 nested function can be optimized away, which results
17002 in the nested function die being orphaned. Likewise
17003 with the return type of that nested function. Force
17004 this to be a child of the containing function.
17006 It may happen that even the containing function got fully
17007 inlined and optimized out. In that case we are lost and
17008 assign the empty child. This should not be big issue as
17009 the function is likely unreachable too. */
17010 tree context = NULL_TREE;
17012 gcc_assert (node->created_for);
17014 if (DECL_P (node->created_for))
17015 context = DECL_CONTEXT (node->created_for);
17016 else if (TYPE_P (node->created_for))
17017 context = TYPE_CONTEXT (node->created_for);
17019 gcc_assert (context
17020 && (TREE_CODE (context) == FUNCTION_DECL
17021 || TREE_CODE (context) == NAMESPACE_DECL));
17023 origin = lookup_decl_die (context);
17025 add_child_die (origin, die);
17027 add_child_die (comp_unit_die, die);
17032 limbo_die_list = NULL;
17034 for (node = deferred_asm_name; node; node = node->next)
17036 tree decl = node->created_for;
17037 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17039 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
17040 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
17041 move_linkage_attr (node->die);
17045 deferred_asm_name = NULL;
17047 /* Walk through the list of incomplete types again, trying once more to
17048 emit full debugging info for them. */
17049 retry_incomplete_types ();
17051 if (flag_eliminate_unused_debug_types)
17052 prune_unused_types ();
17054 /* Generate separate CUs for each of the include files we've seen.
17055 They will go into limbo_die_list. */
17056 if (flag_eliminate_dwarf2_dups)
17057 break_out_includes (comp_unit_die);
17059 /* Traverse the DIE's and add add sibling attributes to those DIE's
17060 that have children. */
17061 add_sibling_attributes (comp_unit_die);
17062 for (node = limbo_die_list; node; node = node->next)
17063 add_sibling_attributes (node->die);
17065 /* Output a terminator label for the .text section. */
17066 switch_to_section (text_section);
17067 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
17068 if (flag_reorder_blocks_and_partition)
17070 switch_to_section (unlikely_text_section ());
17071 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
17074 /* We can only use the low/high_pc attributes if all of the code was
17076 if (!have_multiple_function_sections)
17078 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
17079 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
17084 unsigned fde_idx = 0;
17086 /* We need to give .debug_loc and .debug_ranges an appropriate
17087 "base address". Use zero so that these addresses become
17088 absolute. Historically, we've emitted the unexpected
17089 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
17090 Emit both to give time for other tools to adapt. */
17091 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
17092 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
17094 add_AT_range_list (comp_unit_die, DW_AT_ranges,
17095 add_ranges_by_labels (text_section_label,
17097 if (flag_reorder_blocks_and_partition)
17098 add_ranges_by_labels (cold_text_section_label,
17101 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
17103 dw_fde_ref fde = &fde_table[fde_idx];
17105 if (fde->dw_fde_switched_sections)
17107 add_ranges_by_labels (fde->dw_fde_hot_section_label,
17108 fde->dw_fde_hot_section_end_label);
17109 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
17110 fde->dw_fde_unlikely_section_end_label);
17113 add_ranges_by_labels (fde->dw_fde_begin,
17120 /* Output location list section if necessary. */
17121 if (have_location_lists)
17123 /* Output the location lists info. */
17124 switch_to_section (debug_loc_section);
17125 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
17126 DEBUG_LOC_SECTION_LABEL, 0);
17127 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
17128 output_location_lists (die);
17131 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17132 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
17133 debug_line_section_label);
17135 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17136 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
17138 /* Output all of the compilation units. We put the main one last so that
17139 the offsets are available to output_pubnames. */
17140 for (node = limbo_die_list; node; node = node->next)
17141 output_comp_unit (node->die, 0);
17143 /* Output the main compilation unit if non-empty or if .debug_macinfo
17144 has been emitted. */
17145 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
17147 /* Output the abbreviation table. */
17148 switch_to_section (debug_abbrev_section);
17149 output_abbrev_section ();
17151 /* Output public names table if necessary. */
17152 if (!VEC_empty (pubname_entry, pubname_table))
17154 switch_to_section (debug_pubnames_section);
17155 output_pubnames (pubname_table);
17158 /* Output public types table if necessary. */
17159 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
17160 It shouldn't hurt to emit it always, since pure DWARF2 consumers
17161 simply won't look for the section. */
17162 if (!VEC_empty (pubname_entry, pubtype_table))
17164 switch_to_section (debug_pubtypes_section);
17165 output_pubnames (pubtype_table);
17168 /* Output the address range information. We only put functions in the arange
17169 table, so don't write it out if we don't have any. */
17170 if (fde_table_in_use)
17172 switch_to_section (debug_aranges_section);
17176 /* Output ranges section if necessary. */
17177 if (ranges_table_in_use)
17179 switch_to_section (debug_ranges_section);
17180 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
17184 /* Output the source line correspondence table. We must do this
17185 even if there is no line information. Otherwise, on an empty
17186 translation unit, we will generate a present, but empty,
17187 .debug_info section. IRIX 6.5 `nm' will then complain when
17188 examining the file. This is done late so that any filenames
17189 used by the debug_info section are marked as 'used'. */
17190 if (! DWARF2_ASM_LINE_DEBUG_INFO)
17192 switch_to_section (debug_line_section);
17193 output_line_info ();
17196 /* Have to end the macro section. */
17197 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17199 switch_to_section (debug_macinfo_section);
17200 dw2_asm_output_data (1, 0, "End compilation unit");
17203 /* If we emitted any DW_FORM_strp form attribute, output the string
17205 if (debug_str_hash)
17206 htab_traverse (debug_str_hash, output_indirect_string, NULL);
17210 /* This should never be used, but its address is needed for comparisons. */
17211 const struct gcc_debug_hooks dwarf2_debug_hooks =
17217 0, /* start_source_file */
17218 0, /* end_source_file */
17219 0, /* begin_block */
17221 0, /* ignore_block */
17222 0, /* source_line */
17223 0, /* begin_prologue */
17224 0, /* end_prologue */
17225 0, /* end_epilogue */
17226 0, /* begin_function */
17227 0, /* end_function */
17228 0, /* function_decl */
17229 0, /* global_decl */
17231 0, /* imported_module_or_decl */
17232 0, /* deferred_inline_function */
17233 0, /* outlining_inline_function */
17235 0, /* handle_pch */
17236 0, /* var_location */
17237 0, /* switch_text_section */
17239 0 /* start_end_main_source_file */
17242 #endif /* DWARF2_DEBUGGING_INFO */
17244 #include "gt-dwarf2out.h"