1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *, 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;
286 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
287 unsigned in_std_section : 1;
288 /* True iff dw_fde_unlikely_section_label is in text_section or
289 cold_text_section. */
290 unsigned cold_in_std_section : 1;
294 /* Maximum size (in bytes) of an artificially generated label. */
295 #define MAX_ARTIFICIAL_LABEL_BYTES 30
297 /* The size of addresses as they appear in the Dwarf 2 data.
298 Some architectures use word addresses to refer to code locations,
299 but Dwarf 2 info always uses byte addresses. On such machines,
300 Dwarf 2 addresses need to be larger than the architecture's
302 #ifndef DWARF2_ADDR_SIZE
303 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
306 /* The size in bytes of a DWARF field indicating an offset or length
307 relative to a debug info section, specified to be 4 bytes in the
308 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
311 #ifndef DWARF_OFFSET_SIZE
312 #define DWARF_OFFSET_SIZE 4
315 /* According to the (draft) DWARF 3 specification, the initial length
316 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
317 bytes are 0xffffffff, followed by the length stored in the next 8
320 However, the SGI/MIPS ABI uses an initial length which is equal to
321 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
323 #ifndef DWARF_INITIAL_LENGTH_SIZE
324 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
327 /* Round SIZE up to the nearest BOUNDARY. */
328 #define DWARF_ROUND(SIZE,BOUNDARY) \
329 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
331 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
332 #ifndef DWARF_CIE_DATA_ALIGNMENT
333 #ifdef STACK_GROWS_DOWNWARD
334 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
336 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
340 /* CIE identifier. */
341 #if HOST_BITS_PER_WIDE_INT >= 64
342 #define DWARF_CIE_ID \
343 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
345 #define DWARF_CIE_ID DW_CIE_ID
348 /* A pointer to the base of a table that contains frame description
349 information for each routine. */
350 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
352 /* Number of elements currently allocated for fde_table. */
353 static GTY(()) unsigned fde_table_allocated;
355 /* Number of elements in fde_table currently in use. */
356 static GTY(()) unsigned fde_table_in_use;
358 /* Size (in elements) of increments by which we may expand the
360 #define FDE_TABLE_INCREMENT 256
362 /* Get the current fde_table entry we should use. */
364 static inline dw_fde_ref
367 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
370 /* A list of call frame insns for the CIE. */
371 static GTY(()) dw_cfi_ref cie_cfi_head;
373 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
374 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
375 attribute that accelerates the lookup of the FDE associated
376 with the subprogram. This variable holds the table index of the FDE
377 associated with the current function (body) definition. */
378 static unsigned current_funcdef_fde;
381 struct GTY(()) indirect_string_node {
383 unsigned int refcount;
384 enum dwarf_form form;
388 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
390 static GTY(()) int dw2_string_counter;
391 static GTY(()) unsigned long dwarf2out_cfi_label_num;
393 /* True if the compilation unit places functions in more than one section. */
394 static GTY(()) bool have_multiple_function_sections = false;
396 /* Whether the default text and cold text sections have been used at all. */
398 static GTY(()) bool text_section_used = false;
399 static GTY(()) bool cold_text_section_used = false;
401 /* The default cold text section. */
402 static GTY(()) section *cold_text_section;
404 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
406 /* Forward declarations for functions defined in this file. */
408 static char *stripattributes (const char *);
409 static const char *dwarf_cfi_name (unsigned);
410 static dw_cfi_ref new_cfi (void);
411 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
412 static void add_fde_cfi (const char *, dw_cfi_ref);
413 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
414 static void lookup_cfa (dw_cfa_location *);
415 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
416 #ifdef DWARF2_UNWIND_INFO
417 static void initial_return_save (rtx);
419 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
421 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
422 static void output_cfi_directive (dw_cfi_ref);
423 static void output_call_frame_info (int);
424 static void dwarf2out_note_section_used (void);
425 static void dwarf2out_stack_adjust (rtx, bool);
426 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
427 static void flush_queued_reg_saves (void);
428 static bool clobbers_queued_reg_save (const_rtx);
429 static void dwarf2out_frame_debug_expr (rtx, const char *);
431 /* Support for complex CFA locations. */
432 static void output_cfa_loc (dw_cfi_ref);
433 static void output_cfa_loc_raw (dw_cfi_ref);
434 static void get_cfa_from_loc_descr (dw_cfa_location *,
435 struct dw_loc_descr_struct *);
436 static struct dw_loc_descr_struct *build_cfa_loc
437 (dw_cfa_location *, HOST_WIDE_INT);
438 static struct dw_loc_descr_struct *build_cfa_aligned_loc
439 (HOST_WIDE_INT, HOST_WIDE_INT);
440 static void def_cfa_1 (const char *, dw_cfa_location *);
442 /* How to start an assembler comment. */
443 #ifndef ASM_COMMENT_START
444 #define ASM_COMMENT_START ";#"
447 /* Data and reference forms for relocatable data. */
448 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
449 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
451 #ifndef DEBUG_FRAME_SECTION
452 #define DEBUG_FRAME_SECTION ".debug_frame"
455 #ifndef FUNC_BEGIN_LABEL
456 #define FUNC_BEGIN_LABEL "LFB"
459 #ifndef FUNC_END_LABEL
460 #define FUNC_END_LABEL "LFE"
463 #ifndef FRAME_BEGIN_LABEL
464 #define FRAME_BEGIN_LABEL "Lframe"
466 #define CIE_AFTER_SIZE_LABEL "LSCIE"
467 #define CIE_END_LABEL "LECIE"
468 #define FDE_LABEL "LSFDE"
469 #define FDE_AFTER_SIZE_LABEL "LASFDE"
470 #define FDE_END_LABEL "LEFDE"
471 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
472 #define LINE_NUMBER_END_LABEL "LELT"
473 #define LN_PROLOG_AS_LABEL "LASLTP"
474 #define LN_PROLOG_END_LABEL "LELTP"
475 #define DIE_LABEL_PREFIX "DW"
477 /* The DWARF 2 CFA column which tracks the return address. Normally this
478 is the column for PC, or the first column after all of the hard
480 #ifndef DWARF_FRAME_RETURN_COLUMN
482 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
484 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
488 /* The mapping from gcc register number to DWARF 2 CFA column number. By
489 default, we just provide columns for all registers. */
490 #ifndef DWARF_FRAME_REGNUM
491 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
494 /* Hook used by __throw. */
497 expand_builtin_dwarf_sp_column (void)
499 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
500 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
503 /* Return a pointer to a copy of the section string name S with all
504 attributes stripped off, and an asterisk prepended (for assemble_name). */
507 stripattributes (const char *s)
509 char *stripped = XNEWVEC (char, strlen (s) + 2);
514 while (*s && *s != ',')
521 /* MEM is a memory reference for the register size table, each element of
522 which has mode MODE. Initialize column C as a return address column. */
525 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
527 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
528 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
529 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
532 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
534 static inline HOST_WIDE_INT
535 div_data_align (HOST_WIDE_INT off)
537 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
538 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
542 /* Return true if we need a signed version of a given opcode
543 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
546 need_data_align_sf_opcode (HOST_WIDE_INT off)
548 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
551 /* Generate code to initialize the register size table. */
554 expand_builtin_init_dwarf_reg_sizes (tree address)
557 enum machine_mode mode = TYPE_MODE (char_type_node);
558 rtx addr = expand_normal (address);
559 rtx mem = gen_rtx_MEM (BLKmode, addr);
560 bool wrote_return_column = false;
562 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
564 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
566 if (rnum < DWARF_FRAME_REGISTERS)
568 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
569 enum machine_mode save_mode = reg_raw_mode[i];
572 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
573 save_mode = choose_hard_reg_mode (i, 1, true);
574 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
576 if (save_mode == VOIDmode)
578 wrote_return_column = true;
580 size = GET_MODE_SIZE (save_mode);
584 emit_move_insn (adjust_address (mem, mode, offset),
585 gen_int_mode (size, mode));
589 if (!wrote_return_column)
590 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
592 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
593 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
596 targetm.init_dwarf_reg_sizes_extra (address);
599 /* Convert a DWARF call frame info. operation to its string name */
602 dwarf_cfi_name (unsigned int cfi_opc)
606 case DW_CFA_advance_loc:
607 return "DW_CFA_advance_loc";
609 return "DW_CFA_offset";
611 return "DW_CFA_restore";
615 return "DW_CFA_set_loc";
616 case DW_CFA_advance_loc1:
617 return "DW_CFA_advance_loc1";
618 case DW_CFA_advance_loc2:
619 return "DW_CFA_advance_loc2";
620 case DW_CFA_advance_loc4:
621 return "DW_CFA_advance_loc4";
622 case DW_CFA_offset_extended:
623 return "DW_CFA_offset_extended";
624 case DW_CFA_restore_extended:
625 return "DW_CFA_restore_extended";
626 case DW_CFA_undefined:
627 return "DW_CFA_undefined";
628 case DW_CFA_same_value:
629 return "DW_CFA_same_value";
630 case DW_CFA_register:
631 return "DW_CFA_register";
632 case DW_CFA_remember_state:
633 return "DW_CFA_remember_state";
634 case DW_CFA_restore_state:
635 return "DW_CFA_restore_state";
637 return "DW_CFA_def_cfa";
638 case DW_CFA_def_cfa_register:
639 return "DW_CFA_def_cfa_register";
640 case DW_CFA_def_cfa_offset:
641 return "DW_CFA_def_cfa_offset";
644 case DW_CFA_def_cfa_expression:
645 return "DW_CFA_def_cfa_expression";
646 case DW_CFA_expression:
647 return "DW_CFA_expression";
648 case DW_CFA_offset_extended_sf:
649 return "DW_CFA_offset_extended_sf";
650 case DW_CFA_def_cfa_sf:
651 return "DW_CFA_def_cfa_sf";
652 case DW_CFA_def_cfa_offset_sf:
653 return "DW_CFA_def_cfa_offset_sf";
655 /* SGI/MIPS specific */
656 case DW_CFA_MIPS_advance_loc8:
657 return "DW_CFA_MIPS_advance_loc8";
660 case DW_CFA_GNU_window_save:
661 return "DW_CFA_GNU_window_save";
662 case DW_CFA_GNU_args_size:
663 return "DW_CFA_GNU_args_size";
664 case DW_CFA_GNU_negative_offset_extended:
665 return "DW_CFA_GNU_negative_offset_extended";
668 return "DW_CFA_<unknown>";
672 /* Return a pointer to a newly allocated Call Frame Instruction. */
674 static inline dw_cfi_ref
677 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
679 cfi->dw_cfi_next = NULL;
680 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
681 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
686 /* Add a Call Frame Instruction to list of instructions. */
689 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
692 dw_fde_ref fde = current_fde ();
694 /* When DRAP is used, CFA is defined with an expression. Redefine
695 CFA may lead to a different CFA value. */
696 /* ??? Of course, this heuristic fails when we're annotating epilogues,
697 because of course we'll always want to redefine the CFA back to the
698 stack pointer on the way out. Where should we move this check? */
699 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
700 switch (cfi->dw_cfi_opc)
702 case DW_CFA_def_cfa_register:
703 case DW_CFA_def_cfa_offset:
704 case DW_CFA_def_cfa_offset_sf:
706 case DW_CFA_def_cfa_sf:
713 /* Find the end of the chain. */
714 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
720 /* Generate a new label for the CFI info to refer to. FORCE is true
721 if a label needs to be output even when using .cfi_* directives. */
724 dwarf2out_cfi_label (bool force)
726 static char label[20];
728 if (!force && dwarf2out_do_cfi_asm ())
730 /* In this case, we will be emitting the asm directive instead of
731 the label, so just return a placeholder to keep the rest of the
733 strcpy (label, "<do not output>");
737 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
738 ASM_OUTPUT_LABEL (asm_out_file, label);
744 /* True if remember_state should be emitted before following CFI directive. */
745 static bool emit_cfa_remember;
747 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
748 or to the CIE if LABEL is NULL. */
751 add_fde_cfi (const char *label, dw_cfi_ref cfi)
753 dw_cfi_ref *list_head;
755 if (emit_cfa_remember)
757 dw_cfi_ref cfi_remember;
759 /* Emit the state save. */
760 emit_cfa_remember = false;
761 cfi_remember = new_cfi ();
762 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
763 add_fde_cfi (label, cfi_remember);
766 list_head = &cie_cfi_head;
768 if (dwarf2out_do_cfi_asm ())
772 dw_fde_ref fde = current_fde ();
774 gcc_assert (fde != NULL);
776 /* We still have to add the cfi to the list so that lookup_cfa
777 works later on. When -g2 and above we even need to force
778 emitting of CFI labels and add to list a DW_CFA_set_loc for
779 convert_cfa_to_fb_loc_list purposes. If we're generating
780 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
781 convert_cfa_to_fb_loc_list. */
782 if (dwarf_version == 2
783 && debug_info_level > DINFO_LEVEL_TERSE
784 && (write_symbols == DWARF2_DEBUG
785 || write_symbols == VMS_AND_DWARF2_DEBUG))
787 switch (cfi->dw_cfi_opc)
789 case DW_CFA_def_cfa_offset:
790 case DW_CFA_def_cfa_offset_sf:
791 case DW_CFA_def_cfa_register:
793 case DW_CFA_def_cfa_sf:
794 case DW_CFA_def_cfa_expression:
795 case DW_CFA_restore_state:
796 if (*label == 0 || strcmp (label, "<do not output>") == 0)
797 label = dwarf2out_cfi_label (true);
799 if (fde->dw_fde_current_label == NULL
800 || strcmp (label, fde->dw_fde_current_label) != 0)
804 label = xstrdup (label);
806 /* Set the location counter to the new label. */
808 /* It doesn't metter whether DW_CFA_set_loc
809 or DW_CFA_advance_loc4 is added here, those aren't
810 emitted into assembly, only looked up by
811 convert_cfa_to_fb_loc_list. */
812 xcfi->dw_cfi_opc = DW_CFA_set_loc;
813 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
814 add_cfi (&fde->dw_fde_cfi, xcfi);
815 fde->dw_fde_current_label = label;
823 output_cfi_directive (cfi);
825 list_head = &fde->dw_fde_cfi;
827 /* ??? If this is a CFI for the CIE, we don't emit. This
828 assumes that the standard CIE contents that the assembler
829 uses matches the standard CIE contents that the compiler
830 uses. This is probably a bad assumption. I'm not quite
831 sure how to address this for now. */
835 dw_fde_ref fde = current_fde ();
837 gcc_assert (fde != NULL);
840 label = dwarf2out_cfi_label (false);
842 if (fde->dw_fde_current_label == NULL
843 || strcmp (label, fde->dw_fde_current_label) != 0)
847 label = xstrdup (label);
849 /* Set the location counter to the new label. */
851 /* If we have a current label, advance from there, otherwise
852 set the location directly using set_loc. */
853 xcfi->dw_cfi_opc = fde->dw_fde_current_label
854 ? DW_CFA_advance_loc4
856 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
857 add_cfi (&fde->dw_fde_cfi, xcfi);
859 fde->dw_fde_current_label = label;
862 list_head = &fde->dw_fde_cfi;
865 add_cfi (list_head, cfi);
868 /* Subroutine of lookup_cfa. */
871 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
873 switch (cfi->dw_cfi_opc)
875 case DW_CFA_def_cfa_offset:
876 case DW_CFA_def_cfa_offset_sf:
877 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
879 case DW_CFA_def_cfa_register:
880 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
883 case DW_CFA_def_cfa_sf:
884 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
885 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
887 case DW_CFA_def_cfa_expression:
888 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
891 case DW_CFA_remember_state:
892 gcc_assert (!remember->in_use);
894 remember->in_use = 1;
896 case DW_CFA_restore_state:
897 gcc_assert (remember->in_use);
899 remember->in_use = 0;
907 /* Find the previous value for the CFA. */
910 lookup_cfa (dw_cfa_location *loc)
914 dw_cfa_location remember;
916 memset (loc, 0, sizeof (*loc));
917 loc->reg = INVALID_REGNUM;
920 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
921 lookup_cfa_1 (cfi, loc, &remember);
923 fde = current_fde ();
925 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
926 lookup_cfa_1 (cfi, loc, &remember);
929 /* The current rule for calculating the DWARF2 canonical frame address. */
930 static dw_cfa_location cfa;
932 /* The register used for saving registers to the stack, and its offset
934 static dw_cfa_location cfa_store;
936 /* The current save location around an epilogue. */
937 static dw_cfa_location cfa_remember;
939 /* The running total of the size of arguments pushed onto the stack. */
940 static HOST_WIDE_INT args_size;
942 /* The last args_size we actually output. */
943 static HOST_WIDE_INT old_args_size;
945 /* Entry point to update the canonical frame address (CFA).
946 LABEL is passed to add_fde_cfi. The value of CFA is now to be
947 calculated from REG+OFFSET. */
950 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
957 def_cfa_1 (label, &loc);
960 /* Determine if two dw_cfa_location structures define the same data. */
963 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
965 return (loc1->reg == loc2->reg
966 && loc1->offset == loc2->offset
967 && loc1->indirect == loc2->indirect
968 && (loc1->indirect == 0
969 || loc1->base_offset == loc2->base_offset));
972 /* This routine does the actual work. The CFA is now calculated from
973 the dw_cfa_location structure. */
976 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
979 dw_cfa_location old_cfa, loc;
984 if (cfa_store.reg == loc.reg && loc.indirect == 0)
985 cfa_store.offset = loc.offset;
987 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
988 lookup_cfa (&old_cfa);
990 /* If nothing changed, no need to issue any call frame instructions. */
991 if (cfa_equal_p (&loc, &old_cfa))
996 if (loc.reg == old_cfa.reg && !loc.indirect)
998 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
999 the CFA register did not change but the offset did. The data
1000 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1001 in the assembler via the .cfi_def_cfa_offset directive. */
1003 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1005 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1006 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1009 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1010 else if (loc.offset == old_cfa.offset
1011 && old_cfa.reg != INVALID_REGNUM
1014 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1015 indicating the CFA register has changed to <register> but the
1016 offset has not changed. */
1017 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1018 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1022 else if (loc.indirect == 0)
1024 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1025 indicating the CFA register has changed to <register> with
1026 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1027 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1030 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1032 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1033 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1034 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1038 /* Construct a DW_CFA_def_cfa_expression instruction to
1039 calculate the CFA using a full location expression since no
1040 register-offset pair is available. */
1041 struct dw_loc_descr_struct *loc_list;
1043 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1044 loc_list = build_cfa_loc (&loc, 0);
1045 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1048 add_fde_cfi (label, cfi);
1051 /* Add the CFI for saving a register. REG is the CFA column number.
1052 LABEL is passed to add_fde_cfi.
1053 If SREG is -1, the register is saved at OFFSET from the CFA;
1054 otherwise it is saved in SREG. */
1057 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1059 dw_cfi_ref cfi = new_cfi ();
1060 dw_fde_ref fde = current_fde ();
1062 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1064 /* When stack is aligned, store REG using DW_CFA_expression with
1067 && fde->stack_realign
1068 && sreg == INVALID_REGNUM)
1070 cfi->dw_cfi_opc = DW_CFA_expression;
1071 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1072 cfi->dw_cfi_oprnd1.dw_cfi_loc
1073 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1075 else if (sreg == INVALID_REGNUM)
1077 if (need_data_align_sf_opcode (offset))
1078 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1079 else if (reg & ~0x3f)
1080 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1082 cfi->dw_cfi_opc = DW_CFA_offset;
1083 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1085 else if (sreg == reg)
1086 cfi->dw_cfi_opc = DW_CFA_same_value;
1089 cfi->dw_cfi_opc = DW_CFA_register;
1090 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1093 add_fde_cfi (label, cfi);
1096 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1097 This CFI tells the unwinder that it needs to restore the window registers
1098 from the previous frame's window save area.
1100 ??? Perhaps we should note in the CIE where windows are saved (instead of
1101 assuming 0(cfa)) and what registers are in the window. */
1104 dwarf2out_window_save (const char *label)
1106 dw_cfi_ref cfi = new_cfi ();
1108 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1109 add_fde_cfi (label, cfi);
1112 /* Add a CFI to update the running total of the size of arguments
1113 pushed onto the stack. */
1116 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1120 if (size == old_args_size)
1123 old_args_size = size;
1126 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1127 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1128 add_fde_cfi (label, cfi);
1131 /* Entry point for saving a register to the stack. REG is the GCC register
1132 number. LABEL and OFFSET are passed to reg_save. */
1135 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1137 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1140 /* Entry point for saving the return address in the stack.
1141 LABEL and OFFSET are passed to reg_save. */
1144 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1146 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1149 /* Entry point for saving the return address in a register.
1150 LABEL and SREG are passed to reg_save. */
1153 dwarf2out_return_reg (const char *label, unsigned int sreg)
1155 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1158 #ifdef DWARF2_UNWIND_INFO
1159 /* Record the initial position of the return address. RTL is
1160 INCOMING_RETURN_ADDR_RTX. */
1163 initial_return_save (rtx rtl)
1165 unsigned int reg = INVALID_REGNUM;
1166 HOST_WIDE_INT offset = 0;
1168 switch (GET_CODE (rtl))
1171 /* RA is in a register. */
1172 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1176 /* RA is on the stack. */
1177 rtl = XEXP (rtl, 0);
1178 switch (GET_CODE (rtl))
1181 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1186 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1187 offset = INTVAL (XEXP (rtl, 1));
1191 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1192 offset = -INTVAL (XEXP (rtl, 1));
1202 /* The return address is at some offset from any value we can
1203 actually load. For instance, on the SPARC it is in %i7+8. Just
1204 ignore the offset for now; it doesn't matter for unwinding frames. */
1205 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1206 initial_return_save (XEXP (rtl, 0));
1213 if (reg != DWARF_FRAME_RETURN_COLUMN)
1214 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1218 /* Given a SET, calculate the amount of stack adjustment it
1221 static HOST_WIDE_INT
1222 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1223 HOST_WIDE_INT cur_offset)
1225 const_rtx src = SET_SRC (pattern);
1226 const_rtx dest = SET_DEST (pattern);
1227 HOST_WIDE_INT offset = 0;
1230 if (dest == stack_pointer_rtx)
1232 code = GET_CODE (src);
1234 /* Assume (set (reg sp) (reg whatever)) sets args_size
1236 if (code == REG && src != stack_pointer_rtx)
1238 offset = -cur_args_size;
1239 #ifndef STACK_GROWS_DOWNWARD
1242 return offset - cur_offset;
1245 if (! (code == PLUS || code == MINUS)
1246 || XEXP (src, 0) != stack_pointer_rtx
1247 || !CONST_INT_P (XEXP (src, 1)))
1250 /* (set (reg sp) (plus (reg sp) (const_int))) */
1251 offset = INTVAL (XEXP (src, 1));
1257 if (MEM_P (src) && !MEM_P (dest))
1261 /* (set (mem (pre_dec (reg sp))) (foo)) */
1262 src = XEXP (dest, 0);
1263 code = GET_CODE (src);
1269 if (XEXP (src, 0) == stack_pointer_rtx)
1271 rtx val = XEXP (XEXP (src, 1), 1);
1272 /* We handle only adjustments by constant amount. */
1273 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1274 && CONST_INT_P (val));
1275 offset = -INTVAL (val);
1282 if (XEXP (src, 0) == stack_pointer_rtx)
1284 offset = GET_MODE_SIZE (GET_MODE (dest));
1291 if (XEXP (src, 0) == stack_pointer_rtx)
1293 offset = -GET_MODE_SIZE (GET_MODE (dest));
1308 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1309 indexed by INSN_UID. */
1311 static HOST_WIDE_INT *barrier_args_size;
1313 /* Helper function for compute_barrier_args_size. Handle one insn. */
1315 static HOST_WIDE_INT
1316 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1317 VEC (rtx, heap) **next)
1319 HOST_WIDE_INT offset = 0;
1322 if (! RTX_FRAME_RELATED_P (insn))
1324 if (prologue_epilogue_contains (insn))
1326 else if (GET_CODE (PATTERN (insn)) == SET)
1327 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1328 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1329 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1331 /* There may be stack adjustments inside compound insns. Search
1333 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1334 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1335 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1336 cur_args_size, offset);
1341 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1345 expr = XEXP (expr, 0);
1346 if (GET_CODE (expr) == PARALLEL
1347 || GET_CODE (expr) == SEQUENCE)
1348 for (i = 1; i < XVECLEN (expr, 0); i++)
1350 rtx elem = XVECEXP (expr, 0, i);
1352 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1353 offset += stack_adjust_offset (elem, cur_args_size, offset);
1358 #ifndef STACK_GROWS_DOWNWARD
1362 cur_args_size += offset;
1363 if (cur_args_size < 0)
1368 rtx dest = JUMP_LABEL (insn);
1372 if (barrier_args_size [INSN_UID (dest)] < 0)
1374 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1375 VEC_safe_push (rtx, heap, *next, dest);
1380 return cur_args_size;
1383 /* Walk the whole function and compute args_size on BARRIERs. */
1386 compute_barrier_args_size (void)
1388 int max_uid = get_max_uid (), i;
1390 VEC (rtx, heap) *worklist, *next, *tmp;
1392 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1393 for (i = 0; i < max_uid; i++)
1394 barrier_args_size[i] = -1;
1396 worklist = VEC_alloc (rtx, heap, 20);
1397 next = VEC_alloc (rtx, heap, 20);
1398 insn = get_insns ();
1399 barrier_args_size[INSN_UID (insn)] = 0;
1400 VEC_quick_push (rtx, worklist, insn);
1403 while (!VEC_empty (rtx, worklist))
1405 rtx prev, body, first_insn;
1406 HOST_WIDE_INT cur_args_size;
1408 first_insn = insn = VEC_pop (rtx, worklist);
1409 cur_args_size = barrier_args_size[INSN_UID (insn)];
1410 prev = prev_nonnote_insn (insn);
1411 if (prev && BARRIER_P (prev))
1412 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1414 for (; insn; insn = NEXT_INSN (insn))
1416 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1418 if (BARRIER_P (insn))
1423 if (insn == first_insn)
1425 else if (barrier_args_size[INSN_UID (insn)] < 0)
1427 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1432 /* The insns starting with this label have been
1433 already scanned or are in the worklist. */
1438 body = PATTERN (insn);
1439 if (GET_CODE (body) == SEQUENCE)
1441 HOST_WIDE_INT dest_args_size = cur_args_size;
1442 for (i = 1; i < XVECLEN (body, 0); i++)
1443 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1444 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1446 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1447 dest_args_size, &next);
1450 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1451 cur_args_size, &next);
1453 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1454 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1455 dest_args_size, &next);
1458 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1459 cur_args_size, &next);
1463 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1467 if (VEC_empty (rtx, next))
1470 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1474 VEC_truncate (rtx, next, 0);
1477 VEC_free (rtx, heap, worklist);
1478 VEC_free (rtx, heap, next);
1482 /* Check INSN to see if it looks like a push or a stack adjustment, and
1483 make a note of it if it does. EH uses this information to find out how
1484 much extra space it needs to pop off the stack. */
1487 dwarf2out_stack_adjust (rtx insn, bool after_p)
1489 HOST_WIDE_INT offset;
1493 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1494 with this function. Proper support would require all frame-related
1495 insns to be marked, and to be able to handle saving state around
1496 epilogues textually in the middle of the function. */
1497 if (prologue_epilogue_contains (insn))
1500 /* If INSN is an instruction from target of an annulled branch, the
1501 effects are for the target only and so current argument size
1502 shouldn't change at all. */
1504 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1505 && INSN_FROM_TARGET_P (insn))
1508 /* If only calls can throw, and we have a frame pointer,
1509 save up adjustments until we see the CALL_INSN. */
1510 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1512 if (CALL_P (insn) && !after_p)
1514 /* Extract the size of the args from the CALL rtx itself. */
1515 insn = PATTERN (insn);
1516 if (GET_CODE (insn) == PARALLEL)
1517 insn = XVECEXP (insn, 0, 0);
1518 if (GET_CODE (insn) == SET)
1519 insn = SET_SRC (insn);
1520 gcc_assert (GET_CODE (insn) == CALL);
1521 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1526 if (CALL_P (insn) && !after_p)
1528 if (!flag_asynchronous_unwind_tables)
1529 dwarf2out_args_size ("", args_size);
1532 else if (BARRIER_P (insn))
1534 /* Don't call compute_barrier_args_size () if the only
1535 BARRIER is at the end of function. */
1536 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1537 compute_barrier_args_size ();
1538 if (barrier_args_size == NULL)
1542 offset = barrier_args_size[INSN_UID (insn)];
1547 offset -= args_size;
1548 #ifndef STACK_GROWS_DOWNWARD
1552 else if (GET_CODE (PATTERN (insn)) == SET)
1553 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1554 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1555 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1557 /* There may be stack adjustments inside compound insns. Search
1559 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1560 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1561 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1570 label = dwarf2out_cfi_label (false);
1571 dwarf2out_args_size_adjust (offset, label);
1574 /* Adjust args_size based on stack adjustment OFFSET. */
1577 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1579 if (cfa.reg == STACK_POINTER_REGNUM)
1580 cfa.offset += offset;
1582 if (cfa_store.reg == STACK_POINTER_REGNUM)
1583 cfa_store.offset += offset;
1585 #ifndef STACK_GROWS_DOWNWARD
1589 args_size += offset;
1593 def_cfa_1 (label, &cfa);
1594 if (flag_asynchronous_unwind_tables)
1595 dwarf2out_args_size (label, args_size);
1600 /* We delay emitting a register save until either (a) we reach the end
1601 of the prologue or (b) the register is clobbered. This clusters
1602 register saves so that there are fewer pc advances. */
1604 struct GTY(()) queued_reg_save {
1605 struct queued_reg_save *next;
1607 HOST_WIDE_INT cfa_offset;
1611 static GTY(()) struct queued_reg_save *queued_reg_saves;
1613 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1614 struct GTY(()) reg_saved_in_data {
1619 /* A list of registers saved in other registers.
1620 The list intentionally has a small maximum capacity of 4; if your
1621 port needs more than that, you might consider implementing a
1622 more efficient data structure. */
1623 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1624 static GTY(()) size_t num_regs_saved_in_regs;
1626 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1627 static const char *last_reg_save_label;
1629 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1630 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1633 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1635 struct queued_reg_save *q;
1637 /* Duplicates waste space, but it's also necessary to remove them
1638 for correctness, since the queue gets output in reverse
1640 for (q = queued_reg_saves; q != NULL; q = q->next)
1641 if (REGNO (q->reg) == REGNO (reg))
1646 q = GGC_NEW (struct queued_reg_save);
1647 q->next = queued_reg_saves;
1648 queued_reg_saves = q;
1652 q->cfa_offset = offset;
1653 q->saved_reg = sreg;
1655 last_reg_save_label = label;
1658 /* Output all the entries in QUEUED_REG_SAVES. */
1661 flush_queued_reg_saves (void)
1663 struct queued_reg_save *q;
1665 for (q = queued_reg_saves; q; q = q->next)
1668 unsigned int reg, sreg;
1670 for (i = 0; i < num_regs_saved_in_regs; i++)
1671 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1673 if (q->saved_reg && i == num_regs_saved_in_regs)
1675 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1676 num_regs_saved_in_regs++;
1678 if (i != num_regs_saved_in_regs)
1680 regs_saved_in_regs[i].orig_reg = q->reg;
1681 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1684 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1686 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1688 sreg = INVALID_REGNUM;
1689 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1692 queued_reg_saves = NULL;
1693 last_reg_save_label = NULL;
1696 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1697 location for? Or, does it clobber a register which we've previously
1698 said that some other register is saved in, and for which we now
1699 have a new location for? */
1702 clobbers_queued_reg_save (const_rtx insn)
1704 struct queued_reg_save *q;
1706 for (q = queued_reg_saves; q; q = q->next)
1709 if (modified_in_p (q->reg, insn))
1711 for (i = 0; i < num_regs_saved_in_regs; i++)
1712 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1713 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1720 /* Entry point for saving the first register into the second. */
1723 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1726 unsigned int regno, sregno;
1728 for (i = 0; i < num_regs_saved_in_regs; i++)
1729 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1731 if (i == num_regs_saved_in_regs)
1733 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1734 num_regs_saved_in_regs++;
1736 regs_saved_in_regs[i].orig_reg = reg;
1737 regs_saved_in_regs[i].saved_in_reg = sreg;
1739 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1740 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1741 reg_save (label, regno, sregno, 0);
1744 /* What register, if any, is currently saved in REG? */
1747 reg_saved_in (rtx reg)
1749 unsigned int regn = REGNO (reg);
1751 struct queued_reg_save *q;
1753 for (q = queued_reg_saves; q; q = q->next)
1754 if (q->saved_reg && regn == REGNO (q->saved_reg))
1757 for (i = 0; i < num_regs_saved_in_regs; i++)
1758 if (regs_saved_in_regs[i].saved_in_reg
1759 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1760 return regs_saved_in_regs[i].orig_reg;
1766 /* A temporary register holding an integral value used in adjusting SP
1767 or setting up the store_reg. The "offset" field holds the integer
1768 value, not an offset. */
1769 static dw_cfa_location cfa_temp;
1771 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1774 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1776 memset (&cfa, 0, sizeof (cfa));
1778 switch (GET_CODE (pat))
1781 cfa.reg = REGNO (XEXP (pat, 0));
1782 cfa.offset = INTVAL (XEXP (pat, 1));
1786 cfa.reg = REGNO (pat);
1790 /* Recurse and define an expression. */
1794 def_cfa_1 (label, &cfa);
1797 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1800 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1804 gcc_assert (GET_CODE (pat) == SET);
1805 dest = XEXP (pat, 0);
1806 src = XEXP (pat, 1);
1808 switch (GET_CODE (src))
1811 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1812 cfa.offset -= INTVAL (XEXP (src, 1));
1822 cfa.reg = REGNO (dest);
1823 gcc_assert (cfa.indirect == 0);
1825 def_cfa_1 (label, &cfa);
1828 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1831 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1833 HOST_WIDE_INT offset;
1834 rtx src, addr, span;
1836 src = XEXP (set, 1);
1837 addr = XEXP (set, 0);
1838 gcc_assert (MEM_P (addr));
1839 addr = XEXP (addr, 0);
1841 /* As documented, only consider extremely simple addresses. */
1842 switch (GET_CODE (addr))
1845 gcc_assert (REGNO (addr) == cfa.reg);
1846 offset = -cfa.offset;
1849 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1850 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1856 span = targetm.dwarf_register_span (src);
1858 /* ??? We'd like to use queue_reg_save, but we need to come up with
1859 a different flushing heuristic for epilogues. */
1861 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1864 /* We have a PARALLEL describing where the contents of SRC live.
1865 Queue register saves for each piece of the PARALLEL. */
1868 HOST_WIDE_INT span_offset = offset;
1870 gcc_assert (GET_CODE (span) == PARALLEL);
1872 limit = XVECLEN (span, 0);
1873 for (par_index = 0; par_index < limit; par_index++)
1875 rtx elem = XVECEXP (span, 0, par_index);
1877 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1878 INVALID_REGNUM, span_offset);
1879 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1884 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1887 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1890 unsigned sregno, dregno;
1892 src = XEXP (set, 1);
1893 dest = XEXP (set, 0);
1896 sregno = DWARF_FRAME_RETURN_COLUMN;
1898 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1900 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1902 /* ??? We'd like to use queue_reg_save, but we need to come up with
1903 a different flushing heuristic for epilogues. */
1904 reg_save (label, sregno, dregno, 0);
1907 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1910 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1912 dw_cfi_ref cfi = new_cfi ();
1913 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1915 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1916 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1918 add_fde_cfi (label, cfi);
1921 /* Record call frame debugging information for an expression EXPR,
1922 which either sets SP or FP (adjusting how we calculate the frame
1923 address) or saves a register to the stack or another register.
1924 LABEL indicates the address of EXPR.
1926 This function encodes a state machine mapping rtxes to actions on
1927 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1928 users need not read the source code.
1930 The High-Level Picture
1932 Changes in the register we use to calculate the CFA: Currently we
1933 assume that if you copy the CFA register into another register, we
1934 should take the other one as the new CFA register; this seems to
1935 work pretty well. If it's wrong for some target, it's simple
1936 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1938 Changes in the register we use for saving registers to the stack:
1939 This is usually SP, but not always. Again, we deduce that if you
1940 copy SP into another register (and SP is not the CFA register),
1941 then the new register is the one we will be using for register
1942 saves. This also seems to work.
1944 Register saves: There's not much guesswork about this one; if
1945 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1946 register save, and the register used to calculate the destination
1947 had better be the one we think we're using for this purpose.
1948 It's also assumed that a copy from a call-saved register to another
1949 register is saving that register if RTX_FRAME_RELATED_P is set on
1950 that instruction. If the copy is from a call-saved register to
1951 the *same* register, that means that the register is now the same
1952 value as in the caller.
1954 Except: If the register being saved is the CFA register, and the
1955 offset is nonzero, we are saving the CFA, so we assume we have to
1956 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1957 the intent is to save the value of SP from the previous frame.
1959 In addition, if a register has previously been saved to a different
1962 Invariants / Summaries of Rules
1964 cfa current rule for calculating the CFA. It usually
1965 consists of a register and an offset.
1966 cfa_store register used by prologue code to save things to the stack
1967 cfa_store.offset is the offset from the value of
1968 cfa_store.reg to the actual CFA
1969 cfa_temp register holding an integral value. cfa_temp.offset
1970 stores the value, which will be used to adjust the
1971 stack pointer. cfa_temp is also used like cfa_store,
1972 to track stores to the stack via fp or a temp reg.
1974 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1975 with cfa.reg as the first operand changes the cfa.reg and its
1976 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1979 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1980 expression yielding a constant. This sets cfa_temp.reg
1981 and cfa_temp.offset.
1983 Rule 5: Create a new register cfa_store used to save items to the
1986 Rules 10-14: Save a register to the stack. Define offset as the
1987 difference of the original location and cfa_store's
1988 location (or cfa_temp's location if cfa_temp is used).
1990 Rules 16-20: If AND operation happens on sp in prologue, we assume
1991 stack is realigned. We will use a group of DW_OP_XXX
1992 expressions to represent the location of the stored
1993 register instead of CFA+offset.
1997 "{a,b}" indicates a choice of a xor b.
1998 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2001 (set <reg1> <reg2>:cfa.reg)
2002 effects: cfa.reg = <reg1>
2003 cfa.offset unchanged
2004 cfa_temp.reg = <reg1>
2005 cfa_temp.offset = cfa.offset
2008 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2009 {<const_int>,<reg>:cfa_temp.reg}))
2010 effects: cfa.reg = sp if fp used
2011 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2012 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2013 if cfa_store.reg==sp
2016 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2017 effects: cfa.reg = fp
2018 cfa_offset += +/- <const_int>
2021 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2022 constraints: <reg1> != fp
2024 effects: cfa.reg = <reg1>
2025 cfa_temp.reg = <reg1>
2026 cfa_temp.offset = cfa.offset
2029 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2030 constraints: <reg1> != fp
2032 effects: cfa_store.reg = <reg1>
2033 cfa_store.offset = cfa.offset - cfa_temp.offset
2036 (set <reg> <const_int>)
2037 effects: cfa_temp.reg = <reg>
2038 cfa_temp.offset = <const_int>
2041 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2042 effects: cfa_temp.reg = <reg1>
2043 cfa_temp.offset |= <const_int>
2046 (set <reg> (high <exp>))
2050 (set <reg> (lo_sum <exp> <const_int>))
2051 effects: cfa_temp.reg = <reg>
2052 cfa_temp.offset = <const_int>
2055 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2056 effects: cfa_store.offset -= <const_int>
2057 cfa.offset = cfa_store.offset if cfa.reg == sp
2059 cfa.base_offset = -cfa_store.offset
2062 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2063 effects: cfa_store.offset += -/+ mode_size(mem)
2064 cfa.offset = cfa_store.offset if cfa.reg == sp
2066 cfa.base_offset = -cfa_store.offset
2069 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2072 effects: cfa.reg = <reg1>
2073 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2076 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2077 effects: cfa.reg = <reg1>
2078 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2081 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2082 effects: cfa.reg = <reg1>
2083 cfa.base_offset = -cfa_temp.offset
2084 cfa_temp.offset -= mode_size(mem)
2087 (set <reg> {unspec, unspec_volatile})
2088 effects: target-dependent
2091 (set sp (and: sp <const_int>))
2092 constraints: cfa_store.reg == sp
2093 effects: current_fde.stack_realign = 1
2094 cfa_store.offset = 0
2095 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2098 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2099 effects: cfa_store.offset += -/+ mode_size(mem)
2102 (set (mem ({pre_inc, pre_dec} sp)) fp)
2103 constraints: fde->stack_realign == 1
2104 effects: cfa_store.offset = 0
2105 cfa.reg != HARD_FRAME_POINTER_REGNUM
2108 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2109 constraints: fde->stack_realign == 1
2111 && cfa.indirect == 0
2112 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2113 effects: Use DW_CFA_def_cfa_expression to define cfa
2114 cfa.reg == fde->drap_reg
2117 (set reg fde->drap_reg)
2118 constraints: fde->vdrap_reg == INVALID_REGNUM
2119 effects: fde->vdrap_reg = reg.
2120 (set mem fde->drap_reg)
2121 constraints: fde->drap_reg_saved == 1
2125 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2127 rtx src, dest, span;
2128 HOST_WIDE_INT offset;
2131 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2132 the PARALLEL independently. The first element is always processed if
2133 it is a SET. This is for backward compatibility. Other elements
2134 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2135 flag is set in them. */
2136 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2139 int limit = XVECLEN (expr, 0);
2142 /* PARALLELs have strict read-modify-write semantics, so we
2143 ought to evaluate every rvalue before changing any lvalue.
2144 It's cumbersome to do that in general, but there's an
2145 easy approximation that is enough for all current users:
2146 handle register saves before register assignments. */
2147 if (GET_CODE (expr) == PARALLEL)
2148 for (par_index = 0; par_index < limit; par_index++)
2150 elem = XVECEXP (expr, 0, par_index);
2151 if (GET_CODE (elem) == SET
2152 && MEM_P (SET_DEST (elem))
2153 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2154 dwarf2out_frame_debug_expr (elem, label);
2157 for (par_index = 0; par_index < limit; par_index++)
2159 elem = XVECEXP (expr, 0, par_index);
2160 if (GET_CODE (elem) == SET
2161 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2162 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2163 dwarf2out_frame_debug_expr (elem, label);
2164 else if (GET_CODE (elem) == SET
2166 && !RTX_FRAME_RELATED_P (elem))
2168 /* Stack adjustment combining might combine some post-prologue
2169 stack adjustment into a prologue stack adjustment. */
2170 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2173 dwarf2out_args_size_adjust (offset, label);
2179 gcc_assert (GET_CODE (expr) == SET);
2181 src = SET_SRC (expr);
2182 dest = SET_DEST (expr);
2186 rtx rsi = reg_saved_in (src);
2191 fde = current_fde ();
2195 && fde->drap_reg == REGNO (src)
2196 && (fde->drap_reg_saved
2200 /* If we are saving dynamic realign argument pointer to a
2201 register, the destination is virtual dynamic realign
2202 argument pointer. It may be used to access argument. */
2205 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2206 fde->vdrap_reg = REGNO (dest);
2211 switch (GET_CODE (dest))
2214 switch (GET_CODE (src))
2216 /* Setting FP from SP. */
2218 if (cfa.reg == (unsigned) REGNO (src))
2221 /* Update the CFA rule wrt SP or FP. Make sure src is
2222 relative to the current CFA register.
2224 We used to require that dest be either SP or FP, but the
2225 ARM copies SP to a temporary register, and from there to
2226 FP. So we just rely on the backends to only set
2227 RTX_FRAME_RELATED_P on appropriate insns. */
2228 cfa.reg = REGNO (dest);
2229 cfa_temp.reg = cfa.reg;
2230 cfa_temp.offset = cfa.offset;
2234 /* Saving a register in a register. */
2235 gcc_assert (!fixed_regs [REGNO (dest)]
2236 /* For the SPARC and its register window. */
2237 || (DWARF_FRAME_REGNUM (REGNO (src))
2238 == DWARF_FRAME_RETURN_COLUMN));
2240 /* After stack is aligned, we can only save SP in FP
2241 if drap register is used. In this case, we have
2242 to restore stack pointer with the CFA value and we
2243 don't generate this DWARF information. */
2245 && fde->stack_realign
2246 && REGNO (src) == STACK_POINTER_REGNUM)
2247 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2248 && fde->drap_reg != INVALID_REGNUM
2249 && cfa.reg != REGNO (src));
2251 queue_reg_save (label, src, dest, 0);
2258 if (dest == stack_pointer_rtx)
2262 switch (GET_CODE (XEXP (src, 1)))
2265 offset = INTVAL (XEXP (src, 1));
2268 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2270 offset = cfa_temp.offset;
2276 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2278 /* Restoring SP from FP in the epilogue. */
2279 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2280 cfa.reg = STACK_POINTER_REGNUM;
2282 else if (GET_CODE (src) == LO_SUM)
2283 /* Assume we've set the source reg of the LO_SUM from sp. */
2286 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2288 if (GET_CODE (src) != MINUS)
2290 if (cfa.reg == STACK_POINTER_REGNUM)
2291 cfa.offset += offset;
2292 if (cfa_store.reg == STACK_POINTER_REGNUM)
2293 cfa_store.offset += offset;
2295 else if (dest == hard_frame_pointer_rtx)
2298 /* Either setting the FP from an offset of the SP,
2299 or adjusting the FP */
2300 gcc_assert (frame_pointer_needed);
2302 gcc_assert (REG_P (XEXP (src, 0))
2303 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2304 && CONST_INT_P (XEXP (src, 1)));
2305 offset = INTVAL (XEXP (src, 1));
2306 if (GET_CODE (src) != MINUS)
2308 cfa.offset += offset;
2309 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2313 gcc_assert (GET_CODE (src) != MINUS);
2316 if (REG_P (XEXP (src, 0))
2317 && REGNO (XEXP (src, 0)) == cfa.reg
2318 && CONST_INT_P (XEXP (src, 1)))
2320 /* Setting a temporary CFA register that will be copied
2321 into the FP later on. */
2322 offset = - INTVAL (XEXP (src, 1));
2323 cfa.offset += offset;
2324 cfa.reg = REGNO (dest);
2325 /* Or used to save regs to the stack. */
2326 cfa_temp.reg = cfa.reg;
2327 cfa_temp.offset = cfa.offset;
2331 else if (REG_P (XEXP (src, 0))
2332 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2333 && XEXP (src, 1) == stack_pointer_rtx)
2335 /* Setting a scratch register that we will use instead
2336 of SP for saving registers to the stack. */
2337 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2338 cfa_store.reg = REGNO (dest);
2339 cfa_store.offset = cfa.offset - cfa_temp.offset;
2343 else if (GET_CODE (src) == LO_SUM
2344 && CONST_INT_P (XEXP (src, 1)))
2346 cfa_temp.reg = REGNO (dest);
2347 cfa_temp.offset = INTVAL (XEXP (src, 1));
2356 cfa_temp.reg = REGNO (dest);
2357 cfa_temp.offset = INTVAL (src);
2362 gcc_assert (REG_P (XEXP (src, 0))
2363 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2364 && CONST_INT_P (XEXP (src, 1)));
2366 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2367 cfa_temp.reg = REGNO (dest);
2368 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2371 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2372 which will fill in all of the bits. */
2379 case UNSPEC_VOLATILE:
2380 gcc_assert (targetm.dwarf_handle_frame_unspec);
2381 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2386 /* If this AND operation happens on stack pointer in prologue,
2387 we assume the stack is realigned and we extract the
2389 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2391 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2392 fde->stack_realign = 1;
2393 fde->stack_realignment = INTVAL (XEXP (src, 1));
2394 cfa_store.offset = 0;
2396 if (cfa.reg != STACK_POINTER_REGNUM
2397 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2398 fde->drap_reg = cfa.reg;
2406 def_cfa_1 (label, &cfa);
2411 /* Saving a register to the stack. Make sure dest is relative to the
2413 switch (GET_CODE (XEXP (dest, 0)))
2418 /* We can't handle variable size modifications. */
2419 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2421 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2423 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2424 && cfa_store.reg == STACK_POINTER_REGNUM);
2426 cfa_store.offset += offset;
2427 if (cfa.reg == STACK_POINTER_REGNUM)
2428 cfa.offset = cfa_store.offset;
2430 offset = -cfa_store.offset;
2436 offset = GET_MODE_SIZE (GET_MODE (dest));
2437 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2440 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2441 == STACK_POINTER_REGNUM)
2442 && cfa_store.reg == STACK_POINTER_REGNUM);
2444 cfa_store.offset += offset;
2446 /* Rule 18: If stack is aligned, we will use FP as a
2447 reference to represent the address of the stored
2450 && fde->stack_realign
2451 && src == hard_frame_pointer_rtx)
2453 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2454 cfa_store.offset = 0;
2457 if (cfa.reg == STACK_POINTER_REGNUM)
2458 cfa.offset = cfa_store.offset;
2460 offset = -cfa_store.offset;
2464 /* With an offset. */
2471 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2472 && REG_P (XEXP (XEXP (dest, 0), 0)));
2473 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2474 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2477 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2479 if (cfa_store.reg == (unsigned) regno)
2480 offset -= cfa_store.offset;
2483 gcc_assert (cfa_temp.reg == (unsigned) regno);
2484 offset -= cfa_temp.offset;
2490 /* Without an offset. */
2493 int regno = REGNO (XEXP (dest, 0));
2495 if (cfa_store.reg == (unsigned) regno)
2496 offset = -cfa_store.offset;
2499 gcc_assert (cfa_temp.reg == (unsigned) regno);
2500 offset = -cfa_temp.offset;
2507 gcc_assert (cfa_temp.reg
2508 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2509 offset = -cfa_temp.offset;
2510 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2518 /* If the source operand of this MEM operation is not a
2519 register, basically the source is return address. Here
2520 we only care how much stack grew and we don't save it. */
2524 if (REGNO (src) != STACK_POINTER_REGNUM
2525 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2526 && (unsigned) REGNO (src) == cfa.reg)
2528 /* We're storing the current CFA reg into the stack. */
2530 if (cfa.offset == 0)
2533 /* If stack is aligned, putting CFA reg into stack means
2534 we can no longer use reg + offset to represent CFA.
2535 Here we use DW_CFA_def_cfa_expression instead. The
2536 result of this expression equals to the original CFA
2539 && fde->stack_realign
2540 && cfa.indirect == 0
2541 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2543 dw_cfa_location cfa_exp;
2545 gcc_assert (fde->drap_reg == cfa.reg);
2547 cfa_exp.indirect = 1;
2548 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2549 cfa_exp.base_offset = offset;
2552 fde->drap_reg_saved = 1;
2554 def_cfa_1 (label, &cfa_exp);
2558 /* If the source register is exactly the CFA, assume
2559 we're saving SP like any other register; this happens
2561 def_cfa_1 (label, &cfa);
2562 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2567 /* Otherwise, we'll need to look in the stack to
2568 calculate the CFA. */
2569 rtx x = XEXP (dest, 0);
2573 gcc_assert (REG_P (x));
2575 cfa.reg = REGNO (x);
2576 cfa.base_offset = offset;
2578 def_cfa_1 (label, &cfa);
2583 def_cfa_1 (label, &cfa);
2585 span = targetm.dwarf_register_span (src);
2588 queue_reg_save (label, src, NULL_RTX, offset);
2591 /* We have a PARALLEL describing where the contents of SRC
2592 live. Queue register saves for each piece of the
2596 HOST_WIDE_INT span_offset = offset;
2598 gcc_assert (GET_CODE (span) == PARALLEL);
2600 limit = XVECLEN (span, 0);
2601 for (par_index = 0; par_index < limit; par_index++)
2603 rtx elem = XVECEXP (span, 0, par_index);
2605 queue_reg_save (label, elem, NULL_RTX, span_offset);
2606 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2617 /* Record call frame debugging information for INSN, which either
2618 sets SP or FP (adjusting how we calculate the frame address) or saves a
2619 register to the stack. If INSN is NULL_RTX, initialize our state.
2621 If AFTER_P is false, we're being called before the insn is emitted,
2622 otherwise after. Call instructions get invoked twice. */
2625 dwarf2out_frame_debug (rtx insn, bool after_p)
2629 bool handled_one = false;
2631 if (insn == NULL_RTX)
2635 /* Flush any queued register saves. */
2636 flush_queued_reg_saves ();
2638 /* Set up state for generating call frame debug info. */
2641 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2643 cfa.reg = STACK_POINTER_REGNUM;
2646 cfa_temp.offset = 0;
2648 for (i = 0; i < num_regs_saved_in_regs; i++)
2650 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2651 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2653 num_regs_saved_in_regs = 0;
2655 if (barrier_args_size)
2657 XDELETEVEC (barrier_args_size);
2658 barrier_args_size = NULL;
2663 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2664 flush_queued_reg_saves ();
2666 if (! RTX_FRAME_RELATED_P (insn))
2668 if (!ACCUMULATE_OUTGOING_ARGS)
2669 dwarf2out_stack_adjust (insn, after_p);
2673 label = dwarf2out_cfi_label (false);
2675 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2676 switch (REG_NOTE_KIND (note))
2678 case REG_FRAME_RELATED_EXPR:
2679 insn = XEXP (note, 0);
2682 case REG_CFA_DEF_CFA:
2683 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2687 case REG_CFA_ADJUST_CFA:
2692 if (GET_CODE (n) == PARALLEL)
2693 n = XVECEXP (n, 0, 0);
2695 dwarf2out_frame_debug_adjust_cfa (n, label);
2699 case REG_CFA_OFFSET:
2702 n = single_set (insn);
2703 dwarf2out_frame_debug_cfa_offset (n, label);
2707 case REG_CFA_REGISTER:
2712 if (GET_CODE (n) == PARALLEL)
2713 n = XVECEXP (n, 0, 0);
2715 dwarf2out_frame_debug_cfa_register (n, label);
2719 case REG_CFA_RESTORE:
2724 if (GET_CODE (n) == PARALLEL)
2725 n = XVECEXP (n, 0, 0);
2728 dwarf2out_frame_debug_cfa_restore (n, label);
2738 insn = PATTERN (insn);
2740 dwarf2out_frame_debug_expr (insn, label);
2743 /* Determine if we need to save and restore CFI information around this
2744 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2745 we do need to save/restore, then emit the save now, and insert a
2746 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2749 dwarf2out_begin_epilogue (rtx insn)
2751 bool saw_frp = false;
2754 /* Scan forward to the return insn, noticing if there are possible
2755 frame related insns. */
2756 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2761 /* Look for both regular and sibcalls to end the block. */
2762 if (returnjump_p (i))
2764 if (CALL_P (i) && SIBLING_CALL_P (i))
2767 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2770 rtx seq = PATTERN (i);
2772 if (returnjump_p (XVECEXP (seq, 0, 0)))
2774 if (CALL_P (XVECEXP (seq, 0, 0))
2775 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2778 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2779 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2783 if (RTX_FRAME_RELATED_P (i))
2787 /* If the port doesn't emit epilogue unwind info, we don't need a
2788 save/restore pair. */
2792 /* Otherwise, search forward to see if the return insn was the last
2793 basic block of the function. If so, we don't need save/restore. */
2794 gcc_assert (i != NULL);
2795 i = next_real_insn (i);
2799 /* Insert the restore before that next real insn in the stream, and before
2800 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2801 properly nested. This should be after any label or alignment. This
2802 will be pushed into the CFI stream by the function below. */
2805 rtx p = PREV_INSN (i);
2808 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2812 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2814 emit_cfa_remember = true;
2816 /* And emulate the state save. */
2817 gcc_assert (!cfa_remember.in_use);
2819 cfa_remember.in_use = 1;
2822 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2825 dwarf2out_frame_debug_restore_state (void)
2827 dw_cfi_ref cfi = new_cfi ();
2828 const char *label = dwarf2out_cfi_label (false);
2830 cfi->dw_cfi_opc = DW_CFA_restore_state;
2831 add_fde_cfi (label, cfi);
2833 gcc_assert (cfa_remember.in_use);
2835 cfa_remember.in_use = 0;
2840 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2841 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2842 (enum dwarf_call_frame_info cfi);
2844 static enum dw_cfi_oprnd_type
2845 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2850 case DW_CFA_GNU_window_save:
2851 case DW_CFA_remember_state:
2852 case DW_CFA_restore_state:
2853 return dw_cfi_oprnd_unused;
2855 case DW_CFA_set_loc:
2856 case DW_CFA_advance_loc1:
2857 case DW_CFA_advance_loc2:
2858 case DW_CFA_advance_loc4:
2859 case DW_CFA_MIPS_advance_loc8:
2860 return dw_cfi_oprnd_addr;
2863 case DW_CFA_offset_extended:
2864 case DW_CFA_def_cfa:
2865 case DW_CFA_offset_extended_sf:
2866 case DW_CFA_def_cfa_sf:
2867 case DW_CFA_restore:
2868 case DW_CFA_restore_extended:
2869 case DW_CFA_undefined:
2870 case DW_CFA_same_value:
2871 case DW_CFA_def_cfa_register:
2872 case DW_CFA_register:
2873 return dw_cfi_oprnd_reg_num;
2875 case DW_CFA_def_cfa_offset:
2876 case DW_CFA_GNU_args_size:
2877 case DW_CFA_def_cfa_offset_sf:
2878 return dw_cfi_oprnd_offset;
2880 case DW_CFA_def_cfa_expression:
2881 case DW_CFA_expression:
2882 return dw_cfi_oprnd_loc;
2889 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2890 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2891 (enum dwarf_call_frame_info cfi);
2893 static enum dw_cfi_oprnd_type
2894 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2898 case DW_CFA_def_cfa:
2899 case DW_CFA_def_cfa_sf:
2901 case DW_CFA_offset_extended_sf:
2902 case DW_CFA_offset_extended:
2903 return dw_cfi_oprnd_offset;
2905 case DW_CFA_register:
2906 return dw_cfi_oprnd_reg_num;
2909 return dw_cfi_oprnd_unused;
2913 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2915 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2916 switch to the data section instead, and write out a synthetic label
2920 switch_to_eh_frame_section (void)
2924 #ifdef EH_FRAME_SECTION_NAME
2925 if (eh_frame_section == 0)
2929 if (EH_TABLES_CAN_BE_READ_ONLY)
2935 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2937 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2939 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2941 flags = ((! flag_pic
2942 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2943 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2944 && (per_encoding & 0x70) != DW_EH_PE_absptr
2945 && (per_encoding & 0x70) != DW_EH_PE_aligned
2946 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2947 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2948 ? 0 : SECTION_WRITE);
2951 flags = SECTION_WRITE;
2952 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2956 if (eh_frame_section)
2957 switch_to_section (eh_frame_section);
2960 /* We have no special eh_frame section. Put the information in
2961 the data section and emit special labels to guide collect2. */
2962 switch_to_section (data_section);
2963 label = get_file_function_name ("F");
2964 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2965 targetm.asm_out.globalize_label (asm_out_file,
2966 IDENTIFIER_POINTER (label));
2967 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2971 /* Output a Call Frame Information opcode and its operand(s). */
2974 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2979 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2980 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2981 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2982 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2983 ((unsigned HOST_WIDE_INT)
2984 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2985 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2987 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2988 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2989 "DW_CFA_offset, column 0x%lx", r);
2990 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2991 dw2_asm_output_data_uleb128 (off, NULL);
2993 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2995 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2996 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2997 "DW_CFA_restore, column 0x%lx", r);
3001 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3002 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3004 switch (cfi->dw_cfi_opc)
3006 case DW_CFA_set_loc:
3008 dw2_asm_output_encoded_addr_rtx (
3009 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3010 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3013 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3014 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3015 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3018 case DW_CFA_advance_loc1:
3019 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3020 fde->dw_fde_current_label, NULL);
3021 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3024 case DW_CFA_advance_loc2:
3025 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3026 fde->dw_fde_current_label, NULL);
3027 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3030 case DW_CFA_advance_loc4:
3031 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3032 fde->dw_fde_current_label, NULL);
3033 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3036 case DW_CFA_MIPS_advance_loc8:
3037 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3038 fde->dw_fde_current_label, NULL);
3039 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3042 case DW_CFA_offset_extended:
3043 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3044 dw2_asm_output_data_uleb128 (r, NULL);
3045 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3046 dw2_asm_output_data_uleb128 (off, NULL);
3049 case DW_CFA_def_cfa:
3050 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3051 dw2_asm_output_data_uleb128 (r, NULL);
3052 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3055 case DW_CFA_offset_extended_sf:
3056 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3057 dw2_asm_output_data_uleb128 (r, NULL);
3058 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3059 dw2_asm_output_data_sleb128 (off, NULL);
3062 case DW_CFA_def_cfa_sf:
3063 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3064 dw2_asm_output_data_uleb128 (r, NULL);
3065 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3066 dw2_asm_output_data_sleb128 (off, NULL);
3069 case DW_CFA_restore_extended:
3070 case DW_CFA_undefined:
3071 case DW_CFA_same_value:
3072 case DW_CFA_def_cfa_register:
3073 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3074 dw2_asm_output_data_uleb128 (r, NULL);
3077 case DW_CFA_register:
3078 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3079 dw2_asm_output_data_uleb128 (r, NULL);
3080 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3081 dw2_asm_output_data_uleb128 (r, NULL);
3084 case DW_CFA_def_cfa_offset:
3085 case DW_CFA_GNU_args_size:
3086 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3089 case DW_CFA_def_cfa_offset_sf:
3090 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3091 dw2_asm_output_data_sleb128 (off, NULL);
3094 case DW_CFA_GNU_window_save:
3097 case DW_CFA_def_cfa_expression:
3098 case DW_CFA_expression:
3099 output_cfa_loc (cfi);
3102 case DW_CFA_GNU_negative_offset_extended:
3103 /* Obsoleted by DW_CFA_offset_extended_sf. */
3112 /* Similar, but do it via assembler directives instead. */
3115 output_cfi_directive (dw_cfi_ref cfi)
3117 unsigned long r, r2;
3119 switch (cfi->dw_cfi_opc)
3121 case DW_CFA_advance_loc:
3122 case DW_CFA_advance_loc1:
3123 case DW_CFA_advance_loc2:
3124 case DW_CFA_advance_loc4:
3125 case DW_CFA_MIPS_advance_loc8:
3126 case DW_CFA_set_loc:
3127 /* Should only be created by add_fde_cfi in a code path not
3128 followed when emitting via directives. The assembler is
3129 going to take care of this for us. */
3133 case DW_CFA_offset_extended:
3134 case DW_CFA_offset_extended_sf:
3135 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3136 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3137 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3140 case DW_CFA_restore:
3141 case DW_CFA_restore_extended:
3142 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3143 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3146 case DW_CFA_undefined:
3147 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3148 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3151 case DW_CFA_same_value:
3152 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3153 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3156 case DW_CFA_def_cfa:
3157 case DW_CFA_def_cfa_sf:
3158 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3159 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3160 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3163 case DW_CFA_def_cfa_register:
3164 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3165 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3168 case DW_CFA_register:
3169 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3170 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3171 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3174 case DW_CFA_def_cfa_offset:
3175 case DW_CFA_def_cfa_offset_sf:
3176 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3177 HOST_WIDE_INT_PRINT_DEC"\n",
3178 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3181 case DW_CFA_remember_state:
3182 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3184 case DW_CFA_restore_state:
3185 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3188 case DW_CFA_GNU_args_size:
3189 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3190 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3192 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3193 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3194 fputc ('\n', asm_out_file);
3197 case DW_CFA_GNU_window_save:
3198 fprintf (asm_out_file, "\t.cfi_window_save\n");
3201 case DW_CFA_def_cfa_expression:
3202 case DW_CFA_expression:
3203 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3204 output_cfa_loc_raw (cfi);
3205 fputc ('\n', asm_out_file);
3213 /* Output the call frame information used to record information
3214 that relates to calculating the frame pointer, and records the
3215 location of saved registers. */
3218 output_call_frame_info (int for_eh)
3223 char l1[20], l2[20], section_start_label[20];
3224 bool any_lsda_needed = false;
3225 char augmentation[6];
3226 int augmentation_size;
3227 int fde_encoding = DW_EH_PE_absptr;
3228 int per_encoding = DW_EH_PE_absptr;
3229 int lsda_encoding = DW_EH_PE_absptr;
3233 /* Don't emit a CIE if there won't be any FDEs. */
3234 if (fde_table_in_use == 0)
3237 /* Nothing to do if the assembler's doing it all. */
3238 if (dwarf2out_do_cfi_asm ())
3241 /* If we make FDEs linkonce, we may have to emit an empty label for
3242 an FDE that wouldn't otherwise be emitted. We want to avoid
3243 having an FDE kept around when the function it refers to is
3244 discarded. Example where this matters: a primary function
3245 template in C++ requires EH information, but an explicit
3246 specialization doesn't. */
3247 if (TARGET_USES_WEAK_UNWIND_INFO
3248 && ! flag_asynchronous_unwind_tables
3251 for (i = 0; i < fde_table_in_use; i++)
3252 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3253 && !fde_table[i].uses_eh_lsda
3254 && ! DECL_WEAK (fde_table[i].decl))
3255 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3256 for_eh, /* empty */ 1);
3258 /* If we don't have any functions we'll want to unwind out of, don't
3259 emit any EH unwind information. Note that if exceptions aren't
3260 enabled, we won't have collected nothrow information, and if we
3261 asked for asynchronous tables, we always want this info. */
3264 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3266 for (i = 0; i < fde_table_in_use; i++)
3267 if (fde_table[i].uses_eh_lsda)
3268 any_eh_needed = any_lsda_needed = true;
3269 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3270 any_eh_needed = true;
3271 else if (! fde_table[i].nothrow
3272 && ! fde_table[i].all_throwers_are_sibcalls)
3273 any_eh_needed = true;
3275 if (! any_eh_needed)
3279 /* We're going to be generating comments, so turn on app. */
3284 switch_to_eh_frame_section ();
3287 if (!debug_frame_section)
3288 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3289 SECTION_DEBUG, NULL);
3290 switch_to_section (debug_frame_section);
3293 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3294 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3296 /* Output the CIE. */
3297 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3298 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3299 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3300 dw2_asm_output_data (4, 0xffffffff,
3301 "Initial length escape value indicating 64-bit DWARF extension");
3302 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3303 "Length of Common Information Entry");
3304 ASM_OUTPUT_LABEL (asm_out_file, l1);
3306 /* Now that the CIE pointer is PC-relative for EH,
3307 use 0 to identify the CIE. */
3308 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3309 (for_eh ? 0 : DWARF_CIE_ID),
3310 "CIE Identifier Tag");
3312 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3313 use CIE version 1, unless that would produce incorrect results
3314 due to overflowing the return register column. */
3315 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3317 if (return_reg >= 256 || dwarf_version > 2)
3319 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3321 augmentation[0] = 0;
3322 augmentation_size = 0;
3328 z Indicates that a uleb128 is present to size the
3329 augmentation section.
3330 L Indicates the encoding (and thus presence) of
3331 an LSDA pointer in the FDE augmentation.
3332 R Indicates a non-default pointer encoding for
3334 P Indicates the presence of an encoding + language
3335 personality routine in the CIE augmentation. */
3337 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3338 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3339 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3341 p = augmentation + 1;
3342 if (eh_personality_libfunc)
3345 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3346 assemble_external_libcall (eh_personality_libfunc);
3348 if (any_lsda_needed)
3351 augmentation_size += 1;
3353 if (fde_encoding != DW_EH_PE_absptr)
3356 augmentation_size += 1;
3358 if (p > augmentation + 1)
3360 augmentation[0] = 'z';
3364 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3365 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
3367 int offset = ( 4 /* Length */
3369 + 1 /* CIE version */
3370 + strlen (augmentation) + 1 /* Augmentation */
3371 + size_of_uleb128 (1) /* Code alignment */
3372 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3374 + 1 /* Augmentation size */
3375 + 1 /* Personality encoding */ );
3376 int pad = -offset & (PTR_SIZE - 1);
3378 augmentation_size += pad;
3380 /* Augmentations should be small, so there's scarce need to
3381 iterate for a solution. Die if we exceed one uleb128 byte. */
3382 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3386 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3387 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3388 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3389 "CIE Data Alignment Factor");
3391 if (dw_cie_version == 1)
3392 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3394 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3396 if (augmentation[0])
3398 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3399 if (eh_personality_libfunc)
3401 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3402 eh_data_format_name (per_encoding));
3403 dw2_asm_output_encoded_addr_rtx (per_encoding,
3404 eh_personality_libfunc,
3408 if (any_lsda_needed)
3409 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3410 eh_data_format_name (lsda_encoding));
3412 if (fde_encoding != DW_EH_PE_absptr)
3413 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3414 eh_data_format_name (fde_encoding));
3417 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3418 output_cfi (cfi, NULL, for_eh);
3420 /* Pad the CIE out to an address sized boundary. */
3421 ASM_OUTPUT_ALIGN (asm_out_file,
3422 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3423 ASM_OUTPUT_LABEL (asm_out_file, l2);
3425 /* Loop through all of the FDE's. */
3426 for (i = 0; i < fde_table_in_use; i++)
3428 fde = &fde_table[i];
3430 /* Don't emit EH unwind info for leaf functions that don't need it. */
3431 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3432 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3433 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3434 && !fde->uses_eh_lsda)
3437 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
3438 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
3439 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
3440 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
3441 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3442 dw2_asm_output_data (4, 0xffffffff,
3443 "Initial length escape value indicating 64-bit DWARF extension");
3444 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3446 ASM_OUTPUT_LABEL (asm_out_file, l1);
3449 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3451 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3452 debug_frame_section, "FDE CIE offset");
3456 if (fde->dw_fde_switched_sections)
3458 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
3459 fde->dw_fde_unlikely_section_label);
3460 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
3461 fde->dw_fde_hot_section_label);
3462 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3463 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3464 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3465 "FDE initial location");
3466 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3467 fde->dw_fde_hot_section_end_label,
3468 fde->dw_fde_hot_section_label,
3469 "FDE address range");
3470 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3471 "FDE initial location");
3472 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3473 fde->dw_fde_unlikely_section_end_label,
3474 fde->dw_fde_unlikely_section_label,
3475 "FDE address range");
3479 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3480 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3481 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3484 "FDE initial location");
3485 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3486 fde->dw_fde_end, fde->dw_fde_begin,
3487 "FDE address range");
3492 if (fde->dw_fde_switched_sections)
3494 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3495 fde->dw_fde_hot_section_label,
3496 "FDE initial location");
3497 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3498 fde->dw_fde_hot_section_end_label,
3499 fde->dw_fde_hot_section_label,
3500 "FDE address range");
3501 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3502 fde->dw_fde_unlikely_section_label,
3503 "FDE initial location");
3504 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3505 fde->dw_fde_unlikely_section_end_label,
3506 fde->dw_fde_unlikely_section_label,
3507 "FDE address range");
3511 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3512 "FDE initial location");
3513 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3514 fde->dw_fde_end, fde->dw_fde_begin,
3515 "FDE address range");
3519 if (augmentation[0])
3521 if (any_lsda_needed)
3523 int size = size_of_encoded_value (lsda_encoding);
3525 if (lsda_encoding == DW_EH_PE_aligned)
3527 int offset = ( 4 /* Length */
3528 + 4 /* CIE offset */
3529 + 2 * size_of_encoded_value (fde_encoding)
3530 + 1 /* Augmentation size */ );
3531 int pad = -offset & (PTR_SIZE - 1);
3534 gcc_assert (size_of_uleb128 (size) == 1);
3537 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3539 if (fde->uses_eh_lsda)
3541 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3542 fde->funcdef_number);
3543 dw2_asm_output_encoded_addr_rtx (
3544 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3545 false, "Language Specific Data Area");
3549 if (lsda_encoding == DW_EH_PE_aligned)
3550 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3552 (size_of_encoded_value (lsda_encoding), 0,
3553 "Language Specific Data Area (none)");
3557 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3560 /* Loop through the Call Frame Instructions associated with
3562 fde->dw_fde_current_label = fde->dw_fde_begin;
3563 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3564 output_cfi (cfi, fde, for_eh);
3566 /* Pad the FDE out to an address sized boundary. */
3567 ASM_OUTPUT_ALIGN (asm_out_file,
3568 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3569 ASM_OUTPUT_LABEL (asm_out_file, l2);
3572 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3573 dw2_asm_output_data (4, 0, "End of Table");
3574 #ifdef MIPS_DEBUGGING_INFO
3575 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3576 get a value of 0. Putting .align 0 after the label fixes it. */
3577 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3580 /* Turn off app to make assembly quicker. */
3585 /* Output a marker (i.e. a label) for the beginning of a function, before
3589 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3590 const char *file ATTRIBUTE_UNUSED)
3592 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3597 current_function_func_begin_label = NULL;
3599 #ifdef TARGET_UNWIND_INFO
3600 /* ??? current_function_func_begin_label is also used by except.c
3601 for call-site information. We must emit this label if it might
3603 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3604 && ! dwarf2out_do_frame ())
3607 if (! dwarf2out_do_frame ())
3611 fnsec = function_section (current_function_decl);
3612 switch_to_section (fnsec);
3613 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3614 current_function_funcdef_no);
3615 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3616 current_function_funcdef_no);
3617 dup_label = xstrdup (label);
3618 current_function_func_begin_label = dup_label;
3620 #ifdef TARGET_UNWIND_INFO
3621 /* We can elide the fde allocation if we're not emitting debug info. */
3622 if (! dwarf2out_do_frame ())
3626 /* Expand the fde table if necessary. */
3627 if (fde_table_in_use == fde_table_allocated)
3629 fde_table_allocated += FDE_TABLE_INCREMENT;
3630 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3631 memset (fde_table + fde_table_in_use, 0,
3632 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3635 /* Record the FDE associated with this function. */
3636 current_funcdef_fde = fde_table_in_use;
3638 /* Add the new FDE at the end of the fde_table. */
3639 fde = &fde_table[fde_table_in_use++];
3640 fde->decl = current_function_decl;
3641 fde->dw_fde_begin = dup_label;
3642 fde->dw_fde_current_label = dup_label;
3643 fde->dw_fde_hot_section_label = NULL;
3644 fde->dw_fde_hot_section_end_label = NULL;
3645 fde->dw_fde_unlikely_section_label = NULL;
3646 fde->dw_fde_unlikely_section_end_label = NULL;
3647 fde->dw_fde_switched_sections = false;
3648 fde->dw_fde_end = NULL;
3649 fde->dw_fde_cfi = NULL;
3650 fde->funcdef_number = current_function_funcdef_no;
3651 fde->nothrow = crtl->nothrow;
3652 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3653 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3654 fde->drap_reg = INVALID_REGNUM;
3655 fde->vdrap_reg = INVALID_REGNUM;
3656 if (flag_reorder_blocks_and_partition)
3658 section *unlikelysec;
3659 if (first_function_block_is_cold)
3660 fde->in_std_section = 1;
3663 = (fnsec == text_section
3664 || (cold_text_section && fnsec == cold_text_section));
3665 unlikelysec = unlikely_text_section ();
3666 fde->cold_in_std_section
3667 = (unlikelysec == text_section
3668 || (cold_text_section && unlikelysec == cold_text_section));
3673 = (fnsec == text_section
3674 || (cold_text_section && fnsec == cold_text_section));
3675 fde->cold_in_std_section = 0;
3678 args_size = old_args_size = 0;
3680 /* We only want to output line number information for the genuine dwarf2
3681 prologue case, not the eh frame case. */
3682 #ifdef DWARF2_DEBUGGING_INFO
3684 dwarf2out_source_line (line, file, 0, true);
3687 if (dwarf2out_do_cfi_asm ())
3692 fprintf (asm_out_file, "\t.cfi_startproc\n");
3694 if (eh_personality_libfunc)
3696 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3697 ref = eh_personality_libfunc;
3699 /* ??? The GAS support isn't entirely consistent. We have to
3700 handle indirect support ourselves, but PC-relative is done
3701 in the assembler. Further, the assembler can't handle any
3702 of the weirder relocation types. */
3703 if (enc & DW_EH_PE_indirect)
3704 ref = dw2_force_const_mem (ref, true);
3706 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3707 output_addr_const (asm_out_file, ref);
3708 fputc ('\n', asm_out_file);
3711 if (crtl->uses_eh_lsda)
3715 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3716 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3717 current_function_funcdef_no);
3718 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3719 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3721 if (enc & DW_EH_PE_indirect)
3722 ref = dw2_force_const_mem (ref, true);
3724 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3725 output_addr_const (asm_out_file, ref);
3726 fputc ('\n', asm_out_file);
3731 /* Output a marker (i.e. a label) for the absolute end of the generated code
3732 for a function definition. This gets called *after* the epilogue code has
3736 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3737 const char *file ATTRIBUTE_UNUSED)
3740 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3742 #ifdef DWARF2_DEBUGGING_INFO
3743 last_var_location_insn = NULL_RTX;
3746 if (dwarf2out_do_cfi_asm ())
3747 fprintf (asm_out_file, "\t.cfi_endproc\n");
3749 /* Output a label to mark the endpoint of the code generated for this
3751 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3752 current_function_funcdef_no);
3753 ASM_OUTPUT_LABEL (asm_out_file, label);
3754 fde = current_fde ();
3755 gcc_assert (fde != NULL);
3756 fde->dw_fde_end = xstrdup (label);
3760 dwarf2out_frame_init (void)
3762 /* Allocate the initial hunk of the fde_table. */
3763 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3764 fde_table_allocated = FDE_TABLE_INCREMENT;
3765 fde_table_in_use = 0;
3767 /* Generate the CFA instructions common to all FDE's. Do it now for the
3768 sake of lookup_cfa. */
3770 /* On entry, the Canonical Frame Address is at SP. */
3771 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3773 #ifdef DWARF2_UNWIND_INFO
3774 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3775 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3780 dwarf2out_frame_finish (void)
3782 /* Output call frame information. */
3783 if (DWARF2_FRAME_INFO)
3784 output_call_frame_info (0);
3786 #ifndef TARGET_UNWIND_INFO
3787 /* Output another copy for the unwinder. */
3788 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3789 output_call_frame_info (1);
3793 /* Note that the current function section is being used for code. */
3796 dwarf2out_note_section_used (void)
3798 section *sec = current_function_section ();
3799 if (sec == text_section)
3800 text_section_used = true;
3801 else if (sec == cold_text_section)
3802 cold_text_section_used = true;
3806 dwarf2out_switch_text_section (void)
3808 dw_fde_ref fde = current_fde ();
3810 gcc_assert (cfun && fde);
3812 fde->dw_fde_switched_sections = true;
3813 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3814 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3815 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3816 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3817 have_multiple_function_sections = true;
3819 /* Reset the current label on switching text sections, so that we
3820 don't attempt to advance_loc4 between labels in different sections. */
3821 fde->dw_fde_current_label = NULL;
3823 /* There is no need to mark used sections when not debugging. */
3824 if (cold_text_section != NULL)
3825 dwarf2out_note_section_used ();
3829 /* And now, the subset of the debugging information support code necessary
3830 for emitting location expressions. */
3832 /* Data about a single source file. */
3833 struct GTY(()) dwarf_file_data {
3834 const char * filename;
3838 typedef struct dw_val_struct *dw_val_ref;
3839 typedef struct die_struct *dw_die_ref;
3840 typedef const struct die_struct *const_dw_die_ref;
3841 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3842 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3844 typedef struct GTY(()) deferred_locations_struct
3848 } deferred_locations;
3850 DEF_VEC_O(deferred_locations);
3851 DEF_VEC_ALLOC_O(deferred_locations,gc);
3853 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
3855 /* Each DIE may have a series of attribute/value pairs. Values
3856 can take on several forms. The forms that are used in this
3857 implementation are listed below. */
3862 dw_val_class_offset,
3864 dw_val_class_loc_list,
3865 dw_val_class_range_list,
3867 dw_val_class_unsigned_const,
3868 dw_val_class_long_long,
3871 dw_val_class_die_ref,
3872 dw_val_class_fde_ref,
3873 dw_val_class_lbl_id,
3874 dw_val_class_lineptr,
3876 dw_val_class_macptr,
3880 /* Describe a double word constant value. */
3881 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3883 typedef struct GTY(()) dw_long_long_struct {
3889 /* Describe a floating point constant value, or a vector constant value. */
3891 typedef struct GTY(()) dw_vec_struct {
3892 unsigned char * GTY((length ("%h.length"))) array;
3898 /* The dw_val_node describes an attribute's value, as it is
3899 represented internally. */
3901 typedef struct GTY(()) dw_val_struct {
3902 enum dw_val_class val_class;
3903 union dw_val_struct_union
3905 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3906 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3907 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3908 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3909 HOST_WIDE_INT GTY ((default)) val_int;
3910 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3911 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3912 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3913 struct dw_val_die_union
3917 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3918 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3919 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3920 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3921 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3922 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3924 GTY ((desc ("%1.val_class"))) v;
3928 /* Locations in memory are described using a sequence of stack machine
3931 typedef struct GTY(()) dw_loc_descr_struct {
3932 dw_loc_descr_ref dw_loc_next;
3933 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
3934 /* Used to distinguish DW_OP_addr with a direct symbol relocation
3935 from DW_OP_addr with a dtp-relative symbol relocation. */
3936 unsigned int dtprel : 1;
3938 dw_val_node dw_loc_oprnd1;
3939 dw_val_node dw_loc_oprnd2;
3943 /* Location lists are ranges + location descriptions for that range,
3944 so you can track variables that are in different places over
3945 their entire life. */
3946 typedef struct GTY(()) dw_loc_list_struct {
3947 dw_loc_list_ref dw_loc_next;
3948 const char *begin; /* Label for begin address of range */
3949 const char *end; /* Label for end address of range */
3950 char *ll_symbol; /* Label for beginning of location list.
3951 Only on head of list */
3952 const char *section; /* Section this loclist is relative to */
3953 dw_loc_descr_ref expr;
3956 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3958 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3960 /* Convert a DWARF stack opcode into its string name. */
3963 dwarf_stack_op_name (unsigned int op)
3968 return "DW_OP_addr";
3970 return "DW_OP_deref";
3972 return "DW_OP_const1u";
3974 return "DW_OP_const1s";
3976 return "DW_OP_const2u";
3978 return "DW_OP_const2s";
3980 return "DW_OP_const4u";
3982 return "DW_OP_const4s";
3984 return "DW_OP_const8u";
3986 return "DW_OP_const8s";
3988 return "DW_OP_constu";
3990 return "DW_OP_consts";
3994 return "DW_OP_drop";
3996 return "DW_OP_over";
3998 return "DW_OP_pick";
4000 return "DW_OP_swap";
4004 return "DW_OP_xderef";
4012 return "DW_OP_minus";
4024 return "DW_OP_plus";
4025 case DW_OP_plus_uconst:
4026 return "DW_OP_plus_uconst";
4032 return "DW_OP_shra";
4050 return "DW_OP_skip";
4052 return "DW_OP_lit0";
4054 return "DW_OP_lit1";
4056 return "DW_OP_lit2";
4058 return "DW_OP_lit3";
4060 return "DW_OP_lit4";
4062 return "DW_OP_lit5";
4064 return "DW_OP_lit6";
4066 return "DW_OP_lit7";
4068 return "DW_OP_lit8";
4070 return "DW_OP_lit9";
4072 return "DW_OP_lit10";
4074 return "DW_OP_lit11";
4076 return "DW_OP_lit12";
4078 return "DW_OP_lit13";
4080 return "DW_OP_lit14";
4082 return "DW_OP_lit15";
4084 return "DW_OP_lit16";
4086 return "DW_OP_lit17";
4088 return "DW_OP_lit18";
4090 return "DW_OP_lit19";
4092 return "DW_OP_lit20";
4094 return "DW_OP_lit21";
4096 return "DW_OP_lit22";
4098 return "DW_OP_lit23";
4100 return "DW_OP_lit24";
4102 return "DW_OP_lit25";
4104 return "DW_OP_lit26";
4106 return "DW_OP_lit27";
4108 return "DW_OP_lit28";
4110 return "DW_OP_lit29";
4112 return "DW_OP_lit30";
4114 return "DW_OP_lit31";
4116 return "DW_OP_reg0";
4118 return "DW_OP_reg1";
4120 return "DW_OP_reg2";
4122 return "DW_OP_reg3";
4124 return "DW_OP_reg4";
4126 return "DW_OP_reg5";
4128 return "DW_OP_reg6";
4130 return "DW_OP_reg7";
4132 return "DW_OP_reg8";
4134 return "DW_OP_reg9";
4136 return "DW_OP_reg10";
4138 return "DW_OP_reg11";
4140 return "DW_OP_reg12";
4142 return "DW_OP_reg13";
4144 return "DW_OP_reg14";
4146 return "DW_OP_reg15";
4148 return "DW_OP_reg16";
4150 return "DW_OP_reg17";
4152 return "DW_OP_reg18";
4154 return "DW_OP_reg19";
4156 return "DW_OP_reg20";
4158 return "DW_OP_reg21";
4160 return "DW_OP_reg22";
4162 return "DW_OP_reg23";
4164 return "DW_OP_reg24";
4166 return "DW_OP_reg25";
4168 return "DW_OP_reg26";
4170 return "DW_OP_reg27";
4172 return "DW_OP_reg28";
4174 return "DW_OP_reg29";
4176 return "DW_OP_reg30";
4178 return "DW_OP_reg31";
4180 return "DW_OP_breg0";
4182 return "DW_OP_breg1";
4184 return "DW_OP_breg2";
4186 return "DW_OP_breg3";
4188 return "DW_OP_breg4";
4190 return "DW_OP_breg5";
4192 return "DW_OP_breg6";
4194 return "DW_OP_breg7";
4196 return "DW_OP_breg8";
4198 return "DW_OP_breg9";
4200 return "DW_OP_breg10";
4202 return "DW_OP_breg11";
4204 return "DW_OP_breg12";
4206 return "DW_OP_breg13";
4208 return "DW_OP_breg14";
4210 return "DW_OP_breg15";
4212 return "DW_OP_breg16";
4214 return "DW_OP_breg17";
4216 return "DW_OP_breg18";
4218 return "DW_OP_breg19";
4220 return "DW_OP_breg20";
4222 return "DW_OP_breg21";
4224 return "DW_OP_breg22";
4226 return "DW_OP_breg23";
4228 return "DW_OP_breg24";
4230 return "DW_OP_breg25";
4232 return "DW_OP_breg26";
4234 return "DW_OP_breg27";
4236 return "DW_OP_breg28";
4238 return "DW_OP_breg29";
4240 return "DW_OP_breg30";
4242 return "DW_OP_breg31";
4244 return "DW_OP_regx";
4246 return "DW_OP_fbreg";
4248 return "DW_OP_bregx";
4250 return "DW_OP_piece";
4251 case DW_OP_deref_size:
4252 return "DW_OP_deref_size";
4253 case DW_OP_xderef_size:
4254 return "DW_OP_xderef_size";
4258 case DW_OP_push_object_address:
4259 return "DW_OP_push_object_address";
4261 return "DW_OP_call2";
4263 return "DW_OP_call4";
4264 case DW_OP_call_ref:
4265 return "DW_OP_call_ref";
4266 case DW_OP_form_tls_address:
4267 return "DW_OP_form_tls_address";
4268 case DW_OP_call_frame_cfa:
4269 return "DW_OP_call_frame_cfa";
4270 case DW_OP_bit_piece:
4271 return "DW_OP_bit_piece";
4273 case DW_OP_GNU_push_tls_address:
4274 return "DW_OP_GNU_push_tls_address";
4275 case DW_OP_GNU_uninit:
4276 return "DW_OP_GNU_uninit";
4277 case DW_OP_GNU_encoded_addr:
4278 return "DW_OP_GNU_encoded_addr";
4281 return "OP_<unknown>";
4285 /* Return a pointer to a newly allocated location description. Location
4286 descriptions are simple expression terms that can be strung
4287 together to form more complicated location (address) descriptions. */
4289 static inline dw_loc_descr_ref
4290 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4291 unsigned HOST_WIDE_INT oprnd2)
4293 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4295 descr->dw_loc_opc = op;
4296 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4297 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4298 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4299 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4304 /* Return a pointer to a newly allocated location description for
4307 static inline dw_loc_descr_ref
4308 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4311 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4314 return new_loc_descr (DW_OP_bregx, reg, offset);
4317 /* Add a location description term to a location description expression. */
4320 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4322 dw_loc_descr_ref *d;
4324 /* Find the end of the chain. */
4325 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4331 /* Add a constant OFFSET to a location expression. */
4334 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4336 dw_loc_descr_ref loc;
4339 gcc_assert (*list_head != NULL);
4344 /* Find the end of the chain. */
4345 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4349 if (loc->dw_loc_opc == DW_OP_fbreg
4350 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4351 p = &loc->dw_loc_oprnd1.v.val_int;
4352 else if (loc->dw_loc_opc == DW_OP_bregx)
4353 p = &loc->dw_loc_oprnd2.v.val_int;
4355 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4356 offset. Don't optimize if an signed integer overflow would happen. */
4358 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4359 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4362 else if (offset > 0)
4363 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4367 loc->dw_loc_next = int_loc_descriptor (offset);
4368 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4372 /* Return the size of a location descriptor. */
4374 static unsigned long
4375 size_of_loc_descr (dw_loc_descr_ref loc)
4377 unsigned long size = 1;
4379 switch (loc->dw_loc_opc)
4382 size += DWARF2_ADDR_SIZE;
4401 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4404 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4409 case DW_OP_plus_uconst:
4410 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4448 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4451 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4454 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4457 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4458 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4461 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4463 case DW_OP_deref_size:
4464 case DW_OP_xderef_size:
4473 case DW_OP_call_ref:
4474 size += DWARF2_ADDR_SIZE;
4483 /* Return the size of a series of location descriptors. */
4485 static unsigned long
4486 size_of_locs (dw_loc_descr_ref loc)
4491 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4492 field, to avoid writing to a PCH file. */
4493 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4495 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4497 size += size_of_loc_descr (l);
4502 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4504 l->dw_loc_addr = size;
4505 size += size_of_loc_descr (l);
4511 /* Output location description stack opcode's operands (if any). */
4514 output_loc_operands (dw_loc_descr_ref loc)
4516 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4517 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4519 switch (loc->dw_loc_opc)
4521 #ifdef DWARF2_DEBUGGING_INFO
4524 dw2_asm_output_data (2, val1->v.val_int, NULL);
4528 dw2_asm_output_data (4, val1->v.val_int, NULL);
4532 gcc_assert (HOST_BITS_PER_LONG >= 64);
4533 dw2_asm_output_data (8, val1->v.val_int, NULL);
4540 gcc_assert (val1->val_class == dw_val_class_loc);
4541 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4543 dw2_asm_output_data (2, offset, NULL);
4555 /* We currently don't make any attempt to make sure these are
4556 aligned properly like we do for the main unwind info, so
4557 don't support emitting things larger than a byte if we're
4558 only doing unwinding. */
4563 dw2_asm_output_data (1, val1->v.val_int, NULL);
4566 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4569 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4572 dw2_asm_output_data (1, val1->v.val_int, NULL);
4574 case DW_OP_plus_uconst:
4575 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4609 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4612 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4615 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4618 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4619 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4622 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4624 case DW_OP_deref_size:
4625 case DW_OP_xderef_size:
4626 dw2_asm_output_data (1, val1->v.val_int, NULL);
4632 if (targetm.asm_out.output_dwarf_dtprel)
4634 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4637 fputc ('\n', asm_out_file);
4644 #ifdef DWARF2_DEBUGGING_INFO
4645 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4653 /* Other codes have no operands. */
4658 /* Output a sequence of location operations. */
4661 output_loc_sequence (dw_loc_descr_ref loc)
4663 for (; loc != NULL; loc = loc->dw_loc_next)
4665 /* Output the opcode. */
4666 dw2_asm_output_data (1, loc->dw_loc_opc,
4667 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4669 /* Output the operand(s) (if any). */
4670 output_loc_operands (loc);
4674 /* Output location description stack opcode's operands (if any).
4675 The output is single bytes on a line, suitable for .cfi_escape. */
4678 output_loc_operands_raw (dw_loc_descr_ref loc)
4680 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4681 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4683 switch (loc->dw_loc_opc)
4686 /* We cannot output addresses in .cfi_escape, only bytes. */
4692 case DW_OP_deref_size:
4693 case DW_OP_xderef_size:
4694 fputc (',', asm_out_file);
4695 dw2_asm_output_data_raw (1, val1->v.val_int);
4700 fputc (',', asm_out_file);
4701 dw2_asm_output_data_raw (2, val1->v.val_int);
4706 fputc (',', asm_out_file);
4707 dw2_asm_output_data_raw (4, val1->v.val_int);
4712 gcc_assert (HOST_BITS_PER_LONG >= 64);
4713 fputc (',', asm_out_file);
4714 dw2_asm_output_data_raw (8, val1->v.val_int);
4722 gcc_assert (val1->val_class == dw_val_class_loc);
4723 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4725 fputc (',', asm_out_file);
4726 dw2_asm_output_data_raw (2, offset);
4731 case DW_OP_plus_uconst:
4734 fputc (',', asm_out_file);
4735 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4772 fputc (',', asm_out_file);
4773 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4777 fputc (',', asm_out_file);
4778 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4779 fputc (',', asm_out_file);
4780 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4784 /* Other codes have no operands. */
4790 output_loc_sequence_raw (dw_loc_descr_ref loc)
4794 /* Output the opcode. */
4795 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4796 output_loc_operands_raw (loc);
4798 if (!loc->dw_loc_next)
4800 loc = loc->dw_loc_next;
4802 fputc (',', asm_out_file);
4806 /* This routine will generate the correct assembly data for a location
4807 description based on a cfi entry with a complex address. */
4810 output_cfa_loc (dw_cfi_ref cfi)
4812 dw_loc_descr_ref loc;
4815 if (cfi->dw_cfi_opc == DW_CFA_expression)
4816 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4818 /* Output the size of the block. */
4819 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4820 size = size_of_locs (loc);
4821 dw2_asm_output_data_uleb128 (size, NULL);
4823 /* Now output the operations themselves. */
4824 output_loc_sequence (loc);
4827 /* Similar, but used for .cfi_escape. */
4830 output_cfa_loc_raw (dw_cfi_ref cfi)
4832 dw_loc_descr_ref loc;
4835 if (cfi->dw_cfi_opc == DW_CFA_expression)
4836 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4838 /* Output the size of the block. */
4839 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4840 size = size_of_locs (loc);
4841 dw2_asm_output_data_uleb128_raw (size);
4842 fputc (',', asm_out_file);
4844 /* Now output the operations themselves. */
4845 output_loc_sequence_raw (loc);
4848 /* This function builds a dwarf location descriptor sequence from a
4849 dw_cfa_location, adding the given OFFSET to the result of the
4852 static struct dw_loc_descr_struct *
4853 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4855 struct dw_loc_descr_struct *head, *tmp;
4857 offset += cfa->offset;
4861 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4862 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4863 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4864 add_loc_descr (&head, tmp);
4867 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4868 add_loc_descr (&head, tmp);
4872 head = new_reg_loc_descr (cfa->reg, offset);
4877 /* This function builds a dwarf location descriptor sequence for
4878 the address at OFFSET from the CFA when stack is aligned to
4881 static struct dw_loc_descr_struct *
4882 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4884 struct dw_loc_descr_struct *head;
4885 unsigned int dwarf_fp
4886 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4888 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4889 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4891 head = new_reg_loc_descr (dwarf_fp, 0);
4892 add_loc_descr (&head, int_loc_descriptor (alignment));
4893 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4894 loc_descr_plus_const (&head, offset);
4897 head = new_reg_loc_descr (dwarf_fp, offset);
4901 /* This function fills in aa dw_cfa_location structure from a dwarf location
4902 descriptor sequence. */
4905 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4907 struct dw_loc_descr_struct *ptr;
4909 cfa->base_offset = 0;
4913 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4915 enum dwarf_location_atom op = ptr->dw_loc_opc;
4951 cfa->reg = op - DW_OP_reg0;
4954 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4988 cfa->reg = op - DW_OP_breg0;
4989 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4992 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4993 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4998 case DW_OP_plus_uconst:
4999 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5002 internal_error ("DW_LOC_OP %s not implemented",
5003 dwarf_stack_op_name (ptr->dw_loc_opc));
5007 #endif /* .debug_frame support */
5009 /* And now, the support for symbolic debugging information. */
5010 #ifdef DWARF2_DEBUGGING_INFO
5012 /* .debug_str support. */
5013 static int output_indirect_string (void **, void *);
5015 static void dwarf2out_init (const char *);
5016 static void dwarf2out_finish (const char *);
5017 static void dwarf2out_define (unsigned int, const char *);
5018 static void dwarf2out_undef (unsigned int, const char *);
5019 static void dwarf2out_start_source_file (unsigned, const char *);
5020 static void dwarf2out_end_source_file (unsigned);
5021 static void dwarf2out_begin_block (unsigned, unsigned);
5022 static void dwarf2out_end_block (unsigned, unsigned);
5023 static bool dwarf2out_ignore_block (const_tree);
5024 static void dwarf2out_global_decl (tree);
5025 static void dwarf2out_type_decl (tree, int);
5026 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5027 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5029 static void dwarf2out_abstract_function (tree);
5030 static void dwarf2out_var_location (rtx);
5031 static void dwarf2out_begin_function (tree);
5032 static void dwarf2out_set_name (tree, tree);
5034 /* The debug hooks structure. */
5036 const struct gcc_debug_hooks dwarf2_debug_hooks =
5042 dwarf2out_start_source_file,
5043 dwarf2out_end_source_file,
5044 dwarf2out_begin_block,
5045 dwarf2out_end_block,
5046 dwarf2out_ignore_block,
5047 dwarf2out_source_line,
5048 dwarf2out_begin_prologue,
5049 debug_nothing_int_charstar, /* end_prologue */
5050 dwarf2out_end_epilogue,
5051 dwarf2out_begin_function,
5052 debug_nothing_int, /* end_function */
5053 dwarf2out_decl, /* function_decl */
5054 dwarf2out_global_decl,
5055 dwarf2out_type_decl, /* type_decl */
5056 dwarf2out_imported_module_or_decl,
5057 debug_nothing_tree, /* deferred_inline_function */
5058 /* The DWARF 2 backend tries to reduce debugging bloat by not
5059 emitting the abstract description of inline functions until
5060 something tries to reference them. */
5061 dwarf2out_abstract_function, /* outlining_inline_function */
5062 debug_nothing_rtx, /* label */
5063 debug_nothing_int, /* handle_pch */
5064 dwarf2out_var_location,
5065 dwarf2out_switch_text_section,
5067 1 /* start_end_main_source_file */
5071 /* NOTE: In the comments in this file, many references are made to
5072 "Debugging Information Entries". This term is abbreviated as `DIE'
5073 throughout the remainder of this file. */
5075 /* An internal representation of the DWARF output is built, and then
5076 walked to generate the DWARF debugging info. The walk of the internal
5077 representation is done after the entire program has been compiled.
5078 The types below are used to describe the internal representation. */
5080 /* Various DIE's use offsets relative to the beginning of the
5081 .debug_info section to refer to each other. */
5083 typedef long int dw_offset;
5085 /* Define typedefs here to avoid circular dependencies. */
5087 typedef struct dw_attr_struct *dw_attr_ref;
5088 typedef struct dw_line_info_struct *dw_line_info_ref;
5089 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5090 typedef struct pubname_struct *pubname_ref;
5091 typedef struct dw_ranges_struct *dw_ranges_ref;
5092 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5094 /* Each entry in the line_info_table maintains the file and
5095 line number associated with the label generated for that
5096 entry. The label gives the PC value associated with
5097 the line number entry. */
5099 typedef struct GTY(()) dw_line_info_struct {
5100 unsigned long dw_file_num;
5101 unsigned long dw_line_num;
5105 /* Line information for functions in separate sections; each one gets its
5107 typedef struct GTY(()) dw_separate_line_info_struct {
5108 unsigned long dw_file_num;
5109 unsigned long dw_line_num;
5110 unsigned long function;
5112 dw_separate_line_info_entry;
5114 /* Each DIE attribute has a field specifying the attribute kind,
5115 a link to the next attribute in the chain, and an attribute value.
5116 Attributes are typically linked below the DIE they modify. */
5118 typedef struct GTY(()) dw_attr_struct {
5119 enum dwarf_attribute dw_attr;
5120 dw_val_node dw_attr_val;
5124 DEF_VEC_O(dw_attr_node);
5125 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5127 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5128 The children of each node form a circular list linked by
5129 die_sib. die_child points to the node *before* the "first" child node. */
5131 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5132 enum dwarf_tag die_tag;
5134 VEC(dw_attr_node,gc) * die_attr;
5135 dw_die_ref die_parent;
5136 dw_die_ref die_child;
5138 dw_die_ref die_definition; /* ref from a specification to its definition */
5139 dw_offset die_offset;
5140 unsigned long die_abbrev;
5142 /* Die is used and must not be pruned as unused. */
5143 int die_perennial_p;
5144 unsigned int decl_id;
5148 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5149 #define FOR_EACH_CHILD(die, c, expr) do { \
5150 c = die->die_child; \
5154 } while (c != die->die_child); \
5157 /* The pubname structure */
5159 typedef struct GTY(()) pubname_struct {
5165 DEF_VEC_O(pubname_entry);
5166 DEF_VEC_ALLOC_O(pubname_entry, gc);
5168 struct GTY(()) dw_ranges_struct {
5169 /* If this is positive, it's a block number, otherwise it's a
5170 bitwise-negated index into dw_ranges_by_label. */
5174 struct GTY(()) dw_ranges_by_label_struct {
5179 /* The limbo die list structure. */
5180 typedef struct GTY(()) limbo_die_struct {
5183 struct limbo_die_struct *next;
5187 /* How to start an assembler comment. */
5188 #ifndef ASM_COMMENT_START
5189 #define ASM_COMMENT_START ";#"
5192 /* Define a macro which returns nonzero for a TYPE_DECL which was
5193 implicitly generated for a tagged type.
5195 Note that unlike the gcc front end (which generates a NULL named
5196 TYPE_DECL node for each complete tagged type, each array type, and
5197 each function type node created) the g++ front end generates a
5198 _named_ TYPE_DECL node for each tagged type node created.
5199 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5200 generate a DW_TAG_typedef DIE for them. */
5202 #define TYPE_DECL_IS_STUB(decl) \
5203 (DECL_NAME (decl) == NULL_TREE \
5204 || (DECL_ARTIFICIAL (decl) \
5205 && is_tagged_type (TREE_TYPE (decl)) \
5206 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5207 /* This is necessary for stub decls that \
5208 appear in nested inline functions. */ \
5209 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5210 && (decl_ultimate_origin (decl) \
5211 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5213 /* Information concerning the compilation unit's programming
5214 language, and compiler version. */
5216 /* Fixed size portion of the DWARF compilation unit header. */
5217 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5218 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5220 /* Fixed size portion of public names info. */
5221 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5223 /* Fixed size portion of the address range info. */
5224 #define DWARF_ARANGES_HEADER_SIZE \
5225 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5226 DWARF2_ADDR_SIZE * 2) \
5227 - DWARF_INITIAL_LENGTH_SIZE)
5229 /* Size of padding portion in the address range info. It must be
5230 aligned to twice the pointer size. */
5231 #define DWARF_ARANGES_PAD_SIZE \
5232 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5233 DWARF2_ADDR_SIZE * 2) \
5234 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5236 /* Use assembler line directives if available. */
5237 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5238 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5239 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5241 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5245 /* Minimum line offset in a special line info. opcode.
5246 This value was chosen to give a reasonable range of values. */
5247 #define DWARF_LINE_BASE -10
5249 /* First special line opcode - leave room for the standard opcodes. */
5250 #define DWARF_LINE_OPCODE_BASE 10
5252 /* Range of line offsets in a special line info. opcode. */
5253 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5255 /* Flag that indicates the initial value of the is_stmt_start flag.
5256 In the present implementation, we do not mark any lines as
5257 the beginning of a source statement, because that information
5258 is not made available by the GCC front-end. */
5259 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5261 #ifdef DWARF2_DEBUGGING_INFO
5262 /* This location is used by calc_die_sizes() to keep track
5263 the offset of each DIE within the .debug_info section. */
5264 static unsigned long next_die_offset;
5267 /* Record the root of the DIE's built for the current compilation unit. */
5268 static GTY(()) dw_die_ref comp_unit_die;
5270 /* A list of DIEs with a NULL parent waiting to be relocated. */
5271 static GTY(()) limbo_die_node *limbo_die_list;
5273 /* A list of DIEs for which we may have to generate
5274 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5276 static GTY(()) limbo_die_node *deferred_asm_name;
5278 /* Filenames referenced by this compilation unit. */
5279 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5281 /* A hash table of references to DIE's that describe declarations.
5282 The key is a DECL_UID() which is a unique number identifying each decl. */
5283 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5285 /* A hash table of references to DIE's that describe COMMON blocks.
5286 The key is DECL_UID() ^ die_parent. */
5287 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5289 /* Node of the variable location list. */
5290 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5291 rtx GTY (()) var_loc_note;
5292 const char * GTY (()) label;
5293 const char * GTY (()) section_label;
5294 struct var_loc_node * GTY (()) next;
5297 /* Variable location list. */
5298 struct GTY (()) var_loc_list_def {
5299 struct var_loc_node * GTY (()) first;
5301 /* Do not mark the last element of the chained list because
5302 it is marked through the chain. */
5303 struct var_loc_node * GTY ((skip ("%h"))) last;
5305 /* DECL_UID of the variable decl. */
5306 unsigned int decl_id;
5308 typedef struct var_loc_list_def var_loc_list;
5311 /* Table of decl location linked lists. */
5312 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5314 /* A pointer to the base of a list of references to DIE's that
5315 are uniquely identified by their tag, presence/absence of
5316 children DIE's, and list of attribute/value pairs. */
5317 static GTY((length ("abbrev_die_table_allocated")))
5318 dw_die_ref *abbrev_die_table;
5320 /* Number of elements currently allocated for abbrev_die_table. */
5321 static GTY(()) unsigned abbrev_die_table_allocated;
5323 /* Number of elements in type_die_table currently in use. */
5324 static GTY(()) unsigned abbrev_die_table_in_use;
5326 /* Size (in elements) of increments by which we may expand the
5327 abbrev_die_table. */
5328 #define ABBREV_DIE_TABLE_INCREMENT 256
5330 /* A pointer to the base of a table that contains line information
5331 for each source code line in .text in the compilation unit. */
5332 static GTY((length ("line_info_table_allocated")))
5333 dw_line_info_ref line_info_table;
5335 /* Number of elements currently allocated for line_info_table. */
5336 static GTY(()) unsigned line_info_table_allocated;
5338 /* Number of elements in line_info_table currently in use. */
5339 static GTY(()) unsigned line_info_table_in_use;
5341 /* A pointer to the base of a table that contains line information
5342 for each source code line outside of .text in the compilation unit. */
5343 static GTY ((length ("separate_line_info_table_allocated")))
5344 dw_separate_line_info_ref separate_line_info_table;
5346 /* Number of elements currently allocated for separate_line_info_table. */
5347 static GTY(()) unsigned separate_line_info_table_allocated;
5349 /* Number of elements in separate_line_info_table currently in use. */
5350 static GTY(()) unsigned separate_line_info_table_in_use;
5352 /* Size (in elements) of increments by which we may expand the
5354 #define LINE_INFO_TABLE_INCREMENT 1024
5356 /* A pointer to the base of a table that contains a list of publicly
5357 accessible names. */
5358 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5360 /* A pointer to the base of a table that contains a list of publicly
5361 accessible types. */
5362 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5364 /* Array of dies for which we should generate .debug_arange info. */
5365 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5367 /* Number of elements currently allocated for arange_table. */
5368 static GTY(()) unsigned arange_table_allocated;
5370 /* Number of elements in arange_table currently in use. */
5371 static GTY(()) unsigned arange_table_in_use;
5373 /* Size (in elements) of increments by which we may expand the
5375 #define ARANGE_TABLE_INCREMENT 64
5377 /* Array of dies for which we should generate .debug_ranges info. */
5378 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5380 /* Number of elements currently allocated for ranges_table. */
5381 static GTY(()) unsigned ranges_table_allocated;
5383 /* Number of elements in ranges_table currently in use. */
5384 static GTY(()) unsigned ranges_table_in_use;
5386 /* Array of pairs of labels referenced in ranges_table. */
5387 static GTY ((length ("ranges_by_label_allocated")))
5388 dw_ranges_by_label_ref ranges_by_label;
5390 /* Number of elements currently allocated for ranges_by_label. */
5391 static GTY(()) unsigned ranges_by_label_allocated;
5393 /* Number of elements in ranges_by_label currently in use. */
5394 static GTY(()) unsigned ranges_by_label_in_use;
5396 /* Size (in elements) of increments by which we may expand the
5398 #define RANGES_TABLE_INCREMENT 64
5400 /* Whether we have location lists that need outputting */
5401 static GTY(()) bool have_location_lists;
5403 /* Unique label counter. */
5404 static GTY(()) unsigned int loclabel_num;
5406 #ifdef DWARF2_DEBUGGING_INFO
5407 /* Record whether the function being analyzed contains inlined functions. */
5408 static int current_function_has_inlines;
5410 #if 0 && defined (MIPS_DEBUGGING_INFO)
5411 static int comp_unit_has_inlines;
5414 /* The last file entry emitted by maybe_emit_file(). */
5415 static GTY(()) struct dwarf_file_data * last_emitted_file;
5417 /* Number of internal labels generated by gen_internal_sym(). */
5418 static GTY(()) int label_num;
5420 /* Cached result of previous call to lookup_filename. */
5421 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5423 #ifdef DWARF2_DEBUGGING_INFO
5425 /* Offset from the "steady-state frame pointer" to the frame base,
5426 within the current function. */
5427 static HOST_WIDE_INT frame_pointer_fb_offset;
5429 /* Forward declarations for functions defined in this file. */
5431 static int is_pseudo_reg (const_rtx);
5432 static tree type_main_variant (tree);
5433 static int is_tagged_type (const_tree);
5434 static const char *dwarf_tag_name (unsigned);
5435 static const char *dwarf_attr_name (unsigned);
5436 static const char *dwarf_form_name (unsigned);
5437 static tree decl_ultimate_origin (const_tree);
5438 static tree decl_class_context (tree);
5439 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5440 static inline enum dw_val_class AT_class (dw_attr_ref);
5441 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5442 static inline unsigned AT_flag (dw_attr_ref);
5443 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5444 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5445 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5446 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5447 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
5449 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5450 unsigned int, unsigned char *);
5451 static hashval_t debug_str_do_hash (const void *);
5452 static int debug_str_eq (const void *, const void *);
5453 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5454 static inline const char *AT_string (dw_attr_ref);
5455 static enum dwarf_form AT_string_form (dw_attr_ref);
5456 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5457 static void add_AT_specification (dw_die_ref, dw_die_ref);
5458 static inline dw_die_ref AT_ref (dw_attr_ref);
5459 static inline int AT_ref_external (dw_attr_ref);
5460 static inline void set_AT_ref_external (dw_attr_ref, int);
5461 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5462 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5463 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5464 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5466 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5467 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5468 static inline rtx AT_addr (dw_attr_ref);
5469 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5470 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5471 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5472 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5473 unsigned HOST_WIDE_INT);
5474 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5476 static inline const char *AT_lbl (dw_attr_ref);
5477 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5478 static const char *get_AT_low_pc (dw_die_ref);
5479 static const char *get_AT_hi_pc (dw_die_ref);
5480 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5481 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5482 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5483 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5484 static bool is_c_family (void);
5485 static bool is_cxx (void);
5486 static bool is_java (void);
5487 static bool is_fortran (void);
5488 static bool is_ada (void);
5489 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5490 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5491 static void add_child_die (dw_die_ref, dw_die_ref);
5492 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5493 static dw_die_ref lookup_type_die (tree);
5494 static void equate_type_number_to_die (tree, dw_die_ref);
5495 static hashval_t decl_die_table_hash (const void *);
5496 static int decl_die_table_eq (const void *, const void *);
5497 static dw_die_ref lookup_decl_die (tree);
5498 static hashval_t common_block_die_table_hash (const void *);
5499 static int common_block_die_table_eq (const void *, const void *);
5500 static hashval_t decl_loc_table_hash (const void *);
5501 static int decl_loc_table_eq (const void *, const void *);
5502 static var_loc_list *lookup_decl_loc (const_tree);
5503 static void equate_decl_number_to_die (tree, dw_die_ref);
5504 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5505 static void print_spaces (FILE *);
5506 static void print_die (dw_die_ref, FILE *);
5507 static void print_dwarf_line_table (FILE *);
5508 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5509 static dw_die_ref pop_compile_unit (dw_die_ref);
5510 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5511 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5512 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5513 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5514 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5515 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5516 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5517 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5518 static void compute_section_prefix (dw_die_ref);
5519 static int is_type_die (dw_die_ref);
5520 static int is_comdat_die (dw_die_ref);
5521 static int is_symbol_die (dw_die_ref);
5522 static void assign_symbol_names (dw_die_ref);
5523 static void break_out_includes (dw_die_ref);
5524 static hashval_t htab_cu_hash (const void *);
5525 static int htab_cu_eq (const void *, const void *);
5526 static void htab_cu_del (void *);
5527 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5528 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5529 static void add_sibling_attributes (dw_die_ref);
5530 static void build_abbrev_table (dw_die_ref);
5531 static void output_location_lists (dw_die_ref);
5532 static int constant_size (unsigned HOST_WIDE_INT);
5533 static unsigned long size_of_die (dw_die_ref);
5534 static void calc_die_sizes (dw_die_ref);
5535 static void mark_dies (dw_die_ref);
5536 static void unmark_dies (dw_die_ref);
5537 static void unmark_all_dies (dw_die_ref);
5538 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5539 static unsigned long size_of_aranges (void);
5540 static enum dwarf_form value_format (dw_attr_ref);
5541 static void output_value_format (dw_attr_ref);
5542 static void output_abbrev_section (void);
5543 static void output_die_symbol (dw_die_ref);
5544 static void output_die (dw_die_ref);
5545 static void output_compilation_unit_header (void);
5546 static void output_comp_unit (dw_die_ref, int);
5547 static const char *dwarf2_name (tree, int);
5548 static void add_pubname (tree, dw_die_ref);
5549 static void add_pubname_string (const char *, dw_die_ref);
5550 static void add_pubtype (tree, dw_die_ref);
5551 static void output_pubnames (VEC (pubname_entry,gc) *);
5552 static void add_arange (tree, dw_die_ref);
5553 static void output_aranges (void);
5554 static unsigned int add_ranges_num (int);
5555 static unsigned int add_ranges (const_tree);
5556 static unsigned int add_ranges_by_labels (const char *, const char *);
5557 static void output_ranges (void);
5558 static void output_line_info (void);
5559 static void output_file_names (void);
5560 static dw_die_ref base_type_die (tree);
5561 static int is_base_type (tree);
5562 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5563 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5564 static int type_is_enum (const_tree);
5565 static unsigned int dbx_reg_number (const_rtx);
5566 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5567 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5568 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5569 enum var_init_status);
5570 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5571 enum var_init_status);
5572 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5573 enum var_init_status);
5574 static int is_based_loc (const_rtx);
5575 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5576 enum var_init_status);
5577 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5578 enum var_init_status);
5579 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5580 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5581 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5582 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5583 static tree field_type (const_tree);
5584 static unsigned int simple_type_align_in_bits (const_tree);
5585 static unsigned int simple_decl_align_in_bits (const_tree);
5586 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5587 static HOST_WIDE_INT field_byte_offset (const_tree);
5588 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5590 static void add_data_member_location_attribute (dw_die_ref, tree);
5591 static void add_const_value_attribute (dw_die_ref, rtx);
5592 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5593 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5594 static void insert_float (const_rtx, unsigned char *);
5595 static rtx rtl_for_decl_location (tree);
5596 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5597 enum dwarf_attribute);
5598 static void tree_add_const_value_attribute (dw_die_ref, tree);
5599 static void add_name_attribute (dw_die_ref, const char *);
5600 static void add_comp_dir_attribute (dw_die_ref);
5601 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5602 static void add_subscript_info (dw_die_ref, tree, bool);
5603 static void add_byte_size_attribute (dw_die_ref, tree);
5604 static void add_bit_offset_attribute (dw_die_ref, tree);
5605 static void add_bit_size_attribute (dw_die_ref, tree);
5606 static void add_prototyped_attribute (dw_die_ref, tree);
5607 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5608 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5609 static void add_src_coords_attributes (dw_die_ref, tree);
5610 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5611 static void push_decl_scope (tree);
5612 static void pop_decl_scope (void);
5613 static dw_die_ref scope_die_for (tree, dw_die_ref);
5614 static inline int local_scope_p (dw_die_ref);
5615 static inline int class_scope_p (dw_die_ref);
5616 static inline int class_or_namespace_scope_p (dw_die_ref);
5617 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5618 static void add_calling_convention_attribute (dw_die_ref, tree);
5619 static const char *type_tag (const_tree);
5620 static tree member_declared_type (const_tree);
5622 static const char *decl_start_label (tree);
5624 static void gen_array_type_die (tree, dw_die_ref);
5625 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5627 static void gen_entry_point_die (tree, dw_die_ref);
5629 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5630 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5631 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5632 static void gen_formal_types_die (tree, dw_die_ref);
5633 static void gen_subprogram_die (tree, dw_die_ref);
5634 static void gen_variable_die (tree, tree, dw_die_ref);
5635 static void gen_const_die (tree, dw_die_ref);
5636 static void gen_label_die (tree, dw_die_ref);
5637 static void gen_lexical_block_die (tree, dw_die_ref, int);
5638 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5639 static void gen_field_die (tree, dw_die_ref);
5640 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5641 static dw_die_ref gen_compile_unit_die (const char *);
5642 static void gen_inheritance_die (tree, tree, dw_die_ref);
5643 static void gen_member_die (tree, dw_die_ref);
5644 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5645 enum debug_info_usage);
5646 static void gen_subroutine_type_die (tree, dw_die_ref);
5647 static void gen_typedef_die (tree, dw_die_ref);
5648 static void gen_type_die (tree, dw_die_ref);
5649 static void gen_block_die (tree, dw_die_ref, int);
5650 static void decls_for_scope (tree, dw_die_ref, int);
5651 static int is_redundant_typedef (const_tree);
5652 static void gen_namespace_die (tree, dw_die_ref);
5653 static void gen_decl_die (tree, tree, dw_die_ref);
5654 static dw_die_ref force_decl_die (tree);
5655 static dw_die_ref force_type_die (tree);
5656 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5657 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5658 static struct dwarf_file_data * lookup_filename (const char *);
5659 static void retry_incomplete_types (void);
5660 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5661 static void splice_child_die (dw_die_ref, dw_die_ref);
5662 static int file_info_cmp (const void *, const void *);
5663 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5664 const char *, const char *, unsigned);
5665 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5666 const char *, const char *,
5668 static void output_loc_list (dw_loc_list_ref);
5669 static char *gen_internal_sym (const char *);
5671 static void prune_unmark_dies (dw_die_ref);
5672 static void prune_unused_types_mark (dw_die_ref, int);
5673 static void prune_unused_types_walk (dw_die_ref);
5674 static void prune_unused_types_walk_attribs (dw_die_ref);
5675 static void prune_unused_types_prune (dw_die_ref);
5676 static void prune_unused_types (void);
5677 static int maybe_emit_file (struct dwarf_file_data *fd);
5679 /* Section names used to hold DWARF debugging information. */
5680 #ifndef DEBUG_INFO_SECTION
5681 #define DEBUG_INFO_SECTION ".debug_info"
5683 #ifndef DEBUG_ABBREV_SECTION
5684 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5686 #ifndef DEBUG_ARANGES_SECTION
5687 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5689 #ifndef DEBUG_MACINFO_SECTION
5690 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5692 #ifndef DEBUG_LINE_SECTION
5693 #define DEBUG_LINE_SECTION ".debug_line"
5695 #ifndef DEBUG_LOC_SECTION
5696 #define DEBUG_LOC_SECTION ".debug_loc"
5698 #ifndef DEBUG_PUBNAMES_SECTION
5699 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5701 #ifndef DEBUG_PUBTYPES_SECTION
5702 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
5704 #ifndef DEBUG_STR_SECTION
5705 #define DEBUG_STR_SECTION ".debug_str"
5707 #ifndef DEBUG_RANGES_SECTION
5708 #define DEBUG_RANGES_SECTION ".debug_ranges"
5711 /* Standard ELF section names for compiled code and data. */
5712 #ifndef TEXT_SECTION_NAME
5713 #define TEXT_SECTION_NAME ".text"
5716 /* Section flags for .debug_str section. */
5717 #define DEBUG_STR_SECTION_FLAGS \
5718 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5719 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5722 /* Labels we insert at beginning sections we can reference instead of
5723 the section names themselves. */
5725 #ifndef TEXT_SECTION_LABEL
5726 #define TEXT_SECTION_LABEL "Ltext"
5728 #ifndef COLD_TEXT_SECTION_LABEL
5729 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5731 #ifndef DEBUG_LINE_SECTION_LABEL
5732 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5734 #ifndef DEBUG_INFO_SECTION_LABEL
5735 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5737 #ifndef DEBUG_ABBREV_SECTION_LABEL
5738 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5740 #ifndef DEBUG_LOC_SECTION_LABEL
5741 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5743 #ifndef DEBUG_RANGES_SECTION_LABEL
5744 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5746 #ifndef DEBUG_MACINFO_SECTION_LABEL
5747 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5750 /* Definitions of defaults for formats and names of various special
5751 (artificial) labels which may be generated within this file (when the -g
5752 options is used and DWARF2_DEBUGGING_INFO is in effect.
5753 If necessary, these may be overridden from within the tm.h file, but
5754 typically, overriding these defaults is unnecessary. */
5756 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5757 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5758 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5759 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5760 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5761 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5762 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5763 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5764 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5765 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5767 #ifndef TEXT_END_LABEL
5768 #define TEXT_END_LABEL "Letext"
5770 #ifndef COLD_END_LABEL
5771 #define COLD_END_LABEL "Letext_cold"
5773 #ifndef BLOCK_BEGIN_LABEL
5774 #define BLOCK_BEGIN_LABEL "LBB"
5776 #ifndef BLOCK_END_LABEL
5777 #define BLOCK_END_LABEL "LBE"
5779 #ifndef LINE_CODE_LABEL
5780 #define LINE_CODE_LABEL "LM"
5782 #ifndef SEPARATE_LINE_CODE_LABEL
5783 #define SEPARATE_LINE_CODE_LABEL "LSM"
5787 /* We allow a language front-end to designate a function that is to be
5788 called to "demangle" any name before it is put into a DIE. */
5790 static const char *(*demangle_name_func) (const char *);
5793 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5795 demangle_name_func = func;
5798 /* Test if rtl node points to a pseudo register. */
5801 is_pseudo_reg (const_rtx rtl)
5803 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5804 || (GET_CODE (rtl) == SUBREG
5805 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5808 /* Return a reference to a type, with its const and volatile qualifiers
5812 type_main_variant (tree type)
5814 type = TYPE_MAIN_VARIANT (type);
5816 /* ??? There really should be only one main variant among any group of
5817 variants of a given type (and all of the MAIN_VARIANT values for all
5818 members of the group should point to that one type) but sometimes the C
5819 front-end messes this up for array types, so we work around that bug
5821 if (TREE_CODE (type) == ARRAY_TYPE)
5822 while (type != TYPE_MAIN_VARIANT (type))
5823 type = TYPE_MAIN_VARIANT (type);
5828 /* Return nonzero if the given type node represents a tagged type. */
5831 is_tagged_type (const_tree type)
5833 enum tree_code code = TREE_CODE (type);
5835 return (code == RECORD_TYPE || code == UNION_TYPE
5836 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5839 /* Convert a DIE tag into its string name. */
5842 dwarf_tag_name (unsigned int tag)
5846 case DW_TAG_padding:
5847 return "DW_TAG_padding";
5848 case DW_TAG_array_type:
5849 return "DW_TAG_array_type";
5850 case DW_TAG_class_type:
5851 return "DW_TAG_class_type";
5852 case DW_TAG_entry_point:
5853 return "DW_TAG_entry_point";
5854 case DW_TAG_enumeration_type:
5855 return "DW_TAG_enumeration_type";
5856 case DW_TAG_formal_parameter:
5857 return "DW_TAG_formal_parameter";
5858 case DW_TAG_imported_declaration:
5859 return "DW_TAG_imported_declaration";
5861 return "DW_TAG_label";
5862 case DW_TAG_lexical_block:
5863 return "DW_TAG_lexical_block";
5865 return "DW_TAG_member";
5866 case DW_TAG_pointer_type:
5867 return "DW_TAG_pointer_type";
5868 case DW_TAG_reference_type:
5869 return "DW_TAG_reference_type";
5870 case DW_TAG_compile_unit:
5871 return "DW_TAG_compile_unit";
5872 case DW_TAG_string_type:
5873 return "DW_TAG_string_type";
5874 case DW_TAG_structure_type:
5875 return "DW_TAG_structure_type";
5876 case DW_TAG_subroutine_type:
5877 return "DW_TAG_subroutine_type";
5878 case DW_TAG_typedef:
5879 return "DW_TAG_typedef";
5880 case DW_TAG_union_type:
5881 return "DW_TAG_union_type";
5882 case DW_TAG_unspecified_parameters:
5883 return "DW_TAG_unspecified_parameters";
5884 case DW_TAG_variant:
5885 return "DW_TAG_variant";
5886 case DW_TAG_common_block:
5887 return "DW_TAG_common_block";
5888 case DW_TAG_common_inclusion:
5889 return "DW_TAG_common_inclusion";
5890 case DW_TAG_inheritance:
5891 return "DW_TAG_inheritance";
5892 case DW_TAG_inlined_subroutine:
5893 return "DW_TAG_inlined_subroutine";
5895 return "DW_TAG_module";
5896 case DW_TAG_ptr_to_member_type:
5897 return "DW_TAG_ptr_to_member_type";
5898 case DW_TAG_set_type:
5899 return "DW_TAG_set_type";
5900 case DW_TAG_subrange_type:
5901 return "DW_TAG_subrange_type";
5902 case DW_TAG_with_stmt:
5903 return "DW_TAG_with_stmt";
5904 case DW_TAG_access_declaration:
5905 return "DW_TAG_access_declaration";
5906 case DW_TAG_base_type:
5907 return "DW_TAG_base_type";
5908 case DW_TAG_catch_block:
5909 return "DW_TAG_catch_block";
5910 case DW_TAG_const_type:
5911 return "DW_TAG_const_type";
5912 case DW_TAG_constant:
5913 return "DW_TAG_constant";
5914 case DW_TAG_enumerator:
5915 return "DW_TAG_enumerator";
5916 case DW_TAG_file_type:
5917 return "DW_TAG_file_type";
5919 return "DW_TAG_friend";
5920 case DW_TAG_namelist:
5921 return "DW_TAG_namelist";
5922 case DW_TAG_namelist_item:
5923 return "DW_TAG_namelist_item";
5924 case DW_TAG_packed_type:
5925 return "DW_TAG_packed_type";
5926 case DW_TAG_subprogram:
5927 return "DW_TAG_subprogram";
5928 case DW_TAG_template_type_param:
5929 return "DW_TAG_template_type_param";
5930 case DW_TAG_template_value_param:
5931 return "DW_TAG_template_value_param";
5932 case DW_TAG_thrown_type:
5933 return "DW_TAG_thrown_type";
5934 case DW_TAG_try_block:
5935 return "DW_TAG_try_block";
5936 case DW_TAG_variant_part:
5937 return "DW_TAG_variant_part";
5938 case DW_TAG_variable:
5939 return "DW_TAG_variable";
5940 case DW_TAG_volatile_type:
5941 return "DW_TAG_volatile_type";
5942 case DW_TAG_dwarf_procedure:
5943 return "DW_TAG_dwarf_procedure";
5944 case DW_TAG_restrict_type:
5945 return "DW_TAG_restrict_type";
5946 case DW_TAG_interface_type:
5947 return "DW_TAG_interface_type";
5948 case DW_TAG_namespace:
5949 return "DW_TAG_namespace";
5950 case DW_TAG_imported_module:
5951 return "DW_TAG_imported_module";
5952 case DW_TAG_unspecified_type:
5953 return "DW_TAG_unspecified_type";
5954 case DW_TAG_partial_unit:
5955 return "DW_TAG_partial_unit";
5956 case DW_TAG_imported_unit:
5957 return "DW_TAG_imported_unit";
5958 case DW_TAG_condition:
5959 return "DW_TAG_condition";
5960 case DW_TAG_shared_type:
5961 return "DW_TAG_shared_type";
5962 case DW_TAG_MIPS_loop:
5963 return "DW_TAG_MIPS_loop";
5964 case DW_TAG_format_label:
5965 return "DW_TAG_format_label";
5966 case DW_TAG_function_template:
5967 return "DW_TAG_function_template";
5968 case DW_TAG_class_template:
5969 return "DW_TAG_class_template";
5970 case DW_TAG_GNU_BINCL:
5971 return "DW_TAG_GNU_BINCL";
5972 case DW_TAG_GNU_EINCL:
5973 return "DW_TAG_GNU_EINCL";
5975 return "DW_TAG_<unknown>";
5979 /* Convert a DWARF attribute code into its string name. */
5982 dwarf_attr_name (unsigned int attr)
5987 return "DW_AT_sibling";
5988 case DW_AT_location:
5989 return "DW_AT_location";
5991 return "DW_AT_name";
5992 case DW_AT_ordering:
5993 return "DW_AT_ordering";
5994 case DW_AT_subscr_data:
5995 return "DW_AT_subscr_data";
5996 case DW_AT_byte_size:
5997 return "DW_AT_byte_size";
5998 case DW_AT_bit_offset:
5999 return "DW_AT_bit_offset";
6000 case DW_AT_bit_size:
6001 return "DW_AT_bit_size";
6002 case DW_AT_element_list:
6003 return "DW_AT_element_list";
6004 case DW_AT_stmt_list:
6005 return "DW_AT_stmt_list";
6007 return "DW_AT_low_pc";
6009 return "DW_AT_high_pc";
6010 case DW_AT_language:
6011 return "DW_AT_language";
6013 return "DW_AT_member";
6015 return "DW_AT_discr";
6016 case DW_AT_discr_value:
6017 return "DW_AT_discr_value";
6018 case DW_AT_visibility:
6019 return "DW_AT_visibility";
6021 return "DW_AT_import";
6022 case DW_AT_string_length:
6023 return "DW_AT_string_length";
6024 case DW_AT_common_reference:
6025 return "DW_AT_common_reference";
6026 case DW_AT_comp_dir:
6027 return "DW_AT_comp_dir";
6028 case DW_AT_const_value:
6029 return "DW_AT_const_value";
6030 case DW_AT_containing_type:
6031 return "DW_AT_containing_type";
6032 case DW_AT_default_value:
6033 return "DW_AT_default_value";
6035 return "DW_AT_inline";
6036 case DW_AT_is_optional:
6037 return "DW_AT_is_optional";
6038 case DW_AT_lower_bound:
6039 return "DW_AT_lower_bound";
6040 case DW_AT_producer:
6041 return "DW_AT_producer";
6042 case DW_AT_prototyped:
6043 return "DW_AT_prototyped";
6044 case DW_AT_return_addr:
6045 return "DW_AT_return_addr";
6046 case DW_AT_start_scope:
6047 return "DW_AT_start_scope";
6048 case DW_AT_bit_stride:
6049 return "DW_AT_bit_stride";
6050 case DW_AT_upper_bound:
6051 return "DW_AT_upper_bound";
6052 case DW_AT_abstract_origin:
6053 return "DW_AT_abstract_origin";
6054 case DW_AT_accessibility:
6055 return "DW_AT_accessibility";
6056 case DW_AT_address_class:
6057 return "DW_AT_address_class";
6058 case DW_AT_artificial:
6059 return "DW_AT_artificial";
6060 case DW_AT_base_types:
6061 return "DW_AT_base_types";
6062 case DW_AT_calling_convention:
6063 return "DW_AT_calling_convention";
6065 return "DW_AT_count";
6066 case DW_AT_data_member_location:
6067 return "DW_AT_data_member_location";
6068 case DW_AT_decl_column:
6069 return "DW_AT_decl_column";
6070 case DW_AT_decl_file:
6071 return "DW_AT_decl_file";
6072 case DW_AT_decl_line:
6073 return "DW_AT_decl_line";
6074 case DW_AT_declaration:
6075 return "DW_AT_declaration";
6076 case DW_AT_discr_list:
6077 return "DW_AT_discr_list";
6078 case DW_AT_encoding:
6079 return "DW_AT_encoding";
6080 case DW_AT_external:
6081 return "DW_AT_external";
6082 case DW_AT_explicit:
6083 return "DW_AT_explicit";
6084 case DW_AT_frame_base:
6085 return "DW_AT_frame_base";
6087 return "DW_AT_friend";
6088 case DW_AT_identifier_case:
6089 return "DW_AT_identifier_case";
6090 case DW_AT_macro_info:
6091 return "DW_AT_macro_info";
6092 case DW_AT_namelist_items:
6093 return "DW_AT_namelist_items";
6094 case DW_AT_priority:
6095 return "DW_AT_priority";
6097 return "DW_AT_segment";
6098 case DW_AT_specification:
6099 return "DW_AT_specification";
6100 case DW_AT_static_link:
6101 return "DW_AT_static_link";
6103 return "DW_AT_type";
6104 case DW_AT_use_location:
6105 return "DW_AT_use_location";
6106 case DW_AT_variable_parameter:
6107 return "DW_AT_variable_parameter";
6108 case DW_AT_virtuality:
6109 return "DW_AT_virtuality";
6110 case DW_AT_vtable_elem_location:
6111 return "DW_AT_vtable_elem_location";
6113 case DW_AT_allocated:
6114 return "DW_AT_allocated";
6115 case DW_AT_associated:
6116 return "DW_AT_associated";
6117 case DW_AT_data_location:
6118 return "DW_AT_data_location";
6119 case DW_AT_byte_stride:
6120 return "DW_AT_byte_stride";
6121 case DW_AT_entry_pc:
6122 return "DW_AT_entry_pc";
6123 case DW_AT_use_UTF8:
6124 return "DW_AT_use_UTF8";
6125 case DW_AT_extension:
6126 return "DW_AT_extension";
6128 return "DW_AT_ranges";
6129 case DW_AT_trampoline:
6130 return "DW_AT_trampoline";
6131 case DW_AT_call_column:
6132 return "DW_AT_call_column";
6133 case DW_AT_call_file:
6134 return "DW_AT_call_file";
6135 case DW_AT_call_line:
6136 return "DW_AT_call_line";
6138 case DW_AT_MIPS_fde:
6139 return "DW_AT_MIPS_fde";
6140 case DW_AT_MIPS_loop_begin:
6141 return "DW_AT_MIPS_loop_begin";
6142 case DW_AT_MIPS_tail_loop_begin:
6143 return "DW_AT_MIPS_tail_loop_begin";
6144 case DW_AT_MIPS_epilog_begin:
6145 return "DW_AT_MIPS_epilog_begin";
6146 case DW_AT_MIPS_loop_unroll_factor:
6147 return "DW_AT_MIPS_loop_unroll_factor";
6148 case DW_AT_MIPS_software_pipeline_depth:
6149 return "DW_AT_MIPS_software_pipeline_depth";
6150 case DW_AT_MIPS_linkage_name:
6151 return "DW_AT_MIPS_linkage_name";
6152 case DW_AT_MIPS_stride:
6153 return "DW_AT_MIPS_stride";
6154 case DW_AT_MIPS_abstract_name:
6155 return "DW_AT_MIPS_abstract_name";
6156 case DW_AT_MIPS_clone_origin:
6157 return "DW_AT_MIPS_clone_origin";
6158 case DW_AT_MIPS_has_inlines:
6159 return "DW_AT_MIPS_has_inlines";
6161 case DW_AT_sf_names:
6162 return "DW_AT_sf_names";
6163 case DW_AT_src_info:
6164 return "DW_AT_src_info";
6165 case DW_AT_mac_info:
6166 return "DW_AT_mac_info";
6167 case DW_AT_src_coords:
6168 return "DW_AT_src_coords";
6169 case DW_AT_body_begin:
6170 return "DW_AT_body_begin";
6171 case DW_AT_body_end:
6172 return "DW_AT_body_end";
6173 case DW_AT_GNU_vector:
6174 return "DW_AT_GNU_vector";
6176 case DW_AT_VMS_rtnbeg_pd_address:
6177 return "DW_AT_VMS_rtnbeg_pd_address";
6180 return "DW_AT_<unknown>";
6184 /* Convert a DWARF value form code into its string name. */
6187 dwarf_form_name (unsigned int form)
6192 return "DW_FORM_addr";
6193 case DW_FORM_block2:
6194 return "DW_FORM_block2";
6195 case DW_FORM_block4:
6196 return "DW_FORM_block4";
6198 return "DW_FORM_data2";
6200 return "DW_FORM_data4";
6202 return "DW_FORM_data8";
6203 case DW_FORM_string:
6204 return "DW_FORM_string";
6206 return "DW_FORM_block";
6207 case DW_FORM_block1:
6208 return "DW_FORM_block1";
6210 return "DW_FORM_data1";
6212 return "DW_FORM_flag";
6214 return "DW_FORM_sdata";
6216 return "DW_FORM_strp";
6218 return "DW_FORM_udata";
6219 case DW_FORM_ref_addr:
6220 return "DW_FORM_ref_addr";
6222 return "DW_FORM_ref1";
6224 return "DW_FORM_ref2";
6226 return "DW_FORM_ref4";
6228 return "DW_FORM_ref8";
6229 case DW_FORM_ref_udata:
6230 return "DW_FORM_ref_udata";
6231 case DW_FORM_indirect:
6232 return "DW_FORM_indirect";
6234 return "DW_FORM_<unknown>";
6238 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6239 instance of an inlined instance of a decl which is local to an inline
6240 function, so we have to trace all of the way back through the origin chain
6241 to find out what sort of node actually served as the original seed for the
6245 decl_ultimate_origin (const_tree decl)
6247 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6250 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6251 nodes in the function to point to themselves; ignore that if
6252 we're trying to output the abstract instance of this function. */
6253 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6256 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6257 most distant ancestor, this should never happen. */
6258 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6260 return DECL_ABSTRACT_ORIGIN (decl);
6263 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6264 of a virtual function may refer to a base class, so we check the 'this'
6268 decl_class_context (tree decl)
6270 tree context = NULL_TREE;
6272 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6273 context = DECL_CONTEXT (decl);
6275 context = TYPE_MAIN_VARIANT
6276 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6278 if (context && !TYPE_P (context))
6279 context = NULL_TREE;
6284 /* Add an attribute/value pair to a DIE. */
6287 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6289 /* Maybe this should be an assert? */
6293 if (die->die_attr == NULL)
6294 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6295 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6298 static inline enum dw_val_class
6299 AT_class (dw_attr_ref a)
6301 return a->dw_attr_val.val_class;
6304 /* Add a flag value attribute to a DIE. */
6307 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6311 attr.dw_attr = attr_kind;
6312 attr.dw_attr_val.val_class = dw_val_class_flag;
6313 attr.dw_attr_val.v.val_flag = flag;
6314 add_dwarf_attr (die, &attr);
6317 static inline unsigned
6318 AT_flag (dw_attr_ref a)
6320 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6321 return a->dw_attr_val.v.val_flag;
6324 /* Add a signed integer attribute value to a DIE. */
6327 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6331 attr.dw_attr = attr_kind;
6332 attr.dw_attr_val.val_class = dw_val_class_const;
6333 attr.dw_attr_val.v.val_int = int_val;
6334 add_dwarf_attr (die, &attr);
6337 static inline HOST_WIDE_INT
6338 AT_int (dw_attr_ref a)
6340 gcc_assert (a && AT_class (a) == dw_val_class_const);
6341 return a->dw_attr_val.v.val_int;
6344 /* Add an unsigned integer attribute value to a DIE. */
6347 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6348 unsigned HOST_WIDE_INT unsigned_val)
6352 attr.dw_attr = attr_kind;
6353 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6354 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6355 add_dwarf_attr (die, &attr);
6358 static inline unsigned HOST_WIDE_INT
6359 AT_unsigned (dw_attr_ref a)
6361 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6362 return a->dw_attr_val.v.val_unsigned;
6365 /* Add an unsigned double integer attribute value to a DIE. */
6368 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6369 long unsigned int val_hi, long unsigned int val_low)
6373 attr.dw_attr = attr_kind;
6374 attr.dw_attr_val.val_class = dw_val_class_long_long;
6375 attr.dw_attr_val.v.val_long_long.hi = val_hi;
6376 attr.dw_attr_val.v.val_long_long.low = val_low;
6377 add_dwarf_attr (die, &attr);
6380 /* Add a floating point attribute value to a DIE and return it. */
6383 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6384 unsigned int length, unsigned int elt_size, unsigned char *array)
6388 attr.dw_attr = attr_kind;
6389 attr.dw_attr_val.val_class = dw_val_class_vec;
6390 attr.dw_attr_val.v.val_vec.length = length;
6391 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6392 attr.dw_attr_val.v.val_vec.array = array;
6393 add_dwarf_attr (die, &attr);
6396 /* Hash and equality functions for debug_str_hash. */
6399 debug_str_do_hash (const void *x)
6401 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6405 debug_str_eq (const void *x1, const void *x2)
6407 return strcmp ((((const struct indirect_string_node *)x1)->str),
6408 (const char *)x2) == 0;
6411 static struct indirect_string_node *
6412 find_AT_string (const char *str)
6414 struct indirect_string_node *node;
6417 if (! debug_str_hash)
6418 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6419 debug_str_eq, NULL);
6421 slot = htab_find_slot_with_hash (debug_str_hash, str,
6422 htab_hash_string (str), INSERT);
6425 node = (struct indirect_string_node *)
6426 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6427 node->str = ggc_strdup (str);
6431 node = (struct indirect_string_node *) *slot;
6437 /* Add a string attribute value to a DIE. */
6440 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6443 struct indirect_string_node *node;
6445 node = find_AT_string (str);
6447 attr.dw_attr = attr_kind;
6448 attr.dw_attr_val.val_class = dw_val_class_str;
6449 attr.dw_attr_val.v.val_str = node;
6450 add_dwarf_attr (die, &attr);
6453 static inline const char *
6454 AT_string (dw_attr_ref a)
6456 gcc_assert (a && AT_class (a) == dw_val_class_str);
6457 return a->dw_attr_val.v.val_str->str;
6460 /* Find out whether a string should be output inline in DIE
6461 or out-of-line in .debug_str section. */
6463 static enum dwarf_form
6464 AT_string_form (dw_attr_ref a)
6466 struct indirect_string_node *node;
6470 gcc_assert (a && AT_class (a) == dw_val_class_str);
6472 node = a->dw_attr_val.v.val_str;
6476 len = strlen (node->str) + 1;
6478 /* If the string is shorter or equal to the size of the reference, it is
6479 always better to put it inline. */
6480 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6481 return node->form = DW_FORM_string;
6483 /* If we cannot expect the linker to merge strings in .debug_str
6484 section, only put it into .debug_str if it is worth even in this
6486 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
6487 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
6488 return node->form = DW_FORM_string;
6490 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6491 ++dw2_string_counter;
6492 node->label = xstrdup (label);
6494 return node->form = DW_FORM_strp;
6497 /* Add a DIE reference attribute value to a DIE. */
6500 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6504 attr.dw_attr = attr_kind;
6505 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6506 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6507 attr.dw_attr_val.v.val_die_ref.external = 0;
6508 add_dwarf_attr (die, &attr);
6511 /* Add an AT_specification attribute to a DIE, and also make the back
6512 pointer from the specification to the definition. */
6515 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6517 add_AT_die_ref (die, DW_AT_specification, targ_die);
6518 gcc_assert (!targ_die->die_definition);
6519 targ_die->die_definition = die;
6522 static inline dw_die_ref
6523 AT_ref (dw_attr_ref a)
6525 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6526 return a->dw_attr_val.v.val_die_ref.die;
6530 AT_ref_external (dw_attr_ref a)
6532 if (a && AT_class (a) == dw_val_class_die_ref)
6533 return a->dw_attr_val.v.val_die_ref.external;
6539 set_AT_ref_external (dw_attr_ref a, int i)
6541 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6542 a->dw_attr_val.v.val_die_ref.external = i;
6545 /* Add an FDE reference attribute value to a DIE. */
6548 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6552 attr.dw_attr = attr_kind;
6553 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6554 attr.dw_attr_val.v.val_fde_index = targ_fde;
6555 add_dwarf_attr (die, &attr);
6558 /* Add a location description attribute value to a DIE. */
6561 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6565 attr.dw_attr = attr_kind;
6566 attr.dw_attr_val.val_class = dw_val_class_loc;
6567 attr.dw_attr_val.v.val_loc = loc;
6568 add_dwarf_attr (die, &attr);
6571 static inline dw_loc_descr_ref
6572 AT_loc (dw_attr_ref a)
6574 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6575 return a->dw_attr_val.v.val_loc;
6579 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6583 attr.dw_attr = attr_kind;
6584 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6585 attr.dw_attr_val.v.val_loc_list = loc_list;
6586 add_dwarf_attr (die, &attr);
6587 have_location_lists = true;
6590 static inline dw_loc_list_ref
6591 AT_loc_list (dw_attr_ref a)
6593 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6594 return a->dw_attr_val.v.val_loc_list;
6597 /* Add an address constant attribute value to a DIE. */
6600 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6604 attr.dw_attr = attr_kind;
6605 attr.dw_attr_val.val_class = dw_val_class_addr;
6606 attr.dw_attr_val.v.val_addr = addr;
6607 add_dwarf_attr (die, &attr);
6610 /* Get the RTX from to an address DIE attribute. */
6613 AT_addr (dw_attr_ref a)
6615 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6616 return a->dw_attr_val.v.val_addr;
6619 /* Add a file attribute value to a DIE. */
6622 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6623 struct dwarf_file_data *fd)
6627 attr.dw_attr = attr_kind;
6628 attr.dw_attr_val.val_class = dw_val_class_file;
6629 attr.dw_attr_val.v.val_file = fd;
6630 add_dwarf_attr (die, &attr);
6633 /* Get the dwarf_file_data from a file DIE attribute. */
6635 static inline struct dwarf_file_data *
6636 AT_file (dw_attr_ref a)
6638 gcc_assert (a && AT_class (a) == dw_val_class_file);
6639 return a->dw_attr_val.v.val_file;
6642 /* Add a label identifier attribute value to a DIE. */
6645 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6649 attr.dw_attr = attr_kind;
6650 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6651 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6652 add_dwarf_attr (die, &attr);
6655 /* Add a section offset attribute value to a DIE, an offset into the
6656 debug_line section. */
6659 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6664 attr.dw_attr = attr_kind;
6665 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6666 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6667 add_dwarf_attr (die, &attr);
6670 /* Add a section offset attribute value to a DIE, an offset into the
6671 debug_macinfo section. */
6674 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6679 attr.dw_attr = attr_kind;
6680 attr.dw_attr_val.val_class = dw_val_class_macptr;
6681 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6682 add_dwarf_attr (die, &attr);
6685 /* Add an offset attribute value to a DIE. */
6688 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6689 unsigned HOST_WIDE_INT offset)
6693 attr.dw_attr = attr_kind;
6694 attr.dw_attr_val.val_class = dw_val_class_offset;
6695 attr.dw_attr_val.v.val_offset = offset;
6696 add_dwarf_attr (die, &attr);
6699 /* Add an range_list attribute value to a DIE. */
6702 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6703 long unsigned int offset)
6707 attr.dw_attr = attr_kind;
6708 attr.dw_attr_val.val_class = dw_val_class_range_list;
6709 attr.dw_attr_val.v.val_offset = offset;
6710 add_dwarf_attr (die, &attr);
6713 static inline const char *
6714 AT_lbl (dw_attr_ref a)
6716 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6717 || AT_class (a) == dw_val_class_lineptr
6718 || AT_class (a) == dw_val_class_macptr));
6719 return a->dw_attr_val.v.val_lbl_id;
6722 /* Get the attribute of type attr_kind. */
6725 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6729 dw_die_ref spec = NULL;
6734 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6735 if (a->dw_attr == attr_kind)
6737 else if (a->dw_attr == DW_AT_specification
6738 || a->dw_attr == DW_AT_abstract_origin)
6742 return get_AT (spec, attr_kind);
6747 /* Return the "low pc" attribute value, typically associated with a subprogram
6748 DIE. Return null if the "low pc" attribute is either not present, or if it
6749 cannot be represented as an assembler label identifier. */
6751 static inline const char *
6752 get_AT_low_pc (dw_die_ref die)
6754 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6756 return a ? AT_lbl (a) : NULL;
6759 /* Return the "high pc" attribute value, typically associated with a subprogram
6760 DIE. Return null if the "high pc" attribute is either not present, or if it
6761 cannot be represented as an assembler label identifier. */
6763 static inline const char *
6764 get_AT_hi_pc (dw_die_ref die)
6766 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6768 return a ? AT_lbl (a) : NULL;
6771 /* Return the value of the string attribute designated by ATTR_KIND, or
6772 NULL if it is not present. */
6774 static inline const char *
6775 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6777 dw_attr_ref a = get_AT (die, attr_kind);
6779 return a ? AT_string (a) : NULL;
6782 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6783 if it is not present. */
6786 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6788 dw_attr_ref a = get_AT (die, attr_kind);
6790 return a ? AT_flag (a) : 0;
6793 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6794 if it is not present. */
6796 static inline unsigned
6797 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6799 dw_attr_ref a = get_AT (die, attr_kind);
6801 return a ? AT_unsigned (a) : 0;
6804 static inline dw_die_ref
6805 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6807 dw_attr_ref a = get_AT (die, attr_kind);
6809 return a ? AT_ref (a) : NULL;
6812 static inline struct dwarf_file_data *
6813 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6815 dw_attr_ref a = get_AT (die, attr_kind);
6817 return a ? AT_file (a) : NULL;
6820 /* Return TRUE if the language is C or C++. */
6825 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6827 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6828 || lang == DW_LANG_C99
6829 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6832 /* Return TRUE if the language is C++. */
6837 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6839 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6842 /* Return TRUE if the language is Fortran. */
6847 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6849 return (lang == DW_LANG_Fortran77
6850 || lang == DW_LANG_Fortran90
6851 || lang == DW_LANG_Fortran95);
6854 /* Return TRUE if the language is Java. */
6859 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6861 return lang == DW_LANG_Java;
6864 /* Return TRUE if the language is Ada. */
6869 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6871 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6874 /* Remove the specified attribute if present. */
6877 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6885 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6886 if (a->dw_attr == attr_kind)
6888 if (AT_class (a) == dw_val_class_str)
6889 if (a->dw_attr_val.v.val_str->refcount)
6890 a->dw_attr_val.v.val_str->refcount--;
6892 /* VEC_ordered_remove should help reduce the number of abbrevs
6894 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6899 /* Remove CHILD from its parent. PREV must have the property that
6900 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6903 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6905 gcc_assert (child->die_parent == prev->die_parent);
6906 gcc_assert (prev->die_sib == child);
6909 gcc_assert (child->die_parent->die_child == child);
6913 prev->die_sib = child->die_sib;
6914 if (child->die_parent->die_child == child)
6915 child->die_parent->die_child = prev;
6918 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6922 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6928 dw_die_ref prev = c;
6930 while (c->die_tag == tag)
6932 remove_child_with_prev (c, prev);
6933 /* Might have removed every child. */
6934 if (c == c->die_sib)
6938 } while (c != die->die_child);
6941 /* Add a CHILD_DIE as the last child of DIE. */
6944 add_child_die (dw_die_ref die, dw_die_ref child_die)
6946 /* FIXME this should probably be an assert. */
6947 if (! die || ! child_die)
6949 gcc_assert (die != child_die);
6951 child_die->die_parent = die;
6954 child_die->die_sib = die->die_child->die_sib;
6955 die->die_child->die_sib = child_die;
6958 child_die->die_sib = child_die;
6959 die->die_child = child_die;
6962 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6963 is the specification, to the end of PARENT's list of children.
6964 This is done by removing and re-adding it. */
6967 splice_child_die (dw_die_ref parent, dw_die_ref child)
6971 /* We want the declaration DIE from inside the class, not the
6972 specification DIE at toplevel. */
6973 if (child->die_parent != parent)
6975 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6981 gcc_assert (child->die_parent == parent
6982 || (child->die_parent
6983 == get_AT_ref (parent, DW_AT_specification)));
6985 for (p = child->die_parent->die_child; ; p = p->die_sib)
6986 if (p->die_sib == child)
6988 remove_child_with_prev (child, p);
6992 add_child_die (parent, child);
6995 /* Return a pointer to a newly created DIE node. */
6997 static inline dw_die_ref
6998 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7000 dw_die_ref die = GGC_CNEW (die_node);
7002 die->die_tag = tag_value;
7004 if (parent_die != NULL)
7005 add_child_die (parent_die, die);
7008 limbo_die_node *limbo_node;
7010 limbo_node = GGC_CNEW (limbo_die_node);
7011 limbo_node->die = die;
7012 limbo_node->created_for = t;
7013 limbo_node->next = limbo_die_list;
7014 limbo_die_list = limbo_node;
7020 /* Return the DIE associated with the given type specifier. */
7022 static inline dw_die_ref
7023 lookup_type_die (tree type)
7025 return TYPE_SYMTAB_DIE (type);
7028 /* Equate a DIE to a given type specifier. */
7031 equate_type_number_to_die (tree type, dw_die_ref type_die)
7033 TYPE_SYMTAB_DIE (type) = type_die;
7036 /* Returns a hash value for X (which really is a die_struct). */
7039 decl_die_table_hash (const void *x)
7041 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7044 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7047 decl_die_table_eq (const void *x, const void *y)
7049 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7052 /* Return the DIE associated with a given declaration. */
7054 static inline dw_die_ref
7055 lookup_decl_die (tree decl)
7057 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7060 /* Returns a hash value for X (which really is a var_loc_list). */
7063 decl_loc_table_hash (const void *x)
7065 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7068 /* Return nonzero if decl_id of var_loc_list X is the same as
7072 decl_loc_table_eq (const void *x, const void *y)
7074 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7077 /* Return the var_loc list associated with a given declaration. */
7079 static inline var_loc_list *
7080 lookup_decl_loc (const_tree decl)
7082 return (var_loc_list *)
7083 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7086 /* Equate a DIE to a particular declaration. */
7089 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7091 unsigned int decl_id = DECL_UID (decl);
7094 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7096 decl_die->decl_id = decl_id;
7099 /* Add a variable location node to the linked list for DECL. */
7102 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7104 unsigned int decl_id = DECL_UID (decl);
7108 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7111 temp = GGC_CNEW (var_loc_list);
7112 temp->decl_id = decl_id;
7116 temp = (var_loc_list *) *slot;
7120 /* If the current location is the same as the end of the list,
7121 and either both or neither of the locations is uninitialized,
7122 we have nothing to do. */
7123 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7124 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7125 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7126 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7127 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7128 == VAR_INIT_STATUS_UNINITIALIZED)
7129 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7130 == VAR_INIT_STATUS_UNINITIALIZED))))
7132 /* Add LOC to the end of list and update LAST. */
7133 temp->last->next = loc;
7137 /* Do not add empty location to the beginning of the list. */
7138 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7145 /* Keep track of the number of spaces used to indent the
7146 output of the debugging routines that print the structure of
7147 the DIE internal representation. */
7148 static int print_indent;
7150 /* Indent the line the number of spaces given by print_indent. */
7153 print_spaces (FILE *outfile)
7155 fprintf (outfile, "%*s", print_indent, "");
7158 /* Print the information associated with a given DIE, and its children.
7159 This routine is a debugging aid only. */
7162 print_die (dw_die_ref die, FILE *outfile)
7168 print_spaces (outfile);
7169 fprintf (outfile, "DIE %4ld: %s\n",
7170 die->die_offset, dwarf_tag_name (die->die_tag));
7171 print_spaces (outfile);
7172 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7173 fprintf (outfile, " offset: %ld\n", die->die_offset);
7175 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7177 print_spaces (outfile);
7178 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7180 switch (AT_class (a))
7182 case dw_val_class_addr:
7183 fprintf (outfile, "address");
7185 case dw_val_class_offset:
7186 fprintf (outfile, "offset");
7188 case dw_val_class_loc:
7189 fprintf (outfile, "location descriptor");
7191 case dw_val_class_loc_list:
7192 fprintf (outfile, "location list -> label:%s",
7193 AT_loc_list (a)->ll_symbol);
7195 case dw_val_class_range_list:
7196 fprintf (outfile, "range list");
7198 case dw_val_class_const:
7199 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7201 case dw_val_class_unsigned_const:
7202 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7204 case dw_val_class_long_long:
7205 fprintf (outfile, "constant (%lu,%lu)",
7206 a->dw_attr_val.v.val_long_long.hi,
7207 a->dw_attr_val.v.val_long_long.low);
7209 case dw_val_class_vec:
7210 fprintf (outfile, "floating-point or vector constant");
7212 case dw_val_class_flag:
7213 fprintf (outfile, "%u", AT_flag (a));
7215 case dw_val_class_die_ref:
7216 if (AT_ref (a) != NULL)
7218 if (AT_ref (a)->die_symbol)
7219 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7221 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7224 fprintf (outfile, "die -> <null>");
7226 case dw_val_class_lbl_id:
7227 case dw_val_class_lineptr:
7228 case dw_val_class_macptr:
7229 fprintf (outfile, "label: %s", AT_lbl (a));
7231 case dw_val_class_str:
7232 if (AT_string (a) != NULL)
7233 fprintf (outfile, "\"%s\"", AT_string (a));
7235 fprintf (outfile, "<null>");
7237 case dw_val_class_file:
7238 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7239 AT_file (a)->emitted_number);
7245 fprintf (outfile, "\n");
7248 if (die->die_child != NULL)
7251 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7254 if (print_indent == 0)
7255 fprintf (outfile, "\n");
7258 /* Print the contents of the source code line number correspondence table.
7259 This routine is a debugging aid only. */
7262 print_dwarf_line_table (FILE *outfile)
7265 dw_line_info_ref line_info;
7267 fprintf (outfile, "\n\nDWARF source line information\n");
7268 for (i = 1; i < line_info_table_in_use; i++)
7270 line_info = &line_info_table[i];
7271 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7272 line_info->dw_file_num,
7273 line_info->dw_line_num);
7276 fprintf (outfile, "\n\n");
7279 /* Print the information collected for a given DIE. */
7282 debug_dwarf_die (dw_die_ref die)
7284 print_die (die, stderr);
7287 /* Print all DWARF information collected for the compilation unit.
7288 This routine is a debugging aid only. */
7294 print_die (comp_unit_die, stderr);
7295 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7296 print_dwarf_line_table (stderr);
7299 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7300 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7301 DIE that marks the start of the DIEs for this include file. */
7304 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7306 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7307 dw_die_ref new_unit = gen_compile_unit_die (filename);
7309 new_unit->die_sib = old_unit;
7313 /* Close an include-file CU and reopen the enclosing one. */
7316 pop_compile_unit (dw_die_ref old_unit)
7318 dw_die_ref new_unit = old_unit->die_sib;
7320 old_unit->die_sib = NULL;
7324 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7325 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7327 /* Calculate the checksum of a location expression. */
7330 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7334 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7336 CHECKSUM (loc->dw_loc_oprnd1);
7337 CHECKSUM (loc->dw_loc_oprnd2);
7340 /* Calculate the checksum of an attribute. */
7343 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7345 dw_loc_descr_ref loc;
7348 CHECKSUM (at->dw_attr);
7350 /* We don't care that this was compiled with a different compiler
7351 snapshot; if the output is the same, that's what matters. */
7352 if (at->dw_attr == DW_AT_producer)
7355 switch (AT_class (at))
7357 case dw_val_class_const:
7358 CHECKSUM (at->dw_attr_val.v.val_int);
7360 case dw_val_class_unsigned_const:
7361 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7363 case dw_val_class_long_long:
7364 CHECKSUM (at->dw_attr_val.v.val_long_long);
7366 case dw_val_class_vec:
7367 CHECKSUM (at->dw_attr_val.v.val_vec);
7369 case dw_val_class_flag:
7370 CHECKSUM (at->dw_attr_val.v.val_flag);
7372 case dw_val_class_str:
7373 CHECKSUM_STRING (AT_string (at));
7376 case dw_val_class_addr:
7378 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7379 CHECKSUM_STRING (XSTR (r, 0));
7382 case dw_val_class_offset:
7383 CHECKSUM (at->dw_attr_val.v.val_offset);
7386 case dw_val_class_loc:
7387 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7388 loc_checksum (loc, ctx);
7391 case dw_val_class_die_ref:
7392 die_checksum (AT_ref (at), ctx, mark);
7395 case dw_val_class_fde_ref:
7396 case dw_val_class_lbl_id:
7397 case dw_val_class_lineptr:
7398 case dw_val_class_macptr:
7401 case dw_val_class_file:
7402 CHECKSUM_STRING (AT_file (at)->filename);
7410 /* Calculate the checksum of a DIE. */
7413 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7419 /* To avoid infinite recursion. */
7422 CHECKSUM (die->die_mark);
7425 die->die_mark = ++(*mark);
7427 CHECKSUM (die->die_tag);
7429 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7430 attr_checksum (a, ctx, mark);
7432 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7436 #undef CHECKSUM_STRING
7438 /* Do the location expressions look same? */
7440 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7442 return loc1->dw_loc_opc == loc2->dw_loc_opc
7443 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7444 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7447 /* Do the values look the same? */
7449 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7451 dw_loc_descr_ref loc1, loc2;
7454 if (v1->val_class != v2->val_class)
7457 switch (v1->val_class)
7459 case dw_val_class_const:
7460 return v1->v.val_int == v2->v.val_int;
7461 case dw_val_class_unsigned_const:
7462 return v1->v.val_unsigned == v2->v.val_unsigned;
7463 case dw_val_class_long_long:
7464 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
7465 && v1->v.val_long_long.low == v2->v.val_long_long.low;
7466 case dw_val_class_vec:
7467 if (v1->v.val_vec.length != v2->v.val_vec.length
7468 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7470 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7471 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7474 case dw_val_class_flag:
7475 return v1->v.val_flag == v2->v.val_flag;
7476 case dw_val_class_str:
7477 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7479 case dw_val_class_addr:
7480 r1 = v1->v.val_addr;
7481 r2 = v2->v.val_addr;
7482 if (GET_CODE (r1) != GET_CODE (r2))
7484 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7485 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7487 case dw_val_class_offset:
7488 return v1->v.val_offset == v2->v.val_offset;
7490 case dw_val_class_loc:
7491 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7493 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7494 if (!same_loc_p (loc1, loc2, mark))
7496 return !loc1 && !loc2;
7498 case dw_val_class_die_ref:
7499 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7501 case dw_val_class_fde_ref:
7502 case dw_val_class_lbl_id:
7503 case dw_val_class_lineptr:
7504 case dw_val_class_macptr:
7507 case dw_val_class_file:
7508 return v1->v.val_file == v2->v.val_file;
7515 /* Do the attributes look the same? */
7518 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7520 if (at1->dw_attr != at2->dw_attr)
7523 /* We don't care that this was compiled with a different compiler
7524 snapshot; if the output is the same, that's what matters. */
7525 if (at1->dw_attr == DW_AT_producer)
7528 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7531 /* Do the dies look the same? */
7534 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7540 /* To avoid infinite recursion. */
7542 return die1->die_mark == die2->die_mark;
7543 die1->die_mark = die2->die_mark = ++(*mark);
7545 if (die1->die_tag != die2->die_tag)
7548 if (VEC_length (dw_attr_node, die1->die_attr)
7549 != VEC_length (dw_attr_node, die2->die_attr))
7552 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7553 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7556 c1 = die1->die_child;
7557 c2 = die2->die_child;
7566 if (!same_die_p (c1, c2, mark))
7570 if (c1 == die1->die_child)
7572 if (c2 == die2->die_child)
7582 /* Do the dies look the same? Wrapper around same_die_p. */
7585 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7588 int ret = same_die_p (die1, die2, &mark);
7590 unmark_all_dies (die1);
7591 unmark_all_dies (die2);
7596 /* The prefix to attach to symbols on DIEs in the current comdat debug
7598 static char *comdat_symbol_id;
7600 /* The index of the current symbol within the current comdat CU. */
7601 static unsigned int comdat_symbol_number;
7603 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7604 children, and set comdat_symbol_id accordingly. */
7607 compute_section_prefix (dw_die_ref unit_die)
7609 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7610 const char *base = die_name ? lbasename (die_name) : "anonymous";
7611 char *name = XALLOCAVEC (char, strlen (base) + 64);
7614 unsigned char checksum[16];
7617 /* Compute the checksum of the DIE, then append part of it as hex digits to
7618 the name filename of the unit. */
7620 md5_init_ctx (&ctx);
7622 die_checksum (unit_die, &ctx, &mark);
7623 unmark_all_dies (unit_die);
7624 md5_finish_ctx (&ctx, checksum);
7626 sprintf (name, "%s.", base);
7627 clean_symbol_name (name);
7629 p = name + strlen (name);
7630 for (i = 0; i < 4; i++)
7632 sprintf (p, "%.2x", checksum[i]);
7636 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7637 comdat_symbol_number = 0;
7640 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7643 is_type_die (dw_die_ref die)
7645 switch (die->die_tag)
7647 case DW_TAG_array_type:
7648 case DW_TAG_class_type:
7649 case DW_TAG_interface_type:
7650 case DW_TAG_enumeration_type:
7651 case DW_TAG_pointer_type:
7652 case DW_TAG_reference_type:
7653 case DW_TAG_string_type:
7654 case DW_TAG_structure_type:
7655 case DW_TAG_subroutine_type:
7656 case DW_TAG_union_type:
7657 case DW_TAG_ptr_to_member_type:
7658 case DW_TAG_set_type:
7659 case DW_TAG_subrange_type:
7660 case DW_TAG_base_type:
7661 case DW_TAG_const_type:
7662 case DW_TAG_file_type:
7663 case DW_TAG_packed_type:
7664 case DW_TAG_volatile_type:
7665 case DW_TAG_typedef:
7672 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7673 Basically, we want to choose the bits that are likely to be shared between
7674 compilations (types) and leave out the bits that are specific to individual
7675 compilations (functions). */
7678 is_comdat_die (dw_die_ref c)
7680 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7681 we do for stabs. The advantage is a greater likelihood of sharing between
7682 objects that don't include headers in the same order (and therefore would
7683 put the base types in a different comdat). jason 8/28/00 */
7685 if (c->die_tag == DW_TAG_base_type)
7688 if (c->die_tag == DW_TAG_pointer_type
7689 || c->die_tag == DW_TAG_reference_type
7690 || c->die_tag == DW_TAG_const_type
7691 || c->die_tag == DW_TAG_volatile_type)
7693 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7695 return t ? is_comdat_die (t) : 0;
7698 return is_type_die (c);
7701 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7702 compilation unit. */
7705 is_symbol_die (dw_die_ref c)
7707 return (is_type_die (c)
7708 || (get_AT (c, DW_AT_declaration)
7709 && !get_AT (c, DW_AT_specification))
7710 || c->die_tag == DW_TAG_namespace
7711 || c->die_tag == DW_TAG_module);
7715 gen_internal_sym (const char *prefix)
7719 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7720 return xstrdup (buf);
7723 /* Assign symbols to all worthy DIEs under DIE. */
7726 assign_symbol_names (dw_die_ref die)
7730 if (is_symbol_die (die))
7732 if (comdat_symbol_id)
7734 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7736 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7737 comdat_symbol_id, comdat_symbol_number++);
7738 die->die_symbol = xstrdup (p);
7741 die->die_symbol = gen_internal_sym ("LDIE");
7744 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7747 struct cu_hash_table_entry
7750 unsigned min_comdat_num, max_comdat_num;
7751 struct cu_hash_table_entry *next;
7754 /* Routines to manipulate hash table of CUs. */
7756 htab_cu_hash (const void *of)
7758 const struct cu_hash_table_entry *const entry =
7759 (const struct cu_hash_table_entry *) of;
7761 return htab_hash_string (entry->cu->die_symbol);
7765 htab_cu_eq (const void *of1, const void *of2)
7767 const struct cu_hash_table_entry *const entry1 =
7768 (const struct cu_hash_table_entry *) of1;
7769 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7771 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7775 htab_cu_del (void *what)
7777 struct cu_hash_table_entry *next,
7778 *entry = (struct cu_hash_table_entry *) what;
7788 /* Check whether we have already seen this CU and set up SYM_NUM
7791 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7793 struct cu_hash_table_entry dummy;
7794 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7796 dummy.max_comdat_num = 0;
7798 slot = (struct cu_hash_table_entry **)
7799 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7803 for (; entry; last = entry, entry = entry->next)
7805 if (same_die_p_wrap (cu, entry->cu))
7811 *sym_num = entry->min_comdat_num;
7815 entry = XCNEW (struct cu_hash_table_entry);
7817 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7818 entry->next = *slot;
7824 /* Record SYM_NUM to record of CU in HTABLE. */
7826 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7828 struct cu_hash_table_entry **slot, *entry;
7830 slot = (struct cu_hash_table_entry **)
7831 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7835 entry->max_comdat_num = sym_num;
7838 /* Traverse the DIE (which is always comp_unit_die), and set up
7839 additional compilation units for each of the include files we see
7840 bracketed by BINCL/EINCL. */
7843 break_out_includes (dw_die_ref die)
7846 dw_die_ref unit = NULL;
7847 limbo_die_node *node, **pnode;
7848 htab_t cu_hash_table;
7852 dw_die_ref prev = c;
7854 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7855 || (unit && is_comdat_die (c)))
7857 dw_die_ref next = c->die_sib;
7859 /* This DIE is for a secondary CU; remove it from the main one. */
7860 remove_child_with_prev (c, prev);
7862 if (c->die_tag == DW_TAG_GNU_BINCL)
7863 unit = push_new_compile_unit (unit, c);
7864 else if (c->die_tag == DW_TAG_GNU_EINCL)
7865 unit = pop_compile_unit (unit);
7867 add_child_die (unit, c);
7869 if (c == die->die_child)
7872 } while (c != die->die_child);
7875 /* We can only use this in debugging, since the frontend doesn't check
7876 to make sure that we leave every include file we enter. */
7880 assign_symbol_names (die);
7881 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7882 for (node = limbo_die_list, pnode = &limbo_die_list;
7888 compute_section_prefix (node->die);
7889 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7890 &comdat_symbol_number);
7891 assign_symbol_names (node->die);
7893 *pnode = node->next;
7896 pnode = &node->next;
7897 record_comdat_symbol_number (node->die, cu_hash_table,
7898 comdat_symbol_number);
7901 htab_delete (cu_hash_table);
7904 /* Traverse the DIE and add a sibling attribute if it may have the
7905 effect of speeding up access to siblings. To save some space,
7906 avoid generating sibling attributes for DIE's without children. */
7909 add_sibling_attributes (dw_die_ref die)
7913 if (! die->die_child)
7916 if (die->die_parent && die != die->die_parent->die_child)
7917 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7919 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7922 /* Output all location lists for the DIE and its children. */
7925 output_location_lists (dw_die_ref die)
7931 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7932 if (AT_class (a) == dw_val_class_loc_list)
7933 output_loc_list (AT_loc_list (a));
7935 FOR_EACH_CHILD (die, c, output_location_lists (c));
7938 /* The format of each DIE (and its attribute value pairs) is encoded in an
7939 abbreviation table. This routine builds the abbreviation table and assigns
7940 a unique abbreviation id for each abbreviation entry. The children of each
7941 die are visited recursively. */
7944 build_abbrev_table (dw_die_ref die)
7946 unsigned long abbrev_id;
7947 unsigned int n_alloc;
7952 /* Scan the DIE references, and mark as external any that refer to
7953 DIEs from other CUs (i.e. those which are not marked). */
7954 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7955 if (AT_class (a) == dw_val_class_die_ref
7956 && AT_ref (a)->die_mark == 0)
7958 gcc_assert (AT_ref (a)->die_symbol);
7959 set_AT_ref_external (a, 1);
7962 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7964 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7965 dw_attr_ref die_a, abbrev_a;
7969 if (abbrev->die_tag != die->die_tag)
7971 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7974 if (VEC_length (dw_attr_node, abbrev->die_attr)
7975 != VEC_length (dw_attr_node, die->die_attr))
7978 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7980 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7981 if ((abbrev_a->dw_attr != die_a->dw_attr)
7982 || (value_format (abbrev_a) != value_format (die_a)))
7992 if (abbrev_id >= abbrev_die_table_in_use)
7994 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7996 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7997 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8000 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8001 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8002 abbrev_die_table_allocated = n_alloc;
8005 ++abbrev_die_table_in_use;
8006 abbrev_die_table[abbrev_id] = die;
8009 die->die_abbrev = abbrev_id;
8010 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8013 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8016 constant_size (unsigned HOST_WIDE_INT value)
8023 log = floor_log2 (value);
8026 log = 1 << (floor_log2 (log) + 1);
8031 /* Return the size of a DIE as it is represented in the
8032 .debug_info section. */
8034 static unsigned long
8035 size_of_die (dw_die_ref die)
8037 unsigned long size = 0;
8041 size += size_of_uleb128 (die->die_abbrev);
8042 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8044 switch (AT_class (a))
8046 case dw_val_class_addr:
8047 size += DWARF2_ADDR_SIZE;
8049 case dw_val_class_offset:
8050 size += DWARF_OFFSET_SIZE;
8052 case dw_val_class_loc:
8054 unsigned long lsize = size_of_locs (AT_loc (a));
8057 size += constant_size (lsize);
8061 case dw_val_class_loc_list:
8062 size += DWARF_OFFSET_SIZE;
8064 case dw_val_class_range_list:
8065 size += DWARF_OFFSET_SIZE;
8067 case dw_val_class_const:
8068 size += size_of_sleb128 (AT_int (a));
8070 case dw_val_class_unsigned_const:
8071 size += constant_size (AT_unsigned (a));
8073 case dw_val_class_long_long:
8074 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
8076 case dw_val_class_vec:
8077 size += constant_size (a->dw_attr_val.v.val_vec.length
8078 * a->dw_attr_val.v.val_vec.elt_size)
8079 + a->dw_attr_val.v.val_vec.length
8080 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8082 case dw_val_class_flag:
8085 case dw_val_class_die_ref:
8086 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8087 whereas in DWARF3 it's always sized as an offset. */
8088 if (AT_ref_external (a) && dwarf_version == 2)
8089 size += DWARF2_ADDR_SIZE;
8091 size += DWARF_OFFSET_SIZE;
8093 case dw_val_class_fde_ref:
8094 size += DWARF_OFFSET_SIZE;
8096 case dw_val_class_lbl_id:
8097 size += DWARF2_ADDR_SIZE;
8099 case dw_val_class_lineptr:
8100 case dw_val_class_macptr:
8101 size += DWARF_OFFSET_SIZE;
8103 case dw_val_class_str:
8104 if (AT_string_form (a) == DW_FORM_strp)
8105 size += DWARF_OFFSET_SIZE;
8107 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8109 case dw_val_class_file:
8110 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8120 /* Size the debugging information associated with a given DIE. Visits the
8121 DIE's children recursively. Updates the global variable next_die_offset, on
8122 each time through. Uses the current value of next_die_offset to update the
8123 die_offset field in each DIE. */
8126 calc_die_sizes (dw_die_ref die)
8130 die->die_offset = next_die_offset;
8131 next_die_offset += size_of_die (die);
8133 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8135 if (die->die_child != NULL)
8136 /* Count the null byte used to terminate sibling lists. */
8137 next_die_offset += 1;
8140 /* Set the marks for a die and its children. We do this so
8141 that we know whether or not a reference needs to use FORM_ref_addr; only
8142 DIEs in the same CU will be marked. We used to clear out the offset
8143 and use that as the flag, but ran into ordering problems. */
8146 mark_dies (dw_die_ref die)
8150 gcc_assert (!die->die_mark);
8153 FOR_EACH_CHILD (die, c, mark_dies (c));
8156 /* Clear the marks for a die and its children. */
8159 unmark_dies (dw_die_ref die)
8163 gcc_assert (die->die_mark);
8166 FOR_EACH_CHILD (die, c, unmark_dies (c));
8169 /* Clear the marks for a die, its children and referred dies. */
8172 unmark_all_dies (dw_die_ref die)
8182 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8184 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8185 if (AT_class (a) == dw_val_class_die_ref)
8186 unmark_all_dies (AT_ref (a));
8189 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8190 generated for the compilation unit. */
8192 static unsigned long
8193 size_of_pubnames (VEC (pubname_entry, gc) * names)
8199 size = DWARF_PUBNAMES_HEADER_SIZE;
8200 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8201 if (names != pubtype_table
8202 || p->die->die_offset != 0
8203 || !flag_eliminate_unused_debug_types)
8204 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8206 size += DWARF_OFFSET_SIZE;
8210 /* Return the size of the information in the .debug_aranges section. */
8212 static unsigned long
8213 size_of_aranges (void)
8217 size = DWARF_ARANGES_HEADER_SIZE;
8219 /* Count the address/length pair for this compilation unit. */
8220 if (text_section_used)
8221 size += 2 * DWARF2_ADDR_SIZE;
8222 if (cold_text_section_used)
8223 size += 2 * DWARF2_ADDR_SIZE;
8224 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8226 /* Count the two zero words used to terminated the address range table. */
8227 size += 2 * DWARF2_ADDR_SIZE;
8231 /* Select the encoding of an attribute value. */
8233 static enum dwarf_form
8234 value_format (dw_attr_ref a)
8236 switch (a->dw_attr_val.val_class)
8238 case dw_val_class_addr:
8239 return DW_FORM_addr;
8240 case dw_val_class_range_list:
8241 case dw_val_class_offset:
8242 case dw_val_class_loc_list:
8243 switch (DWARF_OFFSET_SIZE)
8246 return DW_FORM_data4;
8248 return DW_FORM_data8;
8252 case dw_val_class_loc:
8253 switch (constant_size (size_of_locs (AT_loc (a))))
8256 return DW_FORM_block1;
8258 return DW_FORM_block2;
8262 case dw_val_class_const:
8263 return DW_FORM_sdata;
8264 case dw_val_class_unsigned_const:
8265 switch (constant_size (AT_unsigned (a)))
8268 return DW_FORM_data1;
8270 return DW_FORM_data2;
8272 return DW_FORM_data4;
8274 return DW_FORM_data8;
8278 case dw_val_class_long_long:
8279 return DW_FORM_block1;
8280 case dw_val_class_vec:
8281 switch (constant_size (a->dw_attr_val.v.val_vec.length
8282 * a->dw_attr_val.v.val_vec.elt_size))
8285 return DW_FORM_block1;
8287 return DW_FORM_block2;
8289 return DW_FORM_block4;
8293 case dw_val_class_flag:
8294 return DW_FORM_flag;
8295 case dw_val_class_die_ref:
8296 if (AT_ref_external (a))
8297 return DW_FORM_ref_addr;
8300 case dw_val_class_fde_ref:
8301 return DW_FORM_data;
8302 case dw_val_class_lbl_id:
8303 return DW_FORM_addr;
8304 case dw_val_class_lineptr:
8305 case dw_val_class_macptr:
8306 return DW_FORM_data;
8307 case dw_val_class_str:
8308 return AT_string_form (a);
8309 case dw_val_class_file:
8310 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8313 return DW_FORM_data1;
8315 return DW_FORM_data2;
8317 return DW_FORM_data4;
8327 /* Output the encoding of an attribute value. */
8330 output_value_format (dw_attr_ref a)
8332 enum dwarf_form form = value_format (a);
8334 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8337 /* Output the .debug_abbrev section which defines the DIE abbreviation
8341 output_abbrev_section (void)
8343 unsigned long abbrev_id;
8345 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8347 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8351 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8352 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8353 dwarf_tag_name (abbrev->die_tag));
8355 if (abbrev->die_child != NULL)
8356 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8358 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8360 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8363 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8364 dwarf_attr_name (a_attr->dw_attr));
8365 output_value_format (a_attr);
8368 dw2_asm_output_data (1, 0, NULL);
8369 dw2_asm_output_data (1, 0, NULL);
8372 /* Terminate the table. */
8373 dw2_asm_output_data (1, 0, NULL);
8376 /* Output a symbol we can use to refer to this DIE from another CU. */
8379 output_die_symbol (dw_die_ref die)
8381 char *sym = die->die_symbol;
8386 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8387 /* We make these global, not weak; if the target doesn't support
8388 .linkonce, it doesn't support combining the sections, so debugging
8390 targetm.asm_out.globalize_label (asm_out_file, sym);
8392 ASM_OUTPUT_LABEL (asm_out_file, sym);
8395 /* Return a new location list, given the begin and end range, and the
8396 expression. gensym tells us whether to generate a new internal symbol for
8397 this location list node, which is done for the head of the list only. */
8399 static inline dw_loc_list_ref
8400 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8401 const char *section, unsigned int gensym)
8403 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8405 retlist->begin = begin;
8407 retlist->expr = expr;
8408 retlist->section = section;
8410 retlist->ll_symbol = gen_internal_sym ("LLST");
8415 /* Add a location description expression to a location list. */
8418 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8419 const char *begin, const char *end,
8420 const char *section)
8424 /* Find the end of the chain. */
8425 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8428 /* Add a new location list node to the list. */
8429 *d = new_loc_list (descr, begin, end, section, 0);
8432 /* Output the location list given to us. */
8435 output_loc_list (dw_loc_list_ref list_head)
8437 dw_loc_list_ref curr = list_head;
8439 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8441 /* Walk the location list, and output each range + expression. */
8442 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8445 /* Don't output an entry that starts and ends at the same address. */
8446 if (strcmp (curr->begin, curr->end) == 0)
8448 if (!have_multiple_function_sections)
8450 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8451 "Location list begin address (%s)",
8452 list_head->ll_symbol);
8453 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8454 "Location list end address (%s)",
8455 list_head->ll_symbol);
8459 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8460 "Location list begin address (%s)",
8461 list_head->ll_symbol);
8462 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8463 "Location list end address (%s)",
8464 list_head->ll_symbol);
8466 size = size_of_locs (curr->expr);
8468 /* Output the block length for this list of location operations. */
8469 gcc_assert (size <= 0xffff);
8470 dw2_asm_output_data (2, size, "%s", "Location expression size");
8472 output_loc_sequence (curr->expr);
8475 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8476 "Location list terminator begin (%s)",
8477 list_head->ll_symbol);
8478 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8479 "Location list terminator end (%s)",
8480 list_head->ll_symbol);
8483 /* Output the DIE and its attributes. Called recursively to generate
8484 the definitions of each child DIE. */
8487 output_die (dw_die_ref die)
8494 /* If someone in another CU might refer to us, set up a symbol for
8495 them to point to. */
8496 if (die->die_symbol)
8497 output_die_symbol (die);
8499 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8500 (unsigned long)die->die_offset,
8501 dwarf_tag_name (die->die_tag));
8503 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8505 const char *name = dwarf_attr_name (a->dw_attr);
8507 switch (AT_class (a))
8509 case dw_val_class_addr:
8510 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8513 case dw_val_class_offset:
8514 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8518 case dw_val_class_range_list:
8520 char *p = strchr (ranges_section_label, '\0');
8522 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8523 a->dw_attr_val.v.val_offset);
8524 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8525 debug_ranges_section, "%s", name);
8530 case dw_val_class_loc:
8531 size = size_of_locs (AT_loc (a));
8533 /* Output the block length for this list of location operations. */
8534 dw2_asm_output_data (constant_size (size), size, "%s", name);
8536 output_loc_sequence (AT_loc (a));
8539 case dw_val_class_const:
8540 /* ??? It would be slightly more efficient to use a scheme like is
8541 used for unsigned constants below, but gdb 4.x does not sign
8542 extend. Gdb 5.x does sign extend. */
8543 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8546 case dw_val_class_unsigned_const:
8547 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8548 AT_unsigned (a), "%s", name);
8551 case dw_val_class_long_long:
8553 unsigned HOST_WIDE_INT first, second;
8555 dw2_asm_output_data (1,
8556 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8559 if (WORDS_BIG_ENDIAN)
8561 first = a->dw_attr_val.v.val_long_long.hi;
8562 second = a->dw_attr_val.v.val_long_long.low;
8566 first = a->dw_attr_val.v.val_long_long.low;
8567 second = a->dw_attr_val.v.val_long_long.hi;
8570 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8571 first, "long long constant");
8572 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8577 case dw_val_class_vec:
8579 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8580 unsigned int len = a->dw_attr_val.v.val_vec.length;
8584 dw2_asm_output_data (constant_size (len * elt_size),
8585 len * elt_size, "%s", name);
8586 if (elt_size > sizeof (HOST_WIDE_INT))
8591 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8594 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8595 "fp or vector constant word %u", i);
8599 case dw_val_class_flag:
8600 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8603 case dw_val_class_loc_list:
8605 char *sym = AT_loc_list (a)->ll_symbol;
8608 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8613 case dw_val_class_die_ref:
8614 if (AT_ref_external (a))
8616 char *sym = AT_ref (a)->die_symbol;
8621 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8622 length, whereas in DWARF3 it's always sized as an offset. */
8623 if (dwarf_version == 2)
8624 size = DWARF2_ADDR_SIZE;
8626 size = DWARF_OFFSET_SIZE;
8627 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
8631 gcc_assert (AT_ref (a)->die_offset);
8632 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8637 case dw_val_class_fde_ref:
8641 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8642 a->dw_attr_val.v.val_fde_index * 2);
8643 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8648 case dw_val_class_lbl_id:
8649 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8652 case dw_val_class_lineptr:
8653 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8654 debug_line_section, "%s", name);
8657 case dw_val_class_macptr:
8658 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8659 debug_macinfo_section, "%s", name);
8662 case dw_val_class_str:
8663 if (AT_string_form (a) == DW_FORM_strp)
8664 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8665 a->dw_attr_val.v.val_str->label,
8667 "%s: \"%s\"", name, AT_string (a));
8669 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8672 case dw_val_class_file:
8674 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8676 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8677 a->dw_attr_val.v.val_file->filename);
8686 FOR_EACH_CHILD (die, c, output_die (c));
8688 /* Add null byte to terminate sibling list. */
8689 if (die->die_child != NULL)
8690 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8691 (unsigned long) die->die_offset);
8694 /* Output the compilation unit that appears at the beginning of the
8695 .debug_info section, and precedes the DIE descriptions. */
8698 output_compilation_unit_header (void)
8700 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8701 dw2_asm_output_data (4, 0xffffffff,
8702 "Initial length escape value indicating 64-bit DWARF extension");
8703 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8704 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8705 "Length of Compilation Unit Info");
8706 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
8707 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8708 debug_abbrev_section,
8709 "Offset Into Abbrev. Section");
8710 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8713 /* Output the compilation unit DIE and its children. */
8716 output_comp_unit (dw_die_ref die, int output_if_empty)
8718 const char *secname;
8721 /* Unless we are outputting main CU, we may throw away empty ones. */
8722 if (!output_if_empty && die->die_child == NULL)
8725 /* Even if there are no children of this DIE, we must output the information
8726 about the compilation unit. Otherwise, on an empty translation unit, we
8727 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8728 will then complain when examining the file. First mark all the DIEs in
8729 this CU so we know which get local refs. */
8732 build_abbrev_table (die);
8734 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8735 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8736 calc_die_sizes (die);
8738 oldsym = die->die_symbol;
8741 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8743 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8745 die->die_symbol = NULL;
8746 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8749 switch_to_section (debug_info_section);
8751 /* Output debugging information. */
8752 output_compilation_unit_header ();
8755 /* Leave the marks on the main CU, so we can check them in
8760 die->die_symbol = oldsym;
8764 /* Return the DWARF2/3 pubname associated with a decl. */
8767 dwarf2_name (tree decl, int scope)
8769 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8772 /* Add a new entry to .debug_pubnames if appropriate. */
8775 add_pubname_string (const char *str, dw_die_ref die)
8780 e.name = xstrdup (str);
8781 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8785 add_pubname (tree decl, dw_die_ref die)
8787 if (TREE_PUBLIC (decl))
8788 add_pubname_string (dwarf2_name (decl, 1), die);
8791 /* Add a new entry to .debug_pubtypes if appropriate. */
8794 add_pubtype (tree decl, dw_die_ref die)
8799 if ((TREE_PUBLIC (decl)
8800 || die->die_parent == comp_unit_die)
8801 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8806 if (TYPE_NAME (decl))
8808 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8809 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8810 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8811 && DECL_NAME (TYPE_NAME (decl)))
8812 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8814 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8818 e.name = xstrdup (dwarf2_name (decl, 1));
8820 /* If we don't have a name for the type, there's no point in adding
8822 if (e.name && e.name[0] != '\0')
8823 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8827 /* Output the public names table used to speed up access to externally
8828 visible names; or the public types table used to find type definitions. */
8831 output_pubnames (VEC (pubname_entry, gc) * names)
8834 unsigned long pubnames_length = size_of_pubnames (names);
8837 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8838 dw2_asm_output_data (4, 0xffffffff,
8839 "Initial length escape value indicating 64-bit DWARF extension");
8840 if (names == pubname_table)
8841 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8842 "Length of Public Names Info");
8844 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8845 "Length of Public Type Names Info");
8846 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8847 dw2_asm_output_data (2, 2, "DWARF Version");
8848 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8850 "Offset of Compilation Unit Info");
8851 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8852 "Compilation Unit Length");
8854 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8856 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8857 if (names == pubname_table)
8858 gcc_assert (pub->die->die_mark);
8860 if (names != pubtype_table
8861 || pub->die->die_offset != 0
8862 || !flag_eliminate_unused_debug_types)
8864 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8867 dw2_asm_output_nstring (pub->name, -1, "external name");
8871 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8874 /* Add a new entry to .debug_aranges if appropriate. */
8877 add_arange (tree decl, dw_die_ref die)
8879 if (! DECL_SECTION_NAME (decl))
8882 if (arange_table_in_use == arange_table_allocated)
8884 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8885 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8886 arange_table_allocated);
8887 memset (arange_table + arange_table_in_use, 0,
8888 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8891 arange_table[arange_table_in_use++] = die;
8894 /* Output the information that goes into the .debug_aranges table.
8895 Namely, define the beginning and ending address range of the
8896 text section generated for this compilation unit. */
8899 output_aranges (void)
8902 unsigned long aranges_length = size_of_aranges ();
8904 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8905 dw2_asm_output_data (4, 0xffffffff,
8906 "Initial length escape value indicating 64-bit DWARF extension");
8907 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8908 "Length of Address Ranges Info");
8909 /* Version number for aranges is still 2, even in DWARF3. */
8910 dw2_asm_output_data (2, 2, "DWARF Version");
8911 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8913 "Offset of Compilation Unit Info");
8914 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8915 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8917 /* We need to align to twice the pointer size here. */
8918 if (DWARF_ARANGES_PAD_SIZE)
8920 /* Pad using a 2 byte words so that padding is correct for any
8922 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8923 2 * DWARF2_ADDR_SIZE);
8924 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8925 dw2_asm_output_data (2, 0, NULL);
8928 /* It is necessary not to output these entries if the sections were
8929 not used; if the sections were not used, the length will be 0 and
8930 the address may end up as 0 if the section is discarded by ld
8931 --gc-sections, leaving an invalid (0, 0) entry that can be
8932 confused with the terminator. */
8933 if (text_section_used)
8935 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8936 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8937 text_section_label, "Length");
8939 if (cold_text_section_used)
8941 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8943 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8944 cold_text_section_label, "Length");
8947 for (i = 0; i < arange_table_in_use; i++)
8949 dw_die_ref die = arange_table[i];
8951 /* We shouldn't see aranges for DIEs outside of the main CU. */
8952 gcc_assert (die->die_mark);
8954 if (die->die_tag == DW_TAG_subprogram)
8956 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8958 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8959 get_AT_low_pc (die), "Length");
8963 /* A static variable; extract the symbol from DW_AT_location.
8964 Note that this code isn't currently hit, as we only emit
8965 aranges for functions (jason 9/23/99). */
8966 dw_attr_ref a = get_AT (die, DW_AT_location);
8967 dw_loc_descr_ref loc;
8969 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8972 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8974 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8975 loc->dw_loc_oprnd1.v.val_addr, "Address");
8976 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8977 get_AT_unsigned (die, DW_AT_byte_size),
8982 /* Output the terminator words. */
8983 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8984 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8987 /* Add a new entry to .debug_ranges. Return the offset at which it
8991 add_ranges_num (int num)
8993 unsigned int in_use = ranges_table_in_use;
8995 if (in_use == ranges_table_allocated)
8997 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8998 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8999 ranges_table_allocated);
9000 memset (ranges_table + ranges_table_in_use, 0,
9001 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9004 ranges_table[in_use].num = num;
9005 ranges_table_in_use = in_use + 1;
9007 return in_use * 2 * DWARF2_ADDR_SIZE;
9010 /* Add a new entry to .debug_ranges corresponding to a block, or a
9011 range terminator if BLOCK is NULL. */
9014 add_ranges (const_tree block)
9016 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9019 /* Add a new entry to .debug_ranges corresponding to a pair of
9023 add_ranges_by_labels (const char *begin, const char *end)
9025 unsigned int in_use = ranges_by_label_in_use;
9027 if (in_use == ranges_by_label_allocated)
9029 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9030 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9032 ranges_by_label_allocated);
9033 memset (ranges_by_label + ranges_by_label_in_use, 0,
9034 RANGES_TABLE_INCREMENT
9035 * sizeof (struct dw_ranges_by_label_struct));
9038 ranges_by_label[in_use].begin = begin;
9039 ranges_by_label[in_use].end = end;
9040 ranges_by_label_in_use = in_use + 1;
9042 return add_ranges_num (-(int)in_use - 1);
9046 output_ranges (void)
9049 static const char *const start_fmt = "Offset 0x%x";
9050 const char *fmt = start_fmt;
9052 for (i = 0; i < ranges_table_in_use; i++)
9054 int block_num = ranges_table[i].num;
9058 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9059 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9061 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9062 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9064 /* If all code is in the text section, then the compilation
9065 unit base address defaults to DW_AT_low_pc, which is the
9066 base of the text section. */
9067 if (!have_multiple_function_sections)
9069 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9071 fmt, i * 2 * DWARF2_ADDR_SIZE);
9072 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9073 text_section_label, NULL);
9076 /* Otherwise, the compilation unit base address is zero,
9077 which allows us to use absolute addresses, and not worry
9078 about whether the target supports cross-section
9082 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9083 fmt, i * 2 * DWARF2_ADDR_SIZE);
9084 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9090 /* Negative block_num stands for an index into ranges_by_label. */
9091 else if (block_num < 0)
9093 int lab_idx = - block_num - 1;
9095 if (!have_multiple_function_sections)
9099 /* If we ever use add_ranges_by_labels () for a single
9100 function section, all we have to do is to take out
9102 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9103 ranges_by_label[lab_idx].begin,
9105 fmt, i * 2 * DWARF2_ADDR_SIZE);
9106 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9107 ranges_by_label[lab_idx].end,
9108 text_section_label, NULL);
9113 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9114 ranges_by_label[lab_idx].begin,
9115 fmt, i * 2 * DWARF2_ADDR_SIZE);
9116 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9117 ranges_by_label[lab_idx].end,
9123 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9124 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9130 /* Data structure containing information about input files. */
9133 const char *path; /* Complete file name. */
9134 const char *fname; /* File name part. */
9135 int length; /* Length of entire string. */
9136 struct dwarf_file_data * file_idx; /* Index in input file table. */
9137 int dir_idx; /* Index in directory table. */
9140 /* Data structure containing information about directories with source
9144 const char *path; /* Path including directory name. */
9145 int length; /* Path length. */
9146 int prefix; /* Index of directory entry which is a prefix. */
9147 int count; /* Number of files in this directory. */
9148 int dir_idx; /* Index of directory used as base. */
9151 /* Callback function for file_info comparison. We sort by looking at
9152 the directories in the path. */
9155 file_info_cmp (const void *p1, const void *p2)
9157 const struct file_info *const s1 = (const struct file_info *) p1;
9158 const struct file_info *const s2 = (const struct file_info *) p2;
9159 const unsigned char *cp1;
9160 const unsigned char *cp2;
9162 /* Take care of file names without directories. We need to make sure that
9163 we return consistent values to qsort since some will get confused if
9164 we return the same value when identical operands are passed in opposite
9165 orders. So if neither has a directory, return 0 and otherwise return
9166 1 or -1 depending on which one has the directory. */
9167 if ((s1->path == s1->fname || s2->path == s2->fname))
9168 return (s2->path == s2->fname) - (s1->path == s1->fname);
9170 cp1 = (const unsigned char *) s1->path;
9171 cp2 = (const unsigned char *) s2->path;
9177 /* Reached the end of the first path? If so, handle like above. */
9178 if ((cp1 == (const unsigned char *) s1->fname)
9179 || (cp2 == (const unsigned char *) s2->fname))
9180 return ((cp2 == (const unsigned char *) s2->fname)
9181 - (cp1 == (const unsigned char *) s1->fname));
9183 /* Character of current path component the same? */
9184 else if (*cp1 != *cp2)
9189 struct file_name_acquire_data
9191 struct file_info *files;
9196 /* Traversal function for the hash table. */
9199 file_name_acquire (void ** slot, void *data)
9201 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9202 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9203 struct file_info *fi;
9206 gcc_assert (fnad->max_files >= d->emitted_number);
9208 if (! d->emitted_number)
9211 gcc_assert (fnad->max_files != fnad->used_files);
9213 fi = fnad->files + fnad->used_files++;
9215 /* Skip all leading "./". */
9217 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9220 /* Create a new array entry. */
9222 fi->length = strlen (f);
9225 /* Search for the file name part. */
9226 f = strrchr (f, DIR_SEPARATOR);
9227 #if defined (DIR_SEPARATOR_2)
9229 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9233 if (f == NULL || f < g)
9239 fi->fname = f == NULL ? fi->path : f + 1;
9243 /* Output the directory table and the file name table. We try to minimize
9244 the total amount of memory needed. A heuristic is used to avoid large
9245 slowdowns with many input files. */
9248 output_file_names (void)
9250 struct file_name_acquire_data fnad;
9252 struct file_info *files;
9253 struct dir_info *dirs;
9262 if (!last_emitted_file)
9264 dw2_asm_output_data (1, 0, "End directory table");
9265 dw2_asm_output_data (1, 0, "End file name table");
9269 numfiles = last_emitted_file->emitted_number;
9271 /* Allocate the various arrays we need. */
9272 files = XALLOCAVEC (struct file_info, numfiles);
9273 dirs = XALLOCAVEC (struct dir_info, numfiles);
9276 fnad.used_files = 0;
9277 fnad.max_files = numfiles;
9278 htab_traverse (file_table, file_name_acquire, &fnad);
9279 gcc_assert (fnad.used_files == fnad.max_files);
9281 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9283 /* Find all the different directories used. */
9284 dirs[0].path = files[0].path;
9285 dirs[0].length = files[0].fname - files[0].path;
9286 dirs[0].prefix = -1;
9288 dirs[0].dir_idx = 0;
9289 files[0].dir_idx = 0;
9292 for (i = 1; i < numfiles; i++)
9293 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9294 && memcmp (dirs[ndirs - 1].path, files[i].path,
9295 dirs[ndirs - 1].length) == 0)
9297 /* Same directory as last entry. */
9298 files[i].dir_idx = ndirs - 1;
9299 ++dirs[ndirs - 1].count;
9305 /* This is a new directory. */
9306 dirs[ndirs].path = files[i].path;
9307 dirs[ndirs].length = files[i].fname - files[i].path;
9308 dirs[ndirs].count = 1;
9309 dirs[ndirs].dir_idx = ndirs;
9310 files[i].dir_idx = ndirs;
9312 /* Search for a prefix. */
9313 dirs[ndirs].prefix = -1;
9314 for (j = 0; j < ndirs; j++)
9315 if (dirs[j].length < dirs[ndirs].length
9316 && dirs[j].length > 1
9317 && (dirs[ndirs].prefix == -1
9318 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9319 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9320 dirs[ndirs].prefix = j;
9325 /* Now to the actual work. We have to find a subset of the directories which
9326 allow expressing the file name using references to the directory table
9327 with the least amount of characters. We do not do an exhaustive search
9328 where we would have to check out every combination of every single
9329 possible prefix. Instead we use a heuristic which provides nearly optimal
9330 results in most cases and never is much off. */
9331 saved = XALLOCAVEC (int, ndirs);
9332 savehere = XALLOCAVEC (int, ndirs);
9334 memset (saved, '\0', ndirs * sizeof (saved[0]));
9335 for (i = 0; i < ndirs; i++)
9340 /* We can always save some space for the current directory. But this
9341 does not mean it will be enough to justify adding the directory. */
9342 savehere[i] = dirs[i].length;
9343 total = (savehere[i] - saved[i]) * dirs[i].count;
9345 for (j = i + 1; j < ndirs; j++)
9348 if (saved[j] < dirs[i].length)
9350 /* Determine whether the dirs[i] path is a prefix of the
9355 while (k != -1 && k != (int) i)
9360 /* Yes it is. We can possibly save some memory by
9361 writing the filenames in dirs[j] relative to
9363 savehere[j] = dirs[i].length;
9364 total += (savehere[j] - saved[j]) * dirs[j].count;
9369 /* Check whether we can save enough to justify adding the dirs[i]
9371 if (total > dirs[i].length + 1)
9373 /* It's worthwhile adding. */
9374 for (j = i; j < ndirs; j++)
9375 if (savehere[j] > 0)
9377 /* Remember how much we saved for this directory so far. */
9378 saved[j] = savehere[j];
9380 /* Remember the prefix directory. */
9381 dirs[j].dir_idx = i;
9386 /* Emit the directory name table. */
9388 idx_offset = dirs[0].length > 0 ? 1 : 0;
9389 for (i = 1 - idx_offset; i < ndirs; i++)
9390 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
9391 "Directory Entry: 0x%x", i + idx_offset);
9393 dw2_asm_output_data (1, 0, "End directory table");
9395 /* We have to emit them in the order of emitted_number since that's
9396 used in the debug info generation. To do this efficiently we
9397 generate a back-mapping of the indices first. */
9398 backmap = XALLOCAVEC (int, numfiles);
9399 for (i = 0; i < numfiles; i++)
9400 backmap[files[i].file_idx->emitted_number - 1] = i;
9402 /* Now write all the file names. */
9403 for (i = 0; i < numfiles; i++)
9405 int file_idx = backmap[i];
9406 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9408 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9409 "File Entry: 0x%x", (unsigned) i + 1);
9411 /* Include directory index. */
9412 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9414 /* Modification time. */
9415 dw2_asm_output_data_uleb128 (0, NULL);
9417 /* File length in bytes. */
9418 dw2_asm_output_data_uleb128 (0, NULL);
9421 dw2_asm_output_data (1, 0, "End file name table");
9425 /* Output the source line number correspondence information. This
9426 information goes into the .debug_line section. */
9429 output_line_info (void)
9431 char l1[20], l2[20], p1[20], p2[20];
9432 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9433 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9436 unsigned long lt_index;
9437 unsigned long current_line;
9440 unsigned long current_file;
9441 unsigned long function;
9443 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9444 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9445 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9446 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9448 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9449 dw2_asm_output_data (4, 0xffffffff,
9450 "Initial length escape value indicating 64-bit DWARF extension");
9451 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9452 "Length of Source Line Info");
9453 ASM_OUTPUT_LABEL (asm_out_file, l1);
9455 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9456 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9457 ASM_OUTPUT_LABEL (asm_out_file, p1);
9459 /* Define the architecture-dependent minimum instruction length (in
9460 bytes). In this implementation of DWARF, this field is used for
9461 information purposes only. Since GCC generates assembly language,
9462 we have no a priori knowledge of how many instruction bytes are
9463 generated for each source line, and therefore can use only the
9464 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9465 commands. Accordingly, we fix this as `1', which is "correct
9466 enough" for all architectures, and don't let the target override. */
9467 dw2_asm_output_data (1, 1,
9468 "Minimum Instruction Length");
9470 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9471 "Default is_stmt_start flag");
9472 dw2_asm_output_data (1, DWARF_LINE_BASE,
9473 "Line Base Value (Special Opcodes)");
9474 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9475 "Line Range Value (Special Opcodes)");
9476 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9477 "Special Opcode Base");
9479 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9483 case DW_LNS_advance_pc:
9484 case DW_LNS_advance_line:
9485 case DW_LNS_set_file:
9486 case DW_LNS_set_column:
9487 case DW_LNS_fixed_advance_pc:
9495 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9499 /* Write out the information about the files we use. */
9500 output_file_names ();
9501 ASM_OUTPUT_LABEL (asm_out_file, p2);
9503 /* We used to set the address register to the first location in the text
9504 section here, but that didn't accomplish anything since we already
9505 have a line note for the opening brace of the first function. */
9507 /* Generate the line number to PC correspondence table, encoded as
9508 a series of state machine operations. */
9512 if (cfun && in_cold_section_p)
9513 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9515 strcpy (prev_line_label, text_section_label);
9516 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9518 dw_line_info_ref line_info = &line_info_table[lt_index];
9521 /* Disable this optimization for now; GDB wants to see two line notes
9522 at the beginning of a function so it can find the end of the
9525 /* Don't emit anything for redundant notes. Just updating the
9526 address doesn't accomplish anything, because we already assume
9527 that anything after the last address is this line. */
9528 if (line_info->dw_line_num == current_line
9529 && line_info->dw_file_num == current_file)
9533 /* Emit debug info for the address of the current line.
9535 Unfortunately, we have little choice here currently, and must always
9536 use the most general form. GCC does not know the address delta
9537 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9538 attributes which will give an upper bound on the address range. We
9539 could perhaps use length attributes to determine when it is safe to
9540 use DW_LNS_fixed_advance_pc. */
9542 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9545 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9546 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9547 "DW_LNS_fixed_advance_pc");
9548 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9552 /* This can handle any delta. This takes
9553 4+DWARF2_ADDR_SIZE bytes. */
9554 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9555 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9556 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9557 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9560 strcpy (prev_line_label, line_label);
9562 /* Emit debug info for the source file of the current line, if
9563 different from the previous line. */
9564 if (line_info->dw_file_num != current_file)
9566 current_file = line_info->dw_file_num;
9567 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9568 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9571 /* Emit debug info for the current line number, choosing the encoding
9572 that uses the least amount of space. */
9573 if (line_info->dw_line_num != current_line)
9575 line_offset = line_info->dw_line_num - current_line;
9576 line_delta = line_offset - DWARF_LINE_BASE;
9577 current_line = line_info->dw_line_num;
9578 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9579 /* This can handle deltas from -10 to 234, using the current
9580 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9582 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9583 "line %lu", current_line);
9586 /* This can handle any delta. This takes at least 4 bytes,
9587 depending on the value being encoded. */
9588 dw2_asm_output_data (1, DW_LNS_advance_line,
9589 "advance to line %lu", current_line);
9590 dw2_asm_output_data_sleb128 (line_offset, NULL);
9591 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9595 /* We still need to start a new row, so output a copy insn. */
9596 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9599 /* Emit debug info for the address of the end of the function. */
9602 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9603 "DW_LNS_fixed_advance_pc");
9604 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9608 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9609 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9610 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9611 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9614 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9615 dw2_asm_output_data_uleb128 (1, NULL);
9616 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9621 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9623 dw_separate_line_info_ref line_info
9624 = &separate_line_info_table[lt_index];
9627 /* Don't emit anything for redundant notes. */
9628 if (line_info->dw_line_num == current_line
9629 && line_info->dw_file_num == current_file
9630 && line_info->function == function)
9634 /* Emit debug info for the address of the current line. If this is
9635 a new function, or the first line of a function, then we need
9636 to handle it differently. */
9637 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9639 if (function != line_info->function)
9641 function = line_info->function;
9643 /* Set the address register to the first line in the function. */
9644 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9645 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9646 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9647 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9651 /* ??? See the DW_LNS_advance_pc comment above. */
9654 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9655 "DW_LNS_fixed_advance_pc");
9656 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9660 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9661 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9662 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9663 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9667 strcpy (prev_line_label, line_label);
9669 /* Emit debug info for the source file of the current line, if
9670 different from the previous line. */
9671 if (line_info->dw_file_num != current_file)
9673 current_file = line_info->dw_file_num;
9674 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9675 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9678 /* Emit debug info for the current line number, choosing the encoding
9679 that uses the least amount of space. */
9680 if (line_info->dw_line_num != current_line)
9682 line_offset = line_info->dw_line_num - current_line;
9683 line_delta = line_offset - DWARF_LINE_BASE;
9684 current_line = line_info->dw_line_num;
9685 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9686 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9687 "line %lu", current_line);
9690 dw2_asm_output_data (1, DW_LNS_advance_line,
9691 "advance to line %lu", current_line);
9692 dw2_asm_output_data_sleb128 (line_offset, NULL);
9693 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9697 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9705 /* If we're done with a function, end its sequence. */
9706 if (lt_index == separate_line_info_table_in_use
9707 || separate_line_info_table[lt_index].function != function)
9712 /* Emit debug info for the address of the end of the function. */
9713 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9716 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9717 "DW_LNS_fixed_advance_pc");
9718 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9722 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9723 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9724 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9725 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9728 /* Output the marker for the end of this sequence. */
9729 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9730 dw2_asm_output_data_uleb128 (1, NULL);
9731 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9735 /* Output the marker for the end of the line number info. */
9736 ASM_OUTPUT_LABEL (asm_out_file, l2);
9739 /* Given a pointer to a tree node for some base type, return a pointer to
9740 a DIE that describes the given type.
9742 This routine must only be called for GCC type nodes that correspond to
9743 Dwarf base (fundamental) types. */
9746 base_type_die (tree type)
9748 dw_die_ref base_type_result;
9749 enum dwarf_type encoding;
9751 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9754 /* If this is a subtype that should not be emitted as a subrange type,
9755 use the base type. See subrange_type_for_debug_p. */
9756 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9757 type = TREE_TYPE (type);
9759 switch (TREE_CODE (type))
9762 if (TYPE_STRING_FLAG (type))
9764 if (TYPE_UNSIGNED (type))
9765 encoding = DW_ATE_unsigned_char;
9767 encoding = DW_ATE_signed_char;
9769 else if (TYPE_UNSIGNED (type))
9770 encoding = DW_ATE_unsigned;
9772 encoding = DW_ATE_signed;
9776 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9777 encoding = DW_ATE_decimal_float;
9779 encoding = DW_ATE_float;
9782 case FIXED_POINT_TYPE:
9783 if (TYPE_UNSIGNED (type))
9784 encoding = DW_ATE_unsigned_fixed;
9786 encoding = DW_ATE_signed_fixed;
9789 /* Dwarf2 doesn't know anything about complex ints, so use
9790 a user defined type for it. */
9792 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9793 encoding = DW_ATE_complex_float;
9795 encoding = DW_ATE_lo_user;
9799 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9800 encoding = DW_ATE_boolean;
9804 /* No other TREE_CODEs are Dwarf fundamental types. */
9808 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9810 /* This probably indicates a bug. */
9811 if (! TYPE_NAME (type))
9812 add_name_attribute (base_type_result, "__unknown__");
9814 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9815 int_size_in_bytes (type));
9816 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9818 return base_type_result;
9821 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9822 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9825 is_base_type (tree type)
9827 switch (TREE_CODE (type))
9833 case FIXED_POINT_TYPE:
9841 case QUAL_UNION_TYPE:
9846 case REFERENCE_TYPE:
9859 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9860 node, return the size in bits for the type if it is a constant, or else
9861 return the alignment for the type if the type's size is not constant, or
9862 else return BITS_PER_WORD if the type actually turns out to be an
9865 static inline unsigned HOST_WIDE_INT
9866 simple_type_size_in_bits (const_tree type)
9868 if (TREE_CODE (type) == ERROR_MARK)
9869 return BITS_PER_WORD;
9870 else if (TYPE_SIZE (type) == NULL_TREE)
9872 else if (host_integerp (TYPE_SIZE (type), 1))
9873 return tree_low_cst (TYPE_SIZE (type), 1);
9875 return TYPE_ALIGN (type);
9878 /* Given a pointer to a tree node for a subrange type, return a pointer
9879 to a DIE that describes the given type. */
9882 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9884 dw_die_ref subrange_die;
9885 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9887 if (context_die == NULL)
9888 context_die = comp_unit_die;
9890 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9892 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9894 /* The size of the subrange type and its base type do not match,
9895 so we need to generate a size attribute for the subrange type. */
9896 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9900 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9902 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9904 return subrange_die;
9907 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9908 entry that chains various modifiers in front of the given type. */
9911 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9912 dw_die_ref context_die)
9914 enum tree_code code = TREE_CODE (type);
9915 dw_die_ref mod_type_die;
9916 dw_die_ref sub_die = NULL;
9917 tree item_type = NULL;
9918 tree qualified_type;
9919 tree name, low, high;
9921 if (code == ERROR_MARK)
9924 /* See if we already have the appropriately qualified variant of
9927 = get_qualified_type (type,
9928 ((is_const_type ? TYPE_QUAL_CONST : 0)
9929 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9931 /* If we do, then we can just use its DIE, if it exists. */
9934 mod_type_die = lookup_type_die (qualified_type);
9936 return mod_type_die;
9939 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9941 /* Handle C typedef types. */
9942 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9944 tree dtype = TREE_TYPE (name);
9946 if (qualified_type == dtype)
9948 /* For a named type, use the typedef. */
9949 gen_type_die (qualified_type, context_die);
9950 return lookup_type_die (qualified_type);
9952 else if (is_const_type < TYPE_READONLY (dtype)
9953 || is_volatile_type < TYPE_VOLATILE (dtype)
9954 || (is_const_type <= TYPE_READONLY (dtype)
9955 && is_volatile_type <= TYPE_VOLATILE (dtype)
9956 && DECL_ORIGINAL_TYPE (name) != type))
9957 /* cv-unqualified version of named type. Just use the unnamed
9958 type to which it refers. */
9959 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9960 is_const_type, is_volatile_type,
9962 /* Else cv-qualified version of named type; fall through. */
9967 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9968 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9970 else if (is_volatile_type)
9972 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9973 sub_die = modified_type_die (type, 0, 0, context_die);
9975 else if (code == POINTER_TYPE)
9977 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9978 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9979 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9980 item_type = TREE_TYPE (type);
9982 else if (code == REFERENCE_TYPE)
9984 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9985 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9986 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9987 item_type = TREE_TYPE (type);
9989 else if (code == INTEGER_TYPE
9990 && TREE_TYPE (type) != NULL_TREE
9991 && subrange_type_for_debug_p (type, &low, &high))
9993 mod_type_die = subrange_type_die (type, low, high, context_die);
9994 item_type = TREE_TYPE (type);
9996 else if (is_base_type (type))
9997 mod_type_die = base_type_die (type);
10000 gen_type_die (type, context_die);
10002 /* We have to get the type_main_variant here (and pass that to the
10003 `lookup_type_die' routine) because the ..._TYPE node we have
10004 might simply be a *copy* of some original type node (where the
10005 copy was created to help us keep track of typedef names) and
10006 that copy might have a different TYPE_UID from the original
10008 if (TREE_CODE (type) != VECTOR_TYPE)
10009 return lookup_type_die (type_main_variant (type));
10011 /* Vectors have the debugging information in the type,
10012 not the main variant. */
10013 return lookup_type_die (type);
10016 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10017 don't output a DW_TAG_typedef, since there isn't one in the
10018 user's program; just attach a DW_AT_name to the type. */
10020 && (TREE_CODE (name) != TYPE_DECL
10021 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10023 if (TREE_CODE (name) == TYPE_DECL)
10024 /* Could just call add_name_and_src_coords_attributes here,
10025 but since this is a builtin type it doesn't have any
10026 useful source coordinates anyway. */
10027 name = DECL_NAME (name);
10028 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10031 if (qualified_type)
10032 equate_type_number_to_die (qualified_type, mod_type_die);
10035 /* We must do this after the equate_type_number_to_die call, in case
10036 this is a recursive type. This ensures that the modified_type_die
10037 recursion will terminate even if the type is recursive. Recursive
10038 types are possible in Ada. */
10039 sub_die = modified_type_die (item_type,
10040 TYPE_READONLY (item_type),
10041 TYPE_VOLATILE (item_type),
10044 if (sub_die != NULL)
10045 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10047 return mod_type_die;
10050 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10051 an enumerated type. */
10054 type_is_enum (const_tree type)
10056 return TREE_CODE (type) == ENUMERAL_TYPE;
10059 /* Return the DBX register number described by a given RTL node. */
10061 static unsigned int
10062 dbx_reg_number (const_rtx rtl)
10064 unsigned regno = REGNO (rtl);
10066 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10068 #ifdef LEAF_REG_REMAP
10069 if (current_function_uses_only_leaf_regs)
10071 int leaf_reg = LEAF_REG_REMAP (regno);
10072 if (leaf_reg != -1)
10073 regno = (unsigned) leaf_reg;
10077 return DBX_REGISTER_NUMBER (regno);
10080 /* Optionally add a DW_OP_piece term to a location description expression.
10081 DW_OP_piece is only added if the location description expression already
10082 doesn't end with DW_OP_piece. */
10085 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10087 dw_loc_descr_ref loc;
10089 if (*list_head != NULL)
10091 /* Find the end of the chain. */
10092 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10095 if (loc->dw_loc_opc != DW_OP_piece)
10096 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10100 /* Return a location descriptor that designates a machine register or
10101 zero if there is none. */
10103 static dw_loc_descr_ref
10104 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10108 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10111 regs = targetm.dwarf_register_span (rtl);
10113 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10114 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10116 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10119 /* Return a location descriptor that designates a machine register for
10120 a given hard register number. */
10122 static dw_loc_descr_ref
10123 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10125 dw_loc_descr_ref reg_loc_descr;
10129 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10131 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10133 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10134 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10136 return reg_loc_descr;
10139 /* Given an RTL of a register, return a location descriptor that
10140 designates a value that spans more than one register. */
10142 static dw_loc_descr_ref
10143 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10144 enum var_init_status initialized)
10146 int nregs, size, i;
10148 dw_loc_descr_ref loc_result = NULL;
10151 #ifdef LEAF_REG_REMAP
10152 if (current_function_uses_only_leaf_regs)
10154 int leaf_reg = LEAF_REG_REMAP (reg);
10155 if (leaf_reg != -1)
10156 reg = (unsigned) leaf_reg;
10159 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10160 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10162 /* Simple, contiguous registers. */
10163 if (regs == NULL_RTX)
10165 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10170 dw_loc_descr_ref t;
10172 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10173 VAR_INIT_STATUS_INITIALIZED);
10174 add_loc_descr (&loc_result, t);
10175 add_loc_descr_op_piece (&loc_result, size);
10181 /* Now onto stupid register sets in non contiguous locations. */
10183 gcc_assert (GET_CODE (regs) == PARALLEL);
10185 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10188 for (i = 0; i < XVECLEN (regs, 0); ++i)
10190 dw_loc_descr_ref t;
10192 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10193 VAR_INIT_STATUS_INITIALIZED);
10194 add_loc_descr (&loc_result, t);
10195 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10196 add_loc_descr_op_piece (&loc_result, size);
10199 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10200 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10204 #endif /* DWARF2_DEBUGGING_INFO */
10206 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10208 /* Return a location descriptor that designates a constant. */
10210 static dw_loc_descr_ref
10211 int_loc_descriptor (HOST_WIDE_INT i)
10213 enum dwarf_location_atom op;
10215 /* Pick the smallest representation of a constant, rather than just
10216 defaulting to the LEB encoding. */
10220 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10221 else if (i <= 0xff)
10222 op = DW_OP_const1u;
10223 else if (i <= 0xffff)
10224 op = DW_OP_const2u;
10225 else if (HOST_BITS_PER_WIDE_INT == 32
10226 || i <= 0xffffffff)
10227 op = DW_OP_const4u;
10234 op = DW_OP_const1s;
10235 else if (i >= -0x8000)
10236 op = DW_OP_const2s;
10237 else if (HOST_BITS_PER_WIDE_INT == 32
10238 || i >= -0x80000000)
10239 op = DW_OP_const4s;
10244 return new_loc_descr (op, i, 0);
10248 #ifdef DWARF2_DEBUGGING_INFO
10250 /* Return a location descriptor that designates a base+offset location. */
10252 static dw_loc_descr_ref
10253 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10254 enum var_init_status initialized)
10256 unsigned int regno;
10257 dw_loc_descr_ref result;
10258 dw_fde_ref fde = current_fde ();
10260 /* We only use "frame base" when we're sure we're talking about the
10261 post-prologue local stack frame. We do this by *not* running
10262 register elimination until this point, and recognizing the special
10263 argument pointer and soft frame pointer rtx's. */
10264 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10266 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10270 if (GET_CODE (elim) == PLUS)
10272 offset += INTVAL (XEXP (elim, 1));
10273 elim = XEXP (elim, 0);
10275 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10276 && (elim == hard_frame_pointer_rtx
10277 || elim == stack_pointer_rtx))
10278 || elim == (frame_pointer_needed
10279 ? hard_frame_pointer_rtx
10280 : stack_pointer_rtx));
10282 /* If drap register is used to align stack, use frame
10283 pointer + offset to access stack variables. If stack
10284 is aligned without drap, use stack pointer + offset to
10285 access stack variables. */
10286 if (crtl->stack_realign_tried
10287 && reg == frame_pointer_rtx)
10290 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10291 ? HARD_FRAME_POINTER_REGNUM
10292 : STACK_POINTER_REGNUM);
10293 return new_reg_loc_descr (base_reg, offset);
10296 offset += frame_pointer_fb_offset;
10297 return new_loc_descr (DW_OP_fbreg, offset, 0);
10301 && fde->drap_reg != INVALID_REGNUM
10302 && (fde->drap_reg == REGNO (reg)
10303 || fde->vdrap_reg == REGNO (reg)))
10305 /* Use cfa+offset to represent the location of arguments passed
10306 on stack when drap is used to align stack. */
10307 return new_loc_descr (DW_OP_fbreg, offset, 0);
10310 regno = dbx_reg_number (reg);
10312 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10315 result = new_loc_descr (DW_OP_bregx, regno, offset);
10317 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10318 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10323 /* Return true if this RTL expression describes a base+offset calculation. */
10326 is_based_loc (const_rtx rtl)
10328 return (GET_CODE (rtl) == PLUS
10329 && ((REG_P (XEXP (rtl, 0))
10330 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10331 && CONST_INT_P (XEXP (rtl, 1)))));
10334 /* Return a descriptor that describes the concatenation of N locations
10335 used to form the address of a memory location. */
10337 static dw_loc_descr_ref
10338 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10339 enum var_init_status initialized)
10342 dw_loc_descr_ref cc_loc_result = NULL;
10343 unsigned int n = XVECLEN (concatn, 0);
10345 for (i = 0; i < n; ++i)
10347 dw_loc_descr_ref ref;
10348 rtx x = XVECEXP (concatn, 0, i);
10350 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10354 add_loc_descr (&cc_loc_result, ref);
10355 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10358 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10359 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10361 return cc_loc_result;
10364 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10367 static dw_loc_descr_ref
10368 tls_mem_loc_descriptor (rtx mem)
10371 dw_loc_descr_ref loc_result;
10373 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10376 base = get_base_address (MEM_EXPR (mem));
10378 || TREE_CODE (base) != VAR_DECL
10379 || !DECL_THREAD_LOCAL_P (base))
10382 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
10383 if (loc_result == NULL)
10386 if (INTVAL (MEM_OFFSET (mem)))
10387 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
10392 /* The following routine converts the RTL for a variable or parameter
10393 (resident in memory) into an equivalent Dwarf representation of a
10394 mechanism for getting the address of that same variable onto the top of a
10395 hypothetical "address evaluation" stack.
10397 When creating memory location descriptors, we are effectively transforming
10398 the RTL for a memory-resident object into its Dwarf postfix expression
10399 equivalent. This routine recursively descends an RTL tree, turning
10400 it into Dwarf postfix code as it goes.
10402 MODE is the mode of the memory reference, needed to handle some
10403 autoincrement addressing modes.
10405 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10406 location list for RTL.
10408 Return 0 if we can't represent the location. */
10410 static dw_loc_descr_ref
10411 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
10412 enum var_init_status initialized)
10414 dw_loc_descr_ref mem_loc_result = NULL;
10415 enum dwarf_location_atom op;
10417 /* Note that for a dynamically sized array, the location we will generate a
10418 description of here will be the lowest numbered location which is
10419 actually within the array. That's *not* necessarily the same as the
10420 zeroth element of the array. */
10422 rtl = targetm.delegitimize_address (rtl);
10424 switch (GET_CODE (rtl))
10429 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10430 just fall into the SUBREG code. */
10432 /* ... fall through ... */
10435 /* The case of a subreg may arise when we have a local (register)
10436 variable or a formal (register) parameter which doesn't quite fill
10437 up an entire register. For now, just assume that it is
10438 legitimate to make the Dwarf info refer to the whole register which
10439 contains the given subreg. */
10440 rtl = XEXP (rtl, 0);
10442 /* ... fall through ... */
10445 /* Whenever a register number forms a part of the description of the
10446 method for calculating the (dynamic) address of a memory resident
10447 object, DWARF rules require the register number be referred to as
10448 a "base register". This distinction is not based in any way upon
10449 what category of register the hardware believes the given register
10450 belongs to. This is strictly DWARF terminology we're dealing with
10451 here. Note that in cases where the location of a memory-resident
10452 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10453 OP_CONST (0)) the actual DWARF location descriptor that we generate
10454 may just be OP_BASEREG (basereg). This may look deceptively like
10455 the object in question was allocated to a register (rather than in
10456 memory) so DWARF consumers need to be aware of the subtle
10457 distinction between OP_REG and OP_BASEREG. */
10458 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10459 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10460 else if (stack_realign_drap
10462 && crtl->args.internal_arg_pointer == rtl
10463 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10465 /* If RTL is internal_arg_pointer, which has been optimized
10466 out, use DRAP instead. */
10467 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10468 VAR_INIT_STATUS_INITIALIZED);
10473 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10474 VAR_INIT_STATUS_INITIALIZED);
10475 if (mem_loc_result == NULL)
10476 mem_loc_result = tls_mem_loc_descriptor (rtl);
10477 if (mem_loc_result != 0)
10478 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10482 rtl = XEXP (rtl, 1);
10484 /* ... fall through ... */
10487 /* Some ports can transform a symbol ref into a label ref, because
10488 the symbol ref is too far away and has to be dumped into a constant
10492 /* Alternatively, the symbol in the constant pool might be referenced
10493 by a different symbol. */
10494 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10497 rtx tmp = get_pool_constant_mark (rtl, &marked);
10499 if (GET_CODE (tmp) == SYMBOL_REF)
10502 if (CONSTANT_POOL_ADDRESS_P (tmp))
10503 get_pool_constant_mark (tmp, &marked);
10508 /* If all references to this pool constant were optimized away,
10509 it was not output and thus we can't represent it.
10510 FIXME: might try to use DW_OP_const_value here, though
10511 DW_OP_piece complicates it. */
10516 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10517 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10518 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10519 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10523 /* Extract the PLUS expression nested inside and fall into
10524 PLUS code below. */
10525 rtl = XEXP (rtl, 1);
10530 /* Turn these into a PLUS expression and fall into the PLUS code
10532 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10533 GEN_INT (GET_CODE (rtl) == PRE_INC
10534 ? GET_MODE_UNIT_SIZE (mode)
10535 : -GET_MODE_UNIT_SIZE (mode)));
10537 /* ... fall through ... */
10541 if (is_based_loc (rtl))
10542 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10543 INTVAL (XEXP (rtl, 1)),
10544 VAR_INIT_STATUS_INITIALIZED);
10547 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10548 VAR_INIT_STATUS_INITIALIZED);
10549 if (mem_loc_result == 0)
10552 if (CONST_INT_P (XEXP (rtl, 1)))
10553 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
10556 dw_loc_descr_ref mem_loc_result2
10557 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10558 VAR_INIT_STATUS_INITIALIZED);
10559 if (mem_loc_result2 == 0)
10561 add_loc_descr (&mem_loc_result, mem_loc_result2);
10562 add_loc_descr (&mem_loc_result,
10563 new_loc_descr (DW_OP_plus, 0, 0));
10568 /* If a pseudo-reg is optimized away, it is possible for it to
10569 be replaced with a MEM containing a multiply or shift. */
10588 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10589 VAR_INIT_STATUS_INITIALIZED);
10590 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10591 VAR_INIT_STATUS_INITIALIZED);
10593 if (op0 == 0 || op1 == 0)
10596 mem_loc_result = op0;
10597 add_loc_descr (&mem_loc_result, op1);
10598 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10603 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10607 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10608 VAR_INIT_STATUS_INITIALIZED);
10612 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10613 can't express it in the debug info. This can happen e.g. with some
10618 gcc_unreachable ();
10621 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10622 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10624 return mem_loc_result;
10627 /* Return a descriptor that describes the concatenation of two locations.
10628 This is typically a complex variable. */
10630 static dw_loc_descr_ref
10631 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10633 dw_loc_descr_ref cc_loc_result = NULL;
10634 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10635 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10637 if (x0_ref == 0 || x1_ref == 0)
10640 cc_loc_result = x0_ref;
10641 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10643 add_loc_descr (&cc_loc_result, x1_ref);
10644 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10646 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10647 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10649 return cc_loc_result;
10652 /* Return a descriptor that describes the concatenation of N
10655 static dw_loc_descr_ref
10656 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10659 dw_loc_descr_ref cc_loc_result = NULL;
10660 unsigned int n = XVECLEN (concatn, 0);
10662 for (i = 0; i < n; ++i)
10664 dw_loc_descr_ref ref;
10665 rtx x = XVECEXP (concatn, 0, i);
10667 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10671 add_loc_descr (&cc_loc_result, ref);
10672 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10675 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10676 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10678 return cc_loc_result;
10681 /* Output a proper Dwarf location descriptor for a variable or parameter
10682 which is either allocated in a register or in a memory location. For a
10683 register, we just generate an OP_REG and the register number. For a
10684 memory location we provide a Dwarf postfix expression describing how to
10685 generate the (dynamic) address of the object onto the address stack.
10687 If we don't know how to describe it, return 0. */
10689 static dw_loc_descr_ref
10690 loc_descriptor (rtx rtl, enum var_init_status initialized)
10692 dw_loc_descr_ref loc_result = NULL;
10694 switch (GET_CODE (rtl))
10697 /* The case of a subreg may arise when we have a local (register)
10698 variable or a formal (register) parameter which doesn't quite fill
10699 up an entire register. For now, just assume that it is
10700 legitimate to make the Dwarf info refer to the whole register which
10701 contains the given subreg. */
10702 rtl = SUBREG_REG (rtl);
10704 /* ... fall through ... */
10707 loc_result = reg_loc_descriptor (rtl, initialized);
10711 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10713 if (loc_result == NULL)
10714 loc_result = tls_mem_loc_descriptor (rtl);
10718 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10723 loc_result = concatn_loc_descriptor (rtl, initialized);
10728 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10730 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10734 rtl = XEXP (rtl, 1);
10739 rtvec par_elems = XVEC (rtl, 0);
10740 int num_elem = GET_NUM_ELEM (par_elems);
10741 enum machine_mode mode;
10744 /* Create the first one, so we have something to add to. */
10745 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10747 if (loc_result == NULL)
10749 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10750 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10751 for (i = 1; i < num_elem; i++)
10753 dw_loc_descr_ref temp;
10755 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10759 add_loc_descr (&loc_result, temp);
10760 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10761 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10767 gcc_unreachable ();
10773 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10774 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10775 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10776 top-level invocation, and we require the address of LOC; is 0 if we require
10777 the value of LOC. */
10779 static dw_loc_descr_ref
10780 loc_descriptor_from_tree_1 (tree loc, int want_address)
10782 dw_loc_descr_ref ret, ret1;
10783 int have_address = 0;
10784 enum dwarf_location_atom op;
10786 /* ??? Most of the time we do not take proper care for sign/zero
10787 extending the values properly. Hopefully this won't be a real
10790 switch (TREE_CODE (loc))
10795 case PLACEHOLDER_EXPR:
10796 /* This case involves extracting fields from an object to determine the
10797 position of other fields. We don't try to encode this here. The
10798 only user of this is Ada, which encodes the needed information using
10799 the names of types. */
10805 case PREINCREMENT_EXPR:
10806 case PREDECREMENT_EXPR:
10807 case POSTINCREMENT_EXPR:
10808 case POSTDECREMENT_EXPR:
10809 /* There are no opcodes for these operations. */
10813 /* If we already want an address, there's nothing we can do. */
10817 /* Otherwise, process the argument and look for the address. */
10818 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10821 if (DECL_THREAD_LOCAL_P (loc))
10824 enum dwarf_location_atom first_op;
10825 enum dwarf_location_atom second_op;
10826 bool dtprel = false;
10828 if (targetm.have_tls)
10830 /* If this is not defined, we have no way to emit the
10832 if (!targetm.asm_out.output_dwarf_dtprel)
10835 /* The way DW_OP_GNU_push_tls_address is specified, we
10836 can only look up addresses of objects in the current
10838 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
10840 first_op = DW_OP_addr;
10842 second_op = DW_OP_GNU_push_tls_address;
10846 if (!targetm.emutls.debug_form_tls_address)
10848 loc = emutls_decl (loc);
10849 first_op = DW_OP_addr;
10850 second_op = DW_OP_form_tls_address;
10853 rtl = rtl_for_decl_location (loc);
10854 if (rtl == NULL_RTX)
10859 rtl = XEXP (rtl, 0);
10860 if (! CONSTANT_P (rtl))
10863 ret = new_loc_descr (first_op, 0, 0);
10864 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10865 ret->dw_loc_oprnd1.v.val_addr = rtl;
10866 ret->dtprel = dtprel;
10868 ret1 = new_loc_descr (second_op, 0, 0);
10869 add_loc_descr (&ret, ret1);
10877 if (DECL_HAS_VALUE_EXPR_P (loc))
10878 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10883 case FUNCTION_DECL:
10885 rtx rtl = rtl_for_decl_location (loc);
10887 if (rtl == NULL_RTX)
10889 else if (CONST_INT_P (rtl))
10891 HOST_WIDE_INT val = INTVAL (rtl);
10892 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10893 val &= GET_MODE_MASK (DECL_MODE (loc));
10894 ret = int_loc_descriptor (val);
10896 else if (GET_CODE (rtl) == CONST_STRING)
10898 else if (CONSTANT_P (rtl))
10900 ret = new_loc_descr (DW_OP_addr, 0, 0);
10901 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10902 ret->dw_loc_oprnd1.v.val_addr = rtl;
10906 enum machine_mode mode;
10908 /* Certain constructs can only be represented at top-level. */
10909 if (want_address == 2)
10910 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10912 mode = GET_MODE (rtl);
10915 rtl = XEXP (rtl, 0);
10918 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10924 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10928 case COMPOUND_EXPR:
10929 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10932 case VIEW_CONVERT_EXPR:
10935 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10937 case COMPONENT_REF:
10938 case BIT_FIELD_REF:
10940 case ARRAY_RANGE_REF:
10943 HOST_WIDE_INT bitsize, bitpos, bytepos;
10944 enum machine_mode mode;
10946 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10948 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10949 &unsignedp, &volatilep, false);
10954 ret = loc_descriptor_from_tree_1 (obj, 1);
10956 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10959 if (offset != NULL_TREE)
10961 /* Variable offset. */
10962 ret1 = loc_descriptor_from_tree_1 (offset, 0);
10965 add_loc_descr (&ret, ret1);
10966 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10969 bytepos = bitpos / BITS_PER_UNIT;
10970 loc_descr_plus_const (&ret, bytepos);
10977 if (host_integerp (loc, 0))
10978 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10985 /* Get an RTL for this, if something has been emitted. */
10986 rtx rtl = lookup_constant_def (loc);
10987 enum machine_mode mode;
10989 if (!rtl || !MEM_P (rtl))
10991 mode = GET_MODE (rtl);
10992 rtl = XEXP (rtl, 0);
10993 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10998 case TRUTH_AND_EXPR:
10999 case TRUTH_ANDIF_EXPR:
11004 case TRUTH_XOR_EXPR:
11009 case TRUTH_OR_EXPR:
11010 case TRUTH_ORIF_EXPR:
11015 case FLOOR_DIV_EXPR:
11016 case CEIL_DIV_EXPR:
11017 case ROUND_DIV_EXPR:
11018 case TRUNC_DIV_EXPR:
11026 case FLOOR_MOD_EXPR:
11027 case CEIL_MOD_EXPR:
11028 case ROUND_MOD_EXPR:
11029 case TRUNC_MOD_EXPR:
11042 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
11045 case POINTER_PLUS_EXPR:
11047 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
11048 && host_integerp (TREE_OPERAND (loc, 1), 0))
11050 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11054 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
11062 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11069 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11076 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11083 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11098 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11099 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11100 if (ret == 0 || ret1 == 0)
11103 add_loc_descr (&ret, ret1);
11104 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11107 case TRUTH_NOT_EXPR:
11121 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11125 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11131 const enum tree_code code =
11132 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
11134 loc = build3 (COND_EXPR, TREE_TYPE (loc),
11135 build2 (code, integer_type_node,
11136 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
11137 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
11140 /* ... fall through ... */
11144 dw_loc_descr_ref lhs
11145 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11146 dw_loc_descr_ref rhs
11147 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
11148 dw_loc_descr_ref bra_node, jump_node, tmp;
11150 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11151 if (ret == 0 || lhs == 0 || rhs == 0)
11154 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11155 add_loc_descr (&ret, bra_node);
11157 add_loc_descr (&ret, rhs);
11158 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
11159 add_loc_descr (&ret, jump_node);
11161 add_loc_descr (&ret, lhs);
11162 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11163 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
11165 /* ??? Need a node to point the skip at. Use a nop. */
11166 tmp = new_loc_descr (DW_OP_nop, 0, 0);
11167 add_loc_descr (&ret, tmp);
11168 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11169 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
11173 case FIX_TRUNC_EXPR:
11177 /* Leave front-end specific codes as simply unknown. This comes
11178 up, for instance, with the C STMT_EXPR. */
11179 if ((unsigned int) TREE_CODE (loc)
11180 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
11183 #ifdef ENABLE_CHECKING
11184 /* Otherwise this is a generic code; we should just lists all of
11185 these explicitly. We forgot one. */
11186 gcc_unreachable ();
11188 /* In a release build, we want to degrade gracefully: better to
11189 generate incomplete debugging information than to crash. */
11194 /* Show if we can't fill the request for an address. */
11195 if (want_address && !have_address)
11198 /* If we've got an address and don't want one, dereference. */
11199 if (!want_address && have_address && ret)
11201 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
11203 if (size > DWARF2_ADDR_SIZE || size == -1)
11205 else if (size == DWARF2_ADDR_SIZE)
11208 op = DW_OP_deref_size;
11210 add_loc_descr (&ret, new_loc_descr (op, size, 0));
11216 static inline dw_loc_descr_ref
11217 loc_descriptor_from_tree (tree loc)
11219 return loc_descriptor_from_tree_1 (loc, 2);
11222 /* Given a value, round it up to the lowest multiple of `boundary'
11223 which is not less than the value itself. */
11225 static inline HOST_WIDE_INT
11226 ceiling (HOST_WIDE_INT value, unsigned int boundary)
11228 return (((value + boundary - 1) / boundary) * boundary);
11231 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
11232 pointer to the declared type for the relevant field variable, or return
11233 `integer_type_node' if the given node turns out to be an
11234 ERROR_MARK node. */
11237 field_type (const_tree decl)
11241 if (TREE_CODE (decl) == ERROR_MARK)
11242 return integer_type_node;
11244 type = DECL_BIT_FIELD_TYPE (decl);
11245 if (type == NULL_TREE)
11246 type = TREE_TYPE (decl);
11251 /* Given a pointer to a tree node, return the alignment in bits for
11252 it, or else return BITS_PER_WORD if the node actually turns out to
11253 be an ERROR_MARK node. */
11255 static inline unsigned
11256 simple_type_align_in_bits (const_tree type)
11258 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
11261 static inline unsigned
11262 simple_decl_align_in_bits (const_tree decl)
11264 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
11267 /* Return the result of rounding T up to ALIGN. */
11269 static inline HOST_WIDE_INT
11270 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
11272 /* We must be careful if T is negative because HOST_WIDE_INT can be
11273 either "above" or "below" unsigned int as per the C promotion
11274 rules, depending on the host, thus making the signedness of the
11275 direct multiplication and division unpredictable. */
11276 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
11282 return (HOST_WIDE_INT) u;
11285 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
11286 lowest addressed byte of the "containing object" for the given FIELD_DECL,
11287 or return 0 if we are unable to determine what that offset is, either
11288 because the argument turns out to be a pointer to an ERROR_MARK node, or
11289 because the offset is actually variable. (We can't handle the latter case
11292 static HOST_WIDE_INT
11293 field_byte_offset (const_tree decl)
11295 HOST_WIDE_INT object_offset_in_bits;
11296 HOST_WIDE_INT bitpos_int;
11298 if (TREE_CODE (decl) == ERROR_MARK)
11301 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
11303 /* We cannot yet cope with fields whose positions are variable, so
11304 for now, when we see such things, we simply return 0. Someday, we may
11305 be able to handle such cases, but it will be damn difficult. */
11306 if (! host_integerp (bit_position (decl), 0))
11309 bitpos_int = int_bit_position (decl);
11311 #ifdef PCC_BITFIELD_TYPE_MATTERS
11312 if (PCC_BITFIELD_TYPE_MATTERS)
11315 tree field_size_tree;
11316 HOST_WIDE_INT deepest_bitpos;
11317 unsigned HOST_WIDE_INT field_size_in_bits;
11318 unsigned int type_align_in_bits;
11319 unsigned int decl_align_in_bits;
11320 unsigned HOST_WIDE_INT type_size_in_bits;
11322 type = field_type (decl);
11323 type_size_in_bits = simple_type_size_in_bits (type);
11324 type_align_in_bits = simple_type_align_in_bits (type);
11326 field_size_tree = DECL_SIZE (decl);
11328 /* The size could be unspecified if there was an error, or for
11329 a flexible array member. */
11330 if (!field_size_tree)
11331 field_size_tree = bitsize_zero_node;
11333 /* If the size of the field is not constant, use the type size. */
11334 if (host_integerp (field_size_tree, 1))
11335 field_size_in_bits = tree_low_cst (field_size_tree, 1);
11337 field_size_in_bits = type_size_in_bits;
11339 decl_align_in_bits = simple_decl_align_in_bits (decl);
11341 /* The GCC front-end doesn't make any attempt to keep track of the
11342 starting bit offset (relative to the start of the containing
11343 structure type) of the hypothetical "containing object" for a
11344 bit-field. Thus, when computing the byte offset value for the
11345 start of the "containing object" of a bit-field, we must deduce
11346 this information on our own. This can be rather tricky to do in
11347 some cases. For example, handling the following structure type
11348 definition when compiling for an i386/i486 target (which only
11349 aligns long long's to 32-bit boundaries) can be very tricky:
11351 struct S { int field1; long long field2:31; };
11353 Fortunately, there is a simple rule-of-thumb which can be used
11354 in such cases. When compiling for an i386/i486, GCC will
11355 allocate 8 bytes for the structure shown above. It decides to
11356 do this based upon one simple rule for bit-field allocation.
11357 GCC allocates each "containing object" for each bit-field at
11358 the first (i.e. lowest addressed) legitimate alignment boundary
11359 (based upon the required minimum alignment for the declared
11360 type of the field) which it can possibly use, subject to the
11361 condition that there is still enough available space remaining
11362 in the containing object (when allocated at the selected point)
11363 to fully accommodate all of the bits of the bit-field itself.
11365 This simple rule makes it obvious why GCC allocates 8 bytes for
11366 each object of the structure type shown above. When looking
11367 for a place to allocate the "containing object" for `field2',
11368 the compiler simply tries to allocate a 64-bit "containing
11369 object" at each successive 32-bit boundary (starting at zero)
11370 until it finds a place to allocate that 64- bit field such that
11371 at least 31 contiguous (and previously unallocated) bits remain
11372 within that selected 64 bit field. (As it turns out, for the
11373 example above, the compiler finds it is OK to allocate the
11374 "containing object" 64-bit field at bit-offset zero within the
11377 Here we attempt to work backwards from the limited set of facts
11378 we're given, and we try to deduce from those facts, where GCC
11379 must have believed that the containing object started (within
11380 the structure type). The value we deduce is then used (by the
11381 callers of this routine) to generate DW_AT_location and
11382 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11383 the case of DW_AT_location, regular fields as well). */
11385 /* Figure out the bit-distance from the start of the structure to
11386 the "deepest" bit of the bit-field. */
11387 deepest_bitpos = bitpos_int + field_size_in_bits;
11389 /* This is the tricky part. Use some fancy footwork to deduce
11390 where the lowest addressed bit of the containing object must
11392 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11394 /* Round up to type_align by default. This works best for
11396 object_offset_in_bits
11397 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
11399 if (object_offset_in_bits > bitpos_int)
11401 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11403 /* Round up to decl_align instead. */
11404 object_offset_in_bits
11405 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
11410 object_offset_in_bits = bitpos_int;
11412 return object_offset_in_bits / BITS_PER_UNIT;
11415 /* The following routines define various Dwarf attributes and any data
11416 associated with them. */
11418 /* Add a location description attribute value to a DIE.
11420 This emits location attributes suitable for whole variables and
11421 whole parameters. Note that the location attributes for struct fields are
11422 generated by the routine `data_member_location_attribute' below. */
11425 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
11426 dw_loc_descr_ref descr)
11429 add_AT_loc (die, attr_kind, descr);
11432 /* Attach the specialized form of location attribute used for data members of
11433 struct and union types. In the special case of a FIELD_DECL node which
11434 represents a bit-field, the "offset" part of this special location
11435 descriptor must indicate the distance in bytes from the lowest-addressed
11436 byte of the containing struct or union type to the lowest-addressed byte of
11437 the "containing object" for the bit-field. (See the `field_byte_offset'
11440 For any given bit-field, the "containing object" is a hypothetical object
11441 (of some integral or enum type) within which the given bit-field lives. The
11442 type of this hypothetical "containing object" is always the same as the
11443 declared type of the individual bit-field itself (for GCC anyway... the
11444 DWARF spec doesn't actually mandate this). Note that it is the size (in
11445 bytes) of the hypothetical "containing object" which will be given in the
11446 DW_AT_byte_size attribute for this bit-field. (See the
11447 `byte_size_attribute' function below.) It is also used when calculating the
11448 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11449 function below.) */
11452 add_data_member_location_attribute (dw_die_ref die, tree decl)
11454 HOST_WIDE_INT offset;
11455 dw_loc_descr_ref loc_descr = 0;
11457 if (TREE_CODE (decl) == TREE_BINFO)
11459 /* We're working on the TAG_inheritance for a base class. */
11460 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11462 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11463 aren't at a fixed offset from all (sub)objects of the same
11464 type. We need to extract the appropriate offset from our
11465 vtable. The following dwarf expression means
11467 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11469 This is specific to the V3 ABI, of course. */
11471 dw_loc_descr_ref tmp;
11473 /* Make a copy of the object address. */
11474 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11475 add_loc_descr (&loc_descr, tmp);
11477 /* Extract the vtable address. */
11478 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11479 add_loc_descr (&loc_descr, tmp);
11481 /* Calculate the address of the offset. */
11482 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11483 gcc_assert (offset < 0);
11485 tmp = int_loc_descriptor (-offset);
11486 add_loc_descr (&loc_descr, tmp);
11487 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11488 add_loc_descr (&loc_descr, tmp);
11490 /* Extract the offset. */
11491 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11492 add_loc_descr (&loc_descr, tmp);
11494 /* Add it to the object address. */
11495 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11496 add_loc_descr (&loc_descr, tmp);
11499 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11502 offset = field_byte_offset (decl);
11506 if (dwarf_version > 2)
11508 /* Don't need to output a location expression, just the constant. */
11509 add_AT_int (die, DW_AT_data_member_location, offset);
11514 enum dwarf_location_atom op;
11516 /* The DWARF2 standard says that we should assume that the structure
11517 address is already on the stack, so we can specify a structure
11518 field address by using DW_OP_plus_uconst. */
11520 #ifdef MIPS_DEBUGGING_INFO
11521 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11522 operator correctly. It works only if we leave the offset on the
11526 op = DW_OP_plus_uconst;
11529 loc_descr = new_loc_descr (op, offset, 0);
11533 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11536 /* Writes integer values to dw_vec_const array. */
11539 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11543 *dest++ = val & 0xff;
11549 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11551 static HOST_WIDE_INT
11552 extract_int (const unsigned char *src, unsigned int size)
11554 HOST_WIDE_INT val = 0;
11560 val |= *--src & 0xff;
11566 /* Writes floating point values to dw_vec_const array. */
11569 insert_float (const_rtx rtl, unsigned char *array)
11571 REAL_VALUE_TYPE rv;
11575 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11576 real_to_target (val, &rv, GET_MODE (rtl));
11578 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11579 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11581 insert_int (val[i], 4, array);
11586 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11587 does not have a "location" either in memory or in a register. These
11588 things can arise in GNU C when a constant is passed as an actual parameter
11589 to an inlined function. They can also arise in C++ where declared
11590 constants do not necessarily get memory "homes". */
11593 add_const_value_attribute (dw_die_ref die, rtx rtl)
11595 switch (GET_CODE (rtl))
11599 HOST_WIDE_INT val = INTVAL (rtl);
11602 add_AT_int (die, DW_AT_const_value, val);
11604 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11609 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11610 floating-point constant. A CONST_DOUBLE is used whenever the
11611 constant requires more than one word in order to be adequately
11612 represented. We output CONST_DOUBLEs as blocks. */
11614 enum machine_mode mode = GET_MODE (rtl);
11616 if (SCALAR_FLOAT_MODE_P (mode))
11618 unsigned int length = GET_MODE_SIZE (mode);
11619 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11621 insert_float (rtl, array);
11622 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11626 /* ??? We really should be using HOST_WIDE_INT throughout. */
11627 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11629 add_AT_long_long (die, DW_AT_const_value,
11630 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11637 enum machine_mode mode = GET_MODE (rtl);
11638 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11639 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11640 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11644 switch (GET_MODE_CLASS (mode))
11646 case MODE_VECTOR_INT:
11647 for (i = 0, p = array; i < length; i++, p += elt_size)
11649 rtx elt = CONST_VECTOR_ELT (rtl, i);
11650 HOST_WIDE_INT lo, hi;
11652 switch (GET_CODE (elt))
11660 lo = CONST_DOUBLE_LOW (elt);
11661 hi = CONST_DOUBLE_HIGH (elt);
11665 gcc_unreachable ();
11668 if (elt_size <= sizeof (HOST_WIDE_INT))
11669 insert_int (lo, elt_size, p);
11672 unsigned char *p0 = p;
11673 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11675 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11676 if (WORDS_BIG_ENDIAN)
11681 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11682 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11687 case MODE_VECTOR_FLOAT:
11688 for (i = 0, p = array; i < length; i++, p += elt_size)
11690 rtx elt = CONST_VECTOR_ELT (rtl, i);
11691 insert_float (elt, p);
11696 gcc_unreachable ();
11699 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11704 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11710 add_AT_addr (die, DW_AT_const_value, rtl);
11711 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11715 /* In cases where an inlined instance of an inline function is passed
11716 the address of an `auto' variable (which is local to the caller) we
11717 can get a situation where the DECL_RTL of the artificial local
11718 variable (for the inlining) which acts as a stand-in for the
11719 corresponding formal parameter (of the inline function) will look
11720 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11721 exactly a compile-time constant expression, but it isn't the address
11722 of the (artificial) local variable either. Rather, it represents the
11723 *value* which the artificial local variable always has during its
11724 lifetime. We currently have no way to represent such quasi-constant
11725 values in Dwarf, so for now we just punt and generate nothing. */
11729 /* No other kinds of rtx should be possible here. */
11730 gcc_unreachable ();
11735 /* Determine whether the evaluation of EXPR references any variables
11736 or functions which aren't otherwise used (and therefore may not be
11739 reference_to_unused (tree * tp, int * walk_subtrees,
11740 void * data ATTRIBUTE_UNUSED)
11742 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11743 *walk_subtrees = 0;
11745 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11746 && ! TREE_ASM_WRITTEN (*tp))
11748 /* ??? The C++ FE emits debug information for using decls, so
11749 putting gcc_unreachable here falls over. See PR31899. For now
11750 be conservative. */
11751 else if (!cgraph_global_info_ready
11752 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11754 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11756 struct varpool_node *node = varpool_node (*tp);
11760 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11761 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11763 struct cgraph_node *node = cgraph_node (*tp);
11764 if (node->process || TREE_ASM_WRITTEN (*tp))
11767 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11773 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11774 for use in a later add_const_value_attribute call. */
11777 rtl_for_decl_init (tree init, tree type)
11779 rtx rtl = NULL_RTX;
11781 /* If a variable is initialized with a string constant without embedded
11782 zeros, build CONST_STRING. */
11783 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11785 tree enttype = TREE_TYPE (type);
11786 tree domain = TYPE_DOMAIN (type);
11787 enum machine_mode mode = TYPE_MODE (enttype);
11789 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11791 && integer_zerop (TYPE_MIN_VALUE (domain))
11792 && compare_tree_int (TYPE_MAX_VALUE (domain),
11793 TREE_STRING_LENGTH (init) - 1) == 0
11794 && ((size_t) TREE_STRING_LENGTH (init)
11795 == strlen (TREE_STRING_POINTER (init)) + 1))
11796 rtl = gen_rtx_CONST_STRING (VOIDmode,
11797 ggc_strdup (TREE_STRING_POINTER (init)));
11799 /* Other aggregates, and complex values, could be represented using
11801 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11803 /* Vectors only work if their mode is supported by the target.
11804 FIXME: generic vectors ought to work too. */
11805 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11807 /* If the initializer is something that we know will expand into an
11808 immediate RTL constant, expand it now. We must be careful not to
11809 reference variables which won't be output. */
11810 else if (initializer_constant_valid_p (init, type)
11811 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11813 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11815 if (TREE_CODE (type) == VECTOR_TYPE)
11816 switch (TREE_CODE (init))
11821 if (TREE_CONSTANT (init))
11823 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11824 bool constant_p = true;
11826 unsigned HOST_WIDE_INT ix;
11828 /* Even when ctor is constant, it might contain non-*_CST
11829 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11830 belong into VECTOR_CST nodes. */
11831 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11832 if (!CONSTANT_CLASS_P (value))
11834 constant_p = false;
11840 init = build_vector_from_ctor (type, elts);
11850 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11852 /* If expand_expr returns a MEM, it wasn't immediate. */
11853 gcc_assert (!rtl || !MEM_P (rtl));
11859 /* Generate RTL for the variable DECL to represent its location. */
11862 rtl_for_decl_location (tree decl)
11866 /* Here we have to decide where we are going to say the parameter "lives"
11867 (as far as the debugger is concerned). We only have a couple of
11868 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11870 DECL_RTL normally indicates where the parameter lives during most of the
11871 activation of the function. If optimization is enabled however, this
11872 could be either NULL or else a pseudo-reg. Both of those cases indicate
11873 that the parameter doesn't really live anywhere (as far as the code
11874 generation parts of GCC are concerned) during most of the function's
11875 activation. That will happen (for example) if the parameter is never
11876 referenced within the function.
11878 We could just generate a location descriptor here for all non-NULL
11879 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11880 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11881 where DECL_RTL is NULL or is a pseudo-reg.
11883 Note however that we can only get away with using DECL_INCOMING_RTL as
11884 a backup substitute for DECL_RTL in certain limited cases. In cases
11885 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11886 we can be sure that the parameter was passed using the same type as it is
11887 declared to have within the function, and that its DECL_INCOMING_RTL
11888 points us to a place where a value of that type is passed.
11890 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11891 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11892 because in these cases DECL_INCOMING_RTL points us to a value of some
11893 type which is *different* from the type of the parameter itself. Thus,
11894 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11895 such cases, the debugger would end up (for example) trying to fetch a
11896 `float' from a place which actually contains the first part of a
11897 `double'. That would lead to really incorrect and confusing
11898 output at debug-time.
11900 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11901 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11902 are a couple of exceptions however. On little-endian machines we can
11903 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11904 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11905 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11906 when (on a little-endian machine) a non-prototyped function has a
11907 parameter declared to be of type `short' or `char'. In such cases,
11908 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11909 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11910 passed `int' value. If the debugger then uses that address to fetch
11911 a `short' or a `char' (on a little-endian machine) the result will be
11912 the correct data, so we allow for such exceptional cases below.
11914 Note that our goal here is to describe the place where the given formal
11915 parameter lives during most of the function's activation (i.e. between the
11916 end of the prologue and the start of the epilogue). We'll do that as best
11917 as we can. Note however that if the given formal parameter is modified
11918 sometime during the execution of the function, then a stack backtrace (at
11919 debug-time) will show the function as having been called with the *new*
11920 value rather than the value which was originally passed in. This happens
11921 rarely enough that it is not a major problem, but it *is* a problem, and
11922 I'd like to fix it.
11924 A future version of dwarf2out.c may generate two additional attributes for
11925 any given DW_TAG_formal_parameter DIE which will describe the "passed
11926 type" and the "passed location" for the given formal parameter in addition
11927 to the attributes we now generate to indicate the "declared type" and the
11928 "active location" for each parameter. This additional set of attributes
11929 could be used by debuggers for stack backtraces. Separately, note that
11930 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11931 This happens (for example) for inlined-instances of inline function formal
11932 parameters which are never referenced. This really shouldn't be
11933 happening. All PARM_DECL nodes should get valid non-NULL
11934 DECL_INCOMING_RTL values. FIXME. */
11936 /* Use DECL_RTL as the "location" unless we find something better. */
11937 rtl = DECL_RTL_IF_SET (decl);
11939 /* When generating abstract instances, ignore everything except
11940 constants, symbols living in memory, and symbols living in
11941 fixed registers. */
11942 if (! reload_completed)
11945 && (CONSTANT_P (rtl)
11947 && CONSTANT_P (XEXP (rtl, 0)))
11949 && TREE_CODE (decl) == VAR_DECL
11950 && TREE_STATIC (decl))))
11952 rtl = targetm.delegitimize_address (rtl);
11957 else if (TREE_CODE (decl) == PARM_DECL)
11959 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11961 tree declared_type = TREE_TYPE (decl);
11962 tree passed_type = DECL_ARG_TYPE (decl);
11963 enum machine_mode dmode = TYPE_MODE (declared_type);
11964 enum machine_mode pmode = TYPE_MODE (passed_type);
11966 /* This decl represents a formal parameter which was optimized out.
11967 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11968 all cases where (rtl == NULL_RTX) just below. */
11969 if (dmode == pmode)
11970 rtl = DECL_INCOMING_RTL (decl);
11971 else if (SCALAR_INT_MODE_P (dmode)
11972 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11973 && DECL_INCOMING_RTL (decl))
11975 rtx inc = DECL_INCOMING_RTL (decl);
11978 else if (MEM_P (inc))
11980 if (BYTES_BIG_ENDIAN)
11981 rtl = adjust_address_nv (inc, dmode,
11982 GET_MODE_SIZE (pmode)
11983 - GET_MODE_SIZE (dmode));
11990 /* If the parm was passed in registers, but lives on the stack, then
11991 make a big endian correction if the mode of the type of the
11992 parameter is not the same as the mode of the rtl. */
11993 /* ??? This is the same series of checks that are made in dbxout.c before
11994 we reach the big endian correction code there. It isn't clear if all
11995 of these checks are necessary here, but keeping them all is the safe
11997 else if (MEM_P (rtl)
11998 && XEXP (rtl, 0) != const0_rtx
11999 && ! CONSTANT_P (XEXP (rtl, 0))
12000 /* Not passed in memory. */
12001 && !MEM_P (DECL_INCOMING_RTL (decl))
12002 /* Not passed by invisible reference. */
12003 && (!REG_P (XEXP (rtl, 0))
12004 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
12005 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
12006 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
12007 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
12010 /* Big endian correction check. */
12011 && BYTES_BIG_ENDIAN
12012 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
12013 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
12016 int offset = (UNITS_PER_WORD
12017 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
12019 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
12020 plus_constant (XEXP (rtl, 0), offset));
12023 else if (TREE_CODE (decl) == VAR_DECL
12026 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
12027 && BYTES_BIG_ENDIAN)
12029 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
12030 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
12032 /* If a variable is declared "register" yet is smaller than
12033 a register, then if we store the variable to memory, it
12034 looks like we're storing a register-sized value, when in
12035 fact we are not. We need to adjust the offset of the
12036 storage location to reflect the actual value's bytes,
12037 else gdb will not be able to display it. */
12039 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
12040 plus_constant (XEXP (rtl, 0), rsize-dsize));
12043 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
12044 and will have been substituted directly into all expressions that use it.
12045 C does not have such a concept, but C++ and other languages do. */
12046 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
12047 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
12050 rtl = targetm.delegitimize_address (rtl);
12052 /* If we don't look past the constant pool, we risk emitting a
12053 reference to a constant pool entry that isn't referenced from
12054 code, and thus is not emitted. */
12056 rtl = avoid_constant_pool_reference (rtl);
12061 /* We need to figure out what section we should use as the base for the
12062 address ranges where a given location is valid.
12063 1. If this particular DECL has a section associated with it, use that.
12064 2. If this function has a section associated with it, use that.
12065 3. Otherwise, use the text section.
12066 XXX: If you split a variable across multiple sections, we won't notice. */
12068 static const char *
12069 secname_for_decl (const_tree decl)
12071 const char *secname;
12073 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12075 tree sectree = DECL_SECTION_NAME (decl);
12076 secname = TREE_STRING_POINTER (sectree);
12078 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12080 tree sectree = DECL_SECTION_NAME (current_function_decl);
12081 secname = TREE_STRING_POINTER (sectree);
12083 else if (cfun && in_cold_section_p)
12084 secname = crtl->subsections.cold_section_label;
12086 secname = text_section_label;
12091 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
12092 returned. If so, the decl for the COMMON block is returned, and the
12093 value is the offset into the common block for the symbol. */
12096 fortran_common (tree decl, HOST_WIDE_INT *value)
12098 tree val_expr, cvar;
12099 enum machine_mode mode;
12100 HOST_WIDE_INT bitsize, bitpos;
12102 int volatilep = 0, unsignedp = 0;
12104 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
12105 it does not have a value (the offset into the common area), or if it
12106 is thread local (as opposed to global) then it isn't common, and shouldn't
12107 be handled as such. */
12108 if (TREE_CODE (decl) != VAR_DECL
12109 || !TREE_PUBLIC (decl)
12110 || !TREE_STATIC (decl)
12111 || !DECL_HAS_VALUE_EXPR_P (decl)
12115 val_expr = DECL_VALUE_EXPR (decl);
12116 if (TREE_CODE (val_expr) != COMPONENT_REF)
12119 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
12120 &mode, &unsignedp, &volatilep, true);
12122 if (cvar == NULL_TREE
12123 || TREE_CODE (cvar) != VAR_DECL
12124 || DECL_ARTIFICIAL (cvar)
12125 || !TREE_PUBLIC (cvar))
12129 if (offset != NULL)
12131 if (!host_integerp (offset, 0))
12133 *value = tree_low_cst (offset, 0);
12136 *value += bitpos / BITS_PER_UNIT;
12141 /* Dereference a location expression LOC if DECL is passed by invisible
12144 static dw_loc_descr_ref
12145 loc_by_reference (dw_loc_descr_ref loc, tree decl)
12147 HOST_WIDE_INT size;
12148 enum dwarf_location_atom op;
12153 if ((TREE_CODE (decl) != PARM_DECL
12154 && TREE_CODE (decl) != RESULT_DECL
12155 && TREE_CODE (decl) != VAR_DECL)
12156 || !DECL_BY_REFERENCE (decl))
12159 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12160 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12161 location expression is considered to be address of a memory location,
12162 rather than the register itself. */
12163 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
12164 || loc->dw_loc_opc == DW_OP_regx)
12165 && (loc->dw_loc_next == NULL
12166 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
12167 && loc->dw_loc_next->dw_loc_next == NULL)))
12169 if (loc->dw_loc_opc == DW_OP_regx)
12171 loc->dw_loc_opc = DW_OP_bregx;
12172 loc->dw_loc_oprnd2.v.val_int = 0;
12177 = (enum dwarf_location_atom)
12178 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12179 loc->dw_loc_oprnd1.v.val_int = 0;
12184 size = int_size_in_bytes (TREE_TYPE (decl));
12185 if (size > DWARF2_ADDR_SIZE || size == -1)
12187 else if (size == DWARF2_ADDR_SIZE)
12190 op = DW_OP_deref_size;
12191 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12195 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
12196 data attribute for a variable or a parameter. We generate the
12197 DW_AT_const_value attribute only in those cases where the given variable
12198 or parameter does not have a true "location" either in memory or in a
12199 register. This can happen (for example) when a constant is passed as an
12200 actual argument in a call to an inline function. (It's possible that
12201 these things can crop up in other ways also.) Note that one type of
12202 constant value which can be passed into an inlined function is a constant
12203 pointer. This can happen for example if an actual argument in an inlined
12204 function call evaluates to a compile-time constant address. */
12207 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
12208 enum dwarf_attribute attr)
12211 dw_loc_descr_ref descr;
12212 var_loc_list *loc_list;
12213 struct var_loc_node *node;
12214 if (TREE_CODE (decl) == ERROR_MARK)
12217 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
12218 || TREE_CODE (decl) == RESULT_DECL);
12220 /* See if we possibly have multiple locations for this variable. */
12221 loc_list = lookup_decl_loc (decl);
12223 /* If it truly has multiple locations, the first and last node will
12225 if (loc_list && loc_list->first != loc_list->last)
12227 const char *endname, *secname;
12228 dw_loc_list_ref list;
12230 enum var_init_status initialized;
12232 /* Now that we know what section we are using for a base,
12233 actually construct the list of locations.
12234 The first location information is what is passed to the
12235 function that creates the location list, and the remaining
12236 locations just get added on to that list.
12237 Note that we only know the start address for a location
12238 (IE location changes), so to build the range, we use
12239 the range [current location start, next location start].
12240 This means we have to special case the last node, and generate
12241 a range of [last location start, end of function label]. */
12243 node = loc_list->first;
12244 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12245 secname = secname_for_decl (decl);
12247 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12248 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12250 initialized = VAR_INIT_STATUS_INITIALIZED;
12252 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
12253 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12256 for (; node->next; node = node->next)
12257 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12259 /* The variable has a location between NODE->LABEL and
12260 NODE->NEXT->LABEL. */
12261 enum var_init_status initialized =
12262 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12263 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12264 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12266 add_loc_descr_to_loc_list (&list, descr,
12267 node->label, node->next->label, secname);
12270 /* If the variable has a location at the last label
12271 it keeps its location until the end of function. */
12272 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12274 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12275 enum var_init_status initialized =
12276 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12278 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12279 if (!current_function_decl)
12280 endname = text_end_label;
12283 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12284 current_function_funcdef_no);
12285 endname = ggc_strdup (label_id);
12287 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12289 add_loc_descr_to_loc_list (&list, descr,
12290 node->label, endname, secname);
12293 /* Finally, add the location list to the DIE, and we are done. */
12294 add_AT_loc_list (die, attr, list);
12298 /* Try to get some constant RTL for this decl, and use that as the value of
12301 rtl = rtl_for_decl_location (decl);
12302 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
12304 add_const_value_attribute (die, rtl);
12308 /* If we have tried to generate the location otherwise, and it
12309 didn't work out (we wouldn't be here if we did), and we have a one entry
12310 location list, try generating a location from that. */
12311 if (loc_list && loc_list->first)
12313 enum var_init_status status;
12314 node = loc_list->first;
12315 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12316 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
12319 descr = loc_by_reference (descr, decl);
12320 add_AT_location_description (die, attr, descr);
12325 /* We couldn't get any rtl, so try directly generating the location
12326 description from the tree. */
12327 descr = loc_descriptor_from_tree (decl);
12330 descr = loc_by_reference (descr, decl);
12331 add_AT_location_description (die, attr, descr);
12334 /* None of that worked, so it must not really have a location;
12335 try adding a constant value attribute from the DECL_INITIAL. */
12336 tree_add_const_value_attribute (die, decl);
12339 /* Add VARIABLE and DIE into deferred locations list. */
12342 defer_location (tree variable, dw_die_ref die)
12344 deferred_locations entry;
12345 entry.variable = variable;
12347 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
12350 /* Helper function for tree_add_const_value_attribute. Natively encode
12351 initializer INIT into an array. Return true if successful. */
12354 native_encode_initializer (tree init, unsigned char *array, int size)
12358 if (init == NULL_TREE)
12362 switch (TREE_CODE (init))
12365 type = TREE_TYPE (init);
12366 if (TREE_CODE (type) == ARRAY_TYPE)
12368 tree enttype = TREE_TYPE (type);
12369 enum machine_mode mode = TYPE_MODE (enttype);
12371 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
12373 if (int_size_in_bytes (type) != size)
12375 if (size > TREE_STRING_LENGTH (init))
12377 memcpy (array, TREE_STRING_POINTER (init),
12378 TREE_STRING_LENGTH (init));
12379 memset (array + TREE_STRING_LENGTH (init),
12380 '\0', size - TREE_STRING_LENGTH (init));
12383 memcpy (array, TREE_STRING_POINTER (init), size);
12388 type = TREE_TYPE (init);
12389 if (int_size_in_bytes (type) != size)
12391 if (TREE_CODE (type) == ARRAY_TYPE)
12393 HOST_WIDE_INT min_index;
12394 unsigned HOST_WIDE_INT cnt;
12395 int curpos = 0, fieldsize;
12396 constructor_elt *ce;
12398 if (TYPE_DOMAIN (type) == NULL_TREE
12399 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
12402 fieldsize = int_size_in_bytes (TREE_TYPE (type));
12403 if (fieldsize <= 0)
12406 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
12407 memset (array, '\0', size);
12409 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12412 tree val = ce->value;
12413 tree index = ce->index;
12415 if (index && TREE_CODE (index) == RANGE_EXPR)
12416 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
12419 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
12424 if (!native_encode_initializer (val, array + pos, fieldsize))
12427 curpos = pos + fieldsize;
12428 if (index && TREE_CODE (index) == RANGE_EXPR)
12430 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
12431 - tree_low_cst (TREE_OPERAND (index, 0), 0);
12435 memcpy (array + curpos, array + pos, fieldsize);
12436 curpos += fieldsize;
12439 gcc_assert (curpos <= size);
12443 else if (TREE_CODE (type) == RECORD_TYPE
12444 || TREE_CODE (type) == UNION_TYPE)
12446 tree field = NULL_TREE;
12447 unsigned HOST_WIDE_INT cnt;
12448 constructor_elt *ce;
12450 if (int_size_in_bytes (type) != size)
12453 if (TREE_CODE (type) == RECORD_TYPE)
12454 field = TYPE_FIELDS (type);
12457 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12458 cnt++, field = field ? TREE_CHAIN (field) : 0)
12460 tree val = ce->value;
12461 int pos, fieldsize;
12463 if (ce->index != 0)
12469 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12472 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12473 && TYPE_DOMAIN (TREE_TYPE (field))
12474 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12476 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12477 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12479 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12480 pos = int_byte_position (field);
12481 gcc_assert (pos + fieldsize <= size);
12483 && !native_encode_initializer (val, array + pos, fieldsize))
12489 case VIEW_CONVERT_EXPR:
12490 case NON_LVALUE_EXPR:
12491 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12493 return native_encode_expr (init, array, size) == size;
12497 /* If we don't have a copy of this variable in memory for some reason (such
12498 as a C++ member constant that doesn't have an out-of-line definition),
12499 we should tell the debugger about the constant value. */
12502 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12505 tree type = TREE_TYPE (decl);
12508 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12511 init = DECL_INITIAL (decl);
12512 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12517 rtl = rtl_for_decl_init (init, type);
12519 add_const_value_attribute (var_die, rtl);
12520 /* If the host and target are sane, try harder. */
12521 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12522 && initializer_constant_valid_p (init, type))
12524 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12525 if (size > 0 && (int) size == size)
12527 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12529 if (native_encode_initializer (init, array, size))
12530 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12535 /* Convert the CFI instructions for the current function into a
12536 location list. This is used for DW_AT_frame_base when we targeting
12537 a dwarf2 consumer that does not support the dwarf3
12538 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12541 static dw_loc_list_ref
12542 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12545 dw_loc_list_ref list, *list_tail;
12547 dw_cfa_location last_cfa, next_cfa;
12548 const char *start_label, *last_label, *section;
12549 dw_cfa_location remember;
12551 fde = current_fde ();
12552 gcc_assert (fde != NULL);
12554 section = secname_for_decl (current_function_decl);
12558 memset (&next_cfa, 0, sizeof (next_cfa));
12559 next_cfa.reg = INVALID_REGNUM;
12560 remember = next_cfa;
12562 start_label = fde->dw_fde_begin;
12564 /* ??? Bald assumption that the CIE opcode list does not contain
12565 advance opcodes. */
12566 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12567 lookup_cfa_1 (cfi, &next_cfa, &remember);
12569 last_cfa = next_cfa;
12570 last_label = start_label;
12572 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12573 switch (cfi->dw_cfi_opc)
12575 case DW_CFA_set_loc:
12576 case DW_CFA_advance_loc1:
12577 case DW_CFA_advance_loc2:
12578 case DW_CFA_advance_loc4:
12579 if (!cfa_equal_p (&last_cfa, &next_cfa))
12581 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12582 start_label, last_label, section,
12585 list_tail = &(*list_tail)->dw_loc_next;
12586 last_cfa = next_cfa;
12587 start_label = last_label;
12589 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12592 case DW_CFA_advance_loc:
12593 /* The encoding is complex enough that we should never emit this. */
12594 gcc_unreachable ();
12597 lookup_cfa_1 (cfi, &next_cfa, &remember);
12601 if (!cfa_equal_p (&last_cfa, &next_cfa))
12603 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12604 start_label, last_label, section,
12606 list_tail = &(*list_tail)->dw_loc_next;
12607 start_label = last_label;
12609 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12610 start_label, fde->dw_fde_end, section,
12616 /* Compute a displacement from the "steady-state frame pointer" to the
12617 frame base (often the same as the CFA), and store it in
12618 frame_pointer_fb_offset. OFFSET is added to the displacement
12619 before the latter is negated. */
12622 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12626 #ifdef FRAME_POINTER_CFA_OFFSET
12627 reg = frame_pointer_rtx;
12628 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12630 reg = arg_pointer_rtx;
12631 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12634 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12635 if (GET_CODE (elim) == PLUS)
12637 offset += INTVAL (XEXP (elim, 1));
12638 elim = XEXP (elim, 0);
12641 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12642 && (elim == hard_frame_pointer_rtx
12643 || elim == stack_pointer_rtx))
12644 || elim == (frame_pointer_needed
12645 ? hard_frame_pointer_rtx
12646 : stack_pointer_rtx));
12648 frame_pointer_fb_offset = -offset;
12651 /* Generate a DW_AT_name attribute given some string value to be included as
12652 the value of the attribute. */
12655 add_name_attribute (dw_die_ref die, const char *name_string)
12657 if (name_string != NULL && *name_string != 0)
12659 if (demangle_name_func)
12660 name_string = (*demangle_name_func) (name_string);
12662 add_AT_string (die, DW_AT_name, name_string);
12666 /* Generate a DW_AT_comp_dir attribute for DIE. */
12669 add_comp_dir_attribute (dw_die_ref die)
12671 const char *wd = get_src_pwd ();
12673 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12676 /* Given a tree node describing an array bound (either lower or upper) output
12677 a representation for that bound. */
12680 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12682 switch (TREE_CODE (bound))
12687 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12689 if (! host_integerp (bound, 0)
12690 || (bound_attr == DW_AT_lower_bound
12691 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12692 || (is_fortran () && integer_onep (bound)))))
12693 /* Use the default. */
12696 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12700 case VIEW_CONVERT_EXPR:
12701 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
12711 dw_die_ref decl_die = lookup_decl_die (bound);
12712 dw_loc_descr_ref loc;
12714 /* ??? Can this happen, or should the variable have been bound
12715 first? Probably it can, since I imagine that we try to create
12716 the types of parameters in the order in which they exist in
12717 the list, and won't have created a forward reference to a
12718 later parameter. */
12719 if (decl_die != NULL)
12720 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12723 loc = loc_descriptor_from_tree_1 (bound, 0);
12724 add_AT_location_description (subrange_die, bound_attr, loc);
12731 /* Otherwise try to create a stack operation procedure to
12732 evaluate the value of the array bound. */
12734 dw_die_ref ctx, decl_die;
12735 dw_loc_descr_ref loc;
12737 loc = loc_descriptor_from_tree (bound);
12741 if (current_function_decl == 0)
12742 ctx = comp_unit_die;
12744 ctx = lookup_decl_die (current_function_decl);
12746 decl_die = new_die (DW_TAG_variable, ctx, bound);
12747 add_AT_flag (decl_die, DW_AT_artificial, 1);
12748 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12749 add_AT_loc (decl_die, DW_AT_location, loc);
12751 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12757 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12758 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12759 Note that the block of subscript information for an array type also
12760 includes information about the element type of the given array type. */
12763 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12765 unsigned dimension_number;
12767 dw_die_ref subrange_die;
12769 for (dimension_number = 0;
12770 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12771 type = TREE_TYPE (type), dimension_number++)
12773 tree domain = TYPE_DOMAIN (type);
12775 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12778 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12779 and (in GNU C only) variable bounds. Handle all three forms
12781 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12784 /* We have an array type with specified bounds. */
12785 lower = TYPE_MIN_VALUE (domain);
12786 upper = TYPE_MAX_VALUE (domain);
12788 /* Define the index type. */
12789 if (TREE_TYPE (domain))
12791 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12792 TREE_TYPE field. We can't emit debug info for this
12793 because it is an unnamed integral type. */
12794 if (TREE_CODE (domain) == INTEGER_TYPE
12795 && TYPE_NAME (domain) == NULL_TREE
12796 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12797 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12800 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12804 /* ??? If upper is NULL, the array has unspecified length,
12805 but it does have a lower bound. This happens with Fortran
12807 Since the debugger is definitely going to need to know N
12808 to produce useful results, go ahead and output the lower
12809 bound solo, and hope the debugger can cope. */
12811 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12813 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12816 /* Otherwise we have an array type with an unspecified length. The
12817 DWARF-2 spec does not say how to handle this; let's just leave out the
12823 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12827 switch (TREE_CODE (tree_node))
12832 case ENUMERAL_TYPE:
12835 case QUAL_UNION_TYPE:
12836 size = int_size_in_bytes (tree_node);
12839 /* For a data member of a struct or union, the DW_AT_byte_size is
12840 generally given as the number of bytes normally allocated for an
12841 object of the *declared* type of the member itself. This is true
12842 even for bit-fields. */
12843 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12846 gcc_unreachable ();
12849 /* Note that `size' might be -1 when we get to this point. If it is, that
12850 indicates that the byte size of the entity in question is variable. We
12851 have no good way of expressing this fact in Dwarf at the present time,
12852 so just let the -1 pass on through. */
12853 add_AT_unsigned (die, DW_AT_byte_size, size);
12856 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12857 which specifies the distance in bits from the highest order bit of the
12858 "containing object" for the bit-field to the highest order bit of the
12861 For any given bit-field, the "containing object" is a hypothetical object
12862 (of some integral or enum type) within which the given bit-field lives. The
12863 type of this hypothetical "containing object" is always the same as the
12864 declared type of the individual bit-field itself. The determination of the
12865 exact location of the "containing object" for a bit-field is rather
12866 complicated. It's handled by the `field_byte_offset' function (above).
12868 Note that it is the size (in bytes) of the hypothetical "containing object"
12869 which will be given in the DW_AT_byte_size attribute for this bit-field.
12870 (See `byte_size_attribute' above). */
12873 add_bit_offset_attribute (dw_die_ref die, tree decl)
12875 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12876 tree type = DECL_BIT_FIELD_TYPE (decl);
12877 HOST_WIDE_INT bitpos_int;
12878 HOST_WIDE_INT highest_order_object_bit_offset;
12879 HOST_WIDE_INT highest_order_field_bit_offset;
12880 HOST_WIDE_INT unsigned bit_offset;
12882 /* Must be a field and a bit field. */
12883 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12885 /* We can't yet handle bit-fields whose offsets are variable, so if we
12886 encounter such things, just return without generating any attribute
12887 whatsoever. Likewise for variable or too large size. */
12888 if (! host_integerp (bit_position (decl), 0)
12889 || ! host_integerp (DECL_SIZE (decl), 1))
12892 bitpos_int = int_bit_position (decl);
12894 /* Note that the bit offset is always the distance (in bits) from the
12895 highest-order bit of the "containing object" to the highest-order bit of
12896 the bit-field itself. Since the "high-order end" of any object or field
12897 is different on big-endian and little-endian machines, the computation
12898 below must take account of these differences. */
12899 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12900 highest_order_field_bit_offset = bitpos_int;
12902 if (! BYTES_BIG_ENDIAN)
12904 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12905 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12909 = (! BYTES_BIG_ENDIAN
12910 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12911 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12913 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12916 /* For a FIELD_DECL node which represents a bit field, output an attribute
12917 which specifies the length in bits of the given field. */
12920 add_bit_size_attribute (dw_die_ref die, tree decl)
12922 /* Must be a field and a bit field. */
12923 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12924 && DECL_BIT_FIELD_TYPE (decl));
12926 if (host_integerp (DECL_SIZE (decl), 1))
12927 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12930 /* If the compiled language is ANSI C, then add a 'prototyped'
12931 attribute, if arg types are given for the parameters of a function. */
12934 add_prototyped_attribute (dw_die_ref die, tree func_type)
12936 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12937 && TYPE_ARG_TYPES (func_type) != NULL)
12938 add_AT_flag (die, DW_AT_prototyped, 1);
12941 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12942 by looking in either the type declaration or object declaration
12945 static inline dw_die_ref
12946 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12948 dw_die_ref origin_die = NULL;
12950 if (TREE_CODE (origin) != FUNCTION_DECL)
12952 /* We may have gotten separated from the block for the inlined
12953 function, if we're in an exception handler or some such; make
12954 sure that the abstract function has been written out.
12956 Doing this for nested functions is wrong, however; functions are
12957 distinct units, and our context might not even be inline. */
12961 fn = TYPE_STUB_DECL (fn);
12963 fn = decl_function_context (fn);
12965 dwarf2out_abstract_function (fn);
12968 if (DECL_P (origin))
12969 origin_die = lookup_decl_die (origin);
12970 else if (TYPE_P (origin))
12971 origin_die = lookup_type_die (origin);
12973 /* XXX: Functions that are never lowered don't always have correct block
12974 trees (in the case of java, they simply have no block tree, in some other
12975 languages). For these functions, there is nothing we can really do to
12976 output correct debug info for inlined functions in all cases. Rather
12977 than die, we'll just produce deficient debug info now, in that we will
12978 have variables without a proper abstract origin. In the future, when all
12979 functions are lowered, we should re-add a gcc_assert (origin_die)
12983 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12987 /* We do not currently support the pure_virtual attribute. */
12990 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12992 if (DECL_VINDEX (func_decl))
12994 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12996 if (host_integerp (DECL_VINDEX (func_decl), 0))
12997 add_AT_loc (die, DW_AT_vtable_elem_location,
12998 new_loc_descr (DW_OP_constu,
12999 tree_low_cst (DECL_VINDEX (func_decl), 0),
13002 /* GNU extension: Record what type this method came from originally. */
13003 if (debug_info_level > DINFO_LEVEL_TERSE)
13004 add_AT_die_ref (die, DW_AT_containing_type,
13005 lookup_type_die (DECL_CONTEXT (func_decl)));
13009 /* Add source coordinate attributes for the given decl. */
13012 add_src_coords_attributes (dw_die_ref die, tree decl)
13014 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13016 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
13017 add_AT_unsigned (die, DW_AT_decl_line, s.line);
13020 /* Add a DW_AT_name attribute and source coordinate attribute for the
13021 given decl, but only if it actually has a name. */
13024 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
13028 decl_name = DECL_NAME (decl);
13029 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
13031 add_name_attribute (die, dwarf2_name (decl, 0));
13032 if (! DECL_ARTIFICIAL (decl))
13033 add_src_coords_attributes (die, decl);
13035 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
13036 && TREE_PUBLIC (decl)
13037 && !DECL_ABSTRACT (decl)
13038 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
13041 /* Defer until we have an assembler name set. */
13042 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
13044 limbo_die_node *asm_name;
13046 asm_name = GGC_CNEW (limbo_die_node);
13047 asm_name->die = die;
13048 asm_name->created_for = decl;
13049 asm_name->next = deferred_asm_name;
13050 deferred_asm_name = asm_name;
13052 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
13053 add_AT_string (die, DW_AT_MIPS_linkage_name,
13054 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
13058 #ifdef VMS_DEBUGGING_INFO
13059 /* Get the function's name, as described by its RTL. This may be different
13060 from the DECL_NAME name used in the source file. */
13061 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
13063 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
13064 XEXP (DECL_RTL (decl), 0));
13065 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
13070 /* Push a new declaration scope. */
13073 push_decl_scope (tree scope)
13075 VEC_safe_push (tree, gc, decl_scope_table, scope);
13078 /* Pop a declaration scope. */
13081 pop_decl_scope (void)
13083 VEC_pop (tree, decl_scope_table);
13086 /* Return the DIE for the scope that immediately contains this type.
13087 Non-named types get global scope. Named types nested in other
13088 types get their containing scope if it's open, or global scope
13089 otherwise. All other types (i.e. function-local named types) get
13090 the current active scope. */
13093 scope_die_for (tree t, dw_die_ref context_die)
13095 dw_die_ref scope_die = NULL;
13096 tree containing_scope;
13099 /* Non-types always go in the current scope. */
13100 gcc_assert (TYPE_P (t));
13102 containing_scope = TYPE_CONTEXT (t);
13104 /* Use the containing namespace if it was passed in (for a declaration). */
13105 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
13107 if (context_die == lookup_decl_die (containing_scope))
13110 containing_scope = NULL_TREE;
13113 /* Ignore function type "scopes" from the C frontend. They mean that
13114 a tagged type is local to a parmlist of a function declarator, but
13115 that isn't useful to DWARF. */
13116 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
13117 containing_scope = NULL_TREE;
13119 if (containing_scope == NULL_TREE)
13120 scope_die = comp_unit_die;
13121 else if (TYPE_P (containing_scope))
13123 /* For types, we can just look up the appropriate DIE. But
13124 first we check to see if we're in the middle of emitting it
13125 so we know where the new DIE should go. */
13126 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
13127 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
13132 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
13133 || TREE_ASM_WRITTEN (containing_scope));
13135 /* If none of the current dies are suitable, we get file scope. */
13136 scope_die = comp_unit_die;
13139 scope_die = lookup_type_die (containing_scope);
13142 scope_die = context_die;
13147 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
13150 local_scope_p (dw_die_ref context_die)
13152 for (; context_die; context_die = context_die->die_parent)
13153 if (context_die->die_tag == DW_TAG_inlined_subroutine
13154 || context_die->die_tag == DW_TAG_subprogram)
13160 /* Returns nonzero if CONTEXT_DIE is a class. */
13163 class_scope_p (dw_die_ref context_die)
13165 return (context_die
13166 && (context_die->die_tag == DW_TAG_structure_type
13167 || context_die->die_tag == DW_TAG_class_type
13168 || context_die->die_tag == DW_TAG_interface_type
13169 || context_die->die_tag == DW_TAG_union_type));
13172 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
13173 whether or not to treat a DIE in this context as a declaration. */
13176 class_or_namespace_scope_p (dw_die_ref context_die)
13178 return (class_scope_p (context_die)
13179 || (context_die && context_die->die_tag == DW_TAG_namespace));
13182 /* Many forms of DIEs require a "type description" attribute. This
13183 routine locates the proper "type descriptor" die for the type given
13184 by 'type', and adds a DW_AT_type attribute below the given die. */
13187 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
13188 int decl_volatile, dw_die_ref context_die)
13190 enum tree_code code = TREE_CODE (type);
13191 dw_die_ref type_die = NULL;
13193 /* ??? If this type is an unnamed subrange type of an integral, floating-point
13194 or fixed-point type, use the inner type. This is because we have no
13195 support for unnamed types in base_type_die. This can happen if this is
13196 an Ada subrange type. Correct solution is emit a subrange type die. */
13197 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
13198 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
13199 type = TREE_TYPE (type), code = TREE_CODE (type);
13201 if (code == ERROR_MARK
13202 /* Handle a special case. For functions whose return type is void, we
13203 generate *no* type attribute. (Note that no object may have type
13204 `void', so this only applies to function return types). */
13205 || code == VOID_TYPE)
13208 type_die = modified_type_die (type,
13209 decl_const || TYPE_READONLY (type),
13210 decl_volatile || TYPE_VOLATILE (type),
13213 if (type_die != NULL)
13214 add_AT_die_ref (object_die, DW_AT_type, type_die);
13217 /* Given an object die, add the calling convention attribute for the
13218 function call type. */
13220 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
13222 enum dwarf_calling_convention value = DW_CC_normal;
13224 value = ((enum dwarf_calling_convention)
13225 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
13227 /* DWARF doesn't provide a way to identify a program's source-level
13228 entry point. DW_AT_calling_convention attributes are only meant
13229 to describe functions' calling conventions. However, lacking a
13230 better way to signal the Fortran main program, we use this for the
13231 time being, following existing custom. */
13233 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
13234 value = DW_CC_program;
13236 /* Only add the attribute if the backend requests it, and
13237 is not DW_CC_normal. */
13238 if (value && (value != DW_CC_normal))
13239 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
13242 /* Given a tree pointer to a struct, class, union, or enum type node, return
13243 a pointer to the (string) tag name for the given type, or zero if the type
13244 was declared without a tag. */
13246 static const char *
13247 type_tag (const_tree type)
13249 const char *name = 0;
13251 if (TYPE_NAME (type) != 0)
13255 /* Find the IDENTIFIER_NODE for the type name. */
13256 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
13257 t = TYPE_NAME (type);
13259 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
13260 a TYPE_DECL node, regardless of whether or not a `typedef' was
13262 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13263 && ! DECL_IGNORED_P (TYPE_NAME (type)))
13265 /* We want to be extra verbose. Don't call dwarf_name if
13266 DECL_NAME isn't set. The default hook for decl_printable_name
13267 doesn't like that, and in this context it's correct to return
13268 0, instead of "<anonymous>" or the like. */
13269 if (DECL_NAME (TYPE_NAME (type)))
13270 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
13273 /* Now get the name as a string, or invent one. */
13274 if (!name && t != 0)
13275 name = IDENTIFIER_POINTER (t);
13278 return (name == 0 || *name == '\0') ? 0 : name;
13281 /* Return the type associated with a data member, make a special check
13282 for bit field types. */
13285 member_declared_type (const_tree member)
13287 return (DECL_BIT_FIELD_TYPE (member)
13288 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
13291 /* Get the decl's label, as described by its RTL. This may be different
13292 from the DECL_NAME name used in the source file. */
13295 static const char *
13296 decl_start_label (tree decl)
13299 const char *fnname;
13301 x = DECL_RTL (decl);
13302 gcc_assert (MEM_P (x));
13305 gcc_assert (GET_CODE (x) == SYMBOL_REF);
13307 fnname = XSTR (x, 0);
13312 /* These routines generate the internal representation of the DIE's for
13313 the compilation unit. Debugging information is collected by walking
13314 the declaration trees passed in from dwarf2out_decl(). */
13317 gen_array_type_die (tree type, dw_die_ref context_die)
13319 dw_die_ref scope_die = scope_die_for (type, context_die);
13320 dw_die_ref array_die;
13322 /* GNU compilers represent multidimensional array types as sequences of one
13323 dimensional array types whose element types are themselves array types.
13324 We sometimes squish that down to a single array_type DIE with multiple
13325 subscripts in the Dwarf debugging info. The draft Dwarf specification
13326 say that we are allowed to do this kind of compression in C, because
13327 there is no difference between an array of arrays and a multidimensional
13328 array. We don't do this for Ada to remain as close as possible to the
13329 actual representation, which is especially important against the language
13330 flexibilty wrt arrays of variable size. */
13332 bool collapse_nested_arrays = !is_ada ();
13335 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
13336 DW_TAG_string_type doesn't have DW_AT_type attribute). */
13337 if (TYPE_STRING_FLAG (type)
13338 && TREE_CODE (type) == ARRAY_TYPE
13340 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
13342 HOST_WIDE_INT size;
13344 array_die = new_die (DW_TAG_string_type, scope_die, type);
13345 add_name_attribute (array_die, type_tag (type));
13346 equate_type_number_to_die (type, array_die);
13347 size = int_size_in_bytes (type);
13349 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13350 else if (TYPE_DOMAIN (type) != NULL_TREE
13351 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
13352 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
13354 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
13355 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
13357 size = int_size_in_bytes (TREE_TYPE (szdecl));
13358 if (loc && size > 0)
13360 add_AT_loc (array_die, DW_AT_string_length, loc);
13361 if (size != DWARF2_ADDR_SIZE)
13362 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13368 /* ??? The SGI dwarf reader fails for array of array of enum types
13369 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
13370 array type comes before the outer array type. We thus call gen_type_die
13371 before we new_die and must prevent nested array types collapsing for this
13374 #ifdef MIPS_DEBUGGING_INFO
13375 gen_type_die (TREE_TYPE (type), context_die);
13376 collapse_nested_arrays = false;
13379 array_die = new_die (DW_TAG_array_type, scope_die, type);
13380 add_name_attribute (array_die, type_tag (type));
13381 equate_type_number_to_die (type, array_die);
13383 if (TREE_CODE (type) == VECTOR_TYPE)
13385 /* The frontend feeds us a representation for the vector as a struct
13386 containing an array. Pull out the array type. */
13387 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
13388 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
13391 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13393 && TREE_CODE (type) == ARRAY_TYPE
13394 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
13395 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
13396 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13399 /* We default the array ordering. SDB will probably do
13400 the right things even if DW_AT_ordering is not present. It's not even
13401 an issue until we start to get into multidimensional arrays anyway. If
13402 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
13403 then we'll have to put the DW_AT_ordering attribute back in. (But if
13404 and when we find out that we need to put these in, we will only do so
13405 for multidimensional arrays. */
13406 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
13409 #ifdef MIPS_DEBUGGING_INFO
13410 /* The SGI compilers handle arrays of unknown bound by setting
13411 AT_declaration and not emitting any subrange DIEs. */
13412 if (! TYPE_DOMAIN (type))
13413 add_AT_flag (array_die, DW_AT_declaration, 1);
13416 add_subscript_info (array_die, type, collapse_nested_arrays);
13418 /* Add representation of the type of the elements of this array type and
13419 emit the corresponding DIE if we haven't done it already. */
13420 element_type = TREE_TYPE (type);
13421 if (collapse_nested_arrays)
13422 while (TREE_CODE (element_type) == ARRAY_TYPE)
13424 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
13426 element_type = TREE_TYPE (element_type);
13429 #ifndef MIPS_DEBUGGING_INFO
13430 gen_type_die (element_type, context_die);
13433 add_type_attribute (array_die, element_type, 0, 0, context_die);
13435 if (get_AT (array_die, DW_AT_name))
13436 add_pubtype (type, array_die);
13439 static dw_loc_descr_ref
13440 descr_info_loc (tree val, tree base_decl)
13442 HOST_WIDE_INT size;
13443 dw_loc_descr_ref loc, loc2;
13444 enum dwarf_location_atom op;
13446 if (val == base_decl)
13447 return new_loc_descr (DW_OP_push_object_address, 0, 0);
13449 switch (TREE_CODE (val))
13452 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13454 return loc_descriptor_from_tree_1 (val, 0);
13456 if (host_integerp (val, 0))
13457 return int_loc_descriptor (tree_low_cst (val, 0));
13460 size = int_size_in_bytes (TREE_TYPE (val));
13463 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13466 if (size == DWARF2_ADDR_SIZE)
13467 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
13469 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
13471 case POINTER_PLUS_EXPR:
13473 if (host_integerp (TREE_OPERAND (val, 1), 1)
13474 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
13477 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13480 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
13486 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13489 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13492 add_loc_descr (&loc, loc2);
13493 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13515 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13516 tree val, tree base_decl)
13518 dw_loc_descr_ref loc;
13520 if (host_integerp (val, 0))
13522 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13526 loc = descr_info_loc (val, base_decl);
13530 add_AT_loc (die, attr, loc);
13533 /* This routine generates DIE for array with hidden descriptor, details
13534 are filled into *info by a langhook. */
13537 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13538 dw_die_ref context_die)
13540 dw_die_ref scope_die = scope_die_for (type, context_die);
13541 dw_die_ref array_die;
13544 array_die = new_die (DW_TAG_array_type, scope_die, type);
13545 add_name_attribute (array_die, type_tag (type));
13546 equate_type_number_to_die (type, array_die);
13548 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13550 && info->ndimensions >= 2)
13551 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13553 if (info->data_location)
13554 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13556 if (info->associated)
13557 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13559 if (info->allocated)
13560 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13563 for (dim = 0; dim < info->ndimensions; dim++)
13565 dw_die_ref subrange_die
13566 = new_die (DW_TAG_subrange_type, array_die, NULL);
13568 if (info->dimen[dim].lower_bound)
13570 /* If it is the default value, omit it. */
13571 if ((is_c_family () || is_java ())
13572 && integer_zerop (info->dimen[dim].lower_bound))
13574 else if (is_fortran ()
13575 && integer_onep (info->dimen[dim].lower_bound))
13578 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13579 info->dimen[dim].lower_bound,
13582 if (info->dimen[dim].upper_bound)
13583 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13584 info->dimen[dim].upper_bound,
13586 if (info->dimen[dim].stride)
13587 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13588 info->dimen[dim].stride,
13592 gen_type_die (info->element_type, context_die);
13593 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13595 if (get_AT (array_die, DW_AT_name))
13596 add_pubtype (type, array_die);
13601 gen_entry_point_die (tree decl, dw_die_ref context_die)
13603 tree origin = decl_ultimate_origin (decl);
13604 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13606 if (origin != NULL)
13607 add_abstract_origin_attribute (decl_die, origin);
13610 add_name_and_src_coords_attributes (decl_die, decl);
13611 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13612 0, 0, context_die);
13615 if (DECL_ABSTRACT (decl))
13616 equate_decl_number_to_die (decl, decl_die);
13618 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13622 /* Walk through the list of incomplete types again, trying once more to
13623 emit full debugging info for them. */
13626 retry_incomplete_types (void)
13630 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13631 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13634 /* Determine what tag to use for a record type. */
13636 static enum dwarf_tag
13637 record_type_tag (tree type)
13639 if (! lang_hooks.types.classify_record)
13640 return DW_TAG_structure_type;
13642 switch (lang_hooks.types.classify_record (type))
13644 case RECORD_IS_STRUCT:
13645 return DW_TAG_structure_type;
13647 case RECORD_IS_CLASS:
13648 return DW_TAG_class_type;
13650 case RECORD_IS_INTERFACE:
13651 return DW_TAG_interface_type;
13654 gcc_unreachable ();
13658 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13659 include all of the information about the enumeration values also. Each
13660 enumerated type name/value is listed as a child of the enumerated type
13664 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13666 dw_die_ref type_die = lookup_type_die (type);
13668 if (type_die == NULL)
13670 type_die = new_die (DW_TAG_enumeration_type,
13671 scope_die_for (type, context_die), type);
13672 equate_type_number_to_die (type, type_die);
13673 add_name_attribute (type_die, type_tag (type));
13675 else if (! TYPE_SIZE (type))
13678 remove_AT (type_die, DW_AT_declaration);
13680 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13681 given enum type is incomplete, do not generate the DW_AT_byte_size
13682 attribute or the DW_AT_element_list attribute. */
13683 if (TYPE_SIZE (type))
13687 TREE_ASM_WRITTEN (type) = 1;
13688 add_byte_size_attribute (type_die, type);
13689 if (TYPE_STUB_DECL (type) != NULL_TREE)
13690 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13692 /* If the first reference to this type was as the return type of an
13693 inline function, then it may not have a parent. Fix this now. */
13694 if (type_die->die_parent == NULL)
13695 add_child_die (scope_die_for (type, context_die), type_die);
13697 for (link = TYPE_VALUES (type);
13698 link != NULL; link = TREE_CHAIN (link))
13700 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13701 tree value = TREE_VALUE (link);
13703 add_name_attribute (enum_die,
13704 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
13706 if (TREE_CODE (value) == CONST_DECL)
13707 value = DECL_INITIAL (value);
13709 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
13710 /* DWARF2 does not provide a way of indicating whether or
13711 not enumeration constants are signed or unsigned. GDB
13712 always assumes the values are signed, so we output all
13713 values as if they were signed. That means that
13714 enumeration constants with very large unsigned values
13715 will appear to have negative values in the debugger. */
13716 add_AT_int (enum_die, DW_AT_const_value,
13717 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
13721 add_AT_flag (type_die, DW_AT_declaration, 1);
13723 if (get_AT (type_die, DW_AT_name))
13724 add_pubtype (type, type_die);
13729 /* Generate a DIE to represent either a real live formal parameter decl or to
13730 represent just the type of some formal parameter position in some function
13733 Note that this routine is a bit unusual because its argument may be a
13734 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13735 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13736 node. If it's the former then this function is being called to output a
13737 DIE to represent a formal parameter object (or some inlining thereof). If
13738 it's the latter, then this function is only being called to output a
13739 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13740 argument type of some subprogram type. */
13743 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
13745 tree node_or_origin = node ? node : origin;
13746 dw_die_ref parm_die
13747 = new_die (DW_TAG_formal_parameter, context_die, node);
13749 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
13751 case tcc_declaration:
13753 origin = decl_ultimate_origin (node);
13754 if (origin != NULL)
13755 add_abstract_origin_attribute (parm_die, origin);
13758 tree type = TREE_TYPE (node);
13759 add_name_and_src_coords_attributes (parm_die, node);
13760 if (DECL_BY_REFERENCE (node))
13761 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13764 add_type_attribute (parm_die, type,
13765 TREE_READONLY (node),
13766 TREE_THIS_VOLATILE (node),
13768 if (DECL_ARTIFICIAL (node))
13769 add_AT_flag (parm_die, DW_AT_artificial, 1);
13772 if (node && node != origin)
13773 equate_decl_number_to_die (node, parm_die);
13774 if (! DECL_ABSTRACT (node_or_origin))
13775 add_location_or_const_value_attribute (parm_die, node_or_origin,
13781 /* We were called with some kind of a ..._TYPE node. */
13782 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
13786 gcc_unreachable ();
13792 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13793 at the end of an (ANSI prototyped) formal parameters list. */
13796 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13798 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13801 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13802 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13803 parameters as specified in some function type specification (except for
13804 those which appear as part of a function *definition*). */
13807 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13810 tree formal_type = NULL;
13811 tree first_parm_type;
13814 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13816 arg = DECL_ARGUMENTS (function_or_method_type);
13817 function_or_method_type = TREE_TYPE (function_or_method_type);
13822 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13824 /* Make our first pass over the list of formal parameter types and output a
13825 DW_TAG_formal_parameter DIE for each one. */
13826 for (link = first_parm_type; link; )
13828 dw_die_ref parm_die;
13830 formal_type = TREE_VALUE (link);
13831 if (formal_type == void_type_node)
13834 /* Output a (nameless) DIE to represent the formal parameter itself. */
13835 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
13836 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13837 && link == first_parm_type)
13838 || (arg && DECL_ARTIFICIAL (arg)))
13839 add_AT_flag (parm_die, DW_AT_artificial, 1);
13841 link = TREE_CHAIN (link);
13843 arg = TREE_CHAIN (arg);
13846 /* If this function type has an ellipsis, add a
13847 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13848 if (formal_type != void_type_node)
13849 gen_unspecified_parameters_die (function_or_method_type, context_die);
13851 /* Make our second (and final) pass over the list of formal parameter types
13852 and output DIEs to represent those types (as necessary). */
13853 for (link = TYPE_ARG_TYPES (function_or_method_type);
13854 link && TREE_VALUE (link);
13855 link = TREE_CHAIN (link))
13856 gen_type_die (TREE_VALUE (link), context_die);
13859 /* We want to generate the DIE for TYPE so that we can generate the
13860 die for MEMBER, which has been defined; we will need to refer back
13861 to the member declaration nested within TYPE. If we're trying to
13862 generate minimal debug info for TYPE, processing TYPE won't do the
13863 trick; we need to attach the member declaration by hand. */
13866 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13868 gen_type_die (type, context_die);
13870 /* If we're trying to avoid duplicate debug info, we may not have
13871 emitted the member decl for this function. Emit it now. */
13872 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13873 && ! lookup_decl_die (member))
13875 dw_die_ref type_die;
13876 gcc_assert (!decl_ultimate_origin (member));
13878 push_decl_scope (type);
13879 type_die = lookup_type_die (type);
13880 if (TREE_CODE (member) == FUNCTION_DECL)
13881 gen_subprogram_die (member, type_die);
13882 else if (TREE_CODE (member) == FIELD_DECL)
13884 /* Ignore the nameless fields that are used to skip bits but handle
13885 C++ anonymous unions and structs. */
13886 if (DECL_NAME (member) != NULL_TREE
13887 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13888 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13890 gen_type_die (member_declared_type (member), type_die);
13891 gen_field_die (member, type_die);
13895 gen_variable_die (member, NULL_TREE, type_die);
13901 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13902 may later generate inlined and/or out-of-line instances of. */
13905 dwarf2out_abstract_function (tree decl)
13907 dw_die_ref old_die;
13910 int was_abstract = DECL_ABSTRACT (decl);
13912 /* Make sure we have the actual abstract inline, not a clone. */
13913 decl = DECL_ORIGIN (decl);
13914 htab_empty (decl_loc_table);
13916 old_die = lookup_decl_die (decl);
13917 if (old_die && get_AT (old_die, DW_AT_inline))
13918 /* We've already generated the abstract instance. */
13921 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13922 we don't get confused by DECL_ABSTRACT. */
13923 if (debug_info_level > DINFO_LEVEL_TERSE)
13925 context = decl_class_context (decl);
13927 gen_type_die_for_member
13928 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13931 /* Pretend we've just finished compiling this function. */
13932 save_fn = current_function_decl;
13933 current_function_decl = decl;
13934 push_cfun (DECL_STRUCT_FUNCTION (decl));
13936 set_decl_abstract_flags (decl, 1);
13937 dwarf2out_decl (decl);
13938 if (! was_abstract)
13939 set_decl_abstract_flags (decl, 0);
13941 current_function_decl = save_fn;
13945 /* Helper function of premark_used_types() which gets called through
13946 htab_traverse_resize().
13948 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13949 marked as unused by prune_unused_types. */
13951 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13956 type = (tree) *slot;
13957 die = lookup_type_die (type);
13959 die->die_perennial_p = 1;
13963 /* Mark all members of used_types_hash as perennial. */
13965 premark_used_types (void)
13967 if (cfun && cfun->used_types_hash)
13968 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13971 /* Generate a DIE to represent a declared function (either file-scope or
13975 gen_subprogram_die (tree decl, dw_die_ref context_die)
13977 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13978 tree origin = decl_ultimate_origin (decl);
13979 dw_die_ref subr_die;
13982 dw_die_ref old_die = lookup_decl_die (decl);
13983 int declaration = (current_function_decl != decl
13984 || class_or_namespace_scope_p (context_die));
13986 premark_used_types ();
13988 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13989 started to generate the abstract instance of an inline, decided to output
13990 its containing class, and proceeded to emit the declaration of the inline
13991 from the member list for the class. If so, DECLARATION takes priority;
13992 we'll get back to the abstract instance when done with the class. */
13994 /* The class-scope declaration DIE must be the primary DIE. */
13995 if (origin && declaration && class_or_namespace_scope_p (context_die))
13998 gcc_assert (!old_die);
14001 /* Now that the C++ front end lazily declares artificial member fns, we
14002 might need to retrofit the declaration into its class. */
14003 if (!declaration && !origin && !old_die
14004 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
14005 && !class_or_namespace_scope_p (context_die)
14006 && debug_info_level > DINFO_LEVEL_TERSE)
14007 old_die = force_decl_die (decl);
14009 if (origin != NULL)
14011 gcc_assert (!declaration || local_scope_p (context_die));
14013 /* Fixup die_parent for the abstract instance of a nested
14014 inline function. */
14015 if (old_die && old_die->die_parent == NULL)
14016 add_child_die (context_die, old_die);
14018 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14019 add_abstract_origin_attribute (subr_die, origin);
14023 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14024 struct dwarf_file_data * file_index = lookup_filename (s.file);
14026 if (!get_AT_flag (old_die, DW_AT_declaration)
14027 /* We can have a normal definition following an inline one in the
14028 case of redefinition of GNU C extern inlines.
14029 It seems reasonable to use AT_specification in this case. */
14030 && !get_AT (old_die, DW_AT_inline))
14032 /* Detect and ignore this case, where we are trying to output
14033 something we have already output. */
14037 /* If the definition comes from the same place as the declaration,
14038 maybe use the old DIE. We always want the DIE for this function
14039 that has the *_pc attributes to be under comp_unit_die so the
14040 debugger can find it. We also need to do this for abstract
14041 instances of inlines, since the spec requires the out-of-line copy
14042 to have the same parent. For local class methods, this doesn't
14043 apply; we just use the old DIE. */
14044 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
14045 && (DECL_ARTIFICIAL (decl)
14046 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
14047 && (get_AT_unsigned (old_die, DW_AT_decl_line)
14048 == (unsigned) s.line))))
14050 subr_die = old_die;
14052 /* Clear out the declaration attribute and the formal parameters.
14053 Do not remove all children, because it is possible that this
14054 declaration die was forced using force_decl_die(). In such
14055 cases die that forced declaration die (e.g. TAG_imported_module)
14056 is one of the children that we do not want to remove. */
14057 remove_AT (subr_die, DW_AT_declaration);
14058 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
14062 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14063 add_AT_specification (subr_die, old_die);
14064 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14065 add_AT_file (subr_die, DW_AT_decl_file, file_index);
14066 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14067 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
14072 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14074 if (TREE_PUBLIC (decl))
14075 add_AT_flag (subr_die, DW_AT_external, 1);
14077 add_name_and_src_coords_attributes (subr_die, decl);
14078 if (debug_info_level > DINFO_LEVEL_TERSE)
14080 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
14081 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
14082 0, 0, context_die);
14085 add_pure_or_virtual_attribute (subr_die, decl);
14086 if (DECL_ARTIFICIAL (decl))
14087 add_AT_flag (subr_die, DW_AT_artificial, 1);
14089 if (TREE_PROTECTED (decl))
14090 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
14091 else if (TREE_PRIVATE (decl))
14092 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
14097 if (!old_die || !get_AT (old_die, DW_AT_inline))
14099 add_AT_flag (subr_die, DW_AT_declaration, 1);
14101 /* If this is an explicit function declaration then generate
14102 a DW_AT_explicit attribute. */
14103 if (lang_hooks.decls.function_decl_explicit_p (decl))
14104 add_AT_flag (subr_die, DW_AT_explicit, 1);
14106 /* The first time we see a member function, it is in the context of
14107 the class to which it belongs. We make sure of this by emitting
14108 the class first. The next time is the definition, which is
14109 handled above. The two may come from the same source text.
14111 Note that force_decl_die() forces function declaration die. It is
14112 later reused to represent definition. */
14113 equate_decl_number_to_die (decl, subr_die);
14116 else if (DECL_ABSTRACT (decl))
14118 if (DECL_DECLARED_INLINE_P (decl))
14120 if (cgraph_function_possibly_inlined_p (decl))
14121 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
14123 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
14127 if (cgraph_function_possibly_inlined_p (decl))
14128 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
14130 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
14133 if (DECL_DECLARED_INLINE_P (decl)
14134 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
14135 add_AT_flag (subr_die, DW_AT_artificial, 1);
14137 equate_decl_number_to_die (decl, subr_die);
14139 else if (!DECL_EXTERNAL (decl))
14141 HOST_WIDE_INT cfa_fb_offset;
14143 if (!old_die || !get_AT (old_die, DW_AT_inline))
14144 equate_decl_number_to_die (decl, subr_die);
14146 if (!flag_reorder_blocks_and_partition)
14148 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
14149 current_function_funcdef_no);
14150 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
14151 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14152 current_function_funcdef_no);
14153 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
14155 add_pubname (decl, subr_die);
14156 add_arange (decl, subr_die);
14159 { /* Do nothing for now; maybe need to duplicate die, one for
14160 hot section and one for cold section, then use the hot/cold
14161 section begin/end labels to generate the aranges... */
14163 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
14164 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
14165 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
14166 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
14168 add_pubname (decl, subr_die);
14169 add_arange (decl, subr_die);
14170 add_arange (decl, subr_die);
14174 #ifdef MIPS_DEBUGGING_INFO
14175 /* Add a reference to the FDE for this routine. */
14176 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
14179 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
14181 /* We define the "frame base" as the function's CFA. This is more
14182 convenient for several reasons: (1) It's stable across the prologue
14183 and epilogue, which makes it better than just a frame pointer,
14184 (2) With dwarf3, there exists a one-byte encoding that allows us
14185 to reference the .debug_frame data by proxy, but failing that,
14186 (3) We can at least reuse the code inspection and interpretation
14187 code that determines the CFA position at various points in the
14189 if (dwarf_version >= 3)
14191 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
14192 add_AT_loc (subr_die, DW_AT_frame_base, op);
14196 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
14197 if (list->dw_loc_next)
14198 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
14200 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
14203 /* Compute a displacement from the "steady-state frame pointer" to
14204 the CFA. The former is what all stack slots and argument slots
14205 will reference in the rtl; the later is what we've told the
14206 debugger about. We'll need to adjust all frame_base references
14207 by this displacement. */
14208 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
14210 if (cfun->static_chain_decl)
14211 add_AT_location_description (subr_die, DW_AT_static_link,
14212 loc_descriptor_from_tree (cfun->static_chain_decl));
14215 /* Now output descriptions of the arguments for this function. This gets
14216 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
14217 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
14218 `...' at the end of the formal parameter list. In order to find out if
14219 there was a trailing ellipsis or not, we must instead look at the type
14220 associated with the FUNCTION_DECL. This will be a node of type
14221 FUNCTION_TYPE. If the chain of type nodes hanging off of this
14222 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
14223 an ellipsis at the end. */
14225 /* In the case where we are describing a mere function declaration, all we
14226 need to do here (and all we *can* do here) is to describe the *types* of
14227 its formal parameters. */
14228 if (debug_info_level <= DINFO_LEVEL_TERSE)
14230 else if (declaration)
14231 gen_formal_types_die (decl, subr_die);
14234 /* Generate DIEs to represent all known formal parameters. */
14235 tree arg_decls = DECL_ARGUMENTS (decl);
14238 /* When generating DIEs, generate the unspecified_parameters DIE
14239 instead if we come across the arg "__builtin_va_alist" */
14240 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
14241 if (TREE_CODE (parm) == PARM_DECL)
14243 if (DECL_NAME (parm)
14244 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
14245 "__builtin_va_alist"))
14246 gen_unspecified_parameters_die (parm, subr_die);
14248 gen_decl_die (parm, NULL, subr_die);
14251 /* Decide whether we need an unspecified_parameters DIE at the end.
14252 There are 2 more cases to do this for: 1) the ansi ... declaration -
14253 this is detectable when the end of the arg list is not a
14254 void_type_node 2) an unprototyped function declaration (not a
14255 definition). This just means that we have no info about the
14256 parameters at all. */
14257 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
14258 if (fn_arg_types != NULL)
14260 /* This is the prototyped case, check for.... */
14261 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
14262 gen_unspecified_parameters_die (decl, subr_die);
14264 else if (DECL_INITIAL (decl) == NULL_TREE)
14265 gen_unspecified_parameters_die (decl, subr_die);
14268 /* Output Dwarf info for all of the stuff within the body of the function
14269 (if it has one - it may be just a declaration). */
14270 outer_scope = DECL_INITIAL (decl);
14272 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
14273 a function. This BLOCK actually represents the outermost binding contour
14274 for the function, i.e. the contour in which the function's formal
14275 parameters and labels get declared. Curiously, it appears that the front
14276 end doesn't actually put the PARM_DECL nodes for the current function onto
14277 the BLOCK_VARS list for this outer scope, but are strung off of the
14278 DECL_ARGUMENTS list for the function instead.
14280 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
14281 the LABEL_DECL nodes for the function however, and we output DWARF info
14282 for those in decls_for_scope. Just within the `outer_scope' there will be
14283 a BLOCK node representing the function's outermost pair of curly braces,
14284 and any blocks used for the base and member initializers of a C++
14285 constructor function. */
14286 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
14288 /* Emit a DW_TAG_variable DIE for a named return value. */
14289 if (DECL_NAME (DECL_RESULT (decl)))
14290 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
14292 current_function_has_inlines = 0;
14293 decls_for_scope (outer_scope, subr_die, 0);
14295 #if 0 && defined (MIPS_DEBUGGING_INFO)
14296 if (current_function_has_inlines)
14298 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
14299 if (! comp_unit_has_inlines)
14301 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
14302 comp_unit_has_inlines = 1;
14307 /* Add the calling convention attribute if requested. */
14308 add_calling_convention_attribute (subr_die, decl);
14312 /* Returns a hash value for X (which really is a die_struct). */
14315 common_block_die_table_hash (const void *x)
14317 const_dw_die_ref d = (const_dw_die_ref) x;
14318 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
14321 /* Return nonzero if decl_id and die_parent of die_struct X is the same
14322 as decl_id and die_parent of die_struct Y. */
14325 common_block_die_table_eq (const void *x, const void *y)
14327 const_dw_die_ref d = (const_dw_die_ref) x;
14328 const_dw_die_ref e = (const_dw_die_ref) y;
14329 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
14332 /* Generate a DIE to represent a declared data object.
14333 Either DECL or ORIGIN must be non-null. */
14336 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
14340 tree decl_or_origin = decl ? decl : origin;
14341 dw_die_ref var_die;
14342 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
14343 dw_die_ref origin_die;
14344 int declaration = (DECL_EXTERNAL (decl_or_origin)
14345 /* If DECL is COMDAT and has not actually been
14346 emitted, we cannot take its address; there
14347 might end up being no definition anywhere in
14348 the program. For example, consider the C++
14352 struct S { static const int i = 7; };
14357 int f() { return S<int>::i; }
14359 Here, S<int>::i is not DECL_EXTERNAL, but no
14360 definition is required, so the compiler will
14361 not emit a definition. */
14362 || (TREE_CODE (decl_or_origin) == VAR_DECL
14363 && DECL_COMDAT (decl_or_origin)
14364 && !TREE_ASM_WRITTEN (decl_or_origin))
14365 || class_or_namespace_scope_p (context_die));
14368 origin = decl_ultimate_origin (decl);
14370 com_decl = fortran_common (decl_or_origin, &off);
14372 /* Symbol in common gets emitted as a child of the common block, in the form
14373 of a data member. */
14377 dw_die_ref com_die;
14378 dw_loc_descr_ref loc;
14379 die_node com_die_arg;
14381 var_die = lookup_decl_die (decl_or_origin);
14384 if (get_AT (var_die, DW_AT_location) == NULL)
14386 loc = loc_descriptor_from_tree (com_decl);
14391 /* Optimize the common case. */
14392 if (loc->dw_loc_opc == DW_OP_addr
14393 && loc->dw_loc_next == NULL
14394 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
14396 loc->dw_loc_oprnd1.v.val_addr
14397 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14399 loc_descr_plus_const (&loc, off);
14401 add_AT_loc (var_die, DW_AT_location, loc);
14402 remove_AT (var_die, DW_AT_declaration);
14408 if (common_block_die_table == NULL)
14409 common_block_die_table
14410 = htab_create_ggc (10, common_block_die_table_hash,
14411 common_block_die_table_eq, NULL);
14413 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
14414 com_die_arg.decl_id = DECL_UID (com_decl);
14415 com_die_arg.die_parent = context_die;
14416 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
14417 loc = loc_descriptor_from_tree (com_decl);
14418 if (com_die == NULL)
14421 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
14424 com_die = new_die (DW_TAG_common_block, context_die, decl);
14425 add_name_and_src_coords_attributes (com_die, com_decl);
14428 add_AT_loc (com_die, DW_AT_location, loc);
14429 /* Avoid sharing the same loc descriptor between
14430 DW_TAG_common_block and DW_TAG_variable. */
14431 loc = loc_descriptor_from_tree (com_decl);
14433 else if (DECL_EXTERNAL (decl))
14434 add_AT_flag (com_die, DW_AT_declaration, 1);
14435 add_pubname_string (cnam, com_die); /* ??? needed? */
14436 com_die->decl_id = DECL_UID (com_decl);
14437 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
14438 *slot = (void *) com_die;
14440 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
14442 add_AT_loc (com_die, DW_AT_location, loc);
14443 loc = loc_descriptor_from_tree (com_decl);
14444 remove_AT (com_die, DW_AT_declaration);
14446 var_die = new_die (DW_TAG_variable, com_die, decl);
14447 add_name_and_src_coords_attributes (var_die, decl);
14448 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
14449 TREE_THIS_VOLATILE (decl), context_die);
14450 add_AT_flag (var_die, DW_AT_external, 1);
14455 /* Optimize the common case. */
14456 if (loc->dw_loc_opc == DW_OP_addr
14457 && loc->dw_loc_next == NULL
14458 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
14459 loc->dw_loc_oprnd1.v.val_addr
14460 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14462 loc_descr_plus_const (&loc, off);
14464 add_AT_loc (var_die, DW_AT_location, loc);
14466 else if (DECL_EXTERNAL (decl))
14467 add_AT_flag (var_die, DW_AT_declaration, 1);
14468 equate_decl_number_to_die (decl, var_die);
14472 /* If the compiler emitted a definition for the DECL declaration
14473 and if we already emitted a DIE for it, don't emit a second
14474 DIE for it again. */
14477 && old_die->die_parent == context_die)
14480 /* For static data members, the declaration in the class is supposed
14481 to have DW_TAG_member tag; the specification should still be
14482 DW_TAG_variable referencing the DW_TAG_member DIE. */
14483 if (declaration && class_scope_p (context_die))
14484 var_die = new_die (DW_TAG_member, context_die, decl);
14486 var_die = new_die (DW_TAG_variable, context_die, decl);
14489 if (origin != NULL)
14490 origin_die = add_abstract_origin_attribute (var_die, origin);
14492 /* Loop unrolling can create multiple blocks that refer to the same
14493 static variable, so we must test for the DW_AT_declaration flag.
14495 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14496 copy decls and set the DECL_ABSTRACT flag on them instead of
14499 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14501 ??? The declare_in_namespace support causes us to get two DIEs for one
14502 variable, both of which are declarations. We want to avoid considering
14503 one to be a specification, so we must test that this DIE is not a
14505 else if (old_die && TREE_STATIC (decl) && ! declaration
14506 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14508 /* This is a definition of a C++ class level static. */
14509 add_AT_specification (var_die, old_die);
14510 if (DECL_NAME (decl))
14512 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14513 struct dwarf_file_data * file_index = lookup_filename (s.file);
14515 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14516 add_AT_file (var_die, DW_AT_decl_file, file_index);
14518 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14519 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14524 tree type = TREE_TYPE (decl);
14526 add_name_and_src_coords_attributes (var_die, decl);
14527 if ((TREE_CODE (decl) == PARM_DECL
14528 || TREE_CODE (decl) == RESULT_DECL
14529 || TREE_CODE (decl) == VAR_DECL)
14530 && DECL_BY_REFERENCE (decl))
14531 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14533 add_type_attribute (var_die, type, TREE_READONLY (decl),
14534 TREE_THIS_VOLATILE (decl), context_die);
14536 if (TREE_PUBLIC (decl))
14537 add_AT_flag (var_die, DW_AT_external, 1);
14539 if (DECL_ARTIFICIAL (decl))
14540 add_AT_flag (var_die, DW_AT_artificial, 1);
14542 if (TREE_PROTECTED (decl))
14543 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14544 else if (TREE_PRIVATE (decl))
14545 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14549 add_AT_flag (var_die, DW_AT_declaration, 1);
14551 if (decl && (DECL_ABSTRACT (decl) || declaration))
14552 equate_decl_number_to_die (decl, var_die);
14555 && (! DECL_ABSTRACT (decl_or_origin)
14556 /* Local static vars are shared between all clones/inlines,
14557 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14559 || (TREE_CODE (decl_or_origin) == VAR_DECL
14560 && TREE_STATIC (decl_or_origin)
14561 && DECL_RTL_SET_P (decl_or_origin)))
14562 /* When abstract origin already has DW_AT_location attribute, no need
14563 to add it again. */
14564 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14566 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14567 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14568 defer_location (decl_or_origin, var_die);
14570 add_location_or_const_value_attribute (var_die,
14573 add_pubname (decl_or_origin, var_die);
14576 tree_add_const_value_attribute (var_die, decl_or_origin);
14579 /* Generate a DIE to represent a named constant. */
14582 gen_const_die (tree decl, dw_die_ref context_die)
14584 dw_die_ref const_die;
14585 tree type = TREE_TYPE (decl);
14587 const_die = new_die (DW_TAG_constant, context_die, decl);
14588 add_name_and_src_coords_attributes (const_die, decl);
14589 add_type_attribute (const_die, type, 1, 0, context_die);
14590 if (TREE_PUBLIC (decl))
14591 add_AT_flag (const_die, DW_AT_external, 1);
14592 if (DECL_ARTIFICIAL (decl))
14593 add_AT_flag (const_die, DW_AT_artificial, 1);
14594 tree_add_const_value_attribute (const_die, decl);
14597 /* Generate a DIE to represent a label identifier. */
14600 gen_label_die (tree decl, dw_die_ref context_die)
14602 tree origin = decl_ultimate_origin (decl);
14603 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14605 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14607 if (origin != NULL)
14608 add_abstract_origin_attribute (lbl_die, origin);
14610 add_name_and_src_coords_attributes (lbl_die, decl);
14612 if (DECL_ABSTRACT (decl))
14613 equate_decl_number_to_die (decl, lbl_die);
14616 insn = DECL_RTL_IF_SET (decl);
14618 /* Deleted labels are programmer specified labels which have been
14619 eliminated because of various optimizations. We still emit them
14620 here so that it is possible to put breakpoints on them. */
14624 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14626 /* When optimization is enabled (via -O) some parts of the compiler
14627 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14628 represent source-level labels which were explicitly declared by
14629 the user. This really shouldn't be happening though, so catch
14630 it if it ever does happen. */
14631 gcc_assert (!INSN_DELETED_P (insn));
14633 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14634 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14639 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14640 attributes to the DIE for a block STMT, to describe where the inlined
14641 function was called from. This is similar to add_src_coords_attributes. */
14644 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14646 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14648 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14649 add_AT_unsigned (die, DW_AT_call_line, s.line);
14653 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14654 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14657 add_high_low_attributes (tree stmt, dw_die_ref die)
14659 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14661 if (BLOCK_FRAGMENT_CHAIN (stmt))
14665 if (inlined_function_outer_scope_p (stmt))
14667 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14668 BLOCK_NUMBER (stmt));
14669 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14672 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14674 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14677 add_ranges (chain);
14678 chain = BLOCK_FRAGMENT_CHAIN (chain);
14685 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14686 BLOCK_NUMBER (stmt));
14687 add_AT_lbl_id (die, DW_AT_low_pc, label);
14688 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14689 BLOCK_NUMBER (stmt));
14690 add_AT_lbl_id (die, DW_AT_high_pc, label);
14694 /* Generate a DIE for a lexical block. */
14697 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14699 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14701 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14702 add_high_low_attributes (stmt, stmt_die);
14704 decls_for_scope (stmt, stmt_die, depth);
14707 /* Generate a DIE for an inlined subprogram. */
14710 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
14712 tree decl = block_ultimate_origin (stmt);
14714 /* Emit info for the abstract instance first, if we haven't yet. We
14715 must emit this even if the block is abstract, otherwise when we
14716 emit the block below (or elsewhere), we may end up trying to emit
14717 a die whose origin die hasn't been emitted, and crashing. */
14718 dwarf2out_abstract_function (decl);
14720 if (! BLOCK_ABSTRACT (stmt))
14722 dw_die_ref subr_die
14723 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
14725 add_abstract_origin_attribute (subr_die, decl);
14726 if (TREE_ASM_WRITTEN (stmt))
14727 add_high_low_attributes (stmt, subr_die);
14728 add_call_src_coords_attributes (stmt, subr_die);
14730 decls_for_scope (stmt, subr_die, depth);
14731 current_function_has_inlines = 1;
14734 /* We may get here if we're the outer block of function A that was
14735 inlined into function B that was inlined into function C. When
14736 generating debugging info for C, dwarf2out_abstract_function(B)
14737 would mark all inlined blocks as abstract, including this one.
14738 So, we wouldn't (and shouldn't) expect labels to be generated
14739 for this one. Instead, just emit debugging info for
14740 declarations within the block. This is particularly important
14741 in the case of initializers of arguments passed from B to us:
14742 if they're statement expressions containing declarations, we
14743 wouldn't generate dies for their abstract variables, and then,
14744 when generating dies for the real variables, we'd die (pun
14746 gen_lexical_block_die (stmt, context_die, depth);
14749 /* Generate a DIE for a field in a record, or structure. */
14752 gen_field_die (tree decl, dw_die_ref context_die)
14754 dw_die_ref decl_die;
14756 if (TREE_TYPE (decl) == error_mark_node)
14759 decl_die = new_die (DW_TAG_member, context_die, decl);
14760 add_name_and_src_coords_attributes (decl_die, decl);
14761 add_type_attribute (decl_die, member_declared_type (decl),
14762 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
14765 if (DECL_BIT_FIELD_TYPE (decl))
14767 add_byte_size_attribute (decl_die, decl);
14768 add_bit_size_attribute (decl_die, decl);
14769 add_bit_offset_attribute (decl_die, decl);
14772 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
14773 add_data_member_location_attribute (decl_die, decl);
14775 if (DECL_ARTIFICIAL (decl))
14776 add_AT_flag (decl_die, DW_AT_artificial, 1);
14778 if (TREE_PROTECTED (decl))
14779 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
14780 else if (TREE_PRIVATE (decl))
14781 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
14783 /* Equate decl number to die, so that we can look up this decl later on. */
14784 equate_decl_number_to_die (decl, decl_die);
14788 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14789 Use modified_type_die instead.
14790 We keep this code here just in case these types of DIEs may be needed to
14791 represent certain things in other languages (e.g. Pascal) someday. */
14794 gen_pointer_type_die (tree type, dw_die_ref context_die)
14797 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
14799 equate_type_number_to_die (type, ptr_die);
14800 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14801 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14804 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14805 Use modified_type_die instead.
14806 We keep this code here just in case these types of DIEs may be needed to
14807 represent certain things in other languages (e.g. Pascal) someday. */
14810 gen_reference_type_die (tree type, dw_die_ref context_die)
14813 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
14815 equate_type_number_to_die (type, ref_die);
14816 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
14817 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14821 /* Generate a DIE for a pointer to a member type. */
14824 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14827 = new_die (DW_TAG_ptr_to_member_type,
14828 scope_die_for (type, context_die), type);
14830 equate_type_number_to_die (type, ptr_die);
14831 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14832 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14833 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14836 /* Generate the DIE for the compilation unit. */
14839 gen_compile_unit_die (const char *filename)
14842 char producer[250];
14843 const char *language_string = lang_hooks.name;
14846 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14850 add_name_attribute (die, filename);
14851 /* Don't add cwd for <built-in>. */
14852 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14853 add_comp_dir_attribute (die);
14856 sprintf (producer, "%s %s", language_string, version_string);
14858 #ifdef MIPS_DEBUGGING_INFO
14859 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14860 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14861 not appear in the producer string, the debugger reaches the conclusion
14862 that the object file is stripped and has no debugging information.
14863 To get the MIPS/SGI debugger to believe that there is debugging
14864 information in the object file, we add a -g to the producer string. */
14865 if (debug_info_level > DINFO_LEVEL_TERSE)
14866 strcat (producer, " -g");
14869 add_AT_string (die, DW_AT_producer, producer);
14871 if (strcmp (language_string, "GNU C++") == 0)
14872 language = DW_LANG_C_plus_plus;
14873 else if (strcmp (language_string, "GNU Ada") == 0)
14874 language = DW_LANG_Ada95;
14875 else if (strcmp (language_string, "GNU F77") == 0)
14876 language = DW_LANG_Fortran77;
14877 else if (strcmp (language_string, "GNU Fortran") == 0)
14878 language = DW_LANG_Fortran95;
14879 else if (strcmp (language_string, "GNU Pascal") == 0)
14880 language = DW_LANG_Pascal83;
14881 else if (strcmp (language_string, "GNU Java") == 0)
14882 language = DW_LANG_Java;
14883 else if (strcmp (language_string, "GNU Objective-C") == 0)
14884 language = DW_LANG_ObjC;
14885 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14886 language = DW_LANG_ObjC_plus_plus;
14888 language = DW_LANG_C89;
14890 add_AT_unsigned (die, DW_AT_language, language);
14894 /* Generate the DIE for a base class. */
14897 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14899 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14901 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14902 add_data_member_location_attribute (die, binfo);
14904 if (BINFO_VIRTUAL_P (binfo))
14905 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14907 if (access == access_public_node)
14908 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14909 else if (access == access_protected_node)
14910 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14913 /* Generate a DIE for a class member. */
14916 gen_member_die (tree type, dw_die_ref context_die)
14919 tree binfo = TYPE_BINFO (type);
14922 /* If this is not an incomplete type, output descriptions of each of its
14923 members. Note that as we output the DIEs necessary to represent the
14924 members of this record or union type, we will also be trying to output
14925 DIEs to represent the *types* of those members. However the `type'
14926 function (above) will specifically avoid generating type DIEs for member
14927 types *within* the list of member DIEs for this (containing) type except
14928 for those types (of members) which are explicitly marked as also being
14929 members of this (containing) type themselves. The g++ front- end can
14930 force any given type to be treated as a member of some other (containing)
14931 type by setting the TYPE_CONTEXT of the given (member) type to point to
14932 the TREE node representing the appropriate (containing) type. */
14934 /* First output info about the base classes. */
14937 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14941 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14942 gen_inheritance_die (base,
14943 (accesses ? VEC_index (tree, accesses, i)
14944 : access_public_node), context_die);
14947 /* Now output info about the data members and type members. */
14948 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14950 /* If we thought we were generating minimal debug info for TYPE
14951 and then changed our minds, some of the member declarations
14952 may have already been defined. Don't define them again, but
14953 do put them in the right order. */
14955 child = lookup_decl_die (member);
14957 splice_child_die (context_die, child);
14959 gen_decl_die (member, NULL, context_die);
14962 /* Now output info about the function members (if any). */
14963 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14965 /* Don't include clones in the member list. */
14966 if (DECL_ABSTRACT_ORIGIN (member))
14969 child = lookup_decl_die (member);
14971 splice_child_die (context_die, child);
14973 gen_decl_die (member, NULL, context_die);
14977 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14978 is set, we pretend that the type was never defined, so we only get the
14979 member DIEs needed by later specification DIEs. */
14982 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14983 enum debug_info_usage usage)
14985 dw_die_ref type_die = lookup_type_die (type);
14986 dw_die_ref scope_die = 0;
14988 int complete = (TYPE_SIZE (type)
14989 && (! TYPE_STUB_DECL (type)
14990 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14991 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14992 complete = complete && should_emit_struct_debug (type, usage);
14994 if (type_die && ! complete)
14997 if (TYPE_CONTEXT (type) != NULL_TREE
14998 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14999 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
15002 scope_die = scope_die_for (type, context_die);
15004 if (! type_die || (nested && scope_die == comp_unit_die))
15005 /* First occurrence of type or toplevel definition of nested class. */
15007 dw_die_ref old_die = type_die;
15009 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
15010 ? record_type_tag (type) : DW_TAG_union_type,
15012 equate_type_number_to_die (type, type_die);
15014 add_AT_specification (type_die, old_die);
15016 add_name_attribute (type_die, type_tag (type));
15019 remove_AT (type_die, DW_AT_declaration);
15021 /* If this type has been completed, then give it a byte_size attribute and
15022 then give a list of members. */
15023 if (complete && !ns_decl)
15025 /* Prevent infinite recursion in cases where the type of some member of
15026 this type is expressed in terms of this type itself. */
15027 TREE_ASM_WRITTEN (type) = 1;
15028 add_byte_size_attribute (type_die, type);
15029 if (TYPE_STUB_DECL (type) != NULL_TREE)
15030 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
15032 /* If the first reference to this type was as the return type of an
15033 inline function, then it may not have a parent. Fix this now. */
15034 if (type_die->die_parent == NULL)
15035 add_child_die (scope_die, type_die);
15037 push_decl_scope (type);
15038 gen_member_die (type, type_die);
15041 /* GNU extension: Record what type our vtable lives in. */
15042 if (TYPE_VFIELD (type))
15044 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
15046 gen_type_die (vtype, context_die);
15047 add_AT_die_ref (type_die, DW_AT_containing_type,
15048 lookup_type_die (vtype));
15053 add_AT_flag (type_die, DW_AT_declaration, 1);
15055 /* We don't need to do this for function-local types. */
15056 if (TYPE_STUB_DECL (type)
15057 && ! decl_function_context (TYPE_STUB_DECL (type)))
15058 VEC_safe_push (tree, gc, incomplete_types, type);
15061 if (get_AT (type_die, DW_AT_name))
15062 add_pubtype (type, type_die);
15065 /* Generate a DIE for a subroutine _type_. */
15068 gen_subroutine_type_die (tree type, dw_die_ref context_die)
15070 tree return_type = TREE_TYPE (type);
15071 dw_die_ref subr_die
15072 = new_die (DW_TAG_subroutine_type,
15073 scope_die_for (type, context_die), type);
15075 equate_type_number_to_die (type, subr_die);
15076 add_prototyped_attribute (subr_die, type);
15077 add_type_attribute (subr_die, return_type, 0, 0, context_die);
15078 gen_formal_types_die (type, subr_die);
15080 if (get_AT (subr_die, DW_AT_name))
15081 add_pubtype (type, subr_die);
15084 /* Generate a DIE for a type definition. */
15087 gen_typedef_die (tree decl, dw_die_ref context_die)
15089 dw_die_ref type_die;
15092 if (TREE_ASM_WRITTEN (decl))
15095 TREE_ASM_WRITTEN (decl) = 1;
15096 type_die = new_die (DW_TAG_typedef, context_die, decl);
15097 origin = decl_ultimate_origin (decl);
15098 if (origin != NULL)
15099 add_abstract_origin_attribute (type_die, origin);
15104 add_name_and_src_coords_attributes (type_die, decl);
15105 if (DECL_ORIGINAL_TYPE (decl))
15107 type = DECL_ORIGINAL_TYPE (decl);
15109 gcc_assert (type != TREE_TYPE (decl));
15110 equate_type_number_to_die (TREE_TYPE (decl), type_die);
15113 type = TREE_TYPE (decl);
15115 add_type_attribute (type_die, type, TREE_READONLY (decl),
15116 TREE_THIS_VOLATILE (decl), context_die);
15119 if (DECL_ABSTRACT (decl))
15120 equate_decl_number_to_die (decl, type_die);
15122 if (get_AT (type_die, DW_AT_name))
15123 add_pubtype (decl, type_die);
15126 /* Generate a type description DIE. */
15129 gen_type_die_with_usage (tree type, dw_die_ref context_die,
15130 enum debug_info_usage usage)
15133 struct array_descr_info info;
15135 if (type == NULL_TREE || type == error_mark_node)
15138 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
15139 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
15141 if (TREE_ASM_WRITTEN (type))
15144 /* Prevent broken recursion; we can't hand off to the same type. */
15145 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
15147 /* Use the DIE of the containing namespace as the parent DIE of
15148 the type description DIE we want to generate. */
15149 if (DECL_CONTEXT (TYPE_NAME (type))
15150 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
15151 context_die = lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type)));
15153 TREE_ASM_WRITTEN (type) = 1;
15154 gen_decl_die (TYPE_NAME (type), NULL, context_die);
15158 /* If this is an array type with hidden descriptor, handle it first. */
15159 if (!TREE_ASM_WRITTEN (type)
15160 && lang_hooks.types.get_array_descr_info
15161 && lang_hooks.types.get_array_descr_info (type, &info))
15163 gen_descr_array_type_die (type, &info, context_die);
15164 TREE_ASM_WRITTEN (type) = 1;
15168 /* We are going to output a DIE to represent the unqualified version
15169 of this type (i.e. without any const or volatile qualifiers) so
15170 get the main variant (i.e. the unqualified version) of this type
15171 now. (Vectors are special because the debugging info is in the
15172 cloned type itself). */
15173 if (TREE_CODE (type) != VECTOR_TYPE)
15174 type = type_main_variant (type);
15176 if (TREE_ASM_WRITTEN (type))
15179 switch (TREE_CODE (type))
15185 case REFERENCE_TYPE:
15186 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
15187 ensures that the gen_type_die recursion will terminate even if the
15188 type is recursive. Recursive types are possible in Ada. */
15189 /* ??? We could perhaps do this for all types before the switch
15191 TREE_ASM_WRITTEN (type) = 1;
15193 /* For these types, all that is required is that we output a DIE (or a
15194 set of DIEs) to represent the "basis" type. */
15195 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15196 DINFO_USAGE_IND_USE);
15200 /* This code is used for C++ pointer-to-data-member types.
15201 Output a description of the relevant class type. */
15202 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
15203 DINFO_USAGE_IND_USE);
15205 /* Output a description of the type of the object pointed to. */
15206 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15207 DINFO_USAGE_IND_USE);
15209 /* Now output a DIE to represent this pointer-to-data-member type
15211 gen_ptr_to_mbr_type_die (type, context_die);
15214 case FUNCTION_TYPE:
15215 /* Force out return type (in case it wasn't forced out already). */
15216 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15217 DINFO_USAGE_DIR_USE);
15218 gen_subroutine_type_die (type, context_die);
15222 /* Force out return type (in case it wasn't forced out already). */
15223 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15224 DINFO_USAGE_DIR_USE);
15225 gen_subroutine_type_die (type, context_die);
15229 gen_array_type_die (type, context_die);
15233 gen_array_type_die (type, context_die);
15236 case ENUMERAL_TYPE:
15239 case QUAL_UNION_TYPE:
15240 /* If this is a nested type whose containing class hasn't been written
15241 out yet, writing it out will cover this one, too. This does not apply
15242 to instantiations of member class templates; they need to be added to
15243 the containing class as they are generated. FIXME: This hurts the
15244 idea of combining type decls from multiple TUs, since we can't predict
15245 what set of template instantiations we'll get. */
15246 if (TYPE_CONTEXT (type)
15247 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
15248 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
15250 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
15252 if (TREE_ASM_WRITTEN (type))
15255 /* If that failed, attach ourselves to the stub. */
15256 push_decl_scope (TYPE_CONTEXT (type));
15257 context_die = lookup_type_die (TYPE_CONTEXT (type));
15262 context_die = declare_in_namespace (type, context_die);
15266 if (TREE_CODE (type) == ENUMERAL_TYPE)
15268 /* This might have been written out by the call to
15269 declare_in_namespace. */
15270 if (!TREE_ASM_WRITTEN (type))
15271 gen_enumeration_type_die (type, context_die);
15274 gen_struct_or_union_type_die (type, context_die, usage);
15279 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
15280 it up if it is ever completed. gen_*_type_die will set it for us
15281 when appropriate. */
15287 case FIXED_POINT_TYPE:
15290 /* No DIEs needed for fundamental types. */
15294 /* No Dwarf representation currently defined. */
15298 gcc_unreachable ();
15301 TREE_ASM_WRITTEN (type) = 1;
15305 gen_type_die (tree type, dw_die_ref context_die)
15307 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
15310 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
15311 things which are local to the given block. */
15314 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
15316 int must_output_die = 0;
15319 /* Ignore blocks that are NULL. */
15320 if (stmt == NULL_TREE)
15323 inlined_func = inlined_function_outer_scope_p (stmt);
15325 /* If the block is one fragment of a non-contiguous block, do not
15326 process the variables, since they will have been done by the
15327 origin block. Do process subblocks. */
15328 if (BLOCK_FRAGMENT_ORIGIN (stmt))
15332 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
15333 gen_block_die (sub, context_die, depth + 1);
15338 /* Determine if we need to output any Dwarf DIEs at all to represent this
15341 /* The outer scopes for inlinings *must* always be represented. We
15342 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
15343 must_output_die = 1;
15346 /* Determine if this block directly contains any "significant"
15347 local declarations which we will need to output DIEs for. */
15348 if (debug_info_level > DINFO_LEVEL_TERSE)
15349 /* We are not in terse mode so *any* local declaration counts
15350 as being a "significant" one. */
15351 must_output_die = ((BLOCK_VARS (stmt) != NULL
15352 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
15353 && (TREE_USED (stmt)
15354 || TREE_ASM_WRITTEN (stmt)
15355 || BLOCK_ABSTRACT (stmt)));
15356 else if ((TREE_USED (stmt)
15357 || TREE_ASM_WRITTEN (stmt)
15358 || BLOCK_ABSTRACT (stmt))
15359 && !dwarf2out_ignore_block (stmt))
15360 must_output_die = 1;
15363 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
15364 DIE for any block which contains no significant local declarations at
15365 all. Rather, in such cases we just call `decls_for_scope' so that any
15366 needed Dwarf info for any sub-blocks will get properly generated. Note
15367 that in terse mode, our definition of what constitutes a "significant"
15368 local declaration gets restricted to include only inlined function
15369 instances and local (nested) function definitions. */
15370 if (must_output_die)
15373 gen_inlined_subroutine_die (stmt, context_die, depth);
15375 gen_lexical_block_die (stmt, context_die, depth);
15378 decls_for_scope (stmt, context_die, depth);
15381 /* Process variable DECL (or variable with origin ORIGIN) within
15382 block STMT and add it to CONTEXT_DIE. */
15384 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
15387 tree decl_or_origin = decl ? decl : origin;
15388 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
15390 if (ultimate_origin)
15391 origin = ultimate_origin;
15393 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
15394 die = lookup_decl_die (decl_or_origin);
15395 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
15396 && TYPE_DECL_IS_STUB (decl_or_origin))
15397 die = lookup_type_die (TREE_TYPE (decl_or_origin));
15401 if (die != NULL && die->die_parent == NULL)
15402 add_child_die (context_die, die);
15403 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
15404 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
15405 stmt, context_die);
15407 gen_decl_die (decl, origin, context_die);
15410 /* Generate all of the decls declared within a given scope and (recursively)
15411 all of its sub-blocks. */
15414 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
15420 /* Ignore NULL blocks. */
15421 if (stmt == NULL_TREE)
15424 /* Output the DIEs to represent all of the data objects and typedefs
15425 declared directly within this block but not within any nested
15426 sub-blocks. Also, nested function and tag DIEs have been
15427 generated with a parent of NULL; fix that up now. */
15428 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
15429 process_scope_var (stmt, decl, NULL_TREE, context_die);
15430 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
15431 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
15434 /* If we're at -g1, we're not interested in subblocks. */
15435 if (debug_info_level <= DINFO_LEVEL_TERSE)
15438 /* Output the DIEs to represent all sub-blocks (and the items declared
15439 therein) of this block. */
15440 for (subblocks = BLOCK_SUBBLOCKS (stmt);
15442 subblocks = BLOCK_CHAIN (subblocks))
15443 gen_block_die (subblocks, context_die, depth + 1);
15446 /* Is this a typedef we can avoid emitting? */
15449 is_redundant_typedef (const_tree decl)
15451 if (TYPE_DECL_IS_STUB (decl))
15454 if (DECL_ARTIFICIAL (decl)
15455 && DECL_CONTEXT (decl)
15456 && is_tagged_type (DECL_CONTEXT (decl))
15457 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
15458 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
15459 /* Also ignore the artificial member typedef for the class name. */
15465 /* Returns the DIE for a context. */
15467 static inline dw_die_ref
15468 get_context_die (tree context)
15472 /* Find die that represents this context. */
15473 if (TYPE_P (context))
15474 return force_type_die (context);
15476 return force_decl_die (context);
15478 return comp_unit_die;
15481 /* Returns the DIE for decl. A DIE will always be returned. */
15484 force_decl_die (tree decl)
15486 dw_die_ref decl_die;
15487 unsigned saved_external_flag;
15488 tree save_fn = NULL_TREE;
15489 decl_die = lookup_decl_die (decl);
15492 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15494 decl_die = lookup_decl_die (decl);
15498 switch (TREE_CODE (decl))
15500 case FUNCTION_DECL:
15501 /* Clear current_function_decl, so that gen_subprogram_die thinks
15502 that this is a declaration. At this point, we just want to force
15503 declaration die. */
15504 save_fn = current_function_decl;
15505 current_function_decl = NULL_TREE;
15506 gen_subprogram_die (decl, context_die);
15507 current_function_decl = save_fn;
15511 /* Set external flag to force declaration die. Restore it after
15512 gen_decl_die() call. */
15513 saved_external_flag = DECL_EXTERNAL (decl);
15514 DECL_EXTERNAL (decl) = 1;
15515 gen_decl_die (decl, NULL, context_die);
15516 DECL_EXTERNAL (decl) = saved_external_flag;
15519 case NAMESPACE_DECL:
15520 dwarf2out_decl (decl);
15524 gcc_unreachable ();
15527 /* We should be able to find the DIE now. */
15529 decl_die = lookup_decl_die (decl);
15530 gcc_assert (decl_die);
15536 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15537 always returned. */
15540 force_type_die (tree type)
15542 dw_die_ref type_die;
15544 type_die = lookup_type_die (type);
15547 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15549 type_die = modified_type_die (type, TYPE_READONLY (type),
15550 TYPE_VOLATILE (type), context_die);
15551 gcc_assert (type_die);
15556 /* Force out any required namespaces to be able to output DECL,
15557 and return the new context_die for it, if it's changed. */
15560 setup_namespace_context (tree thing, dw_die_ref context_die)
15562 tree context = (DECL_P (thing)
15563 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15564 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15565 /* Force out the namespace. */
15566 context_die = force_decl_die (context);
15568 return context_die;
15571 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15572 type) within its namespace, if appropriate.
15574 For compatibility with older debuggers, namespace DIEs only contain
15575 declarations; all definitions are emitted at CU scope. */
15578 declare_in_namespace (tree thing, dw_die_ref context_die)
15580 dw_die_ref ns_context;
15582 if (debug_info_level <= DINFO_LEVEL_TERSE)
15583 return context_die;
15585 /* If this decl is from an inlined function, then don't try to emit it in its
15586 namespace, as we will get confused. It would have already been emitted
15587 when the abstract instance of the inline function was emitted anyways. */
15588 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15589 return context_die;
15591 ns_context = setup_namespace_context (thing, context_die);
15593 if (ns_context != context_die)
15597 if (DECL_P (thing))
15598 gen_decl_die (thing, NULL, ns_context);
15600 gen_type_die (thing, ns_context);
15602 return context_die;
15605 /* Generate a DIE for a namespace or namespace alias. */
15608 gen_namespace_die (tree decl, dw_die_ref context_die)
15610 dw_die_ref namespace_die;
15612 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15613 they are an alias of. */
15614 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15616 /* Output a real namespace or module. */
15617 context_die = setup_namespace_context (decl, comp_unit_die);
15618 namespace_die = new_die (is_fortran ()
15619 ? DW_TAG_module : DW_TAG_namespace,
15620 context_die, decl);
15621 /* For Fortran modules defined in different CU don't add src coords. */
15622 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15623 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15625 add_name_and_src_coords_attributes (namespace_die, decl);
15626 if (DECL_EXTERNAL (decl))
15627 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15628 equate_decl_number_to_die (decl, namespace_die);
15632 /* Output a namespace alias. */
15634 /* Force out the namespace we are an alias of, if necessary. */
15635 dw_die_ref origin_die
15636 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15638 if (DECL_CONTEXT (decl) == NULL_TREE
15639 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15640 context_die = setup_namespace_context (decl, comp_unit_die);
15641 /* Now create the namespace alias DIE. */
15642 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15643 add_name_and_src_coords_attributes (namespace_die, decl);
15644 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15645 equate_decl_number_to_die (decl, namespace_die);
15649 /* Generate Dwarf debug information for a decl described by DECL. */
15652 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15654 tree decl_or_origin = decl ? decl : origin;
15655 tree class_origin = NULL;
15657 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15660 switch (TREE_CODE (decl_or_origin))
15666 if (!is_fortran ())
15668 /* The individual enumerators of an enum type get output when we output
15669 the Dwarf representation of the relevant enum type itself. */
15673 /* Emit its type. */
15674 gen_type_die (TREE_TYPE (decl), context_die);
15676 /* And its containing namespace. */
15677 context_die = declare_in_namespace (decl, context_die);
15679 gen_const_die (decl, context_die);
15682 case FUNCTION_DECL:
15683 /* Don't output any DIEs to represent mere function declarations,
15684 unless they are class members or explicit block externs. */
15685 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15686 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15687 && (current_function_decl == NULL_TREE
15688 || DECL_ARTIFICIAL (decl_or_origin)))
15693 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15694 on local redeclarations of global functions. That seems broken. */
15695 if (current_function_decl != decl)
15696 /* This is only a declaration. */;
15699 /* If we're emitting a clone, emit info for the abstract instance. */
15700 if (origin || DECL_ORIGIN (decl) != decl)
15701 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
15703 /* If we're emitting an out-of-line copy of an inline function,
15704 emit info for the abstract instance and set up to refer to it. */
15705 else if (cgraph_function_possibly_inlined_p (decl)
15706 && ! DECL_ABSTRACT (decl)
15707 && ! class_or_namespace_scope_p (context_die)
15708 /* dwarf2out_abstract_function won't emit a die if this is just
15709 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15710 that case, because that works only if we have a die. */
15711 && DECL_INITIAL (decl) != NULL_TREE)
15713 dwarf2out_abstract_function (decl);
15714 set_decl_origin_self (decl);
15717 /* Otherwise we're emitting the primary DIE for this decl. */
15718 else if (debug_info_level > DINFO_LEVEL_TERSE)
15720 /* Before we describe the FUNCTION_DECL itself, make sure that we
15721 have described its return type. */
15722 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15724 /* And its virtual context. */
15725 if (DECL_VINDEX (decl) != NULL_TREE)
15726 gen_type_die (DECL_CONTEXT (decl), context_die);
15728 /* And its containing type. */
15730 origin = decl_class_context (decl);
15731 if (origin != NULL_TREE)
15732 gen_type_die_for_member (origin, decl, context_die);
15734 /* And its containing namespace. */
15735 context_die = declare_in_namespace (decl, context_die);
15738 /* Now output a DIE to represent the function itself. */
15740 gen_subprogram_die (decl, context_die);
15744 /* If we are in terse mode, don't generate any DIEs to represent any
15745 actual typedefs. */
15746 if (debug_info_level <= DINFO_LEVEL_TERSE)
15749 /* In the special case of a TYPE_DECL node representing the declaration
15750 of some type tag, if the given TYPE_DECL is marked as having been
15751 instantiated from some other (original) TYPE_DECL node (e.g. one which
15752 was generated within the original definition of an inline function) we
15753 used to generate a special (abbreviated) DW_TAG_structure_type,
15754 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15755 should be actually referencing those DIEs, as variable DIEs with that
15756 type would be emitted already in the abstract origin, so it was always
15757 removed during unused type prunning. Don't add anything in this
15759 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
15762 if (is_redundant_typedef (decl))
15763 gen_type_die (TREE_TYPE (decl), context_die);
15765 /* Output a DIE to represent the typedef itself. */
15766 gen_typedef_die (decl, context_die);
15770 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15771 gen_label_die (decl, context_die);
15776 /* If we are in terse mode, don't generate any DIEs to represent any
15777 variable declarations or definitions. */
15778 if (debug_info_level <= DINFO_LEVEL_TERSE)
15781 /* Output any DIEs that are needed to specify the type of this data
15783 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
15784 || TREE_CODE (decl_or_origin) == VAR_DECL)
15785 && DECL_BY_REFERENCE (decl_or_origin))
15786 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15788 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15790 /* And its containing type. */
15791 class_origin = decl_class_context (decl_or_origin);
15792 if (class_origin != NULL_TREE)
15793 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
15795 /* And its containing namespace. */
15796 context_die = declare_in_namespace (decl_or_origin, context_die);
15798 /* Now output the DIE to represent the data object itself. This gets
15799 complicated because of the possibility that the VAR_DECL really
15800 represents an inlined instance of a formal parameter for an inline
15803 origin = decl_ultimate_origin (decl);
15804 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15805 gen_formal_parameter_die (decl, origin, context_die);
15807 gen_variable_die (decl, origin, context_die);
15811 /* Ignore the nameless fields that are used to skip bits but handle C++
15812 anonymous unions and structs. */
15813 if (DECL_NAME (decl) != NULL_TREE
15814 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15815 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15817 gen_type_die (member_declared_type (decl), context_die);
15818 gen_field_die (decl, context_die);
15823 if (DECL_BY_REFERENCE (decl_or_origin))
15824 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15826 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15827 gen_formal_parameter_die (decl, origin, context_die);
15830 case NAMESPACE_DECL:
15831 case IMPORTED_DECL:
15832 gen_namespace_die (decl, context_die);
15836 /* Probably some frontend-internal decl. Assume we don't care. */
15837 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15842 /* Output debug information for global decl DECL. Called from toplev.c after
15843 compilation proper has finished. */
15846 dwarf2out_global_decl (tree decl)
15848 /* Output DWARF2 information for file-scope tentative data object
15849 declarations, file-scope (extern) function declarations (which
15850 had no corresponding body) and file-scope tagged type declarations
15851 and definitions which have not yet been forced out. */
15852 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15853 dwarf2out_decl (decl);
15856 /* Output debug information for type decl DECL. Called from toplev.c
15857 and from language front ends (to record built-in types). */
15859 dwarf2out_type_decl (tree decl, int local)
15862 dwarf2out_decl (decl);
15865 /* Output debug information for imported module or decl DECL.
15866 NAME is non-NULL name in the lexical block if the decl has been renamed.
15867 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15868 that DECL belongs to.
15869 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15871 dwarf2out_imported_module_or_decl_1 (tree decl,
15873 tree lexical_block,
15874 dw_die_ref lexical_block_die)
15876 expanded_location xloc;
15877 dw_die_ref imported_die = NULL;
15878 dw_die_ref at_import_die;
15880 if (TREE_CODE (decl) == IMPORTED_DECL)
15882 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
15883 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
15887 xloc = expand_location (input_location);
15889 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15891 if (is_base_type (TREE_TYPE (decl)))
15892 at_import_die = base_type_die (TREE_TYPE (decl));
15894 at_import_die = force_type_die (TREE_TYPE (decl));
15895 /* For namespace N { typedef void T; } using N::T; base_type_die
15896 returns NULL, but DW_TAG_imported_declaration requires
15897 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15898 if (!at_import_die)
15900 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15901 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15902 at_import_die = lookup_type_die (TREE_TYPE (decl));
15903 gcc_assert (at_import_die);
15908 at_import_die = lookup_decl_die (decl);
15909 if (!at_import_die)
15911 /* If we're trying to avoid duplicate debug info, we may not have
15912 emitted the member decl for this field. Emit it now. */
15913 if (TREE_CODE (decl) == FIELD_DECL)
15915 tree type = DECL_CONTEXT (decl);
15917 if (TYPE_CONTEXT (type)
15918 && TYPE_P (TYPE_CONTEXT (type))
15919 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15920 DINFO_USAGE_DIR_USE))
15922 gen_type_die_for_member (type, decl,
15923 get_context_die (TYPE_CONTEXT (type)));
15925 at_import_die = force_decl_die (decl);
15929 if (TREE_CODE (decl) == NAMESPACE_DECL)
15930 imported_die = new_die (DW_TAG_imported_module,
15934 imported_die = new_die (DW_TAG_imported_declaration,
15938 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15939 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15941 add_AT_string (imported_die, DW_AT_name,
15942 IDENTIFIER_POINTER (name));
15943 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15946 /* Output debug information for imported module or decl DECL.
15947 NAME is non-NULL name in context if the decl has been renamed.
15948 CHILD is true if decl is one of the renamed decls as part of
15949 importing whole module. */
15952 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15955 /* dw_die_ref at_import_die; */
15956 dw_die_ref scope_die;
15958 if (debug_info_level <= DINFO_LEVEL_TERSE)
15963 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15964 We need decl DIE for reference and scope die. First, get DIE for the decl
15967 /* Get the scope die for decl context. Use comp_unit_die for global module
15968 or decl. If die is not found for non globals, force new die. */
15970 && TYPE_P (context)
15971 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15973 scope_die = get_context_die (context);
15977 gcc_assert (scope_die->die_child);
15978 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15979 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15980 scope_die = scope_die->die_child;
15983 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15984 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
15988 /* Write the debugging output for DECL. */
15991 dwarf2out_decl (tree decl)
15993 dw_die_ref context_die = comp_unit_die;
15995 switch (TREE_CODE (decl))
16000 case FUNCTION_DECL:
16001 /* What we would really like to do here is to filter out all mere
16002 file-scope declarations of file-scope functions which are never
16003 referenced later within this translation unit (and keep all of ones
16004 that *are* referenced later on) but we aren't clairvoyant, so we have
16005 no idea which functions will be referenced in the future (i.e. later
16006 on within the current translation unit). So here we just ignore all
16007 file-scope function declarations which are not also definitions. If
16008 and when the debugger needs to know something about these functions,
16009 it will have to hunt around and find the DWARF information associated
16010 with the definition of the function.
16012 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
16013 nodes represent definitions and which ones represent mere
16014 declarations. We have to check DECL_INITIAL instead. That's because
16015 the C front-end supports some weird semantics for "extern inline"
16016 function definitions. These can get inlined within the current
16017 translation unit (and thus, we need to generate Dwarf info for their
16018 abstract instances so that the Dwarf info for the concrete inlined
16019 instances can have something to refer to) but the compiler never
16020 generates any out-of-lines instances of such things (despite the fact
16021 that they *are* definitions).
16023 The important point is that the C front-end marks these "extern
16024 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
16025 them anyway. Note that the C++ front-end also plays some similar games
16026 for inline function definitions appearing within include files which
16027 also contain `#pragma interface' pragmas. */
16028 if (DECL_INITIAL (decl) == NULL_TREE)
16031 /* If we're a nested function, initially use a parent of NULL; if we're
16032 a plain function, this will be fixed up in decls_for_scope. If
16033 we're a method, it will be ignored, since we already have a DIE. */
16034 if (decl_function_context (decl)
16035 /* But if we're in terse mode, we don't care about scope. */
16036 && debug_info_level > DINFO_LEVEL_TERSE)
16037 context_die = NULL;
16041 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
16042 declaration and if the declaration was never even referenced from
16043 within this entire compilation unit. We suppress these DIEs in
16044 order to save space in the .debug section (by eliminating entries
16045 which are probably useless). Note that we must not suppress
16046 block-local extern declarations (whether used or not) because that
16047 would screw-up the debugger's name lookup mechanism and cause it to
16048 miss things which really ought to be in scope at a given point. */
16049 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
16052 /* For local statics lookup proper context die. */
16053 if (TREE_STATIC (decl) && decl_function_context (decl))
16054 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16056 /* If we are in terse mode, don't generate any DIEs to represent any
16057 variable declarations or definitions. */
16058 if (debug_info_level <= DINFO_LEVEL_TERSE)
16063 if (debug_info_level <= DINFO_LEVEL_TERSE)
16065 if (!is_fortran ())
16067 if (TREE_STATIC (decl) && decl_function_context (decl))
16068 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16071 case NAMESPACE_DECL:
16072 case IMPORTED_DECL:
16073 if (debug_info_level <= DINFO_LEVEL_TERSE)
16075 if (lookup_decl_die (decl) != NULL)
16080 /* Don't emit stubs for types unless they are needed by other DIEs. */
16081 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
16084 /* Don't bother trying to generate any DIEs to represent any of the
16085 normal built-in types for the language we are compiling. */
16086 if (DECL_IS_BUILTIN (decl))
16088 /* OK, we need to generate one for `bool' so GDB knows what type
16089 comparisons have. */
16091 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
16092 && ! DECL_IGNORED_P (decl))
16093 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
16098 /* If we are in terse mode, don't generate any DIEs for types. */
16099 if (debug_info_level <= DINFO_LEVEL_TERSE)
16102 /* If we're a function-scope tag, initially use a parent of NULL;
16103 this will be fixed up in decls_for_scope. */
16104 if (decl_function_context (decl))
16105 context_die = NULL;
16113 gen_decl_die (decl, NULL, context_die);
16116 /* Output a marker (i.e. a label) for the beginning of the generated code for
16117 a lexical block. */
16120 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
16121 unsigned int blocknum)
16123 switch_to_section (current_function_section ());
16124 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
16127 /* Output a marker (i.e. a label) for the end of the generated code for a
16131 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
16133 switch_to_section (current_function_section ());
16134 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
16137 /* Returns nonzero if it is appropriate not to emit any debugging
16138 information for BLOCK, because it doesn't contain any instructions.
16140 Don't allow this for blocks with nested functions or local classes
16141 as we would end up with orphans, and in the presence of scheduling
16142 we may end up calling them anyway. */
16145 dwarf2out_ignore_block (const_tree block)
16150 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
16151 if (TREE_CODE (decl) == FUNCTION_DECL
16152 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16154 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
16156 decl = BLOCK_NONLOCALIZED_VAR (block, i);
16157 if (TREE_CODE (decl) == FUNCTION_DECL
16158 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16165 /* Hash table routines for file_hash. */
16168 file_table_eq (const void *p1_p, const void *p2_p)
16170 const struct dwarf_file_data *const p1 =
16171 (const struct dwarf_file_data *) p1_p;
16172 const char *const p2 = (const char *) p2_p;
16173 return strcmp (p1->filename, p2) == 0;
16177 file_table_hash (const void *p_p)
16179 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
16180 return htab_hash_string (p->filename);
16183 /* Lookup FILE_NAME (in the list of filenames that we know about here in
16184 dwarf2out.c) and return its "index". The index of each (known) filename is
16185 just a unique number which is associated with only that one filename. We
16186 need such numbers for the sake of generating labels (in the .debug_sfnames
16187 section) and references to those files numbers (in the .debug_srcinfo
16188 and.debug_macinfo sections). If the filename given as an argument is not
16189 found in our current list, add it to the list and assign it the next
16190 available unique index number. In order to speed up searches, we remember
16191 the index of the filename was looked up last. This handles the majority of
16194 static struct dwarf_file_data *
16195 lookup_filename (const char *file_name)
16198 struct dwarf_file_data * created;
16200 /* Check to see if the file name that was searched on the previous
16201 call matches this file name. If so, return the index. */
16202 if (file_table_last_lookup
16203 && (file_name == file_table_last_lookup->filename
16204 || strcmp (file_table_last_lookup->filename, file_name) == 0))
16205 return file_table_last_lookup;
16207 /* Didn't match the previous lookup, search the table. */
16208 slot = htab_find_slot_with_hash (file_table, file_name,
16209 htab_hash_string (file_name), INSERT);
16211 return (struct dwarf_file_data *) *slot;
16213 created = GGC_NEW (struct dwarf_file_data);
16214 created->filename = file_name;
16215 created->emitted_number = 0;
16220 /* If the assembler will construct the file table, then translate the compiler
16221 internal file table number into the assembler file table number, and emit
16222 a .file directive if we haven't already emitted one yet. The file table
16223 numbers are different because we prune debug info for unused variables and
16224 types, which may include filenames. */
16227 maybe_emit_file (struct dwarf_file_data * fd)
16229 if (! fd->emitted_number)
16231 if (last_emitted_file)
16232 fd->emitted_number = last_emitted_file->emitted_number + 1;
16234 fd->emitted_number = 1;
16235 last_emitted_file = fd;
16237 if (DWARF2_ASM_LINE_DEBUG_INFO)
16239 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
16240 output_quoted_string (asm_out_file,
16241 remap_debug_filename (fd->filename));
16242 fputc ('\n', asm_out_file);
16246 return fd->emitted_number;
16249 /* Replace DW_AT_name for the decl with name. */
16252 dwarf2out_set_name (tree decl, tree name)
16257 die = TYPE_SYMTAB_DIE (decl);
16261 attr = get_AT (die, DW_AT_name);
16264 struct indirect_string_node *node;
16266 node = find_AT_string (dwarf2_name (name, 0));
16267 /* replace the string. */
16268 attr->dw_attr_val.v.val_str = node;
16272 add_name_attribute (die, dwarf2_name (name, 0));
16275 /* Called by the final INSN scan whenever we see a var location. We
16276 use it to drop labels in the right places, and throw the location in
16277 our lookup table. */
16280 dwarf2out_var_location (rtx loc_note)
16282 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
16283 struct var_loc_node *newloc;
16285 static const char *last_label;
16286 static bool last_in_cold_section_p;
16289 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
16292 next_real = next_real_insn (loc_note);
16293 /* If there are no instructions which would be affected by this note,
16294 don't do anything. */
16295 if (next_real == NULL_RTX)
16298 newloc = GGC_CNEW (struct var_loc_node);
16299 /* If there were no real insns between note we processed last time
16300 and this note, use the label we emitted last time. */
16301 if (last_var_location_insn != NULL_RTX
16302 && last_var_location_insn == next_real
16303 && last_in_cold_section_p == in_cold_section_p)
16304 newloc->label = last_label;
16307 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
16308 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
16310 newloc->label = ggc_strdup (loclabel);
16312 newloc->var_loc_note = loc_note;
16313 newloc->next = NULL;
16315 if (cfun && in_cold_section_p)
16316 newloc->section_label = crtl->subsections.cold_section_label;
16318 newloc->section_label = text_section_label;
16320 last_var_location_insn = next_real;
16321 last_label = newloc->label;
16322 last_in_cold_section_p = in_cold_section_p;
16323 decl = NOTE_VAR_LOCATION_DECL (loc_note);
16324 add_var_loc_to_decl (decl, newloc);
16327 /* We need to reset the locations at the beginning of each
16328 function. We can't do this in the end_function hook, because the
16329 declarations that use the locations won't have been output when
16330 that hook is called. Also compute have_multiple_function_sections here. */
16333 dwarf2out_begin_function (tree fun)
16335 htab_empty (decl_loc_table);
16337 if (function_section (fun) != text_section)
16338 have_multiple_function_sections = true;
16340 dwarf2out_note_section_used ();
16343 /* Output a label to mark the beginning of a source code line entry
16344 and record information relating to this source line, in
16345 'line_info_table' for later output of the .debug_line section. */
16348 dwarf2out_source_line (unsigned int line, const char *filename,
16349 int discriminator, bool is_stmt)
16351 static bool last_is_stmt = true;
16353 if (debug_info_level >= DINFO_LEVEL_NORMAL
16356 int file_num = maybe_emit_file (lookup_filename (filename));
16358 switch_to_section (current_function_section ());
16360 /* If requested, emit something human-readable. */
16361 if (flag_debug_asm)
16362 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
16365 if (DWARF2_ASM_LINE_DEBUG_INFO)
16367 /* Emit the .loc directive understood by GNU as. */
16368 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
16369 if (is_stmt != last_is_stmt)
16371 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
16372 last_is_stmt = is_stmt;
16374 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
16375 fprintf (asm_out_file, " discriminator %d", discriminator);
16376 fputc ('\n', asm_out_file);
16378 /* Indicate that line number info exists. */
16379 line_info_table_in_use++;
16381 else if (function_section (current_function_decl) != text_section)
16383 dw_separate_line_info_ref line_info;
16384 targetm.asm_out.internal_label (asm_out_file,
16385 SEPARATE_LINE_CODE_LABEL,
16386 separate_line_info_table_in_use);
16388 /* Expand the line info table if necessary. */
16389 if (separate_line_info_table_in_use
16390 == separate_line_info_table_allocated)
16392 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16393 separate_line_info_table
16394 = GGC_RESIZEVEC (dw_separate_line_info_entry,
16395 separate_line_info_table,
16396 separate_line_info_table_allocated);
16397 memset (separate_line_info_table
16398 + separate_line_info_table_in_use,
16400 (LINE_INFO_TABLE_INCREMENT
16401 * sizeof (dw_separate_line_info_entry)));
16404 /* Add the new entry at the end of the line_info_table. */
16406 = &separate_line_info_table[separate_line_info_table_in_use++];
16407 line_info->dw_file_num = file_num;
16408 line_info->dw_line_num = line;
16409 line_info->function = current_function_funcdef_no;
16413 dw_line_info_ref line_info;
16415 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
16416 line_info_table_in_use);
16418 /* Expand the line info table if necessary. */
16419 if (line_info_table_in_use == line_info_table_allocated)
16421 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16423 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
16424 line_info_table_allocated);
16425 memset (line_info_table + line_info_table_in_use, 0,
16426 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
16429 /* Add the new entry at the end of the line_info_table. */
16430 line_info = &line_info_table[line_info_table_in_use++];
16431 line_info->dw_file_num = file_num;
16432 line_info->dw_line_num = line;
16437 /* Record the beginning of a new source file. */
16440 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
16442 if (flag_eliminate_dwarf2_dups)
16444 /* Record the beginning of the file for break_out_includes. */
16445 dw_die_ref bincl_die;
16447 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
16448 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
16451 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16453 int file_num = maybe_emit_file (lookup_filename (filename));
16455 switch_to_section (debug_macinfo_section);
16456 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
16457 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
16460 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
16464 /* Record the end of a source file. */
16467 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
16469 if (flag_eliminate_dwarf2_dups)
16470 /* Record the end of the file for break_out_includes. */
16471 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
16473 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16475 switch_to_section (debug_macinfo_section);
16476 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
16480 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16481 the tail part of the directive line, i.e. the part which is past the
16482 initial whitespace, #, whitespace, directive-name, whitespace part. */
16485 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
16486 const char *buffer ATTRIBUTE_UNUSED)
16488 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16490 switch_to_section (debug_macinfo_section);
16491 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
16492 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16493 dw2_asm_output_nstring (buffer, -1, "The macro");
16497 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16498 the tail part of the directive line, i.e. the part which is past the
16499 initial whitespace, #, whitespace, directive-name, whitespace part. */
16502 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
16503 const char *buffer ATTRIBUTE_UNUSED)
16505 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16507 switch_to_section (debug_macinfo_section);
16508 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
16509 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16510 dw2_asm_output_nstring (buffer, -1, "The macro");
16514 /* Set up for Dwarf output at the start of compilation. */
16517 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
16519 /* Allocate the file_table. */
16520 file_table = htab_create_ggc (50, file_table_hash,
16521 file_table_eq, NULL);
16523 /* Allocate the decl_die_table. */
16524 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16525 decl_die_table_eq, NULL);
16527 /* Allocate the decl_loc_table. */
16528 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16529 decl_loc_table_eq, NULL);
16531 /* Allocate the initial hunk of the decl_scope_table. */
16532 decl_scope_table = VEC_alloc (tree, gc, 256);
16534 /* Allocate the initial hunk of the abbrev_die_table. */
16535 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16536 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16537 /* Zero-th entry is allocated, but unused. */
16538 abbrev_die_table_in_use = 1;
16540 /* Allocate the initial hunk of the line_info_table. */
16541 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16542 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16544 /* Zero-th entry is allocated, but unused. */
16545 line_info_table_in_use = 1;
16547 /* Allocate the pubtypes and pubnames vectors. */
16548 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16549 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16551 /* Generate the initial DIE for the .debug section. Note that the (string)
16552 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16553 will (typically) be a relative pathname and that this pathname should be
16554 taken as being relative to the directory from which the compiler was
16555 invoked when the given (base) source file was compiled. We will fill
16556 in this value in dwarf2out_finish. */
16557 comp_unit_die = gen_compile_unit_die (NULL);
16559 incomplete_types = VEC_alloc (tree, gc, 64);
16561 used_rtx_array = VEC_alloc (rtx, gc, 32);
16563 debug_info_section = get_section (DEBUG_INFO_SECTION,
16564 SECTION_DEBUG, NULL);
16565 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16566 SECTION_DEBUG, NULL);
16567 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16568 SECTION_DEBUG, NULL);
16569 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16570 SECTION_DEBUG, NULL);
16571 debug_line_section = get_section (DEBUG_LINE_SECTION,
16572 SECTION_DEBUG, NULL);
16573 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16574 SECTION_DEBUG, NULL);
16575 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16576 SECTION_DEBUG, NULL);
16577 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16578 SECTION_DEBUG, NULL);
16579 debug_str_section = get_section (DEBUG_STR_SECTION,
16580 DEBUG_STR_SECTION_FLAGS, NULL);
16581 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16582 SECTION_DEBUG, NULL);
16583 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16584 SECTION_DEBUG, NULL);
16586 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16587 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16588 DEBUG_ABBREV_SECTION_LABEL, 0);
16589 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16590 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16591 COLD_TEXT_SECTION_LABEL, 0);
16592 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16594 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16595 DEBUG_INFO_SECTION_LABEL, 0);
16596 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16597 DEBUG_LINE_SECTION_LABEL, 0);
16598 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16599 DEBUG_RANGES_SECTION_LABEL, 0);
16600 switch_to_section (debug_abbrev_section);
16601 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16602 switch_to_section (debug_info_section);
16603 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16604 switch_to_section (debug_line_section);
16605 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16607 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16609 switch_to_section (debug_macinfo_section);
16610 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16611 DEBUG_MACINFO_SECTION_LABEL, 0);
16612 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16615 switch_to_section (text_section);
16616 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16617 if (flag_reorder_blocks_and_partition)
16619 cold_text_section = unlikely_text_section ();
16620 switch_to_section (cold_text_section);
16621 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16625 /* A helper function for dwarf2out_finish called through
16626 ht_forall. Emit one queued .debug_str string. */
16629 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16631 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16633 if (node->form == DW_FORM_strp)
16635 switch_to_section (debug_str_section);
16636 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16637 assemble_string (node->str, strlen (node->str) + 1);
16643 #if ENABLE_ASSERT_CHECKING
16644 /* Verify that all marks are clear. */
16647 verify_marks_clear (dw_die_ref die)
16651 gcc_assert (! die->die_mark);
16652 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16654 #endif /* ENABLE_ASSERT_CHECKING */
16656 /* Clear the marks for a die and its children.
16657 Be cool if the mark isn't set. */
16660 prune_unmark_dies (dw_die_ref die)
16666 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16669 /* Given DIE that we're marking as used, find any other dies
16670 it references as attributes and mark them as used. */
16673 prune_unused_types_walk_attribs (dw_die_ref die)
16678 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16680 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16682 /* A reference to another DIE.
16683 Make sure that it will get emitted. */
16684 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16686 /* Set the string's refcount to 0 so that prune_unused_types_mark
16687 accounts properly for it. */
16688 if (AT_class (a) == dw_val_class_str)
16689 a->dw_attr_val.v.val_str->refcount = 0;
16694 /* Mark DIE as being used. If DOKIDS is true, then walk down
16695 to DIE's children. */
16698 prune_unused_types_mark (dw_die_ref die, int dokids)
16702 if (die->die_mark == 0)
16704 /* We haven't done this node yet. Mark it as used. */
16707 /* We also have to mark its parents as used.
16708 (But we don't want to mark our parents' kids due to this.) */
16709 if (die->die_parent)
16710 prune_unused_types_mark (die->die_parent, 0);
16712 /* Mark any referenced nodes. */
16713 prune_unused_types_walk_attribs (die);
16715 /* If this node is a specification,
16716 also mark the definition, if it exists. */
16717 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
16718 prune_unused_types_mark (die->die_definition, 1);
16721 if (dokids && die->die_mark != 2)
16723 /* We need to walk the children, but haven't done so yet.
16724 Remember that we've walked the kids. */
16727 /* If this is an array type, we need to make sure our
16728 kids get marked, even if they're types. */
16729 if (die->die_tag == DW_TAG_array_type)
16730 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
16732 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16736 /* For local classes, look if any static member functions were emitted
16737 and if so, mark them. */
16740 prune_unused_types_walk_local_classes (dw_die_ref die)
16744 if (die->die_mark == 2)
16747 switch (die->die_tag)
16749 case DW_TAG_structure_type:
16750 case DW_TAG_union_type:
16751 case DW_TAG_class_type:
16754 case DW_TAG_subprogram:
16755 if (!get_AT_flag (die, DW_AT_declaration)
16756 || die->die_definition != NULL)
16757 prune_unused_types_mark (die, 1);
16764 /* Mark children. */
16765 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
16768 /* Walk the tree DIE and mark types that we actually use. */
16771 prune_unused_types_walk (dw_die_ref die)
16775 /* Don't do anything if this node is already marked and
16776 children have been marked as well. */
16777 if (die->die_mark == 2)
16780 switch (die->die_tag)
16782 case DW_TAG_structure_type:
16783 case DW_TAG_union_type:
16784 case DW_TAG_class_type:
16785 if (die->die_perennial_p)
16788 for (c = die->die_parent; c; c = c->die_parent)
16789 if (c->die_tag == DW_TAG_subprogram)
16792 /* Finding used static member functions inside of classes
16793 is needed just for local classes, because for other classes
16794 static member function DIEs with DW_AT_specification
16795 are emitted outside of the DW_TAG_*_type. If we ever change
16796 it, we'd need to call this even for non-local classes. */
16798 prune_unused_types_walk_local_classes (die);
16800 /* It's a type node --- don't mark it. */
16803 case DW_TAG_const_type:
16804 case DW_TAG_packed_type:
16805 case DW_TAG_pointer_type:
16806 case DW_TAG_reference_type:
16807 case DW_TAG_volatile_type:
16808 case DW_TAG_typedef:
16809 case DW_TAG_array_type:
16810 case DW_TAG_interface_type:
16811 case DW_TAG_friend:
16812 case DW_TAG_variant_part:
16813 case DW_TAG_enumeration_type:
16814 case DW_TAG_subroutine_type:
16815 case DW_TAG_string_type:
16816 case DW_TAG_set_type:
16817 case DW_TAG_subrange_type:
16818 case DW_TAG_ptr_to_member_type:
16819 case DW_TAG_file_type:
16820 if (die->die_perennial_p)
16823 /* It's a type node --- don't mark it. */
16827 /* Mark everything else. */
16831 if (die->die_mark == 0)
16835 /* Now, mark any dies referenced from here. */
16836 prune_unused_types_walk_attribs (die);
16841 /* Mark children. */
16842 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16845 /* Increment the string counts on strings referred to from DIE's
16849 prune_unused_types_update_strings (dw_die_ref die)
16854 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16855 if (AT_class (a) == dw_val_class_str)
16857 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
16859 /* Avoid unnecessarily putting strings that are used less than
16860 twice in the hash table. */
16862 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
16865 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
16866 htab_hash_string (s->str),
16868 gcc_assert (*slot == NULL);
16874 /* Remove from the tree DIE any dies that aren't marked. */
16877 prune_unused_types_prune (dw_die_ref die)
16881 gcc_assert (die->die_mark);
16882 prune_unused_types_update_strings (die);
16884 if (! die->die_child)
16887 c = die->die_child;
16889 dw_die_ref prev = c;
16890 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
16891 if (c == die->die_child)
16893 /* No marked children between 'prev' and the end of the list. */
16895 /* No marked children at all. */
16896 die->die_child = NULL;
16899 prev->die_sib = c->die_sib;
16900 die->die_child = prev;
16905 if (c != prev->die_sib)
16907 prune_unused_types_prune (c);
16908 } while (c != die->die_child);
16912 /* Remove dies representing declarations that we never use. */
16915 prune_unused_types (void)
16918 limbo_die_node *node;
16921 #if ENABLE_ASSERT_CHECKING
16922 /* All the marks should already be clear. */
16923 verify_marks_clear (comp_unit_die);
16924 for (node = limbo_die_list; node; node = node->next)
16925 verify_marks_clear (node->die);
16926 #endif /* ENABLE_ASSERT_CHECKING */
16928 /* Set the mark on nodes that are actually used. */
16929 prune_unused_types_walk (comp_unit_die);
16930 for (node = limbo_die_list; node; node = node->next)
16931 prune_unused_types_walk (node->die);
16933 /* Also set the mark on nodes referenced from the
16934 pubname_table or arange_table. */
16935 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
16936 prune_unused_types_mark (pub->die, 1);
16937 for (i = 0; i < arange_table_in_use; i++)
16938 prune_unused_types_mark (arange_table[i], 1);
16940 /* Get rid of nodes that aren't marked; and update the string counts. */
16941 if (debug_str_hash)
16942 htab_empty (debug_str_hash);
16943 prune_unused_types_prune (comp_unit_die);
16944 for (node = limbo_die_list; node; node = node->next)
16945 prune_unused_types_prune (node->die);
16947 /* Leave the marks clear. */
16948 prune_unmark_dies (comp_unit_die);
16949 for (node = limbo_die_list; node; node = node->next)
16950 prune_unmark_dies (node->die);
16953 /* Set the parameter to true if there are any relative pathnames in
16956 file_table_relative_p (void ** slot, void *param)
16958 bool *p = (bool *) param;
16959 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16960 if (!IS_ABSOLUTE_PATH (d->filename))
16968 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
16969 to the location it would have been added, should we know its
16970 DECL_ASSEMBLER_NAME when we added other attributes. This will
16971 probably improve compactness of debug info, removing equivalent
16972 abbrevs, and hide any differences caused by deferring the
16973 computation of the assembler name, triggered by e.g. PCH. */
16976 move_linkage_attr (dw_die_ref die)
16978 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
16979 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
16981 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
16985 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
16987 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
16991 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
16993 VEC_pop (dw_attr_node, die->die_attr);
16994 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
16998 /* Output stuff that dwarf requires at the end of every file,
16999 and generate the DWARF-2 debugging info. */
17002 dwarf2out_finish (const char *filename)
17004 limbo_die_node *node, *next_node;
17005 dw_die_ref die = 0;
17008 /* Add the name for the main input file now. We delayed this from
17009 dwarf2out_init to avoid complications with PCH. */
17010 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
17011 if (!IS_ABSOLUTE_PATH (filename))
17012 add_comp_dir_attribute (comp_unit_die);
17013 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
17016 htab_traverse (file_table, file_table_relative_p, &p);
17018 add_comp_dir_attribute (comp_unit_die);
17021 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
17023 add_location_or_const_value_attribute (
17024 VEC_index (deferred_locations, deferred_locations_list, i)->die,
17025 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
17029 /* Traverse the limbo die list, and add parent/child links. The only
17030 dies without parents that should be here are concrete instances of
17031 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
17032 For concrete instances, we can get the parent die from the abstract
17034 for (node = limbo_die_list; node; node = next_node)
17036 next_node = node->next;
17039 if (die->die_parent == NULL)
17041 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
17044 add_child_die (origin->die_parent, die);
17045 else if (die == comp_unit_die)
17047 else if (errorcount > 0 || sorrycount > 0)
17048 /* It's OK to be confused by errors in the input. */
17049 add_child_die (comp_unit_die, die);
17052 /* In certain situations, the lexical block containing a
17053 nested function can be optimized away, which results
17054 in the nested function die being orphaned. Likewise
17055 with the return type of that nested function. Force
17056 this to be a child of the containing function.
17058 It may happen that even the containing function got fully
17059 inlined and optimized out. In that case we are lost and
17060 assign the empty child. This should not be big issue as
17061 the function is likely unreachable too. */
17062 tree context = NULL_TREE;
17064 gcc_assert (node->created_for);
17066 if (DECL_P (node->created_for))
17067 context = DECL_CONTEXT (node->created_for);
17068 else if (TYPE_P (node->created_for))
17069 context = TYPE_CONTEXT (node->created_for);
17071 gcc_assert (context
17072 && (TREE_CODE (context) == FUNCTION_DECL
17073 || TREE_CODE (context) == NAMESPACE_DECL));
17075 origin = lookup_decl_die (context);
17077 add_child_die (origin, die);
17079 add_child_die (comp_unit_die, die);
17084 limbo_die_list = NULL;
17086 for (node = deferred_asm_name; node; node = node->next)
17088 tree decl = node->created_for;
17089 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17091 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
17092 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
17093 move_linkage_attr (node->die);
17097 deferred_asm_name = NULL;
17099 /* Walk through the list of incomplete types again, trying once more to
17100 emit full debugging info for them. */
17101 retry_incomplete_types ();
17103 if (flag_eliminate_unused_debug_types)
17104 prune_unused_types ();
17106 /* Generate separate CUs for each of the include files we've seen.
17107 They will go into limbo_die_list. */
17108 if (flag_eliminate_dwarf2_dups)
17109 break_out_includes (comp_unit_die);
17111 /* Traverse the DIE's and add add sibling attributes to those DIE's
17112 that have children. */
17113 add_sibling_attributes (comp_unit_die);
17114 for (node = limbo_die_list; node; node = node->next)
17115 add_sibling_attributes (node->die);
17117 /* Output a terminator label for the .text section. */
17118 switch_to_section (text_section);
17119 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
17120 if (flag_reorder_blocks_and_partition)
17122 switch_to_section (unlikely_text_section ());
17123 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
17126 /* We can only use the low/high_pc attributes if all of the code was
17128 if (!have_multiple_function_sections)
17130 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
17131 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
17136 unsigned fde_idx = 0;
17138 /* We need to give .debug_loc and .debug_ranges an appropriate
17139 "base address". Use zero so that these addresses become
17140 absolute. Historically, we've emitted the unexpected
17141 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
17142 Emit both to give time for other tools to adapt. */
17143 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
17144 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
17146 add_AT_range_list (comp_unit_die, DW_AT_ranges,
17147 add_ranges_by_labels (text_section_label,
17149 if (flag_reorder_blocks_and_partition)
17150 add_ranges_by_labels (cold_text_section_label,
17153 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
17155 dw_fde_ref fde = &fde_table[fde_idx];
17157 if (fde->dw_fde_switched_sections)
17159 if (!fde->in_std_section)
17160 add_ranges_by_labels (fde->dw_fde_hot_section_label,
17161 fde->dw_fde_hot_section_end_label);
17162 if (!fde->cold_in_std_section)
17163 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
17164 fde->dw_fde_unlikely_section_end_label);
17166 else if (!fde->in_std_section)
17167 add_ranges_by_labels (fde->dw_fde_begin,
17174 /* Output location list section if necessary. */
17175 if (have_location_lists)
17177 /* Output the location lists info. */
17178 switch_to_section (debug_loc_section);
17179 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
17180 DEBUG_LOC_SECTION_LABEL, 0);
17181 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
17182 output_location_lists (die);
17185 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17186 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
17187 debug_line_section_label);
17189 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17190 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
17192 /* Output all of the compilation units. We put the main one last so that
17193 the offsets are available to output_pubnames. */
17194 for (node = limbo_die_list; node; node = node->next)
17195 output_comp_unit (node->die, 0);
17197 /* Output the main compilation unit if non-empty or if .debug_macinfo
17198 has been emitted. */
17199 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
17201 /* Output the abbreviation table. */
17202 switch_to_section (debug_abbrev_section);
17203 output_abbrev_section ();
17205 /* Output public names table if necessary. */
17206 if (!VEC_empty (pubname_entry, pubname_table))
17208 switch_to_section (debug_pubnames_section);
17209 output_pubnames (pubname_table);
17212 /* Output public types table if necessary. */
17213 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
17214 It shouldn't hurt to emit it always, since pure DWARF2 consumers
17215 simply won't look for the section. */
17216 if (!VEC_empty (pubname_entry, pubtype_table))
17218 switch_to_section (debug_pubtypes_section);
17219 output_pubnames (pubtype_table);
17222 /* Output the address range information. We only put functions in the arange
17223 table, so don't write it out if we don't have any. */
17224 if (fde_table_in_use)
17226 switch_to_section (debug_aranges_section);
17230 /* Output ranges section if necessary. */
17231 if (ranges_table_in_use)
17233 switch_to_section (debug_ranges_section);
17234 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
17238 /* Output the source line correspondence table. We must do this
17239 even if there is no line information. Otherwise, on an empty
17240 translation unit, we will generate a present, but empty,
17241 .debug_info section. IRIX 6.5 `nm' will then complain when
17242 examining the file. This is done late so that any filenames
17243 used by the debug_info section are marked as 'used'. */
17244 if (! DWARF2_ASM_LINE_DEBUG_INFO)
17246 switch_to_section (debug_line_section);
17247 output_line_info ();
17250 /* Have to end the macro section. */
17251 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17253 switch_to_section (debug_macinfo_section);
17254 dw2_asm_output_data (1, 0, "End compilation unit");
17257 /* If we emitted any DW_FORM_strp form attribute, output the string
17259 if (debug_str_hash)
17260 htab_traverse (debug_str_hash, output_indirect_string, NULL);
17264 /* This should never be used, but its address is needed for comparisons. */
17265 const struct gcc_debug_hooks dwarf2_debug_hooks =
17271 0, /* start_source_file */
17272 0, /* end_source_file */
17273 0, /* begin_block */
17275 0, /* ignore_block */
17276 0, /* source_line */
17277 0, /* begin_prologue */
17278 0, /* end_prologue */
17279 0, /* end_epilogue */
17280 0, /* begin_function */
17281 0, /* end_function */
17282 0, /* function_decl */
17283 0, /* global_decl */
17285 0, /* imported_module_or_decl */
17286 0, /* deferred_inline_function */
17287 0, /* outlining_inline_function */
17289 0, /* handle_pch */
17290 0, /* var_location */
17291 0, /* switch_text_section */
17293 0 /* start_end_main_source_file */
17296 #endif /* DWARF2_DEBUGGING_INFO */
17298 #include "gt-dwarf2out.h"