1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx,gc) *used_rtx_array;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree,gc) *incomplete_types;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree,gc) *decl_scope_table;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section *debug_info_section;
157 static GTY(()) section *debug_abbrev_section;
158 static GTY(()) section *debug_aranges_section;
159 static GTY(()) section *debug_macinfo_section;
160 static GTY(()) section *debug_line_section;
161 static GTY(()) section *debug_loc_section;
162 static GTY(()) section *debug_pubnames_section;
163 static GTY(()) section *debug_pubtypes_section;
164 static GTY(()) section *debug_str_section;
165 static GTY(()) section *debug_ranges_section;
166 static GTY(()) section *debug_frame_section;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct *dw_cfi_ref;
174 typedef struct dw_fde_struct *dw_fde_ref;
175 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type {
184 dw_cfi_oprnd_reg_num,
190 typedef union dw_cfi_oprnd_struct GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
193 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
195 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
199 typedef struct dw_cfi_struct GTY(())
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc GTY(())
217 HOST_WIDE_INT offset;
218 HOST_WIDE_INT base_offset;
220 int indirect; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct GTY(())
232 const char *dw_fde_begin;
233 const char *dw_fde_current_label;
234 const char *dw_fde_end;
235 const char *dw_fde_hot_section_label;
236 const char *dw_fde_hot_section_end_label;
237 const char *dw_fde_unlikely_section_label;
238 const char *dw_fde_unlikely_section_end_label;
239 bool dw_fde_switched_sections;
240 dw_cfi_ref dw_fde_cfi;
241 unsigned funcdef_number;
242 HOST_WIDE_INT stack_realignment;
243 /* Dynamic realign argument pointer register. */
244 unsigned int drap_reg;
245 /* Virtual dynamic realign argument pointer register. */
246 unsigned int vdrap_reg;
247 unsigned all_throwers_are_sibcalls : 1;
248 unsigned nothrow : 1;
249 unsigned uses_eh_lsda : 1;
250 /* Whether we did stack realign in this call frame. */
251 unsigned stack_realign : 1;
252 /* Whether dynamic realign argument pointer register has been saved. */
253 unsigned drap_reg_saved: 1;
257 /* Maximum size (in bytes) of an artificially generated label. */
258 #define MAX_ARTIFICIAL_LABEL_BYTES 30
260 /* The size of addresses as they appear in the Dwarf 2 data.
261 Some architectures use word addresses to refer to code locations,
262 but Dwarf 2 info always uses byte addresses. On such machines,
263 Dwarf 2 addresses need to be larger than the architecture's
265 #ifndef DWARF2_ADDR_SIZE
266 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
269 /* The size in bytes of a DWARF field indicating an offset or length
270 relative to a debug info section, specified to be 4 bytes in the
271 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
274 #ifndef DWARF_OFFSET_SIZE
275 #define DWARF_OFFSET_SIZE 4
278 /* According to the (draft) DWARF 3 specification, the initial length
279 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
280 bytes are 0xffffffff, followed by the length stored in the next 8
283 However, the SGI/MIPS ABI uses an initial length which is equal to
284 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
286 #ifndef DWARF_INITIAL_LENGTH_SIZE
287 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
290 #define DWARF_VERSION 2
292 /* Round SIZE up to the nearest BOUNDARY. */
293 #define DWARF_ROUND(SIZE,BOUNDARY) \
294 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
296 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
297 #ifndef DWARF_CIE_DATA_ALIGNMENT
298 #ifdef STACK_GROWS_DOWNWARD
299 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
301 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
305 /* CIE identifier. */
306 #if HOST_BITS_PER_WIDE_INT >= 64
307 #define DWARF_CIE_ID \
308 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
310 #define DWARF_CIE_ID DW_CIE_ID
313 /* A pointer to the base of a table that contains frame description
314 information for each routine. */
315 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
317 /* Number of elements currently allocated for fde_table. */
318 static GTY(()) unsigned fde_table_allocated;
320 /* Number of elements in fde_table currently in use. */
321 static GTY(()) unsigned fde_table_in_use;
323 /* Size (in elements) of increments by which we may expand the
325 #define FDE_TABLE_INCREMENT 256
327 /* Get the current fde_table entry we should use. */
329 static inline dw_fde_ref
332 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde;
346 struct indirect_string_node GTY(())
349 unsigned int refcount;
354 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
356 static GTY(()) int dw2_string_counter;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num;
359 /* True if the compilation unit places functions in more than one section. */
360 static GTY(()) bool have_multiple_function_sections = false;
362 /* Whether the default text and cold text sections have been used at all. */
364 static GTY(()) bool text_section_used = false;
365 static GTY(()) bool cold_text_section_used = false;
367 /* The default cold text section. */
368 static GTY(()) section *cold_text_section;
370 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
372 /* Forward declarations for functions defined in this file. */
374 static char *stripattributes (const char *);
375 static const char *dwarf_cfi_name (unsigned);
376 static dw_cfi_ref new_cfi (void);
377 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
378 static void add_fde_cfi (const char *, dw_cfi_ref);
379 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
380 static void lookup_cfa (dw_cfa_location *);
381 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
382 #ifdef DWARF2_UNWIND_INFO
383 static void initial_return_save (rtx);
385 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
386 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
387 static void output_cfi_directive (dw_cfi_ref);
388 static void output_call_frame_info (int);
389 static void dwarf2out_note_section_used (void);
390 static void dwarf2out_stack_adjust (rtx, bool);
391 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
392 static void flush_queued_reg_saves (void);
393 static bool clobbers_queued_reg_save (const_rtx);
394 static void dwarf2out_frame_debug_expr (rtx, const char *);
396 /* Support for complex CFA locations. */
397 static void output_cfa_loc (dw_cfi_ref);
398 static void output_cfa_loc_raw (dw_cfi_ref);
399 static void get_cfa_from_loc_descr (dw_cfa_location *,
400 struct dw_loc_descr_struct *);
401 static struct dw_loc_descr_struct *build_cfa_loc
402 (dw_cfa_location *, HOST_WIDE_INT);
403 static struct dw_loc_descr_struct *build_cfa_aligned_loc
404 (HOST_WIDE_INT, HOST_WIDE_INT);
405 static void def_cfa_1 (const char *, dw_cfa_location *);
407 /* How to start an assembler comment. */
408 #ifndef ASM_COMMENT_START
409 #define ASM_COMMENT_START ";#"
412 /* Data and reference forms for relocatable data. */
413 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
414 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
416 #ifndef DEBUG_FRAME_SECTION
417 #define DEBUG_FRAME_SECTION ".debug_frame"
420 #ifndef FUNC_BEGIN_LABEL
421 #define FUNC_BEGIN_LABEL "LFB"
424 #ifndef FUNC_END_LABEL
425 #define FUNC_END_LABEL "LFE"
428 #ifndef FRAME_BEGIN_LABEL
429 #define FRAME_BEGIN_LABEL "Lframe"
431 #define CIE_AFTER_SIZE_LABEL "LSCIE"
432 #define CIE_END_LABEL "LECIE"
433 #define FDE_LABEL "LSFDE"
434 #define FDE_AFTER_SIZE_LABEL "LASFDE"
435 #define FDE_END_LABEL "LEFDE"
436 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
437 #define LINE_NUMBER_END_LABEL "LELT"
438 #define LN_PROLOG_AS_LABEL "LASLTP"
439 #define LN_PROLOG_END_LABEL "LELTP"
440 #define DIE_LABEL_PREFIX "DW"
442 /* The DWARF 2 CFA column which tracks the return address. Normally this
443 is the column for PC, or the first column after all of the hard
445 #ifndef DWARF_FRAME_RETURN_COLUMN
447 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
449 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
453 /* The mapping from gcc register number to DWARF 2 CFA column number. By
454 default, we just provide columns for all registers. */
455 #ifndef DWARF_FRAME_REGNUM
456 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
459 /* Hook used by __throw. */
462 expand_builtin_dwarf_sp_column (void)
464 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
465 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
468 /* Return a pointer to a copy of the section string name S with all
469 attributes stripped off, and an asterisk prepended (for assemble_name). */
472 stripattributes (const char *s)
474 char *stripped = XNEWVEC (char, strlen (s) + 2);
479 while (*s && *s != ',')
486 /* MEM is a memory reference for the register size table, each element of
487 which has mode MODE. Initialize column C as a return address column. */
490 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
492 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
493 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
494 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
497 /* Generate code to initialize the register size table. */
500 expand_builtin_init_dwarf_reg_sizes (tree address)
503 enum machine_mode mode = TYPE_MODE (char_type_node);
504 rtx addr = expand_normal (address);
505 rtx mem = gen_rtx_MEM (BLKmode, addr);
506 bool wrote_return_column = false;
508 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
510 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
512 if (rnum < DWARF_FRAME_REGISTERS)
514 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
515 enum machine_mode save_mode = reg_raw_mode[i];
518 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
519 save_mode = choose_hard_reg_mode (i, 1, true);
520 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
522 if (save_mode == VOIDmode)
524 wrote_return_column = true;
526 size = GET_MODE_SIZE (save_mode);
530 emit_move_insn (adjust_address (mem, mode, offset),
531 gen_int_mode (size, mode));
535 if (!wrote_return_column)
536 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
538 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
539 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
542 targetm.init_dwarf_reg_sizes_extra (address);
545 /* Convert a DWARF call frame info. operation to its string name */
548 dwarf_cfi_name (unsigned int cfi_opc)
552 case DW_CFA_advance_loc:
553 return "DW_CFA_advance_loc";
555 return "DW_CFA_offset";
557 return "DW_CFA_restore";
561 return "DW_CFA_set_loc";
562 case DW_CFA_advance_loc1:
563 return "DW_CFA_advance_loc1";
564 case DW_CFA_advance_loc2:
565 return "DW_CFA_advance_loc2";
566 case DW_CFA_advance_loc4:
567 return "DW_CFA_advance_loc4";
568 case DW_CFA_offset_extended:
569 return "DW_CFA_offset_extended";
570 case DW_CFA_restore_extended:
571 return "DW_CFA_restore_extended";
572 case DW_CFA_undefined:
573 return "DW_CFA_undefined";
574 case DW_CFA_same_value:
575 return "DW_CFA_same_value";
576 case DW_CFA_register:
577 return "DW_CFA_register";
578 case DW_CFA_remember_state:
579 return "DW_CFA_remember_state";
580 case DW_CFA_restore_state:
581 return "DW_CFA_restore_state";
583 return "DW_CFA_def_cfa";
584 case DW_CFA_def_cfa_register:
585 return "DW_CFA_def_cfa_register";
586 case DW_CFA_def_cfa_offset:
587 return "DW_CFA_def_cfa_offset";
590 case DW_CFA_def_cfa_expression:
591 return "DW_CFA_def_cfa_expression";
592 case DW_CFA_expression:
593 return "DW_CFA_expression";
594 case DW_CFA_offset_extended_sf:
595 return "DW_CFA_offset_extended_sf";
596 case DW_CFA_def_cfa_sf:
597 return "DW_CFA_def_cfa_sf";
598 case DW_CFA_def_cfa_offset_sf:
599 return "DW_CFA_def_cfa_offset_sf";
601 /* SGI/MIPS specific */
602 case DW_CFA_MIPS_advance_loc8:
603 return "DW_CFA_MIPS_advance_loc8";
606 case DW_CFA_GNU_window_save:
607 return "DW_CFA_GNU_window_save";
608 case DW_CFA_GNU_args_size:
609 return "DW_CFA_GNU_args_size";
610 case DW_CFA_GNU_negative_offset_extended:
611 return "DW_CFA_GNU_negative_offset_extended";
614 return "DW_CFA_<unknown>";
618 /* Return a pointer to a newly allocated Call Frame Instruction. */
620 static inline dw_cfi_ref
623 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
625 cfi->dw_cfi_next = NULL;
626 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
627 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
632 /* Add a Call Frame Instruction to list of instructions. */
635 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
638 dw_fde_ref fde = current_fde ();
640 /* When DRAP is used, CFA is defined with an expression. Redefine
641 CFA may lead to a different CFA value. */
642 if (fde && fde->drap_reg != INVALID_REGNUM)
643 switch (cfi->dw_cfi_opc)
645 case DW_CFA_def_cfa_register:
646 case DW_CFA_def_cfa_offset:
647 case DW_CFA_def_cfa_offset_sf:
649 case DW_CFA_def_cfa_sf:
656 /* Find the end of the chain. */
657 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
663 /* Generate a new label for the CFI info to refer to. */
666 dwarf2out_cfi_label (void)
668 static char label[20];
670 if (flag_dwarf2_cfi_asm)
672 /* In this case, we will be emitting the asm directive instead of
673 the label, so just return a placeholder to keep the rest of the
675 strcpy (label, "<do not output>");
679 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
680 ASM_OUTPUT_LABEL (asm_out_file, label);
686 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
687 or to the CIE if LABEL is NULL. */
690 add_fde_cfi (const char *label, dw_cfi_ref cfi)
692 dw_cfi_ref *list_head = &cie_cfi_head;
694 if (flag_dwarf2_cfi_asm)
698 output_cfi_directive (cfi);
700 /* We still have to add the cfi to the list so that
701 lookup_cfa works later on. */
702 list_head = ¤t_fde ()->dw_fde_cfi;
704 /* ??? If this is a CFI for the CIE, we don't emit. This
705 assumes that the standard CIE contents that the assembler
706 uses matches the standard CIE contents that the compiler
707 uses. This is probably a bad assumption. I'm not quite
708 sure how to address this for now. */
712 dw_fde_ref fde = current_fde ();
714 gcc_assert (fde != NULL);
717 label = dwarf2out_cfi_label ();
719 if (fde->dw_fde_current_label == NULL
720 || strcmp (label, fde->dw_fde_current_label) != 0)
724 label = xstrdup (label);
726 /* Set the location counter to the new label. */
728 /* If we have a current label, advance from there, otherwise
729 set the location directly using set_loc. */
730 xcfi->dw_cfi_opc = fde->dw_fde_current_label
731 ? DW_CFA_advance_loc4
733 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
734 add_cfi (&fde->dw_fde_cfi, xcfi);
736 fde->dw_fde_current_label = label;
739 list_head = &fde->dw_fde_cfi;
742 add_cfi (list_head, cfi);
745 /* Subroutine of lookup_cfa. */
748 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
750 switch (cfi->dw_cfi_opc)
752 case DW_CFA_def_cfa_offset:
753 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
755 case DW_CFA_def_cfa_offset_sf:
757 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
759 case DW_CFA_def_cfa_register:
760 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
763 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
764 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
766 case DW_CFA_def_cfa_sf:
767 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
769 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
771 case DW_CFA_def_cfa_expression:
772 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
779 /* Find the previous value for the CFA. */
782 lookup_cfa (dw_cfa_location *loc)
787 loc->reg = INVALID_REGNUM;
790 loc->base_offset = 0;
792 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
793 lookup_cfa_1 (cfi, loc);
795 fde = current_fde ();
797 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
798 lookup_cfa_1 (cfi, loc);
801 /* The current rule for calculating the DWARF2 canonical frame address. */
802 static dw_cfa_location cfa;
804 /* The register used for saving registers to the stack, and its offset
806 static dw_cfa_location cfa_store;
808 /* The running total of the size of arguments pushed onto the stack. */
809 static HOST_WIDE_INT args_size;
811 /* The last args_size we actually output. */
812 static HOST_WIDE_INT old_args_size;
814 /* Entry point to update the canonical frame address (CFA).
815 LABEL is passed to add_fde_cfi. The value of CFA is now to be
816 calculated from REG+OFFSET. */
819 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
826 def_cfa_1 (label, &loc);
829 /* Determine if two dw_cfa_location structures define the same data. */
832 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
834 return (loc1->reg == loc2->reg
835 && loc1->offset == loc2->offset
836 && loc1->indirect == loc2->indirect
837 && (loc1->indirect == 0
838 || loc1->base_offset == loc2->base_offset));
841 /* This routine does the actual work. The CFA is now calculated from
842 the dw_cfa_location structure. */
845 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
848 dw_cfa_location old_cfa, loc;
853 if (cfa_store.reg == loc.reg && loc.indirect == 0)
854 cfa_store.offset = loc.offset;
856 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
857 lookup_cfa (&old_cfa);
859 /* If nothing changed, no need to issue any call frame instructions. */
860 if (cfa_equal_p (&loc, &old_cfa))
865 if (loc.reg == old_cfa.reg && !loc.indirect)
867 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
868 the CFA register did not change but the offset did. */
871 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
872 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
874 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
875 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
879 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
880 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
884 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
885 else if (loc.offset == old_cfa.offset
886 && old_cfa.reg != INVALID_REGNUM
889 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
890 indicating the CFA register has changed to <register> but the
891 offset has not changed. */
892 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
893 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
897 else if (loc.indirect == 0)
899 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
900 indicating the CFA register has changed to <register> with
901 the specified offset. */
904 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
905 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
907 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
908 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
909 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
913 cfi->dw_cfi_opc = DW_CFA_def_cfa;
914 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
915 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
920 /* Construct a DW_CFA_def_cfa_expression instruction to
921 calculate the CFA using a full location expression since no
922 register-offset pair is available. */
923 struct dw_loc_descr_struct *loc_list;
925 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
926 loc_list = build_cfa_loc (&loc, 0);
927 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
930 add_fde_cfi (label, cfi);
933 /* Add the CFI for saving a register. REG is the CFA column number.
934 LABEL is passed to add_fde_cfi.
935 If SREG is -1, the register is saved at OFFSET from the CFA;
936 otherwise it is saved in SREG. */
939 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
941 dw_cfi_ref cfi = new_cfi ();
942 dw_fde_ref fde = current_fde ();
944 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
946 /* When stack is aligned, store REG using DW_CFA_expression with
949 && fde->stack_realign
950 && sreg == INVALID_REGNUM)
952 cfi->dw_cfi_opc = DW_CFA_expression;
953 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
954 cfi->dw_cfi_oprnd1.dw_cfi_loc
955 = build_cfa_aligned_loc (offset, fde->stack_realignment);
957 else if (sreg == INVALID_REGNUM)
960 /* The register number won't fit in 6 bits, so we have to use
962 cfi->dw_cfi_opc = DW_CFA_offset_extended;
964 cfi->dw_cfi_opc = DW_CFA_offset;
966 #ifdef ENABLE_CHECKING
968 /* If we get an offset that is not a multiple of
969 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
970 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
972 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
974 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
977 offset /= DWARF_CIE_DATA_ALIGNMENT;
979 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
981 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
983 else if (sreg == reg)
984 cfi->dw_cfi_opc = DW_CFA_same_value;
987 cfi->dw_cfi_opc = DW_CFA_register;
988 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
991 add_fde_cfi (label, cfi);
994 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
995 This CFI tells the unwinder that it needs to restore the window registers
996 from the previous frame's window save area.
998 ??? Perhaps we should note in the CIE where windows are saved (instead of
999 assuming 0(cfa)) and what registers are in the window. */
1002 dwarf2out_window_save (const char *label)
1004 dw_cfi_ref cfi = new_cfi ();
1006 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1007 add_fde_cfi (label, cfi);
1010 /* Add a CFI to update the running total of the size of arguments
1011 pushed onto the stack. */
1014 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1018 if (size == old_args_size)
1021 old_args_size = size;
1024 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1025 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1026 add_fde_cfi (label, cfi);
1029 /* Entry point for saving a register to the stack. REG is the GCC register
1030 number. LABEL and OFFSET are passed to reg_save. */
1033 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1035 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1038 /* Entry point for saving the return address in the stack.
1039 LABEL and OFFSET are passed to reg_save. */
1042 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1044 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1047 /* Entry point for saving the return address in a register.
1048 LABEL and SREG are passed to reg_save. */
1051 dwarf2out_return_reg (const char *label, unsigned int sreg)
1053 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1056 #ifdef DWARF2_UNWIND_INFO
1057 /* Record the initial position of the return address. RTL is
1058 INCOMING_RETURN_ADDR_RTX. */
1061 initial_return_save (rtx rtl)
1063 unsigned int reg = INVALID_REGNUM;
1064 HOST_WIDE_INT offset = 0;
1066 switch (GET_CODE (rtl))
1069 /* RA is in a register. */
1070 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1074 /* RA is on the stack. */
1075 rtl = XEXP (rtl, 0);
1076 switch (GET_CODE (rtl))
1079 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1084 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1085 offset = INTVAL (XEXP (rtl, 1));
1089 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1090 offset = -INTVAL (XEXP (rtl, 1));
1100 /* The return address is at some offset from any value we can
1101 actually load. For instance, on the SPARC it is in %i7+8. Just
1102 ignore the offset for now; it doesn't matter for unwinding frames. */
1103 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1104 initial_return_save (XEXP (rtl, 0));
1111 if (reg != DWARF_FRAME_RETURN_COLUMN)
1112 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1116 /* Given a SET, calculate the amount of stack adjustment it
1119 static HOST_WIDE_INT
1120 stack_adjust_offset (const_rtx pattern)
1122 const_rtx src = SET_SRC (pattern);
1123 const_rtx dest = SET_DEST (pattern);
1124 HOST_WIDE_INT offset = 0;
1127 if (dest == stack_pointer_rtx)
1129 /* (set (reg sp) (plus (reg sp) (const_int))) */
1130 code = GET_CODE (src);
1131 if (! (code == PLUS || code == MINUS)
1132 || XEXP (src, 0) != stack_pointer_rtx
1133 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1136 offset = INTVAL (XEXP (src, 1));
1140 else if (MEM_P (dest))
1142 /* (set (mem (pre_dec (reg sp))) (foo)) */
1143 src = XEXP (dest, 0);
1144 code = GET_CODE (src);
1150 if (XEXP (src, 0) == stack_pointer_rtx)
1152 rtx val = XEXP (XEXP (src, 1), 1);
1153 /* We handle only adjustments by constant amount. */
1154 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1155 && GET_CODE (val) == CONST_INT);
1156 offset = -INTVAL (val);
1163 if (XEXP (src, 0) == stack_pointer_rtx)
1165 offset = GET_MODE_SIZE (GET_MODE (dest));
1172 if (XEXP (src, 0) == stack_pointer_rtx)
1174 offset = -GET_MODE_SIZE (GET_MODE (dest));
1189 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1190 indexed by INSN_UID. */
1192 static HOST_WIDE_INT *barrier_args_size;
1194 /* Helper function for compute_barrier_args_size. Handle one insn. */
1196 static HOST_WIDE_INT
1197 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1198 VEC (rtx, heap) **next)
1200 HOST_WIDE_INT offset = 0;
1203 if (! RTX_FRAME_RELATED_P (insn))
1205 if (prologue_epilogue_contains (insn)
1206 || sibcall_epilogue_contains (insn))
1208 else if (GET_CODE (PATTERN (insn)) == SET)
1209 offset = stack_adjust_offset (PATTERN (insn));
1210 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1211 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1213 /* There may be stack adjustments inside compound insns. Search
1215 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1216 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1217 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1222 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1226 expr = XEXP (expr, 0);
1227 if (GET_CODE (expr) == PARALLEL
1228 || GET_CODE (expr) == SEQUENCE)
1229 for (i = 1; i < XVECLEN (expr, 0); i++)
1231 rtx elem = XVECEXP (expr, 0, i);
1233 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1234 offset += stack_adjust_offset (elem);
1239 #ifndef STACK_GROWS_DOWNWARD
1243 cur_args_size += offset;
1244 if (cur_args_size < 0)
1249 rtx dest = JUMP_LABEL (insn);
1253 if (barrier_args_size [INSN_UID (dest)] < 0)
1255 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1256 VEC_safe_push (rtx, heap, *next, dest);
1259 gcc_assert (barrier_args_size[INSN_UID (dest)]
1264 return cur_args_size;
1267 /* Walk the whole function and compute args_size on BARRIERs. */
1270 compute_barrier_args_size (void)
1272 int max_uid = get_max_uid (), i;
1274 VEC (rtx, heap) *worklist, *next, *tmp;
1276 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1277 for (i = 0; i < max_uid; i++)
1278 barrier_args_size[i] = -1;
1280 worklist = VEC_alloc (rtx, heap, 20);
1281 next = VEC_alloc (rtx, heap, 20);
1282 insn = get_insns ();
1283 barrier_args_size[INSN_UID (insn)] = 0;
1284 VEC_quick_push (rtx, worklist, insn);
1287 while (!VEC_empty (rtx, worklist))
1289 rtx prev, body, first_insn;
1290 HOST_WIDE_INT cur_args_size;
1292 first_insn = insn = VEC_pop (rtx, worklist);
1293 cur_args_size = barrier_args_size[INSN_UID (insn)];
1294 prev = prev_nonnote_insn (insn);
1295 if (prev && BARRIER_P (prev))
1296 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1298 for (; insn; insn = NEXT_INSN (insn))
1300 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1302 if (BARRIER_P (insn))
1307 if (insn == first_insn)
1309 else if (barrier_args_size[INSN_UID (insn)] < 0)
1311 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1316 /* The insns starting with this label have been
1317 already scanned or are in the worklist. */
1318 gcc_assert (barrier_args_size[INSN_UID (insn)]
1324 body = PATTERN (insn);
1325 if (GET_CODE (body) == SEQUENCE)
1327 for (i = 1; i < XVECLEN (body, 0); i++)
1329 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1330 cur_args_size, &next);
1332 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1333 cur_args_size, &next);
1337 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1341 if (VEC_empty (rtx, next))
1344 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1348 VEC_truncate (rtx, next, 0);
1351 VEC_free (rtx, heap, worklist);
1352 VEC_free (rtx, heap, next);
1356 /* Check INSN to see if it looks like a push or a stack adjustment, and
1357 make a note of it if it does. EH uses this information to find out how
1358 much extra space it needs to pop off the stack. */
1361 dwarf2out_stack_adjust (rtx insn, bool after_p)
1363 HOST_WIDE_INT offset;
1367 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1368 with this function. Proper support would require all frame-related
1369 insns to be marked, and to be able to handle saving state around
1370 epilogues textually in the middle of the function. */
1371 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1374 /* If only calls can throw, and we have a frame pointer,
1375 save up adjustments until we see the CALL_INSN. */
1376 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1378 if (CALL_P (insn) && !after_p)
1380 /* Extract the size of the args from the CALL rtx itself. */
1381 insn = PATTERN (insn);
1382 if (GET_CODE (insn) == PARALLEL)
1383 insn = XVECEXP (insn, 0, 0);
1384 if (GET_CODE (insn) == SET)
1385 insn = SET_SRC (insn);
1386 gcc_assert (GET_CODE (insn) == CALL);
1387 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1392 if (CALL_P (insn) && !after_p)
1394 if (!flag_asynchronous_unwind_tables)
1395 dwarf2out_args_size ("", args_size);
1398 else if (BARRIER_P (insn))
1400 /* Don't call compute_barrier_args_size () if the only
1401 BARRIER is at the end of function. */
1402 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1403 compute_barrier_args_size ();
1404 if (barrier_args_size == NULL)
1408 offset = barrier_args_size[INSN_UID (insn)];
1413 offset -= args_size;
1414 #ifndef STACK_GROWS_DOWNWARD
1418 else if (GET_CODE (PATTERN (insn)) == SET)
1419 offset = stack_adjust_offset (PATTERN (insn));
1420 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1421 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1423 /* There may be stack adjustments inside compound insns. Search
1425 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1426 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1427 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1435 label = dwarf2out_cfi_label ();
1436 dwarf2out_args_size_adjust (offset, label);
1439 /* Adjust args_size based on stack adjustment OFFSET. */
1442 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1444 if (cfa.reg == STACK_POINTER_REGNUM)
1445 cfa.offset += offset;
1447 if (cfa_store.reg == STACK_POINTER_REGNUM)
1448 cfa_store.offset += offset;
1450 #ifndef STACK_GROWS_DOWNWARD
1454 args_size += offset;
1458 def_cfa_1 (label, &cfa);
1459 if (flag_asynchronous_unwind_tables)
1460 dwarf2out_args_size (label, args_size);
1465 /* We delay emitting a register save until either (a) we reach the end
1466 of the prologue or (b) the register is clobbered. This clusters
1467 register saves so that there are fewer pc advances. */
1469 struct queued_reg_save GTY(())
1471 struct queued_reg_save *next;
1473 HOST_WIDE_INT cfa_offset;
1477 static GTY(()) struct queued_reg_save *queued_reg_saves;
1479 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1480 struct reg_saved_in_data GTY(()) {
1485 /* A list of registers saved in other registers.
1486 The list intentionally has a small maximum capacity of 4; if your
1487 port needs more than that, you might consider implementing a
1488 more efficient data structure. */
1489 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1490 static GTY(()) size_t num_regs_saved_in_regs;
1492 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1493 static const char *last_reg_save_label;
1495 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1496 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1499 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1501 struct queued_reg_save *q;
1503 /* Duplicates waste space, but it's also necessary to remove them
1504 for correctness, since the queue gets output in reverse
1506 for (q = queued_reg_saves; q != NULL; q = q->next)
1507 if (REGNO (q->reg) == REGNO (reg))
1512 q = GGC_NEW (struct queued_reg_save);
1513 q->next = queued_reg_saves;
1514 queued_reg_saves = q;
1518 q->cfa_offset = offset;
1519 q->saved_reg = sreg;
1521 last_reg_save_label = label;
1524 /* Output all the entries in QUEUED_REG_SAVES. */
1527 flush_queued_reg_saves (void)
1529 struct queued_reg_save *q;
1531 for (q = queued_reg_saves; q; q = q->next)
1534 unsigned int reg, sreg;
1536 for (i = 0; i < num_regs_saved_in_regs; i++)
1537 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1539 if (q->saved_reg && i == num_regs_saved_in_regs)
1541 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1542 num_regs_saved_in_regs++;
1544 if (i != num_regs_saved_in_regs)
1546 regs_saved_in_regs[i].orig_reg = q->reg;
1547 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1550 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1552 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1554 sreg = INVALID_REGNUM;
1555 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1558 queued_reg_saves = NULL;
1559 last_reg_save_label = NULL;
1562 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1563 location for? Or, does it clobber a register which we've previously
1564 said that some other register is saved in, and for which we now
1565 have a new location for? */
1568 clobbers_queued_reg_save (const_rtx insn)
1570 struct queued_reg_save *q;
1572 for (q = queued_reg_saves; q; q = q->next)
1575 if (modified_in_p (q->reg, insn))
1577 for (i = 0; i < num_regs_saved_in_regs; i++)
1578 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1579 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1586 /* Entry point for saving the first register into the second. */
1589 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1592 unsigned int regno, sregno;
1594 for (i = 0; i < num_regs_saved_in_regs; i++)
1595 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1597 if (i == num_regs_saved_in_regs)
1599 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1600 num_regs_saved_in_regs++;
1602 regs_saved_in_regs[i].orig_reg = reg;
1603 regs_saved_in_regs[i].saved_in_reg = sreg;
1605 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1606 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1607 reg_save (label, regno, sregno, 0);
1610 /* What register, if any, is currently saved in REG? */
1613 reg_saved_in (rtx reg)
1615 unsigned int regn = REGNO (reg);
1617 struct queued_reg_save *q;
1619 for (q = queued_reg_saves; q; q = q->next)
1620 if (q->saved_reg && regn == REGNO (q->saved_reg))
1623 for (i = 0; i < num_regs_saved_in_regs; i++)
1624 if (regs_saved_in_regs[i].saved_in_reg
1625 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1626 return regs_saved_in_regs[i].orig_reg;
1632 /* A temporary register holding an integral value used in adjusting SP
1633 or setting up the store_reg. The "offset" field holds the integer
1634 value, not an offset. */
1635 static dw_cfa_location cfa_temp;
1637 /* Record call frame debugging information for an expression EXPR,
1638 which either sets SP or FP (adjusting how we calculate the frame
1639 address) or saves a register to the stack or another register.
1640 LABEL indicates the address of EXPR.
1642 This function encodes a state machine mapping rtxes to actions on
1643 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1644 users need not read the source code.
1646 The High-Level Picture
1648 Changes in the register we use to calculate the CFA: Currently we
1649 assume that if you copy the CFA register into another register, we
1650 should take the other one as the new CFA register; this seems to
1651 work pretty well. If it's wrong for some target, it's simple
1652 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1654 Changes in the register we use for saving registers to the stack:
1655 This is usually SP, but not always. Again, we deduce that if you
1656 copy SP into another register (and SP is not the CFA register),
1657 then the new register is the one we will be using for register
1658 saves. This also seems to work.
1660 Register saves: There's not much guesswork about this one; if
1661 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1662 register save, and the register used to calculate the destination
1663 had better be the one we think we're using for this purpose.
1664 It's also assumed that a copy from a call-saved register to another
1665 register is saving that register if RTX_FRAME_RELATED_P is set on
1666 that instruction. If the copy is from a call-saved register to
1667 the *same* register, that means that the register is now the same
1668 value as in the caller.
1670 Except: If the register being saved is the CFA register, and the
1671 offset is nonzero, we are saving the CFA, so we assume we have to
1672 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1673 the intent is to save the value of SP from the previous frame.
1675 In addition, if a register has previously been saved to a different
1678 Invariants / Summaries of Rules
1680 cfa current rule for calculating the CFA. It usually
1681 consists of a register and an offset.
1682 cfa_store register used by prologue code to save things to the stack
1683 cfa_store.offset is the offset from the value of
1684 cfa_store.reg to the actual CFA
1685 cfa_temp register holding an integral value. cfa_temp.offset
1686 stores the value, which will be used to adjust the
1687 stack pointer. cfa_temp is also used like cfa_store,
1688 to track stores to the stack via fp or a temp reg.
1690 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1691 with cfa.reg as the first operand changes the cfa.reg and its
1692 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1695 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1696 expression yielding a constant. This sets cfa_temp.reg
1697 and cfa_temp.offset.
1699 Rule 5: Create a new register cfa_store used to save items to the
1702 Rules 10-14: Save a register to the stack. Define offset as the
1703 difference of the original location and cfa_store's
1704 location (or cfa_temp's location if cfa_temp is used).
1706 Rules 16-20: If AND operation happens on sp in prologue, we assume
1707 stack is realigned. We will use a group of DW_OP_XXX
1708 expressions to represent the location of the stored
1709 register instead of CFA+offset.
1713 "{a,b}" indicates a choice of a xor b.
1714 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1717 (set <reg1> <reg2>:cfa.reg)
1718 effects: cfa.reg = <reg1>
1719 cfa.offset unchanged
1720 cfa_temp.reg = <reg1>
1721 cfa_temp.offset = cfa.offset
1724 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1725 {<const_int>,<reg>:cfa_temp.reg}))
1726 effects: cfa.reg = sp if fp used
1727 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1728 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1729 if cfa_store.reg==sp
1732 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1733 effects: cfa.reg = fp
1734 cfa_offset += +/- <const_int>
1737 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1738 constraints: <reg1> != fp
1740 effects: cfa.reg = <reg1>
1741 cfa_temp.reg = <reg1>
1742 cfa_temp.offset = cfa.offset
1745 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1746 constraints: <reg1> != fp
1748 effects: cfa_store.reg = <reg1>
1749 cfa_store.offset = cfa.offset - cfa_temp.offset
1752 (set <reg> <const_int>)
1753 effects: cfa_temp.reg = <reg>
1754 cfa_temp.offset = <const_int>
1757 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1758 effects: cfa_temp.reg = <reg1>
1759 cfa_temp.offset |= <const_int>
1762 (set <reg> (high <exp>))
1766 (set <reg> (lo_sum <exp> <const_int>))
1767 effects: cfa_temp.reg = <reg>
1768 cfa_temp.offset = <const_int>
1771 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1772 effects: cfa_store.offset -= <const_int>
1773 cfa.offset = cfa_store.offset if cfa.reg == sp
1775 cfa.base_offset = -cfa_store.offset
1778 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1779 effects: cfa_store.offset += -/+ mode_size(mem)
1780 cfa.offset = cfa_store.offset if cfa.reg == sp
1782 cfa.base_offset = -cfa_store.offset
1785 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1788 effects: cfa.reg = <reg1>
1789 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1792 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1793 effects: cfa.reg = <reg1>
1794 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1797 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1798 effects: cfa.reg = <reg1>
1799 cfa.base_offset = -cfa_temp.offset
1800 cfa_temp.offset -= mode_size(mem)
1803 (set <reg> {unspec, unspec_volatile})
1804 effects: target-dependent
1807 (set sp (and: sp <const_int>))
1808 constraints: cfa_store.reg == sp
1809 effects: current_fde.stack_realign = 1
1810 cfa_store.offset = 0
1811 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1814 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1815 effects: cfa_store.offset += -/+ mode_size(mem)
1818 (set (mem ({pre_inc, pre_dec} sp)) fp)
1819 constraints: fde->stack_realign == 1
1820 effects: cfa_store.offset = 0
1821 cfa.reg != HARD_FRAME_POINTER_REGNUM
1824 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1825 constraints: fde->stack_realign == 1
1827 && cfa.indirect == 0
1828 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1829 effects: Use DW_CFA_def_cfa_expression to define cfa
1830 cfa.reg == fde->drap_reg
1833 (set reg fde->drap_reg)
1834 constraints: fde->vdrap_reg == INVALID_REGNUM
1835 effects: fde->vdrap_reg = reg.
1836 (set mem fde->drap_reg)
1837 constraints: fde->drap_reg_saved == 1
1841 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1843 rtx src, dest, span;
1844 HOST_WIDE_INT offset;
1847 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1848 the PARALLEL independently. The first element is always processed if
1849 it is a SET. This is for backward compatibility. Other elements
1850 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1851 flag is set in them. */
1852 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1855 int limit = XVECLEN (expr, 0);
1858 /* PARALLELs have strict read-modify-write semantics, so we
1859 ought to evaluate every rvalue before changing any lvalue.
1860 It's cumbersome to do that in general, but there's an
1861 easy approximation that is enough for all current users:
1862 handle register saves before register assignments. */
1863 if (GET_CODE (expr) == PARALLEL)
1864 for (par_index = 0; par_index < limit; par_index++)
1866 elem = XVECEXP (expr, 0, par_index);
1867 if (GET_CODE (elem) == SET
1868 && MEM_P (SET_DEST (elem))
1869 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1870 dwarf2out_frame_debug_expr (elem, label);
1873 for (par_index = 0; par_index < limit; par_index++)
1875 elem = XVECEXP (expr, 0, par_index);
1876 if (GET_CODE (elem) == SET
1877 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1878 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1879 dwarf2out_frame_debug_expr (elem, label);
1880 else if (GET_CODE (elem) == SET
1882 && !RTX_FRAME_RELATED_P (elem))
1884 /* Stack adjustment combining might combine some post-prologue
1885 stack adjustment into a prologue stack adjustment. */
1886 HOST_WIDE_INT offset = stack_adjust_offset (elem);
1889 dwarf2out_args_size_adjust (offset, label);
1895 gcc_assert (GET_CODE (expr) == SET);
1897 src = SET_SRC (expr);
1898 dest = SET_DEST (expr);
1902 rtx rsi = reg_saved_in (src);
1907 fde = current_fde ();
1909 if (GET_CODE (src) == REG
1911 && fde->drap_reg == REGNO (src)
1912 && (fde->drap_reg_saved
1913 || GET_CODE (dest) == REG))
1916 /* If we are saving dynamic realign argument pointer to a
1917 register, the destination is virtual dynamic realign
1918 argument pointer. It may be used to access argument. */
1919 if (GET_CODE (dest) == REG)
1921 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
1922 fde->vdrap_reg = REGNO (dest);
1927 switch (GET_CODE (dest))
1930 switch (GET_CODE (src))
1932 /* Setting FP from SP. */
1934 if (cfa.reg == (unsigned) REGNO (src))
1937 /* Update the CFA rule wrt SP or FP. Make sure src is
1938 relative to the current CFA register.
1940 We used to require that dest be either SP or FP, but the
1941 ARM copies SP to a temporary register, and from there to
1942 FP. So we just rely on the backends to only set
1943 RTX_FRAME_RELATED_P on appropriate insns. */
1944 cfa.reg = REGNO (dest);
1945 cfa_temp.reg = cfa.reg;
1946 cfa_temp.offset = cfa.offset;
1950 /* Saving a register in a register. */
1951 gcc_assert (!fixed_regs [REGNO (dest)]
1952 /* For the SPARC and its register window. */
1953 || (DWARF_FRAME_REGNUM (REGNO (src))
1954 == DWARF_FRAME_RETURN_COLUMN));
1956 /* After stack is aligned, we can only save SP in FP
1957 if drap register is used. In this case, we have
1958 to restore stack pointer with the CFA value and we
1959 don't generate this DWARF information. */
1961 && fde->stack_realign
1962 && REGNO (src) == STACK_POINTER_REGNUM)
1963 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
1964 && fde->drap_reg != INVALID_REGNUM
1965 && cfa.reg != REGNO (src));
1967 queue_reg_save (label, src, dest, 0);
1974 if (dest == stack_pointer_rtx)
1978 switch (GET_CODE (XEXP (src, 1)))
1981 offset = INTVAL (XEXP (src, 1));
1984 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1986 offset = cfa_temp.offset;
1992 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1994 /* Restoring SP from FP in the epilogue. */
1995 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1996 cfa.reg = STACK_POINTER_REGNUM;
1998 else if (GET_CODE (src) == LO_SUM)
1999 /* Assume we've set the source reg of the LO_SUM from sp. */
2002 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2004 if (GET_CODE (src) != MINUS)
2006 if (cfa.reg == STACK_POINTER_REGNUM)
2007 cfa.offset += offset;
2008 if (cfa_store.reg == STACK_POINTER_REGNUM)
2009 cfa_store.offset += offset;
2011 else if (dest == hard_frame_pointer_rtx)
2014 /* Either setting the FP from an offset of the SP,
2015 or adjusting the FP */
2016 gcc_assert (frame_pointer_needed);
2018 gcc_assert (REG_P (XEXP (src, 0))
2019 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2020 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2021 offset = INTVAL (XEXP (src, 1));
2022 if (GET_CODE (src) != MINUS)
2024 cfa.offset += offset;
2025 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2029 gcc_assert (GET_CODE (src) != MINUS);
2032 if (REG_P (XEXP (src, 0))
2033 && REGNO (XEXP (src, 0)) == cfa.reg
2034 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2036 /* Setting a temporary CFA register that will be copied
2037 into the FP later on. */
2038 offset = - INTVAL (XEXP (src, 1));
2039 cfa.offset += offset;
2040 cfa.reg = REGNO (dest);
2041 /* Or used to save regs to the stack. */
2042 cfa_temp.reg = cfa.reg;
2043 cfa_temp.offset = cfa.offset;
2047 else if (REG_P (XEXP (src, 0))
2048 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2049 && XEXP (src, 1) == stack_pointer_rtx)
2051 /* Setting a scratch register that we will use instead
2052 of SP for saving registers to the stack. */
2053 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2054 cfa_store.reg = REGNO (dest);
2055 cfa_store.offset = cfa.offset - cfa_temp.offset;
2059 else if (GET_CODE (src) == LO_SUM
2060 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2062 cfa_temp.reg = REGNO (dest);
2063 cfa_temp.offset = INTVAL (XEXP (src, 1));
2072 cfa_temp.reg = REGNO (dest);
2073 cfa_temp.offset = INTVAL (src);
2078 gcc_assert (REG_P (XEXP (src, 0))
2079 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2080 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2082 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2083 cfa_temp.reg = REGNO (dest);
2084 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2087 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2088 which will fill in all of the bits. */
2095 case UNSPEC_VOLATILE:
2096 gcc_assert (targetm.dwarf_handle_frame_unspec);
2097 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2102 /* If this AND operation happens on stack pointer in prologue,
2103 we assume the stack is realigned and we extract the
2105 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2107 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2108 fde->stack_realign = 1;
2109 fde->stack_realignment = INTVAL (XEXP (src, 1));
2110 cfa_store.offset = 0;
2112 if (cfa.reg != STACK_POINTER_REGNUM
2113 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2114 fde->drap_reg = cfa.reg;
2122 def_cfa_1 (label, &cfa);
2127 /* Saving a register to the stack. Make sure dest is relative to the
2129 switch (GET_CODE (XEXP (dest, 0)))
2134 /* We can't handle variable size modifications. */
2135 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2137 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2139 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2140 && cfa_store.reg == STACK_POINTER_REGNUM);
2142 cfa_store.offset += offset;
2143 if (cfa.reg == STACK_POINTER_REGNUM)
2144 cfa.offset = cfa_store.offset;
2146 offset = -cfa_store.offset;
2152 offset = GET_MODE_SIZE (GET_MODE (dest));
2153 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2156 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2157 == STACK_POINTER_REGNUM)
2158 && cfa_store.reg == STACK_POINTER_REGNUM);
2160 cfa_store.offset += offset;
2162 /* Rule 18: If stack is aligned, we will use FP as a
2163 reference to represent the address of the stored
2166 && fde->stack_realign
2167 && src == hard_frame_pointer_rtx)
2169 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2170 cfa_store.offset = 0;
2173 if (cfa.reg == STACK_POINTER_REGNUM)
2174 cfa.offset = cfa_store.offset;
2176 offset = -cfa_store.offset;
2180 /* With an offset. */
2187 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2188 && REG_P (XEXP (XEXP (dest, 0), 0)));
2189 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2190 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2193 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2195 if (cfa_store.reg == (unsigned) regno)
2196 offset -= cfa_store.offset;
2199 gcc_assert (cfa_temp.reg == (unsigned) regno);
2200 offset -= cfa_temp.offset;
2206 /* Without an offset. */
2209 int regno = REGNO (XEXP (dest, 0));
2211 if (cfa_store.reg == (unsigned) regno)
2212 offset = -cfa_store.offset;
2215 gcc_assert (cfa_temp.reg == (unsigned) regno);
2216 offset = -cfa_temp.offset;
2223 gcc_assert (cfa_temp.reg
2224 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2225 offset = -cfa_temp.offset;
2226 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2234 /* If the source operand of this MEM operation is not a
2235 register, basically the source is return address. Here
2236 we only care how much stack grew and we don't save it. */
2240 if (REGNO (src) != STACK_POINTER_REGNUM
2241 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2242 && (unsigned) REGNO (src) == cfa.reg)
2244 /* We're storing the current CFA reg into the stack. */
2246 if (cfa.offset == 0)
2249 /* If stack is aligned, putting CFA reg into stack means
2250 we can no longer use reg + offset to represent CFA.
2251 Here we use DW_CFA_def_cfa_expression instead. The
2252 result of this expression equals to the original CFA
2255 && fde->stack_realign
2256 && cfa.indirect == 0
2257 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2259 dw_cfa_location cfa_exp;
2261 gcc_assert (fde->drap_reg == cfa.reg);
2263 cfa_exp.indirect = 1;
2264 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2265 cfa_exp.base_offset = offset;
2268 fde->drap_reg_saved = 1;
2270 def_cfa_1 (label, &cfa_exp);
2274 /* If the source register is exactly the CFA, assume
2275 we're saving SP like any other register; this happens
2277 def_cfa_1 (label, &cfa);
2278 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2283 /* Otherwise, we'll need to look in the stack to
2284 calculate the CFA. */
2285 rtx x = XEXP (dest, 0);
2289 gcc_assert (REG_P (x));
2291 cfa.reg = REGNO (x);
2292 cfa.base_offset = offset;
2294 def_cfa_1 (label, &cfa);
2299 def_cfa_1 (label, &cfa);
2301 span = targetm.dwarf_register_span (src);
2304 queue_reg_save (label, src, NULL_RTX, offset);
2307 /* We have a PARALLEL describing where the contents of SRC
2308 live. Queue register saves for each piece of the
2312 HOST_WIDE_INT span_offset = offset;
2314 gcc_assert (GET_CODE (span) == PARALLEL);
2316 limit = XVECLEN (span, 0);
2317 for (par_index = 0; par_index < limit; par_index++)
2319 rtx elem = XVECEXP (span, 0, par_index);
2321 queue_reg_save (label, elem, NULL_RTX, span_offset);
2322 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2333 /* Record call frame debugging information for INSN, which either
2334 sets SP or FP (adjusting how we calculate the frame address) or saves a
2335 register to the stack. If INSN is NULL_RTX, initialize our state.
2337 If AFTER_P is false, we're being called before the insn is emitted,
2338 otherwise after. Call instructions get invoked twice. */
2341 dwarf2out_frame_debug (rtx insn, bool after_p)
2346 if (insn == NULL_RTX)
2350 /* Flush any queued register saves. */
2351 flush_queued_reg_saves ();
2353 /* Set up state for generating call frame debug info. */
2356 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2358 cfa.reg = STACK_POINTER_REGNUM;
2361 cfa_temp.offset = 0;
2363 for (i = 0; i < num_regs_saved_in_regs; i++)
2365 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2366 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2368 num_regs_saved_in_regs = 0;
2370 if (barrier_args_size)
2372 XDELETEVEC (barrier_args_size);
2373 barrier_args_size = NULL;
2378 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2379 flush_queued_reg_saves ();
2381 if (! RTX_FRAME_RELATED_P (insn))
2383 if (!ACCUMULATE_OUTGOING_ARGS)
2384 dwarf2out_stack_adjust (insn, after_p);
2388 label = dwarf2out_cfi_label ();
2389 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2391 insn = XEXP (src, 0);
2393 insn = PATTERN (insn);
2395 dwarf2out_frame_debug_expr (insn, label);
2400 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2401 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2402 (enum dwarf_call_frame_info cfi);
2404 static enum dw_cfi_oprnd_type
2405 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2410 case DW_CFA_GNU_window_save:
2411 return dw_cfi_oprnd_unused;
2413 case DW_CFA_set_loc:
2414 case DW_CFA_advance_loc1:
2415 case DW_CFA_advance_loc2:
2416 case DW_CFA_advance_loc4:
2417 case DW_CFA_MIPS_advance_loc8:
2418 return dw_cfi_oprnd_addr;
2421 case DW_CFA_offset_extended:
2422 case DW_CFA_def_cfa:
2423 case DW_CFA_offset_extended_sf:
2424 case DW_CFA_def_cfa_sf:
2425 case DW_CFA_restore_extended:
2426 case DW_CFA_undefined:
2427 case DW_CFA_same_value:
2428 case DW_CFA_def_cfa_register:
2429 case DW_CFA_register:
2430 return dw_cfi_oprnd_reg_num;
2432 case DW_CFA_def_cfa_offset:
2433 case DW_CFA_GNU_args_size:
2434 case DW_CFA_def_cfa_offset_sf:
2435 return dw_cfi_oprnd_offset;
2437 case DW_CFA_def_cfa_expression:
2438 case DW_CFA_expression:
2439 return dw_cfi_oprnd_loc;
2446 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2447 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2448 (enum dwarf_call_frame_info cfi);
2450 static enum dw_cfi_oprnd_type
2451 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2455 case DW_CFA_def_cfa:
2456 case DW_CFA_def_cfa_sf:
2458 case DW_CFA_offset_extended_sf:
2459 case DW_CFA_offset_extended:
2460 return dw_cfi_oprnd_offset;
2462 case DW_CFA_register:
2463 return dw_cfi_oprnd_reg_num;
2466 return dw_cfi_oprnd_unused;
2470 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2472 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2473 switch to the data section instead, and write out a synthetic label
2477 switch_to_eh_frame_section (void)
2481 #ifdef EH_FRAME_SECTION_NAME
2482 if (eh_frame_section == 0)
2486 if (EH_TABLES_CAN_BE_READ_ONLY)
2492 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2494 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2496 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2498 flags = ((! flag_pic
2499 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2500 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2501 && (per_encoding & 0x70) != DW_EH_PE_absptr
2502 && (per_encoding & 0x70) != DW_EH_PE_aligned
2503 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2504 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2505 ? 0 : SECTION_WRITE);
2508 flags = SECTION_WRITE;
2509 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2513 if (eh_frame_section)
2514 switch_to_section (eh_frame_section);
2517 /* We have no special eh_frame section. Put the information in
2518 the data section and emit special labels to guide collect2. */
2519 switch_to_section (data_section);
2520 label = get_file_function_name ("F");
2521 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2522 targetm.asm_out.globalize_label (asm_out_file,
2523 IDENTIFIER_POINTER (label));
2524 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2528 /* Output a Call Frame Information opcode and its operand(s). */
2531 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2534 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2535 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2536 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2537 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2538 ((unsigned HOST_WIDE_INT)
2539 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2540 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2542 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2543 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2544 "DW_CFA_offset, column 0x%lx", r);
2545 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2547 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2549 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2550 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2551 "DW_CFA_restore, column 0x%lx", r);
2555 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2556 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2558 switch (cfi->dw_cfi_opc)
2560 case DW_CFA_set_loc:
2562 dw2_asm_output_encoded_addr_rtx (
2563 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2564 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2567 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2568 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2569 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2572 case DW_CFA_advance_loc1:
2573 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2574 fde->dw_fde_current_label, NULL);
2575 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2578 case DW_CFA_advance_loc2:
2579 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2580 fde->dw_fde_current_label, NULL);
2581 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2584 case DW_CFA_advance_loc4:
2585 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2586 fde->dw_fde_current_label, NULL);
2587 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2590 case DW_CFA_MIPS_advance_loc8:
2591 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2592 fde->dw_fde_current_label, NULL);
2593 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2596 case DW_CFA_offset_extended:
2597 case DW_CFA_def_cfa:
2598 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2599 dw2_asm_output_data_uleb128 (r, NULL);
2600 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2603 case DW_CFA_offset_extended_sf:
2604 case DW_CFA_def_cfa_sf:
2605 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2606 dw2_asm_output_data_uleb128 (r, NULL);
2607 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2610 case DW_CFA_restore_extended:
2611 case DW_CFA_undefined:
2612 case DW_CFA_same_value:
2613 case DW_CFA_def_cfa_register:
2614 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2615 dw2_asm_output_data_uleb128 (r, NULL);
2618 case DW_CFA_register:
2619 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2620 dw2_asm_output_data_uleb128 (r, NULL);
2621 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2622 dw2_asm_output_data_uleb128 (r, NULL);
2625 case DW_CFA_def_cfa_offset:
2626 case DW_CFA_GNU_args_size:
2627 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2630 case DW_CFA_def_cfa_offset_sf:
2631 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2634 case DW_CFA_GNU_window_save:
2637 case DW_CFA_def_cfa_expression:
2638 case DW_CFA_expression:
2639 output_cfa_loc (cfi);
2642 case DW_CFA_GNU_negative_offset_extended:
2643 /* Obsoleted by DW_CFA_offset_extended_sf. */
2652 /* Similar, but do it via assembler directives instead. */
2655 output_cfi_directive (dw_cfi_ref cfi)
2657 unsigned long r, r2;
2659 switch (cfi->dw_cfi_opc)
2661 case DW_CFA_advance_loc:
2662 case DW_CFA_advance_loc1:
2663 case DW_CFA_advance_loc2:
2664 case DW_CFA_advance_loc4:
2665 case DW_CFA_MIPS_advance_loc8:
2666 case DW_CFA_set_loc:
2667 /* Should only be created by add_fde_cfi in a code path not
2668 followed when emitting via directives. The assembler is
2669 going to take care of this for us. */
2673 case DW_CFA_offset_extended:
2674 case DW_CFA_offset_extended_sf:
2675 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2676 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2677 r, cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT);
2680 case DW_CFA_restore:
2681 case DW_CFA_restore_extended:
2682 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2683 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
2686 case DW_CFA_undefined:
2687 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2688 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
2691 case DW_CFA_same_value:
2692 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2693 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
2696 case DW_CFA_def_cfa:
2697 case DW_CFA_def_cfa_sf:
2698 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2699 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2700 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2703 case DW_CFA_def_cfa_register:
2704 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2705 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
2708 case DW_CFA_register:
2709 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
2710 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 0);
2711 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
2714 case DW_CFA_def_cfa_offset:
2715 case DW_CFA_def_cfa_offset_sf:
2716 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
2717 HOST_WIDE_INT_PRINT_DEC"\n",
2718 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2721 case DW_CFA_GNU_args_size:
2722 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
2723 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2725 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
2726 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
2727 fputc ('\n', asm_out_file);
2730 case DW_CFA_GNU_window_save:
2731 fprintf (asm_out_file, "\t.cfi_window_save\n");
2734 case DW_CFA_def_cfa_expression:
2735 case DW_CFA_expression:
2736 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
2737 output_cfa_loc_raw (cfi);
2738 fputc ('\n', asm_out_file);
2746 /* Output the call frame information used to record information
2747 that relates to calculating the frame pointer, and records the
2748 location of saved registers. */
2751 output_call_frame_info (int for_eh)
2756 char l1[20], l2[20], section_start_label[20];
2757 bool any_lsda_needed = false;
2758 char augmentation[6];
2759 int augmentation_size;
2760 int fde_encoding = DW_EH_PE_absptr;
2761 int per_encoding = DW_EH_PE_absptr;
2762 int lsda_encoding = DW_EH_PE_absptr;
2765 /* Don't emit a CIE if there won't be any FDEs. */
2766 if (fde_table_in_use == 0)
2769 /* Nothing to do if the assembler's doing it all. */
2770 if (flag_dwarf2_cfi_asm)
2773 /* If we make FDEs linkonce, we may have to emit an empty label for
2774 an FDE that wouldn't otherwise be emitted. We want to avoid
2775 having an FDE kept around when the function it refers to is
2776 discarded. Example where this matters: a primary function
2777 template in C++ requires EH information, but an explicit
2778 specialization doesn't. */
2779 if (TARGET_USES_WEAK_UNWIND_INFO
2780 && ! flag_asynchronous_unwind_tables
2783 for (i = 0; i < fde_table_in_use; i++)
2784 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2785 && !fde_table[i].uses_eh_lsda
2786 && ! DECL_WEAK (fde_table[i].decl))
2787 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2788 for_eh, /* empty */ 1);
2790 /* If we don't have any functions we'll want to unwind out of, don't
2791 emit any EH unwind information. Note that if exceptions aren't
2792 enabled, we won't have collected nothrow information, and if we
2793 asked for asynchronous tables, we always want this info. */
2796 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2798 for (i = 0; i < fde_table_in_use; i++)
2799 if (fde_table[i].uses_eh_lsda)
2800 any_eh_needed = any_lsda_needed = true;
2801 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2802 any_eh_needed = true;
2803 else if (! fde_table[i].nothrow
2804 && ! fde_table[i].all_throwers_are_sibcalls)
2805 any_eh_needed = true;
2807 if (! any_eh_needed)
2811 /* We're going to be generating comments, so turn on app. */
2816 switch_to_eh_frame_section ();
2819 if (!debug_frame_section)
2820 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2821 SECTION_DEBUG, NULL);
2822 switch_to_section (debug_frame_section);
2825 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2826 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2828 /* Output the CIE. */
2829 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2830 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2831 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2832 dw2_asm_output_data (4, 0xffffffff,
2833 "Initial length escape value indicating 64-bit DWARF extension");
2834 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2835 "Length of Common Information Entry");
2836 ASM_OUTPUT_LABEL (asm_out_file, l1);
2838 /* Now that the CIE pointer is PC-relative for EH,
2839 use 0 to identify the CIE. */
2840 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2841 (for_eh ? 0 : DWARF_CIE_ID),
2842 "CIE Identifier Tag");
2844 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2846 augmentation[0] = 0;
2847 augmentation_size = 0;
2853 z Indicates that a uleb128 is present to size the
2854 augmentation section.
2855 L Indicates the encoding (and thus presence) of
2856 an LSDA pointer in the FDE augmentation.
2857 R Indicates a non-default pointer encoding for
2859 P Indicates the presence of an encoding + language
2860 personality routine in the CIE augmentation. */
2862 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2863 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2864 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2866 p = augmentation + 1;
2867 if (eh_personality_libfunc)
2870 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2871 assemble_external_libcall (eh_personality_libfunc);
2873 if (any_lsda_needed)
2876 augmentation_size += 1;
2878 if (fde_encoding != DW_EH_PE_absptr)
2881 augmentation_size += 1;
2883 if (p > augmentation + 1)
2885 augmentation[0] = 'z';
2889 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2890 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2892 int offset = ( 4 /* Length */
2894 + 1 /* CIE version */
2895 + strlen (augmentation) + 1 /* Augmentation */
2896 + size_of_uleb128 (1) /* Code alignment */
2897 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2899 + 1 /* Augmentation size */
2900 + 1 /* Personality encoding */ );
2901 int pad = -offset & (PTR_SIZE - 1);
2903 augmentation_size += pad;
2905 /* Augmentations should be small, so there's scarce need to
2906 iterate for a solution. Die if we exceed one uleb128 byte. */
2907 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2911 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2912 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2913 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2914 "CIE Data Alignment Factor");
2916 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2917 if (DW_CIE_VERSION == 1)
2918 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2920 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2922 if (augmentation[0])
2924 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2925 if (eh_personality_libfunc)
2927 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2928 eh_data_format_name (per_encoding));
2929 dw2_asm_output_encoded_addr_rtx (per_encoding,
2930 eh_personality_libfunc,
2934 if (any_lsda_needed)
2935 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2936 eh_data_format_name (lsda_encoding));
2938 if (fde_encoding != DW_EH_PE_absptr)
2939 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2940 eh_data_format_name (fde_encoding));
2943 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2944 output_cfi (cfi, NULL, for_eh);
2946 /* Pad the CIE out to an address sized boundary. */
2947 ASM_OUTPUT_ALIGN (asm_out_file,
2948 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2949 ASM_OUTPUT_LABEL (asm_out_file, l2);
2951 /* Loop through all of the FDE's. */
2952 for (i = 0; i < fde_table_in_use; i++)
2954 fde = &fde_table[i];
2956 /* Don't emit EH unwind info for leaf functions that don't need it. */
2957 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2958 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2959 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2960 && !fde->uses_eh_lsda)
2963 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2964 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2965 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2966 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2967 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2968 dw2_asm_output_data (4, 0xffffffff,
2969 "Initial length escape value indicating 64-bit DWARF extension");
2970 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2972 ASM_OUTPUT_LABEL (asm_out_file, l1);
2975 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2977 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2978 debug_frame_section, "FDE CIE offset");
2982 if (fde->dw_fde_switched_sections)
2984 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2985 fde->dw_fde_unlikely_section_label);
2986 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2987 fde->dw_fde_hot_section_label);
2988 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2989 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2990 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2991 "FDE initial location");
2992 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2993 fde->dw_fde_hot_section_end_label,
2994 fde->dw_fde_hot_section_label,
2995 "FDE address range");
2996 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2997 "FDE initial location");
2998 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2999 fde->dw_fde_unlikely_section_end_label,
3000 fde->dw_fde_unlikely_section_label,
3001 "FDE address range");
3005 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3006 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3007 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3010 "FDE initial location");
3011 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3012 fde->dw_fde_end, fde->dw_fde_begin,
3013 "FDE address range");
3018 if (fde->dw_fde_switched_sections)
3020 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3021 fde->dw_fde_hot_section_label,
3022 "FDE initial location");
3023 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3024 fde->dw_fde_hot_section_end_label,
3025 fde->dw_fde_hot_section_label,
3026 "FDE address range");
3027 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3028 fde->dw_fde_unlikely_section_label,
3029 "FDE initial location");
3030 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3031 fde->dw_fde_unlikely_section_end_label,
3032 fde->dw_fde_unlikely_section_label,
3033 "FDE address range");
3037 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3038 "FDE initial location");
3039 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3040 fde->dw_fde_end, fde->dw_fde_begin,
3041 "FDE address range");
3045 if (augmentation[0])
3047 if (any_lsda_needed)
3049 int size = size_of_encoded_value (lsda_encoding);
3051 if (lsda_encoding == DW_EH_PE_aligned)
3053 int offset = ( 4 /* Length */
3054 + 4 /* CIE offset */
3055 + 2 * size_of_encoded_value (fde_encoding)
3056 + 1 /* Augmentation size */ );
3057 int pad = -offset & (PTR_SIZE - 1);
3060 gcc_assert (size_of_uleb128 (size) == 1);
3063 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3065 if (fde->uses_eh_lsda)
3067 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3068 fde->funcdef_number);
3069 dw2_asm_output_encoded_addr_rtx (
3070 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3071 false, "Language Specific Data Area");
3075 if (lsda_encoding == DW_EH_PE_aligned)
3076 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3078 (size_of_encoded_value (lsda_encoding), 0,
3079 "Language Specific Data Area (none)");
3083 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3086 /* Loop through the Call Frame Instructions associated with
3088 fde->dw_fde_current_label = fde->dw_fde_begin;
3089 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3090 output_cfi (cfi, fde, for_eh);
3092 /* Pad the FDE out to an address sized boundary. */
3093 ASM_OUTPUT_ALIGN (asm_out_file,
3094 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3095 ASM_OUTPUT_LABEL (asm_out_file, l2);
3098 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3099 dw2_asm_output_data (4, 0, "End of Table");
3100 #ifdef MIPS_DEBUGGING_INFO
3101 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3102 get a value of 0. Putting .align 0 after the label fixes it. */
3103 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3106 /* Turn off app to make assembly quicker. */
3111 /* Output a marker (i.e. a label) for the beginning of a function, before
3115 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3116 const char *file ATTRIBUTE_UNUSED)
3118 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3122 current_function_func_begin_label = NULL;
3124 #ifdef TARGET_UNWIND_INFO
3125 /* ??? current_function_func_begin_label is also used by except.c
3126 for call-site information. We must emit this label if it might
3128 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3129 && ! dwarf2out_do_frame ())
3132 if (! dwarf2out_do_frame ())
3136 switch_to_section (function_section (current_function_decl));
3137 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3138 current_function_funcdef_no);
3139 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3140 current_function_funcdef_no);
3141 dup_label = xstrdup (label);
3142 current_function_func_begin_label = dup_label;
3144 #ifdef TARGET_UNWIND_INFO
3145 /* We can elide the fde allocation if we're not emitting debug info. */
3146 if (! dwarf2out_do_frame ())
3150 /* Expand the fde table if necessary. */
3151 if (fde_table_in_use == fde_table_allocated)
3153 fde_table_allocated += FDE_TABLE_INCREMENT;
3154 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3155 memset (fde_table + fde_table_in_use, 0,
3156 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3159 /* Record the FDE associated with this function. */
3160 current_funcdef_fde = fde_table_in_use;
3162 /* Add the new FDE at the end of the fde_table. */
3163 fde = &fde_table[fde_table_in_use++];
3164 fde->decl = current_function_decl;
3165 fde->dw_fde_begin = dup_label;
3166 fde->dw_fde_current_label = dup_label;
3167 fde->dw_fde_hot_section_label = NULL;
3168 fde->dw_fde_hot_section_end_label = NULL;
3169 fde->dw_fde_unlikely_section_label = NULL;
3170 fde->dw_fde_unlikely_section_end_label = NULL;
3171 fde->dw_fde_switched_sections = false;
3172 fde->dw_fde_end = NULL;
3173 fde->dw_fde_cfi = NULL;
3174 fde->funcdef_number = current_function_funcdef_no;
3175 fde->nothrow = TREE_NOTHROW (current_function_decl);
3176 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3177 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3178 fde->drap_reg = INVALID_REGNUM;
3179 fde->vdrap_reg = INVALID_REGNUM;
3181 args_size = old_args_size = 0;
3183 /* We only want to output line number information for the genuine dwarf2
3184 prologue case, not the eh frame case. */
3185 #ifdef DWARF2_DEBUGGING_INFO
3187 dwarf2out_source_line (line, file);
3190 if (flag_dwarf2_cfi_asm)
3195 fprintf (asm_out_file, "\t.cfi_startproc\n");
3197 if (eh_personality_libfunc)
3199 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3200 ref = eh_personality_libfunc;
3202 /* ??? The GAS support isn't entirely consistent. We have to
3203 handle indirect support ourselves, but PC-relative is done
3204 in the assembler. Further, the assembler can't handle any
3205 of the weirder relocation types. */
3206 if (enc & DW_EH_PE_indirect)
3207 ref = dw2_force_const_mem (ref, true);
3209 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3210 output_addr_const (asm_out_file, ref);
3211 fputc ('\n', asm_out_file);
3214 if (crtl->uses_eh_lsda)
3218 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3219 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3220 current_function_funcdef_no);
3221 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3222 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3224 if (enc & DW_EH_PE_indirect)
3225 ref = dw2_force_const_mem (ref, true);
3227 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3228 output_addr_const (asm_out_file, ref);
3229 fputc ('\n', asm_out_file);
3234 /* Output a marker (i.e. a label) for the absolute end of the generated code
3235 for a function definition. This gets called *after* the epilogue code has
3239 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3240 const char *file ATTRIBUTE_UNUSED)
3243 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3245 if (flag_dwarf2_cfi_asm)
3246 fprintf (asm_out_file, "\t.cfi_endproc\n");
3248 /* Output a label to mark the endpoint of the code generated for this
3250 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3251 current_function_funcdef_no);
3252 ASM_OUTPUT_LABEL (asm_out_file, label);
3253 fde = current_fde ();
3254 gcc_assert (fde != NULL);
3255 fde->dw_fde_end = xstrdup (label);
3259 dwarf2out_frame_init (void)
3261 /* Allocate the initial hunk of the fde_table. */
3262 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3263 fde_table_allocated = FDE_TABLE_INCREMENT;
3264 fde_table_in_use = 0;
3266 /* Generate the CFA instructions common to all FDE's. Do it now for the
3267 sake of lookup_cfa. */
3269 /* On entry, the Canonical Frame Address is at SP. */
3270 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3272 #ifdef DWARF2_UNWIND_INFO
3273 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3274 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3279 dwarf2out_frame_finish (void)
3281 /* Output call frame information. */
3282 if (DWARF2_FRAME_INFO)
3283 output_call_frame_info (0);
3285 #ifndef TARGET_UNWIND_INFO
3286 /* Output another copy for the unwinder. */
3287 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3288 output_call_frame_info (1);
3292 /* Note that the current function section is being used for code. */
3295 dwarf2out_note_section_used (void)
3297 section *sec = current_function_section ();
3298 if (sec == text_section)
3299 text_section_used = true;
3300 else if (sec == cold_text_section)
3301 cold_text_section_used = true;
3305 dwarf2out_switch_text_section (void)
3307 dw_fde_ref fde = current_fde ();
3309 gcc_assert (cfun && fde);
3311 fde->dw_fde_switched_sections = true;
3312 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3313 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3314 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3315 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3316 have_multiple_function_sections = true;
3318 /* Reset the current label on switching text sections, so that we
3319 don't attempt to advance_loc4 between labels in different sections. */
3320 fde->dw_fde_current_label = NULL;
3322 /* There is no need to mark used sections when not debugging. */
3323 if (cold_text_section != NULL)
3324 dwarf2out_note_section_used ();
3328 /* And now, the subset of the debugging information support code necessary
3329 for emitting location expressions. */
3331 /* Data about a single source file. */
3332 struct dwarf_file_data GTY(())
3334 const char * filename;
3338 /* We need some way to distinguish DW_OP_addr with a direct symbol
3339 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3340 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3343 typedef struct dw_val_struct *dw_val_ref;
3344 typedef struct die_struct *dw_die_ref;
3345 typedef const struct die_struct *const_dw_die_ref;
3346 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3347 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3349 /* Each DIE may have a series of attribute/value pairs. Values
3350 can take on several forms. The forms that are used in this
3351 implementation are listed below. */
3356 dw_val_class_offset,
3358 dw_val_class_loc_list,
3359 dw_val_class_range_list,
3361 dw_val_class_unsigned_const,
3362 dw_val_class_long_long,
3365 dw_val_class_die_ref,
3366 dw_val_class_fde_ref,
3367 dw_val_class_lbl_id,
3368 dw_val_class_lineptr,
3370 dw_val_class_macptr,
3374 /* Describe a double word constant value. */
3375 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3377 typedef struct dw_long_long_struct GTY(())
3384 /* Describe a floating point constant value, or a vector constant value. */
3386 typedef struct dw_vec_struct GTY(())
3388 unsigned char * GTY((length ("%h.length"))) array;
3394 /* The dw_val_node describes an attribute's value, as it is
3395 represented internally. */
3397 typedef struct dw_val_struct GTY(())
3399 enum dw_val_class val_class;
3400 union dw_val_struct_union
3402 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3403 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3404 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3405 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3406 HOST_WIDE_INT GTY ((default)) val_int;
3407 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3408 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3409 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3410 struct dw_val_die_union
3414 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3415 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3416 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3417 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3418 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3419 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3421 GTY ((desc ("%1.val_class"))) v;
3425 /* Locations in memory are described using a sequence of stack machine
3428 typedef struct dw_loc_descr_struct GTY(())
3430 dw_loc_descr_ref dw_loc_next;
3431 enum dwarf_location_atom dw_loc_opc;
3432 dw_val_node dw_loc_oprnd1;
3433 dw_val_node dw_loc_oprnd2;
3438 /* Location lists are ranges + location descriptions for that range,
3439 so you can track variables that are in different places over
3440 their entire life. */
3441 typedef struct dw_loc_list_struct GTY(())
3443 dw_loc_list_ref dw_loc_next;
3444 const char *begin; /* Label for begin address of range */
3445 const char *end; /* Label for end address of range */
3446 char *ll_symbol; /* Label for beginning of location list.
3447 Only on head of list */
3448 const char *section; /* Section this loclist is relative to */
3449 dw_loc_descr_ref expr;
3452 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3454 static const char *dwarf_stack_op_name (unsigned);
3455 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
3456 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3457 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3458 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
3459 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
3460 static unsigned long size_of_locs (dw_loc_descr_ref);
3461 static void output_loc_operands (dw_loc_descr_ref);
3462 static void output_loc_sequence (dw_loc_descr_ref);
3464 /* Convert a DWARF stack opcode into its string name. */
3467 dwarf_stack_op_name (unsigned int op)
3472 case INTERNAL_DW_OP_tls_addr:
3473 return "DW_OP_addr";
3475 return "DW_OP_deref";
3477 return "DW_OP_const1u";
3479 return "DW_OP_const1s";
3481 return "DW_OP_const2u";
3483 return "DW_OP_const2s";
3485 return "DW_OP_const4u";
3487 return "DW_OP_const4s";
3489 return "DW_OP_const8u";
3491 return "DW_OP_const8s";
3493 return "DW_OP_constu";
3495 return "DW_OP_consts";
3499 return "DW_OP_drop";
3501 return "DW_OP_over";
3503 return "DW_OP_pick";
3505 return "DW_OP_swap";
3509 return "DW_OP_xderef";
3517 return "DW_OP_minus";
3529 return "DW_OP_plus";
3530 case DW_OP_plus_uconst:
3531 return "DW_OP_plus_uconst";
3537 return "DW_OP_shra";
3555 return "DW_OP_skip";
3557 return "DW_OP_lit0";
3559 return "DW_OP_lit1";
3561 return "DW_OP_lit2";
3563 return "DW_OP_lit3";
3565 return "DW_OP_lit4";
3567 return "DW_OP_lit5";
3569 return "DW_OP_lit6";
3571 return "DW_OP_lit7";
3573 return "DW_OP_lit8";
3575 return "DW_OP_lit9";
3577 return "DW_OP_lit10";
3579 return "DW_OP_lit11";
3581 return "DW_OP_lit12";
3583 return "DW_OP_lit13";
3585 return "DW_OP_lit14";
3587 return "DW_OP_lit15";
3589 return "DW_OP_lit16";
3591 return "DW_OP_lit17";
3593 return "DW_OP_lit18";
3595 return "DW_OP_lit19";
3597 return "DW_OP_lit20";
3599 return "DW_OP_lit21";
3601 return "DW_OP_lit22";
3603 return "DW_OP_lit23";
3605 return "DW_OP_lit24";
3607 return "DW_OP_lit25";
3609 return "DW_OP_lit26";
3611 return "DW_OP_lit27";
3613 return "DW_OP_lit28";
3615 return "DW_OP_lit29";
3617 return "DW_OP_lit30";
3619 return "DW_OP_lit31";
3621 return "DW_OP_reg0";
3623 return "DW_OP_reg1";
3625 return "DW_OP_reg2";
3627 return "DW_OP_reg3";
3629 return "DW_OP_reg4";
3631 return "DW_OP_reg5";
3633 return "DW_OP_reg6";
3635 return "DW_OP_reg7";
3637 return "DW_OP_reg8";
3639 return "DW_OP_reg9";
3641 return "DW_OP_reg10";
3643 return "DW_OP_reg11";
3645 return "DW_OP_reg12";
3647 return "DW_OP_reg13";
3649 return "DW_OP_reg14";
3651 return "DW_OP_reg15";
3653 return "DW_OP_reg16";
3655 return "DW_OP_reg17";
3657 return "DW_OP_reg18";
3659 return "DW_OP_reg19";
3661 return "DW_OP_reg20";
3663 return "DW_OP_reg21";
3665 return "DW_OP_reg22";
3667 return "DW_OP_reg23";
3669 return "DW_OP_reg24";
3671 return "DW_OP_reg25";
3673 return "DW_OP_reg26";
3675 return "DW_OP_reg27";
3677 return "DW_OP_reg28";
3679 return "DW_OP_reg29";
3681 return "DW_OP_reg30";
3683 return "DW_OP_reg31";
3685 return "DW_OP_breg0";
3687 return "DW_OP_breg1";
3689 return "DW_OP_breg2";
3691 return "DW_OP_breg3";
3693 return "DW_OP_breg4";
3695 return "DW_OP_breg5";
3697 return "DW_OP_breg6";
3699 return "DW_OP_breg7";
3701 return "DW_OP_breg8";
3703 return "DW_OP_breg9";
3705 return "DW_OP_breg10";
3707 return "DW_OP_breg11";
3709 return "DW_OP_breg12";
3711 return "DW_OP_breg13";
3713 return "DW_OP_breg14";
3715 return "DW_OP_breg15";
3717 return "DW_OP_breg16";
3719 return "DW_OP_breg17";
3721 return "DW_OP_breg18";
3723 return "DW_OP_breg19";
3725 return "DW_OP_breg20";
3727 return "DW_OP_breg21";
3729 return "DW_OP_breg22";
3731 return "DW_OP_breg23";
3733 return "DW_OP_breg24";
3735 return "DW_OP_breg25";
3737 return "DW_OP_breg26";
3739 return "DW_OP_breg27";
3741 return "DW_OP_breg28";
3743 return "DW_OP_breg29";
3745 return "DW_OP_breg30";
3747 return "DW_OP_breg31";
3749 return "DW_OP_regx";
3751 return "DW_OP_fbreg";
3753 return "DW_OP_bregx";
3755 return "DW_OP_piece";
3756 case DW_OP_deref_size:
3757 return "DW_OP_deref_size";
3758 case DW_OP_xderef_size:
3759 return "DW_OP_xderef_size";
3762 case DW_OP_push_object_address:
3763 return "DW_OP_push_object_address";
3765 return "DW_OP_call2";
3767 return "DW_OP_call4";
3768 case DW_OP_call_ref:
3769 return "DW_OP_call_ref";
3770 case DW_OP_GNU_push_tls_address:
3771 return "DW_OP_GNU_push_tls_address";
3772 case DW_OP_GNU_uninit:
3773 return "DW_OP_GNU_uninit";
3775 return "OP_<unknown>";
3779 /* Return a pointer to a newly allocated location description. Location
3780 descriptions are simple expression terms that can be strung
3781 together to form more complicated location (address) descriptions. */
3783 static inline dw_loc_descr_ref
3784 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3785 unsigned HOST_WIDE_INT oprnd2)
3787 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3789 descr->dw_loc_opc = op;
3790 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3791 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3792 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3793 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3798 /* Add a location description term to a location description expression. */
3801 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3803 dw_loc_descr_ref *d;
3805 /* Find the end of the chain. */
3806 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3812 /* Return the size of a location descriptor. */
3814 static unsigned long
3815 size_of_loc_descr (dw_loc_descr_ref loc)
3817 unsigned long size = 1;
3819 switch (loc->dw_loc_opc)
3822 case INTERNAL_DW_OP_tls_addr:
3823 size += DWARF2_ADDR_SIZE;
3842 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3845 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3850 case DW_OP_plus_uconst:
3851 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3889 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3892 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3895 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3898 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3899 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3902 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3904 case DW_OP_deref_size:
3905 case DW_OP_xderef_size:
3914 case DW_OP_call_ref:
3915 size += DWARF2_ADDR_SIZE;
3924 /* Return the size of a series of location descriptors. */
3926 static unsigned long
3927 size_of_locs (dw_loc_descr_ref loc)
3932 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3933 field, to avoid writing to a PCH file. */
3934 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3936 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3938 size += size_of_loc_descr (l);
3943 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3945 l->dw_loc_addr = size;
3946 size += size_of_loc_descr (l);
3952 /* Output location description stack opcode's operands (if any). */
3955 output_loc_operands (dw_loc_descr_ref loc)
3957 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3958 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3960 switch (loc->dw_loc_opc)
3962 #ifdef DWARF2_DEBUGGING_INFO
3964 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3968 dw2_asm_output_data (2, val1->v.val_int, NULL);
3972 dw2_asm_output_data (4, val1->v.val_int, NULL);
3976 gcc_assert (HOST_BITS_PER_LONG >= 64);
3977 dw2_asm_output_data (8, val1->v.val_int, NULL);
3984 gcc_assert (val1->val_class == dw_val_class_loc);
3985 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3987 dw2_asm_output_data (2, offset, NULL);
4000 /* We currently don't make any attempt to make sure these are
4001 aligned properly like we do for the main unwind info, so
4002 don't support emitting things larger than a byte if we're
4003 only doing unwinding. */
4008 dw2_asm_output_data (1, val1->v.val_int, NULL);
4011 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4014 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4017 dw2_asm_output_data (1, val1->v.val_int, NULL);
4019 case DW_OP_plus_uconst:
4020 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4054 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4057 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4060 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4063 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4064 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4067 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4069 case DW_OP_deref_size:
4070 case DW_OP_xderef_size:
4071 dw2_asm_output_data (1, val1->v.val_int, NULL);
4074 case INTERNAL_DW_OP_tls_addr:
4075 if (targetm.asm_out.output_dwarf_dtprel)
4077 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4080 fputc ('\n', asm_out_file);
4087 /* Other codes have no operands. */
4092 /* Output a sequence of location operations. */
4095 output_loc_sequence (dw_loc_descr_ref loc)
4097 for (; loc != NULL; loc = loc->dw_loc_next)
4099 /* Output the opcode. */
4100 dw2_asm_output_data (1, loc->dw_loc_opc,
4101 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4103 /* Output the operand(s) (if any). */
4104 output_loc_operands (loc);
4108 /* Output location description stack opcode's operands (if any).
4109 The output is single bytes on a line, suitable for .cfi_escape. */
4112 output_loc_operands_raw (dw_loc_descr_ref loc)
4114 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4115 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4117 switch (loc->dw_loc_opc)
4120 /* We cannot output addresses in .cfi_escape, only bytes. */
4126 case DW_OP_deref_size:
4127 case DW_OP_xderef_size:
4128 fputc (',', asm_out_file);
4129 dw2_asm_output_data_raw (1, val1->v.val_int);
4134 fputc (',', asm_out_file);
4135 dw2_asm_output_data_raw (2, val1->v.val_int);
4140 fputc (',', asm_out_file);
4141 dw2_asm_output_data_raw (4, val1->v.val_int);
4146 gcc_assert (HOST_BITS_PER_LONG >= 64);
4147 fputc (',', asm_out_file);
4148 dw2_asm_output_data_raw (8, val1->v.val_int);
4156 gcc_assert (val1->val_class == dw_val_class_loc);
4157 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4159 fputc (',', asm_out_file);
4160 dw2_asm_output_data_raw (2, offset);
4165 case DW_OP_plus_uconst:
4168 fputc (',', asm_out_file);
4169 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4206 fputc (',', asm_out_file);
4207 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4211 fputc (',', asm_out_file);
4212 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4213 fputc (',', asm_out_file);
4214 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4217 case INTERNAL_DW_OP_tls_addr:
4221 /* Other codes have no operands. */
4227 output_loc_sequence_raw (dw_loc_descr_ref loc)
4231 /* Output the opcode. */
4232 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4233 output_loc_operands_raw (loc);
4235 if (!loc->dw_loc_next)
4237 loc = loc->dw_loc_next;
4239 fputc (',', asm_out_file);
4243 /* This routine will generate the correct assembly data for a location
4244 description based on a cfi entry with a complex address. */
4247 output_cfa_loc (dw_cfi_ref cfi)
4249 dw_loc_descr_ref loc;
4252 if (cfi->dw_cfi_opc == DW_CFA_expression)
4253 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4255 /* Output the size of the block. */
4256 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4257 size = size_of_locs (loc);
4258 dw2_asm_output_data_uleb128 (size, NULL);
4260 /* Now output the operations themselves. */
4261 output_loc_sequence (loc);
4264 /* Similar, but used for .cfi_escape. */
4267 output_cfa_loc_raw (dw_cfi_ref cfi)
4269 dw_loc_descr_ref loc;
4272 if (cfi->dw_cfi_opc == DW_CFA_expression)
4273 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4275 /* Output the size of the block. */
4276 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4277 size = size_of_locs (loc);
4278 dw2_asm_output_data_uleb128_raw (size);
4279 fputc (',', asm_out_file);
4281 /* Now output the operations themselves. */
4282 output_loc_sequence_raw (loc);
4285 /* This function builds a dwarf location descriptor sequence from a
4286 dw_cfa_location, adding the given OFFSET to the result of the
4289 static struct dw_loc_descr_struct *
4290 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4292 struct dw_loc_descr_struct *head, *tmp;
4294 offset += cfa->offset;
4298 if (cfa->base_offset)
4301 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
4303 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
4305 else if (cfa->reg <= 31)
4306 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
4308 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
4310 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4311 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4312 add_loc_descr (&head, tmp);
4315 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4316 add_loc_descr (&head, tmp);
4323 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
4325 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
4326 else if (cfa->reg <= 31)
4327 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
4329 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
4335 /* This function builds a dwarf location descriptor sequence for
4336 the address at OFFSET from the CFA when stack is aligned to
4339 static struct dw_loc_descr_struct *
4340 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4342 struct dw_loc_descr_struct *head;
4343 unsigned int dwarf_fp
4344 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4346 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4347 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4350 head = new_loc_descr (DW_OP_breg0 + dwarf_fp, 0, 0);
4352 head = new_loc_descr (DW_OP_bregx, dwarf_fp, 0);
4354 add_loc_descr (&head, int_loc_descriptor (alignment));
4355 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4357 add_loc_descr (&head, int_loc_descriptor (offset));
4358 add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
4360 else if (dwarf_fp <= 31)
4361 head = new_loc_descr (DW_OP_breg0 + dwarf_fp, offset, 0);
4363 head = new_loc_descr (DW_OP_bregx, dwarf_fp, offset);
4367 /* This function fills in aa dw_cfa_location structure from a dwarf location
4368 descriptor sequence. */
4371 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4373 struct dw_loc_descr_struct *ptr;
4375 cfa->base_offset = 0;
4379 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4381 enum dwarf_location_atom op = ptr->dw_loc_opc;
4417 cfa->reg = op - DW_OP_reg0;
4420 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4454 cfa->reg = op - DW_OP_breg0;
4455 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4458 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4459 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4464 case DW_OP_plus_uconst:
4465 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4468 internal_error ("DW_LOC_OP %s not implemented",
4469 dwarf_stack_op_name (ptr->dw_loc_opc));
4473 #endif /* .debug_frame support */
4475 /* And now, the support for symbolic debugging information. */
4476 #ifdef DWARF2_DEBUGGING_INFO
4478 /* .debug_str support. */
4479 static int output_indirect_string (void **, void *);
4481 static void dwarf2out_init (const char *);
4482 static void dwarf2out_finish (const char *);
4483 static void dwarf2out_define (unsigned int, const char *);
4484 static void dwarf2out_undef (unsigned int, const char *);
4485 static void dwarf2out_start_source_file (unsigned, const char *);
4486 static void dwarf2out_end_source_file (unsigned);
4487 static void dwarf2out_begin_block (unsigned, unsigned);
4488 static void dwarf2out_end_block (unsigned, unsigned);
4489 static bool dwarf2out_ignore_block (const_tree);
4490 static void dwarf2out_global_decl (tree);
4491 static void dwarf2out_type_decl (tree, int);
4492 static void dwarf2out_imported_module_or_decl (tree, tree);
4493 static void dwarf2out_abstract_function (tree);
4494 static void dwarf2out_var_location (rtx);
4495 static void dwarf2out_begin_function (tree);
4497 /* The debug hooks structure. */
4499 const struct gcc_debug_hooks dwarf2_debug_hooks =
4505 dwarf2out_start_source_file,
4506 dwarf2out_end_source_file,
4507 dwarf2out_begin_block,
4508 dwarf2out_end_block,
4509 dwarf2out_ignore_block,
4510 dwarf2out_source_line,
4511 dwarf2out_begin_prologue,
4512 debug_nothing_int_charstar, /* end_prologue */
4513 dwarf2out_end_epilogue,
4514 dwarf2out_begin_function,
4515 debug_nothing_int, /* end_function */
4516 dwarf2out_decl, /* function_decl */
4517 dwarf2out_global_decl,
4518 dwarf2out_type_decl, /* type_decl */
4519 dwarf2out_imported_module_or_decl,
4520 debug_nothing_tree, /* deferred_inline_function */
4521 /* The DWARF 2 backend tries to reduce debugging bloat by not
4522 emitting the abstract description of inline functions until
4523 something tries to reference them. */
4524 dwarf2out_abstract_function, /* outlining_inline_function */
4525 debug_nothing_rtx, /* label */
4526 debug_nothing_int, /* handle_pch */
4527 dwarf2out_var_location,
4528 dwarf2out_switch_text_section,
4529 1 /* start_end_main_source_file */
4533 /* NOTE: In the comments in this file, many references are made to
4534 "Debugging Information Entries". This term is abbreviated as `DIE'
4535 throughout the remainder of this file. */
4537 /* An internal representation of the DWARF output is built, and then
4538 walked to generate the DWARF debugging info. The walk of the internal
4539 representation is done after the entire program has been compiled.
4540 The types below are used to describe the internal representation. */
4542 /* Various DIE's use offsets relative to the beginning of the
4543 .debug_info section to refer to each other. */
4545 typedef long int dw_offset;
4547 /* Define typedefs here to avoid circular dependencies. */
4549 typedef struct dw_attr_struct *dw_attr_ref;
4550 typedef struct dw_line_info_struct *dw_line_info_ref;
4551 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4552 typedef struct pubname_struct *pubname_ref;
4553 typedef struct dw_ranges_struct *dw_ranges_ref;
4554 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4556 /* Each entry in the line_info_table maintains the file and
4557 line number associated with the label generated for that
4558 entry. The label gives the PC value associated with
4559 the line number entry. */
4561 typedef struct dw_line_info_struct GTY(())
4563 unsigned long dw_file_num;
4564 unsigned long dw_line_num;
4568 /* Line information for functions in separate sections; each one gets its
4570 typedef struct dw_separate_line_info_struct GTY(())
4572 unsigned long dw_file_num;
4573 unsigned long dw_line_num;
4574 unsigned long function;
4576 dw_separate_line_info_entry;
4578 /* Each DIE attribute has a field specifying the attribute kind,
4579 a link to the next attribute in the chain, and an attribute value.
4580 Attributes are typically linked below the DIE they modify. */
4582 typedef struct dw_attr_struct GTY(())
4584 enum dwarf_attribute dw_attr;
4585 dw_val_node dw_attr_val;
4589 DEF_VEC_O(dw_attr_node);
4590 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4592 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4593 The children of each node form a circular list linked by
4594 die_sib. die_child points to the node *before* the "first" child node. */
4596 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
4598 enum dwarf_tag die_tag;
4600 VEC(dw_attr_node,gc) * die_attr;
4601 dw_die_ref die_parent;
4602 dw_die_ref die_child;
4604 dw_die_ref die_definition; /* ref from a specification to its definition */
4605 dw_offset die_offset;
4606 unsigned long die_abbrev;
4608 /* Die is used and must not be pruned as unused. */
4609 int die_perennial_p;
4610 unsigned int decl_id;
4614 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4615 #define FOR_EACH_CHILD(die, c, expr) do { \
4616 c = die->die_child; \
4620 } while (c != die->die_child); \
4623 /* The pubname structure */
4625 typedef struct pubname_struct GTY(())
4632 DEF_VEC_O(pubname_entry);
4633 DEF_VEC_ALLOC_O(pubname_entry, gc);
4635 struct dw_ranges_struct GTY(())
4637 /* If this is positive, it's a block number, otherwise it's a
4638 bitwise-negated index into dw_ranges_by_label. */
4642 struct dw_ranges_by_label_struct GTY(())
4648 /* The limbo die list structure. */
4649 typedef struct limbo_die_struct GTY(())
4653 struct limbo_die_struct *next;
4657 /* How to start an assembler comment. */
4658 #ifndef ASM_COMMENT_START
4659 #define ASM_COMMENT_START ";#"
4662 /* Define a macro which returns nonzero for a TYPE_DECL which was
4663 implicitly generated for a tagged type.
4665 Note that unlike the gcc front end (which generates a NULL named
4666 TYPE_DECL node for each complete tagged type, each array type, and
4667 each function type node created) the g++ front end generates a
4668 _named_ TYPE_DECL node for each tagged type node created.
4669 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4670 generate a DW_TAG_typedef DIE for them. */
4672 #define TYPE_DECL_IS_STUB(decl) \
4673 (DECL_NAME (decl) == NULL_TREE \
4674 || (DECL_ARTIFICIAL (decl) \
4675 && is_tagged_type (TREE_TYPE (decl)) \
4676 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4677 /* This is necessary for stub decls that \
4678 appear in nested inline functions. */ \
4679 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4680 && (decl_ultimate_origin (decl) \
4681 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4683 /* Information concerning the compilation unit's programming
4684 language, and compiler version. */
4686 /* Fixed size portion of the DWARF compilation unit header. */
4687 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4688 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4690 /* Fixed size portion of public names info. */
4691 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4693 /* Fixed size portion of the address range info. */
4694 #define DWARF_ARANGES_HEADER_SIZE \
4695 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4696 DWARF2_ADDR_SIZE * 2) \
4697 - DWARF_INITIAL_LENGTH_SIZE)
4699 /* Size of padding portion in the address range info. It must be
4700 aligned to twice the pointer size. */
4701 #define DWARF_ARANGES_PAD_SIZE \
4702 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4703 DWARF2_ADDR_SIZE * 2) \
4704 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4706 /* Use assembler line directives if available. */
4707 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4708 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4709 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4711 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4715 /* Minimum line offset in a special line info. opcode.
4716 This value was chosen to give a reasonable range of values. */
4717 #define DWARF_LINE_BASE -10
4719 /* First special line opcode - leave room for the standard opcodes. */
4720 #define DWARF_LINE_OPCODE_BASE 10
4722 /* Range of line offsets in a special line info. opcode. */
4723 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4725 /* Flag that indicates the initial value of the is_stmt_start flag.
4726 In the present implementation, we do not mark any lines as
4727 the beginning of a source statement, because that information
4728 is not made available by the GCC front-end. */
4729 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4731 #ifdef DWARF2_DEBUGGING_INFO
4732 /* This location is used by calc_die_sizes() to keep track
4733 the offset of each DIE within the .debug_info section. */
4734 static unsigned long next_die_offset;
4737 /* Record the root of the DIE's built for the current compilation unit. */
4738 static GTY(()) dw_die_ref comp_unit_die;
4740 /* A list of DIEs with a NULL parent waiting to be relocated. */
4741 static GTY(()) limbo_die_node *limbo_die_list;
4743 /* Filenames referenced by this compilation unit. */
4744 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4746 /* A hash table of references to DIE's that describe declarations.
4747 The key is a DECL_UID() which is a unique number identifying each decl. */
4748 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4750 /* Node of the variable location list. */
4751 struct var_loc_node GTY ((chain_next ("%h.next")))
4753 rtx GTY (()) var_loc_note;
4754 const char * GTY (()) label;
4755 const char * GTY (()) section_label;
4756 struct var_loc_node * GTY (()) next;
4759 /* Variable location list. */
4760 struct var_loc_list_def GTY (())
4762 struct var_loc_node * GTY (()) first;
4764 /* Do not mark the last element of the chained list because
4765 it is marked through the chain. */
4766 struct var_loc_node * GTY ((skip ("%h"))) last;
4768 /* DECL_UID of the variable decl. */
4769 unsigned int decl_id;
4771 typedef struct var_loc_list_def var_loc_list;
4774 /* Table of decl location linked lists. */
4775 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4777 /* A pointer to the base of a list of references to DIE's that
4778 are uniquely identified by their tag, presence/absence of
4779 children DIE's, and list of attribute/value pairs. */
4780 static GTY((length ("abbrev_die_table_allocated")))
4781 dw_die_ref *abbrev_die_table;
4783 /* Number of elements currently allocated for abbrev_die_table. */
4784 static GTY(()) unsigned abbrev_die_table_allocated;
4786 /* Number of elements in type_die_table currently in use. */
4787 static GTY(()) unsigned abbrev_die_table_in_use;
4789 /* Size (in elements) of increments by which we may expand the
4790 abbrev_die_table. */
4791 #define ABBREV_DIE_TABLE_INCREMENT 256
4793 /* A pointer to the base of a table that contains line information
4794 for each source code line in .text in the compilation unit. */
4795 static GTY((length ("line_info_table_allocated")))
4796 dw_line_info_ref line_info_table;
4798 /* Number of elements currently allocated for line_info_table. */
4799 static GTY(()) unsigned line_info_table_allocated;
4801 /* Number of elements in line_info_table currently in use. */
4802 static GTY(()) unsigned line_info_table_in_use;
4804 /* A pointer to the base of a table that contains line information
4805 for each source code line outside of .text in the compilation unit. */
4806 static GTY ((length ("separate_line_info_table_allocated")))
4807 dw_separate_line_info_ref separate_line_info_table;
4809 /* Number of elements currently allocated for separate_line_info_table. */
4810 static GTY(()) unsigned separate_line_info_table_allocated;
4812 /* Number of elements in separate_line_info_table currently in use. */
4813 static GTY(()) unsigned separate_line_info_table_in_use;
4815 /* Size (in elements) of increments by which we may expand the
4817 #define LINE_INFO_TABLE_INCREMENT 1024
4819 /* A pointer to the base of a table that contains a list of publicly
4820 accessible names. */
4821 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4823 /* A pointer to the base of a table that contains a list of publicly
4824 accessible types. */
4825 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4827 /* Array of dies for which we should generate .debug_arange info. */
4828 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4830 /* Number of elements currently allocated for arange_table. */
4831 static GTY(()) unsigned arange_table_allocated;
4833 /* Number of elements in arange_table currently in use. */
4834 static GTY(()) unsigned arange_table_in_use;
4836 /* Size (in elements) of increments by which we may expand the
4838 #define ARANGE_TABLE_INCREMENT 64
4840 /* Array of dies for which we should generate .debug_ranges info. */
4841 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4843 /* Number of elements currently allocated for ranges_table. */
4844 static GTY(()) unsigned ranges_table_allocated;
4846 /* Number of elements in ranges_table currently in use. */
4847 static GTY(()) unsigned ranges_table_in_use;
4849 /* Array of pairs of labels referenced in ranges_table. */
4850 static GTY ((length ("ranges_by_label_allocated")))
4851 dw_ranges_by_label_ref ranges_by_label;
4853 /* Number of elements currently allocated for ranges_by_label. */
4854 static GTY(()) unsigned ranges_by_label_allocated;
4856 /* Number of elements in ranges_by_label currently in use. */
4857 static GTY(()) unsigned ranges_by_label_in_use;
4859 /* Size (in elements) of increments by which we may expand the
4861 #define RANGES_TABLE_INCREMENT 64
4863 /* Whether we have location lists that need outputting */
4864 static GTY(()) bool have_location_lists;
4866 /* Unique label counter. */
4867 static GTY(()) unsigned int loclabel_num;
4869 #ifdef DWARF2_DEBUGGING_INFO
4870 /* Record whether the function being analyzed contains inlined functions. */
4871 static int current_function_has_inlines;
4873 #if 0 && defined (MIPS_DEBUGGING_INFO)
4874 static int comp_unit_has_inlines;
4877 /* The last file entry emitted by maybe_emit_file(). */
4878 static GTY(()) struct dwarf_file_data * last_emitted_file;
4880 /* Number of internal labels generated by gen_internal_sym(). */
4881 static GTY(()) int label_num;
4883 /* Cached result of previous call to lookup_filename. */
4884 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4886 #ifdef DWARF2_DEBUGGING_INFO
4888 /* Offset from the "steady-state frame pointer" to the frame base,
4889 within the current function. */
4890 static HOST_WIDE_INT frame_pointer_fb_offset;
4892 /* Forward declarations for functions defined in this file. */
4894 static int is_pseudo_reg (const_rtx);
4895 static tree type_main_variant (tree);
4896 static int is_tagged_type (const_tree);
4897 static const char *dwarf_tag_name (unsigned);
4898 static const char *dwarf_attr_name (unsigned);
4899 static const char *dwarf_form_name (unsigned);
4900 static tree decl_ultimate_origin (const_tree);
4901 static tree block_ultimate_origin (const_tree);
4902 static tree decl_class_context (tree);
4903 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4904 static inline enum dw_val_class AT_class (dw_attr_ref);
4905 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4906 static inline unsigned AT_flag (dw_attr_ref);
4907 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4908 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4909 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4910 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4911 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4913 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4914 unsigned int, unsigned char *);
4915 static hashval_t debug_str_do_hash (const void *);
4916 static int debug_str_eq (const void *, const void *);
4917 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4918 static inline const char *AT_string (dw_attr_ref);
4919 static int AT_string_form (dw_attr_ref);
4920 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4921 static void add_AT_specification (dw_die_ref, dw_die_ref);
4922 static inline dw_die_ref AT_ref (dw_attr_ref);
4923 static inline int AT_ref_external (dw_attr_ref);
4924 static inline void set_AT_ref_external (dw_attr_ref, int);
4925 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4926 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4927 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4928 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4930 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4931 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4932 static inline rtx AT_addr (dw_attr_ref);
4933 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4934 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4935 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4936 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4937 unsigned HOST_WIDE_INT);
4938 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4940 static inline const char *AT_lbl (dw_attr_ref);
4941 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4942 static const char *get_AT_low_pc (dw_die_ref);
4943 static const char *get_AT_hi_pc (dw_die_ref);
4944 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4945 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4946 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4947 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4948 static bool is_c_family (void);
4949 static bool is_cxx (void);
4950 static bool is_java (void);
4951 static bool is_fortran (void);
4952 static bool is_ada (void);
4953 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4954 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4955 static void add_child_die (dw_die_ref, dw_die_ref);
4956 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4957 static dw_die_ref lookup_type_die (tree);
4958 static void equate_type_number_to_die (tree, dw_die_ref);
4959 static hashval_t decl_die_table_hash (const void *);
4960 static int decl_die_table_eq (const void *, const void *);
4961 static dw_die_ref lookup_decl_die (tree);
4962 static hashval_t decl_loc_table_hash (const void *);
4963 static int decl_loc_table_eq (const void *, const void *);
4964 static var_loc_list *lookup_decl_loc (const_tree);
4965 static void equate_decl_number_to_die (tree, dw_die_ref);
4966 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4967 static void print_spaces (FILE *);
4968 static void print_die (dw_die_ref, FILE *);
4969 static void print_dwarf_line_table (FILE *);
4970 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4971 static dw_die_ref pop_compile_unit (dw_die_ref);
4972 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4973 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4974 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4975 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4976 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4977 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4978 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4979 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4980 static void compute_section_prefix (dw_die_ref);
4981 static int is_type_die (dw_die_ref);
4982 static int is_comdat_die (dw_die_ref);
4983 static int is_symbol_die (dw_die_ref);
4984 static void assign_symbol_names (dw_die_ref);
4985 static void break_out_includes (dw_die_ref);
4986 static hashval_t htab_cu_hash (const void *);
4987 static int htab_cu_eq (const void *, const void *);
4988 static void htab_cu_del (void *);
4989 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4990 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4991 static void add_sibling_attributes (dw_die_ref);
4992 static void build_abbrev_table (dw_die_ref);
4993 static void output_location_lists (dw_die_ref);
4994 static int constant_size (long unsigned);
4995 static unsigned long size_of_die (dw_die_ref);
4996 static void calc_die_sizes (dw_die_ref);
4997 static void mark_dies (dw_die_ref);
4998 static void unmark_dies (dw_die_ref);
4999 static void unmark_all_dies (dw_die_ref);
5000 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5001 static unsigned long size_of_aranges (void);
5002 static enum dwarf_form value_format (dw_attr_ref);
5003 static void output_value_format (dw_attr_ref);
5004 static void output_abbrev_section (void);
5005 static void output_die_symbol (dw_die_ref);
5006 static void output_die (dw_die_ref);
5007 static void output_compilation_unit_header (void);
5008 static void output_comp_unit (dw_die_ref, int);
5009 static const char *dwarf2_name (tree, int);
5010 static void add_pubname (tree, dw_die_ref);
5011 static void add_pubname_string (const char *, dw_die_ref);
5012 static void add_pubtype (tree, dw_die_ref);
5013 static void output_pubnames (VEC (pubname_entry,gc) *);
5014 static void add_arange (tree, dw_die_ref);
5015 static void output_aranges (void);
5016 static unsigned int add_ranges_num (int);
5017 static unsigned int add_ranges (const_tree);
5018 static unsigned int add_ranges_by_labels (const char *, const char *);
5019 static void output_ranges (void);
5020 static void output_line_info (void);
5021 static void output_file_names (void);
5022 static dw_die_ref base_type_die (tree);
5023 static int is_base_type (tree);
5024 static bool is_subrange_type (const_tree);
5025 static dw_die_ref subrange_type_die (tree, dw_die_ref);
5026 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5027 static int type_is_enum (const_tree);
5028 static unsigned int dbx_reg_number (const_rtx);
5029 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5030 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5031 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5032 enum var_init_status);
5033 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5034 enum var_init_status);
5035 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5036 enum var_init_status);
5037 static int is_based_loc (const_rtx);
5038 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5039 enum var_init_status);
5040 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5041 enum var_init_status);
5042 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5043 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5044 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5045 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5046 static tree field_type (const_tree);
5047 static unsigned int simple_type_align_in_bits (const_tree);
5048 static unsigned int simple_decl_align_in_bits (const_tree);
5049 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5050 static HOST_WIDE_INT field_byte_offset (const_tree);
5051 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5053 static void add_data_member_location_attribute (dw_die_ref, tree);
5054 static void add_const_value_attribute (dw_die_ref, rtx);
5055 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5056 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5057 static void insert_float (const_rtx, unsigned char *);
5058 static rtx rtl_for_decl_location (tree);
5059 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5060 enum dwarf_attribute);
5061 static void tree_add_const_value_attribute (dw_die_ref, tree);
5062 static void add_name_attribute (dw_die_ref, const char *);
5063 static void add_comp_dir_attribute (dw_die_ref);
5064 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5065 static void add_subscript_info (dw_die_ref, tree, bool);
5066 static void add_byte_size_attribute (dw_die_ref, tree);
5067 static void add_bit_offset_attribute (dw_die_ref, tree);
5068 static void add_bit_size_attribute (dw_die_ref, tree);
5069 static void add_prototyped_attribute (dw_die_ref, tree);
5070 static void add_abstract_origin_attribute (dw_die_ref, tree);
5071 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5072 static void add_src_coords_attributes (dw_die_ref, tree);
5073 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5074 static void push_decl_scope (tree);
5075 static void pop_decl_scope (void);
5076 static dw_die_ref scope_die_for (tree, dw_die_ref);
5077 static inline int local_scope_p (dw_die_ref);
5078 static inline int class_or_namespace_scope_p (dw_die_ref);
5079 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5080 static void add_calling_convention_attribute (dw_die_ref, tree);
5081 static const char *type_tag (const_tree);
5082 static tree member_declared_type (const_tree);
5084 static const char *decl_start_label (tree);
5086 static void gen_array_type_die (tree, dw_die_ref);
5087 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5089 static void gen_entry_point_die (tree, dw_die_ref);
5091 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
5092 static void gen_inlined_structure_type_die (tree, dw_die_ref);
5093 static void gen_inlined_union_type_die (tree, dw_die_ref);
5094 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5095 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
5096 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5097 static void gen_formal_types_die (tree, dw_die_ref);
5098 static void gen_subprogram_die (tree, dw_die_ref);
5099 static void gen_variable_die (tree, dw_die_ref);
5100 static void gen_label_die (tree, dw_die_ref);
5101 static void gen_lexical_block_die (tree, dw_die_ref, int);
5102 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5103 static void gen_field_die (tree, dw_die_ref);
5104 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5105 static dw_die_ref gen_compile_unit_die (const char *);
5106 static void gen_inheritance_die (tree, tree, dw_die_ref);
5107 static void gen_member_die (tree, dw_die_ref);
5108 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5109 enum debug_info_usage);
5110 static void gen_subroutine_type_die (tree, dw_die_ref);
5111 static void gen_typedef_die (tree, dw_die_ref);
5112 static void gen_type_die (tree, dw_die_ref);
5113 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
5114 static void gen_block_die (tree, dw_die_ref, int);
5115 static void decls_for_scope (tree, dw_die_ref, int);
5116 static int is_redundant_typedef (const_tree);
5117 static void gen_namespace_die (tree);
5118 static void gen_decl_die (tree, dw_die_ref);
5119 static dw_die_ref force_decl_die (tree);
5120 static dw_die_ref force_type_die (tree);
5121 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5122 static void declare_in_namespace (tree, dw_die_ref);
5123 static struct dwarf_file_data * lookup_filename (const char *);
5124 static void retry_incomplete_types (void);
5125 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5126 static void splice_child_die (dw_die_ref, dw_die_ref);
5127 static int file_info_cmp (const void *, const void *);
5128 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5129 const char *, const char *, unsigned);
5130 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5131 const char *, const char *,
5133 static void output_loc_list (dw_loc_list_ref);
5134 static char *gen_internal_sym (const char *);
5136 static void prune_unmark_dies (dw_die_ref);
5137 static void prune_unused_types_mark (dw_die_ref, int);
5138 static void prune_unused_types_walk (dw_die_ref);
5139 static void prune_unused_types_walk_attribs (dw_die_ref);
5140 static void prune_unused_types_prune (dw_die_ref);
5141 static void prune_unused_types (void);
5142 static int maybe_emit_file (struct dwarf_file_data *fd);
5144 /* Section names used to hold DWARF debugging information. */
5145 #ifndef DEBUG_INFO_SECTION
5146 #define DEBUG_INFO_SECTION ".debug_info"
5148 #ifndef DEBUG_ABBREV_SECTION
5149 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5151 #ifndef DEBUG_ARANGES_SECTION
5152 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5154 #ifndef DEBUG_MACINFO_SECTION
5155 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5157 #ifndef DEBUG_LINE_SECTION
5158 #define DEBUG_LINE_SECTION ".debug_line"
5160 #ifndef DEBUG_LOC_SECTION
5161 #define DEBUG_LOC_SECTION ".debug_loc"
5163 #ifndef DEBUG_PUBNAMES_SECTION
5164 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5166 #ifndef DEBUG_STR_SECTION
5167 #define DEBUG_STR_SECTION ".debug_str"
5169 #ifndef DEBUG_RANGES_SECTION
5170 #define DEBUG_RANGES_SECTION ".debug_ranges"
5173 /* Standard ELF section names for compiled code and data. */
5174 #ifndef TEXT_SECTION_NAME
5175 #define TEXT_SECTION_NAME ".text"
5178 /* Section flags for .debug_str section. */
5179 #define DEBUG_STR_SECTION_FLAGS \
5180 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5181 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5184 /* Labels we insert at beginning sections we can reference instead of
5185 the section names themselves. */
5187 #ifndef TEXT_SECTION_LABEL
5188 #define TEXT_SECTION_LABEL "Ltext"
5190 #ifndef COLD_TEXT_SECTION_LABEL
5191 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5193 #ifndef DEBUG_LINE_SECTION_LABEL
5194 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5196 #ifndef DEBUG_INFO_SECTION_LABEL
5197 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5199 #ifndef DEBUG_ABBREV_SECTION_LABEL
5200 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5202 #ifndef DEBUG_LOC_SECTION_LABEL
5203 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5205 #ifndef DEBUG_RANGES_SECTION_LABEL
5206 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5208 #ifndef DEBUG_MACINFO_SECTION_LABEL
5209 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5212 /* Definitions of defaults for formats and names of various special
5213 (artificial) labels which may be generated within this file (when the -g
5214 options is used and DWARF2_DEBUGGING_INFO is in effect.
5215 If necessary, these may be overridden from within the tm.h file, but
5216 typically, overriding these defaults is unnecessary. */
5218 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5219 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5220 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5221 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5222 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5223 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5224 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5225 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5226 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5227 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5229 #ifndef TEXT_END_LABEL
5230 #define TEXT_END_LABEL "Letext"
5232 #ifndef COLD_END_LABEL
5233 #define COLD_END_LABEL "Letext_cold"
5235 #ifndef BLOCK_BEGIN_LABEL
5236 #define BLOCK_BEGIN_LABEL "LBB"
5238 #ifndef BLOCK_END_LABEL
5239 #define BLOCK_END_LABEL "LBE"
5241 #ifndef LINE_CODE_LABEL
5242 #define LINE_CODE_LABEL "LM"
5244 #ifndef SEPARATE_LINE_CODE_LABEL
5245 #define SEPARATE_LINE_CODE_LABEL "LSM"
5249 /* We allow a language front-end to designate a function that is to be
5250 called to "demangle" any name before it is put into a DIE. */
5252 static const char *(*demangle_name_func) (const char *);
5255 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5257 demangle_name_func = func;
5260 /* Test if rtl node points to a pseudo register. */
5263 is_pseudo_reg (const_rtx rtl)
5265 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5266 || (GET_CODE (rtl) == SUBREG
5267 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5270 /* Return a reference to a type, with its const and volatile qualifiers
5274 type_main_variant (tree type)
5276 type = TYPE_MAIN_VARIANT (type);
5278 /* ??? There really should be only one main variant among any group of
5279 variants of a given type (and all of the MAIN_VARIANT values for all
5280 members of the group should point to that one type) but sometimes the C
5281 front-end messes this up for array types, so we work around that bug
5283 if (TREE_CODE (type) == ARRAY_TYPE)
5284 while (type != TYPE_MAIN_VARIANT (type))
5285 type = TYPE_MAIN_VARIANT (type);
5290 /* Return nonzero if the given type node represents a tagged type. */
5293 is_tagged_type (const_tree type)
5295 enum tree_code code = TREE_CODE (type);
5297 return (code == RECORD_TYPE || code == UNION_TYPE
5298 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5301 /* Convert a DIE tag into its string name. */
5304 dwarf_tag_name (unsigned int tag)
5308 case DW_TAG_padding:
5309 return "DW_TAG_padding";
5310 case DW_TAG_array_type:
5311 return "DW_TAG_array_type";
5312 case DW_TAG_class_type:
5313 return "DW_TAG_class_type";
5314 case DW_TAG_entry_point:
5315 return "DW_TAG_entry_point";
5316 case DW_TAG_enumeration_type:
5317 return "DW_TAG_enumeration_type";
5318 case DW_TAG_formal_parameter:
5319 return "DW_TAG_formal_parameter";
5320 case DW_TAG_imported_declaration:
5321 return "DW_TAG_imported_declaration";
5323 return "DW_TAG_label";
5324 case DW_TAG_lexical_block:
5325 return "DW_TAG_lexical_block";
5327 return "DW_TAG_member";
5328 case DW_TAG_pointer_type:
5329 return "DW_TAG_pointer_type";
5330 case DW_TAG_reference_type:
5331 return "DW_TAG_reference_type";
5332 case DW_TAG_compile_unit:
5333 return "DW_TAG_compile_unit";
5334 case DW_TAG_string_type:
5335 return "DW_TAG_string_type";
5336 case DW_TAG_structure_type:
5337 return "DW_TAG_structure_type";
5338 case DW_TAG_subroutine_type:
5339 return "DW_TAG_subroutine_type";
5340 case DW_TAG_typedef:
5341 return "DW_TAG_typedef";
5342 case DW_TAG_union_type:
5343 return "DW_TAG_union_type";
5344 case DW_TAG_unspecified_parameters:
5345 return "DW_TAG_unspecified_parameters";
5346 case DW_TAG_variant:
5347 return "DW_TAG_variant";
5348 case DW_TAG_common_block:
5349 return "DW_TAG_common_block";
5350 case DW_TAG_common_inclusion:
5351 return "DW_TAG_common_inclusion";
5352 case DW_TAG_inheritance:
5353 return "DW_TAG_inheritance";
5354 case DW_TAG_inlined_subroutine:
5355 return "DW_TAG_inlined_subroutine";
5357 return "DW_TAG_module";
5358 case DW_TAG_ptr_to_member_type:
5359 return "DW_TAG_ptr_to_member_type";
5360 case DW_TAG_set_type:
5361 return "DW_TAG_set_type";
5362 case DW_TAG_subrange_type:
5363 return "DW_TAG_subrange_type";
5364 case DW_TAG_with_stmt:
5365 return "DW_TAG_with_stmt";
5366 case DW_TAG_access_declaration:
5367 return "DW_TAG_access_declaration";
5368 case DW_TAG_base_type:
5369 return "DW_TAG_base_type";
5370 case DW_TAG_catch_block:
5371 return "DW_TAG_catch_block";
5372 case DW_TAG_const_type:
5373 return "DW_TAG_const_type";
5374 case DW_TAG_constant:
5375 return "DW_TAG_constant";
5376 case DW_TAG_enumerator:
5377 return "DW_TAG_enumerator";
5378 case DW_TAG_file_type:
5379 return "DW_TAG_file_type";
5381 return "DW_TAG_friend";
5382 case DW_TAG_namelist:
5383 return "DW_TAG_namelist";
5384 case DW_TAG_namelist_item:
5385 return "DW_TAG_namelist_item";
5386 case DW_TAG_packed_type:
5387 return "DW_TAG_packed_type";
5388 case DW_TAG_subprogram:
5389 return "DW_TAG_subprogram";
5390 case DW_TAG_template_type_param:
5391 return "DW_TAG_template_type_param";
5392 case DW_TAG_template_value_param:
5393 return "DW_TAG_template_value_param";
5394 case DW_TAG_thrown_type:
5395 return "DW_TAG_thrown_type";
5396 case DW_TAG_try_block:
5397 return "DW_TAG_try_block";
5398 case DW_TAG_variant_part:
5399 return "DW_TAG_variant_part";
5400 case DW_TAG_variable:
5401 return "DW_TAG_variable";
5402 case DW_TAG_volatile_type:
5403 return "DW_TAG_volatile_type";
5404 case DW_TAG_dwarf_procedure:
5405 return "DW_TAG_dwarf_procedure";
5406 case DW_TAG_restrict_type:
5407 return "DW_TAG_restrict_type";
5408 case DW_TAG_interface_type:
5409 return "DW_TAG_interface_type";
5410 case DW_TAG_namespace:
5411 return "DW_TAG_namespace";
5412 case DW_TAG_imported_module:
5413 return "DW_TAG_imported_module";
5414 case DW_TAG_unspecified_type:
5415 return "DW_TAG_unspecified_type";
5416 case DW_TAG_partial_unit:
5417 return "DW_TAG_partial_unit";
5418 case DW_TAG_imported_unit:
5419 return "DW_TAG_imported_unit";
5420 case DW_TAG_condition:
5421 return "DW_TAG_condition";
5422 case DW_TAG_shared_type:
5423 return "DW_TAG_shared_type";
5424 case DW_TAG_MIPS_loop:
5425 return "DW_TAG_MIPS_loop";
5426 case DW_TAG_format_label:
5427 return "DW_TAG_format_label";
5428 case DW_TAG_function_template:
5429 return "DW_TAG_function_template";
5430 case DW_TAG_class_template:
5431 return "DW_TAG_class_template";
5432 case DW_TAG_GNU_BINCL:
5433 return "DW_TAG_GNU_BINCL";
5434 case DW_TAG_GNU_EINCL:
5435 return "DW_TAG_GNU_EINCL";
5437 return "DW_TAG_<unknown>";
5441 /* Convert a DWARF attribute code into its string name. */
5444 dwarf_attr_name (unsigned int attr)
5449 return "DW_AT_sibling";
5450 case DW_AT_location:
5451 return "DW_AT_location";
5453 return "DW_AT_name";
5454 case DW_AT_ordering:
5455 return "DW_AT_ordering";
5456 case DW_AT_subscr_data:
5457 return "DW_AT_subscr_data";
5458 case DW_AT_byte_size:
5459 return "DW_AT_byte_size";
5460 case DW_AT_bit_offset:
5461 return "DW_AT_bit_offset";
5462 case DW_AT_bit_size:
5463 return "DW_AT_bit_size";
5464 case DW_AT_element_list:
5465 return "DW_AT_element_list";
5466 case DW_AT_stmt_list:
5467 return "DW_AT_stmt_list";
5469 return "DW_AT_low_pc";
5471 return "DW_AT_high_pc";
5472 case DW_AT_language:
5473 return "DW_AT_language";
5475 return "DW_AT_member";
5477 return "DW_AT_discr";
5478 case DW_AT_discr_value:
5479 return "DW_AT_discr_value";
5480 case DW_AT_visibility:
5481 return "DW_AT_visibility";
5483 return "DW_AT_import";
5484 case DW_AT_string_length:
5485 return "DW_AT_string_length";
5486 case DW_AT_common_reference:
5487 return "DW_AT_common_reference";
5488 case DW_AT_comp_dir:
5489 return "DW_AT_comp_dir";
5490 case DW_AT_const_value:
5491 return "DW_AT_const_value";
5492 case DW_AT_containing_type:
5493 return "DW_AT_containing_type";
5494 case DW_AT_default_value:
5495 return "DW_AT_default_value";
5497 return "DW_AT_inline";
5498 case DW_AT_is_optional:
5499 return "DW_AT_is_optional";
5500 case DW_AT_lower_bound:
5501 return "DW_AT_lower_bound";
5502 case DW_AT_producer:
5503 return "DW_AT_producer";
5504 case DW_AT_prototyped:
5505 return "DW_AT_prototyped";
5506 case DW_AT_return_addr:
5507 return "DW_AT_return_addr";
5508 case DW_AT_start_scope:
5509 return "DW_AT_start_scope";
5510 case DW_AT_bit_stride:
5511 return "DW_AT_bit_stride";
5512 case DW_AT_upper_bound:
5513 return "DW_AT_upper_bound";
5514 case DW_AT_abstract_origin:
5515 return "DW_AT_abstract_origin";
5516 case DW_AT_accessibility:
5517 return "DW_AT_accessibility";
5518 case DW_AT_address_class:
5519 return "DW_AT_address_class";
5520 case DW_AT_artificial:
5521 return "DW_AT_artificial";
5522 case DW_AT_base_types:
5523 return "DW_AT_base_types";
5524 case DW_AT_calling_convention:
5525 return "DW_AT_calling_convention";
5527 return "DW_AT_count";
5528 case DW_AT_data_member_location:
5529 return "DW_AT_data_member_location";
5530 case DW_AT_decl_column:
5531 return "DW_AT_decl_column";
5532 case DW_AT_decl_file:
5533 return "DW_AT_decl_file";
5534 case DW_AT_decl_line:
5535 return "DW_AT_decl_line";
5536 case DW_AT_declaration:
5537 return "DW_AT_declaration";
5538 case DW_AT_discr_list:
5539 return "DW_AT_discr_list";
5540 case DW_AT_encoding:
5541 return "DW_AT_encoding";
5542 case DW_AT_external:
5543 return "DW_AT_external";
5544 case DW_AT_frame_base:
5545 return "DW_AT_frame_base";
5547 return "DW_AT_friend";
5548 case DW_AT_identifier_case:
5549 return "DW_AT_identifier_case";
5550 case DW_AT_macro_info:
5551 return "DW_AT_macro_info";
5552 case DW_AT_namelist_items:
5553 return "DW_AT_namelist_items";
5554 case DW_AT_priority:
5555 return "DW_AT_priority";
5557 return "DW_AT_segment";
5558 case DW_AT_specification:
5559 return "DW_AT_specification";
5560 case DW_AT_static_link:
5561 return "DW_AT_static_link";
5563 return "DW_AT_type";
5564 case DW_AT_use_location:
5565 return "DW_AT_use_location";
5566 case DW_AT_variable_parameter:
5567 return "DW_AT_variable_parameter";
5568 case DW_AT_virtuality:
5569 return "DW_AT_virtuality";
5570 case DW_AT_vtable_elem_location:
5571 return "DW_AT_vtable_elem_location";
5573 case DW_AT_allocated:
5574 return "DW_AT_allocated";
5575 case DW_AT_associated:
5576 return "DW_AT_associated";
5577 case DW_AT_data_location:
5578 return "DW_AT_data_location";
5579 case DW_AT_byte_stride:
5580 return "DW_AT_byte_stride";
5581 case DW_AT_entry_pc:
5582 return "DW_AT_entry_pc";
5583 case DW_AT_use_UTF8:
5584 return "DW_AT_use_UTF8";
5585 case DW_AT_extension:
5586 return "DW_AT_extension";
5588 return "DW_AT_ranges";
5589 case DW_AT_trampoline:
5590 return "DW_AT_trampoline";
5591 case DW_AT_call_column:
5592 return "DW_AT_call_column";
5593 case DW_AT_call_file:
5594 return "DW_AT_call_file";
5595 case DW_AT_call_line:
5596 return "DW_AT_call_line";
5598 case DW_AT_MIPS_fde:
5599 return "DW_AT_MIPS_fde";
5600 case DW_AT_MIPS_loop_begin:
5601 return "DW_AT_MIPS_loop_begin";
5602 case DW_AT_MIPS_tail_loop_begin:
5603 return "DW_AT_MIPS_tail_loop_begin";
5604 case DW_AT_MIPS_epilog_begin:
5605 return "DW_AT_MIPS_epilog_begin";
5606 case DW_AT_MIPS_loop_unroll_factor:
5607 return "DW_AT_MIPS_loop_unroll_factor";
5608 case DW_AT_MIPS_software_pipeline_depth:
5609 return "DW_AT_MIPS_software_pipeline_depth";
5610 case DW_AT_MIPS_linkage_name:
5611 return "DW_AT_MIPS_linkage_name";
5612 case DW_AT_MIPS_stride:
5613 return "DW_AT_MIPS_stride";
5614 case DW_AT_MIPS_abstract_name:
5615 return "DW_AT_MIPS_abstract_name";
5616 case DW_AT_MIPS_clone_origin:
5617 return "DW_AT_MIPS_clone_origin";
5618 case DW_AT_MIPS_has_inlines:
5619 return "DW_AT_MIPS_has_inlines";
5621 case DW_AT_sf_names:
5622 return "DW_AT_sf_names";
5623 case DW_AT_src_info:
5624 return "DW_AT_src_info";
5625 case DW_AT_mac_info:
5626 return "DW_AT_mac_info";
5627 case DW_AT_src_coords:
5628 return "DW_AT_src_coords";
5629 case DW_AT_body_begin:
5630 return "DW_AT_body_begin";
5631 case DW_AT_body_end:
5632 return "DW_AT_body_end";
5633 case DW_AT_GNU_vector:
5634 return "DW_AT_GNU_vector";
5636 case DW_AT_VMS_rtnbeg_pd_address:
5637 return "DW_AT_VMS_rtnbeg_pd_address";
5640 return "DW_AT_<unknown>";
5644 /* Convert a DWARF value form code into its string name. */
5647 dwarf_form_name (unsigned int form)
5652 return "DW_FORM_addr";
5653 case DW_FORM_block2:
5654 return "DW_FORM_block2";
5655 case DW_FORM_block4:
5656 return "DW_FORM_block4";
5658 return "DW_FORM_data2";
5660 return "DW_FORM_data4";
5662 return "DW_FORM_data8";
5663 case DW_FORM_string:
5664 return "DW_FORM_string";
5666 return "DW_FORM_block";
5667 case DW_FORM_block1:
5668 return "DW_FORM_block1";
5670 return "DW_FORM_data1";
5672 return "DW_FORM_flag";
5674 return "DW_FORM_sdata";
5676 return "DW_FORM_strp";
5678 return "DW_FORM_udata";
5679 case DW_FORM_ref_addr:
5680 return "DW_FORM_ref_addr";
5682 return "DW_FORM_ref1";
5684 return "DW_FORM_ref2";
5686 return "DW_FORM_ref4";
5688 return "DW_FORM_ref8";
5689 case DW_FORM_ref_udata:
5690 return "DW_FORM_ref_udata";
5691 case DW_FORM_indirect:
5692 return "DW_FORM_indirect";
5694 return "DW_FORM_<unknown>";
5698 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5699 instance of an inlined instance of a decl which is local to an inline
5700 function, so we have to trace all of the way back through the origin chain
5701 to find out what sort of node actually served as the original seed for the
5705 decl_ultimate_origin (const_tree decl)
5707 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
5710 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5711 nodes in the function to point to themselves; ignore that if
5712 we're trying to output the abstract instance of this function. */
5713 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
5716 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5717 most distant ancestor, this should never happen. */
5718 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
5720 return DECL_ABSTRACT_ORIGIN (decl);
5723 /* Determine the "ultimate origin" of a block. The block may be an inlined
5724 instance of an inlined instance of a block which is local to an inline
5725 function, so we have to trace all of the way back through the origin chain
5726 to find out what sort of node actually served as the original seed for the
5730 block_ultimate_origin (const_tree block)
5732 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
5734 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5735 nodes in the function to point to themselves; ignore that if
5736 we're trying to output the abstract instance of this function. */
5737 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
5740 if (immediate_origin == NULL_TREE)
5745 tree lookahead = immediate_origin;
5749 ret_val = lookahead;
5750 lookahead = (TREE_CODE (ret_val) == BLOCK
5751 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
5753 while (lookahead != NULL && lookahead != ret_val);
5755 /* The block's abstract origin chain may not be the *ultimate* origin of
5756 the block. It could lead to a DECL that has an abstract origin set.
5757 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5758 will give us if it has one). Note that DECL's abstract origins are
5759 supposed to be the most distant ancestor (or so decl_ultimate_origin
5760 claims), so we don't need to loop following the DECL origins. */
5761 if (DECL_P (ret_val))
5762 return DECL_ORIGIN (ret_val);
5768 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5769 of a virtual function may refer to a base class, so we check the 'this'
5773 decl_class_context (tree decl)
5775 tree context = NULL_TREE;
5777 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5778 context = DECL_CONTEXT (decl);
5780 context = TYPE_MAIN_VARIANT
5781 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5783 if (context && !TYPE_P (context))
5784 context = NULL_TREE;
5789 /* Add an attribute/value pair to a DIE. */
5792 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5794 /* Maybe this should be an assert? */
5798 if (die->die_attr == NULL)
5799 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5800 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5803 static inline enum dw_val_class
5804 AT_class (dw_attr_ref a)
5806 return a->dw_attr_val.val_class;
5809 /* Add a flag value attribute to a DIE. */
5812 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5816 attr.dw_attr = attr_kind;
5817 attr.dw_attr_val.val_class = dw_val_class_flag;
5818 attr.dw_attr_val.v.val_flag = flag;
5819 add_dwarf_attr (die, &attr);
5822 static inline unsigned
5823 AT_flag (dw_attr_ref a)
5825 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5826 return a->dw_attr_val.v.val_flag;
5829 /* Add a signed integer attribute value to a DIE. */
5832 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5836 attr.dw_attr = attr_kind;
5837 attr.dw_attr_val.val_class = dw_val_class_const;
5838 attr.dw_attr_val.v.val_int = int_val;
5839 add_dwarf_attr (die, &attr);
5842 static inline HOST_WIDE_INT
5843 AT_int (dw_attr_ref a)
5845 gcc_assert (a && AT_class (a) == dw_val_class_const);
5846 return a->dw_attr_val.v.val_int;
5849 /* Add an unsigned integer attribute value to a DIE. */
5852 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5853 unsigned HOST_WIDE_INT unsigned_val)
5857 attr.dw_attr = attr_kind;
5858 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5859 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5860 add_dwarf_attr (die, &attr);
5863 static inline unsigned HOST_WIDE_INT
5864 AT_unsigned (dw_attr_ref a)
5866 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5867 return a->dw_attr_val.v.val_unsigned;
5870 /* Add an unsigned double integer attribute value to a DIE. */
5873 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5874 long unsigned int val_hi, long unsigned int val_low)
5878 attr.dw_attr = attr_kind;
5879 attr.dw_attr_val.val_class = dw_val_class_long_long;
5880 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5881 attr.dw_attr_val.v.val_long_long.low = val_low;
5882 add_dwarf_attr (die, &attr);
5885 /* Add a floating point attribute value to a DIE and return it. */
5888 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5889 unsigned int length, unsigned int elt_size, unsigned char *array)
5893 attr.dw_attr = attr_kind;
5894 attr.dw_attr_val.val_class = dw_val_class_vec;
5895 attr.dw_attr_val.v.val_vec.length = length;
5896 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5897 attr.dw_attr_val.v.val_vec.array = array;
5898 add_dwarf_attr (die, &attr);
5901 /* Hash and equality functions for debug_str_hash. */
5904 debug_str_do_hash (const void *x)
5906 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5910 debug_str_eq (const void *x1, const void *x2)
5912 return strcmp ((((const struct indirect_string_node *)x1)->str),
5913 (const char *)x2) == 0;
5916 /* Add a string attribute value to a DIE. */
5919 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5922 struct indirect_string_node *node;
5925 if (! debug_str_hash)
5926 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5927 debug_str_eq, NULL);
5929 slot = htab_find_slot_with_hash (debug_str_hash, str,
5930 htab_hash_string (str), INSERT);
5933 node = (struct indirect_string_node *)
5934 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5935 node->str = ggc_strdup (str);
5939 node = (struct indirect_string_node *) *slot;
5943 attr.dw_attr = attr_kind;
5944 attr.dw_attr_val.val_class = dw_val_class_str;
5945 attr.dw_attr_val.v.val_str = node;
5946 add_dwarf_attr (die, &attr);
5949 static inline const char *
5950 AT_string (dw_attr_ref a)
5952 gcc_assert (a && AT_class (a) == dw_val_class_str);
5953 return a->dw_attr_val.v.val_str->str;
5956 /* Find out whether a string should be output inline in DIE
5957 or out-of-line in .debug_str section. */
5960 AT_string_form (dw_attr_ref a)
5962 struct indirect_string_node *node;
5966 gcc_assert (a && AT_class (a) == dw_val_class_str);
5968 node = a->dw_attr_val.v.val_str;
5972 len = strlen (node->str) + 1;
5974 /* If the string is shorter or equal to the size of the reference, it is
5975 always better to put it inline. */
5976 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5977 return node->form = DW_FORM_string;
5979 /* If we cannot expect the linker to merge strings in .debug_str
5980 section, only put it into .debug_str if it is worth even in this
5982 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5983 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5984 return node->form = DW_FORM_string;
5986 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5987 ++dw2_string_counter;
5988 node->label = xstrdup (label);
5990 return node->form = DW_FORM_strp;
5993 /* Add a DIE reference attribute value to a DIE. */
5996 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6000 attr.dw_attr = attr_kind;
6001 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6002 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6003 attr.dw_attr_val.v.val_die_ref.external = 0;
6004 add_dwarf_attr (die, &attr);
6007 /* Add an AT_specification attribute to a DIE, and also make the back
6008 pointer from the specification to the definition. */
6011 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6013 add_AT_die_ref (die, DW_AT_specification, targ_die);
6014 gcc_assert (!targ_die->die_definition);
6015 targ_die->die_definition = die;
6018 static inline dw_die_ref
6019 AT_ref (dw_attr_ref a)
6021 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6022 return a->dw_attr_val.v.val_die_ref.die;
6026 AT_ref_external (dw_attr_ref a)
6028 if (a && AT_class (a) == dw_val_class_die_ref)
6029 return a->dw_attr_val.v.val_die_ref.external;
6035 set_AT_ref_external (dw_attr_ref a, int i)
6037 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6038 a->dw_attr_val.v.val_die_ref.external = i;
6041 /* Add an FDE reference attribute value to a DIE. */
6044 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6048 attr.dw_attr = attr_kind;
6049 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6050 attr.dw_attr_val.v.val_fde_index = targ_fde;
6051 add_dwarf_attr (die, &attr);
6054 /* Add a location description attribute value to a DIE. */
6057 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6061 attr.dw_attr = attr_kind;
6062 attr.dw_attr_val.val_class = dw_val_class_loc;
6063 attr.dw_attr_val.v.val_loc = loc;
6064 add_dwarf_attr (die, &attr);
6067 static inline dw_loc_descr_ref
6068 AT_loc (dw_attr_ref a)
6070 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6071 return a->dw_attr_val.v.val_loc;
6075 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6079 attr.dw_attr = attr_kind;
6080 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6081 attr.dw_attr_val.v.val_loc_list = loc_list;
6082 add_dwarf_attr (die, &attr);
6083 have_location_lists = true;
6086 static inline dw_loc_list_ref
6087 AT_loc_list (dw_attr_ref a)
6089 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6090 return a->dw_attr_val.v.val_loc_list;
6093 /* Add an address constant attribute value to a DIE. */
6096 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6100 attr.dw_attr = attr_kind;
6101 attr.dw_attr_val.val_class = dw_val_class_addr;
6102 attr.dw_attr_val.v.val_addr = addr;
6103 add_dwarf_attr (die, &attr);
6106 /* Get the RTX from to an address DIE attribute. */
6109 AT_addr (dw_attr_ref a)
6111 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6112 return a->dw_attr_val.v.val_addr;
6115 /* Add a file attribute value to a DIE. */
6118 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6119 struct dwarf_file_data *fd)
6123 attr.dw_attr = attr_kind;
6124 attr.dw_attr_val.val_class = dw_val_class_file;
6125 attr.dw_attr_val.v.val_file = fd;
6126 add_dwarf_attr (die, &attr);
6129 /* Get the dwarf_file_data from a file DIE attribute. */
6131 static inline struct dwarf_file_data *
6132 AT_file (dw_attr_ref a)
6134 gcc_assert (a && AT_class (a) == dw_val_class_file);
6135 return a->dw_attr_val.v.val_file;
6138 /* Add a label identifier attribute value to a DIE. */
6141 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6145 attr.dw_attr = attr_kind;
6146 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6147 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6148 add_dwarf_attr (die, &attr);
6151 /* Add a section offset attribute value to a DIE, an offset into the
6152 debug_line section. */
6155 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6160 attr.dw_attr = attr_kind;
6161 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6162 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6163 add_dwarf_attr (die, &attr);
6166 /* Add a section offset attribute value to a DIE, an offset into the
6167 debug_macinfo section. */
6170 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6175 attr.dw_attr = attr_kind;
6176 attr.dw_attr_val.val_class = dw_val_class_macptr;
6177 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6178 add_dwarf_attr (die, &attr);
6181 /* Add an offset attribute value to a DIE. */
6184 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6185 unsigned HOST_WIDE_INT offset)
6189 attr.dw_attr = attr_kind;
6190 attr.dw_attr_val.val_class = dw_val_class_offset;
6191 attr.dw_attr_val.v.val_offset = offset;
6192 add_dwarf_attr (die, &attr);
6195 /* Add an range_list attribute value to a DIE. */
6198 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6199 long unsigned int offset)
6203 attr.dw_attr = attr_kind;
6204 attr.dw_attr_val.val_class = dw_val_class_range_list;
6205 attr.dw_attr_val.v.val_offset = offset;
6206 add_dwarf_attr (die, &attr);
6209 static inline const char *
6210 AT_lbl (dw_attr_ref a)
6212 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6213 || AT_class (a) == dw_val_class_lineptr
6214 || AT_class (a) == dw_val_class_macptr));
6215 return a->dw_attr_val.v.val_lbl_id;
6218 /* Get the attribute of type attr_kind. */
6221 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6225 dw_die_ref spec = NULL;
6230 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6231 if (a->dw_attr == attr_kind)
6233 else if (a->dw_attr == DW_AT_specification
6234 || a->dw_attr == DW_AT_abstract_origin)
6238 return get_AT (spec, attr_kind);
6243 /* Return the "low pc" attribute value, typically associated with a subprogram
6244 DIE. Return null if the "low pc" attribute is either not present, or if it
6245 cannot be represented as an assembler label identifier. */
6247 static inline const char *
6248 get_AT_low_pc (dw_die_ref die)
6250 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6252 return a ? AT_lbl (a) : NULL;
6255 /* Return the "high pc" attribute value, typically associated with a subprogram
6256 DIE. Return null if the "high pc" attribute is either not present, or if it
6257 cannot be represented as an assembler label identifier. */
6259 static inline const char *
6260 get_AT_hi_pc (dw_die_ref die)
6262 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6264 return a ? AT_lbl (a) : NULL;
6267 /* Return the value of the string attribute designated by ATTR_KIND, or
6268 NULL if it is not present. */
6270 static inline const char *
6271 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6273 dw_attr_ref a = get_AT (die, attr_kind);
6275 return a ? AT_string (a) : NULL;
6278 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6279 if it is not present. */
6282 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6284 dw_attr_ref a = get_AT (die, attr_kind);
6286 return a ? AT_flag (a) : 0;
6289 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6290 if it is not present. */
6292 static inline unsigned
6293 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6295 dw_attr_ref a = get_AT (die, attr_kind);
6297 return a ? AT_unsigned (a) : 0;
6300 static inline dw_die_ref
6301 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6303 dw_attr_ref a = get_AT (die, attr_kind);
6305 return a ? AT_ref (a) : NULL;
6308 static inline struct dwarf_file_data *
6309 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6311 dw_attr_ref a = get_AT (die, attr_kind);
6313 return a ? AT_file (a) : NULL;
6316 /* Return TRUE if the language is C or C++. */
6321 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6323 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6324 || lang == DW_LANG_C99
6325 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6328 /* Return TRUE if the language is C++. */
6333 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6335 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6338 /* Return TRUE if the language is Fortran. */
6343 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6345 return (lang == DW_LANG_Fortran77
6346 || lang == DW_LANG_Fortran90
6347 || lang == DW_LANG_Fortran95);
6350 /* Return TRUE if the language is Java. */
6355 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6357 return lang == DW_LANG_Java;
6360 /* Return TRUE if the language is Ada. */
6365 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6367 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6370 /* Remove the specified attribute if present. */
6373 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6381 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6382 if (a->dw_attr == attr_kind)
6384 if (AT_class (a) == dw_val_class_str)
6385 if (a->dw_attr_val.v.val_str->refcount)
6386 a->dw_attr_val.v.val_str->refcount--;
6388 /* VEC_ordered_remove should help reduce the number of abbrevs
6390 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6395 /* Remove CHILD from its parent. PREV must have the property that
6396 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6399 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6401 gcc_assert (child->die_parent == prev->die_parent);
6402 gcc_assert (prev->die_sib == child);
6405 gcc_assert (child->die_parent->die_child == child);
6409 prev->die_sib = child->die_sib;
6410 if (child->die_parent->die_child == child)
6411 child->die_parent->die_child = prev;
6414 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6418 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6424 dw_die_ref prev = c;
6426 while (c->die_tag == tag)
6428 remove_child_with_prev (c, prev);
6429 /* Might have removed every child. */
6430 if (c == c->die_sib)
6434 } while (c != die->die_child);
6437 /* Add a CHILD_DIE as the last child of DIE. */
6440 add_child_die (dw_die_ref die, dw_die_ref child_die)
6442 /* FIXME this should probably be an assert. */
6443 if (! die || ! child_die)
6445 gcc_assert (die != child_die);
6447 child_die->die_parent = die;
6450 child_die->die_sib = die->die_child->die_sib;
6451 die->die_child->die_sib = child_die;
6454 child_die->die_sib = child_die;
6455 die->die_child = child_die;
6458 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6459 is the specification, to the end of PARENT's list of children.
6460 This is done by removing and re-adding it. */
6463 splice_child_die (dw_die_ref parent, dw_die_ref child)
6467 /* We want the declaration DIE from inside the class, not the
6468 specification DIE at toplevel. */
6469 if (child->die_parent != parent)
6471 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6477 gcc_assert (child->die_parent == parent
6478 || (child->die_parent
6479 == get_AT_ref (parent, DW_AT_specification)));
6481 for (p = child->die_parent->die_child; ; p = p->die_sib)
6482 if (p->die_sib == child)
6484 remove_child_with_prev (child, p);
6488 add_child_die (parent, child);
6491 /* Return a pointer to a newly created DIE node. */
6493 static inline dw_die_ref
6494 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6496 dw_die_ref die = GGC_CNEW (die_node);
6498 die->die_tag = tag_value;
6500 if (parent_die != NULL)
6501 add_child_die (parent_die, die);
6504 limbo_die_node *limbo_node;
6506 limbo_node = GGC_CNEW (limbo_die_node);
6507 limbo_node->die = die;
6508 limbo_node->created_for = t;
6509 limbo_node->next = limbo_die_list;
6510 limbo_die_list = limbo_node;
6516 /* Return the DIE associated with the given type specifier. */
6518 static inline dw_die_ref
6519 lookup_type_die (tree type)
6521 return TYPE_SYMTAB_DIE (type);
6524 /* Equate a DIE to a given type specifier. */
6527 equate_type_number_to_die (tree type, dw_die_ref type_die)
6529 TYPE_SYMTAB_DIE (type) = type_die;
6532 /* Returns a hash value for X (which really is a die_struct). */
6535 decl_die_table_hash (const void *x)
6537 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6540 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6543 decl_die_table_eq (const void *x, const void *y)
6545 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6548 /* Return the DIE associated with a given declaration. */
6550 static inline dw_die_ref
6551 lookup_decl_die (tree decl)
6553 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6556 /* Returns a hash value for X (which really is a var_loc_list). */
6559 decl_loc_table_hash (const void *x)
6561 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6564 /* Return nonzero if decl_id of var_loc_list X is the same as
6568 decl_loc_table_eq (const void *x, const void *y)
6570 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6573 /* Return the var_loc list associated with a given declaration. */
6575 static inline var_loc_list *
6576 lookup_decl_loc (const_tree decl)
6578 return (var_loc_list *)
6579 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6582 /* Equate a DIE to a particular declaration. */
6585 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6587 unsigned int decl_id = DECL_UID (decl);
6590 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6592 decl_die->decl_id = decl_id;
6595 /* Add a variable location node to the linked list for DECL. */
6598 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6600 unsigned int decl_id = DECL_UID (decl);
6604 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6607 temp = GGC_CNEW (var_loc_list);
6608 temp->decl_id = decl_id;
6612 temp = (var_loc_list *) *slot;
6616 /* If the current location is the same as the end of the list,
6617 and either both or neither of the locations is uninitialized,
6618 we have nothing to do. */
6619 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6620 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6621 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6622 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6623 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6624 == VAR_INIT_STATUS_UNINITIALIZED)
6625 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6626 == VAR_INIT_STATUS_UNINITIALIZED))))
6628 /* Add LOC to the end of list and update LAST. */
6629 temp->last->next = loc;
6633 /* Do not add empty location to the beginning of the list. */
6634 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
6641 /* Keep track of the number of spaces used to indent the
6642 output of the debugging routines that print the structure of
6643 the DIE internal representation. */
6644 static int print_indent;
6646 /* Indent the line the number of spaces given by print_indent. */
6649 print_spaces (FILE *outfile)
6651 fprintf (outfile, "%*s", print_indent, "");
6654 /* Print the information associated with a given DIE, and its children.
6655 This routine is a debugging aid only. */
6658 print_die (dw_die_ref die, FILE *outfile)
6664 print_spaces (outfile);
6665 fprintf (outfile, "DIE %4ld: %s\n",
6666 die->die_offset, dwarf_tag_name (die->die_tag));
6667 print_spaces (outfile);
6668 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6669 fprintf (outfile, " offset: %ld\n", die->die_offset);
6671 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6673 print_spaces (outfile);
6674 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6676 switch (AT_class (a))
6678 case dw_val_class_addr:
6679 fprintf (outfile, "address");
6681 case dw_val_class_offset:
6682 fprintf (outfile, "offset");
6684 case dw_val_class_loc:
6685 fprintf (outfile, "location descriptor");
6687 case dw_val_class_loc_list:
6688 fprintf (outfile, "location list -> label:%s",
6689 AT_loc_list (a)->ll_symbol);
6691 case dw_val_class_range_list:
6692 fprintf (outfile, "range list");
6694 case dw_val_class_const:
6695 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6697 case dw_val_class_unsigned_const:
6698 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6700 case dw_val_class_long_long:
6701 fprintf (outfile, "constant (%lu,%lu)",
6702 a->dw_attr_val.v.val_long_long.hi,
6703 a->dw_attr_val.v.val_long_long.low);
6705 case dw_val_class_vec:
6706 fprintf (outfile, "floating-point or vector constant");
6708 case dw_val_class_flag:
6709 fprintf (outfile, "%u", AT_flag (a));
6711 case dw_val_class_die_ref:
6712 if (AT_ref (a) != NULL)
6714 if (AT_ref (a)->die_symbol)
6715 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
6717 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6720 fprintf (outfile, "die -> <null>");
6722 case dw_val_class_lbl_id:
6723 case dw_val_class_lineptr:
6724 case dw_val_class_macptr:
6725 fprintf (outfile, "label: %s", AT_lbl (a));
6727 case dw_val_class_str:
6728 if (AT_string (a) != NULL)
6729 fprintf (outfile, "\"%s\"", AT_string (a));
6731 fprintf (outfile, "<null>");
6733 case dw_val_class_file:
6734 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6735 AT_file (a)->emitted_number);
6741 fprintf (outfile, "\n");
6744 if (die->die_child != NULL)
6747 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6750 if (print_indent == 0)
6751 fprintf (outfile, "\n");
6754 /* Print the contents of the source code line number correspondence table.
6755 This routine is a debugging aid only. */
6758 print_dwarf_line_table (FILE *outfile)
6761 dw_line_info_ref line_info;
6763 fprintf (outfile, "\n\nDWARF source line information\n");
6764 for (i = 1; i < line_info_table_in_use; i++)
6766 line_info = &line_info_table[i];
6767 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6768 line_info->dw_file_num,
6769 line_info->dw_line_num);
6772 fprintf (outfile, "\n\n");
6775 /* Print the information collected for a given DIE. */
6778 debug_dwarf_die (dw_die_ref die)
6780 print_die (die, stderr);
6783 /* Print all DWARF information collected for the compilation unit.
6784 This routine is a debugging aid only. */
6790 print_die (comp_unit_die, stderr);
6791 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6792 print_dwarf_line_table (stderr);
6795 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6796 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6797 DIE that marks the start of the DIEs for this include file. */
6800 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6802 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6803 dw_die_ref new_unit = gen_compile_unit_die (filename);
6805 new_unit->die_sib = old_unit;
6809 /* Close an include-file CU and reopen the enclosing one. */
6812 pop_compile_unit (dw_die_ref old_unit)
6814 dw_die_ref new_unit = old_unit->die_sib;
6816 old_unit->die_sib = NULL;
6820 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6821 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6823 /* Calculate the checksum of a location expression. */
6826 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6828 CHECKSUM (loc->dw_loc_opc);
6829 CHECKSUM (loc->dw_loc_oprnd1);
6830 CHECKSUM (loc->dw_loc_oprnd2);
6833 /* Calculate the checksum of an attribute. */
6836 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6838 dw_loc_descr_ref loc;
6841 CHECKSUM (at->dw_attr);
6843 /* We don't care that this was compiled with a different compiler
6844 snapshot; if the output is the same, that's what matters. */
6845 if (at->dw_attr == DW_AT_producer)
6848 switch (AT_class (at))
6850 case dw_val_class_const:
6851 CHECKSUM (at->dw_attr_val.v.val_int);
6853 case dw_val_class_unsigned_const:
6854 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6856 case dw_val_class_long_long:
6857 CHECKSUM (at->dw_attr_val.v.val_long_long);
6859 case dw_val_class_vec:
6860 CHECKSUM (at->dw_attr_val.v.val_vec);
6862 case dw_val_class_flag:
6863 CHECKSUM (at->dw_attr_val.v.val_flag);
6865 case dw_val_class_str:
6866 CHECKSUM_STRING (AT_string (at));
6869 case dw_val_class_addr:
6871 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6872 CHECKSUM_STRING (XSTR (r, 0));
6875 case dw_val_class_offset:
6876 CHECKSUM (at->dw_attr_val.v.val_offset);
6879 case dw_val_class_loc:
6880 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6881 loc_checksum (loc, ctx);
6884 case dw_val_class_die_ref:
6885 die_checksum (AT_ref (at), ctx, mark);
6888 case dw_val_class_fde_ref:
6889 case dw_val_class_lbl_id:
6890 case dw_val_class_lineptr:
6891 case dw_val_class_macptr:
6894 case dw_val_class_file:
6895 CHECKSUM_STRING (AT_file (at)->filename);
6903 /* Calculate the checksum of a DIE. */
6906 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6912 /* To avoid infinite recursion. */
6915 CHECKSUM (die->die_mark);
6918 die->die_mark = ++(*mark);
6920 CHECKSUM (die->die_tag);
6922 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6923 attr_checksum (a, ctx, mark);
6925 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6929 #undef CHECKSUM_STRING
6931 /* Do the location expressions look same? */
6933 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6935 return loc1->dw_loc_opc == loc2->dw_loc_opc
6936 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6937 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6940 /* Do the values look the same? */
6942 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6944 dw_loc_descr_ref loc1, loc2;
6947 if (v1->val_class != v2->val_class)
6950 switch (v1->val_class)
6952 case dw_val_class_const:
6953 return v1->v.val_int == v2->v.val_int;
6954 case dw_val_class_unsigned_const:
6955 return v1->v.val_unsigned == v2->v.val_unsigned;
6956 case dw_val_class_long_long:
6957 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6958 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6959 case dw_val_class_vec:
6960 if (v1->v.val_vec.length != v2->v.val_vec.length
6961 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6963 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6964 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6967 case dw_val_class_flag:
6968 return v1->v.val_flag == v2->v.val_flag;
6969 case dw_val_class_str:
6970 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6972 case dw_val_class_addr:
6973 r1 = v1->v.val_addr;
6974 r2 = v2->v.val_addr;
6975 if (GET_CODE (r1) != GET_CODE (r2))
6977 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6978 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6980 case dw_val_class_offset:
6981 return v1->v.val_offset == v2->v.val_offset;
6983 case dw_val_class_loc:
6984 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6986 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6987 if (!same_loc_p (loc1, loc2, mark))
6989 return !loc1 && !loc2;
6991 case dw_val_class_die_ref:
6992 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6994 case dw_val_class_fde_ref:
6995 case dw_val_class_lbl_id:
6996 case dw_val_class_lineptr:
6997 case dw_val_class_macptr:
7000 case dw_val_class_file:
7001 return v1->v.val_file == v2->v.val_file;
7008 /* Do the attributes look the same? */
7011 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7013 if (at1->dw_attr != at2->dw_attr)
7016 /* We don't care that this was compiled with a different compiler
7017 snapshot; if the output is the same, that's what matters. */
7018 if (at1->dw_attr == DW_AT_producer)
7021 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7024 /* Do the dies look the same? */
7027 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7033 /* To avoid infinite recursion. */
7035 return die1->die_mark == die2->die_mark;
7036 die1->die_mark = die2->die_mark = ++(*mark);
7038 if (die1->die_tag != die2->die_tag)
7041 if (VEC_length (dw_attr_node, die1->die_attr)
7042 != VEC_length (dw_attr_node, die2->die_attr))
7045 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7046 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7049 c1 = die1->die_child;
7050 c2 = die2->die_child;
7059 if (!same_die_p (c1, c2, mark))
7063 if (c1 == die1->die_child)
7065 if (c2 == die2->die_child)
7075 /* Do the dies look the same? Wrapper around same_die_p. */
7078 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7081 int ret = same_die_p (die1, die2, &mark);
7083 unmark_all_dies (die1);
7084 unmark_all_dies (die2);
7089 /* The prefix to attach to symbols on DIEs in the current comdat debug
7091 static char *comdat_symbol_id;
7093 /* The index of the current symbol within the current comdat CU. */
7094 static unsigned int comdat_symbol_number;
7096 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7097 children, and set comdat_symbol_id accordingly. */
7100 compute_section_prefix (dw_die_ref unit_die)
7102 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7103 const char *base = die_name ? lbasename (die_name) : "anonymous";
7104 char *name = XALLOCAVEC (char, strlen (base) + 64);
7107 unsigned char checksum[16];
7110 /* Compute the checksum of the DIE, then append part of it as hex digits to
7111 the name filename of the unit. */
7113 md5_init_ctx (&ctx);
7115 die_checksum (unit_die, &ctx, &mark);
7116 unmark_all_dies (unit_die);
7117 md5_finish_ctx (&ctx, checksum);
7119 sprintf (name, "%s.", base);
7120 clean_symbol_name (name);
7122 p = name + strlen (name);
7123 for (i = 0; i < 4; i++)
7125 sprintf (p, "%.2x", checksum[i]);
7129 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7130 comdat_symbol_number = 0;
7133 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7136 is_type_die (dw_die_ref die)
7138 switch (die->die_tag)
7140 case DW_TAG_array_type:
7141 case DW_TAG_class_type:
7142 case DW_TAG_interface_type:
7143 case DW_TAG_enumeration_type:
7144 case DW_TAG_pointer_type:
7145 case DW_TAG_reference_type:
7146 case DW_TAG_string_type:
7147 case DW_TAG_structure_type:
7148 case DW_TAG_subroutine_type:
7149 case DW_TAG_union_type:
7150 case DW_TAG_ptr_to_member_type:
7151 case DW_TAG_set_type:
7152 case DW_TAG_subrange_type:
7153 case DW_TAG_base_type:
7154 case DW_TAG_const_type:
7155 case DW_TAG_file_type:
7156 case DW_TAG_packed_type:
7157 case DW_TAG_volatile_type:
7158 case DW_TAG_typedef:
7165 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7166 Basically, we want to choose the bits that are likely to be shared between
7167 compilations (types) and leave out the bits that are specific to individual
7168 compilations (functions). */
7171 is_comdat_die (dw_die_ref c)
7173 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7174 we do for stabs. The advantage is a greater likelihood of sharing between
7175 objects that don't include headers in the same order (and therefore would
7176 put the base types in a different comdat). jason 8/28/00 */
7178 if (c->die_tag == DW_TAG_base_type)
7181 if (c->die_tag == DW_TAG_pointer_type
7182 || c->die_tag == DW_TAG_reference_type
7183 || c->die_tag == DW_TAG_const_type
7184 || c->die_tag == DW_TAG_volatile_type)
7186 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7188 return t ? is_comdat_die (t) : 0;
7191 return is_type_die (c);
7194 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7195 compilation unit. */
7198 is_symbol_die (dw_die_ref c)
7200 return (is_type_die (c)
7201 || (get_AT (c, DW_AT_declaration)
7202 && !get_AT (c, DW_AT_specification))
7203 || c->die_tag == DW_TAG_namespace);
7207 gen_internal_sym (const char *prefix)
7211 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7212 return xstrdup (buf);
7215 /* Assign symbols to all worthy DIEs under DIE. */
7218 assign_symbol_names (dw_die_ref die)
7222 if (is_symbol_die (die))
7224 if (comdat_symbol_id)
7226 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7228 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7229 comdat_symbol_id, comdat_symbol_number++);
7230 die->die_symbol = xstrdup (p);
7233 die->die_symbol = gen_internal_sym ("LDIE");
7236 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7239 struct cu_hash_table_entry
7242 unsigned min_comdat_num, max_comdat_num;
7243 struct cu_hash_table_entry *next;
7246 /* Routines to manipulate hash table of CUs. */
7248 htab_cu_hash (const void *of)
7250 const struct cu_hash_table_entry *const entry =
7251 (const struct cu_hash_table_entry *) of;
7253 return htab_hash_string (entry->cu->die_symbol);
7257 htab_cu_eq (const void *of1, const void *of2)
7259 const struct cu_hash_table_entry *const entry1 =
7260 (const struct cu_hash_table_entry *) of1;
7261 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7263 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7267 htab_cu_del (void *what)
7269 struct cu_hash_table_entry *next,
7270 *entry = (struct cu_hash_table_entry *) what;
7280 /* Check whether we have already seen this CU and set up SYM_NUM
7283 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7285 struct cu_hash_table_entry dummy;
7286 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7288 dummy.max_comdat_num = 0;
7290 slot = (struct cu_hash_table_entry **)
7291 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7295 for (; entry; last = entry, entry = entry->next)
7297 if (same_die_p_wrap (cu, entry->cu))
7303 *sym_num = entry->min_comdat_num;
7307 entry = XCNEW (struct cu_hash_table_entry);
7309 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7310 entry->next = *slot;
7316 /* Record SYM_NUM to record of CU in HTABLE. */
7318 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7320 struct cu_hash_table_entry **slot, *entry;
7322 slot = (struct cu_hash_table_entry **)
7323 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7327 entry->max_comdat_num = sym_num;
7330 /* Traverse the DIE (which is always comp_unit_die), and set up
7331 additional compilation units for each of the include files we see
7332 bracketed by BINCL/EINCL. */
7335 break_out_includes (dw_die_ref die)
7338 dw_die_ref unit = NULL;
7339 limbo_die_node *node, **pnode;
7340 htab_t cu_hash_table;
7344 dw_die_ref prev = c;
7346 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7347 || (unit && is_comdat_die (c)))
7349 dw_die_ref next = c->die_sib;
7351 /* This DIE is for a secondary CU; remove it from the main one. */
7352 remove_child_with_prev (c, prev);
7354 if (c->die_tag == DW_TAG_GNU_BINCL)
7355 unit = push_new_compile_unit (unit, c);
7356 else if (c->die_tag == DW_TAG_GNU_EINCL)
7357 unit = pop_compile_unit (unit);
7359 add_child_die (unit, c);
7361 if (c == die->die_child)
7364 } while (c != die->die_child);
7367 /* We can only use this in debugging, since the frontend doesn't check
7368 to make sure that we leave every include file we enter. */
7372 assign_symbol_names (die);
7373 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7374 for (node = limbo_die_list, pnode = &limbo_die_list;
7380 compute_section_prefix (node->die);
7381 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7382 &comdat_symbol_number);
7383 assign_symbol_names (node->die);
7385 *pnode = node->next;
7388 pnode = &node->next;
7389 record_comdat_symbol_number (node->die, cu_hash_table,
7390 comdat_symbol_number);
7393 htab_delete (cu_hash_table);
7396 /* Traverse the DIE and add a sibling attribute if it may have the
7397 effect of speeding up access to siblings. To save some space,
7398 avoid generating sibling attributes for DIE's without children. */
7401 add_sibling_attributes (dw_die_ref die)
7405 if (! die->die_child)
7408 if (die->die_parent && die != die->die_parent->die_child)
7409 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7411 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7414 /* Output all location lists for the DIE and its children. */
7417 output_location_lists (dw_die_ref die)
7423 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7424 if (AT_class (a) == dw_val_class_loc_list)
7425 output_loc_list (AT_loc_list (a));
7427 FOR_EACH_CHILD (die, c, output_location_lists (c));
7430 /* The format of each DIE (and its attribute value pairs) is encoded in an
7431 abbreviation table. This routine builds the abbreviation table and assigns
7432 a unique abbreviation id for each abbreviation entry. The children of each
7433 die are visited recursively. */
7436 build_abbrev_table (dw_die_ref die)
7438 unsigned long abbrev_id;
7439 unsigned int n_alloc;
7444 /* Scan the DIE references, and mark as external any that refer to
7445 DIEs from other CUs (i.e. those which are not marked). */
7446 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7447 if (AT_class (a) == dw_val_class_die_ref
7448 && AT_ref (a)->die_mark == 0)
7450 gcc_assert (AT_ref (a)->die_symbol);
7452 set_AT_ref_external (a, 1);
7455 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7457 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7458 dw_attr_ref die_a, abbrev_a;
7462 if (abbrev->die_tag != die->die_tag)
7464 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7467 if (VEC_length (dw_attr_node, abbrev->die_attr)
7468 != VEC_length (dw_attr_node, die->die_attr))
7471 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7473 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7474 if ((abbrev_a->dw_attr != die_a->dw_attr)
7475 || (value_format (abbrev_a) != value_format (die_a)))
7485 if (abbrev_id >= abbrev_die_table_in_use)
7487 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7489 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7490 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7493 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7494 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7495 abbrev_die_table_allocated = n_alloc;
7498 ++abbrev_die_table_in_use;
7499 abbrev_die_table[abbrev_id] = die;
7502 die->die_abbrev = abbrev_id;
7503 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7506 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7509 constant_size (long unsigned int value)
7516 log = floor_log2 (value);
7519 log = 1 << (floor_log2 (log) + 1);
7524 /* Return the size of a DIE as it is represented in the
7525 .debug_info section. */
7527 static unsigned long
7528 size_of_die (dw_die_ref die)
7530 unsigned long size = 0;
7534 size += size_of_uleb128 (die->die_abbrev);
7535 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7537 switch (AT_class (a))
7539 case dw_val_class_addr:
7540 size += DWARF2_ADDR_SIZE;
7542 case dw_val_class_offset:
7543 size += DWARF_OFFSET_SIZE;
7545 case dw_val_class_loc:
7547 unsigned long lsize = size_of_locs (AT_loc (a));
7550 size += constant_size (lsize);
7554 case dw_val_class_loc_list:
7555 size += DWARF_OFFSET_SIZE;
7557 case dw_val_class_range_list:
7558 size += DWARF_OFFSET_SIZE;
7560 case dw_val_class_const:
7561 size += size_of_sleb128 (AT_int (a));
7563 case dw_val_class_unsigned_const:
7564 size += constant_size (AT_unsigned (a));
7566 case dw_val_class_long_long:
7567 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7569 case dw_val_class_vec:
7570 size += 1 + (a->dw_attr_val.v.val_vec.length
7571 * a->dw_attr_val.v.val_vec.elt_size); /* block */
7573 case dw_val_class_flag:
7576 case dw_val_class_die_ref:
7577 if (AT_ref_external (a))
7578 size += DWARF2_ADDR_SIZE;
7580 size += DWARF_OFFSET_SIZE;
7582 case dw_val_class_fde_ref:
7583 size += DWARF_OFFSET_SIZE;
7585 case dw_val_class_lbl_id:
7586 size += DWARF2_ADDR_SIZE;
7588 case dw_val_class_lineptr:
7589 case dw_val_class_macptr:
7590 size += DWARF_OFFSET_SIZE;
7592 case dw_val_class_str:
7593 if (AT_string_form (a) == DW_FORM_strp)
7594 size += DWARF_OFFSET_SIZE;
7596 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7598 case dw_val_class_file:
7599 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7609 /* Size the debugging information associated with a given DIE. Visits the
7610 DIE's children recursively. Updates the global variable next_die_offset, on
7611 each time through. Uses the current value of next_die_offset to update the
7612 die_offset field in each DIE. */
7615 calc_die_sizes (dw_die_ref die)
7619 die->die_offset = next_die_offset;
7620 next_die_offset += size_of_die (die);
7622 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7624 if (die->die_child != NULL)
7625 /* Count the null byte used to terminate sibling lists. */
7626 next_die_offset += 1;
7629 /* Set the marks for a die and its children. We do this so
7630 that we know whether or not a reference needs to use FORM_ref_addr; only
7631 DIEs in the same CU will be marked. We used to clear out the offset
7632 and use that as the flag, but ran into ordering problems. */
7635 mark_dies (dw_die_ref die)
7639 gcc_assert (!die->die_mark);
7642 FOR_EACH_CHILD (die, c, mark_dies (c));
7645 /* Clear the marks for a die and its children. */
7648 unmark_dies (dw_die_ref die)
7652 gcc_assert (die->die_mark);
7655 FOR_EACH_CHILD (die, c, unmark_dies (c));
7658 /* Clear the marks for a die, its children and referred dies. */
7661 unmark_all_dies (dw_die_ref die)
7671 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7673 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7674 if (AT_class (a) == dw_val_class_die_ref)
7675 unmark_all_dies (AT_ref (a));
7678 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7679 generated for the compilation unit. */
7681 static unsigned long
7682 size_of_pubnames (VEC (pubname_entry, gc) * names)
7688 size = DWARF_PUBNAMES_HEADER_SIZE;
7689 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7690 if (names != pubtype_table
7691 || p->die->die_offset != 0
7692 || !flag_eliminate_unused_debug_types)
7693 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7695 size += DWARF_OFFSET_SIZE;
7699 /* Return the size of the information in the .debug_aranges section. */
7701 static unsigned long
7702 size_of_aranges (void)
7706 size = DWARF_ARANGES_HEADER_SIZE;
7708 /* Count the address/length pair for this compilation unit. */
7709 if (text_section_used)
7710 size += 2 * DWARF2_ADDR_SIZE;
7711 if (cold_text_section_used)
7712 size += 2 * DWARF2_ADDR_SIZE;
7713 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7715 /* Count the two zero words used to terminated the address range table. */
7716 size += 2 * DWARF2_ADDR_SIZE;
7720 /* Select the encoding of an attribute value. */
7722 static enum dwarf_form
7723 value_format (dw_attr_ref a)
7725 switch (a->dw_attr_val.val_class)
7727 case dw_val_class_addr:
7728 return DW_FORM_addr;
7729 case dw_val_class_range_list:
7730 case dw_val_class_offset:
7731 case dw_val_class_loc_list:
7732 switch (DWARF_OFFSET_SIZE)
7735 return DW_FORM_data4;
7737 return DW_FORM_data8;
7741 case dw_val_class_loc:
7742 switch (constant_size (size_of_locs (AT_loc (a))))
7745 return DW_FORM_block1;
7747 return DW_FORM_block2;
7751 case dw_val_class_const:
7752 return DW_FORM_sdata;
7753 case dw_val_class_unsigned_const:
7754 switch (constant_size (AT_unsigned (a)))
7757 return DW_FORM_data1;
7759 return DW_FORM_data2;
7761 return DW_FORM_data4;
7763 return DW_FORM_data8;
7767 case dw_val_class_long_long:
7768 return DW_FORM_block1;
7769 case dw_val_class_vec:
7770 return DW_FORM_block1;
7771 case dw_val_class_flag:
7772 return DW_FORM_flag;
7773 case dw_val_class_die_ref:
7774 if (AT_ref_external (a))
7775 return DW_FORM_ref_addr;
7778 case dw_val_class_fde_ref:
7779 return DW_FORM_data;
7780 case dw_val_class_lbl_id:
7781 return DW_FORM_addr;
7782 case dw_val_class_lineptr:
7783 case dw_val_class_macptr:
7784 return DW_FORM_data;
7785 case dw_val_class_str:
7786 return AT_string_form (a);
7787 case dw_val_class_file:
7788 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7791 return DW_FORM_data1;
7793 return DW_FORM_data2;
7795 return DW_FORM_data4;
7805 /* Output the encoding of an attribute value. */
7808 output_value_format (dw_attr_ref a)
7810 enum dwarf_form form = value_format (a);
7812 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7815 /* Output the .debug_abbrev section which defines the DIE abbreviation
7819 output_abbrev_section (void)
7821 unsigned long abbrev_id;
7823 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7825 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7829 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7830 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7831 dwarf_tag_name (abbrev->die_tag));
7833 if (abbrev->die_child != NULL)
7834 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7836 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7838 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7841 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7842 dwarf_attr_name (a_attr->dw_attr));
7843 output_value_format (a_attr);
7846 dw2_asm_output_data (1, 0, NULL);
7847 dw2_asm_output_data (1, 0, NULL);
7850 /* Terminate the table. */
7851 dw2_asm_output_data (1, 0, NULL);
7854 /* Output a symbol we can use to refer to this DIE from another CU. */
7857 output_die_symbol (dw_die_ref die)
7859 char *sym = die->die_symbol;
7864 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7865 /* We make these global, not weak; if the target doesn't support
7866 .linkonce, it doesn't support combining the sections, so debugging
7868 targetm.asm_out.globalize_label (asm_out_file, sym);
7870 ASM_OUTPUT_LABEL (asm_out_file, sym);
7873 /* Return a new location list, given the begin and end range, and the
7874 expression. gensym tells us whether to generate a new internal symbol for
7875 this location list node, which is done for the head of the list only. */
7877 static inline dw_loc_list_ref
7878 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7879 const char *section, unsigned int gensym)
7881 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7883 retlist->begin = begin;
7885 retlist->expr = expr;
7886 retlist->section = section;
7888 retlist->ll_symbol = gen_internal_sym ("LLST");
7893 /* Add a location description expression to a location list. */
7896 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7897 const char *begin, const char *end,
7898 const char *section)
7902 /* Find the end of the chain. */
7903 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7906 /* Add a new location list node to the list. */
7907 *d = new_loc_list (descr, begin, end, section, 0);
7910 /* Output the location list given to us. */
7913 output_loc_list (dw_loc_list_ref list_head)
7915 dw_loc_list_ref curr = list_head;
7917 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7919 /* Walk the location list, and output each range + expression. */
7920 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7923 /* Don't output an entry that starts and ends at the same address. */
7924 if (strcmp (curr->begin, curr->end) == 0)
7926 if (!have_multiple_function_sections)
7928 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7929 "Location list begin address (%s)",
7930 list_head->ll_symbol);
7931 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7932 "Location list end address (%s)",
7933 list_head->ll_symbol);
7937 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7938 "Location list begin address (%s)",
7939 list_head->ll_symbol);
7940 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7941 "Location list end address (%s)",
7942 list_head->ll_symbol);
7944 size = size_of_locs (curr->expr);
7946 /* Output the block length for this list of location operations. */
7947 gcc_assert (size <= 0xffff);
7948 dw2_asm_output_data (2, size, "%s", "Location expression size");
7950 output_loc_sequence (curr->expr);
7953 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7954 "Location list terminator begin (%s)",
7955 list_head->ll_symbol);
7956 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7957 "Location list terminator end (%s)",
7958 list_head->ll_symbol);
7961 /* Output the DIE and its attributes. Called recursively to generate
7962 the definitions of each child DIE. */
7965 output_die (dw_die_ref die)
7972 /* If someone in another CU might refer to us, set up a symbol for
7973 them to point to. */
7974 if (die->die_symbol)
7975 output_die_symbol (die);
7977 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7978 (unsigned long)die->die_offset,
7979 dwarf_tag_name (die->die_tag));
7981 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7983 const char *name = dwarf_attr_name (a->dw_attr);
7985 switch (AT_class (a))
7987 case dw_val_class_addr:
7988 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7991 case dw_val_class_offset:
7992 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7996 case dw_val_class_range_list:
7998 char *p = strchr (ranges_section_label, '\0');
8000 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8001 a->dw_attr_val.v.val_offset);
8002 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8003 debug_ranges_section, "%s", name);
8008 case dw_val_class_loc:
8009 size = size_of_locs (AT_loc (a));
8011 /* Output the block length for this list of location operations. */
8012 dw2_asm_output_data (constant_size (size), size, "%s", name);
8014 output_loc_sequence (AT_loc (a));
8017 case dw_val_class_const:
8018 /* ??? It would be slightly more efficient to use a scheme like is
8019 used for unsigned constants below, but gdb 4.x does not sign
8020 extend. Gdb 5.x does sign extend. */
8021 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8024 case dw_val_class_unsigned_const:
8025 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8026 AT_unsigned (a), "%s", name);
8029 case dw_val_class_long_long:
8031 unsigned HOST_WIDE_INT first, second;
8033 dw2_asm_output_data (1,
8034 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8037 if (WORDS_BIG_ENDIAN)
8039 first = a->dw_attr_val.v.val_long_long.hi;
8040 second = a->dw_attr_val.v.val_long_long.low;
8044 first = a->dw_attr_val.v.val_long_long.low;
8045 second = a->dw_attr_val.v.val_long_long.hi;
8048 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8049 first, "long long constant");
8050 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8055 case dw_val_class_vec:
8057 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8058 unsigned int len = a->dw_attr_val.v.val_vec.length;
8062 dw2_asm_output_data (1, len * elt_size, "%s", name);
8063 if (elt_size > sizeof (HOST_WIDE_INT))
8068 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8071 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8072 "fp or vector constant word %u", i);
8076 case dw_val_class_flag:
8077 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8080 case dw_val_class_loc_list:
8082 char *sym = AT_loc_list (a)->ll_symbol;
8085 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8090 case dw_val_class_die_ref:
8091 if (AT_ref_external (a))
8093 char *sym = AT_ref (a)->die_symbol;
8096 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8101 gcc_assert (AT_ref (a)->die_offset);
8102 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8107 case dw_val_class_fde_ref:
8111 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8112 a->dw_attr_val.v.val_fde_index * 2);
8113 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8118 case dw_val_class_lbl_id:
8119 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8122 case dw_val_class_lineptr:
8123 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8124 debug_line_section, "%s", name);
8127 case dw_val_class_macptr:
8128 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8129 debug_macinfo_section, "%s", name);
8132 case dw_val_class_str:
8133 if (AT_string_form (a) == DW_FORM_strp)
8134 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8135 a->dw_attr_val.v.val_str->label,
8137 "%s: \"%s\"", name, AT_string (a));
8139 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8142 case dw_val_class_file:
8144 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8146 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8147 a->dw_attr_val.v.val_file->filename);
8156 FOR_EACH_CHILD (die, c, output_die (c));
8158 /* Add null byte to terminate sibling list. */
8159 if (die->die_child != NULL)
8160 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8161 (unsigned long) die->die_offset);
8164 /* Output the compilation unit that appears at the beginning of the
8165 .debug_info section, and precedes the DIE descriptions. */
8168 output_compilation_unit_header (void)
8170 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8171 dw2_asm_output_data (4, 0xffffffff,
8172 "Initial length escape value indicating 64-bit DWARF extension");
8173 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8174 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8175 "Length of Compilation Unit Info");
8176 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8177 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8178 debug_abbrev_section,
8179 "Offset Into Abbrev. Section");
8180 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8183 /* Output the compilation unit DIE and its children. */
8186 output_comp_unit (dw_die_ref die, int output_if_empty)
8188 const char *secname;
8191 /* Unless we are outputting main CU, we may throw away empty ones. */
8192 if (!output_if_empty && die->die_child == NULL)
8195 /* Even if there are no children of this DIE, we must output the information
8196 about the compilation unit. Otherwise, on an empty translation unit, we
8197 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8198 will then complain when examining the file. First mark all the DIEs in
8199 this CU so we know which get local refs. */
8202 build_abbrev_table (die);
8204 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8205 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8206 calc_die_sizes (die);
8208 oldsym = die->die_symbol;
8211 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8213 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8215 die->die_symbol = NULL;
8216 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8219 switch_to_section (debug_info_section);
8221 /* Output debugging information. */
8222 output_compilation_unit_header ();
8225 /* Leave the marks on the main CU, so we can check them in
8230 die->die_symbol = oldsym;
8234 /* Return the DWARF2/3 pubname associated with a decl. */
8237 dwarf2_name (tree decl, int scope)
8239 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8242 /* Add a new entry to .debug_pubnames if appropriate. */
8245 add_pubname_string (const char *str, dw_die_ref die)
8250 e.name = xstrdup (str);
8251 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8255 add_pubname (tree decl, dw_die_ref die)
8258 if (TREE_PUBLIC (decl))
8259 add_pubname_string (dwarf2_name (decl, 1), die);
8262 /* Add a new entry to .debug_pubtypes if appropriate. */
8265 add_pubtype (tree decl, dw_die_ref die)
8270 if ((TREE_PUBLIC (decl)
8271 || die->die_parent == comp_unit_die)
8272 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8277 if (TYPE_NAME (decl))
8279 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8280 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8281 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8282 && DECL_NAME (TYPE_NAME (decl)))
8283 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8285 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8289 e.name = xstrdup (dwarf2_name (decl, 1));
8291 /* If we don't have a name for the type, there's no point in adding
8293 if (e.name && e.name[0] != '\0')
8294 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8298 /* Output the public names table used to speed up access to externally
8299 visible names; or the public types table used to find type definitions. */
8302 output_pubnames (VEC (pubname_entry, gc) * names)
8305 unsigned long pubnames_length = size_of_pubnames (names);
8308 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8309 dw2_asm_output_data (4, 0xffffffff,
8310 "Initial length escape value indicating 64-bit DWARF extension");
8311 if (names == pubname_table)
8312 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8313 "Length of Public Names Info");
8315 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8316 "Length of Public Type Names Info");
8317 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8318 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8320 "Offset of Compilation Unit Info");
8321 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8322 "Compilation Unit Length");
8324 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8326 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8327 if (names == pubname_table)
8328 gcc_assert (pub->die->die_mark);
8330 if (names != pubtype_table
8331 || pub->die->die_offset != 0
8332 || !flag_eliminate_unused_debug_types)
8334 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8337 dw2_asm_output_nstring (pub->name, -1, "external name");
8341 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8344 /* Add a new entry to .debug_aranges if appropriate. */
8347 add_arange (tree decl, dw_die_ref die)
8349 if (! DECL_SECTION_NAME (decl))
8352 if (arange_table_in_use == arange_table_allocated)
8354 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8355 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8356 arange_table_allocated);
8357 memset (arange_table + arange_table_in_use, 0,
8358 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8361 arange_table[arange_table_in_use++] = die;
8364 /* Output the information that goes into the .debug_aranges table.
8365 Namely, define the beginning and ending address range of the
8366 text section generated for this compilation unit. */
8369 output_aranges (void)
8372 unsigned long aranges_length = size_of_aranges ();
8374 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8375 dw2_asm_output_data (4, 0xffffffff,
8376 "Initial length escape value indicating 64-bit DWARF extension");
8377 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8378 "Length of Address Ranges Info");
8379 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8380 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8382 "Offset of Compilation Unit Info");
8383 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8384 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8386 /* We need to align to twice the pointer size here. */
8387 if (DWARF_ARANGES_PAD_SIZE)
8389 /* Pad using a 2 byte words so that padding is correct for any
8391 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8392 2 * DWARF2_ADDR_SIZE);
8393 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8394 dw2_asm_output_data (2, 0, NULL);
8397 /* It is necessary not to output these entries if the sections were
8398 not used; if the sections were not used, the length will be 0 and
8399 the address may end up as 0 if the section is discarded by ld
8400 --gc-sections, leaving an invalid (0, 0) entry that can be
8401 confused with the terminator. */
8402 if (text_section_used)
8404 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8405 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8406 text_section_label, "Length");
8408 if (cold_text_section_used)
8410 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8412 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8413 cold_text_section_label, "Length");
8416 for (i = 0; i < arange_table_in_use; i++)
8418 dw_die_ref die = arange_table[i];
8420 /* We shouldn't see aranges for DIEs outside of the main CU. */
8421 gcc_assert (die->die_mark);
8423 if (die->die_tag == DW_TAG_subprogram)
8425 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8427 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8428 get_AT_low_pc (die), "Length");
8432 /* A static variable; extract the symbol from DW_AT_location.
8433 Note that this code isn't currently hit, as we only emit
8434 aranges for functions (jason 9/23/99). */
8435 dw_attr_ref a = get_AT (die, DW_AT_location);
8436 dw_loc_descr_ref loc;
8438 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8441 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8443 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8444 loc->dw_loc_oprnd1.v.val_addr, "Address");
8445 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8446 get_AT_unsigned (die, DW_AT_byte_size),
8451 /* Output the terminator words. */
8452 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8453 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8456 /* Add a new entry to .debug_ranges. Return the offset at which it
8460 add_ranges_num (int num)
8462 unsigned int in_use = ranges_table_in_use;
8464 if (in_use == ranges_table_allocated)
8466 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8467 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8468 ranges_table_allocated);
8469 memset (ranges_table + ranges_table_in_use, 0,
8470 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8473 ranges_table[in_use].num = num;
8474 ranges_table_in_use = in_use + 1;
8476 return in_use * 2 * DWARF2_ADDR_SIZE;
8479 /* Add a new entry to .debug_ranges corresponding to a block, or a
8480 range terminator if BLOCK is NULL. */
8483 add_ranges (const_tree block)
8485 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8488 /* Add a new entry to .debug_ranges corresponding to a pair of
8492 add_ranges_by_labels (const char *begin, const char *end)
8494 unsigned int in_use = ranges_by_label_in_use;
8496 if (in_use == ranges_by_label_allocated)
8498 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8499 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8501 ranges_by_label_allocated);
8502 memset (ranges_by_label + ranges_by_label_in_use, 0,
8503 RANGES_TABLE_INCREMENT
8504 * sizeof (struct dw_ranges_by_label_struct));
8507 ranges_by_label[in_use].begin = begin;
8508 ranges_by_label[in_use].end = end;
8509 ranges_by_label_in_use = in_use + 1;
8511 return add_ranges_num (-(int)in_use - 1);
8515 output_ranges (void)
8518 static const char *const start_fmt = "Offset 0x%x";
8519 const char *fmt = start_fmt;
8521 for (i = 0; i < ranges_table_in_use; i++)
8523 int block_num = ranges_table[i].num;
8527 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8528 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8530 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8531 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8533 /* If all code is in the text section, then the compilation
8534 unit base address defaults to DW_AT_low_pc, which is the
8535 base of the text section. */
8536 if (!have_multiple_function_sections)
8538 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8540 fmt, i * 2 * DWARF2_ADDR_SIZE);
8541 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8542 text_section_label, NULL);
8545 /* Otherwise, the compilation unit base address is zero,
8546 which allows us to use absolute addresses, and not worry
8547 about whether the target supports cross-section
8551 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8552 fmt, i * 2 * DWARF2_ADDR_SIZE);
8553 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8559 /* Negative block_num stands for an index into ranges_by_label. */
8560 else if (block_num < 0)
8562 int lab_idx = - block_num - 1;
8564 if (!have_multiple_function_sections)
8568 /* If we ever use add_ranges_by_labels () for a single
8569 function section, all we have to do is to take out
8571 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8572 ranges_by_label[lab_idx].begin,
8574 fmt, i * 2 * DWARF2_ADDR_SIZE);
8575 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8576 ranges_by_label[lab_idx].end,
8577 text_section_label, NULL);
8582 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8583 ranges_by_label[lab_idx].begin,
8584 fmt, i * 2 * DWARF2_ADDR_SIZE);
8585 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8586 ranges_by_label[lab_idx].end,
8592 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8593 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8599 /* Data structure containing information about input files. */
8602 const char *path; /* Complete file name. */
8603 const char *fname; /* File name part. */
8604 int length; /* Length of entire string. */
8605 struct dwarf_file_data * file_idx; /* Index in input file table. */
8606 int dir_idx; /* Index in directory table. */
8609 /* Data structure containing information about directories with source
8613 const char *path; /* Path including directory name. */
8614 int length; /* Path length. */
8615 int prefix; /* Index of directory entry which is a prefix. */
8616 int count; /* Number of files in this directory. */
8617 int dir_idx; /* Index of directory used as base. */
8620 /* Callback function for file_info comparison. We sort by looking at
8621 the directories in the path. */
8624 file_info_cmp (const void *p1, const void *p2)
8626 const struct file_info *const s1 = (const struct file_info *) p1;
8627 const struct file_info *const s2 = (const struct file_info *) p2;
8628 const unsigned char *cp1;
8629 const unsigned char *cp2;
8631 /* Take care of file names without directories. We need to make sure that
8632 we return consistent values to qsort since some will get confused if
8633 we return the same value when identical operands are passed in opposite
8634 orders. So if neither has a directory, return 0 and otherwise return
8635 1 or -1 depending on which one has the directory. */
8636 if ((s1->path == s1->fname || s2->path == s2->fname))
8637 return (s2->path == s2->fname) - (s1->path == s1->fname);
8639 cp1 = (const unsigned char *) s1->path;
8640 cp2 = (const unsigned char *) s2->path;
8646 /* Reached the end of the first path? If so, handle like above. */
8647 if ((cp1 == (const unsigned char *) s1->fname)
8648 || (cp2 == (const unsigned char *) s2->fname))
8649 return ((cp2 == (const unsigned char *) s2->fname)
8650 - (cp1 == (const unsigned char *) s1->fname));
8652 /* Character of current path component the same? */
8653 else if (*cp1 != *cp2)
8658 struct file_name_acquire_data
8660 struct file_info *files;
8665 /* Traversal function for the hash table. */
8668 file_name_acquire (void ** slot, void *data)
8670 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8671 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8672 struct file_info *fi;
8675 gcc_assert (fnad->max_files >= d->emitted_number);
8677 if (! d->emitted_number)
8680 gcc_assert (fnad->max_files != fnad->used_files);
8682 fi = fnad->files + fnad->used_files++;
8684 /* Skip all leading "./". */
8686 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8689 /* Create a new array entry. */
8691 fi->length = strlen (f);
8694 /* Search for the file name part. */
8695 f = strrchr (f, DIR_SEPARATOR);
8696 #if defined (DIR_SEPARATOR_2)
8698 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8702 if (f == NULL || f < g)
8708 fi->fname = f == NULL ? fi->path : f + 1;
8712 /* Output the directory table and the file name table. We try to minimize
8713 the total amount of memory needed. A heuristic is used to avoid large
8714 slowdowns with many input files. */
8717 output_file_names (void)
8719 struct file_name_acquire_data fnad;
8721 struct file_info *files;
8722 struct dir_info *dirs;
8731 if (!last_emitted_file)
8733 dw2_asm_output_data (1, 0, "End directory table");
8734 dw2_asm_output_data (1, 0, "End file name table");
8738 numfiles = last_emitted_file->emitted_number;
8740 /* Allocate the various arrays we need. */
8741 files = XALLOCAVEC (struct file_info, numfiles);
8742 dirs = XALLOCAVEC (struct dir_info, numfiles);
8745 fnad.used_files = 0;
8746 fnad.max_files = numfiles;
8747 htab_traverse (file_table, file_name_acquire, &fnad);
8748 gcc_assert (fnad.used_files == fnad.max_files);
8750 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8752 /* Find all the different directories used. */
8753 dirs[0].path = files[0].path;
8754 dirs[0].length = files[0].fname - files[0].path;
8755 dirs[0].prefix = -1;
8757 dirs[0].dir_idx = 0;
8758 files[0].dir_idx = 0;
8761 for (i = 1; i < numfiles; i++)
8762 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8763 && memcmp (dirs[ndirs - 1].path, files[i].path,
8764 dirs[ndirs - 1].length) == 0)
8766 /* Same directory as last entry. */
8767 files[i].dir_idx = ndirs - 1;
8768 ++dirs[ndirs - 1].count;
8774 /* This is a new directory. */
8775 dirs[ndirs].path = files[i].path;
8776 dirs[ndirs].length = files[i].fname - files[i].path;
8777 dirs[ndirs].count = 1;
8778 dirs[ndirs].dir_idx = ndirs;
8779 files[i].dir_idx = ndirs;
8781 /* Search for a prefix. */
8782 dirs[ndirs].prefix = -1;
8783 for (j = 0; j < ndirs; j++)
8784 if (dirs[j].length < dirs[ndirs].length
8785 && dirs[j].length > 1
8786 && (dirs[ndirs].prefix == -1
8787 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8788 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8789 dirs[ndirs].prefix = j;
8794 /* Now to the actual work. We have to find a subset of the directories which
8795 allow expressing the file name using references to the directory table
8796 with the least amount of characters. We do not do an exhaustive search
8797 where we would have to check out every combination of every single
8798 possible prefix. Instead we use a heuristic which provides nearly optimal
8799 results in most cases and never is much off. */
8800 saved = XALLOCAVEC (int, ndirs);
8801 savehere = XALLOCAVEC (int, ndirs);
8803 memset (saved, '\0', ndirs * sizeof (saved[0]));
8804 for (i = 0; i < ndirs; i++)
8809 /* We can always save some space for the current directory. But this
8810 does not mean it will be enough to justify adding the directory. */
8811 savehere[i] = dirs[i].length;
8812 total = (savehere[i] - saved[i]) * dirs[i].count;
8814 for (j = i + 1; j < ndirs; j++)
8817 if (saved[j] < dirs[i].length)
8819 /* Determine whether the dirs[i] path is a prefix of the
8824 while (k != -1 && k != (int) i)
8829 /* Yes it is. We can possibly save some memory by
8830 writing the filenames in dirs[j] relative to
8832 savehere[j] = dirs[i].length;
8833 total += (savehere[j] - saved[j]) * dirs[j].count;
8838 /* Check whether we can save enough to justify adding the dirs[i]
8840 if (total > dirs[i].length + 1)
8842 /* It's worthwhile adding. */
8843 for (j = i; j < ndirs; j++)
8844 if (savehere[j] > 0)
8846 /* Remember how much we saved for this directory so far. */
8847 saved[j] = savehere[j];
8849 /* Remember the prefix directory. */
8850 dirs[j].dir_idx = i;
8855 /* Emit the directory name table. */
8857 idx_offset = dirs[0].length > 0 ? 1 : 0;
8858 for (i = 1 - idx_offset; i < ndirs; i++)
8859 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8860 "Directory Entry: 0x%x", i + idx_offset);
8862 dw2_asm_output_data (1, 0, "End directory table");
8864 /* We have to emit them in the order of emitted_number since that's
8865 used in the debug info generation. To do this efficiently we
8866 generate a back-mapping of the indices first. */
8867 backmap = XALLOCAVEC (int, numfiles);
8868 for (i = 0; i < numfiles; i++)
8869 backmap[files[i].file_idx->emitted_number - 1] = i;
8871 /* Now write all the file names. */
8872 for (i = 0; i < numfiles; i++)
8874 int file_idx = backmap[i];
8875 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8877 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8878 "File Entry: 0x%x", (unsigned) i + 1);
8880 /* Include directory index. */
8881 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8883 /* Modification time. */
8884 dw2_asm_output_data_uleb128 (0, NULL);
8886 /* File length in bytes. */
8887 dw2_asm_output_data_uleb128 (0, NULL);
8890 dw2_asm_output_data (1, 0, "End file name table");
8894 /* Output the source line number correspondence information. This
8895 information goes into the .debug_line section. */
8898 output_line_info (void)
8900 char l1[20], l2[20], p1[20], p2[20];
8901 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8902 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8905 unsigned long lt_index;
8906 unsigned long current_line;
8909 unsigned long current_file;
8910 unsigned long function;
8912 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8913 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8914 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8915 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8917 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8918 dw2_asm_output_data (4, 0xffffffff,
8919 "Initial length escape value indicating 64-bit DWARF extension");
8920 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8921 "Length of Source Line Info");
8922 ASM_OUTPUT_LABEL (asm_out_file, l1);
8924 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8925 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8926 ASM_OUTPUT_LABEL (asm_out_file, p1);
8928 /* Define the architecture-dependent minimum instruction length (in
8929 bytes). In this implementation of DWARF, this field is used for
8930 information purposes only. Since GCC generates assembly language,
8931 we have no a priori knowledge of how many instruction bytes are
8932 generated for each source line, and therefore can use only the
8933 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8934 commands. Accordingly, we fix this as `1', which is "correct
8935 enough" for all architectures, and don't let the target override. */
8936 dw2_asm_output_data (1, 1,
8937 "Minimum Instruction Length");
8939 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8940 "Default is_stmt_start flag");
8941 dw2_asm_output_data (1, DWARF_LINE_BASE,
8942 "Line Base Value (Special Opcodes)");
8943 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8944 "Line Range Value (Special Opcodes)");
8945 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8946 "Special Opcode Base");
8948 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8952 case DW_LNS_advance_pc:
8953 case DW_LNS_advance_line:
8954 case DW_LNS_set_file:
8955 case DW_LNS_set_column:
8956 case DW_LNS_fixed_advance_pc:
8964 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8968 /* Write out the information about the files we use. */
8969 output_file_names ();
8970 ASM_OUTPUT_LABEL (asm_out_file, p2);
8972 /* We used to set the address register to the first location in the text
8973 section here, but that didn't accomplish anything since we already
8974 have a line note for the opening brace of the first function. */
8976 /* Generate the line number to PC correspondence table, encoded as
8977 a series of state machine operations. */
8981 if (cfun && in_cold_section_p)
8982 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8984 strcpy (prev_line_label, text_section_label);
8985 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8987 dw_line_info_ref line_info = &line_info_table[lt_index];
8990 /* Disable this optimization for now; GDB wants to see two line notes
8991 at the beginning of a function so it can find the end of the
8994 /* Don't emit anything for redundant notes. Just updating the
8995 address doesn't accomplish anything, because we already assume
8996 that anything after the last address is this line. */
8997 if (line_info->dw_line_num == current_line
8998 && line_info->dw_file_num == current_file)
9002 /* Emit debug info for the address of the current line.
9004 Unfortunately, we have little choice here currently, and must always
9005 use the most general form. GCC does not know the address delta
9006 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9007 attributes which will give an upper bound on the address range. We
9008 could perhaps use length attributes to determine when it is safe to
9009 use DW_LNS_fixed_advance_pc. */
9011 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9014 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9015 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9016 "DW_LNS_fixed_advance_pc");
9017 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9021 /* This can handle any delta. This takes
9022 4+DWARF2_ADDR_SIZE bytes. */
9023 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9024 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9025 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9026 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9029 strcpy (prev_line_label, line_label);
9031 /* Emit debug info for the source file of the current line, if
9032 different from the previous line. */
9033 if (line_info->dw_file_num != current_file)
9035 current_file = line_info->dw_file_num;
9036 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9037 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9040 /* Emit debug info for the current line number, choosing the encoding
9041 that uses the least amount of space. */
9042 if (line_info->dw_line_num != current_line)
9044 line_offset = line_info->dw_line_num - current_line;
9045 line_delta = line_offset - DWARF_LINE_BASE;
9046 current_line = line_info->dw_line_num;
9047 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9048 /* This can handle deltas from -10 to 234, using the current
9049 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9051 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9052 "line %lu", current_line);
9055 /* This can handle any delta. This takes at least 4 bytes,
9056 depending on the value being encoded. */
9057 dw2_asm_output_data (1, DW_LNS_advance_line,
9058 "advance to line %lu", current_line);
9059 dw2_asm_output_data_sleb128 (line_offset, NULL);
9060 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9064 /* We still need to start a new row, so output a copy insn. */
9065 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9068 /* Emit debug info for the address of the end of the function. */
9071 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9072 "DW_LNS_fixed_advance_pc");
9073 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9077 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9078 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9079 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9080 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9083 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9084 dw2_asm_output_data_uleb128 (1, NULL);
9085 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9090 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9092 dw_separate_line_info_ref line_info
9093 = &separate_line_info_table[lt_index];
9096 /* Don't emit anything for redundant notes. */
9097 if (line_info->dw_line_num == current_line
9098 && line_info->dw_file_num == current_file
9099 && line_info->function == function)
9103 /* Emit debug info for the address of the current line. If this is
9104 a new function, or the first line of a function, then we need
9105 to handle it differently. */
9106 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9108 if (function != line_info->function)
9110 function = line_info->function;
9112 /* Set the address register to the first line in the function. */
9113 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9114 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9115 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9116 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9120 /* ??? See the DW_LNS_advance_pc comment above. */
9123 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9124 "DW_LNS_fixed_advance_pc");
9125 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9129 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9130 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9131 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9132 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9136 strcpy (prev_line_label, line_label);
9138 /* Emit debug info for the source file of the current line, if
9139 different from the previous line. */
9140 if (line_info->dw_file_num != current_file)
9142 current_file = line_info->dw_file_num;
9143 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9144 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9147 /* Emit debug info for the current line number, choosing the encoding
9148 that uses the least amount of space. */
9149 if (line_info->dw_line_num != current_line)
9151 line_offset = line_info->dw_line_num - current_line;
9152 line_delta = line_offset - DWARF_LINE_BASE;
9153 current_line = line_info->dw_line_num;
9154 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9155 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9156 "line %lu", current_line);
9159 dw2_asm_output_data (1, DW_LNS_advance_line,
9160 "advance to line %lu", current_line);
9161 dw2_asm_output_data_sleb128 (line_offset, NULL);
9162 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9166 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9174 /* If we're done with a function, end its sequence. */
9175 if (lt_index == separate_line_info_table_in_use
9176 || separate_line_info_table[lt_index].function != function)
9181 /* Emit debug info for the address of the end of the function. */
9182 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9185 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9186 "DW_LNS_fixed_advance_pc");
9187 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9191 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9192 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9193 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9194 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9197 /* Output the marker for the end of this sequence. */
9198 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9199 dw2_asm_output_data_uleb128 (1, NULL);
9200 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9204 /* Output the marker for the end of the line number info. */
9205 ASM_OUTPUT_LABEL (asm_out_file, l2);
9208 /* Given a pointer to a tree node for some base type, return a pointer to
9209 a DIE that describes the given type.
9211 This routine must only be called for GCC type nodes that correspond to
9212 Dwarf base (fundamental) types. */
9215 base_type_die (tree type)
9217 dw_die_ref base_type_result;
9218 enum dwarf_type encoding;
9220 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9223 switch (TREE_CODE (type))
9226 if (TYPE_STRING_FLAG (type))
9228 if (TYPE_UNSIGNED (type))
9229 encoding = DW_ATE_unsigned_char;
9231 encoding = DW_ATE_signed_char;
9233 else if (TYPE_UNSIGNED (type))
9234 encoding = DW_ATE_unsigned;
9236 encoding = DW_ATE_signed;
9240 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9241 encoding = DW_ATE_decimal_float;
9243 encoding = DW_ATE_float;
9246 case FIXED_POINT_TYPE:
9247 if (TYPE_UNSIGNED (type))
9248 encoding = DW_ATE_unsigned_fixed;
9250 encoding = DW_ATE_signed_fixed;
9253 /* Dwarf2 doesn't know anything about complex ints, so use
9254 a user defined type for it. */
9256 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9257 encoding = DW_ATE_complex_float;
9259 encoding = DW_ATE_lo_user;
9263 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9264 encoding = DW_ATE_boolean;
9268 /* No other TREE_CODEs are Dwarf fundamental types. */
9272 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9274 /* This probably indicates a bug. */
9275 if (! TYPE_NAME (type))
9276 add_name_attribute (base_type_result, "__unknown__");
9278 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9279 int_size_in_bytes (type));
9280 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9282 return base_type_result;
9285 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9286 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9289 is_base_type (tree type)
9291 switch (TREE_CODE (type))
9297 case FIXED_POINT_TYPE:
9305 case QUAL_UNION_TYPE:
9310 case REFERENCE_TYPE:
9323 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9324 node, return the size in bits for the type if it is a constant, or else
9325 return the alignment for the type if the type's size is not constant, or
9326 else return BITS_PER_WORD if the type actually turns out to be an
9329 static inline unsigned HOST_WIDE_INT
9330 simple_type_size_in_bits (const_tree type)
9332 if (TREE_CODE (type) == ERROR_MARK)
9333 return BITS_PER_WORD;
9334 else if (TYPE_SIZE (type) == NULL_TREE)
9336 else if (host_integerp (TYPE_SIZE (type), 1))
9337 return tree_low_cst (TYPE_SIZE (type), 1);
9339 return TYPE_ALIGN (type);
9342 /* Return true if the debug information for the given type should be
9343 emitted as a subrange type. */
9346 is_subrange_type (const_tree type)
9348 tree subtype = TREE_TYPE (type);
9350 /* Subrange types are identified by the fact that they are integer
9351 types, and that they have a subtype which is either an integer type
9352 or an enumeral type. */
9354 if (TREE_CODE (type) != INTEGER_TYPE
9355 || subtype == NULL_TREE)
9358 if (TREE_CODE (subtype) != INTEGER_TYPE
9359 && TREE_CODE (subtype) != ENUMERAL_TYPE
9360 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9363 if (TREE_CODE (type) == TREE_CODE (subtype)
9364 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9365 && TYPE_MIN_VALUE (type) != NULL
9366 && TYPE_MIN_VALUE (subtype) != NULL
9367 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9368 && TYPE_MAX_VALUE (type) != NULL
9369 && TYPE_MAX_VALUE (subtype) != NULL
9370 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9372 /* The type and its subtype have the same representation. If in
9373 addition the two types also have the same name, then the given
9374 type is not a subrange type, but rather a plain base type. */
9375 /* FIXME: brobecker/2004-03-22:
9376 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9377 therefore be sufficient to check the TYPE_SIZE node pointers
9378 rather than checking the actual size. Unfortunately, we have
9379 found some cases, such as in the Ada "integer" type, where
9380 this is not the case. Until this problem is solved, we need to
9381 keep checking the actual size. */
9382 tree type_name = TYPE_NAME (type);
9383 tree subtype_name = TYPE_NAME (subtype);
9385 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9386 type_name = DECL_NAME (type_name);
9388 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9389 subtype_name = DECL_NAME (subtype_name);
9391 if (type_name == subtype_name)
9398 /* Given a pointer to a tree node for a subrange type, return a pointer
9399 to a DIE that describes the given type. */
9402 subrange_type_die (tree type, dw_die_ref context_die)
9404 dw_die_ref subrange_die;
9405 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9407 if (context_die == NULL)
9408 context_die = comp_unit_die;
9410 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9412 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9414 /* The size of the subrange type and its base type do not match,
9415 so we need to generate a size attribute for the subrange type. */
9416 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9419 if (TYPE_MIN_VALUE (type) != NULL)
9420 add_bound_info (subrange_die, DW_AT_lower_bound,
9421 TYPE_MIN_VALUE (type));
9422 if (TYPE_MAX_VALUE (type) != NULL)
9423 add_bound_info (subrange_die, DW_AT_upper_bound,
9424 TYPE_MAX_VALUE (type));
9426 return subrange_die;
9429 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9430 entry that chains various modifiers in front of the given type. */
9433 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9434 dw_die_ref context_die)
9436 enum tree_code code = TREE_CODE (type);
9437 dw_die_ref mod_type_die;
9438 dw_die_ref sub_die = NULL;
9439 tree item_type = NULL;
9440 tree qualified_type;
9443 if (code == ERROR_MARK)
9446 /* See if we already have the appropriately qualified variant of
9449 = get_qualified_type (type,
9450 ((is_const_type ? TYPE_QUAL_CONST : 0)
9451 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9453 /* If we do, then we can just use its DIE, if it exists. */
9456 mod_type_die = lookup_type_die (qualified_type);
9458 return mod_type_die;
9461 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9463 /* Handle C typedef types. */
9464 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9466 tree dtype = TREE_TYPE (name);
9468 if (qualified_type == dtype)
9470 /* For a named type, use the typedef. */
9471 gen_type_die (qualified_type, context_die);
9472 return lookup_type_die (qualified_type);
9474 else if (is_const_type < TYPE_READONLY (dtype)
9475 || is_volatile_type < TYPE_VOLATILE (dtype)
9476 || (is_const_type <= TYPE_READONLY (dtype)
9477 && is_volatile_type <= TYPE_VOLATILE (dtype)
9478 && DECL_ORIGINAL_TYPE (name) != type))
9479 /* cv-unqualified version of named type. Just use the unnamed
9480 type to which it refers. */
9481 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9482 is_const_type, is_volatile_type,
9484 /* Else cv-qualified version of named type; fall through. */
9489 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9490 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9492 else if (is_volatile_type)
9494 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9495 sub_die = modified_type_die (type, 0, 0, context_die);
9497 else if (code == POINTER_TYPE)
9499 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9500 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9501 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9502 item_type = TREE_TYPE (type);
9504 else if (code == REFERENCE_TYPE)
9506 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9507 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9508 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9509 item_type = TREE_TYPE (type);
9511 else if (is_subrange_type (type))
9513 mod_type_die = subrange_type_die (type, context_die);
9514 item_type = TREE_TYPE (type);
9516 else if (is_base_type (type))
9517 mod_type_die = base_type_die (type);
9520 gen_type_die (type, context_die);
9522 /* We have to get the type_main_variant here (and pass that to the
9523 `lookup_type_die' routine) because the ..._TYPE node we have
9524 might simply be a *copy* of some original type node (where the
9525 copy was created to help us keep track of typedef names) and
9526 that copy might have a different TYPE_UID from the original
9528 if (TREE_CODE (type) != VECTOR_TYPE)
9529 return lookup_type_die (type_main_variant (type));
9531 /* Vectors have the debugging information in the type,
9532 not the main variant. */
9533 return lookup_type_die (type);
9536 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9537 don't output a DW_TAG_typedef, since there isn't one in the
9538 user's program; just attach a DW_AT_name to the type. */
9540 && (TREE_CODE (name) != TYPE_DECL
9541 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9543 if (TREE_CODE (name) == TYPE_DECL)
9544 /* Could just call add_name_and_src_coords_attributes here,
9545 but since this is a builtin type it doesn't have any
9546 useful source coordinates anyway. */
9547 name = DECL_NAME (name);
9548 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9552 equate_type_number_to_die (qualified_type, mod_type_die);
9555 /* We must do this after the equate_type_number_to_die call, in case
9556 this is a recursive type. This ensures that the modified_type_die
9557 recursion will terminate even if the type is recursive. Recursive
9558 types are possible in Ada. */
9559 sub_die = modified_type_die (item_type,
9560 TYPE_READONLY (item_type),
9561 TYPE_VOLATILE (item_type),
9564 if (sub_die != NULL)
9565 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9567 return mod_type_die;
9570 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9571 an enumerated type. */
9574 type_is_enum (const_tree type)
9576 return TREE_CODE (type) == ENUMERAL_TYPE;
9579 /* Return the DBX register number described by a given RTL node. */
9582 dbx_reg_number (const_rtx rtl)
9584 unsigned regno = REGNO (rtl);
9586 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9588 #ifdef LEAF_REG_REMAP
9589 if (current_function_uses_only_leaf_regs)
9591 int leaf_reg = LEAF_REG_REMAP (regno);
9593 regno = (unsigned) leaf_reg;
9597 return DBX_REGISTER_NUMBER (regno);
9600 /* Optionally add a DW_OP_piece term to a location description expression.
9601 DW_OP_piece is only added if the location description expression already
9602 doesn't end with DW_OP_piece. */
9605 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9607 dw_loc_descr_ref loc;
9609 if (*list_head != NULL)
9611 /* Find the end of the chain. */
9612 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9615 if (loc->dw_loc_opc != DW_OP_piece)
9616 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9620 /* Return a location descriptor that designates a machine register or
9621 zero if there is none. */
9623 static dw_loc_descr_ref
9624 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9628 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9631 regs = targetm.dwarf_register_span (rtl);
9633 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9634 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9636 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9639 /* Return a location descriptor that designates a machine register for
9640 a given hard register number. */
9642 static dw_loc_descr_ref
9643 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9645 dw_loc_descr_ref reg_loc_descr;
9647 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
9649 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
9651 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9652 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9654 return reg_loc_descr;
9657 /* Given an RTL of a register, return a location descriptor that
9658 designates a value that spans more than one register. */
9660 static dw_loc_descr_ref
9661 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9662 enum var_init_status initialized)
9666 dw_loc_descr_ref loc_result = NULL;
9669 #ifdef LEAF_REG_REMAP
9670 if (current_function_uses_only_leaf_regs)
9672 int leaf_reg = LEAF_REG_REMAP (reg);
9674 reg = (unsigned) leaf_reg;
9677 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9678 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9680 /* Simple, contiguous registers. */
9681 if (regs == NULL_RTX)
9683 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9690 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9691 VAR_INIT_STATUS_INITIALIZED);
9692 add_loc_descr (&loc_result, t);
9693 add_loc_descr_op_piece (&loc_result, size);
9699 /* Now onto stupid register sets in non contiguous locations. */
9701 gcc_assert (GET_CODE (regs) == PARALLEL);
9703 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9706 for (i = 0; i < XVECLEN (regs, 0); ++i)
9710 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9711 VAR_INIT_STATUS_INITIALIZED);
9712 add_loc_descr (&loc_result, t);
9713 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9714 add_loc_descr_op_piece (&loc_result, size);
9717 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9718 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9722 #endif /* DWARF2_DEBUGGING_INFO */
9724 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9726 /* Return a location descriptor that designates a constant. */
9728 static dw_loc_descr_ref
9729 int_loc_descriptor (HOST_WIDE_INT i)
9731 enum dwarf_location_atom op;
9733 /* Pick the smallest representation of a constant, rather than just
9734 defaulting to the LEB encoding. */
9738 op = DW_OP_lit0 + i;
9741 else if (i <= 0xffff)
9743 else if (HOST_BITS_PER_WIDE_INT == 32
9753 else if (i >= -0x8000)
9755 else if (HOST_BITS_PER_WIDE_INT == 32
9756 || i >= -0x80000000)
9762 return new_loc_descr (op, i, 0);
9766 #ifdef DWARF2_DEBUGGING_INFO
9768 /* Return a location descriptor that designates a base+offset location. */
9770 static dw_loc_descr_ref
9771 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9772 enum var_init_status initialized)
9775 dw_loc_descr_ref result;
9776 dw_fde_ref fde = current_fde ();
9778 /* We only use "frame base" when we're sure we're talking about the
9779 post-prologue local stack frame. We do this by *not* running
9780 register elimination until this point, and recognizing the special
9781 argument pointer and soft frame pointer rtx's. */
9782 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9784 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9788 if (GET_CODE (elim) == PLUS)
9790 offset += INTVAL (XEXP (elim, 1));
9791 elim = XEXP (elim, 0);
9793 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9794 && (elim == hard_frame_pointer_rtx
9795 || elim == stack_pointer_rtx))
9796 || elim == (frame_pointer_needed
9797 ? hard_frame_pointer_rtx
9798 : stack_pointer_rtx));
9800 /* If drap register is used to align stack, use frame
9801 pointer + offset to access stack variables. If stack
9802 is aligned without drap, use stack pointer + offset to
9803 access stack variables. */
9804 if (crtl->stack_realign_tried
9805 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9806 && reg == frame_pointer_rtx)
9809 = DWARF_FRAME_REGNUM (cfa.indirect
9810 ? HARD_FRAME_POINTER_REGNUM
9811 : STACK_POINTER_REGNUM);
9813 return new_loc_descr (DW_OP_breg0 + base_reg, offset, 0);
9815 return new_loc_descr (DW_OP_bregx, base_reg, offset);
9818 offset += frame_pointer_fb_offset;
9819 return new_loc_descr (DW_OP_fbreg, offset, 0);
9823 && fde->drap_reg != INVALID_REGNUM
9824 && (fde->drap_reg == REGNO (reg)
9825 || fde->vdrap_reg == REGNO (reg)))
9827 /* Use cfa+offset to represent the location of arguments passed
9828 on stack when drap is used to align stack. */
9829 return new_loc_descr (DW_OP_fbreg, offset, 0);
9832 regno = dbx_reg_number (reg);
9834 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9836 result = new_loc_descr (DW_OP_bregx, regno, offset);
9838 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9839 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9844 /* Return true if this RTL expression describes a base+offset calculation. */
9847 is_based_loc (const_rtx rtl)
9849 return (GET_CODE (rtl) == PLUS
9850 && ((REG_P (XEXP (rtl, 0))
9851 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9852 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9855 /* Return a descriptor that describes the concatenation of N locations
9856 used to form the address of a memory location. */
9858 static dw_loc_descr_ref
9859 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9860 enum var_init_status initialized)
9863 dw_loc_descr_ref cc_loc_result = NULL;
9864 unsigned int n = XVECLEN (concatn, 0);
9866 for (i = 0; i < n; ++i)
9868 dw_loc_descr_ref ref;
9869 rtx x = XVECEXP (concatn, 0, i);
9871 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9875 add_loc_descr (&cc_loc_result, ref);
9876 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9879 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9880 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9882 return cc_loc_result;
9885 /* The following routine converts the RTL for a variable or parameter
9886 (resident in memory) into an equivalent Dwarf representation of a
9887 mechanism for getting the address of that same variable onto the top of a
9888 hypothetical "address evaluation" stack.
9890 When creating memory location descriptors, we are effectively transforming
9891 the RTL for a memory-resident object into its Dwarf postfix expression
9892 equivalent. This routine recursively descends an RTL tree, turning
9893 it into Dwarf postfix code as it goes.
9895 MODE is the mode of the memory reference, needed to handle some
9896 autoincrement addressing modes.
9898 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9899 location list for RTL.
9901 Return 0 if we can't represent the location. */
9903 static dw_loc_descr_ref
9904 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9905 enum var_init_status initialized)
9907 dw_loc_descr_ref mem_loc_result = NULL;
9908 enum dwarf_location_atom op;
9910 /* Note that for a dynamically sized array, the location we will generate a
9911 description of here will be the lowest numbered location which is
9912 actually within the array. That's *not* necessarily the same as the
9913 zeroth element of the array. */
9915 rtl = targetm.delegitimize_address (rtl);
9917 switch (GET_CODE (rtl))
9922 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9923 just fall into the SUBREG code. */
9925 /* ... fall through ... */
9928 /* The case of a subreg may arise when we have a local (register)
9929 variable or a formal (register) parameter which doesn't quite fill
9930 up an entire register. For now, just assume that it is
9931 legitimate to make the Dwarf info refer to the whole register which
9932 contains the given subreg. */
9933 rtl = XEXP (rtl, 0);
9935 /* ... fall through ... */
9938 /* Whenever a register number forms a part of the description of the
9939 method for calculating the (dynamic) address of a memory resident
9940 object, DWARF rules require the register number be referred to as
9941 a "base register". This distinction is not based in any way upon
9942 what category of register the hardware believes the given register
9943 belongs to. This is strictly DWARF terminology we're dealing with
9944 here. Note that in cases where the location of a memory-resident
9945 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9946 OP_CONST (0)) the actual DWARF location descriptor that we generate
9947 may just be OP_BASEREG (basereg). This may look deceptively like
9948 the object in question was allocated to a register (rather than in
9949 memory) so DWARF consumers need to be aware of the subtle
9950 distinction between OP_REG and OP_BASEREG. */
9951 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9952 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9956 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9957 VAR_INIT_STATUS_INITIALIZED);
9958 if (mem_loc_result != 0)
9959 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9963 rtl = XEXP (rtl, 1);
9965 /* ... fall through ... */
9968 /* Some ports can transform a symbol ref into a label ref, because
9969 the symbol ref is too far away and has to be dumped into a constant
9973 /* Alternatively, the symbol in the constant pool might be referenced
9974 by a different symbol. */
9975 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9978 rtx tmp = get_pool_constant_mark (rtl, &marked);
9980 if (GET_CODE (tmp) == SYMBOL_REF)
9983 if (CONSTANT_POOL_ADDRESS_P (tmp))
9984 get_pool_constant_mark (tmp, &marked);
9989 /* If all references to this pool constant were optimized away,
9990 it was not output and thus we can't represent it.
9991 FIXME: might try to use DW_OP_const_value here, though
9992 DW_OP_piece complicates it. */
9997 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9998 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9999 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10000 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10004 /* Extract the PLUS expression nested inside and fall into
10005 PLUS code below. */
10006 rtl = XEXP (rtl, 1);
10011 /* Turn these into a PLUS expression and fall into the PLUS code
10013 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10014 GEN_INT (GET_CODE (rtl) == PRE_INC
10015 ? GET_MODE_UNIT_SIZE (mode)
10016 : -GET_MODE_UNIT_SIZE (mode)));
10018 /* ... fall through ... */
10022 if (is_based_loc (rtl))
10023 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10024 INTVAL (XEXP (rtl, 1)),
10025 VAR_INIT_STATUS_INITIALIZED);
10028 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10029 VAR_INIT_STATUS_INITIALIZED);
10030 if (mem_loc_result == 0)
10033 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
10034 && INTVAL (XEXP (rtl, 1)) >= 0)
10035 add_loc_descr (&mem_loc_result,
10036 new_loc_descr (DW_OP_plus_uconst,
10037 INTVAL (XEXP (rtl, 1)), 0));
10040 add_loc_descr (&mem_loc_result,
10041 mem_loc_descriptor (XEXP (rtl, 1), mode,
10042 VAR_INIT_STATUS_INITIALIZED));
10043 add_loc_descr (&mem_loc_result,
10044 new_loc_descr (DW_OP_plus, 0, 0));
10049 /* If a pseudo-reg is optimized away, it is possible for it to
10050 be replaced with a MEM containing a multiply or shift. */
10069 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10070 VAR_INIT_STATUS_INITIALIZED);
10071 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10072 VAR_INIT_STATUS_INITIALIZED);
10074 if (op0 == 0 || op1 == 0)
10077 mem_loc_result = op0;
10078 add_loc_descr (&mem_loc_result, op1);
10079 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10084 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10088 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10089 VAR_INIT_STATUS_INITIALIZED);
10093 gcc_unreachable ();
10096 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10097 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10099 return mem_loc_result;
10102 /* Return a descriptor that describes the concatenation of two locations.
10103 This is typically a complex variable. */
10105 static dw_loc_descr_ref
10106 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10108 dw_loc_descr_ref cc_loc_result = NULL;
10109 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10110 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10112 if (x0_ref == 0 || x1_ref == 0)
10115 cc_loc_result = x0_ref;
10116 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10118 add_loc_descr (&cc_loc_result, x1_ref);
10119 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10121 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10122 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10124 return cc_loc_result;
10127 /* Return a descriptor that describes the concatenation of N
10130 static dw_loc_descr_ref
10131 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10134 dw_loc_descr_ref cc_loc_result = NULL;
10135 unsigned int n = XVECLEN (concatn, 0);
10137 for (i = 0; i < n; ++i)
10139 dw_loc_descr_ref ref;
10140 rtx x = XVECEXP (concatn, 0, i);
10142 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10146 add_loc_descr (&cc_loc_result, ref);
10147 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10150 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10151 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10153 return cc_loc_result;
10156 /* Output a proper Dwarf location descriptor for a variable or parameter
10157 which is either allocated in a register or in a memory location. For a
10158 register, we just generate an OP_REG and the register number. For a
10159 memory location we provide a Dwarf postfix expression describing how to
10160 generate the (dynamic) address of the object onto the address stack.
10162 If we don't know how to describe it, return 0. */
10164 static dw_loc_descr_ref
10165 loc_descriptor (rtx rtl, enum var_init_status initialized)
10167 dw_loc_descr_ref loc_result = NULL;
10169 switch (GET_CODE (rtl))
10172 /* The case of a subreg may arise when we have a local (register)
10173 variable or a formal (register) parameter which doesn't quite fill
10174 up an entire register. For now, just assume that it is
10175 legitimate to make the Dwarf info refer to the whole register which
10176 contains the given subreg. */
10177 rtl = SUBREG_REG (rtl);
10179 /* ... fall through ... */
10182 loc_result = reg_loc_descriptor (rtl, initialized);
10186 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10191 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10196 loc_result = concatn_loc_descriptor (rtl, initialized);
10201 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10203 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10207 rtl = XEXP (rtl, 1);
10212 rtvec par_elems = XVEC (rtl, 0);
10213 int num_elem = GET_NUM_ELEM (par_elems);
10214 enum machine_mode mode;
10217 /* Create the first one, so we have something to add to. */
10218 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10220 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10221 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10222 for (i = 1; i < num_elem; i++)
10224 dw_loc_descr_ref temp;
10226 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10228 add_loc_descr (&loc_result, temp);
10229 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10230 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10236 gcc_unreachable ();
10242 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10243 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10244 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10245 top-level invocation, and we require the address of LOC; is 0 if we require
10246 the value of LOC. */
10248 static dw_loc_descr_ref
10249 loc_descriptor_from_tree_1 (tree loc, int want_address)
10251 dw_loc_descr_ref ret, ret1;
10252 int have_address = 0;
10253 enum dwarf_location_atom op;
10255 /* ??? Most of the time we do not take proper care for sign/zero
10256 extending the values properly. Hopefully this won't be a real
10259 switch (TREE_CODE (loc))
10264 case PLACEHOLDER_EXPR:
10265 /* This case involves extracting fields from an object to determine the
10266 position of other fields. We don't try to encode this here. The
10267 only user of this is Ada, which encodes the needed information using
10268 the names of types. */
10274 case PREINCREMENT_EXPR:
10275 case PREDECREMENT_EXPR:
10276 case POSTINCREMENT_EXPR:
10277 case POSTDECREMENT_EXPR:
10278 /* There are no opcodes for these operations. */
10282 /* If we already want an address, there's nothing we can do. */
10286 /* Otherwise, process the argument and look for the address. */
10287 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10290 if (DECL_THREAD_LOCAL_P (loc))
10294 unsigned second_op;
10296 if (targetm.have_tls)
10298 /* If this is not defined, we have no way to emit the
10300 if (!targetm.asm_out.output_dwarf_dtprel)
10303 /* The way DW_OP_GNU_push_tls_address is specified, we
10304 can only look up addresses of objects in the current
10306 if (DECL_EXTERNAL (loc))
10308 first_op = INTERNAL_DW_OP_tls_addr;
10309 second_op = DW_OP_GNU_push_tls_address;
10313 if (!targetm.emutls.debug_form_tls_address)
10315 loc = emutls_decl (loc);
10316 first_op = DW_OP_addr;
10317 second_op = DW_OP_form_tls_address;
10320 rtl = rtl_for_decl_location (loc);
10321 if (rtl == NULL_RTX)
10326 rtl = XEXP (rtl, 0);
10327 if (! CONSTANT_P (rtl))
10330 ret = new_loc_descr (first_op, 0, 0);
10331 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10332 ret->dw_loc_oprnd1.v.val_addr = rtl;
10334 ret1 = new_loc_descr (second_op, 0, 0);
10335 add_loc_descr (&ret, ret1);
10343 if (DECL_HAS_VALUE_EXPR_P (loc))
10344 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10349 case FUNCTION_DECL:
10351 rtx rtl = rtl_for_decl_location (loc);
10353 if (rtl == NULL_RTX)
10355 else if (GET_CODE (rtl) == CONST_INT)
10357 HOST_WIDE_INT val = INTVAL (rtl);
10358 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10359 val &= GET_MODE_MASK (DECL_MODE (loc));
10360 ret = int_loc_descriptor (val);
10362 else if (GET_CODE (rtl) == CONST_STRING)
10364 else if (CONSTANT_P (rtl))
10366 ret = new_loc_descr (DW_OP_addr, 0, 0);
10367 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10368 ret->dw_loc_oprnd1.v.val_addr = rtl;
10372 enum machine_mode mode;
10374 /* Certain constructs can only be represented at top-level. */
10375 if (want_address == 2)
10376 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10378 mode = GET_MODE (rtl);
10381 rtl = XEXP (rtl, 0);
10384 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10390 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10394 case COMPOUND_EXPR:
10395 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10398 case VIEW_CONVERT_EXPR:
10401 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10403 case COMPONENT_REF:
10404 case BIT_FIELD_REF:
10406 case ARRAY_RANGE_REF:
10409 HOST_WIDE_INT bitsize, bitpos, bytepos;
10410 enum machine_mode mode;
10412 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10414 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10415 &unsignedp, &volatilep, false);
10420 ret = loc_descriptor_from_tree_1 (obj, 1);
10422 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10425 if (offset != NULL_TREE)
10427 /* Variable offset. */
10428 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
10429 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10432 bytepos = bitpos / BITS_PER_UNIT;
10434 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10435 else if (bytepos < 0)
10437 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10438 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10446 if (host_integerp (loc, 0))
10447 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10454 /* Get an RTL for this, if something has been emitted. */
10455 rtx rtl = lookup_constant_def (loc);
10456 enum machine_mode mode;
10458 if (!rtl || !MEM_P (rtl))
10460 mode = GET_MODE (rtl);
10461 rtl = XEXP (rtl, 0);
10462 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10467 case TRUTH_AND_EXPR:
10468 case TRUTH_ANDIF_EXPR:
10473 case TRUTH_XOR_EXPR:
10478 case TRUTH_OR_EXPR:
10479 case TRUTH_ORIF_EXPR:
10484 case FLOOR_DIV_EXPR:
10485 case CEIL_DIV_EXPR:
10486 case ROUND_DIV_EXPR:
10487 case TRUNC_DIV_EXPR:
10495 case FLOOR_MOD_EXPR:
10496 case CEIL_MOD_EXPR:
10497 case ROUND_MOD_EXPR:
10498 case TRUNC_MOD_EXPR:
10511 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10514 case POINTER_PLUS_EXPR:
10516 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10517 && host_integerp (TREE_OPERAND (loc, 1), 0))
10519 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10523 add_loc_descr (&ret,
10524 new_loc_descr (DW_OP_plus_uconst,
10525 tree_low_cst (TREE_OPERAND (loc, 1),
10535 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10542 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10549 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10556 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10571 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10572 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10573 if (ret == 0 || ret1 == 0)
10576 add_loc_descr (&ret, ret1);
10577 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10580 case TRUTH_NOT_EXPR:
10594 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10598 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10604 const enum tree_code code =
10605 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10607 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10608 build2 (code, integer_type_node,
10609 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10610 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10613 /* ... fall through ... */
10617 dw_loc_descr_ref lhs
10618 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10619 dw_loc_descr_ref rhs
10620 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10621 dw_loc_descr_ref bra_node, jump_node, tmp;
10623 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10624 if (ret == 0 || lhs == 0 || rhs == 0)
10627 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10628 add_loc_descr (&ret, bra_node);
10630 add_loc_descr (&ret, rhs);
10631 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10632 add_loc_descr (&ret, jump_node);
10634 add_loc_descr (&ret, lhs);
10635 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10636 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10638 /* ??? Need a node to point the skip at. Use a nop. */
10639 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10640 add_loc_descr (&ret, tmp);
10641 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10642 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10646 case FIX_TRUNC_EXPR:
10650 /* Leave front-end specific codes as simply unknown. This comes
10651 up, for instance, with the C STMT_EXPR. */
10652 if ((unsigned int) TREE_CODE (loc)
10653 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10656 #ifdef ENABLE_CHECKING
10657 /* Otherwise this is a generic code; we should just lists all of
10658 these explicitly. We forgot one. */
10659 gcc_unreachable ();
10661 /* In a release build, we want to degrade gracefully: better to
10662 generate incomplete debugging information than to crash. */
10667 /* Show if we can't fill the request for an address. */
10668 if (want_address && !have_address)
10671 /* If we've got an address and don't want one, dereference. */
10672 if (!want_address && have_address && ret)
10674 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10676 if (size > DWARF2_ADDR_SIZE || size == -1)
10678 else if (size == DWARF2_ADDR_SIZE)
10681 op = DW_OP_deref_size;
10683 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10689 static inline dw_loc_descr_ref
10690 loc_descriptor_from_tree (tree loc)
10692 return loc_descriptor_from_tree_1 (loc, 2);
10695 /* Given a value, round it up to the lowest multiple of `boundary'
10696 which is not less than the value itself. */
10698 static inline HOST_WIDE_INT
10699 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10701 return (((value + boundary - 1) / boundary) * boundary);
10704 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10705 pointer to the declared type for the relevant field variable, or return
10706 `integer_type_node' if the given node turns out to be an
10707 ERROR_MARK node. */
10710 field_type (const_tree decl)
10714 if (TREE_CODE (decl) == ERROR_MARK)
10715 return integer_type_node;
10717 type = DECL_BIT_FIELD_TYPE (decl);
10718 if (type == NULL_TREE)
10719 type = TREE_TYPE (decl);
10724 /* Given a pointer to a tree node, return the alignment in bits for
10725 it, or else return BITS_PER_WORD if the node actually turns out to
10726 be an ERROR_MARK node. */
10728 static inline unsigned
10729 simple_type_align_in_bits (const_tree type)
10731 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10734 static inline unsigned
10735 simple_decl_align_in_bits (const_tree decl)
10737 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10740 /* Return the result of rounding T up to ALIGN. */
10742 static inline HOST_WIDE_INT
10743 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10745 /* We must be careful if T is negative because HOST_WIDE_INT can be
10746 either "above" or "below" unsigned int as per the C promotion
10747 rules, depending on the host, thus making the signedness of the
10748 direct multiplication and division unpredictable. */
10749 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10755 return (HOST_WIDE_INT) u;
10758 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10759 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10760 or return 0 if we are unable to determine what that offset is, either
10761 because the argument turns out to be a pointer to an ERROR_MARK node, or
10762 because the offset is actually variable. (We can't handle the latter case
10765 static HOST_WIDE_INT
10766 field_byte_offset (const_tree decl)
10768 HOST_WIDE_INT object_offset_in_bits;
10769 HOST_WIDE_INT bitpos_int;
10771 if (TREE_CODE (decl) == ERROR_MARK)
10774 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10776 /* We cannot yet cope with fields whose positions are variable, so
10777 for now, when we see such things, we simply return 0. Someday, we may
10778 be able to handle such cases, but it will be damn difficult. */
10779 if (! host_integerp (bit_position (decl), 0))
10782 bitpos_int = int_bit_position (decl);
10784 #ifdef PCC_BITFIELD_TYPE_MATTERS
10785 if (PCC_BITFIELD_TYPE_MATTERS)
10788 tree field_size_tree;
10789 HOST_WIDE_INT deepest_bitpos;
10790 unsigned HOST_WIDE_INT field_size_in_bits;
10791 unsigned int type_align_in_bits;
10792 unsigned int decl_align_in_bits;
10793 unsigned HOST_WIDE_INT type_size_in_bits;
10795 type = field_type (decl);
10796 field_size_tree = DECL_SIZE (decl);
10798 /* The size could be unspecified if there was an error, or for
10799 a flexible array member. */
10800 if (! field_size_tree)
10801 field_size_tree = bitsize_zero_node;
10803 /* If we don't know the size of the field, pretend it's a full word. */
10804 if (host_integerp (field_size_tree, 1))
10805 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10807 field_size_in_bits = BITS_PER_WORD;
10809 type_size_in_bits = simple_type_size_in_bits (type);
10810 type_align_in_bits = simple_type_align_in_bits (type);
10811 decl_align_in_bits = simple_decl_align_in_bits (decl);
10813 /* The GCC front-end doesn't make any attempt to keep track of the
10814 starting bit offset (relative to the start of the containing
10815 structure type) of the hypothetical "containing object" for a
10816 bit-field. Thus, when computing the byte offset value for the
10817 start of the "containing object" of a bit-field, we must deduce
10818 this information on our own. This can be rather tricky to do in
10819 some cases. For example, handling the following structure type
10820 definition when compiling for an i386/i486 target (which only
10821 aligns long long's to 32-bit boundaries) can be very tricky:
10823 struct S { int field1; long long field2:31; };
10825 Fortunately, there is a simple rule-of-thumb which can be used
10826 in such cases. When compiling for an i386/i486, GCC will
10827 allocate 8 bytes for the structure shown above. It decides to
10828 do this based upon one simple rule for bit-field allocation.
10829 GCC allocates each "containing object" for each bit-field at
10830 the first (i.e. lowest addressed) legitimate alignment boundary
10831 (based upon the required minimum alignment for the declared
10832 type of the field) which it can possibly use, subject to the
10833 condition that there is still enough available space remaining
10834 in the containing object (when allocated at the selected point)
10835 to fully accommodate all of the bits of the bit-field itself.
10837 This simple rule makes it obvious why GCC allocates 8 bytes for
10838 each object of the structure type shown above. When looking
10839 for a place to allocate the "containing object" for `field2',
10840 the compiler simply tries to allocate a 64-bit "containing
10841 object" at each successive 32-bit boundary (starting at zero)
10842 until it finds a place to allocate that 64- bit field such that
10843 at least 31 contiguous (and previously unallocated) bits remain
10844 within that selected 64 bit field. (As it turns out, for the
10845 example above, the compiler finds it is OK to allocate the
10846 "containing object" 64-bit field at bit-offset zero within the
10849 Here we attempt to work backwards from the limited set of facts
10850 we're given, and we try to deduce from those facts, where GCC
10851 must have believed that the containing object started (within
10852 the structure type). The value we deduce is then used (by the
10853 callers of this routine) to generate DW_AT_location and
10854 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10855 the case of DW_AT_location, regular fields as well). */
10857 /* Figure out the bit-distance from the start of the structure to
10858 the "deepest" bit of the bit-field. */
10859 deepest_bitpos = bitpos_int + field_size_in_bits;
10861 /* This is the tricky part. Use some fancy footwork to deduce
10862 where the lowest addressed bit of the containing object must
10864 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10866 /* Round up to type_align by default. This works best for
10868 object_offset_in_bits
10869 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10871 if (object_offset_in_bits > bitpos_int)
10873 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10875 /* Round up to decl_align instead. */
10876 object_offset_in_bits
10877 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10882 object_offset_in_bits = bitpos_int;
10884 return object_offset_in_bits / BITS_PER_UNIT;
10887 /* The following routines define various Dwarf attributes and any data
10888 associated with them. */
10890 /* Add a location description attribute value to a DIE.
10892 This emits location attributes suitable for whole variables and
10893 whole parameters. Note that the location attributes for struct fields are
10894 generated by the routine `data_member_location_attribute' below. */
10897 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10898 dw_loc_descr_ref descr)
10901 add_AT_loc (die, attr_kind, descr);
10904 /* Attach the specialized form of location attribute used for data members of
10905 struct and union types. In the special case of a FIELD_DECL node which
10906 represents a bit-field, the "offset" part of this special location
10907 descriptor must indicate the distance in bytes from the lowest-addressed
10908 byte of the containing struct or union type to the lowest-addressed byte of
10909 the "containing object" for the bit-field. (See the `field_byte_offset'
10912 For any given bit-field, the "containing object" is a hypothetical object
10913 (of some integral or enum type) within which the given bit-field lives. The
10914 type of this hypothetical "containing object" is always the same as the
10915 declared type of the individual bit-field itself (for GCC anyway... the
10916 DWARF spec doesn't actually mandate this). Note that it is the size (in
10917 bytes) of the hypothetical "containing object" which will be given in the
10918 DW_AT_byte_size attribute for this bit-field. (See the
10919 `byte_size_attribute' function below.) It is also used when calculating the
10920 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10921 function below.) */
10924 add_data_member_location_attribute (dw_die_ref die, tree decl)
10926 HOST_WIDE_INT offset;
10927 dw_loc_descr_ref loc_descr = 0;
10929 if (TREE_CODE (decl) == TREE_BINFO)
10931 /* We're working on the TAG_inheritance for a base class. */
10932 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10934 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10935 aren't at a fixed offset from all (sub)objects of the same
10936 type. We need to extract the appropriate offset from our
10937 vtable. The following dwarf expression means
10939 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10941 This is specific to the V3 ABI, of course. */
10943 dw_loc_descr_ref tmp;
10945 /* Make a copy of the object address. */
10946 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10947 add_loc_descr (&loc_descr, tmp);
10949 /* Extract the vtable address. */
10950 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10951 add_loc_descr (&loc_descr, tmp);
10953 /* Calculate the address of the offset. */
10954 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10955 gcc_assert (offset < 0);
10957 tmp = int_loc_descriptor (-offset);
10958 add_loc_descr (&loc_descr, tmp);
10959 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10960 add_loc_descr (&loc_descr, tmp);
10962 /* Extract the offset. */
10963 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10964 add_loc_descr (&loc_descr, tmp);
10966 /* Add it to the object address. */
10967 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10968 add_loc_descr (&loc_descr, tmp);
10971 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10974 offset = field_byte_offset (decl);
10978 enum dwarf_location_atom op;
10980 /* The DWARF2 standard says that we should assume that the structure
10981 address is already on the stack, so we can specify a structure field
10982 address by using DW_OP_plus_uconst. */
10984 #ifdef MIPS_DEBUGGING_INFO
10985 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10986 operator correctly. It works only if we leave the offset on the
10990 op = DW_OP_plus_uconst;
10993 loc_descr = new_loc_descr (op, offset, 0);
10996 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10999 /* Writes integer values to dw_vec_const array. */
11002 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11006 *dest++ = val & 0xff;
11012 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11014 static HOST_WIDE_INT
11015 extract_int (const unsigned char *src, unsigned int size)
11017 HOST_WIDE_INT val = 0;
11023 val |= *--src & 0xff;
11029 /* Writes floating point values to dw_vec_const array. */
11032 insert_float (const_rtx rtl, unsigned char *array)
11034 REAL_VALUE_TYPE rv;
11038 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11039 real_to_target (val, &rv, GET_MODE (rtl));
11041 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11042 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11044 insert_int (val[i], 4, array);
11049 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11050 does not have a "location" either in memory or in a register. These
11051 things can arise in GNU C when a constant is passed as an actual parameter
11052 to an inlined function. They can also arise in C++ where declared
11053 constants do not necessarily get memory "homes". */
11056 add_const_value_attribute (dw_die_ref die, rtx rtl)
11058 switch (GET_CODE (rtl))
11062 HOST_WIDE_INT val = INTVAL (rtl);
11065 add_AT_int (die, DW_AT_const_value, val);
11067 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11072 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11073 floating-point constant. A CONST_DOUBLE is used whenever the
11074 constant requires more than one word in order to be adequately
11075 represented. We output CONST_DOUBLEs as blocks. */
11077 enum machine_mode mode = GET_MODE (rtl);
11079 if (SCALAR_FLOAT_MODE_P (mode))
11081 unsigned int length = GET_MODE_SIZE (mode);
11082 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11084 insert_float (rtl, array);
11085 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11089 /* ??? We really should be using HOST_WIDE_INT throughout. */
11090 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11092 add_AT_long_long (die, DW_AT_const_value,
11093 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11100 enum machine_mode mode = GET_MODE (rtl);
11101 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11102 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11103 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11107 switch (GET_MODE_CLASS (mode))
11109 case MODE_VECTOR_INT:
11110 for (i = 0, p = array; i < length; i++, p += elt_size)
11112 rtx elt = CONST_VECTOR_ELT (rtl, i);
11113 HOST_WIDE_INT lo, hi;
11115 switch (GET_CODE (elt))
11123 lo = CONST_DOUBLE_LOW (elt);
11124 hi = CONST_DOUBLE_HIGH (elt);
11128 gcc_unreachable ();
11131 if (elt_size <= sizeof (HOST_WIDE_INT))
11132 insert_int (lo, elt_size, p);
11135 unsigned char *p0 = p;
11136 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11138 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11139 if (WORDS_BIG_ENDIAN)
11144 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11145 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11150 case MODE_VECTOR_FLOAT:
11151 for (i = 0, p = array; i < length; i++, p += elt_size)
11153 rtx elt = CONST_VECTOR_ELT (rtl, i);
11154 insert_float (elt, p);
11159 gcc_unreachable ();
11162 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11167 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11173 add_AT_addr (die, DW_AT_const_value, rtl);
11174 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11178 /* In cases where an inlined instance of an inline function is passed
11179 the address of an `auto' variable (which is local to the caller) we
11180 can get a situation where the DECL_RTL of the artificial local
11181 variable (for the inlining) which acts as a stand-in for the
11182 corresponding formal parameter (of the inline function) will look
11183 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11184 exactly a compile-time constant expression, but it isn't the address
11185 of the (artificial) local variable either. Rather, it represents the
11186 *value* which the artificial local variable always has during its
11187 lifetime. We currently have no way to represent such quasi-constant
11188 values in Dwarf, so for now we just punt and generate nothing. */
11192 /* No other kinds of rtx should be possible here. */
11193 gcc_unreachable ();
11198 /* Determine whether the evaluation of EXPR references any variables
11199 or functions which aren't otherwise used (and therefore may not be
11202 reference_to_unused (tree * tp, int * walk_subtrees,
11203 void * data ATTRIBUTE_UNUSED)
11205 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11206 *walk_subtrees = 0;
11208 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11209 && ! TREE_ASM_WRITTEN (*tp))
11211 /* ??? The C++ FE emits debug information for using decls, so
11212 putting gcc_unreachable here falls over. See PR31899. For now
11213 be conservative. */
11214 else if (!cgraph_global_info_ready
11215 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11217 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11219 struct varpool_node *node = varpool_node (*tp);
11223 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11224 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11226 struct cgraph_node *node = cgraph_node (*tp);
11230 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11236 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11237 for use in a later add_const_value_attribute call. */
11240 rtl_for_decl_init (tree init, tree type)
11242 rtx rtl = NULL_RTX;
11244 /* If a variable is initialized with a string constant without embedded
11245 zeros, build CONST_STRING. */
11246 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11248 tree enttype = TREE_TYPE (type);
11249 tree domain = TYPE_DOMAIN (type);
11250 enum machine_mode mode = TYPE_MODE (enttype);
11252 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11254 && integer_zerop (TYPE_MIN_VALUE (domain))
11255 && compare_tree_int (TYPE_MAX_VALUE (domain),
11256 TREE_STRING_LENGTH (init) - 1) == 0
11257 && ((size_t) TREE_STRING_LENGTH (init)
11258 == strlen (TREE_STRING_POINTER (init)) + 1))
11259 rtl = gen_rtx_CONST_STRING (VOIDmode,
11260 ggc_strdup (TREE_STRING_POINTER (init)));
11262 /* Other aggregates, and complex values, could be represented using
11264 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11266 /* Vectors only work if their mode is supported by the target.
11267 FIXME: generic vectors ought to work too. */
11268 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11270 /* If the initializer is something that we know will expand into an
11271 immediate RTL constant, expand it now. We must be careful not to
11272 reference variables which won't be output. */
11273 else if (initializer_constant_valid_p (init, type)
11274 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11276 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11278 if (TREE_CODE (type) == VECTOR_TYPE)
11279 switch (TREE_CODE (init))
11284 if (TREE_CONSTANT (init))
11286 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11287 bool constant_p = true;
11289 unsigned HOST_WIDE_INT ix;
11291 /* Even when ctor is constant, it might contain non-*_CST
11292 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11293 belong into VECTOR_CST nodes. */
11294 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11295 if (!CONSTANT_CLASS_P (value))
11297 constant_p = false;
11303 init = build_vector_from_ctor (type, elts);
11313 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11315 /* If expand_expr returns a MEM, it wasn't immediate. */
11316 gcc_assert (!rtl || !MEM_P (rtl));
11322 /* Generate RTL for the variable DECL to represent its location. */
11325 rtl_for_decl_location (tree decl)
11329 /* Here we have to decide where we are going to say the parameter "lives"
11330 (as far as the debugger is concerned). We only have a couple of
11331 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11333 DECL_RTL normally indicates where the parameter lives during most of the
11334 activation of the function. If optimization is enabled however, this
11335 could be either NULL or else a pseudo-reg. Both of those cases indicate
11336 that the parameter doesn't really live anywhere (as far as the code
11337 generation parts of GCC are concerned) during most of the function's
11338 activation. That will happen (for example) if the parameter is never
11339 referenced within the function.
11341 We could just generate a location descriptor here for all non-NULL
11342 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11343 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11344 where DECL_RTL is NULL or is a pseudo-reg.
11346 Note however that we can only get away with using DECL_INCOMING_RTL as
11347 a backup substitute for DECL_RTL in certain limited cases. In cases
11348 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11349 we can be sure that the parameter was passed using the same type as it is
11350 declared to have within the function, and that its DECL_INCOMING_RTL
11351 points us to a place where a value of that type is passed.
11353 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11354 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11355 because in these cases DECL_INCOMING_RTL points us to a value of some
11356 type which is *different* from the type of the parameter itself. Thus,
11357 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11358 such cases, the debugger would end up (for example) trying to fetch a
11359 `float' from a place which actually contains the first part of a
11360 `double'. That would lead to really incorrect and confusing
11361 output at debug-time.
11363 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11364 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11365 are a couple of exceptions however. On little-endian machines we can
11366 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11367 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11368 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11369 when (on a little-endian machine) a non-prototyped function has a
11370 parameter declared to be of type `short' or `char'. In such cases,
11371 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11372 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11373 passed `int' value. If the debugger then uses that address to fetch
11374 a `short' or a `char' (on a little-endian machine) the result will be
11375 the correct data, so we allow for such exceptional cases below.
11377 Note that our goal here is to describe the place where the given formal
11378 parameter lives during most of the function's activation (i.e. between the
11379 end of the prologue and the start of the epilogue). We'll do that as best
11380 as we can. Note however that if the given formal parameter is modified
11381 sometime during the execution of the function, then a stack backtrace (at
11382 debug-time) will show the function as having been called with the *new*
11383 value rather than the value which was originally passed in. This happens
11384 rarely enough that it is not a major problem, but it *is* a problem, and
11385 I'd like to fix it.
11387 A future version of dwarf2out.c may generate two additional attributes for
11388 any given DW_TAG_formal_parameter DIE which will describe the "passed
11389 type" and the "passed location" for the given formal parameter in addition
11390 to the attributes we now generate to indicate the "declared type" and the
11391 "active location" for each parameter. This additional set of attributes
11392 could be used by debuggers for stack backtraces. Separately, note that
11393 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11394 This happens (for example) for inlined-instances of inline function formal
11395 parameters which are never referenced. This really shouldn't be
11396 happening. All PARM_DECL nodes should get valid non-NULL
11397 DECL_INCOMING_RTL values. FIXME. */
11399 /* Use DECL_RTL as the "location" unless we find something better. */
11400 rtl = DECL_RTL_IF_SET (decl);
11402 /* When generating abstract instances, ignore everything except
11403 constants, symbols living in memory, and symbols living in
11404 fixed registers. */
11405 if (! reload_completed)
11408 && (CONSTANT_P (rtl)
11410 && CONSTANT_P (XEXP (rtl, 0)))
11412 && TREE_CODE (decl) == VAR_DECL
11413 && TREE_STATIC (decl))))
11415 rtl = targetm.delegitimize_address (rtl);
11420 else if (TREE_CODE (decl) == PARM_DECL)
11422 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11424 tree declared_type = TREE_TYPE (decl);
11425 tree passed_type = DECL_ARG_TYPE (decl);
11426 enum machine_mode dmode = TYPE_MODE (declared_type);
11427 enum machine_mode pmode = TYPE_MODE (passed_type);
11429 /* This decl represents a formal parameter which was optimized out.
11430 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11431 all cases where (rtl == NULL_RTX) just below. */
11432 if (dmode == pmode)
11433 rtl = DECL_INCOMING_RTL (decl);
11434 else if (SCALAR_INT_MODE_P (dmode)
11435 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11436 && DECL_INCOMING_RTL (decl))
11438 rtx inc = DECL_INCOMING_RTL (decl);
11441 else if (MEM_P (inc))
11443 if (BYTES_BIG_ENDIAN)
11444 rtl = adjust_address_nv (inc, dmode,
11445 GET_MODE_SIZE (pmode)
11446 - GET_MODE_SIZE (dmode));
11453 /* If the parm was passed in registers, but lives on the stack, then
11454 make a big endian correction if the mode of the type of the
11455 parameter is not the same as the mode of the rtl. */
11456 /* ??? This is the same series of checks that are made in dbxout.c before
11457 we reach the big endian correction code there. It isn't clear if all
11458 of these checks are necessary here, but keeping them all is the safe
11460 else if (MEM_P (rtl)
11461 && XEXP (rtl, 0) != const0_rtx
11462 && ! CONSTANT_P (XEXP (rtl, 0))
11463 /* Not passed in memory. */
11464 && !MEM_P (DECL_INCOMING_RTL (decl))
11465 /* Not passed by invisible reference. */
11466 && (!REG_P (XEXP (rtl, 0))
11467 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11468 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11469 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11470 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11473 /* Big endian correction check. */
11474 && BYTES_BIG_ENDIAN
11475 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11476 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11479 int offset = (UNITS_PER_WORD
11480 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11482 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11483 plus_constant (XEXP (rtl, 0), offset));
11486 else if (TREE_CODE (decl) == VAR_DECL
11489 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11490 && BYTES_BIG_ENDIAN)
11492 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11493 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11495 /* If a variable is declared "register" yet is smaller than
11496 a register, then if we store the variable to memory, it
11497 looks like we're storing a register-sized value, when in
11498 fact we are not. We need to adjust the offset of the
11499 storage location to reflect the actual value's bytes,
11500 else gdb will not be able to display it. */
11502 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11503 plus_constant (XEXP (rtl, 0), rsize-dsize));
11506 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11507 and will have been substituted directly into all expressions that use it.
11508 C does not have such a concept, but C++ and other languages do. */
11509 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11510 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11513 rtl = targetm.delegitimize_address (rtl);
11515 /* If we don't look past the constant pool, we risk emitting a
11516 reference to a constant pool entry that isn't referenced from
11517 code, and thus is not emitted. */
11519 rtl = avoid_constant_pool_reference (rtl);
11524 /* We need to figure out what section we should use as the base for the
11525 address ranges where a given location is valid.
11526 1. If this particular DECL has a section associated with it, use that.
11527 2. If this function has a section associated with it, use that.
11528 3. Otherwise, use the text section.
11529 XXX: If you split a variable across multiple sections, we won't notice. */
11531 static const char *
11532 secname_for_decl (const_tree decl)
11534 const char *secname;
11536 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11538 tree sectree = DECL_SECTION_NAME (decl);
11539 secname = TREE_STRING_POINTER (sectree);
11541 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11543 tree sectree = DECL_SECTION_NAME (current_function_decl);
11544 secname = TREE_STRING_POINTER (sectree);
11546 else if (cfun && in_cold_section_p)
11547 secname = crtl->subsections.cold_section_label;
11549 secname = text_section_label;
11554 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
11555 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
11556 value is the offset into the common block for the symbol. */
11559 fortran_common (tree decl, HOST_WIDE_INT *value)
11561 tree val_expr, cvar;
11562 enum machine_mode mode;
11563 HOST_WIDE_INT bitsize, bitpos;
11565 int volatilep = 0, unsignedp = 0;
11567 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11568 it does not have a value (the offset into the common area), or if it
11569 is thread local (as opposed to global) then it isn't common, and shouldn't
11570 be handled as such. */
11571 if (TREE_CODE (decl) != VAR_DECL
11572 || !TREE_PUBLIC (decl)
11573 || !TREE_STATIC (decl)
11574 || !DECL_HAS_VALUE_EXPR_P (decl)
11578 val_expr = DECL_VALUE_EXPR (decl);
11579 if (TREE_CODE (val_expr) != COMPONENT_REF)
11582 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11583 &mode, &unsignedp, &volatilep, true);
11585 if (cvar == NULL_TREE
11586 || TREE_CODE (cvar) != VAR_DECL
11587 || DECL_ARTIFICIAL (cvar)
11588 || !TREE_PUBLIC (cvar))
11592 if (offset != NULL)
11594 if (!host_integerp (offset, 0))
11596 *value = tree_low_cst (offset, 0);
11599 *value += bitpos / BITS_PER_UNIT;
11605 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11606 data attribute for a variable or a parameter. We generate the
11607 DW_AT_const_value attribute only in those cases where the given variable
11608 or parameter does not have a true "location" either in memory or in a
11609 register. This can happen (for example) when a constant is passed as an
11610 actual argument in a call to an inline function. (It's possible that
11611 these things can crop up in other ways also.) Note that one type of
11612 constant value which can be passed into an inlined function is a constant
11613 pointer. This can happen for example if an actual argument in an inlined
11614 function call evaluates to a compile-time constant address. */
11617 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11618 enum dwarf_attribute attr)
11621 dw_loc_descr_ref descr;
11622 var_loc_list *loc_list;
11623 struct var_loc_node *node;
11624 if (TREE_CODE (decl) == ERROR_MARK)
11627 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11628 || TREE_CODE (decl) == RESULT_DECL);
11630 /* See if we possibly have multiple locations for this variable. */
11631 loc_list = lookup_decl_loc (decl);
11633 /* If it truly has multiple locations, the first and last node will
11635 if (loc_list && loc_list->first != loc_list->last)
11637 const char *endname, *secname;
11638 dw_loc_list_ref list;
11640 enum var_init_status initialized;
11642 /* Now that we know what section we are using for a base,
11643 actually construct the list of locations.
11644 The first location information is what is passed to the
11645 function that creates the location list, and the remaining
11646 locations just get added on to that list.
11647 Note that we only know the start address for a location
11648 (IE location changes), so to build the range, we use
11649 the range [current location start, next location start].
11650 This means we have to special case the last node, and generate
11651 a range of [last location start, end of function label]. */
11653 node = loc_list->first;
11654 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11655 secname = secname_for_decl (decl);
11657 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11658 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11660 initialized = VAR_INIT_STATUS_INITIALIZED;
11662 list = new_loc_list (loc_descriptor (varloc, initialized),
11663 node->label, node->next->label, secname, 1);
11666 for (; node->next; node = node->next)
11667 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11669 /* The variable has a location between NODE->LABEL and
11670 NODE->NEXT->LABEL. */
11671 enum var_init_status initialized =
11672 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11673 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11674 add_loc_descr_to_loc_list (&list,
11675 loc_descriptor (varloc, initialized),
11676 node->label, node->next->label, secname);
11679 /* If the variable has a location at the last label
11680 it keeps its location until the end of function. */
11681 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11683 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11684 enum var_init_status initialized =
11685 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11687 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11688 if (!current_function_decl)
11689 endname = text_end_label;
11692 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11693 current_function_funcdef_no);
11694 endname = ggc_strdup (label_id);
11696 add_loc_descr_to_loc_list (&list,
11697 loc_descriptor (varloc, initialized),
11698 node->label, endname, secname);
11701 /* Finally, add the location list to the DIE, and we are done. */
11702 add_AT_loc_list (die, attr, list);
11706 /* Try to get some constant RTL for this decl, and use that as the value of
11709 rtl = rtl_for_decl_location (decl);
11710 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11712 add_const_value_attribute (die, rtl);
11716 /* If we have tried to generate the location otherwise, and it
11717 didn't work out (we wouldn't be here if we did), and we have a one entry
11718 location list, try generating a location from that. */
11719 if (loc_list && loc_list->first)
11721 enum var_init_status status;
11722 node = loc_list->first;
11723 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11724 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11727 add_AT_location_description (die, attr, descr);
11732 /* We couldn't get any rtl, so try directly generating the location
11733 description from the tree. */
11734 descr = loc_descriptor_from_tree (decl);
11737 add_AT_location_description (die, attr, descr);
11740 /* None of that worked, so it must not really have a location;
11741 try adding a constant value attribute from the DECL_INITIAL. */
11742 tree_add_const_value_attribute (die, decl);
11745 /* If we don't have a copy of this variable in memory for some reason (such
11746 as a C++ member constant that doesn't have an out-of-line definition),
11747 we should tell the debugger about the constant value. */
11750 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
11752 tree init = DECL_INITIAL (decl);
11753 tree type = TREE_TYPE (decl);
11756 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
11761 rtl = rtl_for_decl_init (init, type);
11763 add_const_value_attribute (var_die, rtl);
11766 /* Convert the CFI instructions for the current function into a
11767 location list. This is used for DW_AT_frame_base when we targeting
11768 a dwarf2 consumer that does not support the dwarf3
11769 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11772 static dw_loc_list_ref
11773 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
11776 dw_loc_list_ref list, *list_tail;
11778 dw_cfa_location last_cfa, next_cfa;
11779 const char *start_label, *last_label, *section;
11781 fde = current_fde ();
11782 gcc_assert (fde != NULL);
11784 section = secname_for_decl (current_function_decl);
11788 next_cfa.reg = INVALID_REGNUM;
11789 next_cfa.offset = 0;
11790 next_cfa.indirect = 0;
11791 next_cfa.base_offset = 0;
11793 start_label = fde->dw_fde_begin;
11795 /* ??? Bald assumption that the CIE opcode list does not contain
11796 advance opcodes. */
11797 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11798 lookup_cfa_1 (cfi, &next_cfa);
11800 last_cfa = next_cfa;
11801 last_label = start_label;
11803 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11804 switch (cfi->dw_cfi_opc)
11806 case DW_CFA_set_loc:
11807 case DW_CFA_advance_loc1:
11808 case DW_CFA_advance_loc2:
11809 case DW_CFA_advance_loc4:
11810 if (!cfa_equal_p (&last_cfa, &next_cfa))
11812 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11813 start_label, last_label, section,
11816 list_tail = &(*list_tail)->dw_loc_next;
11817 last_cfa = next_cfa;
11818 start_label = last_label;
11820 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11823 case DW_CFA_advance_loc:
11824 /* The encoding is complex enough that we should never emit this. */
11825 case DW_CFA_remember_state:
11826 case DW_CFA_restore_state:
11827 /* We don't handle these two in this function. It would be possible
11828 if it were to be required. */
11829 gcc_unreachable ();
11832 lookup_cfa_1 (cfi, &next_cfa);
11836 if (!cfa_equal_p (&last_cfa, &next_cfa))
11838 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11839 start_label, last_label, section,
11841 list_tail = &(*list_tail)->dw_loc_next;
11842 start_label = last_label;
11844 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11845 start_label, fde->dw_fde_end, section,
11851 /* Compute a displacement from the "steady-state frame pointer" to the
11852 frame base (often the same as the CFA), and store it in
11853 frame_pointer_fb_offset. OFFSET is added to the displacement
11854 before the latter is negated. */
11857 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11861 #ifdef FRAME_POINTER_CFA_OFFSET
11862 reg = frame_pointer_rtx;
11863 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11865 reg = arg_pointer_rtx;
11866 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11869 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11870 if (GET_CODE (elim) == PLUS)
11872 offset += INTVAL (XEXP (elim, 1));
11873 elim = XEXP (elim, 0);
11876 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11877 && (elim == hard_frame_pointer_rtx
11878 || elim == stack_pointer_rtx))
11879 || elim == (frame_pointer_needed
11880 ? hard_frame_pointer_rtx
11881 : stack_pointer_rtx));
11883 frame_pointer_fb_offset = -offset;
11886 /* Generate a DW_AT_name attribute given some string value to be included as
11887 the value of the attribute. */
11890 add_name_attribute (dw_die_ref die, const char *name_string)
11892 if (name_string != NULL && *name_string != 0)
11894 if (demangle_name_func)
11895 name_string = (*demangle_name_func) (name_string);
11897 add_AT_string (die, DW_AT_name, name_string);
11901 /* Generate a DW_AT_comp_dir attribute for DIE. */
11904 add_comp_dir_attribute (dw_die_ref die)
11906 const char *wd = get_src_pwd ();
11908 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11911 /* Given a tree node describing an array bound (either lower or upper) output
11912 a representation for that bound. */
11915 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11917 switch (TREE_CODE (bound))
11922 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11924 if (! host_integerp (bound, 0)
11925 || (bound_attr == DW_AT_lower_bound
11926 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11927 || (is_fortran () && integer_onep (bound)))))
11928 /* Use the default. */
11931 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11935 case VIEW_CONVERT_EXPR:
11936 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11946 dw_die_ref decl_die = lookup_decl_die (bound);
11948 /* ??? Can this happen, or should the variable have been bound
11949 first? Probably it can, since I imagine that we try to create
11950 the types of parameters in the order in which they exist in
11951 the list, and won't have created a forward reference to a
11952 later parameter. */
11953 if (decl_die != NULL)
11954 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11960 /* Otherwise try to create a stack operation procedure to
11961 evaluate the value of the array bound. */
11963 dw_die_ref ctx, decl_die;
11964 dw_loc_descr_ref loc;
11966 loc = loc_descriptor_from_tree (bound);
11970 if (current_function_decl == 0)
11971 ctx = comp_unit_die;
11973 ctx = lookup_decl_die (current_function_decl);
11975 decl_die = new_die (DW_TAG_variable, ctx, bound);
11976 add_AT_flag (decl_die, DW_AT_artificial, 1);
11977 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11978 add_AT_loc (decl_die, DW_AT_location, loc);
11980 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11986 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
11987 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
11988 Note that the block of subscript information for an array type also
11989 includes information about the element type of the given array type. */
11992 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
11994 unsigned dimension_number;
11996 dw_die_ref subrange_die;
11998 for (dimension_number = 0;
11999 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12000 type = TREE_TYPE (type), dimension_number++)
12002 tree domain = TYPE_DOMAIN (type);
12004 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12005 and (in GNU C only) variable bounds. Handle all three forms
12007 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12010 /* We have an array type with specified bounds. */
12011 lower = TYPE_MIN_VALUE (domain);
12012 upper = TYPE_MAX_VALUE (domain);
12014 /* Define the index type. */
12015 if (TREE_TYPE (domain))
12017 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12018 TREE_TYPE field. We can't emit debug info for this
12019 because it is an unnamed integral type. */
12020 if (TREE_CODE (domain) == INTEGER_TYPE
12021 && TYPE_NAME (domain) == NULL_TREE
12022 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12023 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12026 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12030 /* ??? If upper is NULL, the array has unspecified length,
12031 but it does have a lower bound. This happens with Fortran
12033 Since the debugger is definitely going to need to know N
12034 to produce useful results, go ahead and output the lower
12035 bound solo, and hope the debugger can cope. */
12037 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12039 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12042 /* Otherwise we have an array type with an unspecified length. The
12043 DWARF-2 spec does not say how to handle this; let's just leave out the
12049 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12053 switch (TREE_CODE (tree_node))
12058 case ENUMERAL_TYPE:
12061 case QUAL_UNION_TYPE:
12062 size = int_size_in_bytes (tree_node);
12065 /* For a data member of a struct or union, the DW_AT_byte_size is
12066 generally given as the number of bytes normally allocated for an
12067 object of the *declared* type of the member itself. This is true
12068 even for bit-fields. */
12069 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12072 gcc_unreachable ();
12075 /* Note that `size' might be -1 when we get to this point. If it is, that
12076 indicates that the byte size of the entity in question is variable. We
12077 have no good way of expressing this fact in Dwarf at the present time,
12078 so just let the -1 pass on through. */
12079 add_AT_unsigned (die, DW_AT_byte_size, size);
12082 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12083 which specifies the distance in bits from the highest order bit of the
12084 "containing object" for the bit-field to the highest order bit of the
12087 For any given bit-field, the "containing object" is a hypothetical object
12088 (of some integral or enum type) within which the given bit-field lives. The
12089 type of this hypothetical "containing object" is always the same as the
12090 declared type of the individual bit-field itself. The determination of the
12091 exact location of the "containing object" for a bit-field is rather
12092 complicated. It's handled by the `field_byte_offset' function (above).
12094 Note that it is the size (in bytes) of the hypothetical "containing object"
12095 which will be given in the DW_AT_byte_size attribute for this bit-field.
12096 (See `byte_size_attribute' above). */
12099 add_bit_offset_attribute (dw_die_ref die, tree decl)
12101 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12102 tree type = DECL_BIT_FIELD_TYPE (decl);
12103 HOST_WIDE_INT bitpos_int;
12104 HOST_WIDE_INT highest_order_object_bit_offset;
12105 HOST_WIDE_INT highest_order_field_bit_offset;
12106 HOST_WIDE_INT unsigned bit_offset;
12108 /* Must be a field and a bit field. */
12109 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12111 /* We can't yet handle bit-fields whose offsets are variable, so if we
12112 encounter such things, just return without generating any attribute
12113 whatsoever. Likewise for variable or too large size. */
12114 if (! host_integerp (bit_position (decl), 0)
12115 || ! host_integerp (DECL_SIZE (decl), 1))
12118 bitpos_int = int_bit_position (decl);
12120 /* Note that the bit offset is always the distance (in bits) from the
12121 highest-order bit of the "containing object" to the highest-order bit of
12122 the bit-field itself. Since the "high-order end" of any object or field
12123 is different on big-endian and little-endian machines, the computation
12124 below must take account of these differences. */
12125 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12126 highest_order_field_bit_offset = bitpos_int;
12128 if (! BYTES_BIG_ENDIAN)
12130 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12131 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12135 = (! BYTES_BIG_ENDIAN
12136 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12137 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12139 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12142 /* For a FIELD_DECL node which represents a bit field, output an attribute
12143 which specifies the length in bits of the given field. */
12146 add_bit_size_attribute (dw_die_ref die, tree decl)
12148 /* Must be a field and a bit field. */
12149 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12150 && DECL_BIT_FIELD_TYPE (decl));
12152 if (host_integerp (DECL_SIZE (decl), 1))
12153 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12156 /* If the compiled language is ANSI C, then add a 'prototyped'
12157 attribute, if arg types are given for the parameters of a function. */
12160 add_prototyped_attribute (dw_die_ref die, tree func_type)
12162 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12163 && TYPE_ARG_TYPES (func_type) != NULL)
12164 add_AT_flag (die, DW_AT_prototyped, 1);
12167 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12168 by looking in either the type declaration or object declaration
12172 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12174 dw_die_ref origin_die = NULL;
12176 if (TREE_CODE (origin) != FUNCTION_DECL)
12178 /* We may have gotten separated from the block for the inlined
12179 function, if we're in an exception handler or some such; make
12180 sure that the abstract function has been written out.
12182 Doing this for nested functions is wrong, however; functions are
12183 distinct units, and our context might not even be inline. */
12187 fn = TYPE_STUB_DECL (fn);
12189 fn = decl_function_context (fn);
12191 dwarf2out_abstract_function (fn);
12194 if (DECL_P (origin))
12195 origin_die = lookup_decl_die (origin);
12196 else if (TYPE_P (origin))
12197 origin_die = lookup_type_die (origin);
12199 /* XXX: Functions that are never lowered don't always have correct block
12200 trees (in the case of java, they simply have no block tree, in some other
12201 languages). For these functions, there is nothing we can really do to
12202 output correct debug info for inlined functions in all cases. Rather
12203 than die, we'll just produce deficient debug info now, in that we will
12204 have variables without a proper abstract origin. In the future, when all
12205 functions are lowered, we should re-add a gcc_assert (origin_die)
12209 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12212 /* We do not currently support the pure_virtual attribute. */
12215 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12217 if (DECL_VINDEX (func_decl))
12219 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12221 if (host_integerp (DECL_VINDEX (func_decl), 0))
12222 add_AT_loc (die, DW_AT_vtable_elem_location,
12223 new_loc_descr (DW_OP_constu,
12224 tree_low_cst (DECL_VINDEX (func_decl), 0),
12227 /* GNU extension: Record what type this method came from originally. */
12228 if (debug_info_level > DINFO_LEVEL_TERSE)
12229 add_AT_die_ref (die, DW_AT_containing_type,
12230 lookup_type_die (DECL_CONTEXT (func_decl)));
12234 /* Add source coordinate attributes for the given decl. */
12237 add_src_coords_attributes (dw_die_ref die, tree decl)
12239 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12241 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12242 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12245 /* Add a DW_AT_name attribute and source coordinate attribute for the
12246 given decl, but only if it actually has a name. */
12249 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12253 decl_name = DECL_NAME (decl);
12254 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12256 add_name_attribute (die, dwarf2_name (decl, 0));
12257 if (! DECL_ARTIFICIAL (decl))
12258 add_src_coords_attributes (die, decl);
12260 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12261 && TREE_PUBLIC (decl)
12262 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12263 && !DECL_ABSTRACT (decl)
12264 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12266 add_AT_string (die, DW_AT_MIPS_linkage_name,
12267 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12270 #ifdef VMS_DEBUGGING_INFO
12271 /* Get the function's name, as described by its RTL. This may be different
12272 from the DECL_NAME name used in the source file. */
12273 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12275 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12276 XEXP (DECL_RTL (decl), 0));
12277 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12282 /* Push a new declaration scope. */
12285 push_decl_scope (tree scope)
12287 VEC_safe_push (tree, gc, decl_scope_table, scope);
12290 /* Pop a declaration scope. */
12293 pop_decl_scope (void)
12295 VEC_pop (tree, decl_scope_table);
12298 /* Return the DIE for the scope that immediately contains this type.
12299 Non-named types get global scope. Named types nested in other
12300 types get their containing scope if it's open, or global scope
12301 otherwise. All other types (i.e. function-local named types) get
12302 the current active scope. */
12305 scope_die_for (tree t, dw_die_ref context_die)
12307 dw_die_ref scope_die = NULL;
12308 tree containing_scope;
12311 /* Non-types always go in the current scope. */
12312 gcc_assert (TYPE_P (t));
12314 containing_scope = TYPE_CONTEXT (t);
12316 /* Use the containing namespace if it was passed in (for a declaration). */
12317 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12319 if (context_die == lookup_decl_die (containing_scope))
12322 containing_scope = NULL_TREE;
12325 /* Ignore function type "scopes" from the C frontend. They mean that
12326 a tagged type is local to a parmlist of a function declarator, but
12327 that isn't useful to DWARF. */
12328 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12329 containing_scope = NULL_TREE;
12331 if (containing_scope == NULL_TREE)
12332 scope_die = comp_unit_die;
12333 else if (TYPE_P (containing_scope))
12335 /* For types, we can just look up the appropriate DIE. But
12336 first we check to see if we're in the middle of emitting it
12337 so we know where the new DIE should go. */
12338 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12339 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12344 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12345 || TREE_ASM_WRITTEN (containing_scope));
12347 /* If none of the current dies are suitable, we get file scope. */
12348 scope_die = comp_unit_die;
12351 scope_die = lookup_type_die (containing_scope);
12354 scope_die = context_die;
12359 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12362 local_scope_p (dw_die_ref context_die)
12364 for (; context_die; context_die = context_die->die_parent)
12365 if (context_die->die_tag == DW_TAG_inlined_subroutine
12366 || context_die->die_tag == DW_TAG_subprogram)
12372 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12373 whether or not to treat a DIE in this context as a declaration. */
12376 class_or_namespace_scope_p (dw_die_ref context_die)
12378 return (context_die
12379 && (context_die->die_tag == DW_TAG_structure_type
12380 || context_die->die_tag == DW_TAG_class_type
12381 || context_die->die_tag == DW_TAG_interface_type
12382 || context_die->die_tag == DW_TAG_union_type
12383 || context_die->die_tag == DW_TAG_namespace));
12386 /* Many forms of DIEs require a "type description" attribute. This
12387 routine locates the proper "type descriptor" die for the type given
12388 by 'type', and adds a DW_AT_type attribute below the given die. */
12391 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12392 int decl_volatile, dw_die_ref context_die)
12394 enum tree_code code = TREE_CODE (type);
12395 dw_die_ref type_die = NULL;
12397 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12398 or fixed-point type, use the inner type. This is because we have no
12399 support for unnamed types in base_type_die. This can happen if this is
12400 an Ada subrange type. Correct solution is emit a subrange type die. */
12401 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12402 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12403 type = TREE_TYPE (type), code = TREE_CODE (type);
12405 if (code == ERROR_MARK
12406 /* Handle a special case. For functions whose return type is void, we
12407 generate *no* type attribute. (Note that no object may have type
12408 `void', so this only applies to function return types). */
12409 || code == VOID_TYPE)
12412 type_die = modified_type_die (type,
12413 decl_const || TYPE_READONLY (type),
12414 decl_volatile || TYPE_VOLATILE (type),
12417 if (type_die != NULL)
12418 add_AT_die_ref (object_die, DW_AT_type, type_die);
12421 /* Given an object die, add the calling convention attribute for the
12422 function call type. */
12424 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12426 enum dwarf_calling_convention value = DW_CC_normal;
12428 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12430 /* DWARF doesn't provide a way to identify a program's source-level
12431 entry point. DW_AT_calling_convention attributes are only meant
12432 to describe functions' calling conventions. However, lacking a
12433 better way to signal the Fortran main program, we use this for the
12434 time being, following existing custom. */
12436 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12437 value = DW_CC_program;
12439 /* Only add the attribute if the backend requests it, and
12440 is not DW_CC_normal. */
12441 if (value && (value != DW_CC_normal))
12442 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12445 /* Given a tree pointer to a struct, class, union, or enum type node, return
12446 a pointer to the (string) tag name for the given type, or zero if the type
12447 was declared without a tag. */
12449 static const char *
12450 type_tag (const_tree type)
12452 const char *name = 0;
12454 if (TYPE_NAME (type) != 0)
12458 /* Find the IDENTIFIER_NODE for the type name. */
12459 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12460 t = TYPE_NAME (type);
12462 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12463 a TYPE_DECL node, regardless of whether or not a `typedef' was
12465 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12466 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12468 /* We want to be extra verbose. Don't call dwarf_name if
12469 DECL_NAME isn't set. The default hook for decl_printable_name
12470 doesn't like that, and in this context it's correct to return
12471 0, instead of "<anonymous>" or the like. */
12472 if (DECL_NAME (TYPE_NAME (type)))
12473 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12476 /* Now get the name as a string, or invent one. */
12477 if (!name && t != 0)
12478 name = IDENTIFIER_POINTER (t);
12481 return (name == 0 || *name == '\0') ? 0 : name;
12484 /* Return the type associated with a data member, make a special check
12485 for bit field types. */
12488 member_declared_type (const_tree member)
12490 return (DECL_BIT_FIELD_TYPE (member)
12491 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12494 /* Get the decl's label, as described by its RTL. This may be different
12495 from the DECL_NAME name used in the source file. */
12498 static const char *
12499 decl_start_label (tree decl)
12502 const char *fnname;
12504 x = DECL_RTL (decl);
12505 gcc_assert (MEM_P (x));
12508 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12510 fnname = XSTR (x, 0);
12515 /* These routines generate the internal representation of the DIE's for
12516 the compilation unit. Debugging information is collected by walking
12517 the declaration trees passed in from dwarf2out_decl(). */
12520 gen_array_type_die (tree type, dw_die_ref context_die)
12522 dw_die_ref scope_die = scope_die_for (type, context_die);
12523 dw_die_ref array_die;
12525 /* GNU compilers represent multidimensional array types as sequences of one
12526 dimensional array types whose element types are themselves array types.
12527 We sometimes squish that down to a single array_type DIE with multiple
12528 subscripts in the Dwarf debugging info. The draft Dwarf specification
12529 say that we are allowed to do this kind of compression in C, because
12530 there is no difference between an array of arrays and a multidimensional
12531 array. We don't do this for Ada to remain as close as possible to the
12532 actual representation, which is especially important against the language
12533 flexibilty wrt arrays of variable size. */
12535 bool collapse_nested_arrays = !is_ada ();
12538 /* ??? The SGI dwarf reader fails for array of array of enum types
12539 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12540 array type comes before the outer array type. We thus call gen_type_die
12541 before we new_die and must prevent nested array types collapsing for this
12544 #ifdef MIPS_DEBUGGING_INFO
12545 gen_type_die (TREE_TYPE (type), context_die);
12546 collapse_nested_arrays = false;
12549 array_die = new_die (DW_TAG_array_type, scope_die, type);
12550 add_name_attribute (array_die, type_tag (type));
12551 equate_type_number_to_die (type, array_die);
12553 if (TREE_CODE (type) == VECTOR_TYPE)
12555 /* The frontend feeds us a representation for the vector as a struct
12556 containing an array. Pull out the array type. */
12557 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12558 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12561 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12563 && TREE_CODE (type) == ARRAY_TYPE
12564 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
12565 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12568 /* We default the array ordering. SDB will probably do
12569 the right things even if DW_AT_ordering is not present. It's not even
12570 an issue until we start to get into multidimensional arrays anyway. If
12571 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12572 then we'll have to put the DW_AT_ordering attribute back in. (But if
12573 and when we find out that we need to put these in, we will only do so
12574 for multidimensional arrays. */
12575 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
12578 #ifdef MIPS_DEBUGGING_INFO
12579 /* The SGI compilers handle arrays of unknown bound by setting
12580 AT_declaration and not emitting any subrange DIEs. */
12581 if (! TYPE_DOMAIN (type))
12582 add_AT_flag (array_die, DW_AT_declaration, 1);
12585 add_subscript_info (array_die, type, collapse_nested_arrays);
12587 /* Add representation of the type of the elements of this array type and
12588 emit the corresponding DIE if we haven't done it already. */
12589 element_type = TREE_TYPE (type);
12590 if (collapse_nested_arrays)
12591 while (TREE_CODE (element_type) == ARRAY_TYPE)
12592 element_type = TREE_TYPE (element_type);
12594 #ifndef MIPS_DEBUGGING_INFO
12595 gen_type_die (element_type, context_die);
12598 add_type_attribute (array_die, element_type, 0, 0, context_die);
12600 if (get_AT (array_die, DW_AT_name))
12601 add_pubtype (type, array_die);
12604 static dw_loc_descr_ref
12605 descr_info_loc (tree val, tree base_decl)
12607 HOST_WIDE_INT size;
12608 dw_loc_descr_ref loc, loc2;
12609 enum dwarf_location_atom op;
12611 if (val == base_decl)
12612 return new_loc_descr (DW_OP_push_object_address, 0, 0);
12614 switch (TREE_CODE (val))
12617 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12619 if (host_integerp (val, 0))
12620 return int_loc_descriptor (tree_low_cst (val, 0));
12623 size = int_size_in_bytes (TREE_TYPE (val));
12626 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12629 if (size == DWARF2_ADDR_SIZE)
12630 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
12632 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
12634 case POINTER_PLUS_EXPR:
12636 if (host_integerp (TREE_OPERAND (val, 1), 1)
12637 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
12640 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12643 add_loc_descr (&loc,
12644 new_loc_descr (DW_OP_plus_uconst,
12645 tree_low_cst (TREE_OPERAND (val, 1),
12652 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12655 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
12658 add_loc_descr (&loc, loc2);
12659 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
12681 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
12682 tree val, tree base_decl)
12684 dw_loc_descr_ref loc;
12686 if (host_integerp (val, 0))
12688 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
12692 loc = descr_info_loc (val, base_decl);
12696 add_AT_loc (die, attr, loc);
12699 /* This routine generates DIE for array with hidden descriptor, details
12700 are filled into *info by a langhook. */
12703 gen_descr_array_type_die (tree type, struct array_descr_info *info,
12704 dw_die_ref context_die)
12706 dw_die_ref scope_die = scope_die_for (type, context_die);
12707 dw_die_ref array_die;
12710 array_die = new_die (DW_TAG_array_type, scope_die, type);
12711 add_name_attribute (array_die, type_tag (type));
12712 equate_type_number_to_die (type, array_die);
12714 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12716 && info->ndimensions >= 2)
12717 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12719 if (info->data_location)
12720 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
12722 if (info->associated)
12723 add_descr_info_field (array_die, DW_AT_associated, info->associated,
12725 if (info->allocated)
12726 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
12729 for (dim = 0; dim < info->ndimensions; dim++)
12731 dw_die_ref subrange_die
12732 = new_die (DW_TAG_subrange_type, array_die, NULL);
12734 if (info->dimen[dim].lower_bound)
12736 /* If it is the default value, omit it. */
12737 if ((is_c_family () || is_java ())
12738 && integer_zerop (info->dimen[dim].lower_bound))
12740 else if (is_fortran ()
12741 && integer_onep (info->dimen[dim].lower_bound))
12744 add_descr_info_field (subrange_die, DW_AT_lower_bound,
12745 info->dimen[dim].lower_bound,
12748 if (info->dimen[dim].upper_bound)
12749 add_descr_info_field (subrange_die, DW_AT_upper_bound,
12750 info->dimen[dim].upper_bound,
12752 if (info->dimen[dim].stride)
12753 add_descr_info_field (subrange_die, DW_AT_byte_stride,
12754 info->dimen[dim].stride,
12758 gen_type_die (info->element_type, context_die);
12759 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
12761 if (get_AT (array_die, DW_AT_name))
12762 add_pubtype (type, array_die);
12767 gen_entry_point_die (tree decl, dw_die_ref context_die)
12769 tree origin = decl_ultimate_origin (decl);
12770 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
12772 if (origin != NULL)
12773 add_abstract_origin_attribute (decl_die, origin);
12776 add_name_and_src_coords_attributes (decl_die, decl);
12777 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
12778 0, 0, context_die);
12781 if (DECL_ABSTRACT (decl))
12782 equate_decl_number_to_die (decl, decl_die);
12784 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12788 /* Walk through the list of incomplete types again, trying once more to
12789 emit full debugging info for them. */
12792 retry_incomplete_types (void)
12796 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12797 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12800 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12803 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12805 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12807 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12808 be incomplete and such types are not marked. */
12809 add_abstract_origin_attribute (type_die, type);
12812 /* Determine what tag to use for a record type. */
12814 static enum dwarf_tag
12815 record_type_tag (tree type)
12817 if (! lang_hooks.types.classify_record)
12818 return DW_TAG_structure_type;
12820 switch (lang_hooks.types.classify_record (type))
12822 case RECORD_IS_STRUCT:
12823 return DW_TAG_structure_type;
12825 case RECORD_IS_CLASS:
12826 return DW_TAG_class_type;
12828 case RECORD_IS_INTERFACE:
12829 return DW_TAG_interface_type;
12832 gcc_unreachable ();
12836 /* Generate a DIE to represent an inlined instance of a structure type. */
12839 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12841 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12843 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12844 be incomplete and such types are not marked. */
12845 add_abstract_origin_attribute (type_die, type);
12848 /* Generate a DIE to represent an inlined instance of a union type. */
12851 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12853 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12855 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12856 be incomplete and such types are not marked. */
12857 add_abstract_origin_attribute (type_die, type);
12860 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12861 include all of the information about the enumeration values also. Each
12862 enumerated type name/value is listed as a child of the enumerated type
12866 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12868 dw_die_ref type_die = lookup_type_die (type);
12870 if (type_die == NULL)
12872 type_die = new_die (DW_TAG_enumeration_type,
12873 scope_die_for (type, context_die), type);
12874 equate_type_number_to_die (type, type_die);
12875 add_name_attribute (type_die, type_tag (type));
12877 else if (! TYPE_SIZE (type))
12880 remove_AT (type_die, DW_AT_declaration);
12882 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12883 given enum type is incomplete, do not generate the DW_AT_byte_size
12884 attribute or the DW_AT_element_list attribute. */
12885 if (TYPE_SIZE (type))
12889 TREE_ASM_WRITTEN (type) = 1;
12890 add_byte_size_attribute (type_die, type);
12891 if (TYPE_STUB_DECL (type) != NULL_TREE)
12892 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12894 /* If the first reference to this type was as the return type of an
12895 inline function, then it may not have a parent. Fix this now. */
12896 if (type_die->die_parent == NULL)
12897 add_child_die (scope_die_for (type, context_die), type_die);
12899 for (link = TYPE_VALUES (type);
12900 link != NULL; link = TREE_CHAIN (link))
12902 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12903 tree value = TREE_VALUE (link);
12905 add_name_attribute (enum_die,
12906 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12908 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12909 /* DWARF2 does not provide a way of indicating whether or
12910 not enumeration constants are signed or unsigned. GDB
12911 always assumes the values are signed, so we output all
12912 values as if they were signed. That means that
12913 enumeration constants with very large unsigned values
12914 will appear to have negative values in the debugger. */
12915 add_AT_int (enum_die, DW_AT_const_value,
12916 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12920 add_AT_flag (type_die, DW_AT_declaration, 1);
12922 if (get_AT (type_die, DW_AT_name))
12923 add_pubtype (type, type_die);
12928 /* Generate a DIE to represent either a real live formal parameter decl or to
12929 represent just the type of some formal parameter position in some function
12932 Note that this routine is a bit unusual because its argument may be a
12933 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12934 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12935 node. If it's the former then this function is being called to output a
12936 DIE to represent a formal parameter object (or some inlining thereof). If
12937 it's the latter, then this function is only being called to output a
12938 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12939 argument type of some subprogram type. */
12942 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12944 dw_die_ref parm_die
12945 = new_die (DW_TAG_formal_parameter, context_die, node);
12948 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12950 case tcc_declaration:
12951 origin = decl_ultimate_origin (node);
12952 if (origin != NULL)
12953 add_abstract_origin_attribute (parm_die, origin);
12956 tree type = TREE_TYPE (node);
12957 add_name_and_src_coords_attributes (parm_die, node);
12958 if (DECL_BY_REFERENCE (node))
12959 type = TREE_TYPE (type);
12960 add_type_attribute (parm_die, type,
12961 TREE_READONLY (node),
12962 TREE_THIS_VOLATILE (node),
12964 if (DECL_ARTIFICIAL (node))
12965 add_AT_flag (parm_die, DW_AT_artificial, 1);
12968 equate_decl_number_to_die (node, parm_die);
12969 if (! DECL_ABSTRACT (node))
12970 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12975 /* We were called with some kind of a ..._TYPE node. */
12976 add_type_attribute (parm_die, node, 0, 0, context_die);
12980 gcc_unreachable ();
12986 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12987 at the end of an (ANSI prototyped) formal parameters list. */
12990 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12992 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12995 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12996 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12997 parameters as specified in some function type specification (except for
12998 those which appear as part of a function *definition*). */
13001 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13004 tree formal_type = NULL;
13005 tree first_parm_type;
13008 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13010 arg = DECL_ARGUMENTS (function_or_method_type);
13011 function_or_method_type = TREE_TYPE (function_or_method_type);
13016 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13018 /* Make our first pass over the list of formal parameter types and output a
13019 DW_TAG_formal_parameter DIE for each one. */
13020 for (link = first_parm_type; link; )
13022 dw_die_ref parm_die;
13024 formal_type = TREE_VALUE (link);
13025 if (formal_type == void_type_node)
13028 /* Output a (nameless) DIE to represent the formal parameter itself. */
13029 parm_die = gen_formal_parameter_die (formal_type, context_die);
13030 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13031 && link == first_parm_type)
13032 || (arg && DECL_ARTIFICIAL (arg)))
13033 add_AT_flag (parm_die, DW_AT_artificial, 1);
13035 link = TREE_CHAIN (link);
13037 arg = TREE_CHAIN (arg);
13040 /* If this function type has an ellipsis, add a
13041 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13042 if (formal_type != void_type_node)
13043 gen_unspecified_parameters_die (function_or_method_type, context_die);
13045 /* Make our second (and final) pass over the list of formal parameter types
13046 and output DIEs to represent those types (as necessary). */
13047 for (link = TYPE_ARG_TYPES (function_or_method_type);
13048 link && TREE_VALUE (link);
13049 link = TREE_CHAIN (link))
13050 gen_type_die (TREE_VALUE (link), context_die);
13053 /* We want to generate the DIE for TYPE so that we can generate the
13054 die for MEMBER, which has been defined; we will need to refer back
13055 to the member declaration nested within TYPE. If we're trying to
13056 generate minimal debug info for TYPE, processing TYPE won't do the
13057 trick; we need to attach the member declaration by hand. */
13060 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13062 gen_type_die (type, context_die);
13064 /* If we're trying to avoid duplicate debug info, we may not have
13065 emitted the member decl for this function. Emit it now. */
13066 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13067 && ! lookup_decl_die (member))
13069 dw_die_ref type_die;
13070 gcc_assert (!decl_ultimate_origin (member));
13072 push_decl_scope (type);
13073 type_die = lookup_type_die (type);
13074 if (TREE_CODE (member) == FUNCTION_DECL)
13075 gen_subprogram_die (member, type_die);
13076 else if (TREE_CODE (member) == FIELD_DECL)
13078 /* Ignore the nameless fields that are used to skip bits but handle
13079 C++ anonymous unions and structs. */
13080 if (DECL_NAME (member) != NULL_TREE
13081 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13082 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13084 gen_type_die (member_declared_type (member), type_die);
13085 gen_field_die (member, type_die);
13089 gen_variable_die (member, type_die);
13095 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13096 may later generate inlined and/or out-of-line instances of. */
13099 dwarf2out_abstract_function (tree decl)
13101 dw_die_ref old_die;
13104 int was_abstract = DECL_ABSTRACT (decl);
13106 /* Make sure we have the actual abstract inline, not a clone. */
13107 decl = DECL_ORIGIN (decl);
13109 old_die = lookup_decl_die (decl);
13110 if (old_die && get_AT (old_die, DW_AT_inline))
13111 /* We've already generated the abstract instance. */
13114 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13115 we don't get confused by DECL_ABSTRACT. */
13116 if (debug_info_level > DINFO_LEVEL_TERSE)
13118 context = decl_class_context (decl);
13120 gen_type_die_for_member
13121 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13124 /* Pretend we've just finished compiling this function. */
13125 save_fn = current_function_decl;
13126 current_function_decl = decl;
13127 push_cfun (DECL_STRUCT_FUNCTION (decl));
13129 set_decl_abstract_flags (decl, 1);
13130 dwarf2out_decl (decl);
13131 if (! was_abstract)
13132 set_decl_abstract_flags (decl, 0);
13134 current_function_decl = save_fn;
13138 /* Helper function of premark_used_types() which gets called through
13139 htab_traverse_resize().
13141 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13142 marked as unused by prune_unused_types. */
13144 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13149 type = (tree) *slot;
13150 die = lookup_type_die (type);
13152 die->die_perennial_p = 1;
13156 /* Mark all members of used_types_hash as perennial. */
13158 premark_used_types (void)
13160 if (cfun && cfun->used_types_hash)
13161 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13164 /* Generate a DIE to represent a declared function (either file-scope or
13168 gen_subprogram_die (tree decl, dw_die_ref context_die)
13170 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13171 tree origin = decl_ultimate_origin (decl);
13172 dw_die_ref subr_die;
13175 dw_die_ref old_die = lookup_decl_die (decl);
13176 int declaration = (current_function_decl != decl
13177 || class_or_namespace_scope_p (context_die));
13179 premark_used_types ();
13181 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13182 started to generate the abstract instance of an inline, decided to output
13183 its containing class, and proceeded to emit the declaration of the inline
13184 from the member list for the class. If so, DECLARATION takes priority;
13185 we'll get back to the abstract instance when done with the class. */
13187 /* The class-scope declaration DIE must be the primary DIE. */
13188 if (origin && declaration && class_or_namespace_scope_p (context_die))
13191 gcc_assert (!old_die);
13194 /* Now that the C++ front end lazily declares artificial member fns, we
13195 might need to retrofit the declaration into its class. */
13196 if (!declaration && !origin && !old_die
13197 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13198 && !class_or_namespace_scope_p (context_die)
13199 && debug_info_level > DINFO_LEVEL_TERSE)
13200 old_die = force_decl_die (decl);
13202 if (origin != NULL)
13204 gcc_assert (!declaration || local_scope_p (context_die));
13206 /* Fixup die_parent for the abstract instance of a nested
13207 inline function. */
13208 if (old_die && old_die->die_parent == NULL)
13209 add_child_die (context_die, old_die);
13211 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13212 add_abstract_origin_attribute (subr_die, origin);
13216 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13217 struct dwarf_file_data * file_index = lookup_filename (s.file);
13219 if (!get_AT_flag (old_die, DW_AT_declaration)
13220 /* We can have a normal definition following an inline one in the
13221 case of redefinition of GNU C extern inlines.
13222 It seems reasonable to use AT_specification in this case. */
13223 && !get_AT (old_die, DW_AT_inline))
13225 /* Detect and ignore this case, where we are trying to output
13226 something we have already output. */
13230 /* If the definition comes from the same place as the declaration,
13231 maybe use the old DIE. We always want the DIE for this function
13232 that has the *_pc attributes to be under comp_unit_die so the
13233 debugger can find it. We also need to do this for abstract
13234 instances of inlines, since the spec requires the out-of-line copy
13235 to have the same parent. For local class methods, this doesn't
13236 apply; we just use the old DIE. */
13237 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13238 && (DECL_ARTIFICIAL (decl)
13239 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13240 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13241 == (unsigned) s.line))))
13243 subr_die = old_die;
13245 /* Clear out the declaration attribute and the formal parameters.
13246 Do not remove all children, because it is possible that this
13247 declaration die was forced using force_decl_die(). In such
13248 cases die that forced declaration die (e.g. TAG_imported_module)
13249 is one of the children that we do not want to remove. */
13250 remove_AT (subr_die, DW_AT_declaration);
13251 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13255 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13256 add_AT_specification (subr_die, old_die);
13257 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13258 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13259 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13260 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13265 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13267 if (TREE_PUBLIC (decl))
13268 add_AT_flag (subr_die, DW_AT_external, 1);
13270 add_name_and_src_coords_attributes (subr_die, decl);
13271 if (debug_info_level > DINFO_LEVEL_TERSE)
13273 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13274 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13275 0, 0, context_die);
13278 add_pure_or_virtual_attribute (subr_die, decl);
13279 if (DECL_ARTIFICIAL (decl))
13280 add_AT_flag (subr_die, DW_AT_artificial, 1);
13282 if (TREE_PROTECTED (decl))
13283 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13284 else if (TREE_PRIVATE (decl))
13285 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13290 if (!old_die || !get_AT (old_die, DW_AT_inline))
13292 add_AT_flag (subr_die, DW_AT_declaration, 1);
13294 /* The first time we see a member function, it is in the context of
13295 the class to which it belongs. We make sure of this by emitting
13296 the class first. The next time is the definition, which is
13297 handled above. The two may come from the same source text.
13299 Note that force_decl_die() forces function declaration die. It is
13300 later reused to represent definition. */
13301 equate_decl_number_to_die (decl, subr_die);
13304 else if (DECL_ABSTRACT (decl))
13306 if (DECL_DECLARED_INLINE_P (decl))
13308 if (cgraph_function_possibly_inlined_p (decl))
13309 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13311 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13315 if (cgraph_function_possibly_inlined_p (decl))
13316 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13318 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13321 if (DECL_DECLARED_INLINE_P (decl)
13322 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13323 add_AT_flag (subr_die, DW_AT_artificial, 1);
13325 equate_decl_number_to_die (decl, subr_die);
13327 else if (!DECL_EXTERNAL (decl))
13329 HOST_WIDE_INT cfa_fb_offset;
13331 if (!old_die || !get_AT (old_die, DW_AT_inline))
13332 equate_decl_number_to_die (decl, subr_die);
13334 if (!flag_reorder_blocks_and_partition)
13336 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13337 current_function_funcdef_no);
13338 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13339 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13340 current_function_funcdef_no);
13341 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13343 add_pubname (decl, subr_die);
13344 add_arange (decl, subr_die);
13347 { /* Do nothing for now; maybe need to duplicate die, one for
13348 hot section and one for cold section, then use the hot/cold
13349 section begin/end labels to generate the aranges... */
13351 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13352 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13353 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13354 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13356 add_pubname (decl, subr_die);
13357 add_arange (decl, subr_die);
13358 add_arange (decl, subr_die);
13362 #ifdef MIPS_DEBUGGING_INFO
13363 /* Add a reference to the FDE for this routine. */
13364 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13367 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13369 /* We define the "frame base" as the function's CFA. This is more
13370 convenient for several reasons: (1) It's stable across the prologue
13371 and epilogue, which makes it better than just a frame pointer,
13372 (2) With dwarf3, there exists a one-byte encoding that allows us
13373 to reference the .debug_frame data by proxy, but failing that,
13374 (3) We can at least reuse the code inspection and interpretation
13375 code that determines the CFA position at various points in the
13377 /* ??? Use some command-line or configury switch to enable the use
13378 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13379 consumers that understand it; fall back to "pure" dwarf2 and
13380 convert the CFA data into a location list. */
13382 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13383 if (list->dw_loc_next)
13384 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13386 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13389 /* Compute a displacement from the "steady-state frame pointer" to
13390 the CFA. The former is what all stack slots and argument slots
13391 will reference in the rtl; the later is what we've told the
13392 debugger about. We'll need to adjust all frame_base references
13393 by this displacement. */
13394 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13396 if (cfun->static_chain_decl)
13397 add_AT_location_description (subr_die, DW_AT_static_link,
13398 loc_descriptor_from_tree (cfun->static_chain_decl));
13401 /* Now output descriptions of the arguments for this function. This gets
13402 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13403 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13404 `...' at the end of the formal parameter list. In order to find out if
13405 there was a trailing ellipsis or not, we must instead look at the type
13406 associated with the FUNCTION_DECL. This will be a node of type
13407 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13408 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13409 an ellipsis at the end. */
13411 /* In the case where we are describing a mere function declaration, all we
13412 need to do here (and all we *can* do here) is to describe the *types* of
13413 its formal parameters. */
13414 if (debug_info_level <= DINFO_LEVEL_TERSE)
13416 else if (declaration)
13417 gen_formal_types_die (decl, subr_die);
13420 /* Generate DIEs to represent all known formal parameters. */
13421 tree arg_decls = DECL_ARGUMENTS (decl);
13424 /* When generating DIEs, generate the unspecified_parameters DIE
13425 instead if we come across the arg "__builtin_va_alist" */
13426 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13427 if (TREE_CODE (parm) == PARM_DECL)
13429 if (DECL_NAME (parm)
13430 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13431 "__builtin_va_alist"))
13432 gen_unspecified_parameters_die (parm, subr_die);
13434 gen_decl_die (parm, subr_die);
13437 /* Decide whether we need an unspecified_parameters DIE at the end.
13438 There are 2 more cases to do this for: 1) the ansi ... declaration -
13439 this is detectable when the end of the arg list is not a
13440 void_type_node 2) an unprototyped function declaration (not a
13441 definition). This just means that we have no info about the
13442 parameters at all. */
13443 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13444 if (fn_arg_types != NULL)
13446 /* This is the prototyped case, check for.... */
13447 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13448 gen_unspecified_parameters_die (decl, subr_die);
13450 else if (DECL_INITIAL (decl) == NULL_TREE)
13451 gen_unspecified_parameters_die (decl, subr_die);
13454 /* Output Dwarf info for all of the stuff within the body of the function
13455 (if it has one - it may be just a declaration). */
13456 outer_scope = DECL_INITIAL (decl);
13458 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13459 a function. This BLOCK actually represents the outermost binding contour
13460 for the function, i.e. the contour in which the function's formal
13461 parameters and labels get declared. Curiously, it appears that the front
13462 end doesn't actually put the PARM_DECL nodes for the current function onto
13463 the BLOCK_VARS list for this outer scope, but are strung off of the
13464 DECL_ARGUMENTS list for the function instead.
13466 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13467 the LABEL_DECL nodes for the function however, and we output DWARF info
13468 for those in decls_for_scope. Just within the `outer_scope' there will be
13469 a BLOCK node representing the function's outermost pair of curly braces,
13470 and any blocks used for the base and member initializers of a C++
13471 constructor function. */
13472 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13474 /* Emit a DW_TAG_variable DIE for a named return value. */
13475 if (DECL_NAME (DECL_RESULT (decl)))
13476 gen_decl_die (DECL_RESULT (decl), subr_die);
13478 current_function_has_inlines = 0;
13479 decls_for_scope (outer_scope, subr_die, 0);
13481 #if 0 && defined (MIPS_DEBUGGING_INFO)
13482 if (current_function_has_inlines)
13484 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13485 if (! comp_unit_has_inlines)
13487 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13488 comp_unit_has_inlines = 1;
13493 /* Add the calling convention attribute if requested. */
13494 add_calling_convention_attribute (subr_die, decl);
13498 /* Generate a DIE to represent a declared data object. */
13501 gen_variable_die (tree decl, dw_die_ref context_die)
13505 dw_die_ref var_die;
13506 tree origin = decl_ultimate_origin (decl);
13507 dw_die_ref old_die = lookup_decl_die (decl);
13508 int declaration = (DECL_EXTERNAL (decl)
13509 /* If DECL is COMDAT and has not actually been
13510 emitted, we cannot take its address; there
13511 might end up being no definition anywhere in
13512 the program. For example, consider the C++
13516 struct S { static const int i = 7; };
13521 int f() { return S<int>::i; }
13523 Here, S<int>::i is not DECL_EXTERNAL, but no
13524 definition is required, so the compiler will
13525 not emit a definition. */
13526 || (TREE_CODE (decl) == VAR_DECL
13527 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
13528 || class_or_namespace_scope_p (context_die));
13530 com_decl = fortran_common (decl, &off);
13532 /* Symbol in common gets emitted as a child of the common block, in the form
13535 ??? This creates a new common block die for every common block symbol.
13536 Better to share same common block die for all symbols in that block. */
13540 dw_die_ref com_die;
13541 const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
13542 dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl);
13544 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
13545 var_die = new_die (DW_TAG_common_block, context_die, decl);
13546 add_name_and_src_coords_attributes (var_die, field);
13547 add_AT_flag (var_die, DW_AT_external, 1);
13548 add_AT_loc (var_die, DW_AT_location, loc);
13549 com_die = new_die (DW_TAG_member, var_die, decl);
13550 add_name_and_src_coords_attributes (com_die, decl);
13551 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
13552 TREE_THIS_VOLATILE (decl), context_die);
13553 add_AT_loc (com_die, DW_AT_data_member_location,
13554 int_loc_descriptor (off));
13555 add_pubname_string (cnam, var_die); /* ??? needed? */
13559 var_die = new_die (DW_TAG_variable, context_die, decl);
13561 if (origin != NULL)
13562 add_abstract_origin_attribute (var_die, origin);
13564 /* Loop unrolling can create multiple blocks that refer to the same
13565 static variable, so we must test for the DW_AT_declaration flag.
13567 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13568 copy decls and set the DECL_ABSTRACT flag on them instead of
13571 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13573 ??? The declare_in_namespace support causes us to get two DIEs for one
13574 variable, both of which are declarations. We want to avoid considering
13575 one to be a specification, so we must test that this DIE is not a
13577 else if (old_die && TREE_STATIC (decl) && ! declaration
13578 && get_AT_flag (old_die, DW_AT_declaration) == 1)
13580 /* This is a definition of a C++ class level static. */
13581 add_AT_specification (var_die, old_die);
13582 if (DECL_NAME (decl))
13584 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13585 struct dwarf_file_data * file_index = lookup_filename (s.file);
13587 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13588 add_AT_file (var_die, DW_AT_decl_file, file_index);
13590 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13591 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
13596 tree type = TREE_TYPE (decl);
13597 if ((TREE_CODE (decl) == PARM_DECL
13598 || TREE_CODE (decl) == RESULT_DECL)
13599 && DECL_BY_REFERENCE (decl))
13600 type = TREE_TYPE (type);
13602 add_name_and_src_coords_attributes (var_die, decl);
13603 add_type_attribute (var_die, type, TREE_READONLY (decl),
13604 TREE_THIS_VOLATILE (decl), context_die);
13606 if (TREE_PUBLIC (decl))
13607 add_AT_flag (var_die, DW_AT_external, 1);
13609 if (DECL_ARTIFICIAL (decl))
13610 add_AT_flag (var_die, DW_AT_artificial, 1);
13612 if (TREE_PROTECTED (decl))
13613 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
13614 else if (TREE_PRIVATE (decl))
13615 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
13619 add_AT_flag (var_die, DW_AT_declaration, 1);
13621 if (DECL_ABSTRACT (decl) || declaration)
13622 equate_decl_number_to_die (decl, var_die);
13624 if (! declaration && ! DECL_ABSTRACT (decl))
13626 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
13627 add_pubname (decl, var_die);
13630 tree_add_const_value_attribute (var_die, decl);
13633 /* Generate a DIE to represent a label identifier. */
13636 gen_label_die (tree decl, dw_die_ref context_die)
13638 tree origin = decl_ultimate_origin (decl);
13639 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
13641 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13643 if (origin != NULL)
13644 add_abstract_origin_attribute (lbl_die, origin);
13646 add_name_and_src_coords_attributes (lbl_die, decl);
13648 if (DECL_ABSTRACT (decl))
13649 equate_decl_number_to_die (decl, lbl_die);
13652 insn = DECL_RTL_IF_SET (decl);
13654 /* Deleted labels are programmer specified labels which have been
13655 eliminated because of various optimizations. We still emit them
13656 here so that it is possible to put breakpoints on them. */
13660 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
13662 /* When optimization is enabled (via -O) some parts of the compiler
13663 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
13664 represent source-level labels which were explicitly declared by
13665 the user. This really shouldn't be happening though, so catch
13666 it if it ever does happen. */
13667 gcc_assert (!INSN_DELETED_P (insn));
13669 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
13670 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
13675 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
13676 attributes to the DIE for a block STMT, to describe where the inlined
13677 function was called from. This is similar to add_src_coords_attributes. */
13680 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
13682 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
13684 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
13685 add_AT_unsigned (die, DW_AT_call_line, s.line);
13689 /* If STMT's abstract origin is a function declaration and STMT's
13690 first subblock's abstract origin is the function's outermost block,
13691 then we're looking at the main entry point. */
13693 is_inlined_entry_point (const_tree stmt)
13697 if (!stmt || TREE_CODE (stmt) != BLOCK)
13700 decl = block_ultimate_origin (stmt);
13702 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
13705 block = BLOCK_SUBBLOCKS (stmt);
13709 if (TREE_CODE (block) != BLOCK)
13712 block = block_ultimate_origin (block);
13715 return block == DECL_INITIAL (decl);
13718 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
13719 Add low_pc and high_pc attributes to the DIE for a block STMT. */
13722 add_high_low_attributes (tree stmt, dw_die_ref die)
13724 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13726 if (BLOCK_FRAGMENT_CHAIN (stmt))
13730 if (is_inlined_entry_point (stmt))
13732 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13733 BLOCK_NUMBER (stmt));
13734 add_AT_lbl_id (die, DW_AT_entry_pc, label);
13737 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
13739 chain = BLOCK_FRAGMENT_CHAIN (stmt);
13742 add_ranges (chain);
13743 chain = BLOCK_FRAGMENT_CHAIN (chain);
13750 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13751 BLOCK_NUMBER (stmt));
13752 add_AT_lbl_id (die, DW_AT_low_pc, label);
13753 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
13754 BLOCK_NUMBER (stmt));
13755 add_AT_lbl_id (die, DW_AT_high_pc, label);
13759 /* Generate a DIE for a lexical block. */
13762 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
13764 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
13766 if (! BLOCK_ABSTRACT (stmt))
13767 add_high_low_attributes (stmt, stmt_die);
13769 decls_for_scope (stmt, stmt_die, depth);
13772 /* Generate a DIE for an inlined subprogram. */
13775 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
13777 tree decl = block_ultimate_origin (stmt);
13779 /* Emit info for the abstract instance first, if we haven't yet. We
13780 must emit this even if the block is abstract, otherwise when we
13781 emit the block below (or elsewhere), we may end up trying to emit
13782 a die whose origin die hasn't been emitted, and crashing. */
13783 dwarf2out_abstract_function (decl);
13785 if (! BLOCK_ABSTRACT (stmt))
13787 dw_die_ref subr_die
13788 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13790 add_abstract_origin_attribute (subr_die, decl);
13791 add_high_low_attributes (stmt, subr_die);
13792 add_call_src_coords_attributes (stmt, subr_die);
13794 decls_for_scope (stmt, subr_die, depth);
13795 current_function_has_inlines = 1;
13798 /* We may get here if we're the outer block of function A that was
13799 inlined into function B that was inlined into function C. When
13800 generating debugging info for C, dwarf2out_abstract_function(B)
13801 would mark all inlined blocks as abstract, including this one.
13802 So, we wouldn't (and shouldn't) expect labels to be generated
13803 for this one. Instead, just emit debugging info for
13804 declarations within the block. This is particularly important
13805 in the case of initializers of arguments passed from B to us:
13806 if they're statement expressions containing declarations, we
13807 wouldn't generate dies for their abstract variables, and then,
13808 when generating dies for the real variables, we'd die (pun
13810 gen_lexical_block_die (stmt, context_die, depth);
13813 /* Generate a DIE for a field in a record, or structure. */
13816 gen_field_die (tree decl, dw_die_ref context_die)
13818 dw_die_ref decl_die;
13820 if (TREE_TYPE (decl) == error_mark_node)
13823 decl_die = new_die (DW_TAG_member, context_die, decl);
13824 add_name_and_src_coords_attributes (decl_die, decl);
13825 add_type_attribute (decl_die, member_declared_type (decl),
13826 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13829 if (DECL_BIT_FIELD_TYPE (decl))
13831 add_byte_size_attribute (decl_die, decl);
13832 add_bit_size_attribute (decl_die, decl);
13833 add_bit_offset_attribute (decl_die, decl);
13836 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13837 add_data_member_location_attribute (decl_die, decl);
13839 if (DECL_ARTIFICIAL (decl))
13840 add_AT_flag (decl_die, DW_AT_artificial, 1);
13842 if (TREE_PROTECTED (decl))
13843 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13844 else if (TREE_PRIVATE (decl))
13845 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13847 /* Equate decl number to die, so that we can look up this decl later on. */
13848 equate_decl_number_to_die (decl, decl_die);
13852 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13853 Use modified_type_die instead.
13854 We keep this code here just in case these types of DIEs may be needed to
13855 represent certain things in other languages (e.g. Pascal) someday. */
13858 gen_pointer_type_die (tree type, dw_die_ref context_die)
13861 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13863 equate_type_number_to_die (type, ptr_die);
13864 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13865 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13868 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13869 Use modified_type_die instead.
13870 We keep this code here just in case these types of DIEs may be needed to
13871 represent certain things in other languages (e.g. Pascal) someday. */
13874 gen_reference_type_die (tree type, dw_die_ref context_die)
13877 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13879 equate_type_number_to_die (type, ref_die);
13880 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13881 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13885 /* Generate a DIE for a pointer to a member type. */
13888 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
13891 = new_die (DW_TAG_ptr_to_member_type,
13892 scope_die_for (type, context_die), type);
13894 equate_type_number_to_die (type, ptr_die);
13895 add_AT_die_ref (ptr_die, DW_AT_containing_type,
13896 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
13897 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13900 /* Generate the DIE for the compilation unit. */
13903 gen_compile_unit_die (const char *filename)
13906 char producer[250];
13907 const char *language_string = lang_hooks.name;
13910 die = new_die (DW_TAG_compile_unit, NULL, NULL);
13914 add_name_attribute (die, filename);
13915 /* Don't add cwd for <built-in>. */
13916 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
13917 add_comp_dir_attribute (die);
13920 sprintf (producer, "%s %s", language_string, version_string);
13922 #ifdef MIPS_DEBUGGING_INFO
13923 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13924 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13925 not appear in the producer string, the debugger reaches the conclusion
13926 that the object file is stripped and has no debugging information.
13927 To get the MIPS/SGI debugger to believe that there is debugging
13928 information in the object file, we add a -g to the producer string. */
13929 if (debug_info_level > DINFO_LEVEL_TERSE)
13930 strcat (producer, " -g");
13933 add_AT_string (die, DW_AT_producer, producer);
13935 if (strcmp (language_string, "GNU C++") == 0)
13936 language = DW_LANG_C_plus_plus;
13937 else if (strcmp (language_string, "GNU Ada") == 0)
13938 language = DW_LANG_Ada95;
13939 else if (strcmp (language_string, "GNU F77") == 0)
13940 language = DW_LANG_Fortran77;
13941 else if (strcmp (language_string, "GNU Fortran") == 0)
13942 language = DW_LANG_Fortran95;
13943 else if (strcmp (language_string, "GNU Pascal") == 0)
13944 language = DW_LANG_Pascal83;
13945 else if (strcmp (language_string, "GNU Java") == 0)
13946 language = DW_LANG_Java;
13947 else if (strcmp (language_string, "GNU Objective-C") == 0)
13948 language = DW_LANG_ObjC;
13949 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13950 language = DW_LANG_ObjC_plus_plus;
13952 language = DW_LANG_C89;
13954 add_AT_unsigned (die, DW_AT_language, language);
13958 /* Generate the DIE for a base class. */
13961 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13963 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13965 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13966 add_data_member_location_attribute (die, binfo);
13968 if (BINFO_VIRTUAL_P (binfo))
13969 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13971 if (access == access_public_node)
13972 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13973 else if (access == access_protected_node)
13974 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13977 /* Generate a DIE for a class member. */
13980 gen_member_die (tree type, dw_die_ref context_die)
13983 tree binfo = TYPE_BINFO (type);
13986 /* If this is not an incomplete type, output descriptions of each of its
13987 members. Note that as we output the DIEs necessary to represent the
13988 members of this record or union type, we will also be trying to output
13989 DIEs to represent the *types* of those members. However the `type'
13990 function (above) will specifically avoid generating type DIEs for member
13991 types *within* the list of member DIEs for this (containing) type except
13992 for those types (of members) which are explicitly marked as also being
13993 members of this (containing) type themselves. The g++ front- end can
13994 force any given type to be treated as a member of some other (containing)
13995 type by setting the TYPE_CONTEXT of the given (member) type to point to
13996 the TREE node representing the appropriate (containing) type. */
13998 /* First output info about the base classes. */
14001 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14005 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14006 gen_inheritance_die (base,
14007 (accesses ? VEC_index (tree, accesses, i)
14008 : access_public_node), context_die);
14011 /* Now output info about the data members and type members. */
14012 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14014 /* If we thought we were generating minimal debug info for TYPE
14015 and then changed our minds, some of the member declarations
14016 may have already been defined. Don't define them again, but
14017 do put them in the right order. */
14019 child = lookup_decl_die (member);
14021 splice_child_die (context_die, child);
14023 gen_decl_die (member, context_die);
14026 /* Now output info about the function members (if any). */
14027 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14029 /* Don't include clones in the member list. */
14030 if (DECL_ABSTRACT_ORIGIN (member))
14033 child = lookup_decl_die (member);
14035 splice_child_die (context_die, child);
14037 gen_decl_die (member, context_die);
14041 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14042 is set, we pretend that the type was never defined, so we only get the
14043 member DIEs needed by later specification DIEs. */
14046 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14047 enum debug_info_usage usage)
14049 dw_die_ref type_die = lookup_type_die (type);
14050 dw_die_ref scope_die = 0;
14052 int complete = (TYPE_SIZE (type)
14053 && (! TYPE_STUB_DECL (type)
14054 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14055 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14056 complete = complete && should_emit_struct_debug (type, usage);
14058 if (type_die && ! complete)
14061 if (TYPE_CONTEXT (type) != NULL_TREE
14062 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14063 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14066 scope_die = scope_die_for (type, context_die);
14068 if (! type_die || (nested && scope_die == comp_unit_die))
14069 /* First occurrence of type or toplevel definition of nested class. */
14071 dw_die_ref old_die = type_die;
14073 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14074 ? record_type_tag (type) : DW_TAG_union_type,
14076 equate_type_number_to_die (type, type_die);
14078 add_AT_specification (type_die, old_die);
14080 add_name_attribute (type_die, type_tag (type));
14083 remove_AT (type_die, DW_AT_declaration);
14085 /* If this type has been completed, then give it a byte_size attribute and
14086 then give a list of members. */
14087 if (complete && !ns_decl)
14089 /* Prevent infinite recursion in cases where the type of some member of
14090 this type is expressed in terms of this type itself. */
14091 TREE_ASM_WRITTEN (type) = 1;
14092 add_byte_size_attribute (type_die, type);
14093 if (TYPE_STUB_DECL (type) != NULL_TREE)
14094 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14096 /* If the first reference to this type was as the return type of an
14097 inline function, then it may not have a parent. Fix this now. */
14098 if (type_die->die_parent == NULL)
14099 add_child_die (scope_die, type_die);
14101 push_decl_scope (type);
14102 gen_member_die (type, type_die);
14105 /* GNU extension: Record what type our vtable lives in. */
14106 if (TYPE_VFIELD (type))
14108 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14110 gen_type_die (vtype, context_die);
14111 add_AT_die_ref (type_die, DW_AT_containing_type,
14112 lookup_type_die (vtype));
14117 add_AT_flag (type_die, DW_AT_declaration, 1);
14119 /* We don't need to do this for function-local types. */
14120 if (TYPE_STUB_DECL (type)
14121 && ! decl_function_context (TYPE_STUB_DECL (type)))
14122 VEC_safe_push (tree, gc, incomplete_types, type);
14125 if (get_AT (type_die, DW_AT_name))
14126 add_pubtype (type, type_die);
14129 /* Generate a DIE for a subroutine _type_. */
14132 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14134 tree return_type = TREE_TYPE (type);
14135 dw_die_ref subr_die
14136 = new_die (DW_TAG_subroutine_type,
14137 scope_die_for (type, context_die), type);
14139 equate_type_number_to_die (type, subr_die);
14140 add_prototyped_attribute (subr_die, type);
14141 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14142 gen_formal_types_die (type, subr_die);
14144 if (get_AT (subr_die, DW_AT_name))
14145 add_pubtype (type, subr_die);
14148 /* Generate a DIE for a type definition. */
14151 gen_typedef_die (tree decl, dw_die_ref context_die)
14153 dw_die_ref type_die;
14156 if (TREE_ASM_WRITTEN (decl))
14159 TREE_ASM_WRITTEN (decl) = 1;
14160 type_die = new_die (DW_TAG_typedef, context_die, decl);
14161 origin = decl_ultimate_origin (decl);
14162 if (origin != NULL)
14163 add_abstract_origin_attribute (type_die, origin);
14168 add_name_and_src_coords_attributes (type_die, decl);
14169 if (DECL_ORIGINAL_TYPE (decl))
14171 type = DECL_ORIGINAL_TYPE (decl);
14173 gcc_assert (type != TREE_TYPE (decl));
14174 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14177 type = TREE_TYPE (decl);
14179 add_type_attribute (type_die, type, TREE_READONLY (decl),
14180 TREE_THIS_VOLATILE (decl), context_die);
14183 if (DECL_ABSTRACT (decl))
14184 equate_decl_number_to_die (decl, type_die);
14186 if (get_AT (type_die, DW_AT_name))
14187 add_pubtype (decl, type_die);
14190 /* Generate a type description DIE. */
14193 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14194 enum debug_info_usage usage)
14197 struct array_descr_info info;
14199 if (type == NULL_TREE || type == error_mark_node)
14202 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14203 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14205 if (TREE_ASM_WRITTEN (type))
14208 /* Prevent broken recursion; we can't hand off to the same type. */
14209 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14211 TREE_ASM_WRITTEN (type) = 1;
14212 gen_decl_die (TYPE_NAME (type), context_die);
14216 /* If this is an array type with hidden descriptor, handle it first. */
14217 if (!TREE_ASM_WRITTEN (type)
14218 && lang_hooks.types.get_array_descr_info
14219 && lang_hooks.types.get_array_descr_info (type, &info))
14221 gen_descr_array_type_die (type, &info, context_die);
14222 TREE_ASM_WRITTEN (type) = 1;
14226 /* We are going to output a DIE to represent the unqualified version
14227 of this type (i.e. without any const or volatile qualifiers) so
14228 get the main variant (i.e. the unqualified version) of this type
14229 now. (Vectors are special because the debugging info is in the
14230 cloned type itself). */
14231 if (TREE_CODE (type) != VECTOR_TYPE)
14232 type = type_main_variant (type);
14234 if (TREE_ASM_WRITTEN (type))
14237 switch (TREE_CODE (type))
14243 case REFERENCE_TYPE:
14244 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14245 ensures that the gen_type_die recursion will terminate even if the
14246 type is recursive. Recursive types are possible in Ada. */
14247 /* ??? We could perhaps do this for all types before the switch
14249 TREE_ASM_WRITTEN (type) = 1;
14251 /* For these types, all that is required is that we output a DIE (or a
14252 set of DIEs) to represent the "basis" type. */
14253 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14254 DINFO_USAGE_IND_USE);
14258 /* This code is used for C++ pointer-to-data-member types.
14259 Output a description of the relevant class type. */
14260 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
14261 DINFO_USAGE_IND_USE);
14263 /* Output a description of the type of the object pointed to. */
14264 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14265 DINFO_USAGE_IND_USE);
14267 /* Now output a DIE to represent this pointer-to-data-member type
14269 gen_ptr_to_mbr_type_die (type, context_die);
14272 case FUNCTION_TYPE:
14273 /* Force out return type (in case it wasn't forced out already). */
14274 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14275 DINFO_USAGE_DIR_USE);
14276 gen_subroutine_type_die (type, context_die);
14280 /* Force out return type (in case it wasn't forced out already). */
14281 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14282 DINFO_USAGE_DIR_USE);
14283 gen_subroutine_type_die (type, context_die);
14287 gen_array_type_die (type, context_die);
14291 gen_array_type_die (type, context_die);
14294 case ENUMERAL_TYPE:
14297 case QUAL_UNION_TYPE:
14298 /* If this is a nested type whose containing class hasn't been written
14299 out yet, writing it out will cover this one, too. This does not apply
14300 to instantiations of member class templates; they need to be added to
14301 the containing class as they are generated. FIXME: This hurts the
14302 idea of combining type decls from multiple TUs, since we can't predict
14303 what set of template instantiations we'll get. */
14304 if (TYPE_CONTEXT (type)
14305 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14306 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
14308 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
14310 if (TREE_ASM_WRITTEN (type))
14313 /* If that failed, attach ourselves to the stub. */
14314 push_decl_scope (TYPE_CONTEXT (type));
14315 context_die = lookup_type_die (TYPE_CONTEXT (type));
14320 declare_in_namespace (type, context_die);
14324 if (TREE_CODE (type) == ENUMERAL_TYPE)
14326 /* This might have been written out by the call to
14327 declare_in_namespace. */
14328 if (!TREE_ASM_WRITTEN (type))
14329 gen_enumeration_type_die (type, context_die);
14332 gen_struct_or_union_type_die (type, context_die, usage);
14337 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14338 it up if it is ever completed. gen_*_type_die will set it for us
14339 when appropriate. */
14345 case FIXED_POINT_TYPE:
14348 /* No DIEs needed for fundamental types. */
14352 /* No Dwarf representation currently defined. */
14356 gcc_unreachable ();
14359 TREE_ASM_WRITTEN (type) = 1;
14363 gen_type_die (tree type, dw_die_ref context_die)
14365 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14368 /* Generate a DIE for a tagged type instantiation. */
14371 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
14373 if (type == NULL_TREE || type == error_mark_node)
14376 /* We are going to output a DIE to represent the unqualified version of
14377 this type (i.e. without any const or volatile qualifiers) so make sure
14378 that we have the main variant (i.e. the unqualified version) of this
14380 gcc_assert (type == type_main_variant (type));
14382 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14383 an instance of an unresolved type. */
14385 switch (TREE_CODE (type))
14390 case ENUMERAL_TYPE:
14391 gen_inlined_enumeration_type_die (type, context_die);
14395 gen_inlined_structure_type_die (type, context_die);
14399 case QUAL_UNION_TYPE:
14400 gen_inlined_union_type_die (type, context_die);
14404 gcc_unreachable ();
14408 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14409 things which are local to the given block. */
14412 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14414 int must_output_die = 0;
14417 enum tree_code origin_code;
14419 /* Ignore blocks that are NULL. */
14420 if (stmt == NULL_TREE)
14423 /* If the block is one fragment of a non-contiguous block, do not
14424 process the variables, since they will have been done by the
14425 origin block. Do process subblocks. */
14426 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14430 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14431 gen_block_die (sub, context_die, depth + 1);
14436 /* Determine the "ultimate origin" of this block. This block may be an
14437 inlined instance of an inlined instance of inline function, so we have
14438 to trace all of the way back through the origin chain to find out what
14439 sort of node actually served as the original seed for the creation of
14440 the current block. */
14441 origin = block_ultimate_origin (stmt);
14442 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
14444 /* Determine if we need to output any Dwarf DIEs at all to represent this
14446 if (origin_code == FUNCTION_DECL)
14447 /* The outer scopes for inlinings *must* always be represented. We
14448 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14449 must_output_die = 1;
14452 /* In the case where the current block represents an inlining of the
14453 "body block" of an inline function, we must *NOT* output any DIE for
14454 this block because we have already output a DIE to represent the whole
14455 inlined function scope and the "body block" of any function doesn't
14456 really represent a different scope according to ANSI C rules. So we
14457 check here to make sure that this block does not represent a "body
14458 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14459 if (! is_body_block (origin ? origin : stmt))
14461 /* Determine if this block directly contains any "significant"
14462 local declarations which we will need to output DIEs for. */
14463 if (debug_info_level > DINFO_LEVEL_TERSE)
14464 /* We are not in terse mode so *any* local declaration counts
14465 as being a "significant" one. */
14466 must_output_die = (BLOCK_VARS (stmt) != NULL
14467 && (TREE_USED (stmt)
14468 || TREE_ASM_WRITTEN (stmt)
14469 || BLOCK_ABSTRACT (stmt)));
14471 /* We are in terse mode, so only local (nested) function
14472 definitions count as "significant" local declarations. */
14473 for (decl = BLOCK_VARS (stmt);
14474 decl != NULL; decl = TREE_CHAIN (decl))
14475 if (TREE_CODE (decl) == FUNCTION_DECL
14476 && DECL_INITIAL (decl))
14478 must_output_die = 1;
14484 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14485 DIE for any block which contains no significant local declarations at
14486 all. Rather, in such cases we just call `decls_for_scope' so that any
14487 needed Dwarf info for any sub-blocks will get properly generated. Note
14488 that in terse mode, our definition of what constitutes a "significant"
14489 local declaration gets restricted to include only inlined function
14490 instances and local (nested) function definitions. */
14491 if (must_output_die)
14493 if (origin_code == FUNCTION_DECL)
14494 gen_inlined_subroutine_die (stmt, context_die, depth);
14496 gen_lexical_block_die (stmt, context_die, depth);
14499 decls_for_scope (stmt, context_die, depth);
14502 /* Generate all of the decls declared within a given scope and (recursively)
14503 all of its sub-blocks. */
14506 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
14511 /* Ignore NULL blocks. */
14512 if (stmt == NULL_TREE)
14515 if (TREE_USED (stmt))
14517 /* Output the DIEs to represent all of the data objects and typedefs
14518 declared directly within this block but not within any nested
14519 sub-blocks. Also, nested function and tag DIEs have been
14520 generated with a parent of NULL; fix that up now. */
14521 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
14525 if (TREE_CODE (decl) == FUNCTION_DECL)
14526 die = lookup_decl_die (decl);
14527 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
14528 die = lookup_type_die (TREE_TYPE (decl));
14532 if (die != NULL && die->die_parent == NULL)
14533 add_child_die (context_die, die);
14534 /* Do not produce debug information for static variables since
14535 these might be optimized out. We are called for these later
14536 in varpool_analyze_pending_decls.
14538 But *do* produce it for Fortran COMMON variables because,
14539 even though they are static, their names can differ depending
14540 on the scope, which we need to preserve. */
14541 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
14542 && !(is_fortran () && TREE_PUBLIC (decl)))
14545 gen_decl_die (decl, context_die);
14549 /* If we're at -g1, we're not interested in subblocks. */
14550 if (debug_info_level <= DINFO_LEVEL_TERSE)
14553 /* Output the DIEs to represent all sub-blocks (and the items declared
14554 therein) of this block. */
14555 for (subblocks = BLOCK_SUBBLOCKS (stmt);
14557 subblocks = BLOCK_CHAIN (subblocks))
14558 gen_block_die (subblocks, context_die, depth + 1);
14561 /* Is this a typedef we can avoid emitting? */
14564 is_redundant_typedef (const_tree decl)
14566 if (TYPE_DECL_IS_STUB (decl))
14569 if (DECL_ARTIFICIAL (decl)
14570 && DECL_CONTEXT (decl)
14571 && is_tagged_type (DECL_CONTEXT (decl))
14572 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
14573 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
14574 /* Also ignore the artificial member typedef for the class name. */
14580 /* Returns the DIE for a context. */
14582 static inline dw_die_ref
14583 get_context_die (tree context)
14587 /* Find die that represents this context. */
14588 if (TYPE_P (context))
14589 return force_type_die (context);
14591 return force_decl_die (context);
14593 return comp_unit_die;
14596 /* Returns the DIE for decl. A DIE will always be returned. */
14599 force_decl_die (tree decl)
14601 dw_die_ref decl_die;
14602 unsigned saved_external_flag;
14603 tree save_fn = NULL_TREE;
14604 decl_die = lookup_decl_die (decl);
14607 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
14609 decl_die = lookup_decl_die (decl);
14613 switch (TREE_CODE (decl))
14615 case FUNCTION_DECL:
14616 /* Clear current_function_decl, so that gen_subprogram_die thinks
14617 that this is a declaration. At this point, we just want to force
14618 declaration die. */
14619 save_fn = current_function_decl;
14620 current_function_decl = NULL_TREE;
14621 gen_subprogram_die (decl, context_die);
14622 current_function_decl = save_fn;
14626 /* Set external flag to force declaration die. Restore it after
14627 gen_decl_die() call. */
14628 saved_external_flag = DECL_EXTERNAL (decl);
14629 DECL_EXTERNAL (decl) = 1;
14630 gen_decl_die (decl, context_die);
14631 DECL_EXTERNAL (decl) = saved_external_flag;
14634 case NAMESPACE_DECL:
14635 dwarf2out_decl (decl);
14639 gcc_unreachable ();
14642 /* We should be able to find the DIE now. */
14644 decl_die = lookup_decl_die (decl);
14645 gcc_assert (decl_die);
14651 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
14652 always returned. */
14655 force_type_die (tree type)
14657 dw_die_ref type_die;
14659 type_die = lookup_type_die (type);
14662 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
14664 type_die = modified_type_die (type, TYPE_READONLY (type),
14665 TYPE_VOLATILE (type), context_die);
14666 gcc_assert (type_die);
14671 /* Force out any required namespaces to be able to output DECL,
14672 and return the new context_die for it, if it's changed. */
14675 setup_namespace_context (tree thing, dw_die_ref context_die)
14677 tree context = (DECL_P (thing)
14678 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
14679 if (context && TREE_CODE (context) == NAMESPACE_DECL)
14680 /* Force out the namespace. */
14681 context_die = force_decl_die (context);
14683 return context_die;
14686 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
14687 type) within its namespace, if appropriate.
14689 For compatibility with older debuggers, namespace DIEs only contain
14690 declarations; all definitions are emitted at CU scope. */
14693 declare_in_namespace (tree thing, dw_die_ref context_die)
14695 dw_die_ref ns_context;
14697 if (debug_info_level <= DINFO_LEVEL_TERSE)
14700 /* If this decl is from an inlined function, then don't try to emit it in its
14701 namespace, as we will get confused. It would have already been emitted
14702 when the abstract instance of the inline function was emitted anyways. */
14703 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
14706 ns_context = setup_namespace_context (thing, context_die);
14708 if (ns_context != context_die)
14710 if (DECL_P (thing))
14711 gen_decl_die (thing, ns_context);
14713 gen_type_die (thing, ns_context);
14717 /* Generate a DIE for a namespace or namespace alias. */
14720 gen_namespace_die (tree decl)
14722 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
14724 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
14725 they are an alias of. */
14726 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
14728 /* Output a real namespace. */
14729 dw_die_ref namespace_die
14730 = new_die (DW_TAG_namespace, context_die, decl);
14731 add_name_and_src_coords_attributes (namespace_die, decl);
14732 equate_decl_number_to_die (decl, namespace_die);
14736 /* Output a namespace alias. */
14738 /* Force out the namespace we are an alias of, if necessary. */
14739 dw_die_ref origin_die
14740 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
14742 /* Now create the namespace alias DIE. */
14743 dw_die_ref namespace_die
14744 = new_die (DW_TAG_imported_declaration, context_die, decl);
14745 add_name_and_src_coords_attributes (namespace_die, decl);
14746 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
14747 equate_decl_number_to_die (decl, namespace_die);
14751 /* Generate Dwarf debug information for a decl described by DECL. */
14754 gen_decl_die (tree decl, dw_die_ref context_die)
14758 if (DECL_P (decl) && DECL_IGNORED_P (decl))
14761 switch (TREE_CODE (decl))
14767 /* The individual enumerators of an enum type get output when we output
14768 the Dwarf representation of the relevant enum type itself. */
14771 case FUNCTION_DECL:
14772 /* Don't output any DIEs to represent mere function declarations,
14773 unless they are class members or explicit block externs. */
14774 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
14775 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
14780 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14781 on local redeclarations of global functions. That seems broken. */
14782 if (current_function_decl != decl)
14783 /* This is only a declaration. */;
14786 /* If we're emitting a clone, emit info for the abstract instance. */
14787 if (DECL_ORIGIN (decl) != decl)
14788 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14790 /* If we're emitting an out-of-line copy of an inline function,
14791 emit info for the abstract instance and set up to refer to it. */
14792 else if (cgraph_function_possibly_inlined_p (decl)
14793 && ! DECL_ABSTRACT (decl)
14794 && ! class_or_namespace_scope_p (context_die)
14795 /* dwarf2out_abstract_function won't emit a die if this is just
14796 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14797 that case, because that works only if we have a die. */
14798 && DECL_INITIAL (decl) != NULL_TREE)
14800 dwarf2out_abstract_function (decl);
14801 set_decl_origin_self (decl);
14804 /* Otherwise we're emitting the primary DIE for this decl. */
14805 else if (debug_info_level > DINFO_LEVEL_TERSE)
14807 /* Before we describe the FUNCTION_DECL itself, make sure that we
14808 have described its return type. */
14809 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14811 /* And its virtual context. */
14812 if (DECL_VINDEX (decl) != NULL_TREE)
14813 gen_type_die (DECL_CONTEXT (decl), context_die);
14815 /* And its containing type. */
14816 origin = decl_class_context (decl);
14817 if (origin != NULL_TREE)
14818 gen_type_die_for_member (origin, decl, context_die);
14820 /* And its containing namespace. */
14821 declare_in_namespace (decl, context_die);
14824 /* Now output a DIE to represent the function itself. */
14825 gen_subprogram_die (decl, context_die);
14829 /* If we are in terse mode, don't generate any DIEs to represent any
14830 actual typedefs. */
14831 if (debug_info_level <= DINFO_LEVEL_TERSE)
14834 /* In the special case of a TYPE_DECL node representing the declaration
14835 of some type tag, if the given TYPE_DECL is marked as having been
14836 instantiated from some other (original) TYPE_DECL node (e.g. one which
14837 was generated within the original definition of an inline function) we
14838 have to generate a special (abbreviated) DW_TAG_structure_type,
14839 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14840 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14841 && is_tagged_type (TREE_TYPE (decl)))
14843 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14847 if (is_redundant_typedef (decl))
14848 gen_type_die (TREE_TYPE (decl), context_die);
14850 /* Output a DIE to represent the typedef itself. */
14851 gen_typedef_die (decl, context_die);
14855 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14856 gen_label_die (decl, context_die);
14861 /* If we are in terse mode, don't generate any DIEs to represent any
14862 variable declarations or definitions. */
14863 if (debug_info_level <= DINFO_LEVEL_TERSE)
14866 /* If this is the global definition of the Fortran COMMON block, we don't
14867 need to do anything. Syntactically, the block itself has no identity,
14868 just its constituent identifiers. */
14869 if (TREE_CODE (decl) == VAR_DECL
14870 && TREE_PUBLIC (decl)
14871 && TREE_STATIC (decl)
14873 && !DECL_HAS_VALUE_EXPR_P (decl))
14876 /* Output any DIEs that are needed to specify the type of this data
14878 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14879 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14881 gen_type_die (TREE_TYPE (decl), context_die);
14883 /* And its containing type. */
14884 origin = decl_class_context (decl);
14885 if (origin != NULL_TREE)
14886 gen_type_die_for_member (origin, decl, context_die);
14888 /* And its containing namespace. */
14889 declare_in_namespace (decl, context_die);
14891 /* Now output the DIE to represent the data object itself. This gets
14892 complicated because of the possibility that the VAR_DECL really
14893 represents an inlined instance of a formal parameter for an inline
14895 origin = decl_ultimate_origin (decl);
14896 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
14897 gen_formal_parameter_die (decl, context_die);
14899 gen_variable_die (decl, context_die);
14903 /* Ignore the nameless fields that are used to skip bits but handle C++
14904 anonymous unions and structs. */
14905 if (DECL_NAME (decl) != NULL_TREE
14906 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
14907 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
14909 gen_type_die (member_declared_type (decl), context_die);
14910 gen_field_die (decl, context_die);
14915 if (DECL_BY_REFERENCE (decl))
14916 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14918 gen_type_die (TREE_TYPE (decl), context_die);
14919 gen_formal_parameter_die (decl, context_die);
14922 case NAMESPACE_DECL:
14923 gen_namespace_die (decl);
14927 /* Probably some frontend-internal decl. Assume we don't care. */
14928 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
14933 /* Output debug information for global decl DECL. Called from toplev.c after
14934 compilation proper has finished. */
14937 dwarf2out_global_decl (tree decl)
14939 /* Output DWARF2 information for file-scope tentative data object
14940 declarations, file-scope (extern) function declarations (which
14941 had no corresponding body) and file-scope tagged type declarations
14942 and definitions which have not yet been forced out.
14944 Ignore the global decl of any Fortran COMMON blocks which also
14945 wind up here though they have already been described in the local
14946 scope for the procedures using them. */
14947 if (TREE_CODE (decl) == VAR_DECL
14948 && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ())
14951 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14952 dwarf2out_decl (decl);
14955 /* Output debug information for type decl DECL. Called from toplev.c
14956 and from language front ends (to record built-in types). */
14958 dwarf2out_type_decl (tree decl, int local)
14961 dwarf2out_decl (decl);
14964 /* Output debug information for imported module or decl. */
14967 dwarf2out_imported_module_or_decl (tree decl, tree context)
14969 dw_die_ref imported_die, at_import_die;
14970 dw_die_ref scope_die;
14971 expanded_location xloc;
14973 if (debug_info_level <= DINFO_LEVEL_TERSE)
14978 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14979 We need decl DIE for reference and scope die. First, get DIE for the decl
14982 /* Get the scope die for decl context. Use comp_unit_die for global module
14983 or decl. If die is not found for non globals, force new die. */
14985 && TYPE_P (context)
14986 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14988 scope_die = get_context_die (context);
14990 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14991 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14993 if (is_base_type (TREE_TYPE (decl)))
14994 at_import_die = base_type_die (TREE_TYPE (decl));
14996 at_import_die = force_type_die (TREE_TYPE (decl));
14997 /* For namespace N { typedef void T; } using N::T; base_type_die
14998 returns NULL, but DW_TAG_imported_declaration requires
14999 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15000 if (!at_import_die)
15002 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15003 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15004 at_import_die = lookup_type_die (TREE_TYPE (decl));
15005 gcc_assert (at_import_die);
15010 at_import_die = lookup_decl_die (decl);
15011 if (!at_import_die)
15013 /* If we're trying to avoid duplicate debug info, we may not have
15014 emitted the member decl for this field. Emit it now. */
15015 if (TREE_CODE (decl) == FIELD_DECL)
15017 tree type = DECL_CONTEXT (decl);
15019 if (TYPE_CONTEXT (type)
15020 && TYPE_P (TYPE_CONTEXT (type))
15021 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15022 DINFO_USAGE_DIR_USE))
15024 gen_type_die_for_member (type, decl,
15025 get_context_die (TYPE_CONTEXT (type)));
15027 at_import_die = force_decl_die (decl);
15031 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15032 if (TREE_CODE (decl) == NAMESPACE_DECL)
15033 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
15035 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
15037 xloc = expand_location (input_location);
15038 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15039 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15040 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15043 /* Write the debugging output for DECL. */
15046 dwarf2out_decl (tree decl)
15048 dw_die_ref context_die = comp_unit_die;
15050 switch (TREE_CODE (decl))
15055 case FUNCTION_DECL:
15056 /* What we would really like to do here is to filter out all mere
15057 file-scope declarations of file-scope functions which are never
15058 referenced later within this translation unit (and keep all of ones
15059 that *are* referenced later on) but we aren't clairvoyant, so we have
15060 no idea which functions will be referenced in the future (i.e. later
15061 on within the current translation unit). So here we just ignore all
15062 file-scope function declarations which are not also definitions. If
15063 and when the debugger needs to know something about these functions,
15064 it will have to hunt around and find the DWARF information associated
15065 with the definition of the function.
15067 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15068 nodes represent definitions and which ones represent mere
15069 declarations. We have to check DECL_INITIAL instead. That's because
15070 the C front-end supports some weird semantics for "extern inline"
15071 function definitions. These can get inlined within the current
15072 translation unit (and thus, we need to generate Dwarf info for their
15073 abstract instances so that the Dwarf info for the concrete inlined
15074 instances can have something to refer to) but the compiler never
15075 generates any out-of-lines instances of such things (despite the fact
15076 that they *are* definitions).
15078 The important point is that the C front-end marks these "extern
15079 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15080 them anyway. Note that the C++ front-end also plays some similar games
15081 for inline function definitions appearing within include files which
15082 also contain `#pragma interface' pragmas. */
15083 if (DECL_INITIAL (decl) == NULL_TREE)
15086 /* If we're a nested function, initially use a parent of NULL; if we're
15087 a plain function, this will be fixed up in decls_for_scope. If
15088 we're a method, it will be ignored, since we already have a DIE. */
15089 if (decl_function_context (decl)
15090 /* But if we're in terse mode, we don't care about scope. */
15091 && debug_info_level > DINFO_LEVEL_TERSE)
15092 context_die = NULL;
15096 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15097 declaration and if the declaration was never even referenced from
15098 within this entire compilation unit. We suppress these DIEs in
15099 order to save space in the .debug section (by eliminating entries
15100 which are probably useless). Note that we must not suppress
15101 block-local extern declarations (whether used or not) because that
15102 would screw-up the debugger's name lookup mechanism and cause it to
15103 miss things which really ought to be in scope at a given point. */
15104 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15107 /* For local statics lookup proper context die. */
15108 if (TREE_STATIC (decl) && decl_function_context (decl))
15109 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15111 /* If we are in terse mode, don't generate any DIEs to represent any
15112 variable declarations or definitions. */
15113 if (debug_info_level <= DINFO_LEVEL_TERSE)
15117 case NAMESPACE_DECL:
15118 if (debug_info_level <= DINFO_LEVEL_TERSE)
15120 if (lookup_decl_die (decl) != NULL)
15125 /* Don't emit stubs for types unless they are needed by other DIEs. */
15126 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15129 /* Don't bother trying to generate any DIEs to represent any of the
15130 normal built-in types for the language we are compiling. */
15131 if (DECL_IS_BUILTIN (decl))
15133 /* OK, we need to generate one for `bool' so GDB knows what type
15134 comparisons have. */
15136 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15137 && ! DECL_IGNORED_P (decl))
15138 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15143 /* If we are in terse mode, don't generate any DIEs for types. */
15144 if (debug_info_level <= DINFO_LEVEL_TERSE)
15147 /* If we're a function-scope tag, initially use a parent of NULL;
15148 this will be fixed up in decls_for_scope. */
15149 if (decl_function_context (decl))
15150 context_die = NULL;
15158 gen_decl_die (decl, context_die);
15161 /* Output a marker (i.e. a label) for the beginning of the generated code for
15162 a lexical block. */
15165 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15166 unsigned int blocknum)
15168 switch_to_section (current_function_section ());
15169 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15172 /* Output a marker (i.e. a label) for the end of the generated code for a
15176 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15178 switch_to_section (current_function_section ());
15179 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15182 /* Returns nonzero if it is appropriate not to emit any debugging
15183 information for BLOCK, because it doesn't contain any instructions.
15185 Don't allow this for blocks with nested functions or local classes
15186 as we would end up with orphans, and in the presence of scheduling
15187 we may end up calling them anyway. */
15190 dwarf2out_ignore_block (const_tree block)
15194 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15195 if (TREE_CODE (decl) == FUNCTION_DECL
15196 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15202 /* Hash table routines for file_hash. */
15205 file_table_eq (const void *p1_p, const void *p2_p)
15207 const struct dwarf_file_data *const p1 =
15208 (const struct dwarf_file_data *) p1_p;
15209 const char *const p2 = (const char *) p2_p;
15210 return strcmp (p1->filename, p2) == 0;
15214 file_table_hash (const void *p_p)
15216 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15217 return htab_hash_string (p->filename);
15220 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15221 dwarf2out.c) and return its "index". The index of each (known) filename is
15222 just a unique number which is associated with only that one filename. We
15223 need such numbers for the sake of generating labels (in the .debug_sfnames
15224 section) and references to those files numbers (in the .debug_srcinfo
15225 and.debug_macinfo sections). If the filename given as an argument is not
15226 found in our current list, add it to the list and assign it the next
15227 available unique index number. In order to speed up searches, we remember
15228 the index of the filename was looked up last. This handles the majority of
15231 static struct dwarf_file_data *
15232 lookup_filename (const char *file_name)
15235 struct dwarf_file_data * created;
15237 /* Check to see if the file name that was searched on the previous
15238 call matches this file name. If so, return the index. */
15239 if (file_table_last_lookup
15240 && (file_name == file_table_last_lookup->filename
15241 || strcmp (file_table_last_lookup->filename, file_name) == 0))
15242 return file_table_last_lookup;
15244 /* Didn't match the previous lookup, search the table. */
15245 slot = htab_find_slot_with_hash (file_table, file_name,
15246 htab_hash_string (file_name), INSERT);
15248 return (struct dwarf_file_data *) *slot;
15250 created = GGC_NEW (struct dwarf_file_data);
15251 created->filename = file_name;
15252 created->emitted_number = 0;
15257 /* If the assembler will construct the file table, then translate the compiler
15258 internal file table number into the assembler file table number, and emit
15259 a .file directive if we haven't already emitted one yet. The file table
15260 numbers are different because we prune debug info for unused variables and
15261 types, which may include filenames. */
15264 maybe_emit_file (struct dwarf_file_data * fd)
15266 if (! fd->emitted_number)
15268 if (last_emitted_file)
15269 fd->emitted_number = last_emitted_file->emitted_number + 1;
15271 fd->emitted_number = 1;
15272 last_emitted_file = fd;
15274 if (DWARF2_ASM_LINE_DEBUG_INFO)
15276 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
15277 output_quoted_string (asm_out_file,
15278 remap_debug_filename (fd->filename));
15279 fputc ('\n', asm_out_file);
15283 return fd->emitted_number;
15286 /* Called by the final INSN scan whenever we see a var location. We
15287 use it to drop labels in the right places, and throw the location in
15288 our lookup table. */
15291 dwarf2out_var_location (rtx loc_note)
15293 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
15294 struct var_loc_node *newloc;
15296 static rtx last_insn;
15297 static const char *last_label;
15300 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
15302 prev_insn = PREV_INSN (loc_note);
15304 newloc = GGC_CNEW (struct var_loc_node);
15305 /* If the insn we processed last time is the previous insn
15306 and it is also a var location note, use the label we emitted
15308 if (last_insn != NULL_RTX
15309 && last_insn == prev_insn
15310 && NOTE_P (prev_insn)
15311 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
15313 newloc->label = last_label;
15317 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
15318 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
15320 newloc->label = ggc_strdup (loclabel);
15322 newloc->var_loc_note = loc_note;
15323 newloc->next = NULL;
15325 if (cfun && in_cold_section_p)
15326 newloc->section_label = crtl->subsections.cold_section_label;
15328 newloc->section_label = text_section_label;
15330 last_insn = loc_note;
15331 last_label = newloc->label;
15332 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15333 add_var_loc_to_decl (decl, newloc);
15336 /* We need to reset the locations at the beginning of each
15337 function. We can't do this in the end_function hook, because the
15338 declarations that use the locations won't have been output when
15339 that hook is called. Also compute have_multiple_function_sections here. */
15342 dwarf2out_begin_function (tree fun)
15344 htab_empty (decl_loc_table);
15346 if (function_section (fun) != text_section)
15347 have_multiple_function_sections = true;
15349 dwarf2out_note_section_used ();
15352 /* Output a label to mark the beginning of a source code line entry
15353 and record information relating to this source line, in
15354 'line_info_table' for later output of the .debug_line section. */
15357 dwarf2out_source_line (unsigned int line, const char *filename)
15359 if (debug_info_level >= DINFO_LEVEL_NORMAL
15362 int file_num = maybe_emit_file (lookup_filename (filename));
15364 switch_to_section (current_function_section ());
15366 /* If requested, emit something human-readable. */
15367 if (flag_debug_asm)
15368 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15371 if (DWARF2_ASM_LINE_DEBUG_INFO)
15373 /* Emit the .loc directive understood by GNU as. */
15374 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15376 /* Indicate that line number info exists. */
15377 line_info_table_in_use++;
15379 else if (function_section (current_function_decl) != text_section)
15381 dw_separate_line_info_ref line_info;
15382 targetm.asm_out.internal_label (asm_out_file,
15383 SEPARATE_LINE_CODE_LABEL,
15384 separate_line_info_table_in_use);
15386 /* Expand the line info table if necessary. */
15387 if (separate_line_info_table_in_use
15388 == separate_line_info_table_allocated)
15390 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15391 separate_line_info_table
15392 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15393 separate_line_info_table,
15394 separate_line_info_table_allocated);
15395 memset (separate_line_info_table
15396 + separate_line_info_table_in_use,
15398 (LINE_INFO_TABLE_INCREMENT
15399 * sizeof (dw_separate_line_info_entry)));
15402 /* Add the new entry at the end of the line_info_table. */
15404 = &separate_line_info_table[separate_line_info_table_in_use++];
15405 line_info->dw_file_num = file_num;
15406 line_info->dw_line_num = line;
15407 line_info->function = current_function_funcdef_no;
15411 dw_line_info_ref line_info;
15413 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
15414 line_info_table_in_use);
15416 /* Expand the line info table if necessary. */
15417 if (line_info_table_in_use == line_info_table_allocated)
15419 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15421 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
15422 line_info_table_allocated);
15423 memset (line_info_table + line_info_table_in_use, 0,
15424 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
15427 /* Add the new entry at the end of the line_info_table. */
15428 line_info = &line_info_table[line_info_table_in_use++];
15429 line_info->dw_file_num = file_num;
15430 line_info->dw_line_num = line;
15435 /* Record the beginning of a new source file. */
15438 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
15440 if (flag_eliminate_dwarf2_dups)
15442 /* Record the beginning of the file for break_out_includes. */
15443 dw_die_ref bincl_die;
15445 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
15446 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
15449 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15451 int file_num = maybe_emit_file (lookup_filename (filename));
15453 switch_to_section (debug_macinfo_section);
15454 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
15455 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
15458 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
15462 /* Record the end of a source file. */
15465 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
15467 if (flag_eliminate_dwarf2_dups)
15468 /* Record the end of the file for break_out_includes. */
15469 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
15471 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15473 switch_to_section (debug_macinfo_section);
15474 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
15478 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15479 the tail part of the directive line, i.e. the part which is past the
15480 initial whitespace, #, whitespace, directive-name, whitespace part. */
15483 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
15484 const char *buffer ATTRIBUTE_UNUSED)
15486 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15488 switch_to_section (debug_macinfo_section);
15489 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
15490 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15491 dw2_asm_output_nstring (buffer, -1, "The macro");
15495 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15496 the tail part of the directive line, i.e. the part which is past the
15497 initial whitespace, #, whitespace, directive-name, whitespace part. */
15500 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
15501 const char *buffer ATTRIBUTE_UNUSED)
15503 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15505 switch_to_section (debug_macinfo_section);
15506 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
15507 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15508 dw2_asm_output_nstring (buffer, -1, "The macro");
15512 /* Set up for Dwarf output at the start of compilation. */
15515 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
15517 /* Allocate the file_table. */
15518 file_table = htab_create_ggc (50, file_table_hash,
15519 file_table_eq, NULL);
15521 /* Allocate the decl_die_table. */
15522 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
15523 decl_die_table_eq, NULL);
15525 /* Allocate the decl_loc_table. */
15526 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
15527 decl_loc_table_eq, NULL);
15529 /* Allocate the initial hunk of the decl_scope_table. */
15530 decl_scope_table = VEC_alloc (tree, gc, 256);
15532 /* Allocate the initial hunk of the abbrev_die_table. */
15533 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
15534 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
15535 /* Zero-th entry is allocated, but unused. */
15536 abbrev_die_table_in_use = 1;
15538 /* Allocate the initial hunk of the line_info_table. */
15539 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
15540 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
15542 /* Zero-th entry is allocated, but unused. */
15543 line_info_table_in_use = 1;
15545 /* Allocate the pubtypes and pubnames vectors. */
15546 pubname_table = VEC_alloc (pubname_entry, gc, 32);
15547 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
15549 /* Generate the initial DIE for the .debug section. Note that the (string)
15550 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15551 will (typically) be a relative pathname and that this pathname should be
15552 taken as being relative to the directory from which the compiler was
15553 invoked when the given (base) source file was compiled. We will fill
15554 in this value in dwarf2out_finish. */
15555 comp_unit_die = gen_compile_unit_die (NULL);
15557 incomplete_types = VEC_alloc (tree, gc, 64);
15559 used_rtx_array = VEC_alloc (rtx, gc, 32);
15561 debug_info_section = get_section (DEBUG_INFO_SECTION,
15562 SECTION_DEBUG, NULL);
15563 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
15564 SECTION_DEBUG, NULL);
15565 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
15566 SECTION_DEBUG, NULL);
15567 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
15568 SECTION_DEBUG, NULL);
15569 debug_line_section = get_section (DEBUG_LINE_SECTION,
15570 SECTION_DEBUG, NULL);
15571 debug_loc_section = get_section (DEBUG_LOC_SECTION,
15572 SECTION_DEBUG, NULL);
15573 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
15574 SECTION_DEBUG, NULL);
15575 #ifdef DEBUG_PUBTYPES_SECTION
15576 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
15577 SECTION_DEBUG, NULL);
15579 debug_str_section = get_section (DEBUG_STR_SECTION,
15580 DEBUG_STR_SECTION_FLAGS, NULL);
15581 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
15582 SECTION_DEBUG, NULL);
15583 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
15584 SECTION_DEBUG, NULL);
15586 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
15587 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
15588 DEBUG_ABBREV_SECTION_LABEL, 0);
15589 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
15590 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
15591 COLD_TEXT_SECTION_LABEL, 0);
15592 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
15594 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
15595 DEBUG_INFO_SECTION_LABEL, 0);
15596 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
15597 DEBUG_LINE_SECTION_LABEL, 0);
15598 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
15599 DEBUG_RANGES_SECTION_LABEL, 0);
15600 switch_to_section (debug_abbrev_section);
15601 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
15602 switch_to_section (debug_info_section);
15603 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
15604 switch_to_section (debug_line_section);
15605 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
15607 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15609 switch_to_section (debug_macinfo_section);
15610 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
15611 DEBUG_MACINFO_SECTION_LABEL, 0);
15612 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
15615 switch_to_section (text_section);
15616 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
15617 if (flag_reorder_blocks_and_partition)
15619 cold_text_section = unlikely_text_section ();
15620 switch_to_section (cold_text_section);
15621 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
15625 /* A helper function for dwarf2out_finish called through
15626 ht_forall. Emit one queued .debug_str string. */
15629 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
15631 struct indirect_string_node *node = (struct indirect_string_node *) *h;
15633 if (node->form == DW_FORM_strp)
15635 switch_to_section (debug_str_section);
15636 ASM_OUTPUT_LABEL (asm_out_file, node->label);
15637 assemble_string (node->str, strlen (node->str) + 1);
15643 #if ENABLE_ASSERT_CHECKING
15644 /* Verify that all marks are clear. */
15647 verify_marks_clear (dw_die_ref die)
15651 gcc_assert (! die->die_mark);
15652 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
15654 #endif /* ENABLE_ASSERT_CHECKING */
15656 /* Clear the marks for a die and its children.
15657 Be cool if the mark isn't set. */
15660 prune_unmark_dies (dw_die_ref die)
15666 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
15669 /* Given DIE that we're marking as used, find any other dies
15670 it references as attributes and mark them as used. */
15673 prune_unused_types_walk_attribs (dw_die_ref die)
15678 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15680 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
15682 /* A reference to another DIE.
15683 Make sure that it will get emitted. */
15684 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
15686 /* Set the string's refcount to 0 so that prune_unused_types_mark
15687 accounts properly for it. */
15688 if (AT_class (a) == dw_val_class_str)
15689 a->dw_attr_val.v.val_str->refcount = 0;
15694 /* Mark DIE as being used. If DOKIDS is true, then walk down
15695 to DIE's children. */
15698 prune_unused_types_mark (dw_die_ref die, int dokids)
15702 if (die->die_mark == 0)
15704 /* We haven't done this node yet. Mark it as used. */
15707 /* We also have to mark its parents as used.
15708 (But we don't want to mark our parents' kids due to this.) */
15709 if (die->die_parent)
15710 prune_unused_types_mark (die->die_parent, 0);
15712 /* Mark any referenced nodes. */
15713 prune_unused_types_walk_attribs (die);
15715 /* If this node is a specification,
15716 also mark the definition, if it exists. */
15717 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
15718 prune_unused_types_mark (die->die_definition, 1);
15721 if (dokids && die->die_mark != 2)
15723 /* We need to walk the children, but haven't done so yet.
15724 Remember that we've walked the kids. */
15727 /* If this is an array type, we need to make sure our
15728 kids get marked, even if they're types. */
15729 if (die->die_tag == DW_TAG_array_type)
15730 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
15732 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15737 /* Walk the tree DIE and mark types that we actually use. */
15740 prune_unused_types_walk (dw_die_ref die)
15744 /* Don't do anything if this node is already marked. */
15748 switch (die->die_tag)
15750 case DW_TAG_const_type:
15751 case DW_TAG_packed_type:
15752 case DW_TAG_pointer_type:
15753 case DW_TAG_reference_type:
15754 case DW_TAG_volatile_type:
15755 case DW_TAG_typedef:
15756 case DW_TAG_array_type:
15757 case DW_TAG_structure_type:
15758 case DW_TAG_union_type:
15759 case DW_TAG_class_type:
15760 case DW_TAG_interface_type:
15761 case DW_TAG_friend:
15762 case DW_TAG_variant_part:
15763 case DW_TAG_enumeration_type:
15764 case DW_TAG_subroutine_type:
15765 case DW_TAG_string_type:
15766 case DW_TAG_set_type:
15767 case DW_TAG_subrange_type:
15768 case DW_TAG_ptr_to_member_type:
15769 case DW_TAG_file_type:
15770 if (die->die_perennial_p)
15773 /* It's a type node --- don't mark it. */
15777 /* Mark everything else. */
15783 /* Now, mark any dies referenced from here. */
15784 prune_unused_types_walk_attribs (die);
15786 /* Mark children. */
15787 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15790 /* Increment the string counts on strings referred to from DIE's
15794 prune_unused_types_update_strings (dw_die_ref die)
15799 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15800 if (AT_class (a) == dw_val_class_str)
15802 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15804 /* Avoid unnecessarily putting strings that are used less than
15805 twice in the hash table. */
15807 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15810 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15811 htab_hash_string (s->str),
15813 gcc_assert (*slot == NULL);
15819 /* Remove from the tree DIE any dies that aren't marked. */
15822 prune_unused_types_prune (dw_die_ref die)
15826 gcc_assert (die->die_mark);
15827 prune_unused_types_update_strings (die);
15829 if (! die->die_child)
15832 c = die->die_child;
15834 dw_die_ref prev = c;
15835 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15836 if (c == die->die_child)
15838 /* No marked children between 'prev' and the end of the list. */
15840 /* No marked children at all. */
15841 die->die_child = NULL;
15844 prev->die_sib = c->die_sib;
15845 die->die_child = prev;
15850 if (c != prev->die_sib)
15852 prune_unused_types_prune (c);
15853 } while (c != die->die_child);
15857 /* Remove dies representing declarations that we never use. */
15860 prune_unused_types (void)
15863 limbo_die_node *node;
15866 #if ENABLE_ASSERT_CHECKING
15867 /* All the marks should already be clear. */
15868 verify_marks_clear (comp_unit_die);
15869 for (node = limbo_die_list; node; node = node->next)
15870 verify_marks_clear (node->die);
15871 #endif /* ENABLE_ASSERT_CHECKING */
15873 /* Set the mark on nodes that are actually used. */
15874 prune_unused_types_walk (comp_unit_die);
15875 for (node = limbo_die_list; node; node = node->next)
15876 prune_unused_types_walk (node->die);
15878 /* Also set the mark on nodes referenced from the
15879 pubname_table or arange_table. */
15880 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15881 prune_unused_types_mark (pub->die, 1);
15882 for (i = 0; i < arange_table_in_use; i++)
15883 prune_unused_types_mark (arange_table[i], 1);
15885 /* Get rid of nodes that aren't marked; and update the string counts. */
15886 if (debug_str_hash)
15887 htab_empty (debug_str_hash);
15888 prune_unused_types_prune (comp_unit_die);
15889 for (node = limbo_die_list; node; node = node->next)
15890 prune_unused_types_prune (node->die);
15892 /* Leave the marks clear. */
15893 prune_unmark_dies (comp_unit_die);
15894 for (node = limbo_die_list; node; node = node->next)
15895 prune_unmark_dies (node->die);
15898 /* Set the parameter to true if there are any relative pathnames in
15901 file_table_relative_p (void ** slot, void *param)
15903 bool *p = (bool *) param;
15904 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
15905 if (!IS_ABSOLUTE_PATH (d->filename))
15913 /* Output stuff that dwarf requires at the end of every file,
15914 and generate the DWARF-2 debugging info. */
15917 dwarf2out_finish (const char *filename)
15919 limbo_die_node *node, *next_node;
15920 dw_die_ref die = 0;
15922 /* Add the name for the main input file now. We delayed this from
15923 dwarf2out_init to avoid complications with PCH. */
15924 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
15925 if (!IS_ABSOLUTE_PATH (filename))
15926 add_comp_dir_attribute (comp_unit_die);
15927 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
15930 htab_traverse (file_table, file_table_relative_p, &p);
15932 add_comp_dir_attribute (comp_unit_die);
15935 /* Traverse the limbo die list, and add parent/child links. The only
15936 dies without parents that should be here are concrete instances of
15937 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15938 For concrete instances, we can get the parent die from the abstract
15940 for (node = limbo_die_list; node; node = next_node)
15942 next_node = node->next;
15945 if (die->die_parent == NULL)
15947 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15950 add_child_die (origin->die_parent, die);
15951 else if (die == comp_unit_die)
15953 else if (errorcount > 0 || sorrycount > 0)
15954 /* It's OK to be confused by errors in the input. */
15955 add_child_die (comp_unit_die, die);
15958 /* In certain situations, the lexical block containing a
15959 nested function can be optimized away, which results
15960 in the nested function die being orphaned. Likewise
15961 with the return type of that nested function. Force
15962 this to be a child of the containing function.
15964 It may happen that even the containing function got fully
15965 inlined and optimized out. In that case we are lost and
15966 assign the empty child. This should not be big issue as
15967 the function is likely unreachable too. */
15968 tree context = NULL_TREE;
15970 gcc_assert (node->created_for);
15972 if (DECL_P (node->created_for))
15973 context = DECL_CONTEXT (node->created_for);
15974 else if (TYPE_P (node->created_for))
15975 context = TYPE_CONTEXT (node->created_for);
15977 gcc_assert (context
15978 && (TREE_CODE (context) == FUNCTION_DECL
15979 || TREE_CODE (context) == NAMESPACE_DECL));
15981 origin = lookup_decl_die (context);
15983 add_child_die (origin, die);
15985 add_child_die (comp_unit_die, die);
15990 limbo_die_list = NULL;
15992 /* Walk through the list of incomplete types again, trying once more to
15993 emit full debugging info for them. */
15994 retry_incomplete_types ();
15996 if (flag_eliminate_unused_debug_types)
15997 prune_unused_types ();
15999 /* Generate separate CUs for each of the include files we've seen.
16000 They will go into limbo_die_list. */
16001 if (flag_eliminate_dwarf2_dups)
16002 break_out_includes (comp_unit_die);
16004 /* Traverse the DIE's and add add sibling attributes to those DIE's
16005 that have children. */
16006 add_sibling_attributes (comp_unit_die);
16007 for (node = limbo_die_list; node; node = node->next)
16008 add_sibling_attributes (node->die);
16010 /* Output a terminator label for the .text section. */
16011 switch_to_section (text_section);
16012 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16013 if (flag_reorder_blocks_and_partition)
16015 switch_to_section (unlikely_text_section ());
16016 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16019 /* We can only use the low/high_pc attributes if all of the code was
16021 if (!have_multiple_function_sections)
16023 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16024 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16029 unsigned fde_idx = 0;
16031 /* We need to give .debug_loc and .debug_ranges an appropriate
16032 "base address". Use zero so that these addresses become
16033 absolute. Historically, we've emitted the unexpected
16034 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16035 Emit both to give time for other tools to adapt. */
16036 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16037 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16039 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16040 add_ranges_by_labels (text_section_label,
16042 if (flag_reorder_blocks_and_partition)
16043 add_ranges_by_labels (cold_text_section_label,
16046 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16048 dw_fde_ref fde = &fde_table[fde_idx];
16050 if (fde->dw_fde_switched_sections)
16052 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16053 fde->dw_fde_hot_section_end_label);
16054 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16055 fde->dw_fde_unlikely_section_end_label);
16058 add_ranges_by_labels (fde->dw_fde_begin,
16065 /* Output location list section if necessary. */
16066 if (have_location_lists)
16068 /* Output the location lists info. */
16069 switch_to_section (debug_loc_section);
16070 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16071 DEBUG_LOC_SECTION_LABEL, 0);
16072 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16073 output_location_lists (die);
16076 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16077 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16078 debug_line_section_label);
16080 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16081 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16083 /* Output all of the compilation units. We put the main one last so that
16084 the offsets are available to output_pubnames. */
16085 for (node = limbo_die_list; node; node = node->next)
16086 output_comp_unit (node->die, 0);
16088 output_comp_unit (comp_unit_die, 0);
16090 /* Output the abbreviation table. */
16091 switch_to_section (debug_abbrev_section);
16092 output_abbrev_section ();
16094 /* Output public names table if necessary. */
16095 if (!VEC_empty (pubname_entry, pubname_table))
16097 switch_to_section (debug_pubnames_section);
16098 output_pubnames (pubname_table);
16101 #ifdef DEBUG_PUBTYPES_SECTION
16102 /* Output public types table if necessary. */
16103 if (!VEC_empty (pubname_entry, pubtype_table))
16105 switch_to_section (debug_pubtypes_section);
16106 output_pubnames (pubtype_table);
16110 /* Output the address range information. We only put functions in the arange
16111 table, so don't write it out if we don't have any. */
16112 if (fde_table_in_use)
16114 switch_to_section (debug_aranges_section);
16118 /* Output ranges section if necessary. */
16119 if (ranges_table_in_use)
16121 switch_to_section (debug_ranges_section);
16122 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16126 /* Output the source line correspondence table. We must do this
16127 even if there is no line information. Otherwise, on an empty
16128 translation unit, we will generate a present, but empty,
16129 .debug_info section. IRIX 6.5 `nm' will then complain when
16130 examining the file. This is done late so that any filenames
16131 used by the debug_info section are marked as 'used'. */
16132 if (! DWARF2_ASM_LINE_DEBUG_INFO)
16134 switch_to_section (debug_line_section);
16135 output_line_info ();
16138 /* Have to end the macro section. */
16139 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16141 switch_to_section (debug_macinfo_section);
16142 dw2_asm_output_data (1, 0, "End compilation unit");
16145 /* If we emitted any DW_FORM_strp form attribute, output the string
16147 if (debug_str_hash)
16148 htab_traverse (debug_str_hash, output_indirect_string, NULL);
16152 /* This should never be used, but its address is needed for comparisons. */
16153 const struct gcc_debug_hooks dwarf2_debug_hooks;
16155 #endif /* DWARF2_DEBUGGING_INFO */
16157 #include "gt-dwarf2out.h"