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 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
38 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
70 #ifdef DWARF2_DEBUGGING_INFO
71 static void dwarf2out_source_line (unsigned int, const char *);
74 /* DWARF2 Abbreviation Glossary:
75 CFA = Canonical Frame Address
76 a fixed address on the stack which identifies a call frame.
77 We define it to be the value of SP just before the call insn.
78 The CFA register and offset, which may change during the course
79 of the function, are used to calculate its value at runtime.
80 CFI = Call Frame Instruction
81 an instruction for the DWARF2 abstract machine
82 CIE = Common Information Entry
83 information describing information common to one or more FDEs
84 DIE = Debugging Information Entry
85 FDE = Frame Description Entry
86 information describing the stack call frame, in particular,
87 how to restore registers
89 DW_CFA_... = DWARF2 CFA call frame instruction
90 DW_TAG_... = DWARF2 DIE tag */
92 #ifndef DWARF2_FRAME_INFO
93 # ifdef DWARF2_DEBUGGING_INFO
94 # define DWARF2_FRAME_INFO \
95 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
97 # define DWARF2_FRAME_INFO 0
101 /* Map register numbers held in the call frame info that gcc has
102 collected using DWARF_FRAME_REGNUM to those that should be output in
103 .debug_frame and .eh_frame. */
104 #ifndef DWARF2_FRAME_REG_OUT
105 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
108 /* Decide whether we want to emit frame unwind information for the current
112 dwarf2out_do_frame (void)
114 /* We want to emit correct CFA location expressions or lists, so we
115 have to return true if we're going to output debug info, even if
116 we're not going to output frame or unwind info. */
117 return (write_symbols
== DWARF2_DEBUG
118 || write_symbols
== VMS_AND_DWARF2_DEBUG
120 #ifdef DWARF2_UNWIND_INFO
121 || (DWARF2_UNWIND_INFO
122 && (flag_unwind_tables
123 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
128 /* The size of the target's pointer type. */
130 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
133 /* Array of RTXes referenced by the debugging information, which therefore
134 must be kept around forever. */
135 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
137 /* A pointer to the base of a list of incomplete types which might be
138 completed at some later time. incomplete_types_list needs to be a
139 VEC(tree,gc) because we want to tell the garbage collector about
141 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
143 /* A pointer to the base of a table of references to declaration
144 scopes. This table is a display which tracks the nesting
145 of declaration scopes at the current scope and containing
146 scopes. This table is used to find the proper place to
147 define type declaration DIE's. */
148 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
150 /* Pointers to various DWARF2 sections. */
151 static GTY(()) section
*debug_info_section
;
152 static GTY(()) section
*debug_abbrev_section
;
153 static GTY(()) section
*debug_aranges_section
;
154 static GTY(()) section
*debug_macinfo_section
;
155 static GTY(()) section
*debug_line_section
;
156 static GTY(()) section
*debug_loc_section
;
157 static GTY(()) section
*debug_pubnames_section
;
158 static GTY(()) section
*debug_str_section
;
159 static GTY(()) section
*debug_ranges_section
;
160 static GTY(()) section
*debug_frame_section
;
162 /* How to start an assembler comment. */
163 #ifndef ASM_COMMENT_START
164 #define ASM_COMMENT_START ";#"
167 typedef struct dw_cfi_struct
*dw_cfi_ref
;
168 typedef struct dw_fde_struct
*dw_fde_ref
;
169 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
171 /* Call frames are described using a sequence of Call Frame
172 Information instructions. The register number, offset
173 and address fields are provided as possible operands;
174 their use is selected by the opcode field. */
176 enum dw_cfi_oprnd_type
{
178 dw_cfi_oprnd_reg_num
,
184 typedef union dw_cfi_oprnd_struct
GTY(())
186 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
187 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
188 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
189 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
193 typedef struct dw_cfi_struct
GTY(())
195 dw_cfi_ref dw_cfi_next
;
196 enum dwarf_call_frame_info dw_cfi_opc
;
197 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
199 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
204 /* This is how we define the location of the CFA. We use to handle it
205 as REG + OFFSET all the time, but now it can be more complex.
206 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
207 Instead of passing around REG and OFFSET, we pass a copy
208 of this structure. */
209 typedef struct cfa_loc
GTY(())
211 HOST_WIDE_INT offset
;
212 HOST_WIDE_INT base_offset
;
214 int indirect
; /* 1 if CFA is accessed via a dereference. */
217 /* All call frame descriptions (FDE's) in the GCC generated DWARF
218 refer to a single Common Information Entry (CIE), defined at
219 the beginning of the .debug_frame section. This use of a single
220 CIE obviates the need to keep track of multiple CIE's
221 in the DWARF generation routines below. */
223 typedef struct dw_fde_struct
GTY(())
226 const char *dw_fde_begin
;
227 const char *dw_fde_current_label
;
228 const char *dw_fde_end
;
229 const char *dw_fde_hot_section_label
;
230 const char *dw_fde_hot_section_end_label
;
231 const char *dw_fde_unlikely_section_label
;
232 const char *dw_fde_unlikely_section_end_label
;
233 bool dw_fde_switched_sections
;
234 dw_cfi_ref dw_fde_cfi
;
235 unsigned funcdef_number
;
236 unsigned all_throwers_are_sibcalls
: 1;
237 unsigned nothrow
: 1;
238 unsigned uses_eh_lsda
: 1;
242 /* Maximum size (in bytes) of an artificially generated label. */
243 #define MAX_ARTIFICIAL_LABEL_BYTES 30
245 /* The size of addresses as they appear in the Dwarf 2 data.
246 Some architectures use word addresses to refer to code locations,
247 but Dwarf 2 info always uses byte addresses. On such machines,
248 Dwarf 2 addresses need to be larger than the architecture's
250 #ifndef DWARF2_ADDR_SIZE
251 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
254 /* The size in bytes of a DWARF field indicating an offset or length
255 relative to a debug info section, specified to be 4 bytes in the
256 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
259 #ifndef DWARF_OFFSET_SIZE
260 #define DWARF_OFFSET_SIZE 4
263 /* According to the (draft) DWARF 3 specification, the initial length
264 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
265 bytes are 0xffffffff, followed by the length stored in the next 8
268 However, the SGI/MIPS ABI uses an initial length which is equal to
269 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
271 #ifndef DWARF_INITIAL_LENGTH_SIZE
272 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
275 #define DWARF_VERSION 2
277 /* Round SIZE up to the nearest BOUNDARY. */
278 #define DWARF_ROUND(SIZE,BOUNDARY) \
279 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
281 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
282 #ifndef DWARF_CIE_DATA_ALIGNMENT
283 #ifdef STACK_GROWS_DOWNWARD
284 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
286 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
290 /* CIE identifier. */
291 #if HOST_BITS_PER_WIDE_INT >= 64
292 #define DWARF_CIE_ID \
293 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
295 #define DWARF_CIE_ID DW_CIE_ID
298 /* A pointer to the base of a table that contains frame description
299 information for each routine. */
300 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
302 /* Number of elements currently allocated for fde_table. */
303 static GTY(()) unsigned fde_table_allocated
;
305 /* Number of elements in fde_table currently in use. */
306 static GTY(()) unsigned fde_table_in_use
;
308 /* Size (in elements) of increments by which we may expand the
310 #define FDE_TABLE_INCREMENT 256
312 /* A list of call frame insns for the CIE. */
313 static GTY(()) dw_cfi_ref cie_cfi_head
;
315 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
316 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
317 attribute that accelerates the lookup of the FDE associated
318 with the subprogram. This variable holds the table index of the FDE
319 associated with the current function (body) definition. */
320 static unsigned current_funcdef_fde
;
323 struct indirect_string_node
GTY(())
326 unsigned int refcount
;
331 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
333 static GTY(()) int dw2_string_counter
;
334 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
336 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
338 /* Forward declarations for functions defined in this file. */
340 static char *stripattributes (const char *);
341 static const char *dwarf_cfi_name (unsigned);
342 static dw_cfi_ref
new_cfi (void);
343 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
344 static void add_fde_cfi (const char *, dw_cfi_ref
);
345 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
346 static void lookup_cfa (dw_cfa_location
*);
347 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
348 static void initial_return_save (rtx
);
349 static HOST_WIDE_INT
stack_adjust_offset (rtx
);
350 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
351 static void output_call_frame_info (int);
352 static void dwarf2out_stack_adjust (rtx
, bool);
353 static void flush_queued_reg_saves (void);
354 static bool clobbers_queued_reg_save (rtx
);
355 static void dwarf2out_frame_debug_expr (rtx
, const char *);
357 /* Support for complex CFA locations. */
358 static void output_cfa_loc (dw_cfi_ref
);
359 static void get_cfa_from_loc_descr (dw_cfa_location
*,
360 struct dw_loc_descr_struct
*);
361 static struct dw_loc_descr_struct
*build_cfa_loc
362 (dw_cfa_location
*, HOST_WIDE_INT
);
363 static void def_cfa_1 (const char *, dw_cfa_location
*);
365 /* How to start an assembler comment. */
366 #ifndef ASM_COMMENT_START
367 #define ASM_COMMENT_START ";#"
370 /* Data and reference forms for relocatable data. */
371 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
372 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
374 #ifndef DEBUG_FRAME_SECTION
375 #define DEBUG_FRAME_SECTION ".debug_frame"
378 #ifndef FUNC_BEGIN_LABEL
379 #define FUNC_BEGIN_LABEL "LFB"
382 #ifndef FUNC_END_LABEL
383 #define FUNC_END_LABEL "LFE"
386 #ifndef FRAME_BEGIN_LABEL
387 #define FRAME_BEGIN_LABEL "Lframe"
389 #define CIE_AFTER_SIZE_LABEL "LSCIE"
390 #define CIE_END_LABEL "LECIE"
391 #define FDE_LABEL "LSFDE"
392 #define FDE_AFTER_SIZE_LABEL "LASFDE"
393 #define FDE_END_LABEL "LEFDE"
394 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
395 #define LINE_NUMBER_END_LABEL "LELT"
396 #define LN_PROLOG_AS_LABEL "LASLTP"
397 #define LN_PROLOG_END_LABEL "LELTP"
398 #define DIE_LABEL_PREFIX "DW"
400 /* The DWARF 2 CFA column which tracks the return address. Normally this
401 is the column for PC, or the first column after all of the hard
403 #ifndef DWARF_FRAME_RETURN_COLUMN
405 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
407 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
411 /* The mapping from gcc register number to DWARF 2 CFA column number. By
412 default, we just provide columns for all registers. */
413 #ifndef DWARF_FRAME_REGNUM
414 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
417 /* Hook used by __throw. */
420 expand_builtin_dwarf_sp_column (void)
422 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
423 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
426 /* Return a pointer to a copy of the section string name S with all
427 attributes stripped off, and an asterisk prepended (for assemble_name). */
430 stripattributes (const char *s
)
432 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
437 while (*s
&& *s
!= ',')
444 /* Generate code to initialize the register size table. */
447 expand_builtin_init_dwarf_reg_sizes (tree address
)
450 enum machine_mode mode
= TYPE_MODE (char_type_node
);
451 rtx addr
= expand_normal (address
);
452 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
453 bool wrote_return_column
= false;
455 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
457 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
459 if (rnum
< DWARF_FRAME_REGISTERS
)
461 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
462 enum machine_mode save_mode
= reg_raw_mode
[i
];
465 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
466 save_mode
= choose_hard_reg_mode (i
, 1, true);
467 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
469 if (save_mode
== VOIDmode
)
471 wrote_return_column
= true;
473 size
= GET_MODE_SIZE (save_mode
);
477 emit_move_insn (adjust_address (mem
, mode
, offset
),
478 gen_int_mode (size
, mode
));
482 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
483 gcc_assert (wrote_return_column
);
484 i
= DWARF_ALT_FRAME_RETURN_COLUMN
;
485 wrote_return_column
= false;
487 i
= DWARF_FRAME_RETURN_COLUMN
;
490 if (! wrote_return_column
)
492 enum machine_mode save_mode
= Pmode
;
493 HOST_WIDE_INT offset
= i
* GET_MODE_SIZE (mode
);
494 HOST_WIDE_INT size
= GET_MODE_SIZE (save_mode
);
495 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
499 /* Convert a DWARF call frame info. operation to its string name */
502 dwarf_cfi_name (unsigned int cfi_opc
)
506 case DW_CFA_advance_loc
:
507 return "DW_CFA_advance_loc";
509 return "DW_CFA_offset";
511 return "DW_CFA_restore";
515 return "DW_CFA_set_loc";
516 case DW_CFA_advance_loc1
:
517 return "DW_CFA_advance_loc1";
518 case DW_CFA_advance_loc2
:
519 return "DW_CFA_advance_loc2";
520 case DW_CFA_advance_loc4
:
521 return "DW_CFA_advance_loc4";
522 case DW_CFA_offset_extended
:
523 return "DW_CFA_offset_extended";
524 case DW_CFA_restore_extended
:
525 return "DW_CFA_restore_extended";
526 case DW_CFA_undefined
:
527 return "DW_CFA_undefined";
528 case DW_CFA_same_value
:
529 return "DW_CFA_same_value";
530 case DW_CFA_register
:
531 return "DW_CFA_register";
532 case DW_CFA_remember_state
:
533 return "DW_CFA_remember_state";
534 case DW_CFA_restore_state
:
535 return "DW_CFA_restore_state";
537 return "DW_CFA_def_cfa";
538 case DW_CFA_def_cfa_register
:
539 return "DW_CFA_def_cfa_register";
540 case DW_CFA_def_cfa_offset
:
541 return "DW_CFA_def_cfa_offset";
544 case DW_CFA_def_cfa_expression
:
545 return "DW_CFA_def_cfa_expression";
546 case DW_CFA_expression
:
547 return "DW_CFA_expression";
548 case DW_CFA_offset_extended_sf
:
549 return "DW_CFA_offset_extended_sf";
550 case DW_CFA_def_cfa_sf
:
551 return "DW_CFA_def_cfa_sf";
552 case DW_CFA_def_cfa_offset_sf
:
553 return "DW_CFA_def_cfa_offset_sf";
555 /* SGI/MIPS specific */
556 case DW_CFA_MIPS_advance_loc8
:
557 return "DW_CFA_MIPS_advance_loc8";
560 case DW_CFA_GNU_window_save
:
561 return "DW_CFA_GNU_window_save";
562 case DW_CFA_GNU_args_size
:
563 return "DW_CFA_GNU_args_size";
564 case DW_CFA_GNU_negative_offset_extended
:
565 return "DW_CFA_GNU_negative_offset_extended";
568 return "DW_CFA_<unknown>";
572 /* Return a pointer to a newly allocated Call Frame Instruction. */
574 static inline dw_cfi_ref
577 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
579 cfi
->dw_cfi_next
= NULL
;
580 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
581 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
586 /* Add a Call Frame Instruction to list of instructions. */
589 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
593 /* Find the end of the chain. */
594 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
600 /* Generate a new label for the CFI info to refer to. */
603 dwarf2out_cfi_label (void)
605 static char label
[20];
607 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
608 ASM_OUTPUT_LABEL (asm_out_file
, label
);
612 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
613 or to the CIE if LABEL is NULL. */
616 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
620 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
623 label
= dwarf2out_cfi_label ();
625 if (fde
->dw_fde_current_label
== NULL
626 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
630 label
= xstrdup (label
);
632 /* Set the location counter to the new label. */
634 /* If we have a current label, advance from there, otherwise
635 set the location directly using set_loc. */
636 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
637 ? DW_CFA_advance_loc4
639 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
640 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
642 fde
->dw_fde_current_label
= label
;
645 add_cfi (&fde
->dw_fde_cfi
, cfi
);
649 add_cfi (&cie_cfi_head
, cfi
);
652 /* Subroutine of lookup_cfa. */
655 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
657 switch (cfi
->dw_cfi_opc
)
659 case DW_CFA_def_cfa_offset
:
660 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
662 case DW_CFA_def_cfa_offset_sf
:
664 = cfi
->dw_cfi_oprnd1
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
666 case DW_CFA_def_cfa_register
:
667 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
670 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
671 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
673 case DW_CFA_def_cfa_sf
:
674 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
676 = cfi
->dw_cfi_oprnd2
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
678 case DW_CFA_def_cfa_expression
:
679 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
686 /* Find the previous value for the CFA. */
689 lookup_cfa (dw_cfa_location
*loc
)
693 loc
->reg
= INVALID_REGNUM
;
696 loc
->base_offset
= 0;
698 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
699 lookup_cfa_1 (cfi
, loc
);
701 if (fde_table_in_use
)
703 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
704 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
705 lookup_cfa_1 (cfi
, loc
);
709 /* The current rule for calculating the DWARF2 canonical frame address. */
710 static dw_cfa_location cfa
;
712 /* The register used for saving registers to the stack, and its offset
714 static dw_cfa_location cfa_store
;
716 /* The running total of the size of arguments pushed onto the stack. */
717 static HOST_WIDE_INT args_size
;
719 /* The last args_size we actually output. */
720 static HOST_WIDE_INT old_args_size
;
722 /* Entry point to update the canonical frame address (CFA).
723 LABEL is passed to add_fde_cfi. The value of CFA is now to be
724 calculated from REG+OFFSET. */
727 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
734 def_cfa_1 (label
, &loc
);
737 /* Determine if two dw_cfa_location structures define the same data. */
740 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
742 return (loc1
->reg
== loc2
->reg
743 && loc1
->offset
== loc2
->offset
744 && loc1
->indirect
== loc2
->indirect
745 && (loc1
->indirect
== 0
746 || loc1
->base_offset
== loc2
->base_offset
));
749 /* This routine does the actual work. The CFA is now calculated from
750 the dw_cfa_location structure. */
753 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
756 dw_cfa_location old_cfa
, loc
;
761 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
762 cfa_store
.offset
= loc
.offset
;
764 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
765 lookup_cfa (&old_cfa
);
767 /* If nothing changed, no need to issue any call frame instructions. */
768 if (cfa_equal_p (&loc
, &old_cfa
))
773 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
775 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
776 the CFA register did not change but the offset did. */
779 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
780 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
782 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
783 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= f_offset
;
787 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
788 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
792 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
793 else if (loc
.offset
== old_cfa
.offset
794 && old_cfa
.reg
!= INVALID_REGNUM
797 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
798 indicating the CFA register has changed to <register> but the
799 offset has not changed. */
800 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
801 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
805 else if (loc
.indirect
== 0)
807 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
808 indicating the CFA register has changed to <register> with
809 the specified offset. */
812 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
813 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
815 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
816 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
817 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= f_offset
;
821 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
822 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
823 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
828 /* Construct a DW_CFA_def_cfa_expression instruction to
829 calculate the CFA using a full location expression since no
830 register-offset pair is available. */
831 struct dw_loc_descr_struct
*loc_list
;
833 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
834 loc_list
= build_cfa_loc (&loc
, 0);
835 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
838 add_fde_cfi (label
, cfi
);
841 /* Add the CFI for saving a register. REG is the CFA column number.
842 LABEL is passed to add_fde_cfi.
843 If SREG is -1, the register is saved at OFFSET from the CFA;
844 otherwise it is saved in SREG. */
847 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
849 dw_cfi_ref cfi
= new_cfi ();
851 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
853 if (sreg
== INVALID_REGNUM
)
856 /* The register number won't fit in 6 bits, so we have to use
858 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
860 cfi
->dw_cfi_opc
= DW_CFA_offset
;
862 #ifdef ENABLE_CHECKING
864 /* If we get an offset that is not a multiple of
865 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
866 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
868 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
870 gcc_assert (check_offset
* DWARF_CIE_DATA_ALIGNMENT
== offset
);
873 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
875 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
877 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
879 else if (sreg
== reg
)
880 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
883 cfi
->dw_cfi_opc
= DW_CFA_register
;
884 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
887 add_fde_cfi (label
, cfi
);
890 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
891 This CFI tells the unwinder that it needs to restore the window registers
892 from the previous frame's window save area.
894 ??? Perhaps we should note in the CIE where windows are saved (instead of
895 assuming 0(cfa)) and what registers are in the window. */
898 dwarf2out_window_save (const char *label
)
900 dw_cfi_ref cfi
= new_cfi ();
902 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
903 add_fde_cfi (label
, cfi
);
906 /* Add a CFI to update the running total of the size of arguments
907 pushed onto the stack. */
910 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
914 if (size
== old_args_size
)
917 old_args_size
= size
;
920 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
921 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
922 add_fde_cfi (label
, cfi
);
925 /* Entry point for saving a register to the stack. REG is the GCC register
926 number. LABEL and OFFSET are passed to reg_save. */
929 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
931 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
934 /* Entry point for saving the return address in the stack.
935 LABEL and OFFSET are passed to reg_save. */
938 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
940 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
943 /* Entry point for saving the return address in a register.
944 LABEL and SREG are passed to reg_save. */
947 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
949 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
952 /* Record the initial position of the return address. RTL is
953 INCOMING_RETURN_ADDR_RTX. */
956 initial_return_save (rtx rtl
)
958 unsigned int reg
= INVALID_REGNUM
;
959 HOST_WIDE_INT offset
= 0;
961 switch (GET_CODE (rtl
))
964 /* RA is in a register. */
965 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
969 /* RA is on the stack. */
971 switch (GET_CODE (rtl
))
974 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
979 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
980 offset
= INTVAL (XEXP (rtl
, 1));
984 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
985 offset
= -INTVAL (XEXP (rtl
, 1));
995 /* The return address is at some offset from any value we can
996 actually load. For instance, on the SPARC it is in %i7+8. Just
997 ignore the offset for now; it doesn't matter for unwinding frames. */
998 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
999 initial_return_save (XEXP (rtl
, 0));
1006 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1007 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1010 /* Given a SET, calculate the amount of stack adjustment it
1013 static HOST_WIDE_INT
1014 stack_adjust_offset (rtx pattern
)
1016 rtx src
= SET_SRC (pattern
);
1017 rtx dest
= SET_DEST (pattern
);
1018 HOST_WIDE_INT offset
= 0;
1021 if (dest
== stack_pointer_rtx
)
1023 /* (set (reg sp) (plus (reg sp) (const_int))) */
1024 code
= GET_CODE (src
);
1025 if (! (code
== PLUS
|| code
== MINUS
)
1026 || XEXP (src
, 0) != stack_pointer_rtx
1027 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1030 offset
= INTVAL (XEXP (src
, 1));
1034 else if (MEM_P (dest
))
1036 /* (set (mem (pre_dec (reg sp))) (foo)) */
1037 src
= XEXP (dest
, 0);
1038 code
= GET_CODE (src
);
1044 if (XEXP (src
, 0) == stack_pointer_rtx
)
1046 rtx val
= XEXP (XEXP (src
, 1), 1);
1047 /* We handle only adjustments by constant amount. */
1048 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1049 && GET_CODE (val
) == CONST_INT
);
1050 offset
= -INTVAL (val
);
1057 if (XEXP (src
, 0) == stack_pointer_rtx
)
1059 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1066 if (XEXP (src
, 0) == stack_pointer_rtx
)
1068 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1083 /* Check INSN to see if it looks like a push or a stack adjustment, and
1084 make a note of it if it does. EH uses this information to find out how
1085 much extra space it needs to pop off the stack. */
1088 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1090 HOST_WIDE_INT offset
;
1094 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1095 with this function. Proper support would require all frame-related
1096 insns to be marked, and to be able to handle saving state around
1097 epilogues textually in the middle of the function. */
1098 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1101 /* If only calls can throw, and we have a frame pointer,
1102 save up adjustments until we see the CALL_INSN. */
1103 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1105 if (CALL_P (insn
) && !after_p
)
1107 /* Extract the size of the args from the CALL rtx itself. */
1108 insn
= PATTERN (insn
);
1109 if (GET_CODE (insn
) == PARALLEL
)
1110 insn
= XVECEXP (insn
, 0, 0);
1111 if (GET_CODE (insn
) == SET
)
1112 insn
= SET_SRC (insn
);
1113 if (GET_CODE (insn
) == CALL
) {
1114 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1116 else if ((GET_CODE (insn
) == UNSPEC
) &&
1117 (XINT (insn
, 1) == UNSPEC_NACLCALL
)) {
1118 dwarf2out_args_size ("", INTVAL (XVECEXP (insn
, 0, 1)));
1121 internal_error ("Not recognized as a call or naclcall");
1127 if (CALL_P (insn
) && !after_p
)
1129 if (!flag_asynchronous_unwind_tables
)
1130 dwarf2out_args_size ("", args_size
);
1133 else if (BARRIER_P (insn
))
1135 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1136 the compiler will have already emitted a stack adjustment, but
1137 doesn't bother for calls to noreturn functions. */
1138 #ifdef STACK_GROWS_DOWNWARD
1139 offset
= -args_size
;
1144 else if (GET_CODE (PATTERN (insn
)) == SET
)
1145 offset
= stack_adjust_offset (PATTERN (insn
));
1146 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1147 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1149 /* There may be stack adjustments inside compound insns. Search
1151 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1152 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1153 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1161 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1162 cfa
.offset
+= offset
;
1164 #ifndef STACK_GROWS_DOWNWARD
1168 args_size
+= offset
;
1172 label
= dwarf2out_cfi_label ();
1173 def_cfa_1 (label
, &cfa
);
1174 if (flag_asynchronous_unwind_tables
)
1175 dwarf2out_args_size (label
, args_size
);
1180 /* We delay emitting a register save until either (a) we reach the end
1181 of the prologue or (b) the register is clobbered. This clusters
1182 register saves so that there are fewer pc advances. */
1184 struct queued_reg_save
GTY(())
1186 struct queued_reg_save
*next
;
1188 HOST_WIDE_INT cfa_offset
;
1192 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1194 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1195 struct reg_saved_in_data
GTY(()) {
1200 /* A list of registers saved in other registers.
1201 The list intentionally has a small maximum capacity of 4; if your
1202 port needs more than that, you might consider implementing a
1203 more efficient data structure. */
1204 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1205 static GTY(()) size_t num_regs_saved_in_regs
;
1207 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1208 static const char *last_reg_save_label
;
1210 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1211 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1214 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1216 struct queued_reg_save
*q
;
1218 /* Duplicates waste space, but it's also necessary to remove them
1219 for correctness, since the queue gets output in reverse
1221 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1222 if (REGNO (q
->reg
) == REGNO (reg
))
1227 q
= ggc_alloc (sizeof (*q
));
1228 q
->next
= queued_reg_saves
;
1229 queued_reg_saves
= q
;
1233 q
->cfa_offset
= offset
;
1234 q
->saved_reg
= sreg
;
1236 last_reg_save_label
= label
;
1239 /* Output all the entries in QUEUED_REG_SAVES. */
1242 flush_queued_reg_saves (void)
1244 struct queued_reg_save
*q
;
1246 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1249 unsigned int reg
, sreg
;
1251 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1252 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1254 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1256 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1257 num_regs_saved_in_regs
++;
1259 if (i
!= num_regs_saved_in_regs
)
1261 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1262 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1265 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1267 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1269 sreg
= INVALID_REGNUM
;
1270 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1273 queued_reg_saves
= NULL
;
1274 last_reg_save_label
= NULL
;
1277 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1278 location for? Or, does it clobber a register which we've previously
1279 said that some other register is saved in, and for which we now
1280 have a new location for? */
1283 clobbers_queued_reg_save (rtx insn
)
1285 struct queued_reg_save
*q
;
1287 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1290 if (modified_in_p (q
->reg
, insn
))
1292 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1293 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1294 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1301 /* Entry point for saving the first register into the second. */
1304 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1307 unsigned int regno
, sregno
;
1309 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1310 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1312 if (i
== num_regs_saved_in_regs
)
1314 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1315 num_regs_saved_in_regs
++;
1317 regs_saved_in_regs
[i
].orig_reg
= reg
;
1318 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1320 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1321 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1322 reg_save (label
, regno
, sregno
, 0);
1325 /* What register, if any, is currently saved in REG? */
1328 reg_saved_in (rtx reg
)
1330 unsigned int regn
= REGNO (reg
);
1332 struct queued_reg_save
*q
;
1334 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1335 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1338 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1339 if (regs_saved_in_regs
[i
].saved_in_reg
1340 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1341 return regs_saved_in_regs
[i
].orig_reg
;
1347 /* A temporary register holding an integral value used in adjusting SP
1348 or setting up the store_reg. The "offset" field holds the integer
1349 value, not an offset. */
1350 static dw_cfa_location cfa_temp
;
1352 /* Record call frame debugging information for an expression EXPR,
1353 which either sets SP or FP (adjusting how we calculate the frame
1354 address) or saves a register to the stack or another register.
1355 LABEL indicates the address of EXPR.
1357 This function encodes a state machine mapping rtxes to actions on
1358 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1359 users need not read the source code.
1361 The High-Level Picture
1363 Changes in the register we use to calculate the CFA: Currently we
1364 assume that if you copy the CFA register into another register, we
1365 should take the other one as the new CFA register; this seems to
1366 work pretty well. If it's wrong for some target, it's simple
1367 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1369 Changes in the register we use for saving registers to the stack:
1370 This is usually SP, but not always. Again, we deduce that if you
1371 copy SP into another register (and SP is not the CFA register),
1372 then the new register is the one we will be using for register
1373 saves. This also seems to work.
1375 Register saves: There's not much guesswork about this one; if
1376 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1377 register save, and the register used to calculate the destination
1378 had better be the one we think we're using for this purpose.
1379 It's also assumed that a copy from a call-saved register to another
1380 register is saving that register if RTX_FRAME_RELATED_P is set on
1381 that instruction. If the copy is from a call-saved register to
1382 the *same* register, that means that the register is now the same
1383 value as in the caller.
1385 Except: If the register being saved is the CFA register, and the
1386 offset is nonzero, we are saving the CFA, so we assume we have to
1387 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1388 the intent is to save the value of SP from the previous frame.
1390 In addition, if a register has previously been saved to a different
1393 Invariants / Summaries of Rules
1395 cfa current rule for calculating the CFA. It usually
1396 consists of a register and an offset.
1397 cfa_store register used by prologue code to save things to the stack
1398 cfa_store.offset is the offset from the value of
1399 cfa_store.reg to the actual CFA
1400 cfa_temp register holding an integral value. cfa_temp.offset
1401 stores the value, which will be used to adjust the
1402 stack pointer. cfa_temp is also used like cfa_store,
1403 to track stores to the stack via fp or a temp reg.
1405 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1406 with cfa.reg as the first operand changes the cfa.reg and its
1407 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1410 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1411 expression yielding a constant. This sets cfa_temp.reg
1412 and cfa_temp.offset.
1414 Rule 5: Create a new register cfa_store used to save items to the
1417 Rules 10-14: Save a register to the stack. Define offset as the
1418 difference of the original location and cfa_store's
1419 location (or cfa_temp's location if cfa_temp is used).
1423 "{a,b}" indicates a choice of a xor b.
1424 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1427 (set <reg1> <reg2>:cfa.reg)
1428 effects: cfa.reg = <reg1>
1429 cfa.offset unchanged
1430 cfa_temp.reg = <reg1>
1431 cfa_temp.offset = cfa.offset
1434 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1435 {<const_int>,<reg>:cfa_temp.reg}))
1436 effects: cfa.reg = sp if fp used
1437 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1438 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1439 if cfa_store.reg==sp
1442 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1443 effects: cfa.reg = fp
1444 cfa_offset += +/- <const_int>
1447 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1448 constraints: <reg1> != fp
1450 effects: cfa.reg = <reg1>
1451 cfa_temp.reg = <reg1>
1452 cfa_temp.offset = cfa.offset
1455 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1456 constraints: <reg1> != fp
1458 effects: cfa_store.reg = <reg1>
1459 cfa_store.offset = cfa.offset - cfa_temp.offset
1462 (set <reg> <const_int>)
1463 effects: cfa_temp.reg = <reg>
1464 cfa_temp.offset = <const_int>
1467 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1468 effects: cfa_temp.reg = <reg1>
1469 cfa_temp.offset |= <const_int>
1472 (set <reg> (high <exp>))
1476 (set <reg> (lo_sum <exp> <const_int>))
1477 effects: cfa_temp.reg = <reg>
1478 cfa_temp.offset = <const_int>
1481 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1482 effects: cfa_store.offset -= <const_int>
1483 cfa.offset = cfa_store.offset if cfa.reg == sp
1485 cfa.base_offset = -cfa_store.offset
1488 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1489 effects: cfa_store.offset += -/+ mode_size(mem)
1490 cfa.offset = cfa_store.offset if cfa.reg == sp
1492 cfa.base_offset = -cfa_store.offset
1495 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1498 effects: cfa.reg = <reg1>
1499 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1502 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1503 effects: cfa.reg = <reg1>
1504 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1507 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1508 effects: cfa.reg = <reg1>
1509 cfa.base_offset = -cfa_temp.offset
1510 cfa_temp.offset -= mode_size(mem)
1513 (set <reg> {unspec, unspec_volatile})
1514 effects: target-dependent */
1517 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1520 HOST_WIDE_INT offset
;
1522 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1523 the PARALLEL independently. The first element is always processed if
1524 it is a SET. This is for backward compatibility. Other elements
1525 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1526 flag is set in them. */
1527 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1530 int limit
= XVECLEN (expr
, 0);
1532 for (par_index
= 0; par_index
< limit
; par_index
++)
1533 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1534 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1536 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1541 gcc_assert (GET_CODE (expr
) == SET
);
1543 src
= SET_SRC (expr
);
1544 dest
= SET_DEST (expr
);
1548 rtx rsi
= reg_saved_in (src
);
1553 switch (GET_CODE (dest
))
1556 switch (GET_CODE (src
))
1558 /* Setting FP from SP. */
1560 if (cfa
.reg
== (unsigned) REGNO (src
))
1563 /* Update the CFA rule wrt SP or FP. Make sure src is
1564 relative to the current CFA register.
1566 We used to require that dest be either SP or FP, but the
1567 ARM copies SP to a temporary register, and from there to
1568 FP. So we just rely on the backends to only set
1569 RTX_FRAME_RELATED_P on appropriate insns. */
1570 cfa
.reg
= REGNO (dest
);
1571 cfa_temp
.reg
= cfa
.reg
;
1572 cfa_temp
.offset
= cfa
.offset
;
1576 /* Saving a register in a register. */
1577 gcc_assert (!fixed_regs
[REGNO (dest
)]
1578 /* For the SPARC and its register window. */
1579 || (DWARF_FRAME_REGNUM (REGNO (src
))
1580 == DWARF_FRAME_RETURN_COLUMN
));
1581 queue_reg_save (label
, src
, dest
, 0);
1588 if (dest
== stack_pointer_rtx
)
1592 switch (GET_CODE (XEXP (src
, 1)))
1595 offset
= INTVAL (XEXP (src
, 1));
1598 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1600 offset
= cfa_temp
.offset
;
1606 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1608 /* Restoring SP from FP in the epilogue. */
1609 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1610 cfa
.reg
= STACK_POINTER_REGNUM
;
1612 else if (GET_CODE (src
) == LO_SUM
)
1613 /* Assume we've set the source reg of the LO_SUM from sp. */
1616 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1618 if (GET_CODE (src
) != MINUS
)
1620 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1621 cfa
.offset
+= offset
;
1622 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1623 cfa_store
.offset
+= offset
;
1625 else if (dest
== hard_frame_pointer_rtx
)
1628 /* Either setting the FP from an offset of the SP,
1629 or adjusting the FP */
1630 gcc_assert (frame_pointer_needed
);
1632 gcc_assert (REG_P (XEXP (src
, 0))
1633 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1634 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1635 offset
= INTVAL (XEXP (src
, 1));
1636 if (GET_CODE (src
) != MINUS
)
1638 cfa
.offset
+= offset
;
1639 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1643 gcc_assert (GET_CODE (src
) != MINUS
);
1646 if (REG_P (XEXP (src
, 0))
1647 && REGNO (XEXP (src
, 0)) == cfa
.reg
1648 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1650 /* Setting a temporary CFA register that will be copied
1651 into the FP later on. */
1652 offset
= - INTVAL (XEXP (src
, 1));
1653 cfa
.offset
+= offset
;
1654 cfa
.reg
= REGNO (dest
);
1655 /* Or used to save regs to the stack. */
1656 cfa_temp
.reg
= cfa
.reg
;
1657 cfa_temp
.offset
= cfa
.offset
;
1661 else if (REG_P (XEXP (src
, 0))
1662 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1663 && XEXP (src
, 1) == stack_pointer_rtx
)
1665 /* Setting a scratch register that we will use instead
1666 of SP for saving registers to the stack. */
1667 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
1668 cfa_store
.reg
= REGNO (dest
);
1669 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1673 else if (GET_CODE (src
) == LO_SUM
1674 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1676 cfa_temp
.reg
= REGNO (dest
);
1677 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1686 cfa_temp
.reg
= REGNO (dest
);
1687 cfa_temp
.offset
= INTVAL (src
);
1692 gcc_assert (REG_P (XEXP (src
, 0))
1693 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1694 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1696 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1697 cfa_temp
.reg
= REGNO (dest
);
1698 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1701 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1702 which will fill in all of the bits. */
1709 case UNSPEC_VOLATILE
:
1710 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
1711 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
1718 def_cfa_1 (label
, &cfa
);
1722 gcc_assert (REG_P (src
));
1724 /* Saving a register to the stack. Make sure dest is relative to the
1726 switch (GET_CODE (XEXP (dest
, 0)))
1731 /* We can't handle variable size modifications. */
1732 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
1734 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1736 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1737 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1739 cfa_store
.offset
+= offset
;
1740 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1741 cfa
.offset
= cfa_store
.offset
;
1743 offset
= -cfa_store
.offset
;
1749 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1750 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1753 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1754 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1756 cfa_store
.offset
+= offset
;
1757 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1758 cfa
.offset
= cfa_store
.offset
;
1760 offset
= -cfa_store
.offset
;
1764 /* With an offset. */
1771 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
1772 && REG_P (XEXP (XEXP (dest
, 0), 0)));
1773 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1774 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1777 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
1779 if (cfa_store
.reg
== (unsigned) regno
)
1780 offset
-= cfa_store
.offset
;
1783 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1784 offset
-= cfa_temp
.offset
;
1790 /* Without an offset. */
1793 int regno
= REGNO (XEXP (dest
, 0));
1795 if (cfa_store
.reg
== (unsigned) regno
)
1796 offset
= -cfa_store
.offset
;
1799 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1800 offset
= -cfa_temp
.offset
;
1807 gcc_assert (cfa_temp
.reg
1808 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
1809 offset
= -cfa_temp
.offset
;
1810 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1817 if (REGNO (src
) != STACK_POINTER_REGNUM
1818 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1819 && (unsigned) REGNO (src
) == cfa
.reg
)
1821 /* We're storing the current CFA reg into the stack. */
1823 if (cfa
.offset
== 0)
1825 /* If the source register is exactly the CFA, assume
1826 we're saving SP like any other register; this happens
1828 def_cfa_1 (label
, &cfa
);
1829 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1834 /* Otherwise, we'll need to look in the stack to
1835 calculate the CFA. */
1836 rtx x
= XEXP (dest
, 0);
1840 gcc_assert (REG_P (x
));
1842 cfa
.reg
= REGNO (x
);
1843 cfa
.base_offset
= offset
;
1845 def_cfa_1 (label
, &cfa
);
1850 def_cfa_1 (label
, &cfa
);
1851 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1859 /* Record call frame debugging information for INSN, which either
1860 sets SP or FP (adjusting how we calculate the frame address) or saves a
1861 register to the stack. If INSN is NULL_RTX, initialize our state.
1863 If AFTER_P is false, we're being called before the insn is emitted,
1864 otherwise after. Call instructions get invoked twice. */
1867 dwarf2out_frame_debug (rtx insn
, bool after_p
)
1872 if (insn
== NULL_RTX
)
1876 /* Flush any queued register saves. */
1877 flush_queued_reg_saves ();
1879 /* Set up state for generating call frame debug info. */
1882 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
1884 cfa
.reg
= STACK_POINTER_REGNUM
;
1887 cfa_temp
.offset
= 0;
1889 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1891 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1892 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1894 num_regs_saved_in_regs
= 0;
1898 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
1899 flush_queued_reg_saves ();
1901 if (! RTX_FRAME_RELATED_P (insn
))
1903 if (!ACCUMULATE_OUTGOING_ARGS
)
1904 dwarf2out_stack_adjust (insn
, after_p
);
1908 label
= dwarf2out_cfi_label ();
1909 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1911 insn
= XEXP (src
, 0);
1913 insn
= PATTERN (insn
);
1915 dwarf2out_frame_debug_expr (insn
, label
);
1920 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1921 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1922 (enum dwarf_call_frame_info cfi
);
1924 static enum dw_cfi_oprnd_type
1925 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1930 case DW_CFA_GNU_window_save
:
1931 return dw_cfi_oprnd_unused
;
1933 case DW_CFA_set_loc
:
1934 case DW_CFA_advance_loc1
:
1935 case DW_CFA_advance_loc2
:
1936 case DW_CFA_advance_loc4
:
1937 case DW_CFA_MIPS_advance_loc8
:
1938 return dw_cfi_oprnd_addr
;
1941 case DW_CFA_offset_extended
:
1942 case DW_CFA_def_cfa
:
1943 case DW_CFA_offset_extended_sf
:
1944 case DW_CFA_def_cfa_sf
:
1945 case DW_CFA_restore_extended
:
1946 case DW_CFA_undefined
:
1947 case DW_CFA_same_value
:
1948 case DW_CFA_def_cfa_register
:
1949 case DW_CFA_register
:
1950 return dw_cfi_oprnd_reg_num
;
1952 case DW_CFA_def_cfa_offset
:
1953 case DW_CFA_GNU_args_size
:
1954 case DW_CFA_def_cfa_offset_sf
:
1955 return dw_cfi_oprnd_offset
;
1957 case DW_CFA_def_cfa_expression
:
1958 case DW_CFA_expression
:
1959 return dw_cfi_oprnd_loc
;
1966 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1967 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1968 (enum dwarf_call_frame_info cfi
);
1970 static enum dw_cfi_oprnd_type
1971 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1975 case DW_CFA_def_cfa
:
1976 case DW_CFA_def_cfa_sf
:
1978 case DW_CFA_offset_extended_sf
:
1979 case DW_CFA_offset_extended
:
1980 return dw_cfi_oprnd_offset
;
1982 case DW_CFA_register
:
1983 return dw_cfi_oprnd_reg_num
;
1986 return dw_cfi_oprnd_unused
;
1990 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1992 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
1993 switch to the data section instead, and write out a synthetic label
1997 switch_to_eh_frame_section (void)
2001 #ifdef EH_FRAME_SECTION_NAME
2002 if (eh_frame_section
== 0)
2006 if (EH_TABLES_CAN_BE_READ_ONLY
)
2012 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2014 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2016 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2018 flags
= ((! flag_pic
2019 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2020 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2021 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2022 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2023 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2024 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2025 ? 0 : SECTION_WRITE
);
2028 flags
= SECTION_WRITE
;
2029 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2033 if (eh_frame_section
)
2034 switch_to_section (eh_frame_section
);
2037 /* We have no special eh_frame section. Put the information in
2038 the data section and emit special labels to guide collect2. */
2039 switch_to_section (data_section
);
2040 label
= get_file_function_name ('F');
2041 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2042 targetm
.asm_out
.globalize_label (asm_out_file
,
2043 IDENTIFIER_POINTER (label
));
2044 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2048 /* Output a Call Frame Information opcode and its operand(s). */
2051 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2054 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2055 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2056 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2057 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2058 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2059 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2061 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2062 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2063 "DW_CFA_offset, column 0x%lx", r
);
2064 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2066 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2068 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2069 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2070 "DW_CFA_restore, column 0x%lx", r
);
2074 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2075 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2077 switch (cfi
->dw_cfi_opc
)
2079 case DW_CFA_set_loc
:
2081 dw2_asm_output_encoded_addr_rtx (
2082 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2083 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2086 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2087 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2088 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2091 case DW_CFA_advance_loc1
:
2092 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2093 fde
->dw_fde_current_label
, NULL
);
2094 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2097 case DW_CFA_advance_loc2
:
2098 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2099 fde
->dw_fde_current_label
, NULL
);
2100 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2103 case DW_CFA_advance_loc4
:
2104 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2105 fde
->dw_fde_current_label
, NULL
);
2106 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2109 case DW_CFA_MIPS_advance_loc8
:
2110 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2111 fde
->dw_fde_current_label
, NULL
);
2112 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2115 case DW_CFA_offset_extended
:
2116 case DW_CFA_def_cfa
:
2117 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2118 dw2_asm_output_data_uleb128 (r
, NULL
);
2119 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2122 case DW_CFA_offset_extended_sf
:
2123 case DW_CFA_def_cfa_sf
:
2124 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2125 dw2_asm_output_data_uleb128 (r
, NULL
);
2126 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2129 case DW_CFA_restore_extended
:
2130 case DW_CFA_undefined
:
2131 case DW_CFA_same_value
:
2132 case DW_CFA_def_cfa_register
:
2133 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2134 dw2_asm_output_data_uleb128 (r
, NULL
);
2137 case DW_CFA_register
:
2138 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2139 dw2_asm_output_data_uleb128 (r
, NULL
);
2140 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2141 dw2_asm_output_data_uleb128 (r
, NULL
);
2144 case DW_CFA_def_cfa_offset
:
2145 case DW_CFA_GNU_args_size
:
2146 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2149 case DW_CFA_def_cfa_offset_sf
:
2150 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2153 case DW_CFA_GNU_window_save
:
2156 case DW_CFA_def_cfa_expression
:
2157 case DW_CFA_expression
:
2158 output_cfa_loc (cfi
);
2161 case DW_CFA_GNU_negative_offset_extended
:
2162 /* Obsoleted by DW_CFA_offset_extended_sf. */
2171 /* Output the call frame information used to record information
2172 that relates to calculating the frame pointer, and records the
2173 location of saved registers. */
2176 output_call_frame_info (int for_eh
)
2181 char l1
[20], l2
[20], section_start_label
[20];
2182 bool any_lsda_needed
= false;
2183 char augmentation
[6];
2184 int augmentation_size
;
2185 int fde_encoding
= DW_EH_PE_absptr
;
2186 int per_encoding
= DW_EH_PE_absptr
;
2187 int lsda_encoding
= DW_EH_PE_absptr
;
2190 /* Don't emit a CIE if there won't be any FDEs. */
2191 if (fde_table_in_use
== 0)
2194 /* If we make FDEs linkonce, we may have to emit an empty label for
2195 an FDE that wouldn't otherwise be emitted. We want to avoid
2196 having an FDE kept around when the function it refers to is
2197 discarded. Example where this matters: a primary function
2198 template in C++ requires EH information, but an explicit
2199 specialization doesn't. */
2200 if (TARGET_USES_WEAK_UNWIND_INFO
2201 && ! flag_asynchronous_unwind_tables
2203 for (i
= 0; i
< fde_table_in_use
; i
++)
2204 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2205 && !fde_table
[i
].uses_eh_lsda
2206 && ! DECL_WEAK (fde_table
[i
].decl
))
2207 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2208 for_eh
, /* empty */ 1);
2210 /* If we don't have any functions we'll want to unwind out of, don't
2211 emit any EH unwind information. Note that if exceptions aren't
2212 enabled, we won't have collected nothrow information, and if we
2213 asked for asynchronous tables, we always want this info. */
2216 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2218 for (i
= 0; i
< fde_table_in_use
; i
++)
2219 if (fde_table
[i
].uses_eh_lsda
)
2220 any_eh_needed
= any_lsda_needed
= true;
2221 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2222 any_eh_needed
= true;
2223 else if (! fde_table
[i
].nothrow
2224 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2225 any_eh_needed
= true;
2227 if (! any_eh_needed
)
2231 /* We're going to be generating comments, so turn on app. */
2236 switch_to_eh_frame_section ();
2239 if (!debug_frame_section
)
2240 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
2241 SECTION_DEBUG
, NULL
);
2242 switch_to_section (debug_frame_section
);
2245 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2246 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2248 /* Output the CIE. */
2249 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2250 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2251 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2252 dw2_asm_output_data (4, 0xffffffff,
2253 "Initial length escape value indicating 64-bit DWARF extension");
2254 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2255 "Length of Common Information Entry");
2256 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2258 /* Now that the CIE pointer is PC-relative for EH,
2259 use 0 to identify the CIE. */
2260 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2261 (for_eh
? 0 : DWARF_CIE_ID
),
2262 "CIE Identifier Tag");
2264 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2266 augmentation
[0] = 0;
2267 augmentation_size
= 0;
2273 z Indicates that a uleb128 is present to size the
2274 augmentation section.
2275 L Indicates the encoding (and thus presence) of
2276 an LSDA pointer in the FDE augmentation.
2277 R Indicates a non-default pointer encoding for
2279 P Indicates the presence of an encoding + language
2280 personality routine in the CIE augmentation. */
2282 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2283 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2284 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2286 p
= augmentation
+ 1;
2287 if (eh_personality_libfunc
)
2290 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2292 if (any_lsda_needed
)
2295 augmentation_size
+= 1;
2297 if (fde_encoding
!= DW_EH_PE_absptr
)
2300 augmentation_size
+= 1;
2302 if (p
> augmentation
+ 1)
2304 augmentation
[0] = 'z';
2308 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2309 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2311 int offset
= ( 4 /* Length */
2313 + 1 /* CIE version */
2314 + strlen (augmentation
) + 1 /* Augmentation */
2315 + size_of_uleb128 (1) /* Code alignment */
2316 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2318 + 1 /* Augmentation size */
2319 + 1 /* Personality encoding */ );
2320 int pad
= -offset
& (PTR_SIZE
- 1);
2322 augmentation_size
+= pad
;
2324 /* Augmentations should be small, so there's scarce need to
2325 iterate for a solution. Die if we exceed one uleb128 byte. */
2326 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2330 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2331 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2332 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2333 "CIE Data Alignment Factor");
2335 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2336 if (DW_CIE_VERSION
== 1)
2337 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2339 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2341 if (augmentation
[0])
2343 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2344 if (eh_personality_libfunc
)
2346 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2347 eh_data_format_name (per_encoding
));
2348 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2349 eh_personality_libfunc
,
2353 if (any_lsda_needed
)
2354 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2355 eh_data_format_name (lsda_encoding
));
2357 if (fde_encoding
!= DW_EH_PE_absptr
)
2358 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2359 eh_data_format_name (fde_encoding
));
2362 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2363 output_cfi (cfi
, NULL
, for_eh
);
2365 /* Pad the CIE out to an address sized boundary. */
2366 ASM_OUTPUT_ALIGN (asm_out_file
,
2367 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2368 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2370 /* Loop through all of the FDE's. */
2371 for (i
= 0; i
< fde_table_in_use
; i
++)
2373 fde
= &fde_table
[i
];
2375 /* Don't emit EH unwind info for leaf functions that don't need it. */
2376 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2377 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2378 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2379 && !fde
->uses_eh_lsda
)
2382 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2383 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2384 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2385 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2386 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2387 dw2_asm_output_data (4, 0xffffffff,
2388 "Initial length escape value indicating 64-bit DWARF extension");
2389 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2391 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2394 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2396 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2397 debug_frame_section
, "FDE CIE offset");
2401 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2402 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2403 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2406 "FDE initial location");
2407 if (fde
->dw_fde_switched_sections
)
2409 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
2410 fde
->dw_fde_unlikely_section_label
);
2411 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
2412 fde
->dw_fde_hot_section_label
);
2413 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
2414 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
2415 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
2416 "FDE initial location");
2417 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2418 fde
->dw_fde_hot_section_end_label
,
2419 fde
->dw_fde_hot_section_label
,
2420 "FDE address range");
2421 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
2422 "FDE initial location");
2423 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2424 fde
->dw_fde_unlikely_section_end_label
,
2425 fde
->dw_fde_unlikely_section_label
,
2426 "FDE address range");
2429 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2430 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2431 "FDE address range");
2435 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2436 "FDE initial location");
2437 if (fde
->dw_fde_switched_sections
)
2439 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2440 fde
->dw_fde_hot_section_label
,
2441 "FDE initial location");
2442 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2443 fde
->dw_fde_hot_section_end_label
,
2444 fde
->dw_fde_hot_section_label
,
2445 "FDE address range");
2446 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2447 fde
->dw_fde_unlikely_section_label
,
2448 "FDE initial location");
2449 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2450 fde
->dw_fde_unlikely_section_end_label
,
2451 fde
->dw_fde_unlikely_section_label
,
2452 "FDE address range");
2455 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2456 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2457 "FDE address range");
2460 if (augmentation
[0])
2462 if (any_lsda_needed
)
2464 int size
= size_of_encoded_value (lsda_encoding
);
2466 if (lsda_encoding
== DW_EH_PE_aligned
)
2468 int offset
= ( 4 /* Length */
2469 + 4 /* CIE offset */
2470 + 2 * size_of_encoded_value (fde_encoding
)
2471 + 1 /* Augmentation size */ );
2472 int pad
= -offset
& (PTR_SIZE
- 1);
2475 gcc_assert (size_of_uleb128 (size
) == 1);
2478 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2480 if (fde
->uses_eh_lsda
)
2482 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2483 fde
->funcdef_number
);
2484 dw2_asm_output_encoded_addr_rtx (
2485 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2486 false, "Language Specific Data Area");
2490 if (lsda_encoding
== DW_EH_PE_aligned
)
2491 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2493 (size_of_encoded_value (lsda_encoding
), 0,
2494 "Language Specific Data Area (none)");
2498 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2501 /* Loop through the Call Frame Instructions associated with
2503 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2504 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2505 output_cfi (cfi
, fde
, for_eh
);
2507 /* Pad the FDE out to an address sized boundary. */
2508 ASM_OUTPUT_ALIGN (asm_out_file
,
2509 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2510 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2513 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2514 dw2_asm_output_data (4, 0, "End of Table");
2515 #ifdef MIPS_DEBUGGING_INFO
2516 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2517 get a value of 0. Putting .align 0 after the label fixes it. */
2518 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2521 /* Turn off app to make assembly quicker. */
2526 /* Output a marker (i.e. a label) for the beginning of a function, before
2530 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2531 const char *file ATTRIBUTE_UNUSED
)
2533 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2537 current_function_func_begin_label
= NULL
;
2539 #ifdef TARGET_UNWIND_INFO
2540 /* ??? current_function_func_begin_label is also used by except.c
2541 for call-site information. We must emit this label if it might
2543 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2544 && ! dwarf2out_do_frame ())
2547 if (! dwarf2out_do_frame ())
2551 switch_to_section (function_section (current_function_decl
));
2552 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2553 current_function_funcdef_no
);
2554 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2555 current_function_funcdef_no
);
2556 dup_label
= xstrdup (label
);
2557 current_function_func_begin_label
= dup_label
;
2559 #ifdef TARGET_UNWIND_INFO
2560 /* We can elide the fde allocation if we're not emitting debug info. */
2561 if (! dwarf2out_do_frame ())
2565 /* Expand the fde table if necessary. */
2566 if (fde_table_in_use
== fde_table_allocated
)
2568 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2569 fde_table
= ggc_realloc (fde_table
,
2570 fde_table_allocated
* sizeof (dw_fde_node
));
2571 memset (fde_table
+ fde_table_in_use
, 0,
2572 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2575 /* Record the FDE associated with this function. */
2576 current_funcdef_fde
= fde_table_in_use
;
2578 /* Add the new FDE at the end of the fde_table. */
2579 fde
= &fde_table
[fde_table_in_use
++];
2580 fde
->decl
= current_function_decl
;
2581 fde
->dw_fde_begin
= dup_label
;
2582 fde
->dw_fde_current_label
= dup_label
;
2583 fde
->dw_fde_hot_section_label
= NULL
;
2584 fde
->dw_fde_hot_section_end_label
= NULL
;
2585 fde
->dw_fde_unlikely_section_label
= NULL
;
2586 fde
->dw_fde_unlikely_section_end_label
= NULL
;
2587 fde
->dw_fde_switched_sections
= false;
2588 fde
->dw_fde_end
= NULL
;
2589 fde
->dw_fde_cfi
= NULL
;
2590 fde
->funcdef_number
= current_function_funcdef_no
;
2591 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
2592 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2593 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2595 args_size
= old_args_size
= 0;
2597 /* We only want to output line number information for the genuine dwarf2
2598 prologue case, not the eh frame case. */
2599 #ifdef DWARF2_DEBUGGING_INFO
2601 dwarf2out_source_line (line
, file
);
2605 /* Output a marker (i.e. a label) for the absolute end of the generated code
2606 for a function definition. This gets called *after* the epilogue code has
2610 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2611 const char *file ATTRIBUTE_UNUSED
)
2614 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2616 /* Output a label to mark the endpoint of the code generated for this
2618 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2619 current_function_funcdef_no
);
2620 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2621 fde
= &fde_table
[fde_table_in_use
- 1];
2622 fde
->dw_fde_end
= xstrdup (label
);
2626 dwarf2out_frame_init (void)
2628 /* Allocate the initial hunk of the fde_table. */
2629 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2630 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2631 fde_table_in_use
= 0;
2633 /* Generate the CFA instructions common to all FDE's. Do it now for the
2634 sake of lookup_cfa. */
2636 /* On entry, the Canonical Frame Address is at SP. */
2637 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2639 #ifdef DWARF2_UNWIND_INFO
2640 if (DWARF2_UNWIND_INFO
)
2641 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2646 dwarf2out_frame_finish (void)
2648 /* Output call frame information. */
2649 if (DWARF2_FRAME_INFO
)
2650 output_call_frame_info (0);
2652 #ifndef TARGET_UNWIND_INFO
2653 /* Output another copy for the unwinder. */
2654 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2655 output_call_frame_info (1);
2660 /* And now, the subset of the debugging information support code necessary
2661 for emitting location expressions. */
2663 /* Data about a single source file. */
2664 struct dwarf_file_data
GTY(())
2666 const char * filename
;
2670 /* We need some way to distinguish DW_OP_addr with a direct symbol
2671 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2672 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2675 typedef struct dw_val_struct
*dw_val_ref
;
2676 typedef struct die_struct
*dw_die_ref
;
2677 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2678 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2680 /* Each DIE may have a series of attribute/value pairs. Values
2681 can take on several forms. The forms that are used in this
2682 implementation are listed below. */
2687 dw_val_class_offset
,
2689 dw_val_class_loc_list
,
2690 dw_val_class_range_list
,
2692 dw_val_class_unsigned_const
,
2693 dw_val_class_long_long
,
2696 dw_val_class_die_ref
,
2697 dw_val_class_fde_ref
,
2698 dw_val_class_lbl_id
,
2699 dw_val_class_lineptr
,
2701 dw_val_class_macptr
,
2705 /* Describe a double word constant value. */
2706 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2708 typedef struct dw_long_long_struct
GTY(())
2715 /* Describe a floating point constant value, or a vector constant value. */
2717 typedef struct dw_vec_struct
GTY(())
2719 unsigned char * GTY((length ("%h.length"))) array
;
2725 /* The dw_val_node describes an attribute's value, as it is
2726 represented internally. */
2728 typedef struct dw_val_struct
GTY(())
2730 enum dw_val_class val_class
;
2731 union dw_val_struct_union
2733 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2734 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2735 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2736 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2737 HOST_WIDE_INT
GTY ((default)) val_int
;
2738 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2739 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2740 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2741 struct dw_val_die_union
2745 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2746 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2747 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2748 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2749 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2750 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
2752 GTY ((desc ("%1.val_class"))) v
;
2756 /* Locations in memory are described using a sequence of stack machine
2759 typedef struct dw_loc_descr_struct
GTY(())
2761 dw_loc_descr_ref dw_loc_next
;
2762 enum dwarf_location_atom dw_loc_opc
;
2763 dw_val_node dw_loc_oprnd1
;
2764 dw_val_node dw_loc_oprnd2
;
2769 /* Location lists are ranges + location descriptions for that range,
2770 so you can track variables that are in different places over
2771 their entire life. */
2772 typedef struct dw_loc_list_struct
GTY(())
2774 dw_loc_list_ref dw_loc_next
;
2775 const char *begin
; /* Label for begin address of range */
2776 const char *end
; /* Label for end address of range */
2777 char *ll_symbol
; /* Label for beginning of location list.
2778 Only on head of list */
2779 const char *section
; /* Section this loclist is relative to */
2780 dw_loc_descr_ref expr
;
2783 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2785 static const char *dwarf_stack_op_name (unsigned);
2786 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2787 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2788 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2789 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2790 static unsigned long size_of_locs (dw_loc_descr_ref
);
2791 static void output_loc_operands (dw_loc_descr_ref
);
2792 static void output_loc_sequence (dw_loc_descr_ref
);
2794 /* Convert a DWARF stack opcode into its string name. */
2797 dwarf_stack_op_name (unsigned int op
)
2802 case INTERNAL_DW_OP_tls_addr
:
2803 return "DW_OP_addr";
2805 return "DW_OP_deref";
2807 return "DW_OP_const1u";
2809 return "DW_OP_const1s";
2811 return "DW_OP_const2u";
2813 return "DW_OP_const2s";
2815 return "DW_OP_const4u";
2817 return "DW_OP_const4s";
2819 return "DW_OP_const8u";
2821 return "DW_OP_const8s";
2823 return "DW_OP_constu";
2825 return "DW_OP_consts";
2829 return "DW_OP_drop";
2831 return "DW_OP_over";
2833 return "DW_OP_pick";
2835 return "DW_OP_swap";
2839 return "DW_OP_xderef";
2847 return "DW_OP_minus";
2859 return "DW_OP_plus";
2860 case DW_OP_plus_uconst
:
2861 return "DW_OP_plus_uconst";
2867 return "DW_OP_shra";
2885 return "DW_OP_skip";
2887 return "DW_OP_lit0";
2889 return "DW_OP_lit1";
2891 return "DW_OP_lit2";
2893 return "DW_OP_lit3";
2895 return "DW_OP_lit4";
2897 return "DW_OP_lit5";
2899 return "DW_OP_lit6";
2901 return "DW_OP_lit7";
2903 return "DW_OP_lit8";
2905 return "DW_OP_lit9";
2907 return "DW_OP_lit10";
2909 return "DW_OP_lit11";
2911 return "DW_OP_lit12";
2913 return "DW_OP_lit13";
2915 return "DW_OP_lit14";
2917 return "DW_OP_lit15";
2919 return "DW_OP_lit16";
2921 return "DW_OP_lit17";
2923 return "DW_OP_lit18";
2925 return "DW_OP_lit19";
2927 return "DW_OP_lit20";
2929 return "DW_OP_lit21";
2931 return "DW_OP_lit22";
2933 return "DW_OP_lit23";
2935 return "DW_OP_lit24";
2937 return "DW_OP_lit25";
2939 return "DW_OP_lit26";
2941 return "DW_OP_lit27";
2943 return "DW_OP_lit28";
2945 return "DW_OP_lit29";
2947 return "DW_OP_lit30";
2949 return "DW_OP_lit31";
2951 return "DW_OP_reg0";
2953 return "DW_OP_reg1";
2955 return "DW_OP_reg2";
2957 return "DW_OP_reg3";
2959 return "DW_OP_reg4";
2961 return "DW_OP_reg5";
2963 return "DW_OP_reg6";
2965 return "DW_OP_reg7";
2967 return "DW_OP_reg8";
2969 return "DW_OP_reg9";
2971 return "DW_OP_reg10";
2973 return "DW_OP_reg11";
2975 return "DW_OP_reg12";
2977 return "DW_OP_reg13";
2979 return "DW_OP_reg14";
2981 return "DW_OP_reg15";
2983 return "DW_OP_reg16";
2985 return "DW_OP_reg17";
2987 return "DW_OP_reg18";
2989 return "DW_OP_reg19";
2991 return "DW_OP_reg20";
2993 return "DW_OP_reg21";
2995 return "DW_OP_reg22";
2997 return "DW_OP_reg23";
2999 return "DW_OP_reg24";
3001 return "DW_OP_reg25";
3003 return "DW_OP_reg26";
3005 return "DW_OP_reg27";
3007 return "DW_OP_reg28";
3009 return "DW_OP_reg29";
3011 return "DW_OP_reg30";
3013 return "DW_OP_reg31";
3015 return "DW_OP_breg0";
3017 return "DW_OP_breg1";
3019 return "DW_OP_breg2";
3021 return "DW_OP_breg3";
3023 return "DW_OP_breg4";
3025 return "DW_OP_breg5";
3027 return "DW_OP_breg6";
3029 return "DW_OP_breg7";
3031 return "DW_OP_breg8";
3033 return "DW_OP_breg9";
3035 return "DW_OP_breg10";
3037 return "DW_OP_breg11";
3039 return "DW_OP_breg12";
3041 return "DW_OP_breg13";
3043 return "DW_OP_breg14";
3045 return "DW_OP_breg15";
3047 return "DW_OP_breg16";
3049 return "DW_OP_breg17";
3051 return "DW_OP_breg18";
3053 return "DW_OP_breg19";
3055 return "DW_OP_breg20";
3057 return "DW_OP_breg21";
3059 return "DW_OP_breg22";
3061 return "DW_OP_breg23";
3063 return "DW_OP_breg24";
3065 return "DW_OP_breg25";
3067 return "DW_OP_breg26";
3069 return "DW_OP_breg27";
3071 return "DW_OP_breg28";
3073 return "DW_OP_breg29";
3075 return "DW_OP_breg30";
3077 return "DW_OP_breg31";
3079 return "DW_OP_regx";
3081 return "DW_OP_fbreg";
3083 return "DW_OP_bregx";
3085 return "DW_OP_piece";
3086 case DW_OP_deref_size
:
3087 return "DW_OP_deref_size";
3088 case DW_OP_xderef_size
:
3089 return "DW_OP_xderef_size";
3092 case DW_OP_push_object_address
:
3093 return "DW_OP_push_object_address";
3095 return "DW_OP_call2";
3097 return "DW_OP_call4";
3098 case DW_OP_call_ref
:
3099 return "DW_OP_call_ref";
3100 case DW_OP_GNU_push_tls_address
:
3101 return "DW_OP_GNU_push_tls_address";
3103 return "OP_<unknown>";
3107 /* Return a pointer to a newly allocated location description. Location
3108 descriptions are simple expression terms that can be strung
3109 together to form more complicated location (address) descriptions. */
3111 static inline dw_loc_descr_ref
3112 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3113 unsigned HOST_WIDE_INT oprnd2
)
3115 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
3117 descr
->dw_loc_opc
= op
;
3118 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3119 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3120 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3121 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3126 /* Add a location description term to a location description expression. */
3129 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3131 dw_loc_descr_ref
*d
;
3133 /* Find the end of the chain. */
3134 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3140 /* Return the size of a location descriptor. */
3142 static unsigned long
3143 size_of_loc_descr (dw_loc_descr_ref loc
)
3145 unsigned long size
= 1;
3147 switch (loc
->dw_loc_opc
)
3150 case INTERNAL_DW_OP_tls_addr
:
3151 size
+= DWARF2_ADDR_SIZE
;
3170 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3173 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3178 case DW_OP_plus_uconst
:
3179 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3217 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3220 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3223 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3226 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3227 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3230 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3232 case DW_OP_deref_size
:
3233 case DW_OP_xderef_size
:
3242 case DW_OP_call_ref
:
3243 size
+= DWARF2_ADDR_SIZE
;
3252 /* Return the size of a series of location descriptors. */
3254 static unsigned long
3255 size_of_locs (dw_loc_descr_ref loc
)
3260 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3261 field, to avoid writing to a PCH file. */
3262 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3264 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
3266 size
+= size_of_loc_descr (l
);
3271 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3273 l
->dw_loc_addr
= size
;
3274 size
+= size_of_loc_descr (l
);
3280 /* Output location description stack opcode's operands (if any). */
3283 output_loc_operands (dw_loc_descr_ref loc
)
3285 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3286 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3288 switch (loc
->dw_loc_opc
)
3290 #ifdef DWARF2_DEBUGGING_INFO
3292 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3296 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3300 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3304 gcc_assert (HOST_BITS_PER_LONG
>= 64);
3305 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3312 gcc_assert (val1
->val_class
== dw_val_class_loc
);
3313 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3315 dw2_asm_output_data (2, offset
, NULL
);
3328 /* We currently don't make any attempt to make sure these are
3329 aligned properly like we do for the main unwind info, so
3330 don't support emitting things larger than a byte if we're
3331 only doing unwinding. */
3336 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3339 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3342 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3345 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3347 case DW_OP_plus_uconst
:
3348 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3382 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3385 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3388 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3391 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3392 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3395 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3397 case DW_OP_deref_size
:
3398 case DW_OP_xderef_size
:
3399 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3402 case INTERNAL_DW_OP_tls_addr
:
3403 if (targetm
.asm_out
.output_dwarf_dtprel
)
3405 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
3408 fputc ('\n', asm_out_file
);
3415 /* Other codes have no operands. */
3420 /* Output a sequence of location operations. */
3423 output_loc_sequence (dw_loc_descr_ref loc
)
3425 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3427 /* Output the opcode. */
3428 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3429 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3431 /* Output the operand(s) (if any). */
3432 output_loc_operands (loc
);
3436 /* This routine will generate the correct assembly data for a location
3437 description based on a cfi entry with a complex address. */
3440 output_cfa_loc (dw_cfi_ref cfi
)
3442 dw_loc_descr_ref loc
;
3445 /* Output the size of the block. */
3446 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3447 size
= size_of_locs (loc
);
3448 dw2_asm_output_data_uleb128 (size
, NULL
);
3450 /* Now output the operations themselves. */
3451 output_loc_sequence (loc
);
3454 /* This function builds a dwarf location descriptor sequence from a
3455 dw_cfa_location, adding the given OFFSET to the result of the
3458 static struct dw_loc_descr_struct
*
3459 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
3461 struct dw_loc_descr_struct
*head
, *tmp
;
3463 offset
+= cfa
->offset
;
3467 if (cfa
->base_offset
)
3470 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3472 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3474 else if (cfa
->reg
<= 31)
3475 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3477 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3479 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3480 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3481 add_loc_descr (&head
, tmp
);
3484 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3485 add_loc_descr (&head
, tmp
);
3492 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3494 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3495 else if (cfa
->reg
<= 31)
3496 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, offset
, 0);
3498 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, offset
);
3504 /* This function fills in aa dw_cfa_location structure from a dwarf location
3505 descriptor sequence. */
3508 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3510 struct dw_loc_descr_struct
*ptr
;
3512 cfa
->base_offset
= 0;
3516 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3518 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3554 cfa
->reg
= op
- DW_OP_reg0
;
3557 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3591 cfa
->reg
= op
- DW_OP_breg0
;
3592 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3595 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3596 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3601 case DW_OP_plus_uconst
:
3602 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3605 internal_error ("DW_LOC_OP %s not implemented",
3606 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3610 #endif /* .debug_frame support */
3612 /* And now, the support for symbolic debugging information. */
3613 #ifdef DWARF2_DEBUGGING_INFO
3615 /* .debug_str support. */
3616 static int output_indirect_string (void **, void *);
3618 static void dwarf2out_init (const char *);
3619 static void dwarf2out_finish (const char *);
3620 static void dwarf2out_define (unsigned int, const char *);
3621 static void dwarf2out_undef (unsigned int, const char *);
3622 static void dwarf2out_start_source_file (unsigned, const char *);
3623 static void dwarf2out_end_source_file (unsigned);
3624 static void dwarf2out_begin_block (unsigned, unsigned);
3625 static void dwarf2out_end_block (unsigned, unsigned);
3626 static bool dwarf2out_ignore_block (tree
);
3627 static void dwarf2out_global_decl (tree
);
3628 static void dwarf2out_type_decl (tree
, int);
3629 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3630 static void dwarf2out_abstract_function (tree
);
3631 static void dwarf2out_var_location (rtx
);
3632 static void dwarf2out_begin_function (tree
);
3633 static void dwarf2out_switch_text_section (void);
3635 /* The debug hooks structure. */
3637 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3643 dwarf2out_start_source_file
,
3644 dwarf2out_end_source_file
,
3645 dwarf2out_begin_block
,
3646 dwarf2out_end_block
,
3647 dwarf2out_ignore_block
,
3648 dwarf2out_source_line
,
3649 dwarf2out_begin_prologue
,
3650 debug_nothing_int_charstar
, /* end_prologue */
3651 dwarf2out_end_epilogue
,
3652 dwarf2out_begin_function
,
3653 debug_nothing_int
, /* end_function */
3654 dwarf2out_decl
, /* function_decl */
3655 dwarf2out_global_decl
,
3656 dwarf2out_type_decl
, /* type_decl */
3657 dwarf2out_imported_module_or_decl
,
3658 debug_nothing_tree
, /* deferred_inline_function */
3659 /* The DWARF 2 backend tries to reduce debugging bloat by not
3660 emitting the abstract description of inline functions until
3661 something tries to reference them. */
3662 dwarf2out_abstract_function
, /* outlining_inline_function */
3663 debug_nothing_rtx
, /* label */
3664 debug_nothing_int
, /* handle_pch */
3665 dwarf2out_var_location
,
3666 dwarf2out_switch_text_section
,
3667 1 /* start_end_main_source_file */
3671 /* NOTE: In the comments in this file, many references are made to
3672 "Debugging Information Entries". This term is abbreviated as `DIE'
3673 throughout the remainder of this file. */
3675 /* An internal representation of the DWARF output is built, and then
3676 walked to generate the DWARF debugging info. The walk of the internal
3677 representation is done after the entire program has been compiled.
3678 The types below are used to describe the internal representation. */
3680 /* Various DIE's use offsets relative to the beginning of the
3681 .debug_info section to refer to each other. */
3683 typedef long int dw_offset
;
3685 /* Define typedefs here to avoid circular dependencies. */
3687 typedef struct dw_attr_struct
*dw_attr_ref
;
3688 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3689 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3690 typedef struct pubname_struct
*pubname_ref
;
3691 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3693 /* Each entry in the line_info_table maintains the file and
3694 line number associated with the label generated for that
3695 entry. The label gives the PC value associated with
3696 the line number entry. */
3698 typedef struct dw_line_info_struct
GTY(())
3700 unsigned long dw_file_num
;
3701 unsigned long dw_line_num
;
3705 /* Line information for functions in separate sections; each one gets its
3707 typedef struct dw_separate_line_info_struct
GTY(())
3709 unsigned long dw_file_num
;
3710 unsigned long dw_line_num
;
3711 unsigned long function
;
3713 dw_separate_line_info_entry
;
3715 /* Each DIE attribute has a field specifying the attribute kind,
3716 a link to the next attribute in the chain, and an attribute value.
3717 Attributes are typically linked below the DIE they modify. */
3719 typedef struct dw_attr_struct
GTY(())
3721 enum dwarf_attribute dw_attr
;
3722 dw_val_node dw_attr_val
;
3726 DEF_VEC_O(dw_attr_node
);
3727 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
3729 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3730 The children of each node form a circular list linked by
3731 die_sib. die_child points to the node *before* the "first" child node. */
3733 typedef struct die_struct
GTY(())
3735 enum dwarf_tag die_tag
;
3737 VEC(dw_attr_node
,gc
) * die_attr
;
3738 dw_die_ref die_parent
;
3739 dw_die_ref die_child
;
3741 dw_die_ref die_definition
; /* ref from a specification to its definition */
3742 dw_offset die_offset
;
3743 unsigned long die_abbrev
;
3745 /* Die is used and must not be pruned as unused. */
3746 int die_perennial_p
;
3747 unsigned int decl_id
;
3751 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3752 #define FOR_EACH_CHILD(die, c, expr) do { \
3753 c = die->die_child; \
3757 } while (c != die->die_child); \
3760 /* The pubname structure */
3762 typedef struct pubname_struct
GTY(())
3769 struct dw_ranges_struct
GTY(())
3774 /* The limbo die list structure. */
3775 typedef struct limbo_die_struct
GTY(())
3779 struct limbo_die_struct
*next
;
3783 /* How to start an assembler comment. */
3784 #ifndef ASM_COMMENT_START
3785 #define ASM_COMMENT_START ";#"
3788 /* Define a macro which returns nonzero for a TYPE_DECL which was
3789 implicitly generated for a tagged type.
3791 Note that unlike the gcc front end (which generates a NULL named
3792 TYPE_DECL node for each complete tagged type, each array type, and
3793 each function type node created) the g++ front end generates a
3794 _named_ TYPE_DECL node for each tagged type node created.
3795 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3796 generate a DW_TAG_typedef DIE for them. */
3798 #define TYPE_DECL_IS_STUB(decl) \
3799 (DECL_NAME (decl) == NULL_TREE \
3800 || (DECL_ARTIFICIAL (decl) \
3801 && is_tagged_type (TREE_TYPE (decl)) \
3802 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3803 /* This is necessary for stub decls that \
3804 appear in nested inline functions. */ \
3805 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3806 && (decl_ultimate_origin (decl) \
3807 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3809 /* Information concerning the compilation unit's programming
3810 language, and compiler version. */
3812 /* Fixed size portion of the DWARF compilation unit header. */
3813 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3814 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3816 /* Fixed size portion of public names info. */
3817 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3819 /* Fixed size portion of the address range info. */
3820 #define DWARF_ARANGES_HEADER_SIZE \
3821 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3822 DWARF2_ADDR_SIZE * 2) \
3823 - DWARF_INITIAL_LENGTH_SIZE)
3825 /* Size of padding portion in the address range info. It must be
3826 aligned to twice the pointer size. */
3827 #define DWARF_ARANGES_PAD_SIZE \
3828 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3829 DWARF2_ADDR_SIZE * 2) \
3830 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3832 /* Use assembler line directives if available. */
3833 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3834 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3835 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3837 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3841 /* Minimum line offset in a special line info. opcode.
3842 This value was chosen to give a reasonable range of values. */
3843 #define DWARF_LINE_BASE -10
3845 /* First special line opcode - leave room for the standard opcodes. */
3846 #define DWARF_LINE_OPCODE_BASE 10
3848 /* Range of line offsets in a special line info. opcode. */
3849 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3851 /* Flag that indicates the initial value of the is_stmt_start flag.
3852 In the present implementation, we do not mark any lines as
3853 the beginning of a source statement, because that information
3854 is not made available by the GCC front-end. */
3855 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3857 #ifdef DWARF2_DEBUGGING_INFO
3858 /* This location is used by calc_die_sizes() to keep track
3859 the offset of each DIE within the .debug_info section. */
3860 static unsigned long next_die_offset
;
3863 /* Record the root of the DIE's built for the current compilation unit. */
3864 static GTY(()) dw_die_ref comp_unit_die
;
3866 /* A list of DIEs with a NULL parent waiting to be relocated. */
3867 static GTY(()) limbo_die_node
*limbo_die_list
;
3869 /* Filenames referenced by this compilation unit. */
3870 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
3872 /* A hash table of references to DIE's that describe declarations.
3873 The key is a DECL_UID() which is a unique number identifying each decl. */
3874 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3876 /* Node of the variable location list. */
3877 struct var_loc_node
GTY ((chain_next ("%h.next")))
3879 rtx
GTY (()) var_loc_note
;
3880 const char * GTY (()) label
;
3881 const char * GTY (()) section_label
;
3882 struct var_loc_node
* GTY (()) next
;
3885 /* Variable location list. */
3886 struct var_loc_list_def
GTY (())
3888 struct var_loc_node
* GTY (()) first
;
3890 /* Do not mark the last element of the chained list because
3891 it is marked through the chain. */
3892 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3894 /* DECL_UID of the variable decl. */
3895 unsigned int decl_id
;
3897 typedef struct var_loc_list_def var_loc_list
;
3900 /* Table of decl location linked lists. */
3901 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3903 /* A pointer to the base of a list of references to DIE's that
3904 are uniquely identified by their tag, presence/absence of
3905 children DIE's, and list of attribute/value pairs. */
3906 static GTY((length ("abbrev_die_table_allocated")))
3907 dw_die_ref
*abbrev_die_table
;
3909 /* Number of elements currently allocated for abbrev_die_table. */
3910 static GTY(()) unsigned abbrev_die_table_allocated
;
3912 /* Number of elements in type_die_table currently in use. */
3913 static GTY(()) unsigned abbrev_die_table_in_use
;
3915 /* Size (in elements) of increments by which we may expand the
3916 abbrev_die_table. */
3917 #define ABBREV_DIE_TABLE_INCREMENT 256
3919 /* A pointer to the base of a table that contains line information
3920 for each source code line in .text in the compilation unit. */
3921 static GTY((length ("line_info_table_allocated")))
3922 dw_line_info_ref line_info_table
;
3924 /* Number of elements currently allocated for line_info_table. */
3925 static GTY(()) unsigned line_info_table_allocated
;
3927 /* Number of elements in line_info_table currently in use. */
3928 static GTY(()) unsigned line_info_table_in_use
;
3930 /* True if the compilation unit places functions in more than one section. */
3931 static GTY(()) bool have_multiple_function_sections
= false;
3933 /* A pointer to the base of a table that contains line information
3934 for each source code line outside of .text in the compilation unit. */
3935 static GTY ((length ("separate_line_info_table_allocated")))
3936 dw_separate_line_info_ref separate_line_info_table
;
3938 /* Number of elements currently allocated for separate_line_info_table. */
3939 static GTY(()) unsigned separate_line_info_table_allocated
;
3941 /* Number of elements in separate_line_info_table currently in use. */
3942 static GTY(()) unsigned separate_line_info_table_in_use
;
3944 /* Size (in elements) of increments by which we may expand the
3946 #define LINE_INFO_TABLE_INCREMENT 1024
3948 /* A pointer to the base of a table that contains a list of publicly
3949 accessible names. */
3950 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3952 /* Number of elements currently allocated for pubname_table. */
3953 static GTY(()) unsigned pubname_table_allocated
;
3955 /* Number of elements in pubname_table currently in use. */
3956 static GTY(()) unsigned pubname_table_in_use
;
3958 /* Size (in elements) of increments by which we may expand the
3960 #define PUBNAME_TABLE_INCREMENT 64
3962 /* Array of dies for which we should generate .debug_arange info. */
3963 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3965 /* Number of elements currently allocated for arange_table. */
3966 static GTY(()) unsigned arange_table_allocated
;
3968 /* Number of elements in arange_table currently in use. */
3969 static GTY(()) unsigned arange_table_in_use
;
3971 /* Size (in elements) of increments by which we may expand the
3973 #define ARANGE_TABLE_INCREMENT 64
3975 /* Array of dies for which we should generate .debug_ranges info. */
3976 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3978 /* Number of elements currently allocated for ranges_table. */
3979 static GTY(()) unsigned ranges_table_allocated
;
3981 /* Number of elements in ranges_table currently in use. */
3982 static GTY(()) unsigned ranges_table_in_use
;
3984 /* Size (in elements) of increments by which we may expand the
3986 #define RANGES_TABLE_INCREMENT 64
3988 /* Whether we have location lists that need outputting */
3989 static GTY(()) bool have_location_lists
;
3991 /* Unique label counter. */
3992 static GTY(()) unsigned int loclabel_num
;
3994 #ifdef DWARF2_DEBUGGING_INFO
3995 /* Record whether the function being analyzed contains inlined functions. */
3996 static int current_function_has_inlines
;
3998 #if 0 && defined (MIPS_DEBUGGING_INFO)
3999 static int comp_unit_has_inlines
;
4002 /* The last file entry emitted by maybe_emit_file(). */
4003 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
4005 /* Number of internal labels generated by gen_internal_sym(). */
4006 static GTY(()) int label_num
;
4008 /* Cached result of previous call to lookup_filename. */
4009 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
4011 #ifdef DWARF2_DEBUGGING_INFO
4013 /* Offset from the "steady-state frame pointer" to the frame base,
4014 within the current function. */
4015 static HOST_WIDE_INT frame_pointer_fb_offset
;
4017 /* Forward declarations for functions defined in this file. */
4019 static int is_pseudo_reg (rtx
);
4020 static tree
type_main_variant (tree
);
4021 static int is_tagged_type (tree
);
4022 static const char *dwarf_tag_name (unsigned);
4023 static const char *dwarf_attr_name (unsigned);
4024 static const char *dwarf_form_name (unsigned);
4025 static tree
decl_ultimate_origin (tree
);
4026 static tree
block_ultimate_origin (tree
);
4027 static tree
decl_class_context (tree
);
4028 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
4029 static inline enum dw_val_class
AT_class (dw_attr_ref
);
4030 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
4031 static inline unsigned AT_flag (dw_attr_ref
);
4032 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
4033 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
4034 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
4035 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
4036 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
4038 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
4039 unsigned int, unsigned char *);
4040 static hashval_t
debug_str_do_hash (const void *);
4041 static int debug_str_eq (const void *, const void *);
4042 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
4043 static inline const char *AT_string (dw_attr_ref
);
4044 static int AT_string_form (dw_attr_ref
);
4045 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
4046 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
4047 static inline dw_die_ref
AT_ref (dw_attr_ref
);
4048 static inline int AT_ref_external (dw_attr_ref
);
4049 static inline void set_AT_ref_external (dw_attr_ref
, int);
4050 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
4051 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
4052 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
4053 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
4055 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
4056 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
4057 static inline rtx
AT_addr (dw_attr_ref
);
4058 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
4059 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4060 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4061 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
4062 unsigned HOST_WIDE_INT
);
4063 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
4065 static inline const char *AT_lbl (dw_attr_ref
);
4066 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
4067 static const char *get_AT_low_pc (dw_die_ref
);
4068 static const char *get_AT_hi_pc (dw_die_ref
);
4069 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4070 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4071 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4072 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4073 static bool is_c_family (void);
4074 static bool is_cxx (void);
4075 static bool is_java (void);
4076 static bool is_fortran (void);
4077 static bool is_ada (void);
4078 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4079 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4080 static void add_child_die (dw_die_ref
, dw_die_ref
);
4081 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4082 static dw_die_ref
lookup_type_die (tree
);
4083 static void equate_type_number_to_die (tree
, dw_die_ref
);
4084 static hashval_t
decl_die_table_hash (const void *);
4085 static int decl_die_table_eq (const void *, const void *);
4086 static dw_die_ref
lookup_decl_die (tree
);
4087 static hashval_t
decl_loc_table_hash (const void *);
4088 static int decl_loc_table_eq (const void *, const void *);
4089 static var_loc_list
*lookup_decl_loc (tree
);
4090 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4091 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4092 static void print_spaces (FILE *);
4093 static void print_die (dw_die_ref
, FILE *);
4094 static void print_dwarf_line_table (FILE *);
4095 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4096 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4097 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4098 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4099 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4100 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4101 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
4102 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4103 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4104 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4105 static void compute_section_prefix (dw_die_ref
);
4106 static int is_type_die (dw_die_ref
);
4107 static int is_comdat_die (dw_die_ref
);
4108 static int is_symbol_die (dw_die_ref
);
4109 static void assign_symbol_names (dw_die_ref
);
4110 static void break_out_includes (dw_die_ref
);
4111 static hashval_t
htab_cu_hash (const void *);
4112 static int htab_cu_eq (const void *, const void *);
4113 static void htab_cu_del (void *);
4114 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4115 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4116 static void add_sibling_attributes (dw_die_ref
);
4117 static void build_abbrev_table (dw_die_ref
);
4118 static void output_location_lists (dw_die_ref
);
4119 static int constant_size (long unsigned);
4120 static unsigned long size_of_die (dw_die_ref
);
4121 static void calc_die_sizes (dw_die_ref
);
4122 static void mark_dies (dw_die_ref
);
4123 static void unmark_dies (dw_die_ref
);
4124 static void unmark_all_dies (dw_die_ref
);
4125 static unsigned long size_of_pubnames (void);
4126 static unsigned long size_of_aranges (void);
4127 static enum dwarf_form
value_format (dw_attr_ref
);
4128 static void output_value_format (dw_attr_ref
);
4129 static void output_abbrev_section (void);
4130 static void output_die_symbol (dw_die_ref
);
4131 static void output_die (dw_die_ref
);
4132 static void output_compilation_unit_header (void);
4133 static void output_comp_unit (dw_die_ref
, int);
4134 static const char *dwarf2_name (tree
, int);
4135 static void add_pubname (tree
, dw_die_ref
);
4136 static void output_pubnames (void);
4137 static void add_arange (tree
, dw_die_ref
);
4138 static void output_aranges (void);
4139 static unsigned int add_ranges (tree
);
4140 static void output_ranges (void);
4141 static void output_line_info (void);
4142 static void output_file_names (void);
4143 static dw_die_ref
base_type_die (tree
);
4144 static tree
root_type (tree
);
4145 static int is_base_type (tree
);
4146 static bool is_subrange_type (tree
);
4147 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
4148 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
4149 static int type_is_enum (tree
);
4150 static unsigned int dbx_reg_number (rtx
);
4151 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
4152 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
4153 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
4154 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
4155 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4156 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
);
4157 static int is_based_loc (rtx
);
4158 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
);
4159 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
4160 static dw_loc_descr_ref
loc_descriptor (rtx
);
4161 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
4162 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
4163 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
4164 static tree
field_type (tree
);
4165 static unsigned int simple_type_align_in_bits (tree
);
4166 static unsigned int simple_decl_align_in_bits (tree
);
4167 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
4168 static HOST_WIDE_INT
field_byte_offset (tree
);
4169 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
4171 static void add_data_member_location_attribute (dw_die_ref
, tree
);
4172 static void add_const_value_attribute (dw_die_ref
, rtx
);
4173 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
4174 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4175 static void insert_float (rtx
, unsigned char *);
4176 static rtx
rtl_for_decl_location (tree
);
4177 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
4178 enum dwarf_attribute
);
4179 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
4180 static void add_name_attribute (dw_die_ref
, const char *);
4181 static void add_comp_dir_attribute (dw_die_ref
);
4182 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
4183 static void add_subscript_info (dw_die_ref
, tree
);
4184 static void add_byte_size_attribute (dw_die_ref
, tree
);
4185 static void add_bit_offset_attribute (dw_die_ref
, tree
);
4186 static void add_bit_size_attribute (dw_die_ref
, tree
);
4187 static void add_prototyped_attribute (dw_die_ref
, tree
);
4188 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
4189 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
4190 static void add_src_coords_attributes (dw_die_ref
, tree
);
4191 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
4192 static void push_decl_scope (tree
);
4193 static void pop_decl_scope (void);
4194 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
4195 static inline int local_scope_p (dw_die_ref
);
4196 static inline int class_or_namespace_scope_p (dw_die_ref
);
4197 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
4198 static void add_calling_convention_attribute (dw_die_ref
, tree
);
4199 static const char *type_tag (tree
);
4200 static tree
member_declared_type (tree
);
4202 static const char *decl_start_label (tree
);
4204 static void gen_array_type_die (tree
, dw_die_ref
);
4206 static void gen_entry_point_die (tree
, dw_die_ref
);
4208 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
4209 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
4210 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
4211 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
4212 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
4213 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
4214 static void gen_formal_types_die (tree
, dw_die_ref
);
4215 static void gen_subprogram_die (tree
, dw_die_ref
);
4216 static void gen_variable_die (tree
, dw_die_ref
);
4217 static void gen_label_die (tree
, dw_die_ref
);
4218 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
4219 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
4220 static void gen_field_die (tree
, dw_die_ref
);
4221 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
4222 static dw_die_ref
gen_compile_unit_die (const char *);
4223 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
4224 static void gen_member_die (tree
, dw_die_ref
);
4225 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
4226 static void gen_subroutine_type_die (tree
, dw_die_ref
);
4227 static void gen_typedef_die (tree
, dw_die_ref
);
4228 static void gen_type_die (tree
, dw_die_ref
);
4229 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
4230 static void gen_block_die (tree
, dw_die_ref
, int);
4231 static void decls_for_scope (tree
, dw_die_ref
, int);
4232 static int is_redundant_typedef (tree
);
4233 static void gen_namespace_die (tree
);
4234 static void gen_decl_die (tree
, dw_die_ref
);
4235 static dw_die_ref
force_decl_die (tree
);
4236 static dw_die_ref
force_type_die (tree
);
4237 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
4238 static void declare_in_namespace (tree
, dw_die_ref
);
4239 static struct dwarf_file_data
* lookup_filename (const char *);
4240 static void retry_incomplete_types (void);
4241 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
4242 static void splice_child_die (dw_die_ref
, dw_die_ref
);
4243 static int file_info_cmp (const void *, const void *);
4244 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
4245 const char *, const char *, unsigned);
4246 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4247 const char *, const char *,
4249 static void output_loc_list (dw_loc_list_ref
);
4250 static char *gen_internal_sym (const char *);
4252 static void prune_unmark_dies (dw_die_ref
);
4253 static void prune_unused_types_mark (dw_die_ref
, int);
4254 static void prune_unused_types_walk (dw_die_ref
);
4255 static void prune_unused_types_walk_attribs (dw_die_ref
);
4256 static void prune_unused_types_prune (dw_die_ref
);
4257 static void prune_unused_types (void);
4258 static int maybe_emit_file (struct dwarf_file_data
*fd
);
4260 /* Section names used to hold DWARF debugging information. */
4261 #ifndef DEBUG_INFO_SECTION
4262 #define DEBUG_INFO_SECTION ".debug_info"
4264 #ifndef DEBUG_ABBREV_SECTION
4265 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4267 #ifndef DEBUG_ARANGES_SECTION
4268 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4270 #ifndef DEBUG_MACINFO_SECTION
4271 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4273 #ifndef DEBUG_LINE_SECTION
4274 #define DEBUG_LINE_SECTION ".debug_line"
4276 #ifndef DEBUG_LOC_SECTION
4277 #define DEBUG_LOC_SECTION ".debug_loc"
4279 #ifndef DEBUG_PUBNAMES_SECTION
4280 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4282 #ifndef DEBUG_STR_SECTION
4283 #define DEBUG_STR_SECTION ".debug_str"
4285 #ifndef DEBUG_RANGES_SECTION
4286 #define DEBUG_RANGES_SECTION ".debug_ranges"
4289 /* Standard ELF section names for compiled code and data. */
4290 #ifndef TEXT_SECTION_NAME
4291 #define TEXT_SECTION_NAME ".text"
4294 /* Section flags for .debug_str section. */
4295 #define DEBUG_STR_SECTION_FLAGS \
4296 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4297 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4300 /* Labels we insert at beginning sections we can reference instead of
4301 the section names themselves. */
4303 #ifndef TEXT_SECTION_LABEL
4304 #define TEXT_SECTION_LABEL "Ltext"
4306 #ifndef COLD_TEXT_SECTION_LABEL
4307 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4309 #ifndef DEBUG_LINE_SECTION_LABEL
4310 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4312 #ifndef DEBUG_INFO_SECTION_LABEL
4313 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4315 #ifndef DEBUG_ABBREV_SECTION_LABEL
4316 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4318 #ifndef DEBUG_LOC_SECTION_LABEL
4319 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4321 #ifndef DEBUG_RANGES_SECTION_LABEL
4322 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4324 #ifndef DEBUG_MACINFO_SECTION_LABEL
4325 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4328 /* Definitions of defaults for formats and names of various special
4329 (artificial) labels which may be generated within this file (when the -g
4330 options is used and DWARF2_DEBUGGING_INFO is in effect.
4331 If necessary, these may be overridden from within the tm.h file, but
4332 typically, overriding these defaults is unnecessary. */
4334 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4335 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4336 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4337 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4338 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4339 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4340 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4341 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4342 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4343 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4345 #ifndef TEXT_END_LABEL
4346 #define TEXT_END_LABEL "Letext"
4348 #ifndef COLD_END_LABEL
4349 #define COLD_END_LABEL "Letext_cold"
4351 #ifndef BLOCK_BEGIN_LABEL
4352 #define BLOCK_BEGIN_LABEL "LBB"
4354 #ifndef BLOCK_END_LABEL
4355 #define BLOCK_END_LABEL "LBE"
4357 #ifndef LINE_CODE_LABEL
4358 #define LINE_CODE_LABEL "LM"
4360 #ifndef SEPARATE_LINE_CODE_LABEL
4361 #define SEPARATE_LINE_CODE_LABEL "LSM"
4364 /* We allow a language front-end to designate a function that is to be
4365 called to "demangle" any name before it is put into a DIE. */
4367 static const char *(*demangle_name_func
) (const char *);
4370 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4372 demangle_name_func
= func
;
4375 /* Test if rtl node points to a pseudo register. */
4378 is_pseudo_reg (rtx rtl
)
4380 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4381 || (GET_CODE (rtl
) == SUBREG
4382 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4385 /* Return a reference to a type, with its const and volatile qualifiers
4389 type_main_variant (tree type
)
4391 type
= TYPE_MAIN_VARIANT (type
);
4393 /* ??? There really should be only one main variant among any group of
4394 variants of a given type (and all of the MAIN_VARIANT values for all
4395 members of the group should point to that one type) but sometimes the C
4396 front-end messes this up for array types, so we work around that bug
4398 if (TREE_CODE (type
) == ARRAY_TYPE
)
4399 while (type
!= TYPE_MAIN_VARIANT (type
))
4400 type
= TYPE_MAIN_VARIANT (type
);
4405 /* Return nonzero if the given type node represents a tagged type. */
4408 is_tagged_type (tree type
)
4410 enum tree_code code
= TREE_CODE (type
);
4412 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4413 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4416 /* Convert a DIE tag into its string name. */
4419 dwarf_tag_name (unsigned int tag
)
4423 case DW_TAG_padding
:
4424 return "DW_TAG_padding";
4425 case DW_TAG_array_type
:
4426 return "DW_TAG_array_type";
4427 case DW_TAG_class_type
:
4428 return "DW_TAG_class_type";
4429 case DW_TAG_entry_point
:
4430 return "DW_TAG_entry_point";
4431 case DW_TAG_enumeration_type
:
4432 return "DW_TAG_enumeration_type";
4433 case DW_TAG_formal_parameter
:
4434 return "DW_TAG_formal_parameter";
4435 case DW_TAG_imported_declaration
:
4436 return "DW_TAG_imported_declaration";
4438 return "DW_TAG_label";
4439 case DW_TAG_lexical_block
:
4440 return "DW_TAG_lexical_block";
4442 return "DW_TAG_member";
4443 case DW_TAG_pointer_type
:
4444 return "DW_TAG_pointer_type";
4445 case DW_TAG_reference_type
:
4446 return "DW_TAG_reference_type";
4447 case DW_TAG_compile_unit
:
4448 return "DW_TAG_compile_unit";
4449 case DW_TAG_string_type
:
4450 return "DW_TAG_string_type";
4451 case DW_TAG_structure_type
:
4452 return "DW_TAG_structure_type";
4453 case DW_TAG_subroutine_type
:
4454 return "DW_TAG_subroutine_type";
4455 case DW_TAG_typedef
:
4456 return "DW_TAG_typedef";
4457 case DW_TAG_union_type
:
4458 return "DW_TAG_union_type";
4459 case DW_TAG_unspecified_parameters
:
4460 return "DW_TAG_unspecified_parameters";
4461 case DW_TAG_variant
:
4462 return "DW_TAG_variant";
4463 case DW_TAG_common_block
:
4464 return "DW_TAG_common_block";
4465 case DW_TAG_common_inclusion
:
4466 return "DW_TAG_common_inclusion";
4467 case DW_TAG_inheritance
:
4468 return "DW_TAG_inheritance";
4469 case DW_TAG_inlined_subroutine
:
4470 return "DW_TAG_inlined_subroutine";
4472 return "DW_TAG_module";
4473 case DW_TAG_ptr_to_member_type
:
4474 return "DW_TAG_ptr_to_member_type";
4475 case DW_TAG_set_type
:
4476 return "DW_TAG_set_type";
4477 case DW_TAG_subrange_type
:
4478 return "DW_TAG_subrange_type";
4479 case DW_TAG_with_stmt
:
4480 return "DW_TAG_with_stmt";
4481 case DW_TAG_access_declaration
:
4482 return "DW_TAG_access_declaration";
4483 case DW_TAG_base_type
:
4484 return "DW_TAG_base_type";
4485 case DW_TAG_catch_block
:
4486 return "DW_TAG_catch_block";
4487 case DW_TAG_const_type
:
4488 return "DW_TAG_const_type";
4489 case DW_TAG_constant
:
4490 return "DW_TAG_constant";
4491 case DW_TAG_enumerator
:
4492 return "DW_TAG_enumerator";
4493 case DW_TAG_file_type
:
4494 return "DW_TAG_file_type";
4496 return "DW_TAG_friend";
4497 case DW_TAG_namelist
:
4498 return "DW_TAG_namelist";
4499 case DW_TAG_namelist_item
:
4500 return "DW_TAG_namelist_item";
4501 case DW_TAG_namespace
:
4502 return "DW_TAG_namespace";
4503 case DW_TAG_packed_type
:
4504 return "DW_TAG_packed_type";
4505 case DW_TAG_subprogram
:
4506 return "DW_TAG_subprogram";
4507 case DW_TAG_template_type_param
:
4508 return "DW_TAG_template_type_param";
4509 case DW_TAG_template_value_param
:
4510 return "DW_TAG_template_value_param";
4511 case DW_TAG_thrown_type
:
4512 return "DW_TAG_thrown_type";
4513 case DW_TAG_try_block
:
4514 return "DW_TAG_try_block";
4515 case DW_TAG_variant_part
:
4516 return "DW_TAG_variant_part";
4517 case DW_TAG_variable
:
4518 return "DW_TAG_variable";
4519 case DW_TAG_volatile_type
:
4520 return "DW_TAG_volatile_type";
4521 case DW_TAG_imported_module
:
4522 return "DW_TAG_imported_module";
4523 case DW_TAG_MIPS_loop
:
4524 return "DW_TAG_MIPS_loop";
4525 case DW_TAG_format_label
:
4526 return "DW_TAG_format_label";
4527 case DW_TAG_function_template
:
4528 return "DW_TAG_function_template";
4529 case DW_TAG_class_template
:
4530 return "DW_TAG_class_template";
4531 case DW_TAG_GNU_BINCL
:
4532 return "DW_TAG_GNU_BINCL";
4533 case DW_TAG_GNU_EINCL
:
4534 return "DW_TAG_GNU_EINCL";
4536 return "DW_TAG_<unknown>";
4540 /* Convert a DWARF attribute code into its string name. */
4543 dwarf_attr_name (unsigned int attr
)
4548 return "DW_AT_sibling";
4549 case DW_AT_location
:
4550 return "DW_AT_location";
4552 return "DW_AT_name";
4553 case DW_AT_ordering
:
4554 return "DW_AT_ordering";
4555 case DW_AT_subscr_data
:
4556 return "DW_AT_subscr_data";
4557 case DW_AT_byte_size
:
4558 return "DW_AT_byte_size";
4559 case DW_AT_bit_offset
:
4560 return "DW_AT_bit_offset";
4561 case DW_AT_bit_size
:
4562 return "DW_AT_bit_size";
4563 case DW_AT_element_list
:
4564 return "DW_AT_element_list";
4565 case DW_AT_stmt_list
:
4566 return "DW_AT_stmt_list";
4568 return "DW_AT_low_pc";
4570 return "DW_AT_high_pc";
4571 case DW_AT_language
:
4572 return "DW_AT_language";
4574 return "DW_AT_member";
4576 return "DW_AT_discr";
4577 case DW_AT_discr_value
:
4578 return "DW_AT_discr_value";
4579 case DW_AT_visibility
:
4580 return "DW_AT_visibility";
4582 return "DW_AT_import";
4583 case DW_AT_string_length
:
4584 return "DW_AT_string_length";
4585 case DW_AT_common_reference
:
4586 return "DW_AT_common_reference";
4587 case DW_AT_comp_dir
:
4588 return "DW_AT_comp_dir";
4589 case DW_AT_const_value
:
4590 return "DW_AT_const_value";
4591 case DW_AT_containing_type
:
4592 return "DW_AT_containing_type";
4593 case DW_AT_default_value
:
4594 return "DW_AT_default_value";
4596 return "DW_AT_inline";
4597 case DW_AT_is_optional
:
4598 return "DW_AT_is_optional";
4599 case DW_AT_lower_bound
:
4600 return "DW_AT_lower_bound";
4601 case DW_AT_producer
:
4602 return "DW_AT_producer";
4603 case DW_AT_prototyped
:
4604 return "DW_AT_prototyped";
4605 case DW_AT_return_addr
:
4606 return "DW_AT_return_addr";
4607 case DW_AT_start_scope
:
4608 return "DW_AT_start_scope";
4609 case DW_AT_stride_size
:
4610 return "DW_AT_stride_size";
4611 case DW_AT_upper_bound
:
4612 return "DW_AT_upper_bound";
4613 case DW_AT_abstract_origin
:
4614 return "DW_AT_abstract_origin";
4615 case DW_AT_accessibility
:
4616 return "DW_AT_accessibility";
4617 case DW_AT_address_class
:
4618 return "DW_AT_address_class";
4619 case DW_AT_artificial
:
4620 return "DW_AT_artificial";
4621 case DW_AT_base_types
:
4622 return "DW_AT_base_types";
4623 case DW_AT_calling_convention
:
4624 return "DW_AT_calling_convention";
4626 return "DW_AT_count";
4627 case DW_AT_data_member_location
:
4628 return "DW_AT_data_member_location";
4629 case DW_AT_decl_column
:
4630 return "DW_AT_decl_column";
4631 case DW_AT_decl_file
:
4632 return "DW_AT_decl_file";
4633 case DW_AT_decl_line
:
4634 return "DW_AT_decl_line";
4635 case DW_AT_declaration
:
4636 return "DW_AT_declaration";
4637 case DW_AT_discr_list
:
4638 return "DW_AT_discr_list";
4639 case DW_AT_encoding
:
4640 return "DW_AT_encoding";
4641 case DW_AT_external
:
4642 return "DW_AT_external";
4643 case DW_AT_frame_base
:
4644 return "DW_AT_frame_base";
4646 return "DW_AT_friend";
4647 case DW_AT_identifier_case
:
4648 return "DW_AT_identifier_case";
4649 case DW_AT_macro_info
:
4650 return "DW_AT_macro_info";
4651 case DW_AT_namelist_items
:
4652 return "DW_AT_namelist_items";
4653 case DW_AT_priority
:
4654 return "DW_AT_priority";
4656 return "DW_AT_segment";
4657 case DW_AT_specification
:
4658 return "DW_AT_specification";
4659 case DW_AT_static_link
:
4660 return "DW_AT_static_link";
4662 return "DW_AT_type";
4663 case DW_AT_use_location
:
4664 return "DW_AT_use_location";
4665 case DW_AT_variable_parameter
:
4666 return "DW_AT_variable_parameter";
4667 case DW_AT_virtuality
:
4668 return "DW_AT_virtuality";
4669 case DW_AT_vtable_elem_location
:
4670 return "DW_AT_vtable_elem_location";
4672 case DW_AT_allocated
:
4673 return "DW_AT_allocated";
4674 case DW_AT_associated
:
4675 return "DW_AT_associated";
4676 case DW_AT_data_location
:
4677 return "DW_AT_data_location";
4679 return "DW_AT_stride";
4680 case DW_AT_entry_pc
:
4681 return "DW_AT_entry_pc";
4682 case DW_AT_use_UTF8
:
4683 return "DW_AT_use_UTF8";
4684 case DW_AT_extension
:
4685 return "DW_AT_extension";
4687 return "DW_AT_ranges";
4688 case DW_AT_trampoline
:
4689 return "DW_AT_trampoline";
4690 case DW_AT_call_column
:
4691 return "DW_AT_call_column";
4692 case DW_AT_call_file
:
4693 return "DW_AT_call_file";
4694 case DW_AT_call_line
:
4695 return "DW_AT_call_line";
4697 case DW_AT_MIPS_fde
:
4698 return "DW_AT_MIPS_fde";
4699 case DW_AT_MIPS_loop_begin
:
4700 return "DW_AT_MIPS_loop_begin";
4701 case DW_AT_MIPS_tail_loop_begin
:
4702 return "DW_AT_MIPS_tail_loop_begin";
4703 case DW_AT_MIPS_epilog_begin
:
4704 return "DW_AT_MIPS_epilog_begin";
4705 case DW_AT_MIPS_loop_unroll_factor
:
4706 return "DW_AT_MIPS_loop_unroll_factor";
4707 case DW_AT_MIPS_software_pipeline_depth
:
4708 return "DW_AT_MIPS_software_pipeline_depth";
4709 case DW_AT_MIPS_linkage_name
:
4710 return "DW_AT_MIPS_linkage_name";
4711 case DW_AT_MIPS_stride
:
4712 return "DW_AT_MIPS_stride";
4713 case DW_AT_MIPS_abstract_name
:
4714 return "DW_AT_MIPS_abstract_name";
4715 case DW_AT_MIPS_clone_origin
:
4716 return "DW_AT_MIPS_clone_origin";
4717 case DW_AT_MIPS_has_inlines
:
4718 return "DW_AT_MIPS_has_inlines";
4720 case DW_AT_sf_names
:
4721 return "DW_AT_sf_names";
4722 case DW_AT_src_info
:
4723 return "DW_AT_src_info";
4724 case DW_AT_mac_info
:
4725 return "DW_AT_mac_info";
4726 case DW_AT_src_coords
:
4727 return "DW_AT_src_coords";
4728 case DW_AT_body_begin
:
4729 return "DW_AT_body_begin";
4730 case DW_AT_body_end
:
4731 return "DW_AT_body_end";
4732 case DW_AT_GNU_vector
:
4733 return "DW_AT_GNU_vector";
4735 case DW_AT_VMS_rtnbeg_pd_address
:
4736 return "DW_AT_VMS_rtnbeg_pd_address";
4739 return "DW_AT_<unknown>";
4743 /* Convert a DWARF value form code into its string name. */
4746 dwarf_form_name (unsigned int form
)
4751 return "DW_FORM_addr";
4752 case DW_FORM_block2
:
4753 return "DW_FORM_block2";
4754 case DW_FORM_block4
:
4755 return "DW_FORM_block4";
4757 return "DW_FORM_data2";
4759 return "DW_FORM_data4";
4761 return "DW_FORM_data8";
4762 case DW_FORM_string
:
4763 return "DW_FORM_string";
4765 return "DW_FORM_block";
4766 case DW_FORM_block1
:
4767 return "DW_FORM_block1";
4769 return "DW_FORM_data1";
4771 return "DW_FORM_flag";
4773 return "DW_FORM_sdata";
4775 return "DW_FORM_strp";
4777 return "DW_FORM_udata";
4778 case DW_FORM_ref_addr
:
4779 return "DW_FORM_ref_addr";
4781 return "DW_FORM_ref1";
4783 return "DW_FORM_ref2";
4785 return "DW_FORM_ref4";
4787 return "DW_FORM_ref8";
4788 case DW_FORM_ref_udata
:
4789 return "DW_FORM_ref_udata";
4790 case DW_FORM_indirect
:
4791 return "DW_FORM_indirect";
4793 return "DW_FORM_<unknown>";
4797 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4798 instance of an inlined instance of a decl which is local to an inline
4799 function, so we have to trace all of the way back through the origin chain
4800 to find out what sort of node actually served as the original seed for the
4804 decl_ultimate_origin (tree decl
)
4806 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4809 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4810 nodes in the function to point to themselves; ignore that if
4811 we're trying to output the abstract instance of this function. */
4812 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4815 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4816 most distant ancestor, this should never happen. */
4817 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4819 return DECL_ABSTRACT_ORIGIN (decl
);
4822 /* Determine the "ultimate origin" of a block. The block may be an inlined
4823 instance of an inlined instance of a block which is local to an inline
4824 function, so we have to trace all of the way back through the origin chain
4825 to find out what sort of node actually served as the original seed for the
4829 block_ultimate_origin (tree block
)
4831 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4833 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4834 nodes in the function to point to themselves; ignore that if
4835 we're trying to output the abstract instance of this function. */
4836 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4839 if (immediate_origin
== NULL_TREE
)
4844 tree lookahead
= immediate_origin
;
4848 ret_val
= lookahead
;
4849 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4850 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4852 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4854 /* The block's abstract origin chain may not be the *ultimate* origin of
4855 the block. It could lead to a DECL that has an abstract origin set.
4856 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4857 will give us if it has one). Note that DECL's abstract origins are
4858 supposed to be the most distant ancestor (or so decl_ultimate_origin
4859 claims), so we don't need to loop following the DECL origins. */
4860 if (DECL_P (ret_val
))
4861 return DECL_ORIGIN (ret_val
);
4867 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4868 of a virtual function may refer to a base class, so we check the 'this'
4872 decl_class_context (tree decl
)
4874 tree context
= NULL_TREE
;
4876 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4877 context
= DECL_CONTEXT (decl
);
4879 context
= TYPE_MAIN_VARIANT
4880 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4882 if (context
&& !TYPE_P (context
))
4883 context
= NULL_TREE
;
4888 /* Add an attribute/value pair to a DIE. */
4891 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4893 /* Maybe this should be an assert? */
4897 if (die
->die_attr
== NULL
)
4898 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
4899 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
4902 static inline enum dw_val_class
4903 AT_class (dw_attr_ref a
)
4905 return a
->dw_attr_val
.val_class
;
4908 /* Add a flag value attribute to a DIE. */
4911 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4915 attr
.dw_attr
= attr_kind
;
4916 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
4917 attr
.dw_attr_val
.v
.val_flag
= flag
;
4918 add_dwarf_attr (die
, &attr
);
4921 static inline unsigned
4922 AT_flag (dw_attr_ref a
)
4924 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
4925 return a
->dw_attr_val
.v
.val_flag
;
4928 /* Add a signed integer attribute value to a DIE. */
4931 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4935 attr
.dw_attr
= attr_kind
;
4936 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
4937 attr
.dw_attr_val
.v
.val_int
= int_val
;
4938 add_dwarf_attr (die
, &attr
);
4941 static inline HOST_WIDE_INT
4942 AT_int (dw_attr_ref a
)
4944 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
4945 return a
->dw_attr_val
.v
.val_int
;
4948 /* Add an unsigned integer attribute value to a DIE. */
4951 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4952 unsigned HOST_WIDE_INT unsigned_val
)
4956 attr
.dw_attr
= attr_kind
;
4957 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4958 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4959 add_dwarf_attr (die
, &attr
);
4962 static inline unsigned HOST_WIDE_INT
4963 AT_unsigned (dw_attr_ref a
)
4965 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
4966 return a
->dw_attr_val
.v
.val_unsigned
;
4969 /* Add an unsigned double integer attribute value to a DIE. */
4972 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4973 long unsigned int val_hi
, long unsigned int val_low
)
4977 attr
.dw_attr
= attr_kind
;
4978 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
4979 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4980 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
4981 add_dwarf_attr (die
, &attr
);
4984 /* Add a floating point attribute value to a DIE and return it. */
4987 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4988 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4992 attr
.dw_attr
= attr_kind
;
4993 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4994 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4995 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4996 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4997 add_dwarf_attr (die
, &attr
);
5000 /* Hash and equality functions for debug_str_hash. */
5003 debug_str_do_hash (const void *x
)
5005 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
5009 debug_str_eq (const void *x1
, const void *x2
)
5011 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
5012 (const char *)x2
) == 0;
5015 /* Add a string attribute value to a DIE. */
5018 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
5021 struct indirect_string_node
*node
;
5024 if (! debug_str_hash
)
5025 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
5026 debug_str_eq
, NULL
);
5028 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
5029 htab_hash_string (str
), INSERT
);
5031 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
5032 node
= (struct indirect_string_node
*) *slot
;
5033 node
->str
= ggc_strdup (str
);
5036 attr
.dw_attr
= attr_kind
;
5037 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
5038 attr
.dw_attr_val
.v
.val_str
= node
;
5039 add_dwarf_attr (die
, &attr
);
5042 static inline const char *
5043 AT_string (dw_attr_ref a
)
5045 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5046 return a
->dw_attr_val
.v
.val_str
->str
;
5049 /* Find out whether a string should be output inline in DIE
5050 or out-of-line in .debug_str section. */
5053 AT_string_form (dw_attr_ref a
)
5055 struct indirect_string_node
*node
;
5059 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5061 node
= a
->dw_attr_val
.v
.val_str
;
5065 len
= strlen (node
->str
) + 1;
5067 /* If the string is shorter or equal to the size of the reference, it is
5068 always better to put it inline. */
5069 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5070 return node
->form
= DW_FORM_string
;
5072 /* If we cannot expect the linker to merge strings in .debug_str
5073 section, only put it into .debug_str if it is worth even in this
5075 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5076 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5077 return node
->form
= DW_FORM_string
;
5079 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5080 ++dw2_string_counter
;
5081 node
->label
= xstrdup (label
);
5083 return node
->form
= DW_FORM_strp
;
5086 /* Add a DIE reference attribute value to a DIE. */
5089 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
5093 attr
.dw_attr
= attr_kind
;
5094 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
5095 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
5096 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
5097 add_dwarf_attr (die
, &attr
);
5100 /* Add an AT_specification attribute to a DIE, and also make the back
5101 pointer from the specification to the definition. */
5104 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
5106 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
5107 gcc_assert (!targ_die
->die_definition
);
5108 targ_die
->die_definition
= die
;
5111 static inline dw_die_ref
5112 AT_ref (dw_attr_ref a
)
5114 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5115 return a
->dw_attr_val
.v
.val_die_ref
.die
;
5119 AT_ref_external (dw_attr_ref a
)
5121 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
5122 return a
->dw_attr_val
.v
.val_die_ref
.external
;
5128 set_AT_ref_external (dw_attr_ref a
, int i
)
5130 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5131 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
5134 /* Add an FDE reference attribute value to a DIE. */
5137 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
5141 attr
.dw_attr
= attr_kind
;
5142 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
5143 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
5144 add_dwarf_attr (die
, &attr
);
5147 /* Add a location description attribute value to a DIE. */
5150 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
5154 attr
.dw_attr
= attr_kind
;
5155 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
5156 attr
.dw_attr_val
.v
.val_loc
= loc
;
5157 add_dwarf_attr (die
, &attr
);
5160 static inline dw_loc_descr_ref
5161 AT_loc (dw_attr_ref a
)
5163 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
5164 return a
->dw_attr_val
.v
.val_loc
;
5168 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5172 attr
.dw_attr
= attr_kind
;
5173 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5174 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5175 add_dwarf_attr (die
, &attr
);
5176 have_location_lists
= true;
5179 static inline dw_loc_list_ref
5180 AT_loc_list (dw_attr_ref a
)
5182 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5183 return a
->dw_attr_val
.v
.val_loc_list
;
5186 /* Add an address constant attribute value to a DIE. */
5189 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
5193 attr
.dw_attr
= attr_kind
;
5194 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5195 attr
.dw_attr_val
.v
.val_addr
= addr
;
5196 add_dwarf_attr (die
, &attr
);
5199 /* Get the RTX from to an address DIE attribute. */
5202 AT_addr (dw_attr_ref a
)
5204 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5205 return a
->dw_attr_val
.v
.val_addr
;
5208 /* Add a file attribute value to a DIE. */
5211 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5212 struct dwarf_file_data
*fd
)
5216 attr
.dw_attr
= attr_kind
;
5217 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5218 attr
.dw_attr_val
.v
.val_file
= fd
;
5219 add_dwarf_attr (die
, &attr
);
5222 /* Get the dwarf_file_data from a file DIE attribute. */
5224 static inline struct dwarf_file_data
*
5225 AT_file (dw_attr_ref a
)
5227 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
5228 return a
->dw_attr_val
.v
.val_file
;
5231 /* Add a label identifier attribute value to a DIE. */
5234 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5238 attr
.dw_attr
= attr_kind
;
5239 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5240 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5241 add_dwarf_attr (die
, &attr
);
5244 /* Add a section offset attribute value to a DIE, an offset into the
5245 debug_line section. */
5248 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5253 attr
.dw_attr
= attr_kind
;
5254 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5255 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5256 add_dwarf_attr (die
, &attr
);
5259 /* Add a section offset attribute value to a DIE, an offset into the
5260 debug_macinfo section. */
5263 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5268 attr
.dw_attr
= attr_kind
;
5269 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5270 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5271 add_dwarf_attr (die
, &attr
);
5274 /* Add an offset attribute value to a DIE. */
5277 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5278 unsigned HOST_WIDE_INT offset
)
5282 attr
.dw_attr
= attr_kind
;
5283 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
5284 attr
.dw_attr_val
.v
.val_offset
= offset
;
5285 add_dwarf_attr (die
, &attr
);
5288 /* Add an range_list attribute value to a DIE. */
5291 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5292 long unsigned int offset
)
5296 attr
.dw_attr
= attr_kind
;
5297 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5298 attr
.dw_attr_val
.v
.val_offset
= offset
;
5299 add_dwarf_attr (die
, &attr
);
5302 static inline const char *
5303 AT_lbl (dw_attr_ref a
)
5305 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5306 || AT_class (a
) == dw_val_class_lineptr
5307 || AT_class (a
) == dw_val_class_macptr
));
5308 return a
->dw_attr_val
.v
.val_lbl_id
;
5311 /* Get the attribute of type attr_kind. */
5314 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5318 dw_die_ref spec
= NULL
;
5323 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5324 if (a
->dw_attr
== attr_kind
)
5326 else if (a
->dw_attr
== DW_AT_specification
5327 || a
->dw_attr
== DW_AT_abstract_origin
)
5331 return get_AT (spec
, attr_kind
);
5336 /* Return the "low pc" attribute value, typically associated with a subprogram
5337 DIE. Return null if the "low pc" attribute is either not present, or if it
5338 cannot be represented as an assembler label identifier. */
5340 static inline const char *
5341 get_AT_low_pc (dw_die_ref die
)
5343 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5345 return a
? AT_lbl (a
) : NULL
;
5348 /* Return the "high pc" attribute value, typically associated with a subprogram
5349 DIE. Return null if the "high pc" attribute is either not present, or if it
5350 cannot be represented as an assembler label identifier. */
5352 static inline const char *
5353 get_AT_hi_pc (dw_die_ref die
)
5355 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5357 return a
? AT_lbl (a
) : NULL
;
5360 /* Return the value of the string attribute designated by ATTR_KIND, or
5361 NULL if it is not present. */
5363 static inline const char *
5364 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5366 dw_attr_ref a
= get_AT (die
, attr_kind
);
5368 return a
? AT_string (a
) : NULL
;
5371 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5372 if it is not present. */
5375 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5377 dw_attr_ref a
= get_AT (die
, attr_kind
);
5379 return a
? AT_flag (a
) : 0;
5382 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5383 if it is not present. */
5385 static inline unsigned
5386 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5388 dw_attr_ref a
= get_AT (die
, attr_kind
);
5390 return a
? AT_unsigned (a
) : 0;
5393 static inline dw_die_ref
5394 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5396 dw_attr_ref a
= get_AT (die
, attr_kind
);
5398 return a
? AT_ref (a
) : NULL
;
5401 static inline struct dwarf_file_data
*
5402 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5404 dw_attr_ref a
= get_AT (die
, attr_kind
);
5406 return a
? AT_file (a
) : NULL
;
5409 /* Return TRUE if the language is C or C++. */
5414 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5416 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
5417 || lang
== DW_LANG_C99
5418 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
5421 /* Return TRUE if the language is C++. */
5426 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5428 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
5431 /* Return TRUE if the language is Fortran. */
5436 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5438 return (lang
== DW_LANG_Fortran77
5439 || lang
== DW_LANG_Fortran90
5440 || lang
== DW_LANG_Fortran95
);
5443 /* Return TRUE if the language is Java. */
5448 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5450 return lang
== DW_LANG_Java
;
5453 /* Return TRUE if the language is Ada. */
5458 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5460 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5463 /* Remove the specified attribute if present. */
5466 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5474 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5475 if (a
->dw_attr
== attr_kind
)
5477 if (AT_class (a
) == dw_val_class_str
)
5478 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5479 a
->dw_attr_val
.v
.val_str
->refcount
--;
5481 /* VEC_ordered_remove should help reduce the number of abbrevs
5483 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
5488 /* Remove CHILD from its parent. PREV must have the property that
5489 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5492 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5494 gcc_assert (child
->die_parent
== prev
->die_parent
);
5495 gcc_assert (prev
->die_sib
== child
);
5498 gcc_assert (child
->die_parent
->die_child
== child
);
5502 prev
->die_sib
= child
->die_sib
;
5503 if (child
->die_parent
->die_child
== child
)
5504 child
->die_parent
->die_child
= prev
;
5507 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5511 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5517 dw_die_ref prev
= c
;
5519 while (c
->die_tag
== tag
)
5521 remove_child_with_prev (c
, prev
);
5522 /* Might have removed every child. */
5523 if (c
== c
->die_sib
)
5527 } while (c
!= die
->die_child
);
5530 /* Add a CHILD_DIE as the last child of DIE. */
5533 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5535 /* FIXME this should probably be an assert. */
5536 if (! die
|| ! child_die
)
5538 gcc_assert (die
!= child_die
);
5540 child_die
->die_parent
= die
;
5543 child_die
->die_sib
= die
->die_child
->die_sib
;
5544 die
->die_child
->die_sib
= child_die
;
5547 child_die
->die_sib
= child_die
;
5548 die
->die_child
= child_die
;
5551 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5552 is the specification, to the end of PARENT's list of children.
5553 This is done by removing and re-adding it. */
5556 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5560 /* We want the declaration DIE from inside the class, not the
5561 specification DIE at toplevel. */
5562 if (child
->die_parent
!= parent
)
5564 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5570 gcc_assert (child
->die_parent
== parent
5571 || (child
->die_parent
5572 == get_AT_ref (parent
, DW_AT_specification
)));
5574 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5575 if (p
->die_sib
== child
)
5577 remove_child_with_prev (child
, p
);
5581 add_child_die (parent
, child
);
5584 /* Return a pointer to a newly created DIE node. */
5586 static inline dw_die_ref
5587 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5589 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5591 die
->die_tag
= tag_value
;
5593 if (parent_die
!= NULL
)
5594 add_child_die (parent_die
, die
);
5597 limbo_die_node
*limbo_node
;
5599 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5600 limbo_node
->die
= die
;
5601 limbo_node
->created_for
= t
;
5602 limbo_node
->next
= limbo_die_list
;
5603 limbo_die_list
= limbo_node
;
5609 /* Return the DIE associated with the given type specifier. */
5611 static inline dw_die_ref
5612 lookup_type_die (tree type
)
5614 return TYPE_SYMTAB_DIE (type
);
5617 /* Equate a DIE to a given type specifier. */
5620 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5622 TYPE_SYMTAB_DIE (type
) = type_die
;
5625 /* Returns a hash value for X (which really is a die_struct). */
5628 decl_die_table_hash (const void *x
)
5630 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5633 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5636 decl_die_table_eq (const void *x
, const void *y
)
5638 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5641 /* Return the DIE associated with a given declaration. */
5643 static inline dw_die_ref
5644 lookup_decl_die (tree decl
)
5646 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5649 /* Returns a hash value for X (which really is a var_loc_list). */
5652 decl_loc_table_hash (const void *x
)
5654 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5657 /* Return nonzero if decl_id of var_loc_list X is the same as
5661 decl_loc_table_eq (const void *x
, const void *y
)
5663 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5666 /* Return the var_loc list associated with a given declaration. */
5668 static inline var_loc_list
*
5669 lookup_decl_loc (tree decl
)
5671 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5674 /* Equate a DIE to a particular declaration. */
5677 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5679 unsigned int decl_id
= DECL_UID (decl
);
5682 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5684 decl_die
->decl_id
= decl_id
;
5687 /* Add a variable location node to the linked list for DECL. */
5690 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5692 unsigned int decl_id
= DECL_UID (decl
);
5696 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5699 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5700 temp
->decl_id
= decl_id
;
5708 /* If the current location is the same as the end of the list,
5709 we have nothing to do. */
5710 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5711 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5713 /* Add LOC to the end of list and update LAST. */
5714 temp
->last
->next
= loc
;
5718 /* Do not add empty location to the beginning of the list. */
5719 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5726 /* Keep track of the number of spaces used to indent the
5727 output of the debugging routines that print the structure of
5728 the DIE internal representation. */
5729 static int print_indent
;
5731 /* Indent the line the number of spaces given by print_indent. */
5734 print_spaces (FILE *outfile
)
5736 fprintf (outfile
, "%*s", print_indent
, "");
5739 /* Print the information associated with a given DIE, and its children.
5740 This routine is a debugging aid only. */
5743 print_die (dw_die_ref die
, FILE *outfile
)
5749 print_spaces (outfile
);
5750 fprintf (outfile
, "DIE %4lu: %s\n",
5751 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5752 print_spaces (outfile
);
5753 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5754 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5756 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5758 print_spaces (outfile
);
5759 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5761 switch (AT_class (a
))
5763 case dw_val_class_addr
:
5764 fprintf (outfile
, "address");
5766 case dw_val_class_offset
:
5767 fprintf (outfile
, "offset");
5769 case dw_val_class_loc
:
5770 fprintf (outfile
, "location descriptor");
5772 case dw_val_class_loc_list
:
5773 fprintf (outfile
, "location list -> label:%s",
5774 AT_loc_list (a
)->ll_symbol
);
5776 case dw_val_class_range_list
:
5777 fprintf (outfile
, "range list");
5779 case dw_val_class_const
:
5780 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5782 case dw_val_class_unsigned_const
:
5783 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5785 case dw_val_class_long_long
:
5786 fprintf (outfile
, "constant (%lu,%lu)",
5787 a
->dw_attr_val
.v
.val_long_long
.hi
,
5788 a
->dw_attr_val
.v
.val_long_long
.low
);
5790 case dw_val_class_vec
:
5791 fprintf (outfile
, "floating-point or vector constant");
5793 case dw_val_class_flag
:
5794 fprintf (outfile
, "%u", AT_flag (a
));
5796 case dw_val_class_die_ref
:
5797 if (AT_ref (a
) != NULL
)
5799 if (AT_ref (a
)->die_symbol
)
5800 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5802 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5805 fprintf (outfile
, "die -> <null>");
5807 case dw_val_class_lbl_id
:
5808 case dw_val_class_lineptr
:
5809 case dw_val_class_macptr
:
5810 fprintf (outfile
, "label: %s", AT_lbl (a
));
5812 case dw_val_class_str
:
5813 if (AT_string (a
) != NULL
)
5814 fprintf (outfile
, "\"%s\"", AT_string (a
));
5816 fprintf (outfile
, "<null>");
5818 case dw_val_class_file
:
5819 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5820 AT_file (a
)->emitted_number
);
5826 fprintf (outfile
, "\n");
5829 if (die
->die_child
!= NULL
)
5832 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5835 if (print_indent
== 0)
5836 fprintf (outfile
, "\n");
5839 /* Print the contents of the source code line number correspondence table.
5840 This routine is a debugging aid only. */
5843 print_dwarf_line_table (FILE *outfile
)
5846 dw_line_info_ref line_info
;
5848 fprintf (outfile
, "\n\nDWARF source line information\n");
5849 for (i
= 1; i
< line_info_table_in_use
; i
++)
5851 line_info
= &line_info_table
[i
];
5852 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
5853 line_info
->dw_file_num
,
5854 line_info
->dw_line_num
);
5857 fprintf (outfile
, "\n\n");
5860 /* Print the information collected for a given DIE. */
5863 debug_dwarf_die (dw_die_ref die
)
5865 print_die (die
, stderr
);
5868 /* Print all DWARF information collected for the compilation unit.
5869 This routine is a debugging aid only. */
5875 print_die (comp_unit_die
, stderr
);
5876 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5877 print_dwarf_line_table (stderr
);
5880 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5881 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5882 DIE that marks the start of the DIEs for this include file. */
5885 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5887 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5888 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5890 new_unit
->die_sib
= old_unit
;
5894 /* Close an include-file CU and reopen the enclosing one. */
5897 pop_compile_unit (dw_die_ref old_unit
)
5899 dw_die_ref new_unit
= old_unit
->die_sib
;
5901 old_unit
->die_sib
= NULL
;
5905 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5906 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5908 /* Calculate the checksum of a location expression. */
5911 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5913 CHECKSUM (loc
->dw_loc_opc
);
5914 CHECKSUM (loc
->dw_loc_oprnd1
);
5915 CHECKSUM (loc
->dw_loc_oprnd2
);
5918 /* Calculate the checksum of an attribute. */
5921 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5923 dw_loc_descr_ref loc
;
5926 CHECKSUM (at
->dw_attr
);
5928 /* We don't care that this was compiled with a different compiler
5929 snapshot; if the output is the same, that's what matters. */
5930 if (at
->dw_attr
== DW_AT_producer
)
5933 switch (AT_class (at
))
5935 case dw_val_class_const
:
5936 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5938 case dw_val_class_unsigned_const
:
5939 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5941 case dw_val_class_long_long
:
5942 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5944 case dw_val_class_vec
:
5945 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5947 case dw_val_class_flag
:
5948 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5950 case dw_val_class_str
:
5951 CHECKSUM_STRING (AT_string (at
));
5954 case dw_val_class_addr
:
5956 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5957 CHECKSUM_STRING (XSTR (r
, 0));
5960 case dw_val_class_offset
:
5961 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5964 case dw_val_class_loc
:
5965 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5966 loc_checksum (loc
, ctx
);
5969 case dw_val_class_die_ref
:
5970 die_checksum (AT_ref (at
), ctx
, mark
);
5973 case dw_val_class_fde_ref
:
5974 case dw_val_class_lbl_id
:
5975 case dw_val_class_lineptr
:
5976 case dw_val_class_macptr
:
5979 case dw_val_class_file
:
5980 CHECKSUM_STRING (AT_file (at
)->filename
);
5988 /* Calculate the checksum of a DIE. */
5991 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5997 /* To avoid infinite recursion. */
6000 CHECKSUM (die
->die_mark
);
6003 die
->die_mark
= ++(*mark
);
6005 CHECKSUM (die
->die_tag
);
6007 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6008 attr_checksum (a
, ctx
, mark
);
6010 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6014 #undef CHECKSUM_STRING
6016 /* Do the location expressions look same? */
6018 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6020 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6021 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6022 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6025 /* Do the values look the same? */
6027 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
6029 dw_loc_descr_ref loc1
, loc2
;
6032 if (v1
->val_class
!= v2
->val_class
)
6035 switch (v1
->val_class
)
6037 case dw_val_class_const
:
6038 return v1
->v
.val_int
== v2
->v
.val_int
;
6039 case dw_val_class_unsigned_const
:
6040 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6041 case dw_val_class_long_long
:
6042 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6043 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6044 case dw_val_class_vec
:
6045 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6046 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6048 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6049 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6052 case dw_val_class_flag
:
6053 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6054 case dw_val_class_str
:
6055 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6057 case dw_val_class_addr
:
6058 r1
= v1
->v
.val_addr
;
6059 r2
= v2
->v
.val_addr
;
6060 if (GET_CODE (r1
) != GET_CODE (r2
))
6062 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6063 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6065 case dw_val_class_offset
:
6066 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6068 case dw_val_class_loc
:
6069 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6071 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6072 if (!same_loc_p (loc1
, loc2
, mark
))
6074 return !loc1
&& !loc2
;
6076 case dw_val_class_die_ref
:
6077 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6079 case dw_val_class_fde_ref
:
6080 case dw_val_class_lbl_id
:
6081 case dw_val_class_lineptr
:
6082 case dw_val_class_macptr
:
6085 case dw_val_class_file
:
6086 return v1
->v
.val_file
== v2
->v
.val_file
;
6093 /* Do the attributes look the same? */
6096 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6098 if (at1
->dw_attr
!= at2
->dw_attr
)
6101 /* We don't care that this was compiled with a different compiler
6102 snapshot; if the output is the same, that's what matters. */
6103 if (at1
->dw_attr
== DW_AT_producer
)
6106 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6109 /* Do the dies look the same? */
6112 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6118 /* To avoid infinite recursion. */
6120 return die1
->die_mark
== die2
->die_mark
;
6121 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6123 if (die1
->die_tag
!= die2
->die_tag
)
6126 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6127 != VEC_length (dw_attr_node
, die2
->die_attr
))
6130 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
6131 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6134 c1
= die1
->die_child
;
6135 c2
= die2
->die_child
;
6144 if (!same_die_p (c1
, c2
, mark
))
6148 if (c1
== die1
->die_child
)
6150 if (c2
== die2
->die_child
)
6160 /* Do the dies look the same? Wrapper around same_die_p. */
6163 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6166 int ret
= same_die_p (die1
, die2
, &mark
);
6168 unmark_all_dies (die1
);
6169 unmark_all_dies (die2
);
6174 /* The prefix to attach to symbols on DIEs in the current comdat debug
6176 static char *comdat_symbol_id
;
6178 /* The index of the current symbol within the current comdat CU. */
6179 static unsigned int comdat_symbol_number
;
6181 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6182 children, and set comdat_symbol_id accordingly. */
6185 compute_section_prefix (dw_die_ref unit_die
)
6187 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6188 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6189 char *name
= alloca (strlen (base
) + 64);
6192 unsigned char checksum
[16];
6195 /* Compute the checksum of the DIE, then append part of it as hex digits to
6196 the name filename of the unit. */
6198 md5_init_ctx (&ctx
);
6200 die_checksum (unit_die
, &ctx
, &mark
);
6201 unmark_all_dies (unit_die
);
6202 md5_finish_ctx (&ctx
, checksum
);
6204 sprintf (name
, "%s.", base
);
6205 clean_symbol_name (name
);
6207 p
= name
+ strlen (name
);
6208 for (i
= 0; i
< 4; i
++)
6210 sprintf (p
, "%.2x", checksum
[i
]);
6214 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6215 comdat_symbol_number
= 0;
6218 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6221 is_type_die (dw_die_ref die
)
6223 switch (die
->die_tag
)
6225 case DW_TAG_array_type
:
6226 case DW_TAG_class_type
:
6227 case DW_TAG_enumeration_type
:
6228 case DW_TAG_pointer_type
:
6229 case DW_TAG_reference_type
:
6230 case DW_TAG_string_type
:
6231 case DW_TAG_structure_type
:
6232 case DW_TAG_subroutine_type
:
6233 case DW_TAG_union_type
:
6234 case DW_TAG_ptr_to_member_type
:
6235 case DW_TAG_set_type
:
6236 case DW_TAG_subrange_type
:
6237 case DW_TAG_base_type
:
6238 case DW_TAG_const_type
:
6239 case DW_TAG_file_type
:
6240 case DW_TAG_packed_type
:
6241 case DW_TAG_volatile_type
:
6242 case DW_TAG_typedef
:
6249 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6250 Basically, we want to choose the bits that are likely to be shared between
6251 compilations (types) and leave out the bits that are specific to individual
6252 compilations (functions). */
6255 is_comdat_die (dw_die_ref c
)
6257 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6258 we do for stabs. The advantage is a greater likelihood of sharing between
6259 objects that don't include headers in the same order (and therefore would
6260 put the base types in a different comdat). jason 8/28/00 */
6262 if (c
->die_tag
== DW_TAG_base_type
)
6265 if (c
->die_tag
== DW_TAG_pointer_type
6266 || c
->die_tag
== DW_TAG_reference_type
6267 || c
->die_tag
== DW_TAG_const_type
6268 || c
->die_tag
== DW_TAG_volatile_type
)
6270 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6272 return t
? is_comdat_die (t
) : 0;
6275 return is_type_die (c
);
6278 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6279 compilation unit. */
6282 is_symbol_die (dw_die_ref c
)
6284 return (is_type_die (c
)
6285 || (get_AT (c
, DW_AT_declaration
)
6286 && !get_AT (c
, DW_AT_specification
))
6287 || c
->die_tag
== DW_TAG_namespace
);
6291 gen_internal_sym (const char *prefix
)
6295 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6296 return xstrdup (buf
);
6299 /* Assign symbols to all worthy DIEs under DIE. */
6302 assign_symbol_names (dw_die_ref die
)
6306 if (is_symbol_die (die
))
6308 if (comdat_symbol_id
)
6310 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6312 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6313 comdat_symbol_id
, comdat_symbol_number
++);
6314 die
->die_symbol
= xstrdup (p
);
6317 die
->die_symbol
= gen_internal_sym ("LDIE");
6320 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6323 struct cu_hash_table_entry
6326 unsigned min_comdat_num
, max_comdat_num
;
6327 struct cu_hash_table_entry
*next
;
6330 /* Routines to manipulate hash table of CUs. */
6332 htab_cu_hash (const void *of
)
6334 const struct cu_hash_table_entry
*entry
= of
;
6336 return htab_hash_string (entry
->cu
->die_symbol
);
6340 htab_cu_eq (const void *of1
, const void *of2
)
6342 const struct cu_hash_table_entry
*entry1
= of1
;
6343 const struct die_struct
*entry2
= of2
;
6345 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6349 htab_cu_del (void *what
)
6351 struct cu_hash_table_entry
*next
, *entry
= what
;
6361 /* Check whether we have already seen this CU and set up SYM_NUM
6364 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6366 struct cu_hash_table_entry dummy
;
6367 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6369 dummy
.max_comdat_num
= 0;
6371 slot
= (struct cu_hash_table_entry
**)
6372 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6376 for (; entry
; last
= entry
, entry
= entry
->next
)
6378 if (same_die_p_wrap (cu
, entry
->cu
))
6384 *sym_num
= entry
->min_comdat_num
;
6388 entry
= XCNEW (struct cu_hash_table_entry
);
6390 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6391 entry
->next
= *slot
;
6397 /* Record SYM_NUM to record of CU in HTABLE. */
6399 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6401 struct cu_hash_table_entry
**slot
, *entry
;
6403 slot
= (struct cu_hash_table_entry
**)
6404 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6408 entry
->max_comdat_num
= sym_num
;
6411 /* Traverse the DIE (which is always comp_unit_die), and set up
6412 additional compilation units for each of the include files we see
6413 bracketed by BINCL/EINCL. */
6416 break_out_includes (dw_die_ref die
)
6419 dw_die_ref unit
= NULL
;
6420 limbo_die_node
*node
, **pnode
;
6421 htab_t cu_hash_table
;
6425 dw_die_ref prev
= c
;
6427 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6428 || (unit
&& is_comdat_die (c
)))
6430 dw_die_ref next
= c
->die_sib
;
6432 /* This DIE is for a secondary CU; remove it from the main one. */
6433 remove_child_with_prev (c
, prev
);
6435 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6436 unit
= push_new_compile_unit (unit
, c
);
6437 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6438 unit
= pop_compile_unit (unit
);
6440 add_child_die (unit
, c
);
6442 if (c
== die
->die_child
)
6445 } while (c
!= die
->die_child
);
6448 /* We can only use this in debugging, since the frontend doesn't check
6449 to make sure that we leave every include file we enter. */
6453 assign_symbol_names (die
);
6454 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6455 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6461 compute_section_prefix (node
->die
);
6462 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6463 &comdat_symbol_number
);
6464 assign_symbol_names (node
->die
);
6466 *pnode
= node
->next
;
6469 pnode
= &node
->next
;
6470 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6471 comdat_symbol_number
);
6474 htab_delete (cu_hash_table
);
6477 /* Traverse the DIE and add a sibling attribute if it may have the
6478 effect of speeding up access to siblings. To save some space,
6479 avoid generating sibling attributes for DIE's without children. */
6482 add_sibling_attributes (dw_die_ref die
)
6486 if (! die
->die_child
)
6489 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
6490 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6492 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
6495 /* Output all location lists for the DIE and its children. */
6498 output_location_lists (dw_die_ref die
)
6504 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6505 if (AT_class (a
) == dw_val_class_loc_list
)
6506 output_loc_list (AT_loc_list (a
));
6508 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
6511 /* The format of each DIE (and its attribute value pairs) is encoded in an
6512 abbreviation table. This routine builds the abbreviation table and assigns
6513 a unique abbreviation id for each abbreviation entry. The children of each
6514 die are visited recursively. */
6517 build_abbrev_table (dw_die_ref die
)
6519 unsigned long abbrev_id
;
6520 unsigned int n_alloc
;
6525 /* Scan the DIE references, and mark as external any that refer to
6526 DIEs from other CUs (i.e. those which are not marked). */
6527 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6528 if (AT_class (a
) == dw_val_class_die_ref
6529 && AT_ref (a
)->die_mark
== 0)
6531 gcc_assert (AT_ref (a
)->die_symbol
);
6533 set_AT_ref_external (a
, 1);
6536 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6538 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6539 dw_attr_ref die_a
, abbrev_a
;
6543 if (abbrev
->die_tag
!= die
->die_tag
)
6545 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
6548 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
6549 != VEC_length (dw_attr_node
, die
->die_attr
))
6552 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
6554 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
6555 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
6556 || (value_format (abbrev_a
) != value_format (die_a
)))
6566 if (abbrev_id
>= abbrev_die_table_in_use
)
6568 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6570 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6571 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6572 sizeof (dw_die_ref
) * n_alloc
);
6574 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6575 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6576 abbrev_die_table_allocated
= n_alloc
;
6579 ++abbrev_die_table_in_use
;
6580 abbrev_die_table
[abbrev_id
] = die
;
6583 die
->die_abbrev
= abbrev_id
;
6584 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
6587 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6590 constant_size (long unsigned int value
)
6597 log
= floor_log2 (value
);
6600 log
= 1 << (floor_log2 (log
) + 1);
6605 /* Return the size of a DIE as it is represented in the
6606 .debug_info section. */
6608 static unsigned long
6609 size_of_die (dw_die_ref die
)
6611 unsigned long size
= 0;
6615 size
+= size_of_uleb128 (die
->die_abbrev
);
6616 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6618 switch (AT_class (a
))
6620 case dw_val_class_addr
:
6621 size
+= DWARF2_ADDR_SIZE
;
6623 case dw_val_class_offset
:
6624 size
+= DWARF_OFFSET_SIZE
;
6626 case dw_val_class_loc
:
6628 unsigned long lsize
= size_of_locs (AT_loc (a
));
6631 size
+= constant_size (lsize
);
6635 case dw_val_class_loc_list
:
6636 size
+= DWARF_OFFSET_SIZE
;
6638 case dw_val_class_range_list
:
6639 size
+= DWARF_OFFSET_SIZE
;
6641 case dw_val_class_const
:
6642 size
+= size_of_sleb128 (AT_int (a
));
6644 case dw_val_class_unsigned_const
:
6645 size
+= constant_size (AT_unsigned (a
));
6647 case dw_val_class_long_long
:
6648 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6650 case dw_val_class_vec
:
6651 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6652 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6654 case dw_val_class_flag
:
6657 case dw_val_class_die_ref
:
6658 if (AT_ref_external (a
))
6659 size
+= DWARF2_ADDR_SIZE
;
6661 size
+= DWARF_OFFSET_SIZE
;
6663 case dw_val_class_fde_ref
:
6664 size
+= DWARF_OFFSET_SIZE
;
6666 case dw_val_class_lbl_id
:
6667 size
+= DWARF2_ADDR_SIZE
;
6669 case dw_val_class_lineptr
:
6670 case dw_val_class_macptr
:
6671 size
+= DWARF_OFFSET_SIZE
;
6673 case dw_val_class_str
:
6674 if (AT_string_form (a
) == DW_FORM_strp
)
6675 size
+= DWARF_OFFSET_SIZE
;
6677 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6679 case dw_val_class_file
:
6680 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
6690 /* Size the debugging information associated with a given DIE. Visits the
6691 DIE's children recursively. Updates the global variable next_die_offset, on
6692 each time through. Uses the current value of next_die_offset to update the
6693 die_offset field in each DIE. */
6696 calc_die_sizes (dw_die_ref die
)
6700 die
->die_offset
= next_die_offset
;
6701 next_die_offset
+= size_of_die (die
);
6703 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
6705 if (die
->die_child
!= NULL
)
6706 /* Count the null byte used to terminate sibling lists. */
6707 next_die_offset
+= 1;
6710 /* Set the marks for a die and its children. We do this so
6711 that we know whether or not a reference needs to use FORM_ref_addr; only
6712 DIEs in the same CU will be marked. We used to clear out the offset
6713 and use that as the flag, but ran into ordering problems. */
6716 mark_dies (dw_die_ref die
)
6720 gcc_assert (!die
->die_mark
);
6723 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
6726 /* Clear the marks for a die and its children. */
6729 unmark_dies (dw_die_ref die
)
6733 gcc_assert (die
->die_mark
);
6736 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
6739 /* Clear the marks for a die, its children and referred dies. */
6742 unmark_all_dies (dw_die_ref die
)
6752 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
6754 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6755 if (AT_class (a
) == dw_val_class_die_ref
)
6756 unmark_all_dies (AT_ref (a
));
6759 /* Return the size of the .debug_pubnames table generated for the
6760 compilation unit. */
6762 static unsigned long
6763 size_of_pubnames (void)
6768 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6769 for (i
= 0; i
< pubname_table_in_use
; i
++)
6771 pubname_ref p
= &pubname_table
[i
];
6772 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6775 size
+= DWARF_OFFSET_SIZE
;
6779 /* Return the size of the information in the .debug_aranges section. */
6781 static unsigned long
6782 size_of_aranges (void)
6786 size
= DWARF_ARANGES_HEADER_SIZE
;
6788 /* Count the address/length pair for this compilation unit. */
6789 size
+= 2 * DWARF2_ADDR_SIZE
;
6790 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6792 /* Count the two zero words used to terminated the address range table. */
6793 size
+= 2 * DWARF2_ADDR_SIZE
;
6797 /* Select the encoding of an attribute value. */
6799 static enum dwarf_form
6800 value_format (dw_attr_ref a
)
6802 switch (a
->dw_attr_val
.val_class
)
6804 case dw_val_class_addr
:
6805 return DW_FORM_addr
;
6806 case dw_val_class_range_list
:
6807 case dw_val_class_offset
:
6808 case dw_val_class_loc_list
:
6809 switch (DWARF_OFFSET_SIZE
)
6812 return DW_FORM_data4
;
6814 return DW_FORM_data8
;
6818 case dw_val_class_loc
:
6819 switch (constant_size (size_of_locs (AT_loc (a
))))
6822 return DW_FORM_block1
;
6824 return DW_FORM_block2
;
6828 case dw_val_class_const
:
6829 return DW_FORM_sdata
;
6830 case dw_val_class_unsigned_const
:
6831 switch (constant_size (AT_unsigned (a
)))
6834 return DW_FORM_data1
;
6836 return DW_FORM_data2
;
6838 return DW_FORM_data4
;
6840 return DW_FORM_data8
;
6844 case dw_val_class_long_long
:
6845 return DW_FORM_block1
;
6846 case dw_val_class_vec
:
6847 return DW_FORM_block1
;
6848 case dw_val_class_flag
:
6849 return DW_FORM_flag
;
6850 case dw_val_class_die_ref
:
6851 if (AT_ref_external (a
))
6852 return DW_FORM_ref_addr
;
6855 case dw_val_class_fde_ref
:
6856 return DW_FORM_data
;
6857 case dw_val_class_lbl_id
:
6858 return DW_FORM_addr
;
6859 case dw_val_class_lineptr
:
6860 case dw_val_class_macptr
:
6861 return DW_FORM_data
;
6862 case dw_val_class_str
:
6863 return AT_string_form (a
);
6864 case dw_val_class_file
:
6865 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
6868 return DW_FORM_data1
;
6870 return DW_FORM_data2
;
6872 return DW_FORM_data4
;
6882 /* Output the encoding of an attribute value. */
6885 output_value_format (dw_attr_ref a
)
6887 enum dwarf_form form
= value_format (a
);
6889 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6892 /* Output the .debug_abbrev section which defines the DIE abbreviation
6896 output_abbrev_section (void)
6898 unsigned long abbrev_id
;
6900 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6902 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6906 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6907 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6908 dwarf_tag_name (abbrev
->die_tag
));
6910 if (abbrev
->die_child
!= NULL
)
6911 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6913 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6915 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
6918 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6919 dwarf_attr_name (a_attr
->dw_attr
));
6920 output_value_format (a_attr
);
6923 dw2_asm_output_data (1, 0, NULL
);
6924 dw2_asm_output_data (1, 0, NULL
);
6927 /* Terminate the table. */
6928 dw2_asm_output_data (1, 0, NULL
);
6931 /* Output a symbol we can use to refer to this DIE from another CU. */
6934 output_die_symbol (dw_die_ref die
)
6936 char *sym
= die
->die_symbol
;
6941 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6942 /* We make these global, not weak; if the target doesn't support
6943 .linkonce, it doesn't support combining the sections, so debugging
6945 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6947 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6950 /* Return a new location list, given the begin and end range, and the
6951 expression. gensym tells us whether to generate a new internal symbol for
6952 this location list node, which is done for the head of the list only. */
6954 static inline dw_loc_list_ref
6955 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6956 const char *section
, unsigned int gensym
)
6958 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6960 retlist
->begin
= begin
;
6962 retlist
->expr
= expr
;
6963 retlist
->section
= section
;
6965 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6970 /* Add a location description expression to a location list. */
6973 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6974 const char *begin
, const char *end
,
6975 const char *section
)
6979 /* Find the end of the chain. */
6980 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6983 /* Add a new location list node to the list. */
6984 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6988 dwarf2out_switch_text_section (void)
6994 fde
= &fde_table
[fde_table_in_use
- 1];
6995 fde
->dw_fde_switched_sections
= true;
6996 fde
->dw_fde_hot_section_label
= cfun
->hot_section_label
;
6997 fde
->dw_fde_hot_section_end_label
= cfun
->hot_section_end_label
;
6998 fde
->dw_fde_unlikely_section_label
= cfun
->cold_section_label
;
6999 fde
->dw_fde_unlikely_section_end_label
= cfun
->cold_section_end_label
;
7000 have_multiple_function_sections
= true;
7002 /* Reset the current label on switching text sections, so that we
7003 don't attempt to advance_loc4 between labels in different sections. */
7004 fde
->dw_fde_current_label
= NULL
;
7007 /* Output the location list given to us. */
7010 output_loc_list (dw_loc_list_ref list_head
)
7012 dw_loc_list_ref curr
= list_head
;
7014 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7016 /* Walk the location list, and output each range + expression. */
7017 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7020 if (!have_multiple_function_sections
)
7022 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7023 "Location list begin address (%s)",
7024 list_head
->ll_symbol
);
7025 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7026 "Location list end address (%s)",
7027 list_head
->ll_symbol
);
7031 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7032 "Location list begin address (%s)",
7033 list_head
->ll_symbol
);
7034 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7035 "Location list end address (%s)",
7036 list_head
->ll_symbol
);
7038 size
= size_of_locs (curr
->expr
);
7040 /* Output the block length for this list of location operations. */
7041 gcc_assert (size
<= 0xffff);
7042 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7044 output_loc_sequence (curr
->expr
);
7047 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7048 "Location list terminator begin (%s)",
7049 list_head
->ll_symbol
);
7050 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7051 "Location list terminator end (%s)",
7052 list_head
->ll_symbol
);
7055 /* Output the DIE and its attributes. Called recursively to generate
7056 the definitions of each child DIE. */
7059 output_die (dw_die_ref die
)
7066 /* If someone in another CU might refer to us, set up a symbol for
7067 them to point to. */
7068 if (die
->die_symbol
)
7069 output_die_symbol (die
);
7071 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7072 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
7074 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7076 const char *name
= dwarf_attr_name (a
->dw_attr
);
7078 switch (AT_class (a
))
7080 case dw_val_class_addr
:
7081 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7084 case dw_val_class_offset
:
7085 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7089 case dw_val_class_range_list
:
7091 char *p
= strchr (ranges_section_label
, '\0');
7093 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7094 a
->dw_attr_val
.v
.val_offset
);
7095 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7096 debug_ranges_section
, "%s", name
);
7101 case dw_val_class_loc
:
7102 size
= size_of_locs (AT_loc (a
));
7104 /* Output the block length for this list of location operations. */
7105 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7107 output_loc_sequence (AT_loc (a
));
7110 case dw_val_class_const
:
7111 /* ??? It would be slightly more efficient to use a scheme like is
7112 used for unsigned constants below, but gdb 4.x does not sign
7113 extend. Gdb 5.x does sign extend. */
7114 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7117 case dw_val_class_unsigned_const
:
7118 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
7119 AT_unsigned (a
), "%s", name
);
7122 case dw_val_class_long_long
:
7124 unsigned HOST_WIDE_INT first
, second
;
7126 dw2_asm_output_data (1,
7127 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7130 if (WORDS_BIG_ENDIAN
)
7132 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7133 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
7137 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
7138 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7141 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7142 first
, "long long constant");
7143 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7148 case dw_val_class_vec
:
7150 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7151 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7155 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
7156 if (elt_size
> sizeof (HOST_WIDE_INT
))
7161 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7164 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7165 "fp or vector constant word %u", i
);
7169 case dw_val_class_flag
:
7170 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7173 case dw_val_class_loc_list
:
7175 char *sym
= AT_loc_list (a
)->ll_symbol
;
7178 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7183 case dw_val_class_die_ref
:
7184 if (AT_ref_external (a
))
7186 char *sym
= AT_ref (a
)->die_symbol
;
7189 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
7194 gcc_assert (AT_ref (a
)->die_offset
);
7195 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7200 case dw_val_class_fde_ref
:
7204 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7205 a
->dw_attr_val
.v
.val_fde_index
* 2);
7206 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7211 case dw_val_class_lbl_id
:
7212 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7215 case dw_val_class_lineptr
:
7216 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7217 debug_line_section
, "%s", name
);
7220 case dw_val_class_macptr
:
7221 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7222 debug_macinfo_section
, "%s", name
);
7225 case dw_val_class_str
:
7226 if (AT_string_form (a
) == DW_FORM_strp
)
7227 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7228 a
->dw_attr_val
.v
.val_str
->label
,
7230 "%s: \"%s\"", name
, AT_string (a
));
7232 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7235 case dw_val_class_file
:
7237 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
7239 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
7240 a
->dw_attr_val
.v
.val_file
->filename
);
7249 FOR_EACH_CHILD (die
, c
, output_die (c
));
7251 /* Add null byte to terminate sibling list. */
7252 if (die
->die_child
!= NULL
)
7253 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7257 /* Output the compilation unit that appears at the beginning of the
7258 .debug_info section, and precedes the DIE descriptions. */
7261 output_compilation_unit_header (void)
7263 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7264 dw2_asm_output_data (4, 0xffffffff,
7265 "Initial length escape value indicating 64-bit DWARF extension");
7266 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7267 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7268 "Length of Compilation Unit Info");
7269 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7270 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7271 debug_abbrev_section
,
7272 "Offset Into Abbrev. Section");
7273 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7276 /* Output the compilation unit DIE and its children. */
7279 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7281 const char *secname
;
7284 /* Unless we are outputting main CU, we may throw away empty ones. */
7285 if (!output_if_empty
&& die
->die_child
== NULL
)
7288 /* Even if there are no children of this DIE, we must output the information
7289 about the compilation unit. Otherwise, on an empty translation unit, we
7290 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7291 will then complain when examining the file. First mark all the DIEs in
7292 this CU so we know which get local refs. */
7295 build_abbrev_table (die
);
7297 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7298 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7299 calc_die_sizes (die
);
7301 oldsym
= die
->die_symbol
;
7304 tmp
= alloca (strlen (oldsym
) + 24);
7306 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7308 die
->die_symbol
= NULL
;
7309 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
7312 switch_to_section (debug_info_section
);
7314 /* Output debugging information. */
7315 output_compilation_unit_header ();
7318 /* Leave the marks on the main CU, so we can check them in
7323 die
->die_symbol
= oldsym
;
7327 /* Return the DWARF2/3 pubname associated with a decl. */
7330 dwarf2_name (tree decl
, int scope
)
7332 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
7335 /* Add a new entry to .debug_pubnames if appropriate. */
7338 add_pubname (tree decl
, dw_die_ref die
)
7342 if (! TREE_PUBLIC (decl
))
7345 if (pubname_table_in_use
== pubname_table_allocated
)
7347 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7349 = ggc_realloc (pubname_table
,
7350 (pubname_table_allocated
* sizeof (pubname_entry
)));
7351 memset (pubname_table
+ pubname_table_in_use
, 0,
7352 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7355 p
= &pubname_table
[pubname_table_in_use
++];
7357 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7360 /* Output the public names table used to speed up access to externally
7361 visible names. For now, only generate entries for externally
7362 visible procedures. */
7365 output_pubnames (void)
7368 unsigned long pubnames_length
= size_of_pubnames ();
7370 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7371 dw2_asm_output_data (4, 0xffffffff,
7372 "Initial length escape value indicating 64-bit DWARF extension");
7373 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7374 "Length of Public Names Info");
7375 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7376 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7378 "Offset of Compilation Unit Info");
7379 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7380 "Compilation Unit Length");
7382 for (i
= 0; i
< pubname_table_in_use
; i
++)
7384 pubname_ref pub
= &pubname_table
[i
];
7386 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7387 gcc_assert (pub
->die
->die_mark
);
7389 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7392 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7395 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7398 /* Add a new entry to .debug_aranges if appropriate. */
7401 add_arange (tree decl
, dw_die_ref die
)
7403 if (! DECL_SECTION_NAME (decl
))
7406 if (arange_table_in_use
== arange_table_allocated
)
7408 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7409 arange_table
= ggc_realloc (arange_table
,
7410 (arange_table_allocated
7411 * sizeof (dw_die_ref
)));
7412 memset (arange_table
+ arange_table_in_use
, 0,
7413 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7416 arange_table
[arange_table_in_use
++] = die
;
7419 /* Output the information that goes into the .debug_aranges table.
7420 Namely, define the beginning and ending address range of the
7421 text section generated for this compilation unit. */
7424 output_aranges (void)
7427 unsigned long aranges_length
= size_of_aranges ();
7429 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7430 dw2_asm_output_data (4, 0xffffffff,
7431 "Initial length escape value indicating 64-bit DWARF extension");
7432 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7433 "Length of Address Ranges Info");
7434 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7435 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7437 "Offset of Compilation Unit Info");
7438 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7439 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7441 /* We need to align to twice the pointer size here. */
7442 if (DWARF_ARANGES_PAD_SIZE
)
7444 /* Pad using a 2 byte words so that padding is correct for any
7446 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7447 2 * DWARF2_ADDR_SIZE
);
7448 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7449 dw2_asm_output_data (2, 0, NULL
);
7452 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7453 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7454 text_section_label
, "Length");
7455 if (flag_reorder_blocks_and_partition
)
7457 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
7459 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
7460 cold_text_section_label
, "Length");
7463 for (i
= 0; i
< arange_table_in_use
; i
++)
7465 dw_die_ref die
= arange_table
[i
];
7467 /* We shouldn't see aranges for DIEs outside of the main CU. */
7468 gcc_assert (die
->die_mark
);
7470 if (die
->die_tag
== DW_TAG_subprogram
)
7472 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7474 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7475 get_AT_low_pc (die
), "Length");
7479 /* A static variable; extract the symbol from DW_AT_location.
7480 Note that this code isn't currently hit, as we only emit
7481 aranges for functions (jason 9/23/99). */
7482 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7483 dw_loc_descr_ref loc
;
7485 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7488 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
7490 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7491 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7492 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7493 get_AT_unsigned (die
, DW_AT_byte_size
),
7498 /* Output the terminator words. */
7499 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7500 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7503 /* Add a new entry to .debug_ranges. Return the offset at which it
7507 add_ranges (tree block
)
7509 unsigned int in_use
= ranges_table_in_use
;
7511 if (in_use
== ranges_table_allocated
)
7513 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7515 = ggc_realloc (ranges_table
, (ranges_table_allocated
7516 * sizeof (struct dw_ranges_struct
)));
7517 memset (ranges_table
+ ranges_table_in_use
, 0,
7518 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7521 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7522 ranges_table_in_use
= in_use
+ 1;
7524 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7528 output_ranges (void)
7531 static const char *const start_fmt
= "Offset 0x%x";
7532 const char *fmt
= start_fmt
;
7534 for (i
= 0; i
< ranges_table_in_use
; i
++)
7536 int block_num
= ranges_table
[i
].block_num
;
7540 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7541 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7543 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7544 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7546 /* If all code is in the text section, then the compilation
7547 unit base address defaults to DW_AT_low_pc, which is the
7548 base of the text section. */
7549 if (!have_multiple_function_sections
)
7551 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7553 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7554 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7555 text_section_label
, NULL
);
7558 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7559 compilation unit base address to zero, which allows us to
7560 use absolute addresses, and not worry about whether the
7561 target supports cross-section arithmetic. */
7564 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7565 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7566 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7573 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7574 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7580 /* Data structure containing information about input files. */
7583 const char *path
; /* Complete file name. */
7584 const char *fname
; /* File name part. */
7585 int length
; /* Length of entire string. */
7586 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
7587 int dir_idx
; /* Index in directory table. */
7590 /* Data structure containing information about directories with source
7594 const char *path
; /* Path including directory name. */
7595 int length
; /* Path length. */
7596 int prefix
; /* Index of directory entry which is a prefix. */
7597 int count
; /* Number of files in this directory. */
7598 int dir_idx
; /* Index of directory used as base. */
7601 /* Callback function for file_info comparison. We sort by looking at
7602 the directories in the path. */
7605 file_info_cmp (const void *p1
, const void *p2
)
7607 const struct file_info
*s1
= p1
;
7608 const struct file_info
*s2
= p2
;
7612 /* Take care of file names without directories. We need to make sure that
7613 we return consistent values to qsort since some will get confused if
7614 we return the same value when identical operands are passed in opposite
7615 orders. So if neither has a directory, return 0 and otherwise return
7616 1 or -1 depending on which one has the directory. */
7617 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7618 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7620 cp1
= (unsigned char *) s1
->path
;
7621 cp2
= (unsigned char *) s2
->path
;
7627 /* Reached the end of the first path? If so, handle like above. */
7628 if ((cp1
== (unsigned char *) s1
->fname
)
7629 || (cp2
== (unsigned char *) s2
->fname
))
7630 return ((cp2
== (unsigned char *) s2
->fname
)
7631 - (cp1
== (unsigned char *) s1
->fname
));
7633 /* Character of current path component the same? */
7634 else if (*cp1
!= *cp2
)
7639 struct file_name_acquire_data
7641 struct file_info
*files
;
7646 /* Traversal function for the hash table. */
7649 file_name_acquire (void ** slot
, void *data
)
7651 struct file_name_acquire_data
*fnad
= data
;
7652 struct dwarf_file_data
*d
= *slot
;
7653 struct file_info
*fi
;
7656 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
7658 if (! d
->emitted_number
)
7661 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
7663 fi
= fnad
->files
+ fnad
->used_files
++;
7665 /* Skip all leading "./". */
7667 while (f
[0] == '.' && f
[1] == '/')
7670 /* Create a new array entry. */
7672 fi
->length
= strlen (f
);
7675 /* Search for the file name part. */
7676 f
= strrchr (f
, '/');
7677 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
7681 /* Output the directory table and the file name table. We try to minimize
7682 the total amount of memory needed. A heuristic is used to avoid large
7683 slowdowns with many input files. */
7686 output_file_names (void)
7688 struct file_name_acquire_data fnad
;
7690 struct file_info
*files
;
7691 struct dir_info
*dirs
;
7700 if (!last_emitted_file
)
7702 dw2_asm_output_data (1, 0, "End directory table");
7703 dw2_asm_output_data (1, 0, "End file name table");
7707 numfiles
= last_emitted_file
->emitted_number
;
7709 /* Allocate the various arrays we need. */
7710 files
= alloca (numfiles
* sizeof (struct file_info
));
7711 dirs
= alloca (numfiles
* sizeof (struct dir_info
));
7714 fnad
.used_files
= 0;
7715 fnad
.max_files
= numfiles
;
7716 htab_traverse (file_table
, file_name_acquire
, &fnad
);
7717 gcc_assert (fnad
.used_files
== fnad
.max_files
);
7719 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
7721 /* Find all the different directories used. */
7722 dirs
[0].path
= files
[0].path
;
7723 dirs
[0].length
= files
[0].fname
- files
[0].path
;
7724 dirs
[0].prefix
= -1;
7726 dirs
[0].dir_idx
= 0;
7727 files
[0].dir_idx
= 0;
7730 for (i
= 1; i
< numfiles
; i
++)
7731 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7732 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7733 dirs
[ndirs
- 1].length
) == 0)
7735 /* Same directory as last entry. */
7736 files
[i
].dir_idx
= ndirs
- 1;
7737 ++dirs
[ndirs
- 1].count
;
7743 /* This is a new directory. */
7744 dirs
[ndirs
].path
= files
[i
].path
;
7745 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7746 dirs
[ndirs
].count
= 1;
7747 dirs
[ndirs
].dir_idx
= ndirs
;
7748 files
[i
].dir_idx
= ndirs
;
7750 /* Search for a prefix. */
7751 dirs
[ndirs
].prefix
= -1;
7752 for (j
= 0; j
< ndirs
; j
++)
7753 if (dirs
[j
].length
< dirs
[ndirs
].length
7754 && dirs
[j
].length
> 1
7755 && (dirs
[ndirs
].prefix
== -1
7756 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7757 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7758 dirs
[ndirs
].prefix
= j
;
7763 /* Now to the actual work. We have to find a subset of the directories which
7764 allow expressing the file name using references to the directory table
7765 with the least amount of characters. We do not do an exhaustive search
7766 where we would have to check out every combination of every single
7767 possible prefix. Instead we use a heuristic which provides nearly optimal
7768 results in most cases and never is much off. */
7769 saved
= alloca (ndirs
* sizeof (int));
7770 savehere
= alloca (ndirs
* sizeof (int));
7772 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7773 for (i
= 0; i
< ndirs
; i
++)
7778 /* We can always save some space for the current directory. But this
7779 does not mean it will be enough to justify adding the directory. */
7780 savehere
[i
] = dirs
[i
].length
;
7781 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7783 for (j
= i
+ 1; j
< ndirs
; j
++)
7786 if (saved
[j
] < dirs
[i
].length
)
7788 /* Determine whether the dirs[i] path is a prefix of the
7793 while (k
!= -1 && k
!= (int) i
)
7798 /* Yes it is. We can possibly save some memory by
7799 writing the filenames in dirs[j] relative to
7801 savehere
[j
] = dirs
[i
].length
;
7802 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7807 /* Check whether we can save enough to justify adding the dirs[i]
7809 if (total
> dirs
[i
].length
+ 1)
7811 /* It's worthwhile adding. */
7812 for (j
= i
; j
< ndirs
; j
++)
7813 if (savehere
[j
] > 0)
7815 /* Remember how much we saved for this directory so far. */
7816 saved
[j
] = savehere
[j
];
7818 /* Remember the prefix directory. */
7819 dirs
[j
].dir_idx
= i
;
7824 /* Emit the directory name table. */
7826 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7827 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7828 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7829 "Directory Entry: 0x%x", i
+ idx_offset
);
7831 dw2_asm_output_data (1, 0, "End directory table");
7833 /* We have to emit them in the order of emitted_number since that's
7834 used in the debug info generation. To do this efficiently we
7835 generate a back-mapping of the indices first. */
7836 backmap
= alloca (numfiles
* sizeof (int));
7837 for (i
= 0; i
< numfiles
; i
++)
7838 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
7840 /* Now write all the file names. */
7841 for (i
= 0; i
< numfiles
; i
++)
7843 int file_idx
= backmap
[i
];
7844 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7846 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7847 "File Entry: 0x%x", (unsigned) i
+ 1);
7849 /* Include directory index. */
7850 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
7852 /* Modification time. */
7853 dw2_asm_output_data_uleb128 (0, NULL
);
7855 /* File length in bytes. */
7856 dw2_asm_output_data_uleb128 (0, NULL
);
7859 dw2_asm_output_data (1, 0, "End file name table");
7863 /* Output the source line number correspondence information. This
7864 information goes into the .debug_line section. */
7867 output_line_info (void)
7869 char l1
[20], l2
[20], p1
[20], p2
[20];
7870 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7871 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7874 unsigned long lt_index
;
7875 unsigned long current_line
;
7878 unsigned long current_file
;
7879 unsigned long function
;
7881 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7882 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7883 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7884 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7886 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7887 dw2_asm_output_data (4, 0xffffffff,
7888 "Initial length escape value indicating 64-bit DWARF extension");
7889 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7890 "Length of Source Line Info");
7891 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7893 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7894 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7895 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7897 /* Define the architecture-dependent minimum instruction length (in
7898 bytes). In this implementation of DWARF, this field is used for
7899 information purposes only. Since GCC generates assembly language,
7900 we have no a priori knowledge of how many instruction bytes are
7901 generated for each source line, and therefore can use only the
7902 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7903 commands. Accordingly, we fix this as `1', which is "correct
7904 enough" for all architectures, and don't let the target override. */
7905 dw2_asm_output_data (1, 1,
7906 "Minimum Instruction Length");
7908 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7909 "Default is_stmt_start flag");
7910 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7911 "Line Base Value (Special Opcodes)");
7912 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7913 "Line Range Value (Special Opcodes)");
7914 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7915 "Special Opcode Base");
7917 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7921 case DW_LNS_advance_pc
:
7922 case DW_LNS_advance_line
:
7923 case DW_LNS_set_file
:
7924 case DW_LNS_set_column
:
7925 case DW_LNS_fixed_advance_pc
:
7933 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7937 /* Write out the information about the files we use. */
7938 output_file_names ();
7939 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7941 /* We used to set the address register to the first location in the text
7942 section here, but that didn't accomplish anything since we already
7943 have a line note for the opening brace of the first function. */
7945 /* Generate the line number to PC correspondence table, encoded as
7946 a series of state machine operations. */
7950 if (cfun
&& in_cold_section_p
)
7951 strcpy (prev_line_label
, cfun
->cold_section_label
);
7953 strcpy (prev_line_label
, text_section_label
);
7954 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7956 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7959 /* Disable this optimization for now; GDB wants to see two line notes
7960 at the beginning of a function so it can find the end of the
7963 /* Don't emit anything for redundant notes. Just updating the
7964 address doesn't accomplish anything, because we already assume
7965 that anything after the last address is this line. */
7966 if (line_info
->dw_line_num
== current_line
7967 && line_info
->dw_file_num
== current_file
)
7971 /* Emit debug info for the address of the current line.
7973 Unfortunately, we have little choice here currently, and must always
7974 use the most general form. GCC does not know the address delta
7975 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7976 attributes which will give an upper bound on the address range. We
7977 could perhaps use length attributes to determine when it is safe to
7978 use DW_LNS_fixed_advance_pc. */
7980 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7983 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7984 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7985 "DW_LNS_fixed_advance_pc");
7986 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7990 /* This can handle any delta. This takes
7991 4+DWARF2_ADDR_SIZE bytes. */
7992 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7993 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7994 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7995 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7998 strcpy (prev_line_label
, line_label
);
8000 /* Emit debug info for the source file of the current line, if
8001 different from the previous line. */
8002 if (line_info
->dw_file_num
!= current_file
)
8004 current_file
= line_info
->dw_file_num
;
8005 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8006 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8009 /* Emit debug info for the current line number, choosing the encoding
8010 that uses the least amount of space. */
8011 if (line_info
->dw_line_num
!= current_line
)
8013 line_offset
= line_info
->dw_line_num
- current_line
;
8014 line_delta
= line_offset
- DWARF_LINE_BASE
;
8015 current_line
= line_info
->dw_line_num
;
8016 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8017 /* This can handle deltas from -10 to 234, using the current
8018 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8020 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8021 "line %lu", current_line
);
8024 /* This can handle any delta. This takes at least 4 bytes,
8025 depending on the value being encoded. */
8026 dw2_asm_output_data (1, DW_LNS_advance_line
,
8027 "advance to line %lu", current_line
);
8028 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8029 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8033 /* We still need to start a new row, so output a copy insn. */
8034 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8037 /* Emit debug info for the address of the end of the function. */
8040 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8041 "DW_LNS_fixed_advance_pc");
8042 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
8046 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8047 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8048 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8049 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
8052 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8053 dw2_asm_output_data_uleb128 (1, NULL
);
8054 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8059 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
8061 dw_separate_line_info_ref line_info
8062 = &separate_line_info_table
[lt_index
];
8065 /* Don't emit anything for redundant notes. */
8066 if (line_info
->dw_line_num
== current_line
8067 && line_info
->dw_file_num
== current_file
8068 && line_info
->function
== function
)
8072 /* Emit debug info for the address of the current line. If this is
8073 a new function, or the first line of a function, then we need
8074 to handle it differently. */
8075 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
8077 if (function
!= line_info
->function
)
8079 function
= line_info
->function
;
8081 /* Set the address register to the first line in the function. */
8082 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8083 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8084 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8085 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8089 /* ??? See the DW_LNS_advance_pc comment above. */
8092 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8093 "DW_LNS_fixed_advance_pc");
8094 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8098 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8099 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8100 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8101 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8105 strcpy (prev_line_label
, line_label
);
8107 /* Emit debug info for the source file of the current line, if
8108 different from the previous line. */
8109 if (line_info
->dw_file_num
!= current_file
)
8111 current_file
= line_info
->dw_file_num
;
8112 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8113 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8116 /* Emit debug info for the current line number, choosing the encoding
8117 that uses the least amount of space. */
8118 if (line_info
->dw_line_num
!= current_line
)
8120 line_offset
= line_info
->dw_line_num
- current_line
;
8121 line_delta
= line_offset
- DWARF_LINE_BASE
;
8122 current_line
= line_info
->dw_line_num
;
8123 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8124 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8125 "line %lu", current_line
);
8128 dw2_asm_output_data (1, DW_LNS_advance_line
,
8129 "advance to line %lu", current_line
);
8130 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8131 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8135 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8143 /* If we're done with a function, end its sequence. */
8144 if (lt_index
== separate_line_info_table_in_use
8145 || separate_line_info_table
[lt_index
].function
!= function
)
8150 /* Emit debug info for the address of the end of the function. */
8151 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
8154 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8155 "DW_LNS_fixed_advance_pc");
8156 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8160 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8161 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8162 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8163 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8166 /* Output the marker for the end of this sequence. */
8167 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8168 dw2_asm_output_data_uleb128 (1, NULL
);
8169 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8173 /* Output the marker for the end of the line number info. */
8174 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
8177 /* Given a pointer to a tree node for some base type, return a pointer to
8178 a DIE that describes the given type.
8180 This routine must only be called for GCC type nodes that correspond to
8181 Dwarf base (fundamental) types. */
8184 base_type_die (tree type
)
8186 dw_die_ref base_type_result
;
8187 enum dwarf_type encoding
;
8189 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
8192 switch (TREE_CODE (type
))
8195 if (TYPE_STRING_FLAG (type
))
8197 if (TYPE_UNSIGNED (type
))
8198 encoding
= DW_ATE_unsigned_char
;
8200 encoding
= DW_ATE_signed_char
;
8202 else if (TYPE_UNSIGNED (type
))
8203 encoding
= DW_ATE_unsigned
;
8205 encoding
= DW_ATE_signed
;
8209 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
8210 encoding
= DW_ATE_decimal_float
;
8212 encoding
= DW_ATE_float
;
8215 /* Dwarf2 doesn't know anything about complex ints, so use
8216 a user defined type for it. */
8218 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
8219 encoding
= DW_ATE_complex_float
;
8221 encoding
= DW_ATE_lo_user
;
8225 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8226 encoding
= DW_ATE_boolean
;
8230 /* No other TREE_CODEs are Dwarf fundamental types. */
8234 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8236 /* This probably indicates a bug. */
8237 if (! TYPE_NAME (type
))
8238 add_name_attribute (base_type_result
, "__unknown__");
8240 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8241 int_size_in_bytes (type
));
8242 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8244 return base_type_result
;
8247 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8248 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8249 a given type is generally the same as the given type, except that if the
8250 given type is a pointer or reference type, then the root type of the given
8251 type is the root type of the "basis" type for the pointer or reference
8252 type. (This definition of the "root" type is recursive.) Also, the root
8253 type of a `const' qualified type or a `volatile' qualified type is the
8254 root type of the given type without the qualifiers. */
8257 root_type (tree type
)
8259 if (TREE_CODE (type
) == ERROR_MARK
)
8260 return error_mark_node
;
8262 switch (TREE_CODE (type
))
8265 return error_mark_node
;
8268 case REFERENCE_TYPE
:
8269 return type_main_variant (root_type (TREE_TYPE (type
)));
8272 return type_main_variant (type
);
8276 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8277 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8280 is_base_type (tree type
)
8282 switch (TREE_CODE (type
))
8295 case QUAL_UNION_TYPE
:
8300 case REFERENCE_TYPE
:
8313 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8314 node, return the size in bits for the type if it is a constant, or else
8315 return the alignment for the type if the type's size is not constant, or
8316 else return BITS_PER_WORD if the type actually turns out to be an
8319 static inline unsigned HOST_WIDE_INT
8320 simple_type_size_in_bits (tree type
)
8322 if (TREE_CODE (type
) == ERROR_MARK
)
8323 return BITS_PER_WORD
;
8324 else if (TYPE_SIZE (type
) == NULL_TREE
)
8326 else if (host_integerp (TYPE_SIZE (type
), 1))
8327 return tree_low_cst (TYPE_SIZE (type
), 1);
8329 return TYPE_ALIGN (type
);
8332 /* Return true if the debug information for the given type should be
8333 emitted as a subrange type. */
8336 is_subrange_type (tree type
)
8338 tree subtype
= TREE_TYPE (type
);
8340 /* Subrange types are identified by the fact that they are integer
8341 types, and that they have a subtype which is either an integer type
8342 or an enumeral type. */
8344 if (TREE_CODE (type
) != INTEGER_TYPE
8345 || subtype
== NULL_TREE
)
8348 if (TREE_CODE (subtype
) != INTEGER_TYPE
8349 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8352 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8353 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8354 && TYPE_MIN_VALUE (type
) != NULL
8355 && TYPE_MIN_VALUE (subtype
) != NULL
8356 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8357 && TYPE_MAX_VALUE (type
) != NULL
8358 && TYPE_MAX_VALUE (subtype
) != NULL
8359 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8361 /* The type and its subtype have the same representation. If in
8362 addition the two types also have the same name, then the given
8363 type is not a subrange type, but rather a plain base type. */
8364 /* FIXME: brobecker/2004-03-22:
8365 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8366 therefore be sufficient to check the TYPE_SIZE node pointers
8367 rather than checking the actual size. Unfortunately, we have
8368 found some cases, such as in the Ada "integer" type, where
8369 this is not the case. Until this problem is solved, we need to
8370 keep checking the actual size. */
8371 tree type_name
= TYPE_NAME (type
);
8372 tree subtype_name
= TYPE_NAME (subtype
);
8374 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8375 type_name
= DECL_NAME (type_name
);
8377 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8378 subtype_name
= DECL_NAME (subtype_name
);
8380 if (type_name
== subtype_name
)
8387 /* Given a pointer to a tree node for a subrange type, return a pointer
8388 to a DIE that describes the given type. */
8391 subrange_type_die (tree type
, dw_die_ref context_die
)
8393 dw_die_ref subrange_die
;
8394 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8396 if (context_die
== NULL
)
8397 context_die
= comp_unit_die
;
8399 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8401 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
8403 /* The size of the subrange type and its base type do not match,
8404 so we need to generate a size attribute for the subrange type. */
8405 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8408 if (TYPE_MIN_VALUE (type
) != NULL
)
8409 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8410 TYPE_MIN_VALUE (type
));
8411 if (TYPE_MAX_VALUE (type
) != NULL
)
8412 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8413 TYPE_MAX_VALUE (type
));
8415 return subrange_die
;
8418 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8419 entry that chains various modifiers in front of the given type. */
8422 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8423 dw_die_ref context_die
)
8425 enum tree_code code
= TREE_CODE (type
);
8426 dw_die_ref mod_type_die
;
8427 dw_die_ref sub_die
= NULL
;
8428 tree item_type
= NULL
;
8429 tree qualified_type
;
8432 if (code
== ERROR_MARK
)
8435 /* See if we already have the appropriately qualified variant of
8438 = get_qualified_type (type
,
8439 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8440 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
8442 /* If we do, then we can just use its DIE, if it exists. */
8445 mod_type_die
= lookup_type_die (qualified_type
);
8447 return mod_type_die
;
8450 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
8452 /* Handle C typedef types. */
8453 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8455 tree dtype
= TREE_TYPE (name
);
8457 if (qualified_type
== dtype
)
8459 /* For a named type, use the typedef. */
8460 gen_type_die (qualified_type
, context_die
);
8461 return lookup_type_die (qualified_type
);
8463 else if (is_const_type
< TYPE_READONLY (dtype
)
8464 || is_volatile_type
< TYPE_VOLATILE (dtype
)
8465 || (is_const_type
<= TYPE_READONLY (dtype
)
8466 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
8467 && DECL_ORIGINAL_TYPE (name
) != type
))
8468 /* cv-unqualified version of named type. Just use the unnamed
8469 type to which it refers. */
8470 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
8471 is_const_type
, is_volatile_type
,
8473 /* Else cv-qualified version of named type; fall through. */
8478 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8479 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8481 else if (is_volatile_type
)
8483 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8484 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8486 else if (code
== POINTER_TYPE
)
8488 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8489 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8490 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8491 item_type
= TREE_TYPE (type
);
8493 else if (code
== REFERENCE_TYPE
)
8495 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8496 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8497 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8498 item_type
= TREE_TYPE (type
);
8500 else if (is_subrange_type (type
))
8502 mod_type_die
= subrange_type_die (type
, context_die
);
8503 item_type
= TREE_TYPE (type
);
8505 else if (is_base_type (type
))
8506 mod_type_die
= base_type_die (type
);
8509 gen_type_die (type
, context_die
);
8511 /* We have to get the type_main_variant here (and pass that to the
8512 `lookup_type_die' routine) because the ..._TYPE node we have
8513 might simply be a *copy* of some original type node (where the
8514 copy was created to help us keep track of typedef names) and
8515 that copy might have a different TYPE_UID from the original
8517 if (TREE_CODE (type
) != VECTOR_TYPE
)
8518 return lookup_type_die (type_main_variant (type
));
8520 /* Vectors have the debugging information in the type,
8521 not the main variant. */
8522 return lookup_type_die (type
);
8525 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8526 don't output a DW_TAG_typedef, since there isn't one in the
8527 user's program; just attach a DW_AT_name to the type. */
8529 && (TREE_CODE (name
) != TYPE_DECL
8530 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
8532 if (TREE_CODE (name
) == TYPE_DECL
)
8533 /* Could just call add_name_and_src_coords_attributes here,
8534 but since this is a builtin type it doesn't have any
8535 useful source coordinates anyway. */
8536 name
= DECL_NAME (name
);
8537 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
8541 equate_type_number_to_die (qualified_type
, mod_type_die
);
8544 /* We must do this after the equate_type_number_to_die call, in case
8545 this is a recursive type. This ensures that the modified_type_die
8546 recursion will terminate even if the type is recursive. Recursive
8547 types are possible in Ada. */
8548 sub_die
= modified_type_die (item_type
,
8549 TYPE_READONLY (item_type
),
8550 TYPE_VOLATILE (item_type
),
8553 if (sub_die
!= NULL
)
8554 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8556 return mod_type_die
;
8559 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8560 an enumerated type. */
8563 type_is_enum (tree type
)
8565 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8568 /* Return the DBX register number described by a given RTL node. */
8571 dbx_reg_number (rtx rtl
)
8573 unsigned regno
= REGNO (rtl
);
8575 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
8577 #ifdef LEAF_REG_REMAP
8578 if (current_function_uses_only_leaf_regs
)
8580 int leaf_reg
= LEAF_REG_REMAP (regno
);
8582 regno
= (unsigned) leaf_reg
;
8586 return DBX_REGISTER_NUMBER (regno
);
8589 /* Optionally add a DW_OP_piece term to a location description expression.
8590 DW_OP_piece is only added if the location description expression already
8591 doesn't end with DW_OP_piece. */
8594 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
8596 dw_loc_descr_ref loc
;
8598 if (*list_head
!= NULL
)
8600 /* Find the end of the chain. */
8601 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
8604 if (loc
->dw_loc_opc
!= DW_OP_piece
)
8605 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
8609 /* Return a location descriptor that designates a machine register or
8610 zero if there is none. */
8612 static dw_loc_descr_ref
8613 reg_loc_descriptor (rtx rtl
)
8617 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8620 regs
= targetm
.dwarf_register_span (rtl
);
8622 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
8623 return multiple_reg_loc_descriptor (rtl
, regs
);
8625 return one_reg_loc_descriptor (dbx_reg_number (rtl
));
8628 /* Return a location descriptor that designates a machine register for
8629 a given hard register number. */
8631 static dw_loc_descr_ref
8632 one_reg_loc_descriptor (unsigned int regno
)
8635 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8637 return new_loc_descr (DW_OP_regx
, regno
, 0);
8640 /* Given an RTL of a register, return a location descriptor that
8641 designates a value that spans more than one register. */
8643 static dw_loc_descr_ref
8644 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8648 dw_loc_descr_ref loc_result
= NULL
;
8651 #ifdef LEAF_REG_REMAP
8652 if (current_function_uses_only_leaf_regs
)
8654 int leaf_reg
= LEAF_REG_REMAP (reg
);
8656 reg
= (unsigned) leaf_reg
;
8659 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
8660 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8662 /* Simple, contiguous registers. */
8663 if (regs
== NULL_RTX
)
8665 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8672 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
));
8673 add_loc_descr (&loc_result
, t
);
8674 add_loc_descr_op_piece (&loc_result
, size
);
8680 /* Now onto stupid register sets in non contiguous locations. */
8682 gcc_assert (GET_CODE (regs
) == PARALLEL
);
8684 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8687 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8691 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8692 add_loc_descr (&loc_result
, t
);
8693 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8694 add_loc_descr_op_piece (&loc_result
, size
);
8699 /* Return a location descriptor that designates a constant. */
8701 static dw_loc_descr_ref
8702 int_loc_descriptor (HOST_WIDE_INT i
)
8704 enum dwarf_location_atom op
;
8706 /* Pick the smallest representation of a constant, rather than just
8707 defaulting to the LEB encoding. */
8711 op
= DW_OP_lit0
+ i
;
8714 else if (i
<= 0xffff)
8716 else if (HOST_BITS_PER_WIDE_INT
== 32
8726 else if (i
>= -0x8000)
8728 else if (HOST_BITS_PER_WIDE_INT
== 32
8729 || i
>= -0x80000000)
8735 return new_loc_descr (op
, i
, 0);
8738 /* Return a location descriptor that designates a base+offset location. */
8740 static dw_loc_descr_ref
8741 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
)
8745 /* We only use "frame base" when we're sure we're talking about the
8746 post-prologue local stack frame. We do this by *not* running
8747 register elimination until this point, and recognizing the special
8748 argument pointer and soft frame pointer rtx's. */
8749 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
8751 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
8755 if (GET_CODE (elim
) == PLUS
)
8757 offset
+= INTVAL (XEXP (elim
, 1));
8758 elim
= XEXP (elim
, 0);
8760 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
8761 : stack_pointer_rtx
));
8762 offset
+= frame_pointer_fb_offset
;
8764 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
8768 regno
= dbx_reg_number (reg
);
8770 return new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
8772 return new_loc_descr (DW_OP_bregx
, regno
, offset
);
8775 /* Return true if this RTL expression describes a base+offset calculation. */
8778 is_based_loc (rtx rtl
)
8780 return (GET_CODE (rtl
) == PLUS
8781 && ((REG_P (XEXP (rtl
, 0))
8782 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8783 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8786 /* The following routine converts the RTL for a variable or parameter
8787 (resident in memory) into an equivalent Dwarf representation of a
8788 mechanism for getting the address of that same variable onto the top of a
8789 hypothetical "address evaluation" stack.
8791 When creating memory location descriptors, we are effectively transforming
8792 the RTL for a memory-resident object into its Dwarf postfix expression
8793 equivalent. This routine recursively descends an RTL tree, turning
8794 it into Dwarf postfix code as it goes.
8796 MODE is the mode of the memory reference, needed to handle some
8797 autoincrement addressing modes.
8799 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8800 location list for RTL.
8802 Return 0 if we can't represent the location. */
8804 static dw_loc_descr_ref
8805 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
)
8807 dw_loc_descr_ref mem_loc_result
= NULL
;
8808 enum dwarf_location_atom op
;
8810 /* Note that for a dynamically sized array, the location we will generate a
8811 description of here will be the lowest numbered location which is
8812 actually within the array. That's *not* necessarily the same as the
8813 zeroth element of the array. */
8815 rtl
= targetm
.delegitimize_address (rtl
);
8817 switch (GET_CODE (rtl
))
8822 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8823 just fall into the SUBREG code. */
8825 /* ... fall through ... */
8828 /* The case of a subreg may arise when we have a local (register)
8829 variable or a formal (register) parameter which doesn't quite fill
8830 up an entire register. For now, just assume that it is
8831 legitimate to make the Dwarf info refer to the whole register which
8832 contains the given subreg. */
8833 rtl
= XEXP (rtl
, 0);
8835 /* ... fall through ... */
8838 /* Whenever a register number forms a part of the description of the
8839 method for calculating the (dynamic) address of a memory resident
8840 object, DWARF rules require the register number be referred to as
8841 a "base register". This distinction is not based in any way upon
8842 what category of register the hardware believes the given register
8843 belongs to. This is strictly DWARF terminology we're dealing with
8844 here. Note that in cases where the location of a memory-resident
8845 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8846 OP_CONST (0)) the actual DWARF location descriptor that we generate
8847 may just be OP_BASEREG (basereg). This may look deceptively like
8848 the object in question was allocated to a register (rather than in
8849 memory) so DWARF consumers need to be aware of the subtle
8850 distinction between OP_REG and OP_BASEREG. */
8851 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8852 mem_loc_result
= based_loc_descr (rtl
, 0);
8856 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8857 if (mem_loc_result
!= 0)
8858 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8862 rtl
= XEXP (rtl
, 1);
8864 /* ... fall through ... */
8867 /* Some ports can transform a symbol ref into a label ref, because
8868 the symbol ref is too far away and has to be dumped into a constant
8872 /* Alternatively, the symbol in the constant pool might be referenced
8873 by a different symbol. */
8874 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8877 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8879 if (GET_CODE (tmp
) == SYMBOL_REF
)
8882 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8883 get_pool_constant_mark (tmp
, &marked
);
8888 /* If all references to this pool constant were optimized away,
8889 it was not output and thus we can't represent it.
8890 FIXME: might try to use DW_OP_const_value here, though
8891 DW_OP_piece complicates it. */
8896 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8897 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8898 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8899 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
8903 /* Extract the PLUS expression nested inside and fall into
8905 rtl
= XEXP (rtl
, 1);
8910 /* Turn these into a PLUS expression and fall into the PLUS code
8912 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8913 GEN_INT (GET_CODE (rtl
) == PRE_INC
8914 ? GET_MODE_UNIT_SIZE (mode
)
8915 : -GET_MODE_UNIT_SIZE (mode
)));
8917 /* ... fall through ... */
8921 if (is_based_loc (rtl
))
8922 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
8923 INTVAL (XEXP (rtl
, 1)));
8926 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8927 if (mem_loc_result
== 0)
8930 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8931 && INTVAL (XEXP (rtl
, 1)) >= 0)
8932 add_loc_descr (&mem_loc_result
,
8933 new_loc_descr (DW_OP_plus_uconst
,
8934 INTVAL (XEXP (rtl
, 1)), 0));
8937 add_loc_descr (&mem_loc_result
,
8938 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8939 add_loc_descr (&mem_loc_result
,
8940 new_loc_descr (DW_OP_plus
, 0, 0));
8945 /* If a pseudo-reg is optimized away, it is possible for it to
8946 be replaced with a MEM containing a multiply or shift. */
8965 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8966 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8968 if (op0
== 0 || op1
== 0)
8971 mem_loc_result
= op0
;
8972 add_loc_descr (&mem_loc_result
, op1
);
8973 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8978 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8985 return mem_loc_result
;
8988 /* Return a descriptor that describes the concatenation of two locations.
8989 This is typically a complex variable. */
8991 static dw_loc_descr_ref
8992 concat_loc_descriptor (rtx x0
, rtx x1
)
8994 dw_loc_descr_ref cc_loc_result
= NULL
;
8995 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8996 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8998 if (x0_ref
== 0 || x1_ref
== 0)
9001 cc_loc_result
= x0_ref
;
9002 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
9004 add_loc_descr (&cc_loc_result
, x1_ref
);
9005 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
9007 return cc_loc_result
;
9010 /* Output a proper Dwarf location descriptor for a variable or parameter
9011 which is either allocated in a register or in a memory location. For a
9012 register, we just generate an OP_REG and the register number. For a
9013 memory location we provide a Dwarf postfix expression describing how to
9014 generate the (dynamic) address of the object onto the address stack.
9016 If we don't know how to describe it, return 0. */
9018 static dw_loc_descr_ref
9019 loc_descriptor (rtx rtl
)
9021 dw_loc_descr_ref loc_result
= NULL
;
9023 switch (GET_CODE (rtl
))
9026 /* The case of a subreg may arise when we have a local (register)
9027 variable or a formal (register) parameter which doesn't quite fill
9028 up an entire register. For now, just assume that it is
9029 legitimate to make the Dwarf info refer to the whole register which
9030 contains the given subreg. */
9031 rtl
= SUBREG_REG (rtl
);
9033 /* ... fall through ... */
9036 loc_result
= reg_loc_descriptor (rtl
);
9040 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
9044 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
9049 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
9051 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0));
9055 rtl
= XEXP (rtl
, 1);
9060 rtvec par_elems
= XVEC (rtl
, 0);
9061 int num_elem
= GET_NUM_ELEM (par_elems
);
9062 enum machine_mode mode
;
9065 /* Create the first one, so we have something to add to. */
9066 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9067 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9068 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9069 for (i
= 1; i
< num_elem
; i
++)
9071 dw_loc_descr_ref temp
;
9073 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9074 add_loc_descr (&loc_result
, temp
);
9075 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9076 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9088 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9089 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9090 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9091 top-level invocation, and we require the address of LOC; is 0 if we require
9092 the value of LOC. */
9094 static dw_loc_descr_ref
9095 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
9097 dw_loc_descr_ref ret
, ret1
;
9098 int have_address
= 0;
9099 enum dwarf_location_atom op
;
9101 /* ??? Most of the time we do not take proper care for sign/zero
9102 extending the values properly. Hopefully this won't be a real
9105 switch (TREE_CODE (loc
))
9110 case PLACEHOLDER_EXPR
:
9111 /* This case involves extracting fields from an object to determine the
9112 position of other fields. We don't try to encode this here. The
9113 only user of this is Ada, which encodes the needed information using
9114 the names of types. */
9120 case PREINCREMENT_EXPR
:
9121 case PREDECREMENT_EXPR
:
9122 case POSTINCREMENT_EXPR
:
9123 case POSTDECREMENT_EXPR
:
9124 /* There are no opcodes for these operations. */
9128 /* If we already want an address, there's nothing we can do. */
9132 /* Otherwise, process the argument and look for the address. */
9133 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
9136 if (DECL_THREAD_LOCAL_P (loc
))
9140 /* If this is not defined, we have no way to emit the data. */
9141 if (!targetm
.asm_out
.output_dwarf_dtprel
)
9144 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9145 look up addresses of objects in the current module. */
9146 if (DECL_EXTERNAL (loc
))
9149 rtl
= rtl_for_decl_location (loc
);
9150 if (rtl
== NULL_RTX
)
9155 rtl
= XEXP (rtl
, 0);
9156 if (! CONSTANT_P (rtl
))
9159 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
9160 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9161 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9163 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
9164 add_loc_descr (&ret
, ret1
);
9172 if (DECL_HAS_VALUE_EXPR_P (loc
))
9173 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
9180 rtx rtl
= rtl_for_decl_location (loc
);
9182 if (rtl
== NULL_RTX
)
9184 else if (GET_CODE (rtl
) == CONST_INT
)
9186 HOST_WIDE_INT val
= INTVAL (rtl
);
9187 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
9188 val
&= GET_MODE_MASK (DECL_MODE (loc
));
9189 ret
= int_loc_descriptor (val
);
9191 else if (GET_CODE (rtl
) == CONST_STRING
)
9193 else if (CONSTANT_P (rtl
))
9195 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
9196 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9197 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9201 enum machine_mode mode
;
9203 /* Certain constructs can only be represented at top-level. */
9204 if (want_address
== 2)
9205 return loc_descriptor (rtl
);
9207 mode
= GET_MODE (rtl
);
9210 rtl
= XEXP (rtl
, 0);
9213 ret
= mem_loc_descriptor (rtl
, mode
);
9219 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9224 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
9228 case NON_LVALUE_EXPR
:
9229 case VIEW_CONVERT_EXPR
:
9232 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
9237 case ARRAY_RANGE_REF
:
9240 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9241 enum machine_mode mode
;
9243 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
9245 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9246 &unsignedp
, &volatilep
, false);
9251 ret
= loc_descriptor_from_tree_1 (obj
, 1);
9253 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9256 if (offset
!= NULL_TREE
)
9258 /* Variable offset. */
9259 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
9260 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9263 bytepos
= bitpos
/ BITS_PER_UNIT
;
9265 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
9266 else if (bytepos
< 0)
9268 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
9269 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9277 if (host_integerp (loc
, 0))
9278 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9285 /* Get an RTL for this, if something has been emitted. */
9286 rtx rtl
= lookup_constant_def (loc
);
9287 enum machine_mode mode
;
9289 if (!rtl
|| !MEM_P (rtl
))
9291 mode
= GET_MODE (rtl
);
9292 rtl
= XEXP (rtl
, 0);
9293 ret
= mem_loc_descriptor (rtl
, mode
);
9298 case TRUTH_AND_EXPR
:
9299 case TRUTH_ANDIF_EXPR
:
9304 case TRUTH_XOR_EXPR
:
9310 case TRUTH_ORIF_EXPR
:
9315 case FLOOR_DIV_EXPR
:
9317 case ROUND_DIV_EXPR
:
9318 case TRUNC_DIV_EXPR
:
9326 case FLOOR_MOD_EXPR
:
9328 case ROUND_MOD_EXPR
:
9329 case TRUNC_MOD_EXPR
:
9342 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
9346 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9347 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9349 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9353 add_loc_descr (&ret
,
9354 new_loc_descr (DW_OP_plus_uconst
,
9355 tree_low_cst (TREE_OPERAND (loc
, 1),
9365 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9372 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9379 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9386 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9401 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9402 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9403 if (ret
== 0 || ret1
== 0)
9406 add_loc_descr (&ret
, ret1
);
9407 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9410 case TRUTH_NOT_EXPR
:
9424 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9428 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9434 const enum tree_code code
=
9435 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9437 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
9438 build2 (code
, integer_type_node
,
9439 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9440 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9443 /* ... fall through ... */
9447 dw_loc_descr_ref lhs
9448 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9449 dw_loc_descr_ref rhs
9450 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
9451 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9453 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9454 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9457 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9458 add_loc_descr (&ret
, bra_node
);
9460 add_loc_descr (&ret
, rhs
);
9461 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9462 add_loc_descr (&ret
, jump_node
);
9464 add_loc_descr (&ret
, lhs
);
9465 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9466 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9468 /* ??? Need a node to point the skip at. Use a nop. */
9469 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9470 add_loc_descr (&ret
, tmp
);
9471 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9472 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9476 case FIX_TRUNC_EXPR
:
9478 case FIX_FLOOR_EXPR
:
9479 case FIX_ROUND_EXPR
:
9483 /* Leave front-end specific codes as simply unknown. This comes
9484 up, for instance, with the C STMT_EXPR. */
9485 if ((unsigned int) TREE_CODE (loc
)
9486 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9489 #ifdef ENABLE_CHECKING
9490 /* Otherwise this is a generic code; we should just lists all of
9491 these explicitly. We forgot one. */
9494 /* In a release build, we want to degrade gracefully: better to
9495 generate incomplete debugging information than to crash. */
9500 /* Show if we can't fill the request for an address. */
9501 if (want_address
&& !have_address
)
9504 /* If we've got an address and don't want one, dereference. */
9505 if (!want_address
&& have_address
&& ret
)
9507 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9509 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9511 else if (size
== DWARF2_ADDR_SIZE
)
9514 op
= DW_OP_deref_size
;
9516 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9522 static inline dw_loc_descr_ref
9523 loc_descriptor_from_tree (tree loc
)
9525 return loc_descriptor_from_tree_1 (loc
, 2);
9528 /* Given a value, round it up to the lowest multiple of `boundary'
9529 which is not less than the value itself. */
9531 static inline HOST_WIDE_INT
9532 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9534 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9537 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9538 pointer to the declared type for the relevant field variable, or return
9539 `integer_type_node' if the given node turns out to be an
9543 field_type (tree decl
)
9547 if (TREE_CODE (decl
) == ERROR_MARK
)
9548 return integer_type_node
;
9550 type
= DECL_BIT_FIELD_TYPE (decl
);
9551 if (type
== NULL_TREE
)
9552 type
= TREE_TYPE (decl
);
9557 /* Given a pointer to a tree node, return the alignment in bits for
9558 it, or else return BITS_PER_WORD if the node actually turns out to
9559 be an ERROR_MARK node. */
9561 static inline unsigned
9562 simple_type_align_in_bits (tree type
)
9564 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9567 static inline unsigned
9568 simple_decl_align_in_bits (tree decl
)
9570 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9573 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9574 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9575 or return 0 if we are unable to determine what that offset is, either
9576 because the argument turns out to be a pointer to an ERROR_MARK node, or
9577 because the offset is actually variable. (We can't handle the latter case
9580 static HOST_WIDE_INT
9581 field_byte_offset (tree decl
)
9583 unsigned int type_align_in_bits
;
9584 unsigned int decl_align_in_bits
;
9585 unsigned HOST_WIDE_INT type_size_in_bits
;
9586 HOST_WIDE_INT object_offset_in_bits
;
9588 tree field_size_tree
;
9589 HOST_WIDE_INT bitpos_int
;
9590 HOST_WIDE_INT deepest_bitpos
;
9591 unsigned HOST_WIDE_INT field_size_in_bits
;
9593 if (TREE_CODE (decl
) == ERROR_MARK
)
9596 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
9598 type
= field_type (decl
);
9599 field_size_tree
= DECL_SIZE (decl
);
9601 /* The size could be unspecified if there was an error, or for
9602 a flexible array member. */
9603 if (! field_size_tree
)
9604 field_size_tree
= bitsize_zero_node
;
9606 /* We cannot yet cope with fields whose positions are variable, so
9607 for now, when we see such things, we simply return 0. Someday, we may
9608 be able to handle such cases, but it will be damn difficult. */
9609 if (! host_integerp (bit_position (decl
), 0))
9612 bitpos_int
= int_bit_position (decl
);
9614 /* If we don't know the size of the field, pretend it's a full word. */
9615 if (host_integerp (field_size_tree
, 1))
9616 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9618 field_size_in_bits
= BITS_PER_WORD
;
9620 type_size_in_bits
= simple_type_size_in_bits (type
);
9621 type_align_in_bits
= simple_type_align_in_bits (type
);
9622 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9624 /* The GCC front-end doesn't make any attempt to keep track of the starting
9625 bit offset (relative to the start of the containing structure type) of the
9626 hypothetical "containing object" for a bit-field. Thus, when computing
9627 the byte offset value for the start of the "containing object" of a
9628 bit-field, we must deduce this information on our own. This can be rather
9629 tricky to do in some cases. For example, handling the following structure
9630 type definition when compiling for an i386/i486 target (which only aligns
9631 long long's to 32-bit boundaries) can be very tricky:
9633 struct S { int field1; long long field2:31; };
9635 Fortunately, there is a simple rule-of-thumb which can be used in such
9636 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9637 structure shown above. It decides to do this based upon one simple rule
9638 for bit-field allocation. GCC allocates each "containing object" for each
9639 bit-field at the first (i.e. lowest addressed) legitimate alignment
9640 boundary (based upon the required minimum alignment for the declared type
9641 of the field) which it can possibly use, subject to the condition that
9642 there is still enough available space remaining in the containing object
9643 (when allocated at the selected point) to fully accommodate all of the
9644 bits of the bit-field itself.
9646 This simple rule makes it obvious why GCC allocates 8 bytes for each
9647 object of the structure type shown above. When looking for a place to
9648 allocate the "containing object" for `field2', the compiler simply tries
9649 to allocate a 64-bit "containing object" at each successive 32-bit
9650 boundary (starting at zero) until it finds a place to allocate that 64-
9651 bit field such that at least 31 contiguous (and previously unallocated)
9652 bits remain within that selected 64 bit field. (As it turns out, for the
9653 example above, the compiler finds it is OK to allocate the "containing
9654 object" 64-bit field at bit-offset zero within the structure type.)
9656 Here we attempt to work backwards from the limited set of facts we're
9657 given, and we try to deduce from those facts, where GCC must have believed
9658 that the containing object started (within the structure type). The value
9659 we deduce is then used (by the callers of this routine) to generate
9660 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9661 and, in the case of DW_AT_location, regular fields as well). */
9663 /* Figure out the bit-distance from the start of the structure to the
9664 "deepest" bit of the bit-field. */
9665 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9667 /* This is the tricky part. Use some fancy footwork to deduce where the
9668 lowest addressed bit of the containing object must be. */
9669 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9671 /* Round up to type_align by default. This works best for bitfields. */
9672 object_offset_in_bits
+= type_align_in_bits
- 1;
9673 object_offset_in_bits
/= type_align_in_bits
;
9674 object_offset_in_bits
*= type_align_in_bits
;
9676 if (object_offset_in_bits
> bitpos_int
)
9678 /* Sigh, the decl must be packed. */
9679 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9681 /* Round up to decl_align instead. */
9682 object_offset_in_bits
+= decl_align_in_bits
- 1;
9683 object_offset_in_bits
/= decl_align_in_bits
;
9684 object_offset_in_bits
*= decl_align_in_bits
;
9687 return object_offset_in_bits
/ BITS_PER_UNIT
;
9690 /* The following routines define various Dwarf attributes and any data
9691 associated with them. */
9693 /* Add a location description attribute value to a DIE.
9695 This emits location attributes suitable for whole variables and
9696 whole parameters. Note that the location attributes for struct fields are
9697 generated by the routine `data_member_location_attribute' below. */
9700 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9701 dw_loc_descr_ref descr
)
9704 add_AT_loc (die
, attr_kind
, descr
);
9707 /* Attach the specialized form of location attribute used for data members of
9708 struct and union types. In the special case of a FIELD_DECL node which
9709 represents a bit-field, the "offset" part of this special location
9710 descriptor must indicate the distance in bytes from the lowest-addressed
9711 byte of the containing struct or union type to the lowest-addressed byte of
9712 the "containing object" for the bit-field. (See the `field_byte_offset'
9715 For any given bit-field, the "containing object" is a hypothetical object
9716 (of some integral or enum type) within which the given bit-field lives. The
9717 type of this hypothetical "containing object" is always the same as the
9718 declared type of the individual bit-field itself (for GCC anyway... the
9719 DWARF spec doesn't actually mandate this). Note that it is the size (in
9720 bytes) of the hypothetical "containing object" which will be given in the
9721 DW_AT_byte_size attribute for this bit-field. (See the
9722 `byte_size_attribute' function below.) It is also used when calculating the
9723 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9727 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9729 HOST_WIDE_INT offset
;
9730 dw_loc_descr_ref loc_descr
= 0;
9732 if (TREE_CODE (decl
) == TREE_BINFO
)
9734 /* We're working on the TAG_inheritance for a base class. */
9735 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
9737 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9738 aren't at a fixed offset from all (sub)objects of the same
9739 type. We need to extract the appropriate offset from our
9740 vtable. The following dwarf expression means
9742 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9744 This is specific to the V3 ABI, of course. */
9746 dw_loc_descr_ref tmp
;
9748 /* Make a copy of the object address. */
9749 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9750 add_loc_descr (&loc_descr
, tmp
);
9752 /* Extract the vtable address. */
9753 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9754 add_loc_descr (&loc_descr
, tmp
);
9756 /* Calculate the address of the offset. */
9757 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9758 gcc_assert (offset
< 0);
9760 tmp
= int_loc_descriptor (-offset
);
9761 add_loc_descr (&loc_descr
, tmp
);
9762 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9763 add_loc_descr (&loc_descr
, tmp
);
9765 /* Extract the offset. */
9766 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9767 add_loc_descr (&loc_descr
, tmp
);
9769 /* Add it to the object address. */
9770 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9771 add_loc_descr (&loc_descr
, tmp
);
9774 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9777 offset
= field_byte_offset (decl
);
9781 enum dwarf_location_atom op
;
9783 /* The DWARF2 standard says that we should assume that the structure
9784 address is already on the stack, so we can specify a structure field
9785 address by using DW_OP_plus_uconst. */
9787 #ifdef MIPS_DEBUGGING_INFO
9788 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9789 operator correctly. It works only if we leave the offset on the
9793 op
= DW_OP_plus_uconst
;
9796 loc_descr
= new_loc_descr (op
, offset
, 0);
9799 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9802 /* Writes integer values to dw_vec_const array. */
9805 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9809 *dest
++ = val
& 0xff;
9815 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9817 static HOST_WIDE_INT
9818 extract_int (const unsigned char *src
, unsigned int size
)
9820 HOST_WIDE_INT val
= 0;
9826 val
|= *--src
& 0xff;
9832 /* Writes floating point values to dw_vec_const array. */
9835 insert_float (rtx rtl
, unsigned char *array
)
9841 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9842 real_to_target (val
, &rv
, GET_MODE (rtl
));
9844 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9845 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9847 insert_int (val
[i
], 4, array
);
9852 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9853 does not have a "location" either in memory or in a register. These
9854 things can arise in GNU C when a constant is passed as an actual parameter
9855 to an inlined function. They can also arise in C++ where declared
9856 constants do not necessarily get memory "homes". */
9859 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9861 switch (GET_CODE (rtl
))
9865 HOST_WIDE_INT val
= INTVAL (rtl
);
9868 add_AT_int (die
, DW_AT_const_value
, val
);
9870 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9875 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9876 floating-point constant. A CONST_DOUBLE is used whenever the
9877 constant requires more than one word in order to be adequately
9878 represented. We output CONST_DOUBLEs as blocks. */
9880 enum machine_mode mode
= GET_MODE (rtl
);
9882 if (SCALAR_FLOAT_MODE_P (mode
))
9884 unsigned int length
= GET_MODE_SIZE (mode
);
9885 unsigned char *array
= ggc_alloc (length
);
9887 insert_float (rtl
, array
);
9888 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9892 /* ??? We really should be using HOST_WIDE_INT throughout. */
9893 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
9895 add_AT_long_long (die
, DW_AT_const_value
,
9896 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9903 enum machine_mode mode
= GET_MODE (rtl
);
9904 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9905 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9906 unsigned char *array
= ggc_alloc (length
* elt_size
);
9910 switch (GET_MODE_CLASS (mode
))
9912 case MODE_VECTOR_INT
:
9913 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9915 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9916 HOST_WIDE_INT lo
, hi
;
9918 switch (GET_CODE (elt
))
9926 lo
= CONST_DOUBLE_LOW (elt
);
9927 hi
= CONST_DOUBLE_HIGH (elt
);
9934 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9935 insert_int (lo
, elt_size
, p
);
9938 unsigned char *p0
= p
;
9939 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9941 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
9942 if (WORDS_BIG_ENDIAN
)
9947 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9948 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9953 case MODE_VECTOR_FLOAT
:
9954 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9956 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9957 insert_float (elt
, p
);
9965 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9970 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9976 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9977 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
9981 /* In cases where an inlined instance of an inline function is passed
9982 the address of an `auto' variable (which is local to the caller) we
9983 can get a situation where the DECL_RTL of the artificial local
9984 variable (for the inlining) which acts as a stand-in for the
9985 corresponding formal parameter (of the inline function) will look
9986 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9987 exactly a compile-time constant expression, but it isn't the address
9988 of the (artificial) local variable either. Rather, it represents the
9989 *value* which the artificial local variable always has during its
9990 lifetime. We currently have no way to represent such quasi-constant
9991 values in Dwarf, so for now we just punt and generate nothing. */
9995 /* No other kinds of rtx should be possible here. */
10001 /* Determine whether the evaluation of EXPR references any variables
10002 or functions which aren't otherwise used (and therefore may not be
10005 reference_to_unused (tree
* tp
, int * walk_subtrees
,
10006 void * data ATTRIBUTE_UNUSED
)
10008 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
10009 *walk_subtrees
= 0;
10011 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
10012 && ! TREE_ASM_WRITTEN (*tp
))
10014 else if (!flag_unit_at_a_time
)
10016 else if (!cgraph_global_info_ready
10017 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
10018 gcc_unreachable ();
10019 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
10021 struct cgraph_varpool_node
*node
= cgraph_varpool_node (*tp
);
10025 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
10026 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
10028 struct cgraph_node
*node
= cgraph_node (*tp
);
10036 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10037 for use in a later add_const_value_attribute call. */
10040 rtl_for_decl_init (tree init
, tree type
)
10042 rtx rtl
= NULL_RTX
;
10044 /* If a variable is initialized with a string constant without embedded
10045 zeros, build CONST_STRING. */
10046 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
10048 tree enttype
= TREE_TYPE (type
);
10049 tree domain
= TYPE_DOMAIN (type
);
10050 enum machine_mode mode
= TYPE_MODE (enttype
);
10052 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
10054 && integer_zerop (TYPE_MIN_VALUE (domain
))
10055 && compare_tree_int (TYPE_MAX_VALUE (domain
),
10056 TREE_STRING_LENGTH (init
) - 1) == 0
10057 && ((size_t) TREE_STRING_LENGTH (init
)
10058 == strlen (TREE_STRING_POINTER (init
)) + 1))
10059 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
10060 ggc_strdup (TREE_STRING_POINTER (init
)));
10062 /* Other aggregates, and complex values, could be represented using
10064 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
10066 /* Vectors only work if their mode is supported by the target.
10067 FIXME: generic vectors ought to work too. */
10068 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
10070 /* If the initializer is something that we know will expand into an
10071 immediate RTL constant, expand it now. We must be careful not to
10072 reference variables which won't be output. */
10073 else if (initializer_constant_valid_p (init
, type
)
10074 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
10076 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10078 if (TREE_CODE (type
) == VECTOR_TYPE
)
10079 switch (TREE_CODE (init
))
10084 if (TREE_CONSTANT (init
))
10086 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
10087 bool constant_p
= true;
10089 unsigned HOST_WIDE_INT ix
;
10091 /* Even when ctor is constant, it might contain non-*_CST
10092 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10093 belong into VECTOR_CST nodes. */
10094 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
10095 if (!CONSTANT_CLASS_P (value
))
10097 constant_p
= false;
10103 init
= build_vector_from_ctor (type
, elts
);
10113 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
10115 /* If expand_expr returns a MEM, it wasn't immediate. */
10116 gcc_assert (!rtl
|| !MEM_P (rtl
));
10122 /* Generate RTL for the variable DECL to represent its location. */
10125 rtl_for_decl_location (tree decl
)
10129 /* Here we have to decide where we are going to say the parameter "lives"
10130 (as far as the debugger is concerned). We only have a couple of
10131 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10133 DECL_RTL normally indicates where the parameter lives during most of the
10134 activation of the function. If optimization is enabled however, this
10135 could be either NULL or else a pseudo-reg. Both of those cases indicate
10136 that the parameter doesn't really live anywhere (as far as the code
10137 generation parts of GCC are concerned) during most of the function's
10138 activation. That will happen (for example) if the parameter is never
10139 referenced within the function.
10141 We could just generate a location descriptor here for all non-NULL
10142 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10143 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10144 where DECL_RTL is NULL or is a pseudo-reg.
10146 Note however that we can only get away with using DECL_INCOMING_RTL as
10147 a backup substitute for DECL_RTL in certain limited cases. In cases
10148 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10149 we can be sure that the parameter was passed using the same type as it is
10150 declared to have within the function, and that its DECL_INCOMING_RTL
10151 points us to a place where a value of that type is passed.
10153 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10154 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10155 because in these cases DECL_INCOMING_RTL points us to a value of some
10156 type which is *different* from the type of the parameter itself. Thus,
10157 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10158 such cases, the debugger would end up (for example) trying to fetch a
10159 `float' from a place which actually contains the first part of a
10160 `double'. That would lead to really incorrect and confusing
10161 output at debug-time.
10163 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10164 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10165 are a couple of exceptions however. On little-endian machines we can
10166 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10167 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10168 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10169 when (on a little-endian machine) a non-prototyped function has a
10170 parameter declared to be of type `short' or `char'. In such cases,
10171 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10172 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10173 passed `int' value. If the debugger then uses that address to fetch
10174 a `short' or a `char' (on a little-endian machine) the result will be
10175 the correct data, so we allow for such exceptional cases below.
10177 Note that our goal here is to describe the place where the given formal
10178 parameter lives during most of the function's activation (i.e. between the
10179 end of the prologue and the start of the epilogue). We'll do that as best
10180 as we can. Note however that if the given formal parameter is modified
10181 sometime during the execution of the function, then a stack backtrace (at
10182 debug-time) will show the function as having been called with the *new*
10183 value rather than the value which was originally passed in. This happens
10184 rarely enough that it is not a major problem, but it *is* a problem, and
10185 I'd like to fix it.
10187 A future version of dwarf2out.c may generate two additional attributes for
10188 any given DW_TAG_formal_parameter DIE which will describe the "passed
10189 type" and the "passed location" for the given formal parameter in addition
10190 to the attributes we now generate to indicate the "declared type" and the
10191 "active location" for each parameter. This additional set of attributes
10192 could be used by debuggers for stack backtraces. Separately, note that
10193 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10194 This happens (for example) for inlined-instances of inline function formal
10195 parameters which are never referenced. This really shouldn't be
10196 happening. All PARM_DECL nodes should get valid non-NULL
10197 DECL_INCOMING_RTL values. FIXME. */
10199 /* Use DECL_RTL as the "location" unless we find something better. */
10200 rtl
= DECL_RTL_IF_SET (decl
);
10202 /* When generating abstract instances, ignore everything except
10203 constants, symbols living in memory, and symbols living in
10204 fixed registers. */
10205 if (! reload_completed
)
10208 && (CONSTANT_P (rtl
)
10210 && CONSTANT_P (XEXP (rtl
, 0)))
10212 && TREE_CODE (decl
) == VAR_DECL
10213 && TREE_STATIC (decl
))))
10215 rtl
= targetm
.delegitimize_address (rtl
);
10220 else if (TREE_CODE (decl
) == PARM_DECL
)
10222 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
10224 tree declared_type
= TREE_TYPE (decl
);
10225 tree passed_type
= DECL_ARG_TYPE (decl
);
10226 enum machine_mode dmode
= TYPE_MODE (declared_type
);
10227 enum machine_mode pmode
= TYPE_MODE (passed_type
);
10229 /* This decl represents a formal parameter which was optimized out.
10230 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10231 all cases where (rtl == NULL_RTX) just below. */
10232 if (dmode
== pmode
)
10233 rtl
= DECL_INCOMING_RTL (decl
);
10234 else if (SCALAR_INT_MODE_P (dmode
)
10235 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
10236 && DECL_INCOMING_RTL (decl
))
10238 rtx inc
= DECL_INCOMING_RTL (decl
);
10241 else if (MEM_P (inc
))
10243 if (BYTES_BIG_ENDIAN
)
10244 rtl
= adjust_address_nv (inc
, dmode
,
10245 GET_MODE_SIZE (pmode
)
10246 - GET_MODE_SIZE (dmode
));
10253 /* If the parm was passed in registers, but lives on the stack, then
10254 make a big endian correction if the mode of the type of the
10255 parameter is not the same as the mode of the rtl. */
10256 /* ??? This is the same series of checks that are made in dbxout.c before
10257 we reach the big endian correction code there. It isn't clear if all
10258 of these checks are necessary here, but keeping them all is the safe
10260 else if (MEM_P (rtl
)
10261 && XEXP (rtl
, 0) != const0_rtx
10262 && ! CONSTANT_P (XEXP (rtl
, 0))
10263 /* Not passed in memory. */
10264 && !MEM_P (DECL_INCOMING_RTL (decl
))
10265 /* Not passed by invisible reference. */
10266 && (!REG_P (XEXP (rtl
, 0))
10267 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
10268 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
10269 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10270 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
10273 /* Big endian correction check. */
10274 && BYTES_BIG_ENDIAN
10275 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
10276 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
10279 int offset
= (UNITS_PER_WORD
10280 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
10282 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10283 plus_constant (XEXP (rtl
, 0), offset
));
10286 else if (TREE_CODE (decl
) == VAR_DECL
10289 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
10290 && BYTES_BIG_ENDIAN
)
10292 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
10293 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
10295 /* If a variable is declared "register" yet is smaller than
10296 a register, then if we store the variable to memory, it
10297 looks like we're storing a register-sized value, when in
10298 fact we are not. We need to adjust the offset of the
10299 storage location to reflect the actual value's bytes,
10300 else gdb will not be able to display it. */
10302 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10303 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
10306 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10307 and will have been substituted directly into all expressions that use it.
10308 C does not have such a concept, but C++ and other languages do. */
10309 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
10310 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
10313 rtl
= targetm
.delegitimize_address (rtl
);
10315 /* If we don't look past the constant pool, we risk emitting a
10316 reference to a constant pool entry that isn't referenced from
10317 code, and thus is not emitted. */
10319 rtl
= avoid_constant_pool_reference (rtl
);
10324 /* We need to figure out what section we should use as the base for the
10325 address ranges where a given location is valid.
10326 1. If this particular DECL has a section associated with it, use that.
10327 2. If this function has a section associated with it, use that.
10328 3. Otherwise, use the text section.
10329 XXX: If you split a variable across multiple sections, we won't notice. */
10331 static const char *
10332 secname_for_decl (tree decl
)
10334 const char *secname
;
10336 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
10338 tree sectree
= DECL_SECTION_NAME (decl
);
10339 secname
= TREE_STRING_POINTER (sectree
);
10341 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
10343 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10344 secname
= TREE_STRING_POINTER (sectree
);
10346 else if (cfun
&& in_cold_section_p
)
10347 secname
= cfun
->cold_section_label
;
10349 secname
= text_section_label
;
10354 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10355 data attribute for a variable or a parameter. We generate the
10356 DW_AT_const_value attribute only in those cases where the given variable
10357 or parameter does not have a true "location" either in memory or in a
10358 register. This can happen (for example) when a constant is passed as an
10359 actual argument in a call to an inline function. (It's possible that
10360 these things can crop up in other ways also.) Note that one type of
10361 constant value which can be passed into an inlined function is a constant
10362 pointer. This can happen for example if an actual argument in an inlined
10363 function call evaluates to a compile-time constant address. */
10366 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
10367 enum dwarf_attribute attr
)
10370 dw_loc_descr_ref descr
;
10371 var_loc_list
*loc_list
;
10372 struct var_loc_node
*node
;
10373 if (TREE_CODE (decl
) == ERROR_MARK
)
10376 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
10377 || TREE_CODE (decl
) == RESULT_DECL
);
10379 /* See if we possibly have multiple locations for this variable. */
10380 loc_list
= lookup_decl_loc (decl
);
10382 /* If it truly has multiple locations, the first and last node will
10384 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10386 const char *endname
, *secname
;
10387 dw_loc_list_ref list
;
10390 /* Now that we know what section we are using for a base,
10391 actually construct the list of locations.
10392 The first location information is what is passed to the
10393 function that creates the location list, and the remaining
10394 locations just get added on to that list.
10395 Note that we only know the start address for a location
10396 (IE location changes), so to build the range, we use
10397 the range [current location start, next location start].
10398 This means we have to special case the last node, and generate
10399 a range of [last location start, end of function label]. */
10401 node
= loc_list
->first
;
10402 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10403 secname
= secname_for_decl (decl
);
10405 list
= new_loc_list (loc_descriptor (varloc
),
10406 node
->label
, node
->next
->label
, secname
, 1);
10409 for (; node
->next
; node
= node
->next
)
10410 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10412 /* The variable has a location between NODE->LABEL and
10413 NODE->NEXT->LABEL. */
10414 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10415 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10416 node
->label
, node
->next
->label
, secname
);
10419 /* If the variable has a location at the last label
10420 it keeps its location until the end of function. */
10421 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10423 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10425 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10426 if (!current_function_decl
)
10427 endname
= text_end_label
;
10430 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10431 current_function_funcdef_no
);
10432 endname
= ggc_strdup (label_id
);
10434 add_loc_descr_to_loc_list (&list
, loc_descriptor (varloc
),
10435 node
->label
, endname
, secname
);
10438 /* Finally, add the location list to the DIE, and we are done. */
10439 add_AT_loc_list (die
, attr
, list
);
10443 /* Try to get some constant RTL for this decl, and use that as the value of
10446 rtl
= rtl_for_decl_location (decl
);
10447 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
10449 add_const_value_attribute (die
, rtl
);
10453 /* If we have tried to generate the location otherwise, and it
10454 didn't work out (we wouldn't be here if we did), and we have a one entry
10455 location list, try generating a location from that. */
10456 if (loc_list
&& loc_list
->first
)
10458 node
= loc_list
->first
;
10459 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
));
10462 add_AT_location_description (die
, attr
, descr
);
10467 /* We couldn't get any rtl, so try directly generating the location
10468 description from the tree. */
10469 descr
= loc_descriptor_from_tree (decl
);
10472 add_AT_location_description (die
, attr
, descr
);
10475 /* None of that worked, so it must not really have a location;
10476 try adding a constant value attribute from the DECL_INITIAL. */
10477 tree_add_const_value_attribute (die
, decl
);
10480 /* If we don't have a copy of this variable in memory for some reason (such
10481 as a C++ member constant that doesn't have an out-of-line definition),
10482 we should tell the debugger about the constant value. */
10485 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10487 tree init
= DECL_INITIAL (decl
);
10488 tree type
= TREE_TYPE (decl
);
10491 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
10496 rtl
= rtl_for_decl_init (init
, type
);
10498 add_const_value_attribute (var_die
, rtl
);
10501 /* Convert the CFI instructions for the current function into a
10502 location list. This is used for DW_AT_frame_base when we targeting
10503 a dwarf2 consumer that does not support the dwarf3
10504 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10507 static dw_loc_list_ref
10508 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
10511 dw_loc_list_ref list
, *list_tail
;
10513 dw_cfa_location last_cfa
, next_cfa
;
10514 const char *start_label
, *last_label
, *section
;
10516 fde
= &fde_table
[fde_table_in_use
- 1];
10518 section
= secname_for_decl (current_function_decl
);
10522 next_cfa
.reg
= INVALID_REGNUM
;
10523 next_cfa
.offset
= 0;
10524 next_cfa
.indirect
= 0;
10525 next_cfa
.base_offset
= 0;
10527 start_label
= fde
->dw_fde_begin
;
10529 /* ??? Bald assumption that the CIE opcode list does not contain
10530 advance opcodes. */
10531 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
10532 lookup_cfa_1 (cfi
, &next_cfa
);
10534 last_cfa
= next_cfa
;
10535 last_label
= start_label
;
10537 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
10538 switch (cfi
->dw_cfi_opc
)
10540 case DW_CFA_set_loc
:
10541 case DW_CFA_advance_loc1
:
10542 case DW_CFA_advance_loc2
:
10543 case DW_CFA_advance_loc4
:
10544 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10546 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10547 start_label
, last_label
, section
,
10550 list_tail
= &(*list_tail
)->dw_loc_next
;
10551 last_cfa
= next_cfa
;
10552 start_label
= last_label
;
10554 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
10557 case DW_CFA_advance_loc
:
10558 /* The encoding is complex enough that we should never emit this. */
10559 case DW_CFA_remember_state
:
10560 case DW_CFA_restore_state
:
10561 /* We don't handle these two in this function. It would be possible
10562 if it were to be required. */
10563 gcc_unreachable ();
10566 lookup_cfa_1 (cfi
, &next_cfa
);
10570 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10572 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10573 start_label
, last_label
, section
,
10575 list_tail
= &(*list_tail
)->dw_loc_next
;
10576 start_label
= last_label
;
10578 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
10579 start_label
, fde
->dw_fde_end
, section
,
10585 /* Compute a displacement from the "steady-state frame pointer" to the
10586 frame base (often the same as the CFA), and store it in
10587 frame_pointer_fb_offset. OFFSET is added to the displacement
10588 before the latter is negated. */
10591 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
10595 #ifdef FRAME_POINTER_CFA_OFFSET
10596 reg
= frame_pointer_rtx
;
10597 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
10599 reg
= arg_pointer_rtx
;
10600 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
10603 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10604 if (GET_CODE (elim
) == PLUS
)
10606 offset
+= INTVAL (XEXP (elim
, 1));
10607 elim
= XEXP (elim
, 0);
10609 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
10610 : stack_pointer_rtx
));
10612 frame_pointer_fb_offset
= -offset
;
10615 /* Generate a DW_AT_name attribute given some string value to be included as
10616 the value of the attribute. */
10619 add_name_attribute (dw_die_ref die
, const char *name_string
)
10621 if (name_string
!= NULL
&& *name_string
!= 0)
10623 if (demangle_name_func
)
10624 name_string
= (*demangle_name_func
) (name_string
);
10626 add_AT_string (die
, DW_AT_name
, name_string
);
10630 /* Generate a DW_AT_comp_dir attribute for DIE. */
10633 add_comp_dir_attribute (dw_die_ref die
)
10635 const char *wd
= get_src_pwd ();
10637 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10640 /* Given a tree node describing an array bound (either lower or upper) output
10641 a representation for that bound. */
10644 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10646 switch (TREE_CODE (bound
))
10651 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10653 if (! host_integerp (bound
, 0)
10654 || (bound_attr
== DW_AT_lower_bound
10655 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10656 || (is_fortran () && integer_onep (bound
)))))
10657 /* Use the default. */
10660 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10665 case NON_LVALUE_EXPR
:
10666 case VIEW_CONVERT_EXPR
:
10667 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10677 dw_die_ref decl_die
= lookup_decl_die (bound
);
10679 /* ??? Can this happen, or should the variable have been bound
10680 first? Probably it can, since I imagine that we try to create
10681 the types of parameters in the order in which they exist in
10682 the list, and won't have created a forward reference to a
10683 later parameter. */
10684 if (decl_die
!= NULL
)
10685 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10691 /* Otherwise try to create a stack operation procedure to
10692 evaluate the value of the array bound. */
10694 dw_die_ref ctx
, decl_die
;
10695 dw_loc_descr_ref loc
;
10697 loc
= loc_descriptor_from_tree (bound
);
10701 if (current_function_decl
== 0)
10702 ctx
= comp_unit_die
;
10704 ctx
= lookup_decl_die (current_function_decl
);
10706 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10707 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10708 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10709 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10711 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10717 /* Note that the block of subscript information for an array type also
10718 includes information about the element type of type given array type. */
10721 add_subscript_info (dw_die_ref type_die
, tree type
)
10723 #ifndef MIPS_DEBUGGING_INFO
10724 unsigned dimension_number
;
10727 dw_die_ref subrange_die
;
10729 /* The GNU compilers represent multidimensional array types as sequences of
10730 one dimensional array types whose element types are themselves array
10731 types. Here we squish that down, so that each multidimensional array
10732 type gets only one array_type DIE in the Dwarf debugging info. The draft
10733 Dwarf specification say that we are allowed to do this kind of
10734 compression in C (because there is no difference between an array or
10735 arrays and a multidimensional array in C) but for other source languages
10736 (e.g. Ada) we probably shouldn't do this. */
10738 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10739 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10740 We work around this by disabling this feature. See also
10741 gen_array_type_die. */
10742 #ifndef MIPS_DEBUGGING_INFO
10743 for (dimension_number
= 0;
10744 TREE_CODE (type
) == ARRAY_TYPE
;
10745 type
= TREE_TYPE (type
), dimension_number
++)
10748 tree domain
= TYPE_DOMAIN (type
);
10750 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10751 and (in GNU C only) variable bounds. Handle all three forms
10753 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10756 /* We have an array type with specified bounds. */
10757 lower
= TYPE_MIN_VALUE (domain
);
10758 upper
= TYPE_MAX_VALUE (domain
);
10760 /* Define the index type. */
10761 if (TREE_TYPE (domain
))
10763 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10764 TREE_TYPE field. We can't emit debug info for this
10765 because it is an unnamed integral type. */
10766 if (TREE_CODE (domain
) == INTEGER_TYPE
10767 && TYPE_NAME (domain
) == NULL_TREE
10768 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10769 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10772 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10776 /* ??? If upper is NULL, the array has unspecified length,
10777 but it does have a lower bound. This happens with Fortran
10779 Since the debugger is definitely going to need to know N
10780 to produce useful results, go ahead and output the lower
10781 bound solo, and hope the debugger can cope. */
10783 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10785 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10788 /* Otherwise we have an array type with an unspecified length. The
10789 DWARF-2 spec does not say how to handle this; let's just leave out the
10795 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10799 switch (TREE_CODE (tree_node
))
10804 case ENUMERAL_TYPE
:
10807 case QUAL_UNION_TYPE
:
10808 size
= int_size_in_bytes (tree_node
);
10811 /* For a data member of a struct or union, the DW_AT_byte_size is
10812 generally given as the number of bytes normally allocated for an
10813 object of the *declared* type of the member itself. This is true
10814 even for bit-fields. */
10815 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10818 gcc_unreachable ();
10821 /* Note that `size' might be -1 when we get to this point. If it is, that
10822 indicates that the byte size of the entity in question is variable. We
10823 have no good way of expressing this fact in Dwarf at the present time,
10824 so just let the -1 pass on through. */
10825 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10828 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10829 which specifies the distance in bits from the highest order bit of the
10830 "containing object" for the bit-field to the highest order bit of the
10833 For any given bit-field, the "containing object" is a hypothetical object
10834 (of some integral or enum type) within which the given bit-field lives. The
10835 type of this hypothetical "containing object" is always the same as the
10836 declared type of the individual bit-field itself. The determination of the
10837 exact location of the "containing object" for a bit-field is rather
10838 complicated. It's handled by the `field_byte_offset' function (above).
10840 Note that it is the size (in bytes) of the hypothetical "containing object"
10841 which will be given in the DW_AT_byte_size attribute for this bit-field.
10842 (See `byte_size_attribute' above). */
10845 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10847 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10848 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10849 HOST_WIDE_INT bitpos_int
;
10850 HOST_WIDE_INT highest_order_object_bit_offset
;
10851 HOST_WIDE_INT highest_order_field_bit_offset
;
10852 HOST_WIDE_INT
unsigned bit_offset
;
10854 /* Must be a field and a bit field. */
10855 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
10857 /* We can't yet handle bit-fields whose offsets are variable, so if we
10858 encounter such things, just return without generating any attribute
10859 whatsoever. Likewise for variable or too large size. */
10860 if (! host_integerp (bit_position (decl
), 0)
10861 || ! host_integerp (DECL_SIZE (decl
), 1))
10864 bitpos_int
= int_bit_position (decl
);
10866 /* Note that the bit offset is always the distance (in bits) from the
10867 highest-order bit of the "containing object" to the highest-order bit of
10868 the bit-field itself. Since the "high-order end" of any object or field
10869 is different on big-endian and little-endian machines, the computation
10870 below must take account of these differences. */
10871 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10872 highest_order_field_bit_offset
= bitpos_int
;
10874 if (! BYTES_BIG_ENDIAN
)
10876 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10877 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10881 = (! BYTES_BIG_ENDIAN
10882 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10883 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10885 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10888 /* For a FIELD_DECL node which represents a bit field, output an attribute
10889 which specifies the length in bits of the given field. */
10892 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10894 /* Must be a field and a bit field. */
10895 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
10896 && DECL_BIT_FIELD_TYPE (decl
));
10898 if (host_integerp (DECL_SIZE (decl
), 1))
10899 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10902 /* If the compiled language is ANSI C, then add a 'prototyped'
10903 attribute, if arg types are given for the parameters of a function. */
10906 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10908 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10909 && TYPE_ARG_TYPES (func_type
) != NULL
)
10910 add_AT_flag (die
, DW_AT_prototyped
, 1);
10913 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10914 by looking in either the type declaration or object declaration
10918 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10920 dw_die_ref origin_die
= NULL
;
10922 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10924 /* We may have gotten separated from the block for the inlined
10925 function, if we're in an exception handler or some such; make
10926 sure that the abstract function has been written out.
10928 Doing this for nested functions is wrong, however; functions are
10929 distinct units, and our context might not even be inline. */
10933 fn
= TYPE_STUB_DECL (fn
);
10935 fn
= decl_function_context (fn
);
10937 dwarf2out_abstract_function (fn
);
10940 if (DECL_P (origin
))
10941 origin_die
= lookup_decl_die (origin
);
10942 else if (TYPE_P (origin
))
10943 origin_die
= lookup_type_die (origin
);
10945 /* XXX: Functions that are never lowered don't always have correct block
10946 trees (in the case of java, they simply have no block tree, in some other
10947 languages). For these functions, there is nothing we can really do to
10948 output correct debug info for inlined functions in all cases. Rather
10949 than die, we'll just produce deficient debug info now, in that we will
10950 have variables without a proper abstract origin. In the future, when all
10951 functions are lowered, we should re-add a gcc_assert (origin_die)
10955 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10958 /* We do not currently support the pure_virtual attribute. */
10961 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10963 if (DECL_VINDEX (func_decl
))
10965 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10967 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10968 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10969 new_loc_descr (DW_OP_constu
,
10970 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10973 /* GNU extension: Record what type this method came from originally. */
10974 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10975 add_AT_die_ref (die
, DW_AT_containing_type
,
10976 lookup_type_die (DECL_CONTEXT (func_decl
)));
10980 /* Add source coordinate attributes for the given decl. */
10983 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10985 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10987 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
10988 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10991 /* Add a DW_AT_name attribute and source coordinate attribute for the
10992 given decl, but only if it actually has a name. */
10995 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10999 decl_name
= DECL_NAME (decl
);
11000 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
11002 add_name_attribute (die
, dwarf2_name (decl
, 0));
11003 if (! DECL_ARTIFICIAL (decl
))
11004 add_src_coords_attributes (die
, decl
);
11006 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
11007 && TREE_PUBLIC (decl
)
11008 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
11009 && !DECL_ABSTRACT (decl
)
11010 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
)))
11011 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
11012 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
11015 #ifdef VMS_DEBUGGING_INFO
11016 /* Get the function's name, as described by its RTL. This may be different
11017 from the DECL_NAME name used in the source file. */
11018 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
11020 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
11021 XEXP (DECL_RTL (decl
), 0));
11022 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
11027 /* Push a new declaration scope. */
11030 push_decl_scope (tree scope
)
11032 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
11035 /* Pop a declaration scope. */
11038 pop_decl_scope (void)
11040 VEC_pop (tree
, decl_scope_table
);
11043 /* Return the DIE for the scope that immediately contains this type.
11044 Non-named types get global scope. Named types nested in other
11045 types get their containing scope if it's open, or global scope
11046 otherwise. All other types (i.e. function-local named types) get
11047 the current active scope. */
11050 scope_die_for (tree t
, dw_die_ref context_die
)
11052 dw_die_ref scope_die
= NULL
;
11053 tree containing_scope
;
11056 /* Non-types always go in the current scope. */
11057 gcc_assert (TYPE_P (t
));
11059 containing_scope
= TYPE_CONTEXT (t
);
11061 /* Use the containing namespace if it was passed in (for a declaration). */
11062 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
11064 if (context_die
== lookup_decl_die (containing_scope
))
11067 containing_scope
= NULL_TREE
;
11070 /* Ignore function type "scopes" from the C frontend. They mean that
11071 a tagged type is local to a parmlist of a function declarator, but
11072 that isn't useful to DWARF. */
11073 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
11074 containing_scope
= NULL_TREE
;
11076 if (containing_scope
== NULL_TREE
)
11077 scope_die
= comp_unit_die
;
11078 else if (TYPE_P (containing_scope
))
11080 /* For types, we can just look up the appropriate DIE. But
11081 first we check to see if we're in the middle of emitting it
11082 so we know where the new DIE should go. */
11083 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
11084 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
11089 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
11090 || TREE_ASM_WRITTEN (containing_scope
));
11092 /* If none of the current dies are suitable, we get file scope. */
11093 scope_die
= comp_unit_die
;
11096 scope_die
= lookup_type_die (containing_scope
);
11099 scope_die
= context_die
;
11104 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11107 local_scope_p (dw_die_ref context_die
)
11109 for (; context_die
; context_die
= context_die
->die_parent
)
11110 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
11111 || context_die
->die_tag
== DW_TAG_subprogram
)
11117 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11118 whether or not to treat a DIE in this context as a declaration. */
11121 class_or_namespace_scope_p (dw_die_ref context_die
)
11123 return (context_die
11124 && (context_die
->die_tag
== DW_TAG_structure_type
11125 || context_die
->die_tag
== DW_TAG_union_type
11126 || context_die
->die_tag
== DW_TAG_namespace
));
11129 /* Many forms of DIEs require a "type description" attribute. This
11130 routine locates the proper "type descriptor" die for the type given
11131 by 'type', and adds a DW_AT_type attribute below the given die. */
11134 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
11135 int decl_volatile
, dw_die_ref context_die
)
11137 enum tree_code code
= TREE_CODE (type
);
11138 dw_die_ref type_die
= NULL
;
11140 /* ??? If this type is an unnamed subrange type of an integral or
11141 floating-point type, use the inner type. This is because we have no
11142 support for unnamed types in base_type_die. This can happen if this is
11143 an Ada subrange type. Correct solution is emit a subrange type die. */
11144 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
11145 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
11146 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
11148 if (code
== ERROR_MARK
11149 /* Handle a special case. For functions whose return type is void, we
11150 generate *no* type attribute. (Note that no object may have type
11151 `void', so this only applies to function return types). */
11152 || code
== VOID_TYPE
)
11155 type_die
= modified_type_die (type
,
11156 decl_const
|| TYPE_READONLY (type
),
11157 decl_volatile
|| TYPE_VOLATILE (type
),
11160 if (type_die
!= NULL
)
11161 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
11164 /* Given an object die, add the calling convention attribute for the
11165 function call type. */
11167 add_calling_convention_attribute (dw_die_ref subr_die
, tree type
)
11169 enum dwarf_calling_convention value
= DW_CC_normal
;
11171 value
= targetm
.dwarf_calling_convention (type
);
11173 /* Only add the attribute if the backend requests it, and
11174 is not DW_CC_normal. */
11175 if (value
&& (value
!= DW_CC_normal
))
11176 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
11179 /* Given a tree pointer to a struct, class, union, or enum type node, return
11180 a pointer to the (string) tag name for the given type, or zero if the type
11181 was declared without a tag. */
11183 static const char *
11184 type_tag (tree type
)
11186 const char *name
= 0;
11188 if (TYPE_NAME (type
) != 0)
11192 /* Find the IDENTIFIER_NODE for the type name. */
11193 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
11194 t
= TYPE_NAME (type
);
11196 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11197 a TYPE_DECL node, regardless of whether or not a `typedef' was
11199 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11200 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
11201 t
= DECL_NAME (TYPE_NAME (type
));
11203 /* Now get the name as a string, or invent one. */
11205 name
= IDENTIFIER_POINTER (t
);
11208 return (name
== 0 || *name
== '\0') ? 0 : name
;
11211 /* Return the type associated with a data member, make a special check
11212 for bit field types. */
11215 member_declared_type (tree member
)
11217 return (DECL_BIT_FIELD_TYPE (member
)
11218 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
11221 /* Get the decl's label, as described by its RTL. This may be different
11222 from the DECL_NAME name used in the source file. */
11225 static const char *
11226 decl_start_label (tree decl
)
11229 const char *fnname
;
11231 x
= DECL_RTL (decl
);
11232 gcc_assert (MEM_P (x
));
11235 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
11237 fnname
= XSTR (x
, 0);
11242 /* These routines generate the internal representation of the DIE's for
11243 the compilation unit. Debugging information is collected by walking
11244 the declaration trees passed in from dwarf2out_decl(). */
11247 gen_array_type_die (tree type
, dw_die_ref context_die
)
11249 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
11250 dw_die_ref array_die
;
11253 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11254 the inner array type comes before the outer array type. Thus we must
11255 call gen_type_die before we call new_die. See below also. */
11256 #ifdef MIPS_DEBUGGING_INFO
11257 gen_type_die (TREE_TYPE (type
), context_die
);
11260 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
11261 add_name_attribute (array_die
, type_tag (type
));
11262 equate_type_number_to_die (type
, array_die
);
11264 if (TREE_CODE (type
) == VECTOR_TYPE
)
11266 /* The frontend feeds us a representation for the vector as a struct
11267 containing an array. Pull out the array type. */
11268 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
11269 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
11273 /* We default the array ordering. SDB will probably do
11274 the right things even if DW_AT_ordering is not present. It's not even
11275 an issue until we start to get into multidimensional arrays anyway. If
11276 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11277 then we'll have to put the DW_AT_ordering attribute back in. (But if
11278 and when we find out that we need to put these in, we will only do so
11279 for multidimensional arrays. */
11280 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
11283 #ifdef MIPS_DEBUGGING_INFO
11284 /* The SGI compilers handle arrays of unknown bound by setting
11285 AT_declaration and not emitting any subrange DIEs. */
11286 if (! TYPE_DOMAIN (type
))
11287 add_AT_flag (array_die
, DW_AT_declaration
, 1);
11290 add_subscript_info (array_die
, type
);
11292 /* Add representation of the type of the elements of this array type. */
11293 element_type
= TREE_TYPE (type
);
11295 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11296 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11297 We work around this by disabling this feature. See also
11298 add_subscript_info. */
11299 #ifndef MIPS_DEBUGGING_INFO
11300 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
11301 element_type
= TREE_TYPE (element_type
);
11303 gen_type_die (element_type
, context_die
);
11306 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
11311 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
11313 tree origin
= decl_ultimate_origin (decl
);
11314 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
11316 if (origin
!= NULL
)
11317 add_abstract_origin_attribute (decl_die
, origin
);
11320 add_name_and_src_coords_attributes (decl_die
, decl
);
11321 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
11322 0, 0, context_die
);
11325 if (DECL_ABSTRACT (decl
))
11326 equate_decl_number_to_die (decl
, decl_die
);
11328 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
11332 /* Walk through the list of incomplete types again, trying once more to
11333 emit full debugging info for them. */
11336 retry_incomplete_types (void)
11340 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
11341 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
11344 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11347 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
11349 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
11351 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11352 be incomplete and such types are not marked. */
11353 add_abstract_origin_attribute (type_die
, type
);
11356 /* Generate a DIE to represent an inlined instance of a structure type. */
11359 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
11361 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
11363 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11364 be incomplete and such types are not marked. */
11365 add_abstract_origin_attribute (type_die
, type
);
11368 /* Generate a DIE to represent an inlined instance of a union type. */
11371 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
11373 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
11375 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11376 be incomplete and such types are not marked. */
11377 add_abstract_origin_attribute (type_die
, type
);
11380 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11381 include all of the information about the enumeration values also. Each
11382 enumerated type name/value is listed as a child of the enumerated type
11386 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
11388 dw_die_ref type_die
= lookup_type_die (type
);
11390 if (type_die
== NULL
)
11392 type_die
= new_die (DW_TAG_enumeration_type
,
11393 scope_die_for (type
, context_die
), type
);
11394 equate_type_number_to_die (type
, type_die
);
11395 add_name_attribute (type_die
, type_tag (type
));
11397 else if (! TYPE_SIZE (type
))
11400 remove_AT (type_die
, DW_AT_declaration
);
11402 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11403 given enum type is incomplete, do not generate the DW_AT_byte_size
11404 attribute or the DW_AT_element_list attribute. */
11405 if (TYPE_SIZE (type
))
11409 TREE_ASM_WRITTEN (type
) = 1;
11410 add_byte_size_attribute (type_die
, type
);
11411 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11412 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11414 /* If the first reference to this type was as the return type of an
11415 inline function, then it may not have a parent. Fix this now. */
11416 if (type_die
->die_parent
== NULL
)
11417 add_child_die (scope_die_for (type
, context_die
), type_die
);
11419 for (link
= TYPE_VALUES (type
);
11420 link
!= NULL
; link
= TREE_CHAIN (link
))
11422 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
11423 tree value
= TREE_VALUE (link
);
11425 add_name_attribute (enum_die
,
11426 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
11428 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
11429 /* DWARF2 does not provide a way of indicating whether or
11430 not enumeration constants are signed or unsigned. GDB
11431 always assumes the values are signed, so we output all
11432 values as if they were signed. That means that
11433 enumeration constants with very large unsigned values
11434 will appear to have negative values in the debugger. */
11435 add_AT_int (enum_die
, DW_AT_const_value
,
11436 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
11440 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11445 /* Generate a DIE to represent either a real live formal parameter decl or to
11446 represent just the type of some formal parameter position in some function
11449 Note that this routine is a bit unusual because its argument may be a
11450 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11451 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11452 node. If it's the former then this function is being called to output a
11453 DIE to represent a formal parameter object (or some inlining thereof). If
11454 it's the latter, then this function is only being called to output a
11455 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11456 argument type of some subprogram type. */
11459 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
11461 dw_die_ref parm_die
11462 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
11465 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
11467 case tcc_declaration
:
11468 origin
= decl_ultimate_origin (node
);
11469 if (origin
!= NULL
)
11470 add_abstract_origin_attribute (parm_die
, origin
);
11473 add_name_and_src_coords_attributes (parm_die
, node
);
11474 add_type_attribute (parm_die
, TREE_TYPE (node
),
11475 TREE_READONLY (node
),
11476 TREE_THIS_VOLATILE (node
),
11478 if (DECL_ARTIFICIAL (node
))
11479 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11482 equate_decl_number_to_die (node
, parm_die
);
11483 if (! DECL_ABSTRACT (node
))
11484 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11489 /* We were called with some kind of a ..._TYPE node. */
11490 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11494 gcc_unreachable ();
11500 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11501 at the end of an (ANSI prototyped) formal parameters list. */
11504 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11506 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11509 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11510 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11511 parameters as specified in some function type specification (except for
11512 those which appear as part of a function *definition*). */
11515 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11518 tree formal_type
= NULL
;
11519 tree first_parm_type
;
11522 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11524 arg
= DECL_ARGUMENTS (function_or_method_type
);
11525 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11530 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11532 /* Make our first pass over the list of formal parameter types and output a
11533 DW_TAG_formal_parameter DIE for each one. */
11534 for (link
= first_parm_type
; link
; )
11536 dw_die_ref parm_die
;
11538 formal_type
= TREE_VALUE (link
);
11539 if (formal_type
== void_type_node
)
11542 /* Output a (nameless) DIE to represent the formal parameter itself. */
11543 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11544 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11545 && link
== first_parm_type
)
11546 || (arg
&& DECL_ARTIFICIAL (arg
)))
11547 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11549 link
= TREE_CHAIN (link
);
11551 arg
= TREE_CHAIN (arg
);
11554 /* If this function type has an ellipsis, add a
11555 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11556 if (formal_type
!= void_type_node
)
11557 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11559 /* Make our second (and final) pass over the list of formal parameter types
11560 and output DIEs to represent those types (as necessary). */
11561 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11562 link
&& TREE_VALUE (link
);
11563 link
= TREE_CHAIN (link
))
11564 gen_type_die (TREE_VALUE (link
), context_die
);
11567 /* We want to generate the DIE for TYPE so that we can generate the
11568 die for MEMBER, which has been defined; we will need to refer back
11569 to the member declaration nested within TYPE. If we're trying to
11570 generate minimal debug info for TYPE, processing TYPE won't do the
11571 trick; we need to attach the member declaration by hand. */
11574 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11576 gen_type_die (type
, context_die
);
11578 /* If we're trying to avoid duplicate debug info, we may not have
11579 emitted the member decl for this function. Emit it now. */
11580 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11581 && ! lookup_decl_die (member
))
11583 dw_die_ref type_die
;
11584 gcc_assert (!decl_ultimate_origin (member
));
11586 push_decl_scope (type
);
11587 type_die
= lookup_type_die (type
);
11588 if (TREE_CODE (member
) == FUNCTION_DECL
)
11589 gen_subprogram_die (member
, type_die
);
11590 else if (TREE_CODE (member
) == FIELD_DECL
)
11592 /* Ignore the nameless fields that are used to skip bits but handle
11593 C++ anonymous unions and structs. */
11594 if (DECL_NAME (member
) != NULL_TREE
11595 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
11596 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
11598 gen_type_die (member_declared_type (member
), type_die
);
11599 gen_field_die (member
, type_die
);
11603 gen_variable_die (member
, type_die
);
11609 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11610 may later generate inlined and/or out-of-line instances of. */
11613 dwarf2out_abstract_function (tree decl
)
11615 dw_die_ref old_die
;
11617 struct function
*save_cfun
;
11619 int was_abstract
= DECL_ABSTRACT (decl
);
11621 /* Make sure we have the actual abstract inline, not a clone. */
11622 decl
= DECL_ORIGIN (decl
);
11624 old_die
= lookup_decl_die (decl
);
11625 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11626 /* We've already generated the abstract instance. */
11629 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11630 we don't get confused by DECL_ABSTRACT. */
11631 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11633 context
= decl_class_context (decl
);
11635 gen_type_die_for_member
11636 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11639 /* Pretend we've just finished compiling this function. */
11640 save_fn
= current_function_decl
;
11642 current_function_decl
= decl
;
11643 cfun
= DECL_STRUCT_FUNCTION (decl
);
11645 set_decl_abstract_flags (decl
, 1);
11646 dwarf2out_decl (decl
);
11647 if (! was_abstract
)
11648 set_decl_abstract_flags (decl
, 0);
11650 current_function_decl
= save_fn
;
11654 /* Helper function of premark_used_types() which gets called through
11655 htab_traverse_resize().
11657 Marks the DIE of a given type in *SLOT as perennial, so it never gets
11658 marked as unused by prune_unused_types. */
11660 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
11666 die
= lookup_type_die (type
);
11668 die
->die_perennial_p
= 1;
11672 /* Mark all members of used_types_hash as perennial. */
11674 premark_used_types (void)
11676 if (cfun
&& cfun
->used_types_hash
)
11677 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
11680 /* Generate a DIE to represent a declared function (either file-scope or
11684 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11686 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11687 tree origin
= decl_ultimate_origin (decl
);
11688 dw_die_ref subr_die
;
11691 dw_die_ref old_die
= lookup_decl_die (decl
);
11692 int declaration
= (current_function_decl
!= decl
11693 || class_or_namespace_scope_p (context_die
));
11695 premark_used_types ();
11697 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11698 started to generate the abstract instance of an inline, decided to output
11699 its containing class, and proceeded to emit the declaration of the inline
11700 from the member list for the class. If so, DECLARATION takes priority;
11701 we'll get back to the abstract instance when done with the class. */
11703 /* The class-scope declaration DIE must be the primary DIE. */
11704 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11707 gcc_assert (!old_die
);
11710 /* Now that the C++ front end lazily declares artificial member fns, we
11711 might need to retrofit the declaration into its class. */
11712 if (!declaration
&& !origin
&& !old_die
11713 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
11714 && !class_or_namespace_scope_p (context_die
)
11715 && debug_info_level
> DINFO_LEVEL_TERSE
)
11716 old_die
= force_decl_die (decl
);
11718 if (origin
!= NULL
)
11720 gcc_assert (!declaration
|| local_scope_p (context_die
));
11722 /* Fixup die_parent for the abstract instance of a nested
11723 inline function. */
11724 if (old_die
&& old_die
->die_parent
== NULL
)
11725 add_child_die (context_die
, old_die
);
11727 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11728 add_abstract_origin_attribute (subr_die
, origin
);
11732 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11733 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
11735 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11736 /* We can have a normal definition following an inline one in the
11737 case of redefinition of GNU C extern inlines.
11738 It seems reasonable to use AT_specification in this case. */
11739 && !get_AT (old_die
, DW_AT_inline
))
11741 /* Detect and ignore this case, where we are trying to output
11742 something we have already output. */
11746 /* If the definition comes from the same place as the declaration,
11747 maybe use the old DIE. We always want the DIE for this function
11748 that has the *_pc attributes to be under comp_unit_die so the
11749 debugger can find it. We also need to do this for abstract
11750 instances of inlines, since the spec requires the out-of-line copy
11751 to have the same parent. For local class methods, this doesn't
11752 apply; we just use the old DIE. */
11753 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11754 && (DECL_ARTIFICIAL (decl
)
11755 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
11756 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11757 == (unsigned) s
.line
))))
11759 subr_die
= old_die
;
11761 /* Clear out the declaration attribute and the formal parameters.
11762 Do not remove all children, because it is possible that this
11763 declaration die was forced using force_decl_die(). In such
11764 cases die that forced declaration die (e.g. TAG_imported_module)
11765 is one of the children that we do not want to remove. */
11766 remove_AT (subr_die
, DW_AT_declaration
);
11767 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11771 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11772 add_AT_specification (subr_die
, old_die
);
11773 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
11774 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
11775 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
11776 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
11781 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11783 if (TREE_PUBLIC (decl
))
11784 add_AT_flag (subr_die
, DW_AT_external
, 1);
11786 add_name_and_src_coords_attributes (subr_die
, decl
);
11787 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11789 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11790 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11791 0, 0, context_die
);
11794 add_pure_or_virtual_attribute (subr_die
, decl
);
11795 if (DECL_ARTIFICIAL (decl
))
11796 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11798 if (TREE_PROTECTED (decl
))
11799 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11800 else if (TREE_PRIVATE (decl
))
11801 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11806 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11808 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11810 /* The first time we see a member function, it is in the context of
11811 the class to which it belongs. We make sure of this by emitting
11812 the class first. The next time is the definition, which is
11813 handled above. The two may come from the same source text.
11815 Note that force_decl_die() forces function declaration die. It is
11816 later reused to represent definition. */
11817 equate_decl_number_to_die (decl
, subr_die
);
11820 else if (DECL_ABSTRACT (decl
))
11822 if (DECL_DECLARED_INLINE_P (decl
))
11824 if (cgraph_function_possibly_inlined_p (decl
))
11825 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11827 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11831 if (cgraph_function_possibly_inlined_p (decl
))
11832 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11834 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11837 equate_decl_number_to_die (decl
, subr_die
);
11839 else if (!DECL_EXTERNAL (decl
))
11841 HOST_WIDE_INT cfa_fb_offset
;
11843 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11844 equate_decl_number_to_die (decl
, subr_die
);
11846 if (!flag_reorder_blocks_and_partition
)
11848 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11849 current_function_funcdef_no
);
11850 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11851 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11852 current_function_funcdef_no
);
11853 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11855 add_pubname (decl
, subr_die
);
11856 add_arange (decl
, subr_die
);
11859 { /* Do nothing for now; maybe need to duplicate die, one for
11860 hot section and ond for cold section, then use the hot/cold
11861 section begin/end labels to generate the aranges... */
11863 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11864 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11865 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11866 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11868 add_pubname (decl, subr_die);
11869 add_arange (decl, subr_die);
11870 add_arange (decl, subr_die);
11874 #ifdef MIPS_DEBUGGING_INFO
11875 /* Add a reference to the FDE for this routine. */
11876 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11879 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
11881 /* We define the "frame base" as the function's CFA. This is more
11882 convenient for several reasons: (1) It's stable across the prologue
11883 and epilogue, which makes it better than just a frame pointer,
11884 (2) With dwarf3, there exists a one-byte encoding that allows us
11885 to reference the .debug_frame data by proxy, but failing that,
11886 (3) We can at least reuse the code inspection and interpretation
11887 code that determines the CFA position at various points in the
11889 /* ??? Use some command-line or configury switch to enable the use
11890 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11891 consumers that understand it; fall back to "pure" dwarf2 and
11892 convert the CFA data into a location list. */
11894 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
11895 if (list
->dw_loc_next
)
11896 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
11898 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
11901 /* Compute a displacement from the "steady-state frame pointer" to
11902 the CFA. The former is what all stack slots and argument slots
11903 will reference in the rtl; the later is what we've told the
11904 debugger about. We'll need to adjust all frame_base references
11905 by this displacement. */
11906 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
11908 if (cfun
->static_chain_decl
)
11909 add_AT_location_description (subr_die
, DW_AT_static_link
,
11910 loc_descriptor_from_tree (cfun
->static_chain_decl
));
11913 /* Now output descriptions of the arguments for this function. This gets
11914 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11915 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11916 `...' at the end of the formal parameter list. In order to find out if
11917 there was a trailing ellipsis or not, we must instead look at the type
11918 associated with the FUNCTION_DECL. This will be a node of type
11919 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11920 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11921 an ellipsis at the end. */
11923 /* In the case where we are describing a mere function declaration, all we
11924 need to do here (and all we *can* do here) is to describe the *types* of
11925 its formal parameters. */
11926 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11928 else if (declaration
)
11929 gen_formal_types_die (decl
, subr_die
);
11932 /* Generate DIEs to represent all known formal parameters. */
11933 tree arg_decls
= DECL_ARGUMENTS (decl
);
11936 /* When generating DIEs, generate the unspecified_parameters DIE
11937 instead if we come across the arg "__builtin_va_alist" */
11938 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11939 if (TREE_CODE (parm
) == PARM_DECL
)
11941 if (DECL_NAME (parm
)
11942 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11943 "__builtin_va_alist"))
11944 gen_unspecified_parameters_die (parm
, subr_die
);
11946 gen_decl_die (parm
, subr_die
);
11949 /* Decide whether we need an unspecified_parameters DIE at the end.
11950 There are 2 more cases to do this for: 1) the ansi ... declaration -
11951 this is detectable when the end of the arg list is not a
11952 void_type_node 2) an unprototyped function declaration (not a
11953 definition). This just means that we have no info about the
11954 parameters at all. */
11955 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11956 if (fn_arg_types
!= NULL
)
11958 /* This is the prototyped case, check for.... */
11959 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11960 gen_unspecified_parameters_die (decl
, subr_die
);
11962 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11963 gen_unspecified_parameters_die (decl
, subr_die
);
11966 /* Output Dwarf info for all of the stuff within the body of the function
11967 (if it has one - it may be just a declaration). */
11968 outer_scope
= DECL_INITIAL (decl
);
11970 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11971 a function. This BLOCK actually represents the outermost binding contour
11972 for the function, i.e. the contour in which the function's formal
11973 parameters and labels get declared. Curiously, it appears that the front
11974 end doesn't actually put the PARM_DECL nodes for the current function onto
11975 the BLOCK_VARS list for this outer scope, but are strung off of the
11976 DECL_ARGUMENTS list for the function instead.
11978 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11979 the LABEL_DECL nodes for the function however, and we output DWARF info
11980 for those in decls_for_scope. Just within the `outer_scope' there will be
11981 a BLOCK node representing the function's outermost pair of curly braces,
11982 and any blocks used for the base and member initializers of a C++
11983 constructor function. */
11984 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11986 /* Emit a DW_TAG_variable DIE for a named return value. */
11987 if (DECL_NAME (DECL_RESULT (decl
)))
11988 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11990 current_function_has_inlines
= 0;
11991 decls_for_scope (outer_scope
, subr_die
, 0);
11993 #if 0 && defined (MIPS_DEBUGGING_INFO)
11994 if (current_function_has_inlines
)
11996 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11997 if (! comp_unit_has_inlines
)
11999 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
12000 comp_unit_has_inlines
= 1;
12005 /* Add the calling convention attribute if requested. */
12006 add_calling_convention_attribute (subr_die
, TREE_TYPE (decl
));
12010 /* Generate a DIE to represent a declared data object. */
12013 gen_variable_die (tree decl
, dw_die_ref context_die
)
12015 tree origin
= decl_ultimate_origin (decl
);
12016 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
12018 dw_die_ref old_die
= lookup_decl_die (decl
);
12019 int declaration
= (DECL_EXTERNAL (decl
)
12020 /* If DECL is COMDAT and has not actually been
12021 emitted, we cannot take its address; there
12022 might end up being no definition anywhere in
12023 the program. For example, consider the C++
12027 struct S { static const int i = 7; };
12032 int f() { return S<int>::i; }
12034 Here, S<int>::i is not DECL_EXTERNAL, but no
12035 definition is required, so the compiler will
12036 not emit a definition. */
12037 || (TREE_CODE (decl
) == VAR_DECL
12038 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
12039 || class_or_namespace_scope_p (context_die
));
12041 if (origin
!= NULL
)
12042 add_abstract_origin_attribute (var_die
, origin
);
12044 /* Loop unrolling can create multiple blocks that refer to the same
12045 static variable, so we must test for the DW_AT_declaration flag.
12047 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12048 copy decls and set the DECL_ABSTRACT flag on them instead of
12051 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12053 ??? The declare_in_namespace support causes us to get two DIEs for one
12054 variable, both of which are declarations. We want to avoid considering
12055 one to be a specification, so we must test that this DIE is not a
12057 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
12058 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
12060 /* This is a definition of a C++ class level static. */
12061 add_AT_specification (var_die
, old_die
);
12062 if (DECL_NAME (decl
))
12064 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12065 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
12067 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
12068 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
12070 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
12072 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
12077 add_name_and_src_coords_attributes (var_die
, decl
);
12078 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
12079 TREE_THIS_VOLATILE (decl
), context_die
);
12081 if (TREE_PUBLIC (decl
))
12082 add_AT_flag (var_die
, DW_AT_external
, 1);
12084 if (DECL_ARTIFICIAL (decl
))
12085 add_AT_flag (var_die
, DW_AT_artificial
, 1);
12087 if (TREE_PROTECTED (decl
))
12088 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12089 else if (TREE_PRIVATE (decl
))
12090 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12094 add_AT_flag (var_die
, DW_AT_declaration
, 1);
12096 if (DECL_ABSTRACT (decl
) || declaration
)
12097 equate_decl_number_to_die (decl
, var_die
);
12099 if (! declaration
&& ! DECL_ABSTRACT (decl
))
12101 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
12102 add_pubname (decl
, var_die
);
12105 tree_add_const_value_attribute (var_die
, decl
);
12108 /* Generate a DIE to represent a label identifier. */
12111 gen_label_die (tree decl
, dw_die_ref context_die
)
12113 tree origin
= decl_ultimate_origin (decl
);
12114 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
12116 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12118 if (origin
!= NULL
)
12119 add_abstract_origin_attribute (lbl_die
, origin
);
12121 add_name_and_src_coords_attributes (lbl_die
, decl
);
12123 if (DECL_ABSTRACT (decl
))
12124 equate_decl_number_to_die (decl
, lbl_die
);
12127 insn
= DECL_RTL_IF_SET (decl
);
12129 /* Deleted labels are programmer specified labels which have been
12130 eliminated because of various optimizations. We still emit them
12131 here so that it is possible to put breakpoints on them. */
12135 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
12137 /* When optimization is enabled (via -O) some parts of the compiler
12138 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12139 represent source-level labels which were explicitly declared by
12140 the user. This really shouldn't be happening though, so catch
12141 it if it ever does happen. */
12142 gcc_assert (!INSN_DELETED_P (insn
));
12144 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
12145 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
12150 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12151 attributes to the DIE for a block STMT, to describe where the inlined
12152 function was called from. This is similar to add_src_coords_attributes. */
12155 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
12157 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
12159 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
12160 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
12163 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12164 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12167 add_high_low_attributes (tree stmt
, dw_die_ref die
)
12169 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12171 if (BLOCK_FRAGMENT_CHAIN (stmt
))
12175 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
12177 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
12180 add_ranges (chain
);
12181 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
12188 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
12189 BLOCK_NUMBER (stmt
));
12190 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
12191 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
12192 BLOCK_NUMBER (stmt
));
12193 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
12197 /* Generate a DIE for a lexical block. */
12200 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12202 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
12204 if (! BLOCK_ABSTRACT (stmt
))
12205 add_high_low_attributes (stmt
, stmt_die
);
12207 decls_for_scope (stmt
, stmt_die
, depth
);
12210 /* Generate a DIE for an inlined subprogram. */
12213 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
12215 tree decl
= block_ultimate_origin (stmt
);
12217 /* Emit info for the abstract instance first, if we haven't yet. We
12218 must emit this even if the block is abstract, otherwise when we
12219 emit the block below (or elsewhere), we may end up trying to emit
12220 a die whose origin die hasn't been emitted, and crashing. */
12221 dwarf2out_abstract_function (decl
);
12223 if (! BLOCK_ABSTRACT (stmt
))
12225 dw_die_ref subr_die
12226 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
12228 add_abstract_origin_attribute (subr_die
, decl
);
12229 add_high_low_attributes (stmt
, subr_die
);
12230 add_call_src_coords_attributes (stmt
, subr_die
);
12232 decls_for_scope (stmt
, subr_die
, depth
);
12233 current_function_has_inlines
= 1;
12236 /* We may get here if we're the outer block of function A that was
12237 inlined into function B that was inlined into function C. When
12238 generating debugging info for C, dwarf2out_abstract_function(B)
12239 would mark all inlined blocks as abstract, including this one.
12240 So, we wouldn't (and shouldn't) expect labels to be generated
12241 for this one. Instead, just emit debugging info for
12242 declarations within the block. This is particularly important
12243 in the case of initializers of arguments passed from B to us:
12244 if they're statement expressions containing declarations, we
12245 wouldn't generate dies for their abstract variables, and then,
12246 when generating dies for the real variables, we'd die (pun
12248 gen_lexical_block_die (stmt
, context_die
, depth
);
12251 /* Generate a DIE for a field in a record, or structure. */
12254 gen_field_die (tree decl
, dw_die_ref context_die
)
12256 dw_die_ref decl_die
;
12258 if (TREE_TYPE (decl
) == error_mark_node
)
12261 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
12262 add_name_and_src_coords_attributes (decl_die
, decl
);
12263 add_type_attribute (decl_die
, member_declared_type (decl
),
12264 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
12267 if (DECL_BIT_FIELD_TYPE (decl
))
12269 add_byte_size_attribute (decl_die
, decl
);
12270 add_bit_size_attribute (decl_die
, decl
);
12271 add_bit_offset_attribute (decl_die
, decl
);
12274 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
12275 add_data_member_location_attribute (decl_die
, decl
);
12277 if (DECL_ARTIFICIAL (decl
))
12278 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12280 if (TREE_PROTECTED (decl
))
12281 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12282 else if (TREE_PRIVATE (decl
))
12283 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12285 /* Equate decl number to die, so that we can look up this decl later on. */
12286 equate_decl_number_to_die (decl
, decl_die
);
12290 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12291 Use modified_type_die instead.
12292 We keep this code here just in case these types of DIEs may be needed to
12293 represent certain things in other languages (e.g. Pascal) someday. */
12296 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
12299 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
12301 equate_type_number_to_die (type
, ptr_die
);
12302 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12303 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12306 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12307 Use modified_type_die instead.
12308 We keep this code here just in case these types of DIEs may be needed to
12309 represent certain things in other languages (e.g. Pascal) someday. */
12312 gen_reference_type_die (tree type
, dw_die_ref context_die
)
12315 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
12317 equate_type_number_to_die (type
, ref_die
);
12318 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
12319 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12323 /* Generate a DIE for a pointer to a member type. */
12326 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
12329 = new_die (DW_TAG_ptr_to_member_type
,
12330 scope_die_for (type
, context_die
), type
);
12332 equate_type_number_to_die (type
, ptr_die
);
12333 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
12334 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
12335 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12338 /* Generate the DIE for the compilation unit. */
12341 gen_compile_unit_die (const char *filename
)
12344 char producer
[250];
12345 const char *language_string
= lang_hooks
.name
;
12348 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
12352 add_name_attribute (die
, filename
);
12353 /* Don't add cwd for <built-in>. */
12354 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
12355 add_comp_dir_attribute (die
);
12358 sprintf (producer
, "%s %s", language_string
, version_string
);
12360 #ifdef MIPS_DEBUGGING_INFO
12361 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12362 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12363 not appear in the producer string, the debugger reaches the conclusion
12364 that the object file is stripped and has no debugging information.
12365 To get the MIPS/SGI debugger to believe that there is debugging
12366 information in the object file, we add a -g to the producer string. */
12367 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12368 strcat (producer
, " -g");
12371 add_AT_string (die
, DW_AT_producer
, producer
);
12373 if (strcmp (language_string
, "GNU C++") == 0)
12374 language
= DW_LANG_C_plus_plus
;
12375 else if (strcmp (language_string
, "GNU Ada") == 0)
12376 language
= DW_LANG_Ada95
;
12377 else if (strcmp (language_string
, "GNU F77") == 0)
12378 language
= DW_LANG_Fortran77
;
12379 else if (strcmp (language_string
, "GNU F95") == 0)
12380 language
= DW_LANG_Fortran95
;
12381 else if (strcmp (language_string
, "GNU Pascal") == 0)
12382 language
= DW_LANG_Pascal83
;
12383 else if (strcmp (language_string
, "GNU Java") == 0)
12384 language
= DW_LANG_Java
;
12385 else if (strcmp (language_string
, "GNU Objective-C") == 0)
12386 language
= DW_LANG_ObjC
;
12387 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
12388 language
= DW_LANG_ObjC_plus_plus
;
12390 language
= DW_LANG_C89
;
12392 add_AT_unsigned (die
, DW_AT_language
, language
);
12396 /* Generate the DIE for a base class. */
12399 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
12401 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
12403 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
12404 add_data_member_location_attribute (die
, binfo
);
12406 if (BINFO_VIRTUAL_P (binfo
))
12407 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
12409 if (access
== access_public_node
)
12410 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
12411 else if (access
== access_protected_node
)
12412 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12415 /* Generate a DIE for a class member. */
12418 gen_member_die (tree type
, dw_die_ref context_die
)
12421 tree binfo
= TYPE_BINFO (type
);
12424 /* If this is not an incomplete type, output descriptions of each of its
12425 members. Note that as we output the DIEs necessary to represent the
12426 members of this record or union type, we will also be trying to output
12427 DIEs to represent the *types* of those members. However the `type'
12428 function (above) will specifically avoid generating type DIEs for member
12429 types *within* the list of member DIEs for this (containing) type except
12430 for those types (of members) which are explicitly marked as also being
12431 members of this (containing) type themselves. The g++ front- end can
12432 force any given type to be treated as a member of some other (containing)
12433 type by setting the TYPE_CONTEXT of the given (member) type to point to
12434 the TREE node representing the appropriate (containing) type. */
12436 /* First output info about the base classes. */
12439 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
12443 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
12444 gen_inheritance_die (base
,
12445 (accesses
? VEC_index (tree
, accesses
, i
)
12446 : access_public_node
), context_die
);
12449 /* Now output info about the data members and type members. */
12450 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
12452 /* If we thought we were generating minimal debug info for TYPE
12453 and then changed our minds, some of the member declarations
12454 may have already been defined. Don't define them again, but
12455 do put them in the right order. */
12457 child
= lookup_decl_die (member
);
12459 splice_child_die (context_die
, child
);
12461 gen_decl_die (member
, context_die
);
12464 /* Now output info about the function members (if any). */
12465 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
12467 /* Don't include clones in the member list. */
12468 if (DECL_ABSTRACT_ORIGIN (member
))
12471 child
= lookup_decl_die (member
);
12473 splice_child_die (context_die
, child
);
12475 gen_decl_die (member
, context_die
);
12479 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12480 is set, we pretend that the type was never defined, so we only get the
12481 member DIEs needed by later specification DIEs. */
12484 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
12486 dw_die_ref type_die
= lookup_type_die (type
);
12487 dw_die_ref scope_die
= 0;
12489 int complete
= (TYPE_SIZE (type
)
12490 && (! TYPE_STUB_DECL (type
)
12491 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
12492 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
12494 if (type_die
&& ! complete
)
12497 if (TYPE_CONTEXT (type
) != NULL_TREE
12498 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12499 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
12502 scope_die
= scope_die_for (type
, context_die
);
12504 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
12505 /* First occurrence of type or toplevel definition of nested class. */
12507 dw_die_ref old_die
= type_die
;
12509 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
12510 ? DW_TAG_structure_type
: DW_TAG_union_type
,
12512 equate_type_number_to_die (type
, type_die
);
12514 add_AT_specification (type_die
, old_die
);
12516 add_name_attribute (type_die
, type_tag (type
));
12519 remove_AT (type_die
, DW_AT_declaration
);
12521 /* If this type has been completed, then give it a byte_size attribute and
12522 then give a list of members. */
12523 if (complete
&& !ns_decl
)
12525 /* Prevent infinite recursion in cases where the type of some member of
12526 this type is expressed in terms of this type itself. */
12527 TREE_ASM_WRITTEN (type
) = 1;
12528 add_byte_size_attribute (type_die
, type
);
12529 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12530 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12532 /* If the first reference to this type was as the return type of an
12533 inline function, then it may not have a parent. Fix this now. */
12534 if (type_die
->die_parent
== NULL
)
12535 add_child_die (scope_die
, type_die
);
12537 push_decl_scope (type
);
12538 gen_member_die (type
, type_die
);
12541 /* GNU extension: Record what type our vtable lives in. */
12542 if (TYPE_VFIELD (type
))
12544 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
12546 gen_type_die (vtype
, context_die
);
12547 add_AT_die_ref (type_die
, DW_AT_containing_type
,
12548 lookup_type_die (vtype
));
12553 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12555 /* We don't need to do this for function-local types. */
12556 if (TYPE_STUB_DECL (type
)
12557 && ! decl_function_context (TYPE_STUB_DECL (type
)))
12558 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
12562 /* Generate a DIE for a subroutine _type_. */
12565 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
12567 tree return_type
= TREE_TYPE (type
);
12568 dw_die_ref subr_die
12569 = new_die (DW_TAG_subroutine_type
,
12570 scope_die_for (type
, context_die
), type
);
12572 equate_type_number_to_die (type
, subr_die
);
12573 add_prototyped_attribute (subr_die
, type
);
12574 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
12575 gen_formal_types_die (type
, subr_die
);
12578 /* Generate a DIE for a type definition. */
12581 gen_typedef_die (tree decl
, dw_die_ref context_die
)
12583 dw_die_ref type_die
;
12586 if (TREE_ASM_WRITTEN (decl
))
12589 TREE_ASM_WRITTEN (decl
) = 1;
12590 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12591 origin
= decl_ultimate_origin (decl
);
12592 if (origin
!= NULL
)
12593 add_abstract_origin_attribute (type_die
, origin
);
12598 add_name_and_src_coords_attributes (type_die
, decl
);
12599 if (DECL_ORIGINAL_TYPE (decl
))
12601 type
= DECL_ORIGINAL_TYPE (decl
);
12603 gcc_assert (type
!= TREE_TYPE (decl
));
12604 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12607 type
= TREE_TYPE (decl
);
12609 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12610 TREE_THIS_VOLATILE (decl
), context_die
);
12613 if (DECL_ABSTRACT (decl
))
12614 equate_decl_number_to_die (decl
, type_die
);
12617 /* Generate a type description DIE. */
12620 gen_type_die (tree type
, dw_die_ref context_die
)
12624 if (type
== NULL_TREE
|| type
== error_mark_node
)
12627 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12628 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12630 if (TREE_ASM_WRITTEN (type
))
12633 /* Prevent broken recursion; we can't hand off to the same type. */
12634 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
12636 TREE_ASM_WRITTEN (type
) = 1;
12637 gen_decl_die (TYPE_NAME (type
), context_die
);
12641 /* We are going to output a DIE to represent the unqualified version
12642 of this type (i.e. without any const or volatile qualifiers) so
12643 get the main variant (i.e. the unqualified version) of this type
12644 now. (Vectors are special because the debugging info is in the
12645 cloned type itself). */
12646 if (TREE_CODE (type
) != VECTOR_TYPE
)
12647 type
= type_main_variant (type
);
12649 if (TREE_ASM_WRITTEN (type
))
12652 switch (TREE_CODE (type
))
12658 case REFERENCE_TYPE
:
12659 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12660 ensures that the gen_type_die recursion will terminate even if the
12661 type is recursive. Recursive types are possible in Ada. */
12662 /* ??? We could perhaps do this for all types before the switch
12664 TREE_ASM_WRITTEN (type
) = 1;
12666 /* For these types, all that is required is that we output a DIE (or a
12667 set of DIEs) to represent the "basis" type. */
12668 gen_type_die (TREE_TYPE (type
), context_die
);
12672 /* This code is used for C++ pointer-to-data-member types.
12673 Output a description of the relevant class type. */
12674 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12676 /* Output a description of the type of the object pointed to. */
12677 gen_type_die (TREE_TYPE (type
), context_die
);
12679 /* Now output a DIE to represent this pointer-to-data-member type
12681 gen_ptr_to_mbr_type_die (type
, context_die
);
12684 case FUNCTION_TYPE
:
12685 /* Force out return type (in case it wasn't forced out already). */
12686 gen_type_die (TREE_TYPE (type
), context_die
);
12687 gen_subroutine_type_die (type
, context_die
);
12691 /* Force out return type (in case it wasn't forced out already). */
12692 gen_type_die (TREE_TYPE (type
), context_die
);
12693 gen_subroutine_type_die (type
, context_die
);
12697 gen_array_type_die (type
, context_die
);
12701 gen_array_type_die (type
, context_die
);
12704 case ENUMERAL_TYPE
:
12707 case QUAL_UNION_TYPE
:
12708 /* If this is a nested type whose containing class hasn't been written
12709 out yet, writing it out will cover this one, too. This does not apply
12710 to instantiations of member class templates; they need to be added to
12711 the containing class as they are generated. FIXME: This hurts the
12712 idea of combining type decls from multiple TUs, since we can't predict
12713 what set of template instantiations we'll get. */
12714 if (TYPE_CONTEXT (type
)
12715 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12716 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12718 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12720 if (TREE_ASM_WRITTEN (type
))
12723 /* If that failed, attach ourselves to the stub. */
12724 push_decl_scope (TYPE_CONTEXT (type
));
12725 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12730 declare_in_namespace (type
, context_die
);
12734 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12736 /* This might have been written out by the call to
12737 declare_in_namespace. */
12738 if (!TREE_ASM_WRITTEN (type
))
12739 gen_enumeration_type_die (type
, context_die
);
12742 gen_struct_or_union_type_die (type
, context_die
);
12747 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12748 it up if it is ever completed. gen_*_type_die will set it for us
12749 when appropriate. */
12757 /* No DIEs needed for fundamental types. */
12761 /* No Dwarf representation currently defined. */
12765 gcc_unreachable ();
12768 TREE_ASM_WRITTEN (type
) = 1;
12771 /* Generate a DIE for a tagged type instantiation. */
12774 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12776 if (type
== NULL_TREE
|| type
== error_mark_node
)
12779 /* We are going to output a DIE to represent the unqualified version of
12780 this type (i.e. without any const or volatile qualifiers) so make sure
12781 that we have the main variant (i.e. the unqualified version) of this
12783 gcc_assert (type
== type_main_variant (type
));
12785 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12786 an instance of an unresolved type. */
12788 switch (TREE_CODE (type
))
12793 case ENUMERAL_TYPE
:
12794 gen_inlined_enumeration_type_die (type
, context_die
);
12798 gen_inlined_structure_type_die (type
, context_die
);
12802 case QUAL_UNION_TYPE
:
12803 gen_inlined_union_type_die (type
, context_die
);
12807 gcc_unreachable ();
12811 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12812 things which are local to the given block. */
12815 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12817 int must_output_die
= 0;
12820 enum tree_code origin_code
;
12822 /* Ignore blocks that are NULL. */
12823 if (stmt
== NULL_TREE
)
12826 /* If the block is one fragment of a non-contiguous block, do not
12827 process the variables, since they will have been done by the
12828 origin block. Do process subblocks. */
12829 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12833 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12834 gen_block_die (sub
, context_die
, depth
+ 1);
12839 /* Determine the "ultimate origin" of this block. This block may be an
12840 inlined instance of an inlined instance of inline function, so we have
12841 to trace all of the way back through the origin chain to find out what
12842 sort of node actually served as the original seed for the creation of
12843 the current block. */
12844 origin
= block_ultimate_origin (stmt
);
12845 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12847 /* Determine if we need to output any Dwarf DIEs at all to represent this
12849 if (origin_code
== FUNCTION_DECL
)
12850 /* The outer scopes for inlinings *must* always be represented. We
12851 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12852 must_output_die
= 1;
12855 /* In the case where the current block represents an inlining of the
12856 "body block" of an inline function, we must *NOT* output any DIE for
12857 this block because we have already output a DIE to represent the whole
12858 inlined function scope and the "body block" of any function doesn't
12859 really represent a different scope according to ANSI C rules. So we
12860 check here to make sure that this block does not represent a "body
12861 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12862 if (! is_body_block (origin
? origin
: stmt
))
12864 /* Determine if this block directly contains any "significant"
12865 local declarations which we will need to output DIEs for. */
12866 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12867 /* We are not in terse mode so *any* local declaration counts
12868 as being a "significant" one. */
12869 must_output_die
= (BLOCK_VARS (stmt
) != NULL
12870 && (TREE_USED (stmt
)
12871 || TREE_ASM_WRITTEN (stmt
)
12872 || BLOCK_ABSTRACT (stmt
)));
12874 /* We are in terse mode, so only local (nested) function
12875 definitions count as "significant" local declarations. */
12876 for (decl
= BLOCK_VARS (stmt
);
12877 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12878 if (TREE_CODE (decl
) == FUNCTION_DECL
12879 && DECL_INITIAL (decl
))
12881 must_output_die
= 1;
12887 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12888 DIE for any block which contains no significant local declarations at
12889 all. Rather, in such cases we just call `decls_for_scope' so that any
12890 needed Dwarf info for any sub-blocks will get properly generated. Note
12891 that in terse mode, our definition of what constitutes a "significant"
12892 local declaration gets restricted to include only inlined function
12893 instances and local (nested) function definitions. */
12894 if (must_output_die
)
12896 if (origin_code
== FUNCTION_DECL
)
12897 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12899 gen_lexical_block_die (stmt
, context_die
, depth
);
12902 decls_for_scope (stmt
, context_die
, depth
);
12905 /* Generate all of the decls declared within a given scope and (recursively)
12906 all of its sub-blocks. */
12909 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12914 /* Ignore NULL blocks. */
12915 if (stmt
== NULL_TREE
)
12918 if (TREE_USED (stmt
))
12920 /* Output the DIEs to represent all of the data objects and typedefs
12921 declared directly within this block but not within any nested
12922 sub-blocks. Also, nested function and tag DIEs have been
12923 generated with a parent of NULL; fix that up now. */
12924 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12928 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12929 die
= lookup_decl_die (decl
);
12930 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12931 die
= lookup_type_die (TREE_TYPE (decl
));
12935 if (die
!= NULL
&& die
->die_parent
== NULL
)
12936 add_child_die (context_die
, die
);
12937 /* Do not produce debug information for static variables since
12938 these might be optimized out. We are called for these later
12939 in cgraph_varpool_analyze_pending_decls. */
12940 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
12943 gen_decl_die (decl
, context_die
);
12947 /* If we're at -g1, we're not interested in subblocks. */
12948 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12951 /* Output the DIEs to represent all sub-blocks (and the items declared
12952 therein) of this block. */
12953 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12955 subblocks
= BLOCK_CHAIN (subblocks
))
12956 gen_block_die (subblocks
, context_die
, depth
+ 1);
12959 /* Is this a typedef we can avoid emitting? */
12962 is_redundant_typedef (tree decl
)
12964 if (TYPE_DECL_IS_STUB (decl
))
12967 if (DECL_ARTIFICIAL (decl
)
12968 && DECL_CONTEXT (decl
)
12969 && is_tagged_type (DECL_CONTEXT (decl
))
12970 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12971 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12972 /* Also ignore the artificial member typedef for the class name. */
12978 /* Returns the DIE for decl. A DIE will always be returned. */
12981 force_decl_die (tree decl
)
12983 dw_die_ref decl_die
;
12984 unsigned saved_external_flag
;
12985 tree save_fn
= NULL_TREE
;
12986 decl_die
= lookup_decl_die (decl
);
12989 dw_die_ref context_die
;
12990 tree decl_context
= DECL_CONTEXT (decl
);
12993 /* Find die that represents this context. */
12994 if (TYPE_P (decl_context
))
12995 context_die
= force_type_die (decl_context
);
12997 context_die
= force_decl_die (decl_context
);
13000 context_die
= comp_unit_die
;
13002 decl_die
= lookup_decl_die (decl
);
13006 switch (TREE_CODE (decl
))
13008 case FUNCTION_DECL
:
13009 /* Clear current_function_decl, so that gen_subprogram_die thinks
13010 that this is a declaration. At this point, we just want to force
13011 declaration die. */
13012 save_fn
= current_function_decl
;
13013 current_function_decl
= NULL_TREE
;
13014 gen_subprogram_die (decl
, context_die
);
13015 current_function_decl
= save_fn
;
13019 /* Set external flag to force declaration die. Restore it after
13020 gen_decl_die() call. */
13021 saved_external_flag
= DECL_EXTERNAL (decl
);
13022 DECL_EXTERNAL (decl
) = 1;
13023 gen_decl_die (decl
, context_die
);
13024 DECL_EXTERNAL (decl
) = saved_external_flag
;
13027 case NAMESPACE_DECL
:
13028 dwarf2out_decl (decl
);
13032 gcc_unreachable ();
13035 /* We should be able to find the DIE now. */
13037 decl_die
= lookup_decl_die (decl
);
13038 gcc_assert (decl_die
);
13044 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13045 always returned. */
13048 force_type_die (tree type
)
13050 dw_die_ref type_die
;
13052 type_die
= lookup_type_die (type
);
13055 dw_die_ref context_die
;
13056 if (TYPE_CONTEXT (type
))
13058 if (TYPE_P (TYPE_CONTEXT (type
)))
13059 context_die
= force_type_die (TYPE_CONTEXT (type
));
13061 context_die
= force_decl_die (TYPE_CONTEXT (type
));
13064 context_die
= comp_unit_die
;
13066 type_die
= lookup_type_die (type
);
13069 gen_type_die (type
, context_die
);
13070 type_die
= lookup_type_die (type
);
13071 gcc_assert (type_die
);
13076 /* Force out any required namespaces to be able to output DECL,
13077 and return the new context_die for it, if it's changed. */
13080 setup_namespace_context (tree thing
, dw_die_ref context_die
)
13082 tree context
= (DECL_P (thing
)
13083 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
13084 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
13085 /* Force out the namespace. */
13086 context_die
= force_decl_die (context
);
13088 return context_die
;
13091 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13092 type) within its namespace, if appropriate.
13094 For compatibility with older debuggers, namespace DIEs only contain
13095 declarations; all definitions are emitted at CU scope. */
13098 declare_in_namespace (tree thing
, dw_die_ref context_die
)
13100 dw_die_ref ns_context
;
13102 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13105 /* If this decl is from an inlined function, then don't try to emit it in its
13106 namespace, as we will get confused. It would have already been emitted
13107 when the abstract instance of the inline function was emitted anyways. */
13108 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
13111 ns_context
= setup_namespace_context (thing
, context_die
);
13113 if (ns_context
!= context_die
)
13115 if (DECL_P (thing
))
13116 gen_decl_die (thing
, ns_context
);
13118 gen_type_die (thing
, ns_context
);
13122 /* Generate a DIE for a namespace or namespace alias. */
13125 gen_namespace_die (tree decl
)
13127 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
13129 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13130 they are an alias of. */
13131 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
13133 /* Output a real namespace. */
13134 dw_die_ref namespace_die
13135 = new_die (DW_TAG_namespace
, context_die
, decl
);
13136 add_name_and_src_coords_attributes (namespace_die
, decl
);
13137 equate_decl_number_to_die (decl
, namespace_die
);
13141 /* Output a namespace alias. */
13143 /* Force out the namespace we are an alias of, if necessary. */
13144 dw_die_ref origin_die
13145 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
13147 /* Now create the namespace alias DIE. */
13148 dw_die_ref namespace_die
13149 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
13150 add_name_and_src_coords_attributes (namespace_die
, decl
);
13151 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
13152 equate_decl_number_to_die (decl
, namespace_die
);
13156 /* Generate Dwarf debug information for a decl described by DECL. */
13159 gen_decl_die (tree decl
, dw_die_ref context_die
)
13163 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
13166 switch (TREE_CODE (decl
))
13172 /* The individual enumerators of an enum type get output when we output
13173 the Dwarf representation of the relevant enum type itself. */
13176 case FUNCTION_DECL
:
13177 /* Don't output any DIEs to represent mere function declarations,
13178 unless they are class members or explicit block externs. */
13179 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
13180 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
13185 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13186 on local redeclarations of global functions. That seems broken. */
13187 if (current_function_decl
!= decl
)
13188 /* This is only a declaration. */;
13191 /* If we're emitting a clone, emit info for the abstract instance. */
13192 if (DECL_ORIGIN (decl
) != decl
)
13193 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
13195 /* If we're emitting an out-of-line copy of an inline function,
13196 emit info for the abstract instance and set up to refer to it. */
13197 else if (cgraph_function_possibly_inlined_p (decl
)
13198 && ! DECL_ABSTRACT (decl
)
13199 && ! class_or_namespace_scope_p (context_die
)
13200 /* dwarf2out_abstract_function won't emit a die if this is just
13201 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13202 that case, because that works only if we have a die. */
13203 && DECL_INITIAL (decl
) != NULL_TREE
)
13205 dwarf2out_abstract_function (decl
);
13206 set_decl_origin_self (decl
);
13209 /* Otherwise we're emitting the primary DIE for this decl. */
13210 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
13212 /* Before we describe the FUNCTION_DECL itself, make sure that we
13213 have described its return type. */
13214 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13216 /* And its virtual context. */
13217 if (DECL_VINDEX (decl
) != NULL_TREE
)
13218 gen_type_die (DECL_CONTEXT (decl
), context_die
);
13220 /* And its containing type. */
13221 origin
= decl_class_context (decl
);
13222 if (origin
!= NULL_TREE
)
13223 gen_type_die_for_member (origin
, decl
, context_die
);
13225 /* And its containing namespace. */
13226 declare_in_namespace (decl
, context_die
);
13229 /* Now output a DIE to represent the function itself. */
13230 gen_subprogram_die (decl
, context_die
);
13234 /* If we are in terse mode, don't generate any DIEs to represent any
13235 actual typedefs. */
13236 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13239 /* In the special case of a TYPE_DECL node representing the declaration
13240 of some type tag, if the given TYPE_DECL is marked as having been
13241 instantiated from some other (original) TYPE_DECL node (e.g. one which
13242 was generated within the original definition of an inline function) we
13243 have to generate a special (abbreviated) DW_TAG_structure_type,
13244 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13245 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
13246 && is_tagged_type (TREE_TYPE (decl
)))
13248 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
13252 if (is_redundant_typedef (decl
))
13253 gen_type_die (TREE_TYPE (decl
), context_die
);
13255 /* Output a DIE to represent the typedef itself. */
13256 gen_typedef_die (decl
, context_die
);
13260 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13261 gen_label_die (decl
, context_die
);
13266 /* If we are in terse mode, don't generate any DIEs to represent any
13267 variable declarations or definitions. */
13268 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13271 /* Output any DIEs that are needed to specify the type of this data
13273 gen_type_die (TREE_TYPE (decl
), context_die
);
13275 /* And its containing type. */
13276 origin
= decl_class_context (decl
);
13277 if (origin
!= NULL_TREE
)
13278 gen_type_die_for_member (origin
, decl
, context_die
);
13280 /* And its containing namespace. */
13281 declare_in_namespace (decl
, context_die
);
13283 /* Now output the DIE to represent the data object itself. This gets
13284 complicated because of the possibility that the VAR_DECL really
13285 represents an inlined instance of a formal parameter for an inline
13287 origin
= decl_ultimate_origin (decl
);
13288 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
13289 gen_formal_parameter_die (decl
, context_die
);
13291 gen_variable_die (decl
, context_die
);
13295 /* Ignore the nameless fields that are used to skip bits but handle C++
13296 anonymous unions and structs. */
13297 if (DECL_NAME (decl
) != NULL_TREE
13298 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
13299 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
13301 gen_type_die (member_declared_type (decl
), context_die
);
13302 gen_field_die (decl
, context_die
);
13307 gen_type_die (TREE_TYPE (decl
), context_die
);
13308 gen_formal_parameter_die (decl
, context_die
);
13311 case NAMESPACE_DECL
:
13312 gen_namespace_die (decl
);
13316 /* Probably some frontend-internal decl. Assume we don't care. */
13317 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
13322 /* Output debug information for global decl DECL. Called from toplev.c after
13323 compilation proper has finished. */
13326 dwarf2out_global_decl (tree decl
)
13328 /* Output DWARF2 information for file-scope tentative data object
13329 declarations, file-scope (extern) function declarations (which had no
13330 corresponding body) and file-scope tagged type declarations and
13331 definitions which have not yet been forced out. */
13332 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
13333 dwarf2out_decl (decl
);
13336 /* Output debug information for type decl DECL. Called from toplev.c
13337 and from language front ends (to record built-in types). */
13339 dwarf2out_type_decl (tree decl
, int local
)
13342 dwarf2out_decl (decl
);
13345 /* Output debug information for imported module or decl. */
13348 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
13350 dw_die_ref imported_die
, at_import_die
;
13351 dw_die_ref scope_die
;
13352 expanded_location xloc
;
13354 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13359 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13360 We need decl DIE for reference and scope die. First, get DIE for the decl
13363 /* Get the scope die for decl context. Use comp_unit_die for global module
13364 or decl. If die is not found for non globals, force new die. */
13366 scope_die
= comp_unit_die
;
13367 else if (TYPE_P (context
))
13368 scope_die
= force_type_die (context
);
13370 scope_die
= force_decl_die (context
);
13372 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13373 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
13375 if (is_base_type (TREE_TYPE (decl
)))
13376 at_import_die
= base_type_die (TREE_TYPE (decl
));
13378 at_import_die
= force_type_die (TREE_TYPE (decl
));
13382 at_import_die
= lookup_decl_die (decl
);
13383 if (!at_import_die
)
13385 /* If we're trying to avoid duplicate debug info, we may not have
13386 emitted the member decl for this field. Emit it now. */
13387 if (TREE_CODE (decl
) == FIELD_DECL
)
13389 tree type
= DECL_CONTEXT (decl
);
13390 dw_die_ref type_context_die
;
13392 if (TYPE_CONTEXT (type
))
13393 if (TYPE_P (TYPE_CONTEXT (type
)))
13394 type_context_die
= force_type_die (TYPE_CONTEXT (type
));
13396 type_context_die
= force_decl_die (TYPE_CONTEXT (type
));
13398 type_context_die
= comp_unit_die
;
13399 gen_type_die_for_member (type
, decl
, type_context_die
);
13401 at_import_die
= force_decl_die (decl
);
13405 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13406 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
13407 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
13409 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
13411 xloc
= expand_location (input_location
);
13412 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
13413 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
13414 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
13417 /* Write the debugging output for DECL. */
13420 dwarf2out_decl (tree decl
)
13422 dw_die_ref context_die
= comp_unit_die
;
13424 switch (TREE_CODE (decl
))
13429 case FUNCTION_DECL
:
13430 /* What we would really like to do here is to filter out all mere
13431 file-scope declarations of file-scope functions which are never
13432 referenced later within this translation unit (and keep all of ones
13433 that *are* referenced later on) but we aren't clairvoyant, so we have
13434 no idea which functions will be referenced in the future (i.e. later
13435 on within the current translation unit). So here we just ignore all
13436 file-scope function declarations which are not also definitions. If
13437 and when the debugger needs to know something about these functions,
13438 it will have to hunt around and find the DWARF information associated
13439 with the definition of the function.
13441 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13442 nodes represent definitions and which ones represent mere
13443 declarations. We have to check DECL_INITIAL instead. That's because
13444 the C front-end supports some weird semantics for "extern inline"
13445 function definitions. These can get inlined within the current
13446 translation unit (and thus, we need to generate Dwarf info for their
13447 abstract instances so that the Dwarf info for the concrete inlined
13448 instances can have something to refer to) but the compiler never
13449 generates any out-of-lines instances of such things (despite the fact
13450 that they *are* definitions).
13452 The important point is that the C front-end marks these "extern
13453 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13454 them anyway. Note that the C++ front-end also plays some similar games
13455 for inline function definitions appearing within include files which
13456 also contain `#pragma interface' pragmas. */
13457 if (DECL_INITIAL (decl
) == NULL_TREE
)
13460 /* If we're a nested function, initially use a parent of NULL; if we're
13461 a plain function, this will be fixed up in decls_for_scope. If
13462 we're a method, it will be ignored, since we already have a DIE. */
13463 if (decl_function_context (decl
)
13464 /* But if we're in terse mode, we don't care about scope. */
13465 && debug_info_level
> DINFO_LEVEL_TERSE
)
13466 context_die
= NULL
;
13470 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13471 declaration and if the declaration was never even referenced from
13472 within this entire compilation unit. We suppress these DIEs in
13473 order to save space in the .debug section (by eliminating entries
13474 which are probably useless). Note that we must not suppress
13475 block-local extern declarations (whether used or not) because that
13476 would screw-up the debugger's name lookup mechanism and cause it to
13477 miss things which really ought to be in scope at a given point. */
13478 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
13481 /* For local statics lookup proper context die. */
13482 if (TREE_STATIC (decl
) && decl_function_context (decl
))
13483 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
13485 /* If we are in terse mode, don't generate any DIEs to represent any
13486 variable declarations or definitions. */
13487 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13491 case NAMESPACE_DECL
:
13492 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13494 if (lookup_decl_die (decl
) != NULL
)
13499 /* Don't emit stubs for types unless they are needed by other DIEs. */
13500 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
13503 /* Don't bother trying to generate any DIEs to represent any of the
13504 normal built-in types for the language we are compiling. */
13505 if (DECL_IS_BUILTIN (decl
))
13507 /* OK, we need to generate one for `bool' so GDB knows what type
13508 comparisons have. */
13510 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
13511 && ! DECL_IGNORED_P (decl
))
13512 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
13517 /* If we are in terse mode, don't generate any DIEs for types. */
13518 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13521 /* If we're a function-scope tag, initially use a parent of NULL;
13522 this will be fixed up in decls_for_scope. */
13523 if (decl_function_context (decl
))
13524 context_die
= NULL
;
13532 gen_decl_die (decl
, context_die
);
13535 /* Output a marker (i.e. a label) for the beginning of the generated code for
13536 a lexical block. */
13539 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
13540 unsigned int blocknum
)
13542 switch_to_section (current_function_section ());
13543 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
13546 /* Output a marker (i.e. a label) for the end of the generated code for a
13550 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
13552 switch_to_section (current_function_section ());
13553 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
13556 /* Returns nonzero if it is appropriate not to emit any debugging
13557 information for BLOCK, because it doesn't contain any instructions.
13559 Don't allow this for blocks with nested functions or local classes
13560 as we would end up with orphans, and in the presence of scheduling
13561 we may end up calling them anyway. */
13564 dwarf2out_ignore_block (tree block
)
13568 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
13569 if (TREE_CODE (decl
) == FUNCTION_DECL
13570 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
13576 /* Hash table routines for file_hash. */
13579 file_table_eq (const void *p1_p
, const void *p2_p
)
13581 const struct dwarf_file_data
* p1
= p1_p
;
13582 const char * p2
= p2_p
;
13583 return strcmp (p1
->filename
, p2
) == 0;
13587 file_table_hash (const void *p_p
)
13589 const struct dwarf_file_data
* p
= p_p
;
13590 return htab_hash_string (p
->filename
);
13593 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13594 dwarf2out.c) and return its "index". The index of each (known) filename is
13595 just a unique number which is associated with only that one filename. We
13596 need such numbers for the sake of generating labels (in the .debug_sfnames
13597 section) and references to those files numbers (in the .debug_srcinfo
13598 and.debug_macinfo sections). If the filename given as an argument is not
13599 found in our current list, add it to the list and assign it the next
13600 available unique index number. In order to speed up searches, we remember
13601 the index of the filename was looked up last. This handles the majority of
13604 static struct dwarf_file_data
*
13605 lookup_filename (const char *file_name
)
13608 struct dwarf_file_data
* created
;
13610 /* Check to see if the file name that was searched on the previous
13611 call matches this file name. If so, return the index. */
13612 if (file_table_last_lookup
13613 && (file_name
== file_table_last_lookup
->filename
13614 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
13615 return file_table_last_lookup
;
13617 /* Didn't match the previous lookup, search the table. */
13618 slot
= htab_find_slot_with_hash (file_table
, file_name
,
13619 htab_hash_string (file_name
), INSERT
);
13623 created
= ggc_alloc (sizeof (struct dwarf_file_data
));
13624 created
->filename
= file_name
;
13625 created
->emitted_number
= 0;
13630 /* If the assembler will construct the file table, then translate the compiler
13631 internal file table number into the assembler file table number, and emit
13632 a .file directive if we haven't already emitted one yet. The file table
13633 numbers are different because we prune debug info for unused variables and
13634 types, which may include filenames. */
13637 maybe_emit_file (struct dwarf_file_data
* fd
)
13639 if (! fd
->emitted_number
)
13641 if (last_emitted_file
)
13642 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
13644 fd
->emitted_number
= 1;
13645 last_emitted_file
= fd
;
13647 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13649 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
13650 output_quoted_string (asm_out_file
, fd
->filename
);
13651 fputc ('\n', asm_out_file
);
13655 return fd
->emitted_number
;
13658 /* Called by the final INSN scan whenever we see a var location. We
13659 use it to drop labels in the right places, and throw the location in
13660 our lookup table. */
13663 dwarf2out_var_location (rtx loc_note
)
13665 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13666 struct var_loc_node
*newloc
;
13668 static rtx last_insn
;
13669 static const char *last_label
;
13672 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13674 prev_insn
= PREV_INSN (loc_note
);
13676 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13677 /* If the insn we processed last time is the previous insn
13678 and it is also a var location note, use the label we emitted
13680 if (last_insn
!= NULL_RTX
13681 && last_insn
== prev_insn
13682 && NOTE_P (prev_insn
)
13683 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13685 newloc
->label
= last_label
;
13689 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13690 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13692 newloc
->label
= ggc_strdup (loclabel
);
13694 newloc
->var_loc_note
= loc_note
;
13695 newloc
->next
= NULL
;
13697 if (cfun
&& in_cold_section_p
)
13698 newloc
->section_label
= cfun
->cold_section_label
;
13700 newloc
->section_label
= text_section_label
;
13702 last_insn
= loc_note
;
13703 last_label
= newloc
->label
;
13704 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
13705 add_var_loc_to_decl (decl
, newloc
);
13708 /* We need to reset the locations at the beginning of each
13709 function. We can't do this in the end_function hook, because the
13710 declarations that use the locations won't have been output when
13711 that hook is called. Also compute have_multiple_function_sections here. */
13714 dwarf2out_begin_function (tree fun
)
13716 htab_empty (decl_loc_table
);
13718 if (function_section (fun
) != text_section
)
13719 have_multiple_function_sections
= true;
13722 /* Output a label to mark the beginning of a source code line entry
13723 and record information relating to this source line, in
13724 'line_info_table' for later output of the .debug_line section. */
13727 dwarf2out_source_line (unsigned int line
, const char *filename
)
13729 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13732 int file_num
= maybe_emit_file (lookup_filename (filename
));
13734 switch_to_section (current_function_section ());
13736 /* If requested, emit something human-readable. */
13737 if (flag_debug_asm
)
13738 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13741 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13743 /* Emit the .loc directive understood by GNU as. */
13744 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13746 /* Indicate that line number info exists. */
13747 line_info_table_in_use
++;
13749 else if (function_section (current_function_decl
) != text_section
)
13751 dw_separate_line_info_ref line_info
;
13752 targetm
.asm_out
.internal_label (asm_out_file
,
13753 SEPARATE_LINE_CODE_LABEL
,
13754 separate_line_info_table_in_use
);
13756 /* Expand the line info table if necessary. */
13757 if (separate_line_info_table_in_use
13758 == separate_line_info_table_allocated
)
13760 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13761 separate_line_info_table
13762 = ggc_realloc (separate_line_info_table
,
13763 separate_line_info_table_allocated
13764 * sizeof (dw_separate_line_info_entry
));
13765 memset (separate_line_info_table
13766 + separate_line_info_table_in_use
,
13768 (LINE_INFO_TABLE_INCREMENT
13769 * sizeof (dw_separate_line_info_entry
)));
13772 /* Add the new entry at the end of the line_info_table. */
13774 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13775 line_info
->dw_file_num
= file_num
;
13776 line_info
->dw_line_num
= line
;
13777 line_info
->function
= current_function_funcdef_no
;
13781 dw_line_info_ref line_info
;
13783 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13784 line_info_table_in_use
);
13786 /* Expand the line info table if necessary. */
13787 if (line_info_table_in_use
== line_info_table_allocated
)
13789 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13791 = ggc_realloc (line_info_table
,
13792 (line_info_table_allocated
13793 * sizeof (dw_line_info_entry
)));
13794 memset (line_info_table
+ line_info_table_in_use
, 0,
13795 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13798 /* Add the new entry at the end of the line_info_table. */
13799 line_info
= &line_info_table
[line_info_table_in_use
++];
13800 line_info
->dw_file_num
= file_num
;
13801 line_info
->dw_line_num
= line
;
13806 /* Record the beginning of a new source file. */
13809 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13811 if (flag_eliminate_dwarf2_dups
)
13813 /* Record the beginning of the file for break_out_includes. */
13814 dw_die_ref bincl_die
;
13816 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13817 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13820 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13822 int file_num
= maybe_emit_file (lookup_filename (filename
));
13824 switch_to_section (debug_macinfo_section
);
13825 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13826 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13829 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
13833 /* Record the end of a source file. */
13836 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13838 if (flag_eliminate_dwarf2_dups
)
13839 /* Record the end of the file for break_out_includes. */
13840 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13842 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13844 switch_to_section (debug_macinfo_section
);
13845 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13849 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13850 the tail part of the directive line, i.e. the part which is past the
13851 initial whitespace, #, whitespace, directive-name, whitespace part. */
13854 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13855 const char *buffer ATTRIBUTE_UNUSED
)
13857 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13859 switch_to_section (debug_macinfo_section
);
13860 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13861 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13862 dw2_asm_output_nstring (buffer
, -1, "The macro");
13866 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13867 the tail part of the directive line, i.e. the part which is past the
13868 initial whitespace, #, whitespace, directive-name, whitespace part. */
13871 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13872 const char *buffer ATTRIBUTE_UNUSED
)
13874 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13876 switch_to_section (debug_macinfo_section
);
13877 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13878 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13879 dw2_asm_output_nstring (buffer
, -1, "The macro");
13883 /* Set up for Dwarf output at the start of compilation. */
13886 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13888 /* Allocate the file_table. */
13889 file_table
= htab_create_ggc (50, file_table_hash
,
13890 file_table_eq
, NULL
);
13892 /* Allocate the decl_die_table. */
13893 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13894 decl_die_table_eq
, NULL
);
13896 /* Allocate the decl_loc_table. */
13897 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13898 decl_loc_table_eq
, NULL
);
13900 /* Allocate the initial hunk of the decl_scope_table. */
13901 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
13903 /* Allocate the initial hunk of the abbrev_die_table. */
13904 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13905 * sizeof (dw_die_ref
));
13906 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13907 /* Zero-th entry is allocated, but unused. */
13908 abbrev_die_table_in_use
= 1;
13910 /* Allocate the initial hunk of the line_info_table. */
13911 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13912 * sizeof (dw_line_info_entry
));
13913 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13915 /* Zero-th entry is allocated, but unused. */
13916 line_info_table_in_use
= 1;
13918 /* Generate the initial DIE for the .debug section. Note that the (string)
13919 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13920 will (typically) be a relative pathname and that this pathname should be
13921 taken as being relative to the directory from which the compiler was
13922 invoked when the given (base) source file was compiled. We will fill
13923 in this value in dwarf2out_finish. */
13924 comp_unit_die
= gen_compile_unit_die (NULL
);
13926 incomplete_types
= VEC_alloc (tree
, gc
, 64);
13928 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
13930 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
13931 SECTION_DEBUG
, NULL
);
13932 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
13933 SECTION_DEBUG
, NULL
);
13934 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
13935 SECTION_DEBUG
, NULL
);
13936 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
13937 SECTION_DEBUG
, NULL
);
13938 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
13939 SECTION_DEBUG
, NULL
);
13940 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
13941 SECTION_DEBUG
, NULL
);
13942 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
13943 SECTION_DEBUG
, NULL
);
13944 debug_str_section
= get_section (DEBUG_STR_SECTION
,
13945 DEBUG_STR_SECTION_FLAGS
, NULL
);
13946 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
13947 SECTION_DEBUG
, NULL
);
13948 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
13949 SECTION_DEBUG
, NULL
);
13951 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13952 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13953 DEBUG_ABBREV_SECTION_LABEL
, 0);
13954 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13955 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
13956 COLD_TEXT_SECTION_LABEL
, 0);
13957 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
13959 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13960 DEBUG_INFO_SECTION_LABEL
, 0);
13961 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13962 DEBUG_LINE_SECTION_LABEL
, 0);
13963 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13964 DEBUG_RANGES_SECTION_LABEL
, 0);
13965 switch_to_section (debug_abbrev_section
);
13966 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13967 switch_to_section (debug_info_section
);
13968 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13969 switch_to_section (debug_line_section
);
13970 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13972 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13974 switch_to_section (debug_macinfo_section
);
13975 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13976 DEBUG_MACINFO_SECTION_LABEL
, 0);
13977 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13980 switch_to_section (text_section
);
13981 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13982 if (flag_reorder_blocks_and_partition
)
13984 switch_to_section (unlikely_text_section ());
13985 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
13989 /* A helper function for dwarf2out_finish called through
13990 ht_forall. Emit one queued .debug_str string. */
13993 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13995 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13997 if (node
->form
== DW_FORM_strp
)
13999 switch_to_section (debug_str_section
);
14000 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
14001 assemble_string (node
->str
, strlen (node
->str
) + 1);
14007 #if ENABLE_ASSERT_CHECKING
14008 /* Verify that all marks are clear. */
14011 verify_marks_clear (dw_die_ref die
)
14015 gcc_assert (! die
->die_mark
);
14016 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
14018 #endif /* ENABLE_ASSERT_CHECKING */
14020 /* Clear the marks for a die and its children.
14021 Be cool if the mark isn't set. */
14024 prune_unmark_dies (dw_die_ref die
)
14030 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
14033 /* Given DIE that we're marking as used, find any other dies
14034 it references as attributes and mark them as used. */
14037 prune_unused_types_walk_attribs (dw_die_ref die
)
14042 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
14044 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
14046 /* A reference to another DIE.
14047 Make sure that it will get emitted. */
14048 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
14050 /* Set the string's refcount to 0 so that prune_unused_types_mark
14051 accounts properly for it. */
14052 if (AT_class (a
) == dw_val_class_str
)
14053 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
14058 /* Mark DIE as being used. If DOKIDS is true, then walk down
14059 to DIE's children. */
14062 prune_unused_types_mark (dw_die_ref die
, int dokids
)
14066 if (die
->die_mark
== 0)
14068 /* We haven't done this node yet. Mark it as used. */
14071 /* We also have to mark its parents as used.
14072 (But we don't want to mark our parents' kids due to this.) */
14073 if (die
->die_parent
)
14074 prune_unused_types_mark (die
->die_parent
, 0);
14076 /* Mark any referenced nodes. */
14077 prune_unused_types_walk_attribs (die
);
14079 /* If this node is a specification,
14080 also mark the definition, if it exists. */
14081 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
14082 prune_unused_types_mark (die
->die_definition
, 1);
14085 if (dokids
&& die
->die_mark
!= 2)
14087 /* We need to walk the children, but haven't done so yet.
14088 Remember that we've walked the kids. */
14091 /* If this is an array type, we need to make sure our
14092 kids get marked, even if they're types. */
14093 if (die
->die_tag
== DW_TAG_array_type
)
14094 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
14096 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
14101 /* Walk the tree DIE and mark types that we actually use. */
14104 prune_unused_types_walk (dw_die_ref die
)
14108 /* Don't do anything if this node is already marked. */
14112 switch (die
->die_tag
) {
14113 case DW_TAG_const_type
:
14114 case DW_TAG_packed_type
:
14115 case DW_TAG_pointer_type
:
14116 case DW_TAG_reference_type
:
14117 case DW_TAG_volatile_type
:
14118 case DW_TAG_typedef
:
14119 case DW_TAG_array_type
:
14120 case DW_TAG_structure_type
:
14121 case DW_TAG_union_type
:
14122 case DW_TAG_class_type
:
14123 case DW_TAG_friend
:
14124 case DW_TAG_variant_part
:
14125 case DW_TAG_enumeration_type
:
14126 case DW_TAG_subroutine_type
:
14127 case DW_TAG_string_type
:
14128 case DW_TAG_set_type
:
14129 case DW_TAG_subrange_type
:
14130 case DW_TAG_ptr_to_member_type
:
14131 case DW_TAG_file_type
:
14132 if (die
->die_perennial_p
)
14135 /* It's a type node --- don't mark it. */
14139 /* Mark everything else. */
14145 /* Now, mark any dies referenced from here. */
14146 prune_unused_types_walk_attribs (die
);
14148 /* Mark children. */
14149 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
14152 /* Increment the string counts on strings referred to from DIE's
14156 prune_unused_types_update_strings (dw_die_ref die
)
14161 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
14162 if (AT_class (a
) == dw_val_class_str
)
14164 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
14166 /* Avoid unnecessarily putting strings that are used less than
14167 twice in the hash table. */
14169 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
14172 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
14173 htab_hash_string (s
->str
),
14175 gcc_assert (*slot
== NULL
);
14181 /* Remove from the tree DIE any dies that aren't marked. */
14184 prune_unused_types_prune (dw_die_ref die
)
14188 gcc_assert (die
->die_mark
);
14189 prune_unused_types_update_strings (die
);
14191 if (! die
->die_child
)
14194 c
= die
->die_child
;
14196 dw_die_ref prev
= c
;
14197 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
14198 if (c
== die
->die_child
)
14200 /* No marked children between 'prev' and the end of the list. */
14202 /* No marked children at all. */
14203 die
->die_child
= NULL
;
14206 prev
->die_sib
= c
->die_sib
;
14207 die
->die_child
= prev
;
14212 if (c
!= prev
->die_sib
)
14214 prune_unused_types_prune (c
);
14215 } while (c
!= die
->die_child
);
14219 /* Remove dies representing declarations that we never use. */
14222 prune_unused_types (void)
14225 limbo_die_node
*node
;
14227 #if ENABLE_ASSERT_CHECKING
14228 /* All the marks should already be clear. */
14229 verify_marks_clear (comp_unit_die
);
14230 for (node
= limbo_die_list
; node
; node
= node
->next
)
14231 verify_marks_clear (node
->die
);
14232 #endif /* ENABLE_ASSERT_CHECKING */
14234 /* Set the mark on nodes that are actually used. */
14235 prune_unused_types_walk (comp_unit_die
);
14236 for (node
= limbo_die_list
; node
; node
= node
->next
)
14237 prune_unused_types_walk (node
->die
);
14239 /* Also set the mark on nodes referenced from the
14240 pubname_table or arange_table. */
14241 for (i
= 0; i
< pubname_table_in_use
; i
++)
14242 prune_unused_types_mark (pubname_table
[i
].die
, 1);
14243 for (i
= 0; i
< arange_table_in_use
; i
++)
14244 prune_unused_types_mark (arange_table
[i
], 1);
14246 /* Get rid of nodes that aren't marked; and update the string counts. */
14247 if (debug_str_hash
)
14248 htab_empty (debug_str_hash
);
14249 prune_unused_types_prune (comp_unit_die
);
14250 for (node
= limbo_die_list
; node
; node
= node
->next
)
14251 prune_unused_types_prune (node
->die
);
14253 /* Leave the marks clear. */
14254 prune_unmark_dies (comp_unit_die
);
14255 for (node
= limbo_die_list
; node
; node
= node
->next
)
14256 prune_unmark_dies (node
->die
);
14259 /* Set the parameter to true if there are any relative pathnames in
14262 file_table_relative_p (void ** slot
, void *param
)
14265 struct dwarf_file_data
*d
= *slot
;
14266 if (d
->emitted_number
&& d
->filename
[0] != DIR_SEPARATOR
)
14274 /* Output stuff that dwarf requires at the end of every file,
14275 and generate the DWARF-2 debugging info. */
14278 dwarf2out_finish (const char *filename
)
14280 limbo_die_node
*node
, *next_node
;
14281 dw_die_ref die
= 0;
14283 /* Add the name for the main input file now. We delayed this from
14284 dwarf2out_init to avoid complications with PCH. */
14285 add_name_attribute (comp_unit_die
, filename
);
14286 if (filename
[0] != DIR_SEPARATOR
)
14287 add_comp_dir_attribute (comp_unit_die
);
14288 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
14291 htab_traverse (file_table
, file_table_relative_p
, &p
);
14293 add_comp_dir_attribute (comp_unit_die
);
14296 /* Traverse the limbo die list, and add parent/child links. The only
14297 dies without parents that should be here are concrete instances of
14298 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14299 For concrete instances, we can get the parent die from the abstract
14301 for (node
= limbo_die_list
; node
; node
= next_node
)
14303 next_node
= node
->next
;
14306 if (die
->die_parent
== NULL
)
14308 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
14311 add_child_die (origin
->die_parent
, die
);
14312 else if (die
== comp_unit_die
)
14314 else if (errorcount
> 0 || sorrycount
> 0)
14315 /* It's OK to be confused by errors in the input. */
14316 add_child_die (comp_unit_die
, die
);
14319 /* In certain situations, the lexical block containing a
14320 nested function can be optimized away, which results
14321 in the nested function die being orphaned. Likewise
14322 with the return type of that nested function. Force
14323 this to be a child of the containing function.
14325 It may happen that even the containing function got fully
14326 inlined and optimized out. In that case we are lost and
14327 assign the empty child. This should not be big issue as
14328 the function is likely unreachable too. */
14329 tree context
= NULL_TREE
;
14331 gcc_assert (node
->created_for
);
14333 if (DECL_P (node
->created_for
))
14334 context
= DECL_CONTEXT (node
->created_for
);
14335 else if (TYPE_P (node
->created_for
))
14336 context
= TYPE_CONTEXT (node
->created_for
);
14338 gcc_assert (context
14339 && (TREE_CODE (context
) == FUNCTION_DECL
14340 || TREE_CODE (context
) == NAMESPACE_DECL
));
14342 origin
= lookup_decl_die (context
);
14344 add_child_die (origin
, die
);
14346 add_child_die (comp_unit_die
, die
);
14351 limbo_die_list
= NULL
;
14353 /* Walk through the list of incomplete types again, trying once more to
14354 emit full debugging info for them. */
14355 retry_incomplete_types ();
14357 if (flag_eliminate_unused_debug_types
)
14358 prune_unused_types ();
14360 /* Generate separate CUs for each of the include files we've seen.
14361 They will go into limbo_die_list. */
14362 if (flag_eliminate_dwarf2_dups
)
14363 break_out_includes (comp_unit_die
);
14365 /* Traverse the DIE's and add add sibling attributes to those DIE's
14366 that have children. */
14367 add_sibling_attributes (comp_unit_die
);
14368 for (node
= limbo_die_list
; node
; node
= node
->next
)
14369 add_sibling_attributes (node
->die
);
14371 /* Output a terminator label for the .text section. */
14372 switch_to_section (text_section
);
14373 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
14374 if (flag_reorder_blocks_and_partition
)
14376 switch_to_section (unlikely_text_section ());
14377 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
14380 /* We can only use the low/high_pc attributes if all of the code was
14382 if (!have_multiple_function_sections
)
14384 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
14385 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
14388 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14389 "base address". Use zero so that these addresses become absolute. */
14390 else if (have_location_lists
|| ranges_table_in_use
)
14391 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
14393 /* Output location list section if necessary. */
14394 if (have_location_lists
)
14396 /* Output the location lists info. */
14397 switch_to_section (debug_loc_section
);
14398 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
14399 DEBUG_LOC_SECTION_LABEL
, 0);
14400 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
14401 output_location_lists (die
);
14404 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
14405 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
14406 debug_line_section_label
);
14408 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14409 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
14411 /* Output all of the compilation units. We put the main one last so that
14412 the offsets are available to output_pubnames. */
14413 for (node
= limbo_die_list
; node
; node
= node
->next
)
14414 output_comp_unit (node
->die
, 0);
14416 output_comp_unit (comp_unit_die
, 0);
14418 /* Output the abbreviation table. */
14419 switch_to_section (debug_abbrev_section
);
14420 output_abbrev_section ();
14422 /* Output public names table if necessary. */
14423 if (pubname_table_in_use
)
14425 switch_to_section (debug_pubnames_section
);
14426 output_pubnames ();
14429 /* Output the address range information. We only put functions in the arange
14430 table, so don't write it out if we don't have any. */
14431 if (fde_table_in_use
)
14433 switch_to_section (debug_aranges_section
);
14437 /* Output ranges section if necessary. */
14438 if (ranges_table_in_use
)
14440 switch_to_section (debug_ranges_section
);
14441 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
14445 /* Output the source line correspondence table. We must do this
14446 even if there is no line information. Otherwise, on an empty
14447 translation unit, we will generate a present, but empty,
14448 .debug_info section. IRIX 6.5 `nm' will then complain when
14449 examining the file. This is done late so that any filenames
14450 used by the debug_info section are marked as 'used'. */
14451 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
14453 switch_to_section (debug_line_section
);
14454 output_line_info ();
14457 /* Have to end the macro section. */
14458 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14460 switch_to_section (debug_macinfo_section
);
14461 dw2_asm_output_data (1, 0, "End compilation unit");
14464 /* If we emitted any DW_FORM_strp form attribute, output the string
14466 if (debug_str_hash
)
14467 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
14471 /* This should never be used, but its address is needed for comparisons. */
14472 const struct gcc_debug_hooks dwarf2_debug_hooks
;
14474 #endif /* DWARF2_DEBUGGING_INFO */
14476 #include "gt-dwarf2out.h"